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

Support verification of older offchain attestations #69

Merged
merged 2 commits into from
Nov 12, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion dist/offchain/offchain.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/offchain/offchain.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions dist/offchain/typed-data-handler.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,10 @@ export type EIP712Response<T extends EIP712MessageTypes, P extends EIP712Params>
};
export declare const EIP712_DOMAIN = "EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)";
export declare abstract class TypedDataHandler {
protected config: TypedDataConfig;
config: TypedDataConfig;
constructor(config: TypedDataConfig);
getDomainSeparator(): string;
getDomainTypedData(): DomainTypedData;
signTypedDataRequest<T extends EIP712MessageTypes, P extends EIP712Params>(params: P, types: EIP712TypedData<T, P>, signer: Signer): Promise<EIP712Response<T, P>>;
verifyTypedDataRequestSignature<T extends EIP712MessageTypes, P extends EIP712Params>(attester: string, response: EIP712Response<T, P>, types: EIP712Types<T>): boolean;
verifyTypedDataRequestSignature<T extends EIP712MessageTypes, P extends EIP712Params>(attester: string, response: EIP712Response<T, P>, types: EIP712Types<T>, strict?: boolean): boolean;
}
12 changes: 9 additions & 3 deletions dist/offchain/typed-data-handler.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/offchain/typed-data-handler.js.map

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@ethereum-attestation-service/eas-sdk",
"version": "1.3.0-beta.0",
"version": "1.3.0-beta.1",
"description": "Ethereum Attestation Service - TypeScript/JavaScript SDK",
"repository": "[email protected]:ethereum-attestation-service/eas-sdk.git",
"author": "Leonid Beder <[email protected]>",
Expand Down
13 changes: 9 additions & 4 deletions src/offchain/offchain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,15 @@ export class Offchain extends TypedDataHandler {
public verifyOffchainAttestationSignature(attester: string, request: SignedOffchainAttestation): boolean {
return (
request.uid === Offchain.getOffchainUID(request.message) &&
this.verifyTypedDataRequestSignature(attester, request, {
primaryType: this.type.primaryType,
types: this.type.types
})
this.verifyTypedDataRequestSignature(
attester,
request,
{
primaryType: this.type.primaryType,
types: this.type.types
},
false
)
);
}

Expand Down
17 changes: 13 additions & 4 deletions src/offchain/typed-data-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ export type EIP712Response<T extends EIP712MessageTypes, P extends EIP712Params>
export const EIP712_DOMAIN = 'EIP712Domain(string name,string version,uint256 chainId,address verifyingContract)';

export abstract class TypedDataHandler {
protected config: TypedDataConfig;
public config: TypedDataConfig;

constructor(config: TypedDataConfig) {
this.config = config;
Expand Down Expand Up @@ -133,9 +133,18 @@ export abstract class TypedDataHandler {
public verifyTypedDataRequestSignature<T extends EIP712MessageTypes, P extends EIP712Params>(
attester: string,
response: EIP712Response<T, P>,
types: EIP712Types<T>
types: EIP712Types<T>,
strict = true
): boolean {
if (!isEqual(response.domain, this.getDomainTypedData())) {
// Normalize the chain ID
const domain: EIP712DomainTypedData = { ...response.domain, chainId: BigInt(response.domain.chainId) };

let expectedDomain = this.getDomainTypedData();
if (!strict) {
expectedDomain = { ...expectedDomain, version: domain.version };
}

if (!isEqual(domain, expectedDomain)) {
throw new Error('Invalid domain');
}

Expand All @@ -153,7 +162,7 @@ export abstract class TypedDataHandler {

const { signature } = response;
const sig = Sig.from({ v: signature.v, r: hexlify(signature.r), s: hexlify(signature.s) }).serialized;
const recoveredAddress = verifyTypedData(response.domain, response.types, response.message, sig);
const recoveredAddress = verifyTypedData(domain, response.types, response.message, sig);

return getAddress(attester) === getAddress(recoveredAddress);
}
Expand Down
Loading