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

[ASv2] update attestation hash #9659

Merged
merged 5 commits into from
Jun 23, 2022
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
21 changes: 16 additions & 5 deletions packages/protocol/contracts/identity/FederatedAttestations.sol
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ contract FederatedAttestations is
mapping(bytes32 => bool) public revokedAttestations;

bytes32 public constant EIP712_OWNERSHIP_ATTESTATION_TYPEHASH = keccak256(
"OwnershipAttestation(bytes32 identifier,address issuer,address account,uint64 issuedOn)"
abi.encodePacked(
"OwnershipAttestation(bytes32 identifier,address issuer,",
"address account,address signer,uint64 issuedOn)"
)
);
bytes32 public eip712DomainSeparator;

Expand Down Expand Up @@ -291,9 +294,7 @@ contract FederatedAttestations is
getAccounts().attestationSignerToAccount(signer) == issuer,
"Signer is not a currently authorized AttestationSigner for the issuer"
);
bytes32 structHash = keccak256(
abi.encode(EIP712_OWNERSHIP_ATTESTATION_TYPEHASH, identifier, issuer, account, issuedOn)
);
bytes32 structHash = getUniqueAttestationHash(identifier, issuer, account, signer, issuedOn);
address guessedSigner = Signatures.getSignerOfTypedDataHash(
eip712DomainSeparator,
structHash,
Expand All @@ -311,7 +312,17 @@ contract FederatedAttestations is
address signer,
uint64 issuedOn
) public pure returns (bytes32) {
return keccak256(abi.encode(identifier, issuer, account, signer, issuedOn));
return
keccak256(
abi.encode(
EIP712_OWNERSHIP_ATTESTATION_TYPEHASH,
identifier,
issuer,
account,
signer,
issuedOn
)
);
}

/**
Expand Down
4 changes: 3 additions & 1 deletion packages/protocol/lib/fed-attestations-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ export interface AttestationDetails{
identifier: string,
issuer: string,
account: string,
signer: string,
issuedOn: number,
}

Expand All @@ -24,6 +25,7 @@ const getTypedData = (chainId: number, contractAddress: Address, message?: Attes
{ name: 'identifier', type: 'bytes32' },
{ name: 'issuer', type: 'address'},
{ name: 'account', type: 'address' },
{ name: 'signer', type: 'address' },
{ name: 'issuedOn', type: 'uint64' },
],
},
Expand All @@ -48,7 +50,7 @@ export const getSignatureForAttestation = async (
chainId: number,
contractAddress: string
) => {
const typedData = getTypedData(chainId, contractAddress, { identifier,issuer,account, issuedOn})
const typedData = getTypedData(chainId, contractAddress, { identifier,issuer,account, signer, issuedOn})

const signature = await new Promise<string>((resolve, reject) => {
web3.currentProvider.send(
Expand Down
2 changes: 1 addition & 1 deletion packages/protocol/test/identity/federatedattestations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ contract('FederatedAttestations', (accounts: string[]) => {
describe('#EIP712_OWNERSHIP_ATTESTATION_TYPEHASH()', () => {
it('should have set the right typehash', async () => {
const expectedTypehash = keccak256(
'OwnershipAttestation(bytes32 identifier,address issuer,address account,uint64 issuedOn)'
'OwnershipAttestation(bytes32 identifier,address issuer,address account,address signer,uint64 issuedOn)'
)
assert.equal(
await federatedAttestations.EIP712_OWNERSHIP_ATTESTATION_TYPEHASH(),
Expand Down