From 07e2bd2748d532d34b35671f074ba610eba4aaf6 Mon Sep 17 00:00:00 2001 From: motechFR Date: Thu, 7 Nov 2024 14:58:49 +0200 Subject: [PATCH] Add encoding for name schema args --- src/lib/protocol/easSchemas/constants.ts | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/src/lib/protocol/easSchemas/constants.ts b/src/lib/protocol/easSchemas/constants.ts index f7d9b242..6d24e09f 100644 --- a/src/lib/protocol/easSchemas/constants.ts +++ b/src/lib/protocol/easSchemas/constants.ts @@ -1,8 +1,23 @@ -import { getSchemaUID } from '@ethereum-attestation-service/eas-sdk'; +import { getSchemaUID, SchemaEncoder } from '@ethereum-attestation-service/eas-sdk'; export const NULL_EAS_REF_UID = '0x0000000000000000000000000000000000000000000000000000000000000000'; export const NULL_EVM_ADDRESS = '0x0000000000000000000000000000000000000000'; +// This allows us to encode the schemaId and name of a name schema attestation // Obtained from https://github.com/ethereum-attestation-service/eas-contracts/blob/558250dae4cb434859b1ac3b6d32833c6448be21/deploy/scripts/000004-name-initial-schemas.ts#L10C1-L11C1 -export const NAME_SCHEMA_UID = getSchemaUID('bytes32 schemaId,string name', NULL_EVM_ADDRESS, true); +export const NAME_SCHEMA_UID = getSchemaUID('bytes32 schemaId,string name', NULL_EVM_ADDRESS, true) as `0x${string}`; + +export type NameSchemaAttestation = { + schemaId: `0x${string}`; + name: string; +}; + +export function encodeNameSchemaAttestation({ name, schemaId }: NameSchemaAttestation): `0x${string}` { + const encoder = new SchemaEncoder(NAME_SCHEMA_UID); + + return encoder.encodeData([ + { name: 'schemaId', type: 'bytes32', value: schemaId }, + { name: 'name', type: 'string', value: name } + ]) as `0x${string}`; +}