@settlemint/sdk-eas 2.2.3 → 2.3.0-prf341a7af
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 +29 -17
- package/dist/eas.cjs.map +1 -1
- package/dist/eas.d.cts +1 -1
- package/dist/eas.d.ts +1 -1
- package/dist/eas.mjs.map +1 -1
- package/package.json +3 -3
package/README.md
CHANGED
|
@@ -36,6 +36,7 @@
|
|
|
36
36
|
- [Type Aliases](#type-aliases)
|
|
37
37
|
- [ClientOptions](#clientoptions)
|
|
38
38
|
- [Variables](#variables)
|
|
39
|
+
- [ClientOptionsSchema](#clientoptionsschema)
|
|
39
40
|
- [EAS\_FIELD\_TYPES](#eas_field_types)
|
|
40
41
|
- [Contributing](#contributing)
|
|
41
42
|
- [License](#license)
|
|
@@ -52,7 +53,7 @@ The SettleMint EAS SDK provides a lightweight wrapper for the Ethereum Attestati
|
|
|
52
53
|
|
|
53
54
|
> **createEASClient**(`options`): `object`
|
|
54
55
|
|
|
55
|
-
Defined in: [eas.ts:36](https://github.com/settlemint/sdk/blob/v2.
|
|
56
|
+
Defined in: [sdk/eas/src/eas.ts:36](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/eas.ts#L36)
|
|
56
57
|
|
|
57
58
|
Creates an EAS client for interacting with the Ethereum Attestation Service.
|
|
58
59
|
|
|
@@ -70,8 +71,8 @@ An object containing the EAS client instance
|
|
|
70
71
|
|
|
71
72
|
| Name | Type | Defined in |
|
|
72
73
|
| ------ | ------ | ------ |
|
|
73
|
-
| `getSchema()` | (`uid`) => `Promise`\<`string`\> | [eas.ts:96](https://github.com/settlemint/sdk/blob/v2.
|
|
74
|
-
| `registerSchema()` | (`options`) => `Promise`\<`string`\> | [eas.ts:95](https://github.com/settlemint/sdk/blob/v2.
|
|
74
|
+
| `getSchema()` | (`uid`) => `Promise`\<`string`\> | [sdk/eas/src/eas.ts:96](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/eas.ts#L96) |
|
|
75
|
+
| `registerSchema()` | (`options`) => `Promise`\<`string`\> | [sdk/eas/src/eas.ts:95](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/eas.ts#L95) |
|
|
75
76
|
|
|
76
77
|
##### Throws
|
|
77
78
|
|
|
@@ -96,7 +97,7 @@ const client = createEASClient({
|
|
|
96
97
|
|
|
97
98
|
#### RegisterSchemaOptions
|
|
98
99
|
|
|
99
|
-
Defined in: [types.ts:39](https://github.com/settlemint/sdk/blob/v2.
|
|
100
|
+
Defined in: [sdk/eas/src/types.ts:39](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L39)
|
|
100
101
|
|
|
101
102
|
Options for registering a new schema in the EAS Schema Registry.
|
|
102
103
|
|
|
@@ -104,7 +105,7 @@ Options for registering a new schema in the EAS Schema Registry.
|
|
|
104
105
|
|
|
105
106
|
#### SchemaField
|
|
106
107
|
|
|
107
|
-
Defined in: [types.ts:26](https://github.com/settlemint/sdk/blob/v2.
|
|
108
|
+
Defined in: [sdk/eas/src/types.ts:26](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L26)
|
|
108
109
|
|
|
109
110
|
Represents a single field in an EAS schema.
|
|
110
111
|
|
|
@@ -112,20 +113,31 @@ Represents a single field in an EAS schema.
|
|
|
112
113
|
|
|
113
114
|
#### ClientOptions
|
|
114
115
|
|
|
115
|
-
> **ClientOptions** = `z.infer`\<*typeof* `ClientOptionsSchema
|
|
116
|
+
> **ClientOptions** = `z.infer`\<*typeof* [`ClientOptionsSchema`](#clientoptionsschema)\> & `Pick`\<`ViemClientOptions`, `"accessToken"` \| `"chainId"` \| `"chainName"` \| `"rpcUrl"`\>
|
|
116
117
|
|
|
117
|
-
Defined in: [client-options.schema.ts:32](https://github.com/settlemint/sdk/blob/v2.
|
|
118
|
+
Defined in: [sdk/eas/src/client-options.schema.ts:32](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/client-options.schema.ts#L32)
|
|
118
119
|
|
|
119
120
|
Configuration options for creating an EAS client.
|
|
120
121
|
Combines EAS-specific options with base Viem client options.
|
|
121
122
|
|
|
122
123
|
### Variables
|
|
123
124
|
|
|
125
|
+
#### ClientOptionsSchema
|
|
126
|
+
|
|
127
|
+
> `const` **ClientOptionsSchema**: `ZodObject`\<\{ `accessToken`: `ZodString`; `attestationAddress`: `ZodEffects`\<`ZodString`, `` `0x${string}` ``, `string`\>; `chainId`: `ZodString`; `chainName`: `ZodString`; `rpcUrl`: `ZodString`; `schemaRegistryAddress`: `ZodEffects`\<`ZodString`, `` `0x${string}` ``, `string`\>; \}, `"strip"`, `ZodTypeAny`, \{ `accessToken`: `string`; `attestationAddress`: `` `0x${string}` ``; `chainId`: `string`; `chainName`: `string`; `rpcUrl`: `string`; `schemaRegistryAddress`: `` `0x${string}` ``; \}, \{ `accessToken`: `string`; `attestationAddress`: `string`; `chainId`: `string`; `chainName`: `string`; `rpcUrl`: `string`; `schemaRegistryAddress`: `string`; \}\>
|
|
128
|
+
|
|
129
|
+
Defined in: [sdk/eas/src/client-options.schema.ts:10](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/client-options.schema.ts#L10)
|
|
130
|
+
|
|
131
|
+
Schema for validating EAS client configuration options.
|
|
132
|
+
Extends the base Viem client options with EAS-specific requirements.
|
|
133
|
+
|
|
134
|
+
***
|
|
135
|
+
|
|
124
136
|
#### EAS\_FIELD\_TYPES
|
|
125
137
|
|
|
126
138
|
> `const` **EAS\_FIELD\_TYPES**: `object`
|
|
127
139
|
|
|
128
|
-
Defined in: [types.ts:5](https://github.com/settlemint/sdk/blob/v2.
|
|
140
|
+
Defined in: [sdk/eas/src/types.ts:5](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L5)
|
|
129
141
|
|
|
130
142
|
Supported field types for EAS schema fields.
|
|
131
143
|
Maps to the Solidity types that can be used in EAS schemas.
|
|
@@ -134,15 +146,15 @@ Maps to the Solidity types that can be used in EAS schemas.
|
|
|
134
146
|
|
|
135
147
|
| Name | Type | Default value | Defined in |
|
|
136
148
|
| ------ | ------ | ------ | ------ |
|
|
137
|
-
| <a id="address"></a> `address` | `"address"` | `"address"` | [types.ts:7](https://github.com/settlemint/sdk/blob/v2.
|
|
138
|
-
| <a id="bool"></a> `bool` | `"bool"` | `"bool"` | [types.ts:8](https://github.com/settlemint/sdk/blob/v2.
|
|
139
|
-
| <a id="bytes"></a> `bytes` | `"bytes"` | `"bytes"` | [types.ts:9](https://github.com/settlemint/sdk/blob/v2.
|
|
140
|
-
| <a id="bytes32"></a> `bytes32` | `"bytes32"` | `"bytes32"` | [types.ts:10](https://github.com/settlemint/sdk/blob/v2.
|
|
141
|
-
| <a id="int256"></a> `int256` | `"int256"` | `"int256"` | [types.ts:12](https://github.com/settlemint/sdk/blob/v2.
|
|
142
|
-
| <a id="int8"></a> `int8` | `"int8"` | `"int8"` | [types.ts:14](https://github.com/settlemint/sdk/blob/v2.
|
|
143
|
-
| <a id="string"></a> `string` | `"string"` | `"string"` | [types.ts:6](https://github.com/settlemint/sdk/blob/v2.
|
|
144
|
-
| <a id="uint256"></a> `uint256` | `"uint256"` | `"uint256"` | [types.ts:11](https://github.com/settlemint/sdk/blob/v2.
|
|
145
|
-
| <a id="uint8"></a> `uint8` | `"uint8"` | `"uint8"` | [types.ts:13](https://github.com/settlemint/sdk/blob/v2.
|
|
149
|
+
| <a id="address"></a> `address` | `"address"` | `"address"` | [sdk/eas/src/types.ts:7](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L7) |
|
|
150
|
+
| <a id="bool"></a> `bool` | `"bool"` | `"bool"` | [sdk/eas/src/types.ts:8](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L8) |
|
|
151
|
+
| <a id="bytes"></a> `bytes` | `"bytes"` | `"bytes"` | [sdk/eas/src/types.ts:9](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L9) |
|
|
152
|
+
| <a id="bytes32"></a> `bytes32` | `"bytes32"` | `"bytes32"` | [sdk/eas/src/types.ts:10](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L10) |
|
|
153
|
+
| <a id="int256"></a> `int256` | `"int256"` | `"int256"` | [sdk/eas/src/types.ts:12](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L12) |
|
|
154
|
+
| <a id="int8"></a> `int8` | `"int8"` | `"int8"` | [sdk/eas/src/types.ts:14](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L14) |
|
|
155
|
+
| <a id="string"></a> `string` | `"string"` | `"string"` | [sdk/eas/src/types.ts:6](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L6) |
|
|
156
|
+
| <a id="uint256"></a> `uint256` | `"uint256"` | `"uint256"` | [sdk/eas/src/types.ts:11](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L11) |
|
|
157
|
+
| <a id="uint8"></a> `uint8` | `"uint8"` | `"uint8"` | [sdk/eas/src/types.ts:13](https://github.com/settlemint/sdk/blob/v2.3.0/sdk/eas/src/types.ts#L13) |
|
|
146
158
|
|
|
147
159
|
## Contributing
|
|
148
160
|
|
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":"yOASO,IAAMA,CA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,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 type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod\";\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 } 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":"yOASO,IAAMA,CAAsBC,CAAAA,KAAAA,CAAE,OAAO,CAC1C,qBAAA,CAAuBA,KAAE,CAAA,MAAA,EAAS,CAAA,MAAA,CAAOC,cAAW,CAAA,iCAAiC,EACrF,kBAAoBD,CAAAA,KAAAA,CAAE,MAAO,EAAA,CAAE,MAAOC,CAAAA,cAAAA,CAAW,iCAAiC,CAAA,CAClF,GAAGD,KAAE,CAAA,MAAA,CAAO,CACV,WAAA,CAAaE,4BACb,CAAA,OAAA,CAASF,KAAE,CAAA,MAAA,GAAS,GAAI,CAAA,CAAC,CACzB,CAAA,SAAA,CAAWA,KAAE,CAAA,MAAA,EAAS,CAAA,GAAA,CAAI,CAAC,CAC3B,CAAA,MAAA,CAAQG,oBACV,CAAC,CAAE,CAAA,KACL,CAAC,CAAA,CCZM,SAASC,CAAuBC,CAAAA,CAAAA,CAAgC,CACrE,GAAM,CAAE,KAAAC,CAAAA,CAAAA,CAAO,SAAAC,CAAAA,CAAU,CAAIF,CAAAA,CAAAA,CAC7B,GAAI,CAACC,CAAAA,CAAO,MAAM,IAAI,KAAM,CAAA,mBAAmB,CAE/C,CAAA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7B,eAAeG,CAAAA,CAAeT,CAAiD,CAAA,CAC7EN,CAAqBM,CAAAA,CAAAA,CAAQ,MAAM,CAAA,CACnC,IAAMU,CAASZ,CAAAA,CAAAA,CAAkBE,CAAQ,CAAA,MAAM,CAE/C,CAAA,GAAI,CAEF,MAAMhB,EAAS,UAAW,EAAA,CAE1B,IAAM2B,CAAAA,CAAK,MAAMJ,CAAAA,CAAe,QAAS,CAAA,CACvC,OAAAG,CACA,CAAA,eAAA,CAAiBV,CAAQ,CAAA,eAAA,CACzB,SAAWA,CAAAA,CAAAA,CAAQ,SACrB,CAAC,EAED,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 type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod\";\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"]}
|
package/dist/eas.d.cts
CHANGED
|
@@ -107,4 +107,4 @@ declare function createEASClient(options: ClientOptions): {
|
|
|
107
107
|
getSchema: (uid: string) => Promise<string>;
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
export { type ClientOptions, type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField, createEASClient };
|
|
110
|
+
export { type ClientOptions, ClientOptionsSchema, type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField, createEASClient };
|
package/dist/eas.d.ts
CHANGED
|
@@ -107,4 +107,4 @@ declare function createEASClient(options: ClientOptions): {
|
|
|
107
107
|
getSchema: (uid: string) => Promise<string>;
|
|
108
108
|
};
|
|
109
109
|
|
|
110
|
-
export { type ClientOptions, type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField, createEASClient };
|
|
110
|
+
export { type ClientOptions, ClientOptionsSchema, type EASFieldType, EAS_FIELD_TYPES, type RegisterSchemaOptions, type SchemaField, createEASClient };
|
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":"uTASO,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,CCZM,SAASC,CAAuBC,CAAAA,CAAAA,CAAgC,CACrE,GAAM,CAAE,KAAAC,CAAAA,CAAAA,CAAO,SAAAC,CAAAA,CAAU,CAAIF,CAAAA,CAAAA,CAC7B,GAAI,CAACC,CAAAA,CAAO,MAAM,IAAI,KAAM,CAAA,mBAAmB,CAE/C,C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eAAeG,CAAAA,CAAeT,CAAiD,CAAA,CAC7EN,CAAqBM,CAAAA,CAAAA,CAAQ,MAAM,CAAA,CACnC,IAAMU,CAASZ,CAAAA,CAAAA,CAAkBE,CAAQ,CAAA,MAAM,CAE/C,CAAA,GAAI,CAEF,MAAMhB,EAAS,UAAW,EAAA,CAE1B,IAAM2B,CAAAA,CAAK,MAAMJ,CAAAA,CAAe,QAAS,CAAA,CACvC,OAAAG,CACA,CAAA,eAAA,CAAiBV,CAAQ,CAAA,eAAA,CACzB,SAAWA,CAAAA,CAAAA,CAAQ,SACrB,CAAC,EAED,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.mjs","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\";\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 } 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":"uTASO,IAAMA,CAAsBC,CAAAA,CAAAA,CAAE,OAAO,CAC1C,qBAAA,CAAuBA,CAAE,CAAA,MAAA,EAAS,CAAA,MAAA,CAAOC,SAAW,CAAA,iCAAiC,EACrF,kBAAoBD,CAAAA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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 type { ClientOptions as ViemClientOptions } from \"@settlemint/sdk-viem\";\nimport { isAddress } from \"viem\";\nimport { z } from \"zod\";\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"]}
|
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.
|
|
4
|
+
"version": "2.3.0-prf341a7af",
|
|
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.
|
|
56
|
-
"@settlemint/sdk-viem": "2.
|
|
55
|
+
"@settlemint/sdk-utils": "2.3.0-prf341a7af",
|
|
56
|
+
"@settlemint/sdk-viem": "2.3.0-prf341a7af",
|
|
57
57
|
"ethers": "^6",
|
|
58
58
|
"viem": "^2"
|
|
59
59
|
},
|