From 076c2802559d5d50160615a3e3725c9413d8e92b Mon Sep 17 00:00:00 2001 From: Leszek Stachowski Date: Fri, 6 Dec 2024 13:54:35 +0100 Subject: [PATCH] one more test case --- .../sdk/metadata-claims/src/metadata.test.ts | 29 ++++++++++++++++++- packages/sdk/metadata-claims/src/metadata.ts | 1 + packages/sdk/metadata-claims/src/types.ts | 2 +- 3 files changed, 30 insertions(+), 2 deletions(-) diff --git a/packages/sdk/metadata-claims/src/metadata.test.ts b/packages/sdk/metadata-claims/src/metadata.test.ts index 59c2bfa07..2269ba4c1 100644 --- a/packages/sdk/metadata-claims/src/metadata.test.ts +++ b/packages/sdk/metadata-claims/src/metadata.test.ts @@ -91,7 +91,7 @@ testWithAnvilL1('Metadata', (web3) => { } }) - it('throws an error while trying to add a ATTESTAION_SERVICE_URL claim ', async () => { + it('throws an error while trying to add a ATTESTATION_SERVICE_URL claim ', async () => { const metadata = IdentityMetadataWrapper.fromEmpty(address) const claim = { @@ -104,4 +104,31 @@ testWithAnvilL1('Metadata', (web3) => { metadata.addClaim(claim as Claim, NativeSigner(kit.connection.sign, address)) ).rejects.toThrow('ATTESTATION_SERVICE_URL claims are not supported') }) + + it('allows to add a new valid claim and hashes it even if the existing claims contains deprecated ATTESTATION_SERVICE_URL', async () => { + const metadata = await IdentityMetadataWrapper.fromRawString( + await kit.contracts.getAccounts(), + `{ + "claims": [ + { + "url": "https://example.com/attestations", + "timestamp": 1733488714, + "type": "ATTESTATION_SERVICE_URL" + } + ], + "meta": { + "address": "0x5409ED021D9299bf6814279A6A1411A7e866A631", + "signature": "0x48b156db90446fcc0587575ad4913c40184cae119ef40e17652c66641f6fef4611d4be7b7940d36b46ac8803ba26ea608e6009c12bf9361e2e149fee33ecbbf11c" + } + }` + ) + + await expect( + metadata.addClaim(createNameClaim('Test name'), NativeSigner(kit.connection.sign, address)) + ).resolves.toMatchObject({ + // Not checking timestamp here on purpose + name: 'Test name', + type: 'NAME', + }) + }) }) diff --git a/packages/sdk/metadata-claims/src/metadata.ts b/packages/sdk/metadata-claims/src/metadata.ts index df8ea94a2..0ba412cea 100644 --- a/packages/sdk/metadata-claims/src/metadata.ts +++ b/packages/sdk/metadata-claims/src/metadata.ts @@ -199,6 +199,7 @@ export class IdentityMetadataWrapper { if (existingClaims.length > 0) { return existingClaims[0] } + break } case ClaimTypes.ATTESTATION_SERVICE_URL: { throw new Error('ATTESTATION_SERVICE_URL claims are not supported') diff --git a/packages/sdk/metadata-claims/src/types.ts b/packages/sdk/metadata-claims/src/types.ts index 48560d664..1bb2d6da7 100644 --- a/packages/sdk/metadata-claims/src/types.ts +++ b/packages/sdk/metadata-claims/src/types.ts @@ -24,7 +24,7 @@ export enum ClaimTypes { } export const VERIFIABLE_CLAIM_TYPES = [ClaimTypes.KEYBASE, ClaimTypes.ACCOUNT, ClaimTypes.DOMAIN] -export const SINGULAR_CLAIM_TYPES = [ClaimTypes.NAME, ClaimTypes.ATTESTATION_SERVICE_URL] +export const SINGULAR_CLAIM_TYPES = [ClaimTypes.NAME] export type AccountSignerGetters = { isAccount: (address: Address) => Promise