Skip to content

Commit

Permalink
Add encoding for name schema args
Browse files Browse the repository at this point in the history
  • Loading branch information
motechFR committed Nov 7, 2024
1 parent b4afedc commit 07e2bd2
Showing 1 changed file with 17 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/lib/protocol/easSchemas/constants.ts
Original file line number Diff line number Diff line change
@@ -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}`;
}

0 comments on commit 07e2bd2

Please sign in to comment.