@settlemint/sdk-eas 2.2.2-prda687784 → 2.2.2-prdc6e1d84
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/eas.cjs +1 -1
- package/dist/eas.cjs.map +1 -1
- package/dist/eas.d.cts +45 -172
- package/dist/eas.d.ts +45 -172
- package/dist/eas.mjs +1 -1
- package/dist/eas.mjs.map +1 -1
- package/package.json +5 -2
package/dist/eas.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var
|
|
1
|
+
'use strict';var easSdk=require('@ethereum-attestation-service/eas-sdk'),validation=require('@settlemint/sdk-utils/validation'),sdkViem=require('@settlemint/sdk-viem'),zod=require('zod'),ethers=require('ethers');var u=zod.z.object({schemaRegistryAddress:zod.z.string().min(1),attestationAddress:zod.z.string().min(1),...zod.z.object({accessToken:zod.z.string().min(1),chainId:zod.z.string().min(1),chainName:zod.z.string().min(1),rpcUrl:zod.z.string().min(1)}).shape});function f(e){let{chain:t,transport:r}=e;if(!t)throw new Error("Chain is required");let a={chainId:t.id,name:t.name,ensAddress:t.contracts?.ensRegistry?.address};if(r.type==="fallback"){let s=r.transports.map(({value:i})=>{if(!i?.url)return null;try{return new ethers.JsonRpcProvider(i.url,a)}catch{return null}}).filter(i=>i!=null);if(s.length===0)throw new Error("No valid RPC URLs found");return s[0]}return new ethers.JsonRpcProvider(r.url,a)}function g(e){let{account:t,chain:r,transport:a}=e;if(!r)throw new Error("Chain is required");if(!t)throw new Error("Account is required");let s={chainId:r.id,name:r.name,ensAddress:r.contracts?.ensRegistry?.address},i=new ethers.JsonRpcProvider(a.url,s),c=t.privateKey;if(!c||typeof c!="string")throw new Error("Private key is required and must be a string");return new ethers.Wallet(c,i)}var p={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function v(e){if(!e)throw new Error("Field name cannot be empty");if(e.includes(" "))throw new Error("Field name cannot contain spaces");if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))throw new Error("Field name must start with a letter or underscore and contain only alphanumeric characters and underscores")}function E(e){if(!(e in p))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(p).join(", ")}`)}function h(e){if(!e||e.length===0)throw new Error("Schema must have at least one field");let t=new Set;for(let r of e){if(v(r.name),E(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function y(e){return h(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function q(e){validation.validate(u,e);let t=sdkViem.getPublicClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl}),r=sdkViem.getWalletClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl})(),a=f(t),s=g(r),i=new easSdk.SchemaRegistry(e.schemaRegistryAddress);i.connect(s);async function c(o){h(o.fields);let l=y(o.fields);try{await a.getNetwork();let m=await i.register({schema:l,resolverAddress:o.resolverAddress,revocable:o.revocable});return await m.wait(),m.toString()}catch(m){throw new Error(`Failed to register schema: ${m.message}`)}}async function w(o){try{return await a.getNetwork(),(await i.getSchema({uid:o})).toString()}catch(l){throw new Error(`Failed to get schema: ${l.message}`)}}return {registerSchema:c,getSchema:w}}exports.createEASClient=q;//# sourceMappingURL=eas.cjs.map
|
|
2
2
|
//# sourceMappingURL=eas.cjs.map
|
package/dist/eas.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema.ts","../src/eas.ts"],"names":["EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","validateEthereumAddress","address","isAddress","registerSchema","options","resolverAddress","revocable","schemaString","createEASClient"],"mappings":"sCAcO,IAAMA,CAAkB,CAAA,CAC7B,MAAQ,CAAA,QAAA,CACR,OAAS,CAAA,SAAA,CACT,IAAM,CAAA,MAAA,CACN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uB,EACrC,CAAA,CAEA,SAAY,EAAA,CACV,OAAQ,CAAA,GAAA,CAAI,sBAAsB,EACpC,CAAA,CAEA,eAAkB,EAAA,CAChB,OAAQ,CAAA,GAAA,CAAI,4BAA4B,EAC1C,CACF,CACF","file":"eas.cjs","sourcesContent":["/**\n * Supported EAS schema field types.\n * Maps user-friendly type names to EAS-compatible type strings.\n * @example\n * ```ts\n * import { EAS_FIELD_TYPES } from '@settlemint/sdk-eas';\n *\n * // Use in type definitions\n * type MyFieldType = keyof typeof EAS_FIELD_TYPES;\n *\n * // Check if a type is supported\n * const isValidType = \"string\" in EAS_FIELD_TYPES;\n * ```\n */\nexport const EAS_FIELD_TYPES = {\n string: \"string\",\n address: \"address\",\n bool: \"bool\",\n bytes: \"bytes\",\n bytes32: \"bytes32\",\n uint256: \"uint256\",\n int256: \"int256\",\n uint8: \"uint8\",\n int8: \"int8\",\n} as const;\n\n/**\n * Type representing all valid EAS field types.\n */\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Interface for defining a schema field.\n * @example\n * ```ts\n * import { SchemaField } from '@settlemint/sdk-eas';\n *\n * const field: SchemaField = {\n * name: \"userAddress\",\n * type: \"address\",\n * description: \"The Ethereum address of the user\"\n * };\n * ```\n */\nexport interface SchemaField {\n /** The name of the field */\n name: string;\n /** The type of the field */\n type: EASFieldType;\n /** Optional description of the field */\n description?: string;\n}\n\n/**\n * Validates a schema field name.\n * @param name - The field name to validate\n * @throws Error if the name is invalid\n * @example\n * ```ts\n * import { validateFieldName } from '@settlemint/sdk-eas';\n *\n * // Valid names\n * validateFieldName(\"userAddress\"); // OK\n * validateFieldName(\"user_address\"); // OK\n *\n * // Invalid names\n * validateFieldName(\"user address\"); // Throws: \"Field name cannot contain spaces\"\n * validateFieldName(\"123user\"); // Throws: \"Field name must start with a letter or underscore\"\n * ```\n */\nexport function validateFieldName(name: string): void {\n if (!name) {\n throw new Error(\"Field name cannot be empty\");\n }\n if (name.includes(\" \")) {\n throw new Error(\"Field name cannot contain spaces\");\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n throw new Error(\n \"Field name must start with a letter or underscore and contain only alphanumeric characters and underscores\",\n );\n }\n}\n\n/**\n * Validates a schema field type.\n * @param type - The field type to validate\n * @throws Error if the type is invalid\n * @example\n * ```ts\n * import { validateFieldType } from '@settlemint/sdk-eas';\n *\n * // Valid types\n * validateFieldType(\"string\"); // OK\n * validateFieldType(\"address\"); // OK\n *\n * // Invalid types\n * validateFieldType(\"invalidType\"); // Throws: \"Invalid field type: invalidType\"\n * ```\n */\nexport function validateFieldType(type: string): asserts type is EASFieldType {\n if (!(type in EAS_FIELD_TYPES)) {\n throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(\", \")}`);\n }\n}\n\n/**\n * Validates an array of schema fields.\n * @param fields - The fields to validate\n * @throws Error if any field is invalid\n * @example\n * ```ts\n * import { validateSchemaFields, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ];\n *\n * validateSchemaFields(fields); // OK\n *\n * // Invalid fields\n * validateSchemaFields([]); // Throws: \"Schema must have at least one field\"\n * validateSchemaFields([\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"userAddress\", type: \"uint8\" }\n * ]); // Throws: \"Duplicate field name: userAddress\"\n * ```\n */\nexport function validateSchemaFields(fields: SchemaField[]): void {\n if (!fields || fields.length === 0) {\n throw new Error(\"Schema must have at least one field\");\n }\n\n const seenNames = new Set<string>();\n for (const field of fields) {\n validateFieldName(field.name);\n validateFieldType(field.type);\n\n if (seenNames.has(field.name)) {\n throw new Error(`Duplicate field name: ${field.name}`);\n }\n seenNames.add(field.name);\n }\n}\n\n/**\n * Builds an EAS schema string from an array of fields.\n * @param fields - The fields to include in the schema\n * @returns The EAS-compatible schema string\n * @throws Error if any field is invalid\n * @example\n * ```ts\n * import { buildSchemaString, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" },\n * { name: \"isActive\", type: \"bool\" }\n * ];\n *\n * const schemaString = buildSchemaString(fields);\n * // Result: \"address userAddress, uint8 age, bool isActive\"\n * ```\n */\nexport function buildSchemaString(fields: SchemaField[]): string {\n validateSchemaFields(fields);\n return fields.map((field) => `${field.type} ${field.name}`).join(\", \");\n}\n\n/**\n * Options for registering a schema.\n * @example\n * ```ts\n * import { RegisterSchemaOptions, SchemaField } from '@settlemint/sdk-eas';\n *\n * const options: RegisterSchemaOptions = {\n * fields: [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ],\n * resolverAddress: \"0x1234567890123456789012345678901234567890\",\n * revocable: true\n * };\n * ```\n */\nexport interface RegisterSchemaOptions {\n /** The fields that make up the schema */\n fields: SchemaField[];\n /** The Ethereum address of the resolver */\n resolverAddress: string;\n /** Whether attestations using this schema can be revoked */\n revocable: boolean;\n}\n\nimport { isAddress } from \"viem\";\n\n/**\n * Validates an Ethereum address.\n * @param address - The address to validate\n * @throws Error if the address is invalid\n * @example\n * ```ts\n * import { validateEthereumAddress } from '@settlemint/sdk-eas';\n *\n * // Valid address\n * validateEthereumAddress(\"0x1234567890123456789012345678901234567890\"); // OK\n *\n * // Invalid addresses\n * validateEthereumAddress(\"0x123\"); // Throws: \"Invalid Ethereum address format\"\n * validateEthereumAddress(\"\"); // Throws: \"Resolver address cannot be empty\"\n * ```\n */\nexport function validateEthereumAddress(address: string): void {\n if (!address) {\n throw new Error(\"Resolver address cannot be empty\");\n }\n if (!isAddress(address)) {\n throw new Error(\"Invalid Ethereum address format\");\n }\n}\n\n/**\n * Registers a new schema with EAS.\n * @param options - The schema registration options\n * @returns A promise that resolves to the schema UID\n * @throws Error if the schema registration fails\n * @example\n * ```ts\n * import { registerSchema, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ];\n *\n * const schemaUID = await registerSchema({\n * fields,\n * resolverAddress: \"0x1234567890123456789012345678901234567890\",\n * revocable: true\n * });\n *\n * console.log(`Schema registered with UID: ${schemaUID}`);\n * ```\n */\nexport async function registerSchema(options: RegisterSchemaOptions): Promise<string> {\n const { fields, resolverAddress, revocable } = options;\n\n // Validate the schema fields\n validateSchemaFields(fields);\n\n // Validate the resolver address\n validateEthereumAddress(resolverAddress);\n\n // Build the schema string\n const schemaString = buildSchemaString(fields);\n\n // TODO: Implement actual EAS SDK registration\n // This is a placeholder that will be replaced with actual EAS SDK integration\n console.log(`[EAS] Registering schema: ${schemaString}`);\n console.log(`[EAS] Resolver: ${resolverAddress}`);\n console.log(`[EAS] Revocable: ${revocable}`);\n\n // Return a mock UID for now\n return `0x${\"0\".repeat(64)}`;\n}\n","export * from \"./schema.js\";\n\nexport function createEASClient() {\n return {\n submitAttestation() {\n console.log(\"[EAS] Submitting attestation\");\n },\n\n parseAttestation() {\n console.log(\"[EAS] Parsing attestation\");\n },\n\n createSchema() {\n console.log(\"[EAS] Creating schema\");\n },\n\n getSchema() {\n console.log(\"[EAS] Getting schema\");\n },\n\n getAttestations() {\n console.log(\"[EAS] Getting attestations\");\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client-options.schema.ts","../src/ethers-adapter.ts","../src/types.ts","../src/validation.ts","../src/eas.ts"],"names":["ClientOptionsSchema","z","publicClientToProvider","client","chain","transport","network","providers","value","JsonRpcProvider","provider","walletClientToSigner","account","privateKey","Wallet","EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","createEASClient","options","validate","publicClient","getPublicClient","walletClient","getWalletClient","wallet","schemaRegistry","SchemaRegistry","registerSchema","schema","tx","error","getSchema","uid"],"mappings":"oNAGO,IAAMA,CAAAA,CAAsBC,KAAE,CA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B,CAASC,MAAAA,CAAAA,CAAO,CACd,MAAM,IAAI,KAAA,CAAM,8BAA+BA,CAAgB,CAAA,OAAO,CAAE,CAAA,CAC1E,CACF,CAEA,eAAeC,CAAAA,CAAUC,EAA8B,CACrD,GAAI,CAEF,OAAA,MAAM9B,CAAS,CAAA,UAAA,EAEA,CAAA,CAAA,MAAMuB,EAAe,SAAU,CAAA,CAAE,GAAAO,CAAAA,CAAI,CAAC,CAAA,EACvC,QAAS,EACzB,OAASF,CAAO,CAAA,CACd,MAAM,IAAI,KAAM,CAAA,CAAA,sBAAA,EAA0BA,CAAgB,CAAA,OAAO,EAAE,CACrE,CACF,CAEA,OAAO,CACL,cAAA,CAAAH,CACA,CAAA,SAAA,CAAAI,CACF,CACF","file":"eas.cjs","sourcesContent":["import type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { z } from \"zod\";\n\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().min(1),\n attestationAddress: z.string().min(1),\n ...z.object({\n accessToken: z.string().min(1),\n chainId: z.string().min(1),\n chainName: z.string().min(1),\n rpcUrl: z.string().min(1),\n }).shape,\n});\n\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema> &\n Pick<ViemClientOptions, \"accessToken\" | \"chainId\" | \"chainName\" | \"rpcUrl\">;\n","import { JsonRpcProvider, type Provider, Wallet } from \"ethers\";\nimport type { PublicClient, Transport, WalletClient } from \"viem\";\n\n/**\n * Converts a viem PublicClient to an ethers JsonRpcProvider\n */\nexport function publicClientToProvider(client: PublicClient): Provider {\n const { chain, transport } = client;\n if (!chain) throw new Error(\"Chain is required\");\n\n const network = {\n chainId: chain.id,\n name: chain.name,\n ensAddress: chain.contracts?.ensRegistry?.address,\n };\n\n if (transport.type === \"fallback\") {\n const providers = (transport.transports as ReturnType<Transport>[])\n .map(({ value }) => {\n if (!value?.url) return null;\n try {\n return new JsonRpcProvider(value.url, network);\n } catch {\n return null;\n }\n })\n .filter((provider): provider is JsonRpcProvider => provider != null);\n\n if (providers.length === 0) throw new Error(\"No valid RPC URLs found\");\n // We know providers[0] exists because we checked length > 0\n return providers[0] as Provider;\n }\n\n return new JsonRpcProvider(transport.url, network);\n}\n\n/**\n * Converts a viem WalletClient to an ethers Wallet\n */\nexport function walletClientToSigner(client: WalletClient): Wallet {\n const { account, chain, transport } = client;\n if (!chain) throw new Error(\"Chain is required\");\n if (!account) throw new Error(\"Account is required\");\n\n const network = {\n chainId: chain.id,\n name: chain.name,\n ensAddress: chain.contracts?.ensRegistry?.address,\n };\n\n const provider = new JsonRpcProvider(transport.url, network);\n\n // For viem, we need to get the private key from the account\n const privateKey = (account as { privateKey?: string }).privateKey;\n if (!privateKey || typeof privateKey !== \"string\") {\n throw new Error(\"Private key is required and must be a string\");\n }\n\n return new Wallet(privateKey, provider);\n}\n","export const EAS_FIELD_TYPES = {\n string: \"string\",\n address: \"address\",\n bool: \"bool\",\n bytes: \"bytes\",\n bytes32: \"bytes32\",\n uint256: \"uint256\",\n int256: \"int256\",\n uint8: \"uint8\",\n int8: \"int8\",\n} as const;\n\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\nexport interface SchemaField {\n name: string;\n type: EASFieldType;\n description?: string;\n}\n\nexport interface RegisterSchemaOptions {\n fields: SchemaField[];\n resolverAddress: string;\n revocable: boolean;\n}\n","import { type EASFieldType, EAS_FIELD_TYPES, type SchemaField } from \"./types.js\";\n\nexport function validateFieldName(name: string): void {\n if (!name) {\n throw new Error(\"Field name cannot be empty\");\n }\n if (name.includes(\" \")) {\n throw new Error(\"Field name cannot contain spaces\");\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n throw new Error(\n \"Field name must start with a letter or underscore and contain only alphanumeric characters and underscores\",\n );\n }\n}\n\nexport function validateFieldType(type: string): asserts type is EASFieldType {\n if (!(type in EAS_FIELD_TYPES)) {\n throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(\", \")}`);\n }\n}\n\nexport function validateSchemaFields(fields: SchemaField[]): void {\n if (!fields || fields.length === 0) {\n throw new Error(\"Schema must have at least one field\");\n }\n\n const seenNames = new Set<string>();\n for (const field of fields) {\n validateFieldName(field.name);\n validateFieldType(field.type);\n\n if (seenNames.has(field.name)) {\n throw new Error(`Duplicate field name: ${field.name}`);\n }\n seenNames.add(field.name);\n }\n}\n\nexport function buildSchemaString(fields: SchemaField[]): string {\n validateSchemaFields(fields);\n return fields.map((field) => `${field.type} ${field.name}`).join(\", \");\n}\n","import { SchemaRegistry } from \"@ethereum-attestation-service/eas-sdk\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { getPublicClient, getWalletClient } from \"@settlemint/sdk-viem\";\nimport type { PublicClient } from \"viem\";\nimport { type ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nimport { publicClientToProvider, walletClientToSigner } from \"./ethers-adapter.js\";\nimport type { RegisterSchemaOptions } from \"./types.js\";\nimport { buildSchemaString, validateSchemaFields } from \"./validation.js\";\n\n/**\n * Creates an EAS client for interacting with the Ethereum Attestation Service.\n *\n * @param options - Configuration options for the client\n * @returns An object containing the EAS client instance\n * @throws Will throw an error if the options fail validation\n *\n * @example\n * ```ts\n * import { createEASClient } from '@settlemint/sdk-eas';\n *\n * const client = createEASClient({\n * schemaRegistryAddress: \"0x1234567890123456789012345678901234567890\",\n * attestationAddress: \"0x1234567890123456789012345678901234567890\",\n * accessToken: \"your-access-token\",\n * chainId: \"1\",\n * chainName: \"Ethereum\",\n * rpcUrl: \"http://localhost:8545\"\n * });\n * ```\n */\nexport function createEASClient(options: ClientOptions) {\n validate(ClientOptionsSchema, options);\n\n // Create viem clients\n const publicClient = getPublicClient({\n accessToken: options.accessToken,\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n }) as PublicClient;\n\n const walletClient = getWalletClient({\n accessToken: options.accessToken,\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n })();\n\n // Convert to ethers for EAS SDK\n const provider = publicClientToProvider(publicClient);\n const wallet = walletClientToSigner(walletClient);\n\n const schemaRegistry = new SchemaRegistry(options.schemaRegistryAddress);\n schemaRegistry.connect(wallet);\n\n async function registerSchema(options: RegisterSchemaOptions): Promise<string> {\n validateSchemaFields(options.fields);\n const schema = buildSchemaString(options.fields);\n\n try {\n // Check if the provider is available\n await provider.getNetwork();\n\n const tx = await schemaRegistry.register({\n schema,\n resolverAddress: options.resolverAddress,\n revocable: options.revocable,\n });\n\n await tx.wait();\n return tx.toString();\n } catch (error) {\n throw new Error(`Failed to register schema: ${(error as Error).message}`);\n }\n }\n\n async function getSchema(uid: string): Promise<string> {\n try {\n // Check if the provider is available\n await provider.getNetwork();\n\n const schema = await schemaRegistry.getSchema({ uid });\n return schema.toString();\n } catch (error) {\n throw new Error(`Failed to get schema: ${(error as Error).message}`);\n }\n }\n\n return {\n registerSchema,\n getSchema,\n };\n}\n"]}
|
package/dist/eas.d.cts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
5
|
+
accessToken: z.ZodString;
|
|
6
|
+
chainId: z.ZodString;
|
|
7
|
+
chainName: z.ZodString;
|
|
8
|
+
rpcUrl: z.ZodString;
|
|
9
|
+
schemaRegistryAddress: z.ZodString;
|
|
10
|
+
attestationAddress: z.ZodString;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
schemaRegistryAddress: string;
|
|
13
|
+
attestationAddress: string;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
chainId: string;
|
|
16
|
+
chainName: string;
|
|
17
|
+
rpcUrl: string;
|
|
18
|
+
}, {
|
|
19
|
+
schemaRegistryAddress: string;
|
|
20
|
+
attestationAddress: string;
|
|
21
|
+
accessToken: string;
|
|
22
|
+
chainId: string;
|
|
23
|
+
chainName: string;
|
|
24
|
+
rpcUrl: string;
|
|
25
|
+
}>;
|
|
26
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema> & Pick<ClientOptions$1, "accessToken" | "chainId" | "chainName" | "rpcUrl">;
|
|
27
|
+
|
|
15
28
|
declare const EAS_FIELD_TYPES: {
|
|
16
29
|
readonly string: "string";
|
|
17
30
|
readonly address: "address";
|
|
@@ -23,182 +36,42 @@ declare const EAS_FIELD_TYPES: {
|
|
|
23
36
|
readonly uint8: "uint8";
|
|
24
37
|
readonly int8: "int8";
|
|
25
38
|
};
|
|
26
|
-
/**
|
|
27
|
-
* Type representing all valid EAS field types.
|
|
28
|
-
*/
|
|
29
39
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
30
|
-
/**
|
|
31
|
-
* Interface for defining a schema field.
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* import { SchemaField } from '@settlemint/sdk-eas';
|
|
35
|
-
*
|
|
36
|
-
* const field: SchemaField = {
|
|
37
|
-
* name: "userAddress",
|
|
38
|
-
* type: "address",
|
|
39
|
-
* description: "The Ethereum address of the user"
|
|
40
|
-
* };
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
40
|
interface SchemaField {
|
|
44
|
-
/** The name of the field */
|
|
45
41
|
name: string;
|
|
46
|
-
/** The type of the field */
|
|
47
42
|
type: EASFieldType;
|
|
48
|
-
/** Optional description of the field */
|
|
49
43
|
description?: string;
|
|
50
44
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Validates a schema field name.
|
|
53
|
-
* @param name - The field name to validate
|
|
54
|
-
* @throws Error if the name is invalid
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* import { validateFieldName } from '@settlemint/sdk-eas';
|
|
58
|
-
*
|
|
59
|
-
* // Valid names
|
|
60
|
-
* validateFieldName("userAddress"); // OK
|
|
61
|
-
* validateFieldName("user_address"); // OK
|
|
62
|
-
*
|
|
63
|
-
* // Invalid names
|
|
64
|
-
* validateFieldName("user address"); // Throws: "Field name cannot contain spaces"
|
|
65
|
-
* validateFieldName("123user"); // Throws: "Field name must start with a letter or underscore"
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function validateFieldName(name: string): void;
|
|
69
|
-
/**
|
|
70
|
-
* Validates a schema field type.
|
|
71
|
-
* @param type - The field type to validate
|
|
72
|
-
* @throws Error if the type is invalid
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* import { validateFieldType } from '@settlemint/sdk-eas';
|
|
76
|
-
*
|
|
77
|
-
* // Valid types
|
|
78
|
-
* validateFieldType("string"); // OK
|
|
79
|
-
* validateFieldType("address"); // OK
|
|
80
|
-
*
|
|
81
|
-
* // Invalid types
|
|
82
|
-
* validateFieldType("invalidType"); // Throws: "Invalid field type: invalidType"
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
declare function validateFieldType(type: string): asserts type is EASFieldType;
|
|
86
|
-
/**
|
|
87
|
-
* Validates an array of schema fields.
|
|
88
|
-
* @param fields - The fields to validate
|
|
89
|
-
* @throws Error if any field is invalid
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { validateSchemaFields, SchemaField } from '@settlemint/sdk-eas';
|
|
93
|
-
*
|
|
94
|
-
* const fields: SchemaField[] = [
|
|
95
|
-
* { name: "userAddress", type: "address" },
|
|
96
|
-
* { name: "age", type: "uint8" }
|
|
97
|
-
* ];
|
|
98
|
-
*
|
|
99
|
-
* validateSchemaFields(fields); // OK
|
|
100
|
-
*
|
|
101
|
-
* // Invalid fields
|
|
102
|
-
* validateSchemaFields([]); // Throws: "Schema must have at least one field"
|
|
103
|
-
* validateSchemaFields([
|
|
104
|
-
* { name: "userAddress", type: "address" },
|
|
105
|
-
* { name: "userAddress", type: "uint8" }
|
|
106
|
-
* ]); // Throws: "Duplicate field name: userAddress"
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
declare function validateSchemaFields(fields: SchemaField[]): void;
|
|
110
|
-
/**
|
|
111
|
-
* Builds an EAS schema string from an array of fields.
|
|
112
|
-
* @param fields - The fields to include in the schema
|
|
113
|
-
* @returns The EAS-compatible schema string
|
|
114
|
-
* @throws Error if any field is invalid
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* import { buildSchemaString, SchemaField } from '@settlemint/sdk-eas';
|
|
118
|
-
*
|
|
119
|
-
* const fields: SchemaField[] = [
|
|
120
|
-
* { name: "userAddress", type: "address" },
|
|
121
|
-
* { name: "age", type: "uint8" },
|
|
122
|
-
* { name: "isActive", type: "bool" }
|
|
123
|
-
* ];
|
|
124
|
-
*
|
|
125
|
-
* const schemaString = buildSchemaString(fields);
|
|
126
|
-
* // Result: "address userAddress, uint8 age, bool isActive"
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
declare function buildSchemaString(fields: SchemaField[]): string;
|
|
130
|
-
/**
|
|
131
|
-
* Options for registering a schema.
|
|
132
|
-
* @example
|
|
133
|
-
* ```ts
|
|
134
|
-
* import { RegisterSchemaOptions, SchemaField } from '@settlemint/sdk-eas';
|
|
135
|
-
*
|
|
136
|
-
* const options: RegisterSchemaOptions = {
|
|
137
|
-
* fields: [
|
|
138
|
-
* { name: "userAddress", type: "address" },
|
|
139
|
-
* { name: "age", type: "uint8" }
|
|
140
|
-
* ],
|
|
141
|
-
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
142
|
-
* revocable: true
|
|
143
|
-
* };
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
45
|
interface RegisterSchemaOptions {
|
|
147
|
-
/** The fields that make up the schema */
|
|
148
46
|
fields: SchemaField[];
|
|
149
|
-
/** The Ethereum address of the resolver */
|
|
150
47
|
resolverAddress: string;
|
|
151
|
-
/** Whether attestations using this schema can be revoked */
|
|
152
48
|
revocable: boolean;
|
|
153
49
|
}
|
|
50
|
+
|
|
154
51
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @param address - The address to validate
|
|
157
|
-
* @throws Error if the address is invalid
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* import { validateEthereumAddress } from '@settlemint/sdk-eas';
|
|
52
|
+
* Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
161
53
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
54
|
+
* @param options - Configuration options for the client
|
|
55
|
+
* @returns An object containing the EAS client instance
|
|
56
|
+
* @throws Will throw an error if the options fail validation
|
|
164
57
|
*
|
|
165
|
-
* // Invalid addresses
|
|
166
|
-
* validateEthereumAddress("0x123"); // Throws: "Invalid Ethereum address format"
|
|
167
|
-
* validateEthereumAddress(""); // Throws: "Resolver address cannot be empty"
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
declare function validateEthereumAddress(address: string): void;
|
|
171
|
-
/**
|
|
172
|
-
* Registers a new schema with EAS.
|
|
173
|
-
* @param options - The schema registration options
|
|
174
|
-
* @returns A promise that resolves to the schema UID
|
|
175
|
-
* @throws Error if the schema registration fails
|
|
176
58
|
* @example
|
|
177
59
|
* ```ts
|
|
178
|
-
* import {
|
|
179
|
-
*
|
|
180
|
-
* const
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
188
|
-
* revocable: true
|
|
60
|
+
* import { createEASClient } from '@settlemint/sdk-eas';
|
|
61
|
+
*
|
|
62
|
+
* const client = createEASClient({
|
|
63
|
+
* schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
64
|
+
* attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
65
|
+
* accessToken: "your-access-token",
|
|
66
|
+
* chainId: "1",
|
|
67
|
+
* chainName: "Ethereum",
|
|
68
|
+
* rpcUrl: "http://localhost:8545"
|
|
189
69
|
* });
|
|
190
|
-
*
|
|
191
|
-
* console.log(`Schema registered with UID: ${schemaUID}`);
|
|
192
70
|
* ```
|
|
193
71
|
*/
|
|
194
|
-
declare function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
submitAttestation(): void;
|
|
198
|
-
parseAttestation(): void;
|
|
199
|
-
createSchema(): void;
|
|
200
|
-
getSchema(): void;
|
|
201
|
-
getAttestations(): void;
|
|
72
|
+
declare function createEASClient(options: ClientOptions): {
|
|
73
|
+
registerSchema: (options: RegisterSchemaOptions) => Promise<string>;
|
|
74
|
+
getSchema: (uid: string) => Promise<string>;
|
|
202
75
|
};
|
|
203
76
|
|
|
204
|
-
export {
|
|
77
|
+
export { createEASClient };
|
package/dist/eas.d.ts
CHANGED
|
@@ -1,17 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
|
+
import { z } from 'zod';
|
|
3
|
+
|
|
4
|
+
declare const ClientOptionsSchema: z.ZodObject<{
|
|
5
|
+
accessToken: z.ZodString;
|
|
6
|
+
chainId: z.ZodString;
|
|
7
|
+
chainName: z.ZodString;
|
|
8
|
+
rpcUrl: z.ZodString;
|
|
9
|
+
schemaRegistryAddress: z.ZodString;
|
|
10
|
+
attestationAddress: z.ZodString;
|
|
11
|
+
}, "strip", z.ZodTypeAny, {
|
|
12
|
+
schemaRegistryAddress: string;
|
|
13
|
+
attestationAddress: string;
|
|
14
|
+
accessToken: string;
|
|
15
|
+
chainId: string;
|
|
16
|
+
chainName: string;
|
|
17
|
+
rpcUrl: string;
|
|
18
|
+
}, {
|
|
19
|
+
schemaRegistryAddress: string;
|
|
20
|
+
attestationAddress: string;
|
|
21
|
+
accessToken: string;
|
|
22
|
+
chainId: string;
|
|
23
|
+
chainName: string;
|
|
24
|
+
rpcUrl: string;
|
|
25
|
+
}>;
|
|
26
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema> & Pick<ClientOptions$1, "accessToken" | "chainId" | "chainName" | "rpcUrl">;
|
|
27
|
+
|
|
15
28
|
declare const EAS_FIELD_TYPES: {
|
|
16
29
|
readonly string: "string";
|
|
17
30
|
readonly address: "address";
|
|
@@ -23,182 +36,42 @@ declare const EAS_FIELD_TYPES: {
|
|
|
23
36
|
readonly uint8: "uint8";
|
|
24
37
|
readonly int8: "int8";
|
|
25
38
|
};
|
|
26
|
-
/**
|
|
27
|
-
* Type representing all valid EAS field types.
|
|
28
|
-
*/
|
|
29
39
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
30
|
-
/**
|
|
31
|
-
* Interface for defining a schema field.
|
|
32
|
-
* @example
|
|
33
|
-
* ```ts
|
|
34
|
-
* import { SchemaField } from '@settlemint/sdk-eas';
|
|
35
|
-
*
|
|
36
|
-
* const field: SchemaField = {
|
|
37
|
-
* name: "userAddress",
|
|
38
|
-
* type: "address",
|
|
39
|
-
* description: "The Ethereum address of the user"
|
|
40
|
-
* };
|
|
41
|
-
* ```
|
|
42
|
-
*/
|
|
43
40
|
interface SchemaField {
|
|
44
|
-
/** The name of the field */
|
|
45
41
|
name: string;
|
|
46
|
-
/** The type of the field */
|
|
47
42
|
type: EASFieldType;
|
|
48
|
-
/** Optional description of the field */
|
|
49
43
|
description?: string;
|
|
50
44
|
}
|
|
51
|
-
/**
|
|
52
|
-
* Validates a schema field name.
|
|
53
|
-
* @param name - The field name to validate
|
|
54
|
-
* @throws Error if the name is invalid
|
|
55
|
-
* @example
|
|
56
|
-
* ```ts
|
|
57
|
-
* import { validateFieldName } from '@settlemint/sdk-eas';
|
|
58
|
-
*
|
|
59
|
-
* // Valid names
|
|
60
|
-
* validateFieldName("userAddress"); // OK
|
|
61
|
-
* validateFieldName("user_address"); // OK
|
|
62
|
-
*
|
|
63
|
-
* // Invalid names
|
|
64
|
-
* validateFieldName("user address"); // Throws: "Field name cannot contain spaces"
|
|
65
|
-
* validateFieldName("123user"); // Throws: "Field name must start with a letter or underscore"
|
|
66
|
-
* ```
|
|
67
|
-
*/
|
|
68
|
-
declare function validateFieldName(name: string): void;
|
|
69
|
-
/**
|
|
70
|
-
* Validates a schema field type.
|
|
71
|
-
* @param type - The field type to validate
|
|
72
|
-
* @throws Error if the type is invalid
|
|
73
|
-
* @example
|
|
74
|
-
* ```ts
|
|
75
|
-
* import { validateFieldType } from '@settlemint/sdk-eas';
|
|
76
|
-
*
|
|
77
|
-
* // Valid types
|
|
78
|
-
* validateFieldType("string"); // OK
|
|
79
|
-
* validateFieldType("address"); // OK
|
|
80
|
-
*
|
|
81
|
-
* // Invalid types
|
|
82
|
-
* validateFieldType("invalidType"); // Throws: "Invalid field type: invalidType"
|
|
83
|
-
* ```
|
|
84
|
-
*/
|
|
85
|
-
declare function validateFieldType(type: string): asserts type is EASFieldType;
|
|
86
|
-
/**
|
|
87
|
-
* Validates an array of schema fields.
|
|
88
|
-
* @param fields - The fields to validate
|
|
89
|
-
* @throws Error if any field is invalid
|
|
90
|
-
* @example
|
|
91
|
-
* ```ts
|
|
92
|
-
* import { validateSchemaFields, SchemaField } from '@settlemint/sdk-eas';
|
|
93
|
-
*
|
|
94
|
-
* const fields: SchemaField[] = [
|
|
95
|
-
* { name: "userAddress", type: "address" },
|
|
96
|
-
* { name: "age", type: "uint8" }
|
|
97
|
-
* ];
|
|
98
|
-
*
|
|
99
|
-
* validateSchemaFields(fields); // OK
|
|
100
|
-
*
|
|
101
|
-
* // Invalid fields
|
|
102
|
-
* validateSchemaFields([]); // Throws: "Schema must have at least one field"
|
|
103
|
-
* validateSchemaFields([
|
|
104
|
-
* { name: "userAddress", type: "address" },
|
|
105
|
-
* { name: "userAddress", type: "uint8" }
|
|
106
|
-
* ]); // Throws: "Duplicate field name: userAddress"
|
|
107
|
-
* ```
|
|
108
|
-
*/
|
|
109
|
-
declare function validateSchemaFields(fields: SchemaField[]): void;
|
|
110
|
-
/**
|
|
111
|
-
* Builds an EAS schema string from an array of fields.
|
|
112
|
-
* @param fields - The fields to include in the schema
|
|
113
|
-
* @returns The EAS-compatible schema string
|
|
114
|
-
* @throws Error if any field is invalid
|
|
115
|
-
* @example
|
|
116
|
-
* ```ts
|
|
117
|
-
* import { buildSchemaString, SchemaField } from '@settlemint/sdk-eas';
|
|
118
|
-
*
|
|
119
|
-
* const fields: SchemaField[] = [
|
|
120
|
-
* { name: "userAddress", type: "address" },
|
|
121
|
-
* { name: "age", type: "uint8" },
|
|
122
|
-
* { name: "isActive", type: "bool" }
|
|
123
|
-
* ];
|
|
124
|
-
*
|
|
125
|
-
* const schemaString = buildSchemaString(fields);
|
|
126
|
-
* // Result: "address userAddress, uint8 age, bool isActive"
|
|
127
|
-
* ```
|
|
128
|
-
*/
|
|
129
|
-
declare function buildSchemaString(fields: SchemaField[]): string;
|
|
130
|
-
/**
|
|
131
|
-
* Options for registering a schema.
|
|
132
|
-
* @example
|
|
133
|
-
* ```ts
|
|
134
|
-
* import { RegisterSchemaOptions, SchemaField } from '@settlemint/sdk-eas';
|
|
135
|
-
*
|
|
136
|
-
* const options: RegisterSchemaOptions = {
|
|
137
|
-
* fields: [
|
|
138
|
-
* { name: "userAddress", type: "address" },
|
|
139
|
-
* { name: "age", type: "uint8" }
|
|
140
|
-
* ],
|
|
141
|
-
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
142
|
-
* revocable: true
|
|
143
|
-
* };
|
|
144
|
-
* ```
|
|
145
|
-
*/
|
|
146
45
|
interface RegisterSchemaOptions {
|
|
147
|
-
/** The fields that make up the schema */
|
|
148
46
|
fields: SchemaField[];
|
|
149
|
-
/** The Ethereum address of the resolver */
|
|
150
47
|
resolverAddress: string;
|
|
151
|
-
/** Whether attestations using this schema can be revoked */
|
|
152
48
|
revocable: boolean;
|
|
153
49
|
}
|
|
50
|
+
|
|
154
51
|
/**
|
|
155
|
-
*
|
|
156
|
-
* @param address - The address to validate
|
|
157
|
-
* @throws Error if the address is invalid
|
|
158
|
-
* @example
|
|
159
|
-
* ```ts
|
|
160
|
-
* import { validateEthereumAddress } from '@settlemint/sdk-eas';
|
|
52
|
+
* Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
161
53
|
*
|
|
162
|
-
*
|
|
163
|
-
*
|
|
54
|
+
* @param options - Configuration options for the client
|
|
55
|
+
* @returns An object containing the EAS client instance
|
|
56
|
+
* @throws Will throw an error if the options fail validation
|
|
164
57
|
*
|
|
165
|
-
* // Invalid addresses
|
|
166
|
-
* validateEthereumAddress("0x123"); // Throws: "Invalid Ethereum address format"
|
|
167
|
-
* validateEthereumAddress(""); // Throws: "Resolver address cannot be empty"
|
|
168
|
-
* ```
|
|
169
|
-
*/
|
|
170
|
-
declare function validateEthereumAddress(address: string): void;
|
|
171
|
-
/**
|
|
172
|
-
* Registers a new schema with EAS.
|
|
173
|
-
* @param options - The schema registration options
|
|
174
|
-
* @returns A promise that resolves to the schema UID
|
|
175
|
-
* @throws Error if the schema registration fails
|
|
176
58
|
* @example
|
|
177
59
|
* ```ts
|
|
178
|
-
* import {
|
|
179
|
-
*
|
|
180
|
-
* const
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* resolverAddress: "0x1234567890123456789012345678901234567890",
|
|
188
|
-
* revocable: true
|
|
60
|
+
* import { createEASClient } from '@settlemint/sdk-eas';
|
|
61
|
+
*
|
|
62
|
+
* const client = createEASClient({
|
|
63
|
+
* schemaRegistryAddress: "0x1234567890123456789012345678901234567890",
|
|
64
|
+
* attestationAddress: "0x1234567890123456789012345678901234567890",
|
|
65
|
+
* accessToken: "your-access-token",
|
|
66
|
+
* chainId: "1",
|
|
67
|
+
* chainName: "Ethereum",
|
|
68
|
+
* rpcUrl: "http://localhost:8545"
|
|
189
69
|
* });
|
|
190
|
-
*
|
|
191
|
-
* console.log(`Schema registered with UID: ${schemaUID}`);
|
|
192
70
|
* ```
|
|
193
71
|
*/
|
|
194
|
-
declare function
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
submitAttestation(): void;
|
|
198
|
-
parseAttestation(): void;
|
|
199
|
-
createSchema(): void;
|
|
200
|
-
getSchema(): void;
|
|
201
|
-
getAttestations(): void;
|
|
72
|
+
declare function createEASClient(options: ClientOptions): {
|
|
73
|
+
registerSchema: (options: RegisterSchemaOptions) => Promise<string>;
|
|
74
|
+
getSchema: (uid: string) => Promise<string>;
|
|
202
75
|
};
|
|
203
76
|
|
|
204
|
-
export {
|
|
77
|
+
export { createEASClient };
|
package/dist/eas.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {SchemaRegistry}from'@ethereum-attestation-service/eas-sdk';import {validate}from'@settlemint/sdk-utils/validation';import {getPublicClient,getWalletClient}from'@settlemint/sdk-viem';import {z}from'zod';import {JsonRpcProvider,Wallet}from'ethers';var u=z.object({schemaRegistryAddress:z.string().min(1),attestationAddress:z.string().min(1),...z.object({accessToken:z.string().min(1),chainId:z.string().min(1),chainName:z.string().min(1),rpcUrl:z.string().min(1)}).shape});function f(e){let{chain:t,transport:r}=e;if(!t)throw new Error("Chain is required");let a={chainId:t.id,name:t.name,ensAddress:t.contracts?.ensRegistry?.address};if(r.type==="fallback"){let s=r.transports.map(({value:i})=>{if(!i?.url)return null;try{return new JsonRpcProvider(i.url,a)}catch{return null}}).filter(i=>i!=null);if(s.length===0)throw new Error("No valid RPC URLs found");return s[0]}return new JsonRpcProvider(r.url,a)}function g(e){let{account:t,chain:r,transport:a}=e;if(!r)throw new Error("Chain is required");if(!t)throw new Error("Account is required");let s={chainId:r.id,name:r.name,ensAddress:r.contracts?.ensRegistry?.address},i=new JsonRpcProvider(a.url,s),c=t.privateKey;if(!c||typeof c!="string")throw new Error("Private key is required and must be a string");return new Wallet(c,i)}var p={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function v(e){if(!e)throw new Error("Field name cannot be empty");if(e.includes(" "))throw new Error("Field name cannot contain spaces");if(!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(e))throw new Error("Field name must start with a letter or underscore and contain only alphanumeric characters and underscores")}function E(e){if(!(e in p))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(p).join(", ")}`)}function h(e){if(!e||e.length===0)throw new Error("Schema must have at least one field");let t=new Set;for(let r of e){if(v(r.name),E(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function y(e){return h(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function q(e){validate(u,e);let t=getPublicClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl}),r=getWalletClient({accessToken:e.accessToken,chainId:e.chainId,chainName:e.chainName,rpcUrl:e.rpcUrl})(),a=f(t),s=g(r),i=new SchemaRegistry(e.schemaRegistryAddress);i.connect(s);async function c(o){h(o.fields);let l=y(o.fields);try{await a.getNetwork();let m=await i.register({schema:l,resolverAddress:o.resolverAddress,revocable:o.revocable});return await m.wait(),m.toString()}catch(m){throw new Error(`Failed to register schema: ${m.message}`)}}async function w(o){try{return await a.getNetwork(),(await i.getSchema({uid:o})).toString()}catch(l){throw new Error(`Failed to get schema: ${l.message}`)}}return {registerSchema:c,getSchema:w}}export{q as createEASClient};//# sourceMappingURL=eas.mjs.map
|
|
2
2
|
//# sourceMappingURL=eas.mjs.map
|
package/dist/eas.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/schema.ts","../src/eas.ts"],"names":["EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","validateEthereumAddress","address","isAddress","registerSchema","options","resolverAddress","revocable","schemaString","createEASClient"],"mappings":"6BAcO,IAAMA,CAAkB,CAAA,CAC7B,MAAQ,CAAA,QAAA,CACR,OAAS,CAAA,SAAA,CACT,IAAM,CAAA,MAAA,CACN,MAAO,OACP,CAAA,OAAA,CAAS,SACT,CAAA,OAAA,CAAS,SACT,CAAA,MAAA,CAAQ,QACR,CAAA,KAAA,CAAO,OACP,CAAA,IAAA,CAAM,MACR,EA8CO,SAASC,CAAAA,CAAkBC,CAAoB,CAAA,CACpD,GAAI,CAACA,CAAAA,CACH,MAAM,IAAI,KAAM,CAAA,4BAA4B,CAE9C,CAAA,GAAIA,CAAK,CAAA,QAAA,CAAS,GAAG,CAAA,CACnB,MAAM,IAAI,KAAM,CAAA,kCAAkC,EAEpD,GAAI,CAAC,0BAA2B,CAAA,IAAA,CAAKA,CAAI,CAAA,CACvC,MAAM,IAAI,KACR,CAAA,4GACF,CAEJ,CAkBO,SAASC,CAAAA,CAAkBC,CAA4C,CAAA,CAC5E,GAAI,EAAEA,CAAAA,IAAQJ,CACZ,CAAA,CAAA,MAAM,IAAI,KAAA,CAAM,CAAuBI,oBAAAA,EAAAA,CAAI,CAAqB,kBAAA,EAAA,MAAA,CAAO,IAAKJ,CAAAA,CAAe,CAAE,CAAA,IAAA,CAAK,IAAI,CAAC,EAAE,CAE7G,CAyBO,SAASK,CAAAA,CAAqBC,CAA6B,CAAA,CAChE,GAAI,CAACA,CAAUA,EAAAA,CAAAA,CAAO,MAAW,GAAA,CAAA,CAC/B,MAAM,IAAI,KAAM,CAAA,qCAAqC,EAGvD,IAAMC,CAAAA,CAAY,IAAI,GAAA,CACtB,IAAWC,IAAAA,CAAAA,IAASF,CAAQ,CAAA,CAI1B,GAHAL,CAAAA,CAAkBO,CAAM,CAAA,IAAI,CAC5BL,CAAAA,C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E,CAAC,CAC5B,CAAA,CCvQO,SAASE,CAAAA,EAAkB,CAChC,OAAO,CACL,iBAAoB,EAAA,CAClB,OAAQ,CAAA,GAAA,CAAI,8BAA8B,EAC5C,CAEA,CAAA,gBAAA,EAAmB,CACjB,OAAA,CAAQ,GAAI,CAAA,2BAA2B,EACzC,CAAA,CAEA,YAAe,EAAA,CACb,QAAQ,GAAI,CAAA,uBAAuB,EACrC,CAAA,CAEA,SAAY,EAAA,CACV,OAAQ,CAAA,GAAA,CAAI,sBAAsB,EACpC,CAAA,CAEA,eAAkB,EAAA,CAChB,OAAQ,CAAA,GAAA,CAAI,4BAA4B,EAC1C,CACF,CACF","file":"eas.mjs","sourcesContent":["/**\n * Supported EAS schema field types.\n * Maps user-friendly type names to EAS-compatible type strings.\n * @example\n * ```ts\n * import { EAS_FIELD_TYPES } from '@settlemint/sdk-eas';\n *\n * // Use in type definitions\n * type MyFieldType = keyof typeof EAS_FIELD_TYPES;\n *\n * // Check if a type is supported\n * const isValidType = \"string\" in EAS_FIELD_TYPES;\n * ```\n */\nexport const EAS_FIELD_TYPES = {\n string: \"string\",\n address: \"address\",\n bool: \"bool\",\n bytes: \"bytes\",\n bytes32: \"bytes32\",\n uint256: \"uint256\",\n int256: \"int256\",\n uint8: \"uint8\",\n int8: \"int8\",\n} as const;\n\n/**\n * Type representing all valid EAS field types.\n */\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Interface for defining a schema field.\n * @example\n * ```ts\n * import { SchemaField } from '@settlemint/sdk-eas';\n *\n * const field: SchemaField = {\n * name: \"userAddress\",\n * type: \"address\",\n * description: \"The Ethereum address of the user\"\n * };\n * ```\n */\nexport interface SchemaField {\n /** The name of the field */\n name: string;\n /** The type of the field */\n type: EASFieldType;\n /** Optional description of the field */\n description?: string;\n}\n\n/**\n * Validates a schema field name.\n * @param name - The field name to validate\n * @throws Error if the name is invalid\n * @example\n * ```ts\n * import { validateFieldName } from '@settlemint/sdk-eas';\n *\n * // Valid names\n * validateFieldName(\"userAddress\"); // OK\n * validateFieldName(\"user_address\"); // OK\n *\n * // Invalid names\n * validateFieldName(\"user address\"); // Throws: \"Field name cannot contain spaces\"\n * validateFieldName(\"123user\"); // Throws: \"Field name must start with a letter or underscore\"\n * ```\n */\nexport function validateFieldName(name: string): void {\n if (!name) {\n throw new Error(\"Field name cannot be empty\");\n }\n if (name.includes(\" \")) {\n throw new Error(\"Field name cannot contain spaces\");\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n throw new Error(\n \"Field name must start with a letter or underscore and contain only alphanumeric characters and underscores\",\n );\n }\n}\n\n/**\n * Validates a schema field type.\n * @param type - The field type to validate\n * @throws Error if the type is invalid\n * @example\n * ```ts\n * import { validateFieldType } from '@settlemint/sdk-eas';\n *\n * // Valid types\n * validateFieldType(\"string\"); // OK\n * validateFieldType(\"address\"); // OK\n *\n * // Invalid types\n * validateFieldType(\"invalidType\"); // Throws: \"Invalid field type: invalidType\"\n * ```\n */\nexport function validateFieldType(type: string): asserts type is EASFieldType {\n if (!(type in EAS_FIELD_TYPES)) {\n throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(\", \")}`);\n }\n}\n\n/**\n * Validates an array of schema fields.\n * @param fields - The fields to validate\n * @throws Error if any field is invalid\n * @example\n * ```ts\n * import { validateSchemaFields, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ];\n *\n * validateSchemaFields(fields); // OK\n *\n * // Invalid fields\n * validateSchemaFields([]); // Throws: \"Schema must have at least one field\"\n * validateSchemaFields([\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"userAddress\", type: \"uint8\" }\n * ]); // Throws: \"Duplicate field name: userAddress\"\n * ```\n */\nexport function validateSchemaFields(fields: SchemaField[]): void {\n if (!fields || fields.length === 0) {\n throw new Error(\"Schema must have at least one field\");\n }\n\n const seenNames = new Set<string>();\n for (const field of fields) {\n validateFieldName(field.name);\n validateFieldType(field.type);\n\n if (seenNames.has(field.name)) {\n throw new Error(`Duplicate field name: ${field.name}`);\n }\n seenNames.add(field.name);\n }\n}\n\n/**\n * Builds an EAS schema string from an array of fields.\n * @param fields - The fields to include in the schema\n * @returns The EAS-compatible schema string\n * @throws Error if any field is invalid\n * @example\n * ```ts\n * import { buildSchemaString, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" },\n * { name: \"isActive\", type: \"bool\" }\n * ];\n *\n * const schemaString = buildSchemaString(fields);\n * // Result: \"address userAddress, uint8 age, bool isActive\"\n * ```\n */\nexport function buildSchemaString(fields: SchemaField[]): string {\n validateSchemaFields(fields);\n return fields.map((field) => `${field.type} ${field.name}`).join(\", \");\n}\n\n/**\n * Options for registering a schema.\n * @example\n * ```ts\n * import { RegisterSchemaOptions, SchemaField } from '@settlemint/sdk-eas';\n *\n * const options: RegisterSchemaOptions = {\n * fields: [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ],\n * resolverAddress: \"0x1234567890123456789012345678901234567890\",\n * revocable: true\n * };\n * ```\n */\nexport interface RegisterSchemaOptions {\n /** The fields that make up the schema */\n fields: SchemaField[];\n /** The Ethereum address of the resolver */\n resolverAddress: string;\n /** Whether attestations using this schema can be revoked */\n revocable: boolean;\n}\n\nimport { isAddress } from \"viem\";\n\n/**\n * Validates an Ethereum address.\n * @param address - The address to validate\n * @throws Error if the address is invalid\n * @example\n * ```ts\n * import { validateEthereumAddress } from '@settlemint/sdk-eas';\n *\n * // Valid address\n * validateEthereumAddress(\"0x1234567890123456789012345678901234567890\"); // OK\n *\n * // Invalid addresses\n * validateEthereumAddress(\"0x123\"); // Throws: \"Invalid Ethereum address format\"\n * validateEthereumAddress(\"\"); // Throws: \"Resolver address cannot be empty\"\n * ```\n */\nexport function validateEthereumAddress(address: string): void {\n if (!address) {\n throw new Error(\"Resolver address cannot be empty\");\n }\n if (!isAddress(address)) {\n throw new Error(\"Invalid Ethereum address format\");\n }\n}\n\n/**\n * Registers a new schema with EAS.\n * @param options - The schema registration options\n * @returns A promise that resolves to the schema UID\n * @throws Error if the schema registration fails\n * @example\n * ```ts\n * import { registerSchema, SchemaField } from '@settlemint/sdk-eas';\n *\n * const fields: SchemaField[] = [\n * { name: \"userAddress\", type: \"address\" },\n * { name: \"age\", type: \"uint8\" }\n * ];\n *\n * const schemaUID = await registerSchema({\n * fields,\n * resolverAddress: \"0x1234567890123456789012345678901234567890\",\n * revocable: true\n * });\n *\n * console.log(`Schema registered with UID: ${schemaUID}`);\n * ```\n */\nexport async function registerSchema(options: RegisterSchemaOptions): Promise<string> {\n const { fields, resolverAddress, revocable } = options;\n\n // Validate the schema fields\n validateSchemaFields(fields);\n\n // Validate the resolver address\n validateEthereumAddress(resolverAddress);\n\n // Build the schema string\n const schemaString = buildSchemaString(fields);\n\n // TODO: Implement actual EAS SDK registration\n // This is a placeholder that will be replaced with actual EAS SDK integration\n console.log(`[EAS] Registering schema: ${schemaString}`);\n console.log(`[EAS] Resolver: ${resolverAddress}`);\n console.log(`[EAS] Revocable: ${revocable}`);\n\n // Return a mock UID for now\n return `0x${\"0\".repeat(64)}`;\n}\n","export * from \"./schema.js\";\n\nexport function createEASClient() {\n return {\n submitAttestation() {\n console.log(\"[EAS] Submitting attestation\");\n },\n\n parseAttestation() {\n console.log(\"[EAS] Parsing attestation\");\n },\n\n createSchema() {\n console.log(\"[EAS] Creating schema\");\n },\n\n getSchema() {\n console.log(\"[EAS] Getting schema\");\n },\n\n getAttestations() {\n console.log(\"[EAS] Getting attestations\");\n },\n };\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../src/client-options.schema.ts","../src/ethers-adapter.ts","../src/types.ts","../src/validation.ts","../src/eas.ts"],"names":["ClientOptionsSchema","z","publicClientToProvider","client","chain","transport","network","providers","value","JsonRpcProvider","provider","walletClientToSigner","account","privateKey","Wallet","EAS_FIELD_TYPES","validateFieldName","name","validateFieldType","type","validateSchemaFields","fields","seenNames","field","buildSchemaString","createEASClient","options","validate","publicClient","getPublicClient","walletClient","getWalletClient","wallet","schemaRegistry","SchemaRegistry","registerSchema","schema","tx","error","getSchema","uid"],"mappings":"8PAGO,IAAMA,CAAAA,CAAsBC,CAAE,CAAA,MAAA,CAAO,CAC1C,qBAAuBA,CAAAA,CAAAA,CAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,CACvC,CAAA,kBAAA,CAAoBA,EAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,CACpC,CAAA,GAAGA,CAAE,CAAA,MAAA,CAAO,CACV,WAAaA,CAAAA,CAAAA,CAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,CAC7B,CAAA,OAAA,CAASA,EAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,CACzB,CAAA,SAAA,CAAWA,CAAE,CAAA,MAAA,GAAS,GAAI,CAAA,CAAC,CAC3B,CAAA,MAAA,CAAQA,CAAE,CAAA,MAAA,EAAS,CAAA,GAAA,CAAI,CAAC,CAC1B,CAAC,CAAE,CAAA,KACL,CAAC,CAAA,CCNM,SAASC,CAAAA,CAAuBC,CAAgC,CAAA,CACrE,GAAM,CAAE,KAAA,CAAAC,CAAO,CAAA,SAAA,CAAAC,CAAU,CAAA,CAAIF,CAC7B,CAAA,GAAI,CAACC,CAAO,CAAA,MAAM,IAAI,KAAA,CAAM,mBAAmB,CAAA,CAE/C,IAAME,CAAAA,CAAU,CACd,OAASF,CAAAA,CAAAA,CAAM,EACf,CAAA,IAAA,CAAMA,CAAM,CAAA,IAAA,CACZ,UAAYA,CAAAA,CAAAA,CAAM,WAAW,WAAa,EAAA,OAC5C,CAEA,CAAA,GAAIC,CAAU,CAAA,IAAA,GAAS,UAAY,CAAA,CACjC,IAAME,CAAaF,CAAAA,CAAAA,CAAU,UAC1B,CAA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EAEf,CAAA,IAAM2B,CAAK,CAAA,MAAMJ,EAAe,QAAS,CAAA,CACvC,MAAAG,CAAAA,CAAAA,CACA,eAAiBV,CAAAA,CAAAA,CAAQ,eACzB,CAAA,SAAA,CAAWA,CAAQ,CAAA,SACrB,CAAC,CAAA,CAED,OAAMW,MAAAA,CAAAA,CAAG,IAAK,EAAA,CACPA,EAAG,QAAS,EACrB,CAASC,MAAAA,CAAAA,CAAO,CACd,MAAM,IAAI,KAAA,CAAM,8BAA+BA,CAAgB,CAAA,OAAO,CAAE,CAAA,CAC1E,CACF,CAEA,eAAeC,CAAAA,CAAUC,EAA8B,CACrD,GAAI,CAEF,OAAA,MAAM9B,CAAS,CAAA,UAAA,EAEA,CAAA,CAAA,MAAMuB,EAAe,SAAU,CAAA,CAAE,GAAAO,CAAAA,CAAI,CAAC,CAAA,EACvC,QAAS,EACzB,OAASF,CAAO,CAAA,CACd,MAAM,IAAI,KAAM,CAAA,CAAA,sBAAA,EAA0BA,CAAgB,CAAA,OAAO,EAAE,CACrE,CACF,CAEA,OAAO,CACL,cAAA,CAAAH,CACA,CAAA,SAAA,CAAAI,CACF,CACF","file":"eas.mjs","sourcesContent":["import type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { z } from \"zod\";\n\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().min(1),\n attestationAddress: z.string().min(1),\n ...z.object({\n accessToken: z.string().min(1),\n chainId: z.string().min(1),\n chainName: z.string().min(1),\n rpcUrl: z.string().min(1),\n }).shape,\n});\n\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema> &\n Pick<ViemClientOptions, \"accessToken\" | \"chainId\" | \"chainName\" | \"rpcUrl\">;\n","import { JsonRpcProvider, type Provider, Wallet } from \"ethers\";\nimport type { PublicClient, Transport, WalletClient } from \"viem\";\n\n/**\n * Converts a viem PublicClient to an ethers JsonRpcProvider\n */\nexport function publicClientToProvider(client: PublicClient): Provider {\n const { chain, transport } = client;\n if (!chain) throw new Error(\"Chain is required\");\n\n const network = {\n chainId: chain.id,\n name: chain.name,\n ensAddress: chain.contracts?.ensRegistry?.address,\n };\n\n if (transport.type === \"fallback\") {\n const providers = (transport.transports as ReturnType<Transport>[])\n .map(({ value }) => {\n if (!value?.url) return null;\n try {\n return new JsonRpcProvider(value.url, network);\n } catch {\n return null;\n }\n })\n .filter((provider): provider is JsonRpcProvider => provider != null);\n\n if (providers.length === 0) throw new Error(\"No valid RPC URLs found\");\n // We know providers[0] exists because we checked length > 0\n return providers[0] as Provider;\n }\n\n return new JsonRpcProvider(transport.url, network);\n}\n\n/**\n * Converts a viem WalletClient to an ethers Wallet\n */\nexport function walletClientToSigner(client: WalletClient): Wallet {\n const { account, chain, transport } = client;\n if (!chain) throw new Error(\"Chain is required\");\n if (!account) throw new Error(\"Account is required\");\n\n const network = {\n chainId: chain.id,\n name: chain.name,\n ensAddress: chain.contracts?.ensRegistry?.address,\n };\n\n const provider = new JsonRpcProvider(transport.url, network);\n\n // For viem, we need to get the private key from the account\n const privateKey = (account as { privateKey?: string }).privateKey;\n if (!privateKey || typeof privateKey !== \"string\") {\n throw new Error(\"Private key is required and must be a string\");\n }\n\n return new Wallet(privateKey, provider);\n}\n","export const EAS_FIELD_TYPES = {\n string: \"string\",\n address: \"address\",\n bool: \"bool\",\n bytes: \"bytes\",\n bytes32: \"bytes32\",\n uint256: \"uint256\",\n int256: \"int256\",\n uint8: \"uint8\",\n int8: \"int8\",\n} as const;\n\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\nexport interface SchemaField {\n name: string;\n type: EASFieldType;\n description?: string;\n}\n\nexport interface RegisterSchemaOptions {\n fields: SchemaField[];\n resolverAddress: string;\n revocable: boolean;\n}\n","import { type EASFieldType, EAS_FIELD_TYPES, type SchemaField } from \"./types.js\";\n\nexport function validateFieldName(name: string): void {\n if (!name) {\n throw new Error(\"Field name cannot be empty\");\n }\n if (name.includes(\" \")) {\n throw new Error(\"Field name cannot contain spaces\");\n }\n if (!/^[a-zA-Z_][a-zA-Z0-9_]*$/.test(name)) {\n throw new Error(\n \"Field name must start with a letter or underscore and contain only alphanumeric characters and underscores\",\n );\n }\n}\n\nexport function validateFieldType(type: string): asserts type is EASFieldType {\n if (!(type in EAS_FIELD_TYPES)) {\n throw new Error(`Invalid field type: ${type}. Must be one of: ${Object.keys(EAS_FIELD_TYPES).join(\", \")}`);\n }\n}\n\nexport function validateSchemaFields(fields: SchemaField[]): void {\n if (!fields || fields.length === 0) {\n throw new Error(\"Schema must have at least one field\");\n }\n\n const seenNames = new Set<string>();\n for (const field of fields) {\n validateFieldName(field.name);\n validateFieldType(field.type);\n\n if (seenNames.has(field.name)) {\n throw new Error(`Duplicate field name: ${field.name}`);\n }\n seenNames.add(field.name);\n }\n}\n\nexport function buildSchemaString(fields: SchemaField[]): string {\n validateSchemaFields(fields);\n return fields.map((field) => `${field.type} ${field.name}`).join(\", \");\n}\n","import { SchemaRegistry } from \"@ethereum-attestation-service/eas-sdk\";\nimport { validate } from \"@settlemint/sdk-utils/validation\";\nimport { getPublicClient, getWalletClient } from \"@settlemint/sdk-viem\";\nimport type { PublicClient } from \"viem\";\nimport { type ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nimport { publicClientToProvider, walletClientToSigner } from \"./ethers-adapter.js\";\nimport type { RegisterSchemaOptions } from \"./types.js\";\nimport { buildSchemaString, validateSchemaFields } from \"./validation.js\";\n\n/**\n * Creates an EAS client for interacting with the Ethereum Attestation Service.\n *\n * @param options - Configuration options for the client\n * @returns An object containing the EAS client instance\n * @throws Will throw an error if the options fail validation\n *\n * @example\n * ```ts\n * import { createEASClient } from '@settlemint/sdk-eas';\n *\n * const client = createEASClient({\n * schemaRegistryAddress: \"0x1234567890123456789012345678901234567890\",\n * attestationAddress: \"0x1234567890123456789012345678901234567890\",\n * accessToken: \"your-access-token\",\n * chainId: \"1\",\n * chainName: \"Ethereum\",\n * rpcUrl: \"http://localhost:8545\"\n * });\n * ```\n */\nexport function createEASClient(options: ClientOptions) {\n validate(ClientOptionsSchema, options);\n\n // Create viem clients\n const publicClient = getPublicClient({\n accessToken: options.accessToken,\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n }) as PublicClient;\n\n const walletClient = getWalletClient({\n accessToken: options.accessToken,\n chainId: options.chainId,\n chainName: options.chainName,\n rpcUrl: options.rpcUrl,\n })();\n\n // Convert to ethers for EAS SDK\n const provider = publicClientToProvider(publicClient);\n const wallet = walletClientToSigner(walletClient);\n\n const schemaRegistry = new SchemaRegistry(options.schemaRegistryAddress);\n schemaRegistry.connect(wallet);\n\n async function registerSchema(options: RegisterSchemaOptions): Promise<string> {\n validateSchemaFields(options.fields);\n const schema = buildSchemaString(options.fields);\n\n try {\n // Check if the provider is available\n await provider.getNetwork();\n\n const tx = await schemaRegistry.register({\n schema,\n resolverAddress: options.resolverAddress,\n revocable: options.revocable,\n });\n\n await tx.wait();\n return tx.toString();\n } catch (error) {\n throw new Error(`Failed to register schema: ${(error as Error).message}`);\n }\n }\n\n async function getSchema(uid: string): Promise<string> {\n try {\n // Check if the provider is available\n await provider.getNetwork();\n\n const schema = await schemaRegistry.getSchema({ uid });\n return schema.toString();\n } catch (error) {\n throw new Error(`Failed to get schema: ${(error as Error).message}`);\n }\n }\n\n return {\n registerSchema,\n getSchema,\n };\n}\n"]}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@settlemint/sdk-eas",
|
|
3
3
|
"description": "Ethereum Attestation Service (EAS) integration for SettleMint SDK",
|
|
4
|
-
"version": "2.2.2-
|
|
4
|
+
"version": "2.2.2-prdc6e1d84",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -51,7 +51,10 @@
|
|
|
51
51
|
},
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
|
-
"@
|
|
54
|
+
"@ethereum-attestation-service/eas-sdk": "2.7.0",
|
|
55
|
+
"@settlemint/sdk-utils": "2.2.2-prdc6e1d84",
|
|
56
|
+
"@settlemint/sdk-viem": "2.2.2-prdc6e1d84",
|
|
57
|
+
"ethers": "^6.11.1",
|
|
55
58
|
"viem": "^2.7.9"
|
|
56
59
|
},
|
|
57
60
|
"peerDependencies": {},
|