@settlemint/sdk-eas 2.3.2 → 2.3.3-pr0702b3ed
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 +41 -19
- package/dist/browser/eas.d.ts +97 -0
- package/dist/browser/eas.js +10401 -0
- package/dist/browser/eas.js.map +1 -0
- package/dist/eas.cjs +10420 -1
- package/dist/eas.cjs.map +1 -1
- package/dist/eas.d.cts +43 -42
- package/dist/eas.d.ts +43 -42
- package/dist/eas.js +10402 -0
- package/dist/eas.js.map +1 -0
- package/package.json +7 -7
- package/dist/eas.mjs +0 -2
- package/dist/eas.mjs.map +0 -1
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.
|
|
4
|
+
"version": "2.3.3-pr0702b3ed",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
7
7
|
"license": "FSL-1.1-MIT",
|
|
@@ -22,14 +22,14 @@
|
|
|
22
22
|
},
|
|
23
23
|
"files": ["dist"],
|
|
24
24
|
"main": "./dist/eas.cjs",
|
|
25
|
-
"module": "./dist/eas.
|
|
25
|
+
"module": "./dist/eas.js",
|
|
26
26
|
"types": "./dist/eas.d.ts",
|
|
27
27
|
"exports": {
|
|
28
28
|
"./package.json": "./package.json",
|
|
29
29
|
".": {
|
|
30
30
|
"import": {
|
|
31
31
|
"types": "./dist/eas.d.ts",
|
|
32
|
-
"default": "./dist/eas.
|
|
32
|
+
"default": "./dist/eas.js"
|
|
33
33
|
},
|
|
34
34
|
"require": {
|
|
35
35
|
"types": "./dist/eas.d.cts",
|
|
@@ -38,8 +38,8 @@
|
|
|
38
38
|
}
|
|
39
39
|
},
|
|
40
40
|
"scripts": {
|
|
41
|
-
"build": "
|
|
42
|
-
"dev": "
|
|
41
|
+
"build": "tsdown",
|
|
42
|
+
"dev": "tsdown --watch",
|
|
43
43
|
"publint": "publint run --strict",
|
|
44
44
|
"attw": "attw --pack .",
|
|
45
45
|
"test": "bun test",
|
|
@@ -52,8 +52,8 @@
|
|
|
52
52
|
"devDependencies": {},
|
|
53
53
|
"dependencies": {
|
|
54
54
|
"@ethereum-attestation-service/eas-sdk": "^2",
|
|
55
|
-
"@settlemint/sdk-utils": "2.3.
|
|
56
|
-
"@settlemint/sdk-viem": "2.3.
|
|
55
|
+
"@settlemint/sdk-utils": "2.3.3-pr0702b3ed",
|
|
56
|
+
"@settlemint/sdk-viem": "2.3.3-pr0702b3ed",
|
|
57
57
|
"ethers": "^6",
|
|
58
58
|
"viem": "^2"
|
|
59
59
|
},
|
package/dist/eas.mjs
DELETED
|
@@ -1,2 +0,0 @@
|
|
|
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"),...z.object({accessToken:AccessTokenSchema,chainId:z.string().min(1),chainName:z.string().min(1),rpcUrl:UrlSchema}).shape});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 s=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(s.length===0)throw new Error("No valid RPC URLs found");return s[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 s={chainId:r.id,name:r.name,ensAddress:r.contracts?.ensRegistry?.address},i=new JsonRpcProvider(n.url,s),c=t.privateKey;if(!c||typeof c!="string")throw new Error("Private key is required and must be a string");return new Wallet(c,i)}var d={string:"string",address:"address",bool:"bool",bytes:"bytes",bytes32:"bytes32",uint256:"uint256",int256:"int256",uint8:"uint8",int8:"int8"};function b(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(b(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),s=g(r),i=new SchemaRegistry(e.schemaRegistryAddress);i.connect(s);async function c(a){h(a.fields);let m=w(a.fields);try{await n.getNetwork();let l=await i.register({schema:m,resolverAddress:a.resolverAddress,revocable:a.revocable});return await l.wait(),l.toString()}catch(l){throw new Error(`Failed to register schema: ${l.message}`,{cause:l})}}async function S(a){try{return await n.getNetwork(),(await i.getSchema({uid:a})).toString()}catch(m){throw new Error(`Failed to get schema: ${m.message}`)}}return {registerSchema:c,getSchema:S}}export{d as EAS_FIELD_TYPES,K as createEASClient};//# sourceMappingURL=eas.mjs.map
|
|
2
|
-
//# sourceMappingURL=eas.mjs.map
|
package/dist/eas.mjs.map
DELETED
|
@@ -1 +0,0 @@
|
|
|
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,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,IAAME,EAAU,CACd,OAAA,CAASF,CAAM,CAAA,EAAA,CACf,IAAMA,CAAAA,CAAAA,CAAM,IACZ,CAAA,UAAA,CAAYA,EAAM,SAAW,EAAA,WAAA,EAAa,OAC5C,CAAA,CAEA,GAAIC,CAAAA,CAAU,IAAS,GAAA,UAAA,CAAY,CACjC,IAAME,CAAAA,CAAaF,C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AMJ,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/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"]}
|