@agirails/sdk 2.5.2 → 2.5.4

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.
Files changed (172) hide show
  1. package/dist/ACTPClient.d.ts +18 -0
  2. package/dist/ACTPClient.d.ts.map +1 -1
  3. package/dist/ACTPClient.js +67 -22
  4. package/dist/ACTPClient.js.map +1 -1
  5. package/dist/adapters/BasicAdapter.d.ts +12 -0
  6. package/dist/adapters/BasicAdapter.d.ts.map +1 -1
  7. package/dist/adapters/BasicAdapter.js +30 -4
  8. package/dist/adapters/BasicAdapter.js.map +1 -1
  9. package/dist/adapters/StandardAdapter.d.ts +20 -3
  10. package/dist/adapters/StandardAdapter.d.ts.map +1 -1
  11. package/dist/adapters/StandardAdapter.js +45 -11
  12. package/dist/adapters/StandardAdapter.js.map +1 -1
  13. package/dist/cli/commands/publish.js +16 -4
  14. package/dist/cli/commands/publish.js.map +1 -1
  15. package/dist/cli/commands/register.js +16 -4
  16. package/dist/cli/commands/register.js.map +1 -1
  17. package/dist/cli/commands/tx.js +31 -3
  18. package/dist/cli/commands/tx.js.map +1 -1
  19. package/dist/cli/utils/client.d.ts.map +1 -1
  20. package/dist/cli/utils/client.js +1 -0
  21. package/dist/cli/utils/client.js.map +1 -1
  22. package/dist/config/networks.d.ts +2 -2
  23. package/dist/config/networks.d.ts.map +1 -1
  24. package/dist/config/networks.js +27 -22
  25. package/dist/config/networks.js.map +1 -1
  26. package/dist/level0/request.d.ts.map +1 -1
  27. package/dist/level0/request.js +2 -1
  28. package/dist/level0/request.js.map +1 -1
  29. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  30. package/dist/runtime/BlockchainRuntime.js +11 -5
  31. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  32. package/dist/runtime/MockStateManager.d.ts.map +1 -1
  33. package/dist/runtime/MockStateManager.js +2 -1
  34. package/dist/runtime/MockStateManager.js.map +1 -1
  35. package/dist/utils/IPFSClient.d.ts +3 -1
  36. package/dist/utils/IPFSClient.d.ts.map +1 -1
  37. package/dist/utils/IPFSClient.js +27 -7
  38. package/dist/utils/IPFSClient.js.map +1 -1
  39. package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
  40. package/dist/wallet/AutoWalletProvider.js +52 -18
  41. package/dist/wallet/AutoWalletProvider.js.map +1 -1
  42. package/dist/wallet/SmartWalletRouter.d.ts +116 -0
  43. package/dist/wallet/SmartWalletRouter.d.ts.map +1 -0
  44. package/dist/wallet/SmartWalletRouter.js +212 -0
  45. package/dist/wallet/SmartWalletRouter.js.map +1 -0
  46. package/dist/wallet/aa/DualNonceManager.d.ts +19 -0
  47. package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
  48. package/dist/wallet/aa/DualNonceManager.js +100 -5
  49. package/dist/wallet/aa/DualNonceManager.js.map +1 -1
  50. package/package.json +3 -6
  51. package/src/ACTPClient.ts +0 -1579
  52. package/src/abi/ACTPKernel.json +0 -1356
  53. package/src/abi/AgentRegistry.json +0 -915
  54. package/src/abi/ERC20.json +0 -40
  55. package/src/abi/EscrowVault.json +0 -134
  56. package/src/abi/IdentityRegistry.json +0 -316
  57. package/src/adapters/AdapterRegistry.ts +0 -173
  58. package/src/adapters/AdapterRouter.ts +0 -416
  59. package/src/adapters/BaseAdapter.ts +0 -498
  60. package/src/adapters/BasicAdapter.ts +0 -514
  61. package/src/adapters/IAdapter.ts +0 -292
  62. package/src/adapters/StandardAdapter.ts +0 -555
  63. package/src/adapters/X402Adapter.ts +0 -731
  64. package/src/adapters/index.ts +0 -60
  65. package/src/builders/DeliveryProofBuilder.ts +0 -327
  66. package/src/builders/QuoteBuilder.ts +0 -483
  67. package/src/builders/index.ts +0 -17
  68. package/src/cli/commands/balance.ts +0 -110
  69. package/src/cli/commands/batch.ts +0 -487
  70. package/src/cli/commands/config.ts +0 -231
  71. package/src/cli/commands/deploy-check.ts +0 -364
  72. package/src/cli/commands/deploy-env.ts +0 -120
  73. package/src/cli/commands/diff.ts +0 -141
  74. package/src/cli/commands/init.ts +0 -469
  75. package/src/cli/commands/mint.ts +0 -116
  76. package/src/cli/commands/pay.ts +0 -113
  77. package/src/cli/commands/publish.ts +0 -475
  78. package/src/cli/commands/pull.ts +0 -124
  79. package/src/cli/commands/register.ts +0 -247
  80. package/src/cli/commands/simulate.ts +0 -345
  81. package/src/cli/commands/time.ts +0 -302
  82. package/src/cli/commands/tx.ts +0 -448
  83. package/src/cli/commands/watch.ts +0 -211
  84. package/src/cli/index.ts +0 -134
  85. package/src/cli/utils/client.ts +0 -251
  86. package/src/cli/utils/config.ts +0 -389
  87. package/src/cli/utils/output.ts +0 -465
  88. package/src/cli/utils/wallet.ts +0 -109
  89. package/src/config/agirailsmd.ts +0 -262
  90. package/src/config/networks.ts +0 -275
  91. package/src/config/pendingPublish.ts +0 -237
  92. package/src/config/publishPipeline.ts +0 -359
  93. package/src/config/syncOperations.ts +0 -279
  94. package/src/erc8004/ERC8004Bridge.ts +0 -462
  95. package/src/erc8004/ReputationReporter.ts +0 -468
  96. package/src/erc8004/index.ts +0 -61
  97. package/src/errors/index.ts +0 -427
  98. package/src/index.ts +0 -364
  99. package/src/level0/Provider.ts +0 -117
  100. package/src/level0/ServiceDirectory.ts +0 -131
  101. package/src/level0/index.ts +0 -10
  102. package/src/level0/provide.ts +0 -132
  103. package/src/level0/request.ts +0 -432
  104. package/src/level1/Agent.ts +0 -1426
  105. package/src/level1/index.ts +0 -10
  106. package/src/level1/pricing/PriceCalculator.ts +0 -255
  107. package/src/level1/pricing/PricingStrategy.ts +0 -198
  108. package/src/level1/types/Job.ts +0 -179
  109. package/src/level1/types/Options.ts +0 -291
  110. package/src/level1/types/index.ts +0 -8
  111. package/src/protocol/ACTPKernel.ts +0 -808
  112. package/src/protocol/AgentRegistry.ts +0 -559
  113. package/src/protocol/DIDManager.ts +0 -629
  114. package/src/protocol/DIDResolver.ts +0 -554
  115. package/src/protocol/EASHelper.ts +0 -378
  116. package/src/protocol/EscrowVault.ts +0 -255
  117. package/src/protocol/EventMonitor.ts +0 -204
  118. package/src/protocol/MessageSigner.ts +0 -510
  119. package/src/protocol/ProofGenerator.ts +0 -339
  120. package/src/protocol/QuoteBuilder.ts +0 -15
  121. package/src/registry/AgentRegistryClient.ts +0 -202
  122. package/src/runtime/BlockchainRuntime.ts +0 -1015
  123. package/src/runtime/IACTPRuntime.ts +0 -306
  124. package/src/runtime/MockRuntime.ts +0 -1298
  125. package/src/runtime/MockStateManager.ts +0 -576
  126. package/src/runtime/index.ts +0 -25
  127. package/src/runtime/types/MockState.ts +0 -237
  128. package/src/storage/ArchiveBundleBuilder.ts +0 -561
  129. package/src/storage/ArweaveClient.ts +0 -946
  130. package/src/storage/FilebaseClient.ts +0 -790
  131. package/src/storage/index.ts +0 -96
  132. package/src/storage/types.ts +0 -348
  133. package/src/types/adapter.ts +0 -310
  134. package/src/types/agent.ts +0 -79
  135. package/src/types/did.ts +0 -223
  136. package/src/types/eip712.ts +0 -175
  137. package/src/types/erc8004.ts +0 -293
  138. package/src/types/escrow.ts +0 -27
  139. package/src/types/index.ts +0 -17
  140. package/src/types/message.ts +0 -145
  141. package/src/types/state.ts +0 -87
  142. package/src/types/transaction.ts +0 -69
  143. package/src/types/x402.ts +0 -251
  144. package/src/utils/ErrorRecoveryGuide.ts +0 -676
  145. package/src/utils/Helpers.ts +0 -688
  146. package/src/utils/IPFSClient.ts +0 -368
  147. package/src/utils/Logger.ts +0 -484
  148. package/src/utils/NonceManager.ts +0 -591
  149. package/src/utils/RateLimiter.ts +0 -534
  150. package/src/utils/ReceivedNonceTracker.ts +0 -567
  151. package/src/utils/SDKLifecycle.ts +0 -416
  152. package/src/utils/SecureNonce.ts +0 -78
  153. package/src/utils/Semaphore.ts +0 -276
  154. package/src/utils/UsedAttestationTracker.ts +0 -385
  155. package/src/utils/canonicalJson.ts +0 -38
  156. package/src/utils/circuitBreaker.ts +0 -324
  157. package/src/utils/computeTypeHash.ts +0 -48
  158. package/src/utils/fsSafe.ts +0 -80
  159. package/src/utils/index.ts +0 -80
  160. package/src/utils/retry.ts +0 -364
  161. package/src/utils/security.ts +0 -418
  162. package/src/utils/validation.ts +0 -540
  163. package/src/wallet/AutoWalletProvider.ts +0 -299
  164. package/src/wallet/EOAWalletProvider.ts +0 -69
  165. package/src/wallet/IWalletProvider.ts +0 -135
  166. package/src/wallet/aa/BundlerClient.ts +0 -274
  167. package/src/wallet/aa/DualNonceManager.ts +0 -173
  168. package/src/wallet/aa/PaymasterClient.ts +0 -174
  169. package/src/wallet/aa/TransactionBatcher.ts +0 -353
  170. package/src/wallet/aa/UserOpBuilder.ts +0 -246
  171. package/src/wallet/aa/constants.ts +0 -60
  172. package/src/wallet/keystore.ts +0 -240
@@ -1,60 +0,0 @@
1
- /**
2
- * Adapter Layer - Bridges user-friendly API to protocol-level SDK
3
- *
4
- * This module exports all adapter classes and types for the Three-Level API:
5
- * - BaseAdapter: Abstract base with shared utilities
6
- * - BasicAdapter: High-level, opinionated API
7
- * - StandardAdapter: Balanced control API
8
- * - AdapterRegistry: Central registry for adapter management
9
- * - AdapterRouter: Intelligent adapter selection with guard-rails
10
- * - IAdapter: Common interface for all adapters
11
- *
12
- * @module adapters
13
- */
14
-
15
- export {
16
- BaseAdapter,
17
- ValidationError,
18
- DEFAULT_DISPUTE_WINDOW_SECONDS,
19
- DEFAULT_DEADLINE_SECONDS,
20
- MIN_AMOUNT_WEI,
21
- MAX_DEADLINE_HOURS,
22
- MAX_DEADLINE_DAYS,
23
- } from './BaseAdapter';
24
- export { BasicAdapter, BasicPayParams, BasicPayResult } from './BasicAdapter';
25
- export { StandardAdapter, StandardTransactionParams } from './StandardAdapter';
26
- export {
27
- X402Adapter,
28
- X402AdapterConfig,
29
- X402PayParams,
30
- X402HttpMethod,
31
- FetchFunction,
32
- ApproveFunction,
33
- RelayPayFunction,
34
- } from './X402Adapter';
35
- export { AdapterRegistry } from './AdapterRegistry';
36
- export { AdapterRouter, AdapterSelectionResult } from './AdapterRouter';
37
- export {
38
- IAdapter,
39
- TransactionStatus,
40
- AdapterTransactionState,
41
- isAdapter,
42
- } from './IAdapter';
43
-
44
- // Re-export runtime interface for convenience
45
- export { IACTPRuntime, CreateTransactionParams } from '../runtime/IACTPRuntime';
46
-
47
- // Re-export adapter types for convenience
48
- export {
49
- AdapterMetadata,
50
- PaymentMetadata,
51
- PaymentIdentity,
52
- UnifiedPayParams,
53
- UnifiedPayResult,
54
- InitialTransactionState,
55
- AdapterMetadataSchema,
56
- PaymentMetadataSchema,
57
- UnifiedPayParamsSchema,
58
- validatePayParams,
59
- safeValidatePayParams,
60
- } from '../types/adapter';
@@ -1,327 +0,0 @@
1
- /**
2
- * DeliveryProofBuilder - AIP-4 Delivery Proof Construction
3
- * Reference: AIP-4 §9.1
4
- *
5
- * Builds complete delivery proofs with:
6
- * - IPFS upload of result data
7
- * - EAS attestation creation
8
- * - EIP-712 signature
9
- * - Canonical JSON hashing
10
- */
11
-
12
- import { Signer, verifyTypedData } from 'ethers';
13
- import { EAS, SchemaEncoder } from '@ethereum-attestation-service/eas-sdk';
14
- import { computeResultHash } from '../utils/canonicalJson';
15
- import { IPFSClient } from '../utils/IPFSClient';
16
- import { NonceManager } from '../utils/NonceManager';
17
- import { DeliveryProofMessage } from '../types/message';
18
- import { AIP4DeliveryProofTypes, AIP4DeliveryProofData, EIP712Domain } from '../types/eip712';
19
-
20
- /**
21
- * AGIRAILS Delivery Schema UID (Base Sepolia)
22
- * Deployed 2025-11-23 - AIP-4 delivery proof schema
23
- * Schema: bytes32 txId, string resultCID, bytes32 resultHash, uint256 deliveredAt
24
- */
25
- export const AGIRAILS_DELIVERY_SCHEMA_UID = '0x1b0ebdf0bd20c28ec9d5362571ce8715a55f46e81c3de2f9b0d8e1b95fb5ffce';
26
-
27
- /**
28
- * Delivery proof build parameters
29
- */
30
- export interface DeliveryProofParams {
31
- txId: string; // bytes32 (0x-prefixed)
32
- provider: string; // DID (e.g., "did:ethr:84532:0x...")
33
- consumer: string; // DID
34
- resultData: any; // Service result data (will be uploaded to IPFS)
35
- metadata?: {
36
- executionTime?: number;
37
- outputFormat?: string;
38
- outputSize?: number;
39
- notes?: string;
40
- };
41
- chainId: number; // 84532 (Base Sepolia) or 8453 (Base Mainnet)
42
- kernelAddress: string; // ACTPKernel contract address
43
- }
44
-
45
- // IPFSClient and NonceManager interfaces imported from utils
46
-
47
- /**
48
- * DeliveryProofBuilder - Main Builder Class
49
- */
50
- export class DeliveryProofBuilder {
51
- constructor(
52
- private ipfs: IPFSClient,
53
- private signer: Signer,
54
- private nonceManager: NonceManager,
55
- private eas: EAS
56
- ) {}
57
-
58
- /**
59
- * Build complete delivery proof
60
- * Reference: AIP-4 §5.1 (Provider workflow steps 1-9)
61
- *
62
- * @param params - Delivery proof parameters
63
- * @returns Delivery proof message, IPFS CID, and attestation UID
64
- */
65
- async build(params: DeliveryProofParams): Promise<{
66
- deliveryProof: DeliveryProofMessage;
67
- deliveryProofCID: string;
68
- attestationUID: string;
69
- }> {
70
- // Step 1: Upload result to IPFS
71
- const resultCID = await this.ipfs.add(JSON.stringify(params.resultData));
72
- await this.ipfs.pin(resultCID); // Permanent pinning
73
-
74
- // Step 2: Compute result hash (canonical JSON)
75
- const resultHash = computeResultHash(params.resultData);
76
-
77
- // Step 3: Create EAS attestation on-chain
78
- const deliveredAt = Math.floor(Date.now() / 1000);
79
-
80
- const schemaEncoder = new SchemaEncoder(
81
- 'bytes32 txId,string resultCID,bytes32 resultHash,uint256 deliveredAt'
82
- );
83
-
84
- // Extract Ethereum address from consumer DID
85
- const consumerAddress = this.extractAddressFromDID(params.consumer);
86
-
87
- const encodedData = schemaEncoder.encodeData([
88
- { name: 'txId', value: params.txId, type: 'bytes32' },
89
- { name: 'resultCID', value: resultCID, type: 'string' },
90
- { name: 'resultHash', value: resultHash, type: 'bytes32' },
91
- { name: 'deliveredAt', value: deliveredAt, type: 'uint256' }
92
- ]);
93
-
94
- const tx = await this.eas.attest({
95
- schema: AGIRAILS_DELIVERY_SCHEMA_UID,
96
- data: {
97
- recipient: consumerAddress,
98
- expirationTime: 0n, // No expiration (use bigint)
99
- revocable: false,
100
- data: encodedData
101
- }
102
- });
103
-
104
- const receipt = await tx.wait();
105
- // EAS SDK returns attestation UID directly in newAttestationUID
106
- const attestationUID = (receipt as any).newAttestationUID || (receipt as any);
107
-
108
- // Step 4: Build delivery proof message (unsigned)
109
- const deliveryProof: DeliveryProofMessage = {
110
- type: 'agirails.delivery.v1',
111
- version: '1.0.0',
112
- txId: params.txId,
113
- provider: params.provider,
114
- consumer: params.consumer,
115
- resultCID,
116
- resultHash,
117
- metadata: params.metadata || {},
118
- easAttestationUID: attestationUID,
119
- deliveredAt,
120
- chainId: params.chainId,
121
- nonce: this.nonceManager.getNextNonce('agirails.delivery.v1'),
122
- signature: '' // Filled in next step
123
- };
124
-
125
- // Step 5: Sign with EIP-712
126
- const signature = await this.signDeliveryProof(deliveryProof, params.kernelAddress);
127
- deliveryProof.signature = signature;
128
-
129
- // Step 6: Upload delivery proof to IPFS
130
- const deliveryProofCID = await this.ipfs.add(JSON.stringify(deliveryProof));
131
- await this.ipfs.pin(deliveryProofCID); // Permanent
132
-
133
- // Record nonce usage
134
- this.nonceManager.recordNonce('agirails.delivery.v1', deliveryProof.nonce);
135
-
136
- return {
137
- deliveryProof,
138
- deliveryProofCID,
139
- attestationUID
140
- };
141
- }
142
-
143
- /**
144
- * Verify delivery proof signature and integrity
145
- * Reference: AIP-4 §5.2 (Consumer verification)
146
- *
147
- * @param deliveryProof - Delivery proof message
148
- * @param resultData - Actual result data (from IPFS)
149
- * @param kernelAddress - ACTPKernel contract address
150
- * @returns true if valid, throws error otherwise
151
- */
152
- async verify(
153
- deliveryProof: DeliveryProofMessage,
154
- resultData: any,
155
- kernelAddress: string
156
- ): Promise<boolean> {
157
- // 1. Verify signature
158
- const recoveredAddress = await this.recoverDeliveryProofSigner(deliveryProof, kernelAddress);
159
- const expectedAddress = this.extractAddressFromDID(deliveryProof.provider);
160
-
161
- if (recoveredAddress.toLowerCase() !== expectedAddress.toLowerCase()) {
162
- throw new Error('Invalid signature: recovered address does not match provider');
163
- }
164
-
165
- // 2. Verify result hash
166
- const computedHash = computeResultHash(resultData);
167
-
168
- if (computedHash !== deliveryProof.resultHash) {
169
- throw new Error('Result hash mismatch - data may be tampered');
170
- }
171
-
172
- // 3. Verify EAS attestation exists and is valid
173
- const attestation = await this.eas.getAttestation(deliveryProof.easAttestationUID);
174
-
175
- if (!attestation) {
176
- throw new Error('Attestation not found on EAS');
177
- }
178
-
179
- if (attestation.schema !== AGIRAILS_DELIVERY_SCHEMA_UID) {
180
- throw new Error(`Invalid attestation schema: expected ${AGIRAILS_DELIVERY_SCHEMA_UID}, got ${attestation.schema}`);
181
- }
182
-
183
- // Check if attestation is revoked (property may not exist in all EAS SDK versions)
184
- if ('revoked' in attestation && (attestation as any).revoked) {
185
- throw new Error('Attestation was revoked');
186
- }
187
-
188
- if ('revocationTime' in attestation && (attestation as any).revocationTime > 0) {
189
- throw new Error('Attestation was revoked');
190
- }
191
-
192
- // 4. Verify attestation data matches delivery proof
193
- const schemaEncoder = new SchemaEncoder(
194
- 'bytes32 txId,string resultCID,bytes32 resultHash,uint256 deliveredAt'
195
- );
196
- const decodedData = schemaEncoder.decodeData(attestation.data);
197
-
198
- const attestationTxId = decodedData.find((d) => d.name === 'txId')?.value.value;
199
- const attestationResultCID = decodedData.find((d) => d.name === 'resultCID')?.value.value;
200
- const attestationResultHash = decodedData.find((d) => d.name === 'resultHash')?.value.value;
201
-
202
- if (attestationTxId !== deliveryProof.txId) {
203
- throw new Error('Attestation txId mismatch');
204
- }
205
-
206
- if (attestationResultCID !== deliveryProof.resultCID) {
207
- throw new Error('Attestation resultCID mismatch');
208
- }
209
-
210
- if (attestationResultHash !== deliveryProof.resultHash) {
211
- throw new Error('Attestation resultHash mismatch');
212
- }
213
-
214
- return true;
215
- }
216
-
217
- /**
218
- * Sign delivery proof with EIP-712
219
- * Reference: AIP-4 §3.3
220
- *
221
- * @param deliveryProof - Delivery proof message (unsigned)
222
- * @param kernelAddress - ACTPKernel contract address
223
- * @returns EIP-712 signature (0x-prefixed, 130 chars)
224
- */
225
- private async signDeliveryProof(
226
- deliveryProof: DeliveryProofMessage,
227
- kernelAddress: string
228
- ): Promise<string> {
229
- const domain: EIP712Domain = {
230
- name: 'AGIRAILS',
231
- version: '1',
232
- chainId: deliveryProof.chainId,
233
- verifyingContract: kernelAddress
234
- };
235
-
236
- const message: AIP4DeliveryProofData = {
237
- txId: deliveryProof.txId,
238
- provider: deliveryProof.provider,
239
- consumer: deliveryProof.consumer,
240
- resultCID: deliveryProof.resultCID,
241
- resultHash: deliveryProof.resultHash,
242
- easAttestationUID: deliveryProof.easAttestationUID,
243
- deliveredAt: deliveryProof.deliveredAt,
244
- chainId: deliveryProof.chainId,
245
- nonce: deliveryProof.nonce
246
- };
247
-
248
- // Sign using ethers v6 signTypedData API
249
- // ethers v6 uses signTypedData() (without underscore)
250
- if ('signTypedData' in this.signer && typeof (this.signer as any).signTypedData === 'function') {
251
- const signature = await (this.signer as any).signTypedData(
252
- domain,
253
- AIP4DeliveryProofTypes,
254
- message
255
- );
256
- return signature;
257
- }
258
-
259
- throw new Error('Signer does not support EIP-712 typed data signing (ethers v6+)');
260
-
261
- }
262
-
263
- /**
264
- * Recover signer address from delivery proof signature
265
- *
266
- * @param deliveryProof - Delivery proof message
267
- * @param kernelAddress - ACTPKernel contract address
268
- * @returns Recovered Ethereum address
269
- */
270
- private async recoverDeliveryProofSigner(
271
- deliveryProof: DeliveryProofMessage,
272
- kernelAddress: string
273
- ): Promise<string> {
274
- const domain: EIP712Domain = {
275
- name: 'AGIRAILS',
276
- version: '1',
277
- chainId: deliveryProof.chainId,
278
- verifyingContract: kernelAddress
279
- };
280
-
281
- const message: AIP4DeliveryProofData = {
282
- txId: deliveryProof.txId,
283
- provider: deliveryProof.provider,
284
- consumer: deliveryProof.consumer,
285
- resultCID: deliveryProof.resultCID,
286
- resultHash: deliveryProof.resultHash,
287
- easAttestationUID: deliveryProof.easAttestationUID,
288
- deliveredAt: deliveryProof.deliveredAt,
289
- chainId: deliveryProof.chainId,
290
- nonce: deliveryProof.nonce
291
- };
292
-
293
- // Recover address using ethers.js verifyTypedData
294
- // Wrap in try-catch to handle low-level cryptographic errors gracefully
295
- try {
296
- const recoveredAddress = verifyTypedData(
297
- domain,
298
- AIP4DeliveryProofTypes,
299
- message,
300
- deliveryProof.signature
301
- );
302
-
303
- return recoveredAddress;
304
- } catch (error: any) {
305
- // Wrap low-level cryptographic errors in meaningful error message
306
- throw new Error(`Invalid signature: ${error.message || 'signature verification failed'}`);
307
- }
308
- }
309
-
310
- /**
311
- * Extract Ethereum address from DID
312
- * Supports: did:ethr:0x... and did:ethr:84532:0x...
313
- *
314
- * @param did - DID string
315
- * @returns Ethereum address (0x-prefixed, checksummed)
316
- */
317
- private extractAddressFromDID(did: string): string {
318
- const parts = did.replace('did:ethr:', '').split(':');
319
- const address = parts.length === 2 ? parts[1] : parts[0];
320
-
321
- if (!address.startsWith('0x') || address.length !== 42) {
322
- throw new Error(`Invalid DID format: ${did}`);
323
- }
324
-
325
- return address;
326
- }
327
- }