Skip to content

Commit

Permalink
Merge pull request #69 from ethereum-attestation-service/offchain
Browse files Browse the repository at this point in the history
Support verification of older offchain attestations
  • Loading branch information
lbeder authored Nov 12, 2023
2 parents f569c5b + 63c5ef0 commit 1b027b8
Show file tree
Hide file tree
Showing 10 changed files with 73 additions and 21 deletions.
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

0 comments on commit 1b027b8

Please sign in to comment.