@settlemint/sdk-eas 2.3.2-pr983b407d → 2.3.2-pr9d565676
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/README.md +28 -6
- package/dist/eas.cjs +1 -1
- package/dist/eas.cjs.map +1 -1
- package/dist/eas.d.cts +9 -19
- package/dist/eas.d.ts +9 -19
- package/dist/eas.mjs +1 -1
- package/dist/eas.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -61,7 +61,13 @@ Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
|
61
61
|
|
|
62
62
|
| Parameter | Type | Description |
|
|
63
63
|
| ------ | ------ | ------ |
|
|
64
|
-
| `options` |
|
|
64
|
+
| `options` | \{ `accessToken`: `string`; `attestationAddress`: `string`; `chainId`: `string`; `chainName`: `string`; `rpcUrl`: `string`; `schemaRegistryAddress`: `string`; \} | Configuration options for the client |
|
|
65
|
+
| `options.accessToken` | `string` | Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_') |
|
|
66
|
+
| `options.attestationAddress` | `string` | The address of the EAS Attestation contract |
|
|
67
|
+
| `options.chainId` | `string` | The chain ID to connect to |
|
|
68
|
+
| `options.chainName` | `string` | The name of the chain to connect to |
|
|
69
|
+
| `options.rpcUrl` | `string` | The RPC URL to connect to (must be a valid URL) |
|
|
70
|
+
| `options.schemaRegistryAddress` | `string` | The address of the EAS Schema Registry contract |
|
|
65
71
|
|
|
66
72
|
##### Returns
|
|
67
73
|
|
|
@@ -97,25 +103,41 @@ const client = createEASClient({
|
|
|
97
103
|
|
|
98
104
|
#### RegisterSchemaOptions
|
|
99
105
|
|
|
100
|
-
Defined in: [sdk/eas/src/types.ts:
|
|
106
|
+
Defined in: [sdk/eas/src/types.ts:34](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/types.ts#L34)
|
|
101
107
|
|
|
102
108
|
Options for registering a new schema in the EAS Schema Registry.
|
|
103
109
|
|
|
110
|
+
##### Properties
|
|
111
|
+
|
|
112
|
+
| Property | Type | Description | Defined in |
|
|
113
|
+
| ------ | ------ | ------ | ------ |
|
|
114
|
+
| <a id="fields"></a> `fields` | [`SchemaField`](#schemafield)[] | Array of fields that make up the schema | [sdk/eas/src/types.ts:36](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/types.ts#L36) |
|
|
115
|
+
| <a id="resolveraddress"></a> `resolverAddress` | `string` | Address of the resolver contract that will handle attestations | [sdk/eas/src/types.ts:38](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/types.ts#L38) |
|
|
116
|
+
| <a id="revocable"></a> `revocable` | `boolean` | Whether attestations using this schema can be revoked | [sdk/eas/src/types.ts:40](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/types.ts#L40) |
|
|
117
|
+
|
|
104
118
|
***
|
|
105
119
|
|
|
106
120
|
#### SchemaField
|
|
107
121
|
|
|
108
|
-
Defined in: [sdk/eas/src/types.ts:
|
|
122
|
+
Defined in: [sdk/eas/src/types.ts:22](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/types.ts#L22)
|
|
109
123
|
|
|
110
124
|
Represents a single field in an EAS schema.
|
|
111
125
|
|
|
126
|
+
##### Properties
|
|
127
|
+
|
|
128
|
+
| Property | Type | Description | Defined in |
|
|
129
|
+
| ------ | ------ | ------ | ------ |
|
|
130
|
+
| <a id="description"></a> `description?` | `string` | Optional description of the field's purpose | [sdk/eas/src/types.ts:28](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/types.ts#L28) |
|
|
131
|
+
| <a id="name"></a> `name` | `string` | The name of the field | [sdk/eas/src/types.ts:24](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/types.ts#L24) |
|
|
132
|
+
| <a id="type"></a> `type` | `"string"` \| `"address"` \| `"bool"` \| `"bytes"` \| `"bytes32"` \| `"int8"` \| `"int256"` \| `"uint8"` \| `"uint256"` | The Solidity type of the field | [sdk/eas/src/types.ts:26](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/types.ts#L26) |
|
|
133
|
+
|
|
112
134
|
### Type Aliases
|
|
113
135
|
|
|
114
136
|
#### ClientOptions
|
|
115
137
|
|
|
116
|
-
> **ClientOptions** = `z.infer`\<*typeof* [`ClientOptionsSchema`](#clientoptionsschema)\>
|
|
138
|
+
> **ClientOptions** = `z.infer`\<*typeof* [`ClientOptionsSchema`](#clientoptionsschema)\>
|
|
117
139
|
|
|
118
|
-
Defined in: [sdk/eas/src/client-options.schema.ts:
|
|
140
|
+
Defined in: [sdk/eas/src/client-options.schema.ts:28](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/client-options.schema.ts#L28)
|
|
119
141
|
|
|
120
142
|
Configuration options for creating an EAS client.
|
|
121
143
|
Combines EAS-specific options with base Viem client options.
|
|
@@ -126,7 +148,7 @@ Combines EAS-specific options with base Viem client options.
|
|
|
126
148
|
|
|
127
149
|
> `const` **ClientOptionsSchema**: `ZodObject`\<\{ `accessToken`: `ZodString`; `attestationAddress`: `ZodString`; `chainId`: `ZodString`; `chainName`: `ZodString`; `rpcUrl`: `ZodString`; `schemaRegistryAddress`: `ZodString`; \}, `$strip`\>
|
|
128
150
|
|
|
129
|
-
Defined in: [sdk/eas/src/client-options.schema.ts:
|
|
151
|
+
Defined in: [sdk/eas/src/client-options.schema.ts:9](https://github.com/settlemint/sdk/blob/v2.3.2/sdk/eas/src/client-options.schema.ts#L9)
|
|
130
152
|
|
|
131
153
|
Schema for validating EAS client configuration options.
|
|
132
154
|
Extends the base Viem client options with EAS-specific requirements.
|
package/dist/eas.cjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
'use strict';var easSdk=require('@ethereum-attestation-service/eas-sdk'),validation=require('@settlemint/sdk-utils/validation'),sdkViem=require('@settlemint/sdk-viem'),viem=require('viem'),v4=require('zod/v4'),ethers=require('ethers');var u=v4.z.object({schemaRegistryAddress:v4.z.string().refine(viem.isAddress,"Invalid Ethereum address format"),attestationAddress:v4.z.string().refine(viem.isAddress,"Invalid Ethereum address format")
|
|
1
|
+
'use strict';var easSdk=require('@ethereum-attestation-service/eas-sdk'),validation=require('@settlemint/sdk-utils/validation'),sdkViem=require('@settlemint/sdk-viem'),viem=require('viem'),v4=require('zod/v4'),ethers=require('ethers');var u=v4.z.object({schemaRegistryAddress:v4.z.string().refine(viem.isAddress,"Invalid Ethereum address format"),attestationAddress:v4.z.string().refine(viem.isAddress,"Invalid Ethereum address format"),accessToken:validation.AccessTokenSchema,chainId:v4.z.string().min(1),chainName:v4.z.string().min(1),rpcUrl:validation.UrlSchema});function y(e){let{chain:t,transport:r}=e;if(!t)throw new Error("Chain is required");let n={chainId:t.id,name:t.name,ensAddress:t.contracts?.ensRegistry?.address};if(r.type==="fallback"){let a=r.transports.map(({value:i})=>{if(!i?.url)return null;try{return new ethers.JsonRpcProvider(i.url,n)}catch{return null}}).filter(i=>i!=null);if(a.length===0)throw new Error("No valid RPC URLs found");return a[0]}return new ethers.JsonRpcProvider(r.url,n)}function g(e){let{account:t,chain:r,transport:n}=e;if(!r)throw new Error("Chain is required");if(!t)throw new Error("Account is required");let a={chainId:r.id,name:r.name,ensAddress:r.contracts?.ensRegistry?.address},i=new ethers.JsonRpcProvider(n.url,a),o=t.privateKey;if(!o||typeof o!="string")throw new Error("Private key is required and must be a string");return new ethers.Wallet(o,i)}var d={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function C(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 F(e){if(!(e in d))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(d).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(C(r.name),F(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function w(e){return h(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function K(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})(),n=y(t),a=g(r),i=new easSdk.SchemaRegistry(e.schemaRegistryAddress);i.connect(a);async function o(s){h(s.fields);let m=w(s.fields);try{await n.getNetwork();let c=await i.register({schema:m,resolverAddress:s.resolverAddress,revocable:s.revocable});return await c.wait(),c.toString()}catch(c){throw new Error(`Failed to register schema: ${c.message}`,{cause:c})}}async function S(s){try{return await n.getNetwork(),(await i.getSchema({uid:s})).toString()}catch(m){throw new Error(`Failed to get schema: ${m.message}`)}}return {registerSchema:o,getSchema:S}}exports.EAS_FIELD_TYPES=d;exports.createEASClient=K;//# sourceMappingURL=eas.cjs.map
|
|
2
2
|
//# sourceMappingURL=eas.cjs.map
|
package/dist/eas.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
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","isAddress","AccessTokenSchema","UrlSchema","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":"2OASO,IAAMA,CAAsBC,CAAAA,IAAAA,CAAE,OAAO,CAC1C,qBAAA,CAAuBA,IAAE,CAAA,MAAA,EAAS,CAAA,MAAA,CAAOC,cAAW,C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AAA,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 { AccessTokenSchema, UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod/v4\";\n\n/**\n * Schema for validating EAS client configuration options.\n * Extends the base Viem client options with EAS-specific requirements.\n */\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n attestationAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n ...z.object({\n accessToken: AccessTokenSchema,\n chainId: z.string().min(1),\n chainName: z.string().min(1),\n rpcUrl: UrlSchema,\n }).shape,\n});\n\n/**\n * Configuration options for creating an EAS client.\n * Combines EAS-specific options with base Viem client options.\n *\n * @property schemaRegistryAddress - The address of the EAS Schema Registry contract\n * @property attestationAddress - The address of the EAS Attestation contract\n * @property accessToken - Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_')\n * @property chainId - The chain ID to connect to\n * @property chainName - The name of the chain to connect to\n * @property rpcUrl - The RPC URL to connect to (must be a valid URL)\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","/**\n * Supported field types for EAS schema fields.\n * Maps to the Solidity types that can be used in EAS schemas.\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\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Represents a single field in an EAS schema.\n *\n * @property name - The name of the field\n * @property type - The Solidity type of the field\n * @property description - Optional description of the field's purpose\n */\nexport interface SchemaField {\n name: string;\n type: EASFieldType;\n description?: string;\n}\n\n/**\n * Options for registering a new schema in the EAS Schema Registry.\n *\n * @property fields - Array of fields that make up the schema\n * @property resolverAddress - Address of the resolver contract that will handle attestations\n * @property revocable - Whether attestations using this schema can be revoked\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// Re-export types and constants\nexport type { ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nexport type { RegisterSchemaOptions, SchemaField, EASFieldType } from \"./types.js\";\nexport { EAS_FIELD_TYPES } from \"./types.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}`, { cause: error });\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"]}
|
|
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","isAddress","AccessTokenSchema","UrlSchema","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":"2OAQO,IAAMA,CAAsBC,CAAAA,IAAAA,CAAE,OAAO,CAE1C,qBAAA,CAAuBA,IAAE,CAAA,MAAA,EAAS,CAAA,MAAA,CAAOC,cAAW,CAAA,iCAAiC,CAErF,CAAA,kBAAA,CAAoBD,IAAE,CAAA,MAAA,EAAS,CAAA,MAAA,CAAOC,cAAW,CAAA,iCAAiC,EAElF,WAAaC,CAAAA,4BAAAA,CAEb,OAASF,CAAAA,IAAAA,CAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,EAEzB,SAAWA,CAAAA,IAAAA,CAAE,MAAO,EAAA,CAAE,GAAI,CAAA,CAAC,CAE3B,CAAA,MAAA,CAAQG,oBACV,CAAC,CAAA,CCfM,SAASC,CAAAA,CAAuBC,CAAgC,CAAA,CACrE,GAAM,CAAE,KAAAC,CAAAA,CAAAA,CAAO,UAAAC,CAAU,CAAA,CAAIF,CAC7B,CAAA,GAAI,CAACC,CAAAA,CAAO,MAAM,IAAI,MAAM,mBAAmB,CAAA,CAE/C,IAAME,CAAAA,CAAU,CACd,OAAA,CAASF,CAAM,CAAA,EAAA,CACf,KAAMA,CAAM,CAAA,IAAA,CACZ,UAAYA,CAAAA,CAAAA,CAAM,SAAW,EAAA,WAAA,EAAa,OAC5C,CAAA,CA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CAAQ,MAAM,CAAA,CAE/C,GAAI,CAEF,MAAMhB,CAAAA,CAAS,YAEf,CAAA,IAAM2B,CAAK,CAAA,MAAMJ,CAAe,CAAA,QAAA,CAAS,CACvC,MAAA,CAAAG,EACA,eAAiBV,CAAAA,CAAAA,CAAQ,eACzB,CAAA,SAAA,CAAWA,CAAQ,CAAA,SACrB,CAAC,CAAA,CAED,OAAMW,MAAAA,CAAAA,CAAG,IAAK,EAAA,CACPA,CAAG,CAAA,QAAA,EACZ,CAAA,MAASC,EAAO,CACd,MAAM,IAAI,KAAA,CAAM,CAA+BA,2BAAAA,EAAAA,CAAAA,CAAgB,OAAO,CAAA,CAAA,CAAI,CAAE,KAAOA,CAAAA,CAAM,CAAC,CAC5F,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 { AccessTokenSchema, UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod/v4\";\n\n/**\n * Schema for validating EAS client configuration options.\n * Extends the base Viem client options with EAS-specific requirements.\n */\nexport const ClientOptionsSchema = z.object({\n /** The address of the EAS Schema Registry contract */\n schemaRegistryAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n /** The address of the EAS Attestation contract */\n attestationAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n /** Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_') */\n accessToken: AccessTokenSchema,\n /** The chain ID to connect to */\n chainId: z.string().min(1),\n /** The name of the chain to connect to */\n chainName: z.string().min(1),\n /** The RPC URL to connect to (must be a valid URL) */\n rpcUrl: UrlSchema,\n});\n\n/**\n * Configuration options for creating an EAS client.\n * Combines EAS-specific options with base Viem client options.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\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","/**\n * Supported field types for EAS schema fields.\n * Maps to the Solidity types that can be used in EAS schemas.\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\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Represents a single field in an EAS schema.\n */\nexport interface SchemaField {\n /** The name of the field */\n name: string;\n /** The Solidity type of the field */\n type: EASFieldType;\n /** Optional description of the field's purpose */\n description?: string;\n}\n\n/**\n * Options for registering a new schema in the EAS Schema Registry.\n */\nexport interface RegisterSchemaOptions {\n /** Array of fields that make up the schema */\n fields: SchemaField[];\n /** Address of the resolver contract that will handle attestations */\n resolverAddress: string;\n /** Whether attestations using this schema can be revoked */\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// Re-export types and constants\nexport type { ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nexport type { RegisterSchemaOptions, SchemaField, EASFieldType } from \"./types.js\";\nexport { EAS_FIELD_TYPES } from \"./types.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}`, { cause: error });\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,4 +1,3 @@
|
|
|
1
|
-
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
1
|
import { z } from 'zod/v4';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -6,25 +5,18 @@ import { z } from 'zod/v4';
|
|
|
6
5
|
* Extends the base Viem client options with EAS-specific requirements.
|
|
7
6
|
*/
|
|
8
7
|
declare const ClientOptionsSchema: z.ZodObject<{
|
|
8
|
+
schemaRegistryAddress: z.ZodString;
|
|
9
|
+
attestationAddress: z.ZodString;
|
|
9
10
|
accessToken: z.ZodString;
|
|
10
11
|
chainId: z.ZodString;
|
|
11
12
|
chainName: z.ZodString;
|
|
12
13
|
rpcUrl: z.ZodString;
|
|
13
|
-
schemaRegistryAddress: z.ZodString;
|
|
14
|
-
attestationAddress: z.ZodString;
|
|
15
14
|
}, z.core.$strip>;
|
|
16
15
|
/**
|
|
17
16
|
* Configuration options for creating an EAS client.
|
|
18
17
|
* Combines EAS-specific options with base Viem client options.
|
|
19
|
-
*
|
|
20
|
-
* @property schemaRegistryAddress - The address of the EAS Schema Registry contract
|
|
21
|
-
* @property attestationAddress - The address of the EAS Attestation contract
|
|
22
|
-
* @property accessToken - Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_')
|
|
23
|
-
* @property chainId - The chain ID to connect to
|
|
24
|
-
* @property chainName - The name of the chain to connect to
|
|
25
|
-
* @property rpcUrl - The RPC URL to connect to (must be a valid URL)
|
|
26
18
|
*/
|
|
27
|
-
type ClientOptions = z.infer<typeof ClientOptionsSchema
|
|
19
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
28
20
|
|
|
29
21
|
/**
|
|
30
22
|
* Supported field types for EAS schema fields.
|
|
@@ -44,26 +36,24 @@ declare const EAS_FIELD_TYPES: {
|
|
|
44
36
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
45
37
|
/**
|
|
46
38
|
* Represents a single field in an EAS schema.
|
|
47
|
-
*
|
|
48
|
-
* @property name - The name of the field
|
|
49
|
-
* @property type - The Solidity type of the field
|
|
50
|
-
* @property description - Optional description of the field's purpose
|
|
51
39
|
*/
|
|
52
40
|
interface SchemaField {
|
|
41
|
+
/** The name of the field */
|
|
53
42
|
name: string;
|
|
43
|
+
/** The Solidity type of the field */
|
|
54
44
|
type: EASFieldType;
|
|
45
|
+
/** Optional description of the field's purpose */
|
|
55
46
|
description?: string;
|
|
56
47
|
}
|
|
57
48
|
/**
|
|
58
49
|
* Options for registering a new schema in the EAS Schema Registry.
|
|
59
|
-
*
|
|
60
|
-
* @property fields - Array of fields that make up the schema
|
|
61
|
-
* @property resolverAddress - Address of the resolver contract that will handle attestations
|
|
62
|
-
* @property revocable - Whether attestations using this schema can be revoked
|
|
63
50
|
*/
|
|
64
51
|
interface RegisterSchemaOptions {
|
|
52
|
+
/** Array of fields that make up the schema */
|
|
65
53
|
fields: SchemaField[];
|
|
54
|
+
/** Address of the resolver contract that will handle attestations */
|
|
66
55
|
resolverAddress: string;
|
|
56
|
+
/** Whether attestations using this schema can be revoked */
|
|
67
57
|
revocable: boolean;
|
|
68
58
|
}
|
|
69
59
|
|
package/dist/eas.d.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { ClientOptions as ClientOptions$1 } from '@settlemint/sdk-viem';
|
|
2
1
|
import { z } from 'zod/v4';
|
|
3
2
|
|
|
4
3
|
/**
|
|
@@ -6,25 +5,18 @@ import { z } from 'zod/v4';
|
|
|
6
5
|
* Extends the base Viem client options with EAS-specific requirements.
|
|
7
6
|
*/
|
|
8
7
|
declare const ClientOptionsSchema: z.ZodObject<{
|
|
8
|
+
schemaRegistryAddress: z.ZodString;
|
|
9
|
+
attestationAddress: z.ZodString;
|
|
9
10
|
accessToken: z.ZodString;
|
|
10
11
|
chainId: z.ZodString;
|
|
11
12
|
chainName: z.ZodString;
|
|
12
13
|
rpcUrl: z.ZodString;
|
|
13
|
-
schemaRegistryAddress: z.ZodString;
|
|
14
|
-
attestationAddress: z.ZodString;
|
|
15
14
|
}, z.core.$strip>;
|
|
16
15
|
/**
|
|
17
16
|
* Configuration options for creating an EAS client.
|
|
18
17
|
* Combines EAS-specific options with base Viem client options.
|
|
19
|
-
*
|
|
20
|
-
* @property schemaRegistryAddress - The address of the EAS Schema Registry contract
|
|
21
|
-
* @property attestationAddress - The address of the EAS Attestation contract
|
|
22
|
-
* @property accessToken - Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_')
|
|
23
|
-
* @property chainId - The chain ID to connect to
|
|
24
|
-
* @property chainName - The name of the chain to connect to
|
|
25
|
-
* @property rpcUrl - The RPC URL to connect to (must be a valid URL)
|
|
26
18
|
*/
|
|
27
|
-
type ClientOptions = z.infer<typeof ClientOptionsSchema
|
|
19
|
+
type ClientOptions = z.infer<typeof ClientOptionsSchema>;
|
|
28
20
|
|
|
29
21
|
/**
|
|
30
22
|
* Supported field types for EAS schema fields.
|
|
@@ -44,26 +36,24 @@ declare const EAS_FIELD_TYPES: {
|
|
|
44
36
|
type EASFieldType = keyof typeof EAS_FIELD_TYPES;
|
|
45
37
|
/**
|
|
46
38
|
* Represents a single field in an EAS schema.
|
|
47
|
-
*
|
|
48
|
-
* @property name - The name of the field
|
|
49
|
-
* @property type - The Solidity type of the field
|
|
50
|
-
* @property description - Optional description of the field's purpose
|
|
51
39
|
*/
|
|
52
40
|
interface SchemaField {
|
|
41
|
+
/** The name of the field */
|
|
53
42
|
name: string;
|
|
43
|
+
/** The Solidity type of the field */
|
|
54
44
|
type: EASFieldType;
|
|
45
|
+
/** Optional description of the field's purpose */
|
|
55
46
|
description?: string;
|
|
56
47
|
}
|
|
57
48
|
/**
|
|
58
49
|
* Options for registering a new schema in the EAS Schema Registry.
|
|
59
|
-
*
|
|
60
|
-
* @property fields - Array of fields that make up the schema
|
|
61
|
-
* @property resolverAddress - Address of the resolver contract that will handle attestations
|
|
62
|
-
* @property revocable - Whether attestations using this schema can be revoked
|
|
63
50
|
*/
|
|
64
51
|
interface RegisterSchemaOptions {
|
|
52
|
+
/** Array of fields that make up the schema */
|
|
65
53
|
fields: SchemaField[];
|
|
54
|
+
/** Address of the resolver contract that will handle attestations */
|
|
66
55
|
resolverAddress: string;
|
|
56
|
+
/** Whether attestations using this schema can be revoked */
|
|
67
57
|
revocable: boolean;
|
|
68
58
|
}
|
|
69
59
|
|
package/dist/eas.mjs
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import {SchemaRegistry}from'@ethereum-attestation-service/eas-sdk';import {UrlSchema,AccessTokenSchema,validate}from'@settlemint/sdk-utils/validation';import {getPublicClient,getWalletClient}from'@settlemint/sdk-viem';import {isAddress}from'viem';import {z}from'zod/v4';import {JsonRpcProvider,Wallet}from'ethers';var u=z.object({schemaRegistryAddress:z.string().refine(isAddress,"Invalid Ethereum address format"),attestationAddress:z.string().refine(isAddress,"Invalid Ethereum address format")
|
|
1
|
+
import {SchemaRegistry}from'@ethereum-attestation-service/eas-sdk';import {UrlSchema,AccessTokenSchema,validate}from'@settlemint/sdk-utils/validation';import {getPublicClient,getWalletClient}from'@settlemint/sdk-viem';import {isAddress}from'viem';import {z}from'zod/v4';import {JsonRpcProvider,Wallet}from'ethers';var u=z.object({schemaRegistryAddress:z.string().refine(isAddress,"Invalid Ethereum address format"),attestationAddress:z.string().refine(isAddress,"Invalid Ethereum address format"),accessToken:AccessTokenSchema,chainId:z.string().min(1),chainName:z.string().min(1),rpcUrl:UrlSchema});function y(e){let{chain:t,transport:r}=e;if(!t)throw new Error("Chain is required");let n={chainId:t.id,name:t.name,ensAddress:t.contracts?.ensRegistry?.address};if(r.type==="fallback"){let a=r.transports.map(({value:i})=>{if(!i?.url)return null;try{return new JsonRpcProvider(i.url,n)}catch{return null}}).filter(i=>i!=null);if(a.length===0)throw new Error("No valid RPC URLs found");return a[0]}return new JsonRpcProvider(r.url,n)}function g(e){let{account:t,chain:r,transport:n}=e;if(!r)throw new Error("Chain is required");if(!t)throw new Error("Account is required");let a={chainId:r.id,name:r.name,ensAddress:r.contracts?.ensRegistry?.address},i=new JsonRpcProvider(n.url,a),o=t.privateKey;if(!o||typeof o!="string")throw new Error("Private key is required and must be a string");return new Wallet(o,i)}var d={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function C(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 F(e){if(!(e in d))throw new Error(`Invalid field type: ${e}. Must be one of: ${Object.keys(d).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(C(r.name),F(r.type),t.has(r.name))throw new Error(`Duplicate field name: ${r.name}`);t.add(r.name);}}function w(e){return h(e),e.map(t=>`${t.type} ${t.name}`).join(", ")}function K(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})(),n=y(t),a=g(r),i=new SchemaRegistry(e.schemaRegistryAddress);i.connect(a);async function o(s){h(s.fields);let m=w(s.fields);try{await n.getNetwork();let c=await i.register({schema:m,resolverAddress:s.resolverAddress,revocable:s.revocable});return await c.wait(),c.toString()}catch(c){throw new Error(`Failed to register schema: ${c.message}`,{cause:c})}}async function S(s){try{return await n.getNetwork(),(await i.getSchema({uid:s})).toString()}catch(m){throw new Error(`Failed to get schema: ${m.message}`)}}return {registerSchema:o,getSchema:S}}export{d as EAS_FIELD_TYPES,K 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/client-options.schema.ts","../src/ethers-adapter.ts","../src/types.ts","../src/validation.ts","../src/eas.ts"],"names":["ClientOptionsSchema","z","isAddress","AccessTokenSchema","UrlSchema","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":"0TASO,IAAMA,CAAsBC,CAAAA,CAAAA,CAAE,OAAO,CAC1C,qBAAA,CAAuBA,CAAE,CAAA,MAAA,EAAS,CAAA,MAAA,CAAOC,SAAW,CAAA,iCAAiC,EACrF,kBAAoBD,CAAAA,CAAAA,CAAE,MAAO,EAAA,CAAE,MAAOC,CAAAA,SAAAA,CAAW,iCAAiC,CAAA,CAClF,GAAGD,CAAE,CAAA,MAAA,CAAO,CACV,WAAA,CAAaE,iBACb,CAAA,OAAA,CAASF,CAAE,CAAA,MAAA,GAAS,GAAI,CAAA,CAAC,CACzB,CAAA,SAAA,CAAWA,CAAE,CAAA,MAAA,EAAS,CAAA,GAAA,CAAI,CAAC,CAC3B,CAAA,MAAA,CAAQG,SACV,CAAC,CAAE,CAAA,KACL,CAAC,CAAA,C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Options as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod/v4\";\n\n/**\n * Schema for validating EAS client configuration options.\n * Extends the base Viem client options with EAS-specific requirements.\n */\nexport const ClientOptionsSchema = z.object({\n schemaRegistryAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n attestationAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n ...z.object({\n accessToken: AccessTokenSchema,\n chainId: z.string().min(1),\n chainName: z.string().min(1),\n rpcUrl: UrlSchema,\n }).shape,\n});\n\n/**\n * Configuration options for creating an EAS client.\n * Combines EAS-specific options with base Viem client options.\n *\n * @property schemaRegistryAddress - The address of the EAS Schema Registry contract\n * @property attestationAddress - The address of the EAS Attestation contract\n * @property accessToken - Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_')\n * @property chainId - The chain ID to connect to\n * @property chainName - The name of the chain to connect to\n * @property rpcUrl - The RPC URL to connect to (must be a valid URL)\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","/**\n * Supported field types for EAS schema fields.\n * Maps to the Solidity types that can be used in EAS schemas.\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\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Represents a single field in an EAS schema.\n *\n * @property name - The name of the field\n * @property type - The Solidity type of the field\n * @property description - Optional description of the field's purpose\n */\nexport interface SchemaField {\n name: string;\n type: EASFieldType;\n description?: string;\n}\n\n/**\n * Options for registering a new schema in the EAS Schema Registry.\n *\n * @property fields - Array of fields that make up the schema\n * @property resolverAddress - Address of the resolver contract that will handle attestations\n * @property revocable - Whether attestations using this schema can be revoked\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// Re-export types and constants\nexport type { ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nexport type { RegisterSchemaOptions, SchemaField, EASFieldType } from \"./types.js\";\nexport { EAS_FIELD_TYPES } from \"./types.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}`, { cause: error });\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"]}
|
|
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","isAddress","AccessTokenSchema","UrlSchema","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","getWalletCl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AAgB,OAAO,CAAA,CAAA,CAAI,CAAE,KAAOA,CAAAA,CAAM,CAAC,CAC5F,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 { AccessTokenSchema, UrlSchema } from \"@settlemint/sdk-utils/validation\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod/v4\";\n\n/**\n * Schema for validating EAS client configuration options.\n * Extends the base Viem client options with EAS-specific requirements.\n */\nexport const ClientOptionsSchema = z.object({\n /** The address of the EAS Schema Registry contract */\n schemaRegistryAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n /** The address of the EAS Attestation contract */\n attestationAddress: z.string().refine(isAddress, \"Invalid Ethereum address format\"),\n /** Access token for the RPC provider (must start with 'sm_aat_' or 'sm_pat_') */\n accessToken: AccessTokenSchema,\n /** The chain ID to connect to */\n chainId: z.string().min(1),\n /** The name of the chain to connect to */\n chainName: z.string().min(1),\n /** The RPC URL to connect to (must be a valid URL) */\n rpcUrl: UrlSchema,\n});\n\n/**\n * Configuration options for creating an EAS client.\n * Combines EAS-specific options with base Viem client options.\n */\nexport type ClientOptions = z.infer<typeof ClientOptionsSchema>;\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","/**\n * Supported field types for EAS schema fields.\n * Maps to the Solidity types that can be used in EAS schemas.\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\nexport type EASFieldType = keyof typeof EAS_FIELD_TYPES;\n\n/**\n * Represents a single field in an EAS schema.\n */\nexport interface SchemaField {\n /** The name of the field */\n name: string;\n /** The Solidity type of the field */\n type: EASFieldType;\n /** Optional description of the field's purpose */\n description?: string;\n}\n\n/**\n * Options for registering a new schema in the EAS Schema Registry.\n */\nexport interface RegisterSchemaOptions {\n /** Array of fields that make up the schema */\n fields: SchemaField[];\n /** Address of the resolver contract that will handle attestations */\n resolverAddress: string;\n /** Whether attestations using this schema can be revoked */\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// Re-export types and constants\nexport type { ClientOptions, ClientOptionsSchema } from \"./client-options.schema.js\";\nexport type { RegisterSchemaOptions, SchemaField, EASFieldType } from \"./types.js\";\nexport { EAS_FIELD_TYPES } from \"./types.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}`, { cause: error });\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.3.2-
|
|
4
|
+
"version": "2.3.2-pr9d565676",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@ethereum-attestation-service/eas-sdk": "^2",
|
|
55
|
-
"@settlemint/sdk-utils": "2.3.2-
|
|
56
|
-
"@settlemint/sdk-viem": "2.3.2-
|
|
55
|
+
"@settlemint/sdk-utils": "2.3.2-pr9d565676",
|
|
56
|
+
"@settlemint/sdk-viem": "2.3.2-pr9d565676",
|
|
57
57
|
"ethers": "^6",
|
|
58
58
|
"viem": "^2"
|
|
59
59
|
},
|