Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ Add verifyProxySignature method #68

Open
FranklinWaller opened this issue Aug 29, 2024 · 0 comments
Open

✨ Add verifyProxySignature method #68

FranklinWaller opened this issue Aug 29, 2024 · 0 comments
Labels
type: feature ✨ New feature or request

Comments

@FranklinWaller
Copy link
Member

✨ Feature

Allows developers to verify signatures from proxies if they want to.

Motivation

Even though a user can build this themselves it's enough of a use case that we should provider the method in the SDK.

Implementation

A verify function the reconstructs the same message hash as on the data proxy node and takes as input a public key, signature, request (HttpFetchAction) and response.

This is how the signature is created:

async signData(
		request: Request,
		responseBody: string,
	): Promise<Result<SignedData, string>> {
		const requestBody = await tryAsync(async () =>
			Buffer.from(await request.arrayBuffer()),
		);

		if (requestBody.isErr) {
			return Result.err(`Could not read request body: ${requestBody.error}`);
		}

		const requestUrlHash = keccak256(Buffer.from(request.url));
		const requestMethodHash = keccak256(Buffer.from(request.method));
		const requestBodyHash = keccak256(requestBody.value);
		const responseBodyHash = keccak256(Buffer.from(responseBody));

		const signResult = this.sign(
			Buffer.concat([
				requestUrlHash,
				requestMethodHash,
				requestBodyHash,
				responseBodyHash,
			]),
		);

		return Result.ok({
			publicKey: this.publicKey.toString("hex"),
			signature: Buffer.from(signResult.signature).toString("hex"),
			recId: signResult.recid,
		});
	}
@FranklinWaller FranklinWaller added the type: feature ✨ New feature or request label Aug 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: feature ✨ New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant