@agirails/sdk 2.5.3 → 2.5.5

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 (169) hide show
  1. package/dist/ACTPClient.d.ts +18 -0
  2. package/dist/ACTPClient.d.ts.map +1 -1
  3. package/dist/ACTPClient.js +72 -23
  4. package/dist/ACTPClient.js.map +1 -1
  5. package/dist/adapters/BasicAdapter.d.ts +15 -0
  6. package/dist/adapters/BasicAdapter.d.ts.map +1 -1
  7. package/dist/adapters/BasicAdapter.js +33 -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 +90 -12
  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/config/networks.d.ts +10 -2
  20. package/dist/config/networks.d.ts.map +1 -1
  21. package/dist/config/networks.js +31 -22
  22. package/dist/config/networks.js.map +1 -1
  23. package/dist/level0/request.d.ts.map +1 -1
  24. package/dist/level0/request.js +2 -1
  25. package/dist/level0/request.js.map +1 -1
  26. package/dist/runtime/BlockchainRuntime.d.ts.map +1 -1
  27. package/dist/runtime/BlockchainRuntime.js +11 -5
  28. package/dist/runtime/BlockchainRuntime.js.map +1 -1
  29. package/dist/utils/IPFSClient.d.ts +3 -1
  30. package/dist/utils/IPFSClient.d.ts.map +1 -1
  31. package/dist/utils/IPFSClient.js +27 -7
  32. package/dist/utils/IPFSClient.js.map +1 -1
  33. package/dist/wallet/AutoWalletProvider.d.ts +11 -1
  34. package/dist/wallet/AutoWalletProvider.d.ts.map +1 -1
  35. package/dist/wallet/AutoWalletProvider.js +84 -19
  36. package/dist/wallet/AutoWalletProvider.js.map +1 -1
  37. package/dist/wallet/IWalletProvider.d.ts +34 -0
  38. package/dist/wallet/IWalletProvider.d.ts.map +1 -1
  39. package/dist/wallet/SmartWalletRouter.d.ts +128 -0
  40. package/dist/wallet/SmartWalletRouter.d.ts.map +1 -0
  41. package/dist/wallet/SmartWalletRouter.js +248 -0
  42. package/dist/wallet/SmartWalletRouter.js.map +1 -0
  43. package/dist/wallet/aa/DualNonceManager.d.ts +26 -1
  44. package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
  45. package/dist/wallet/aa/DualNonceManager.js +140 -6
  46. package/dist/wallet/aa/DualNonceManager.js.map +1 -1
  47. package/package.json +3 -6
  48. package/src/ACTPClient.ts +0 -1579
  49. package/src/abi/ACTPKernel.json +0 -1356
  50. package/src/abi/AgentRegistry.json +0 -915
  51. package/src/abi/ERC20.json +0 -40
  52. package/src/abi/EscrowVault.json +0 -134
  53. package/src/abi/IdentityRegistry.json +0 -316
  54. package/src/adapters/AdapterRegistry.ts +0 -173
  55. package/src/adapters/AdapterRouter.ts +0 -416
  56. package/src/adapters/BaseAdapter.ts +0 -498
  57. package/src/adapters/BasicAdapter.ts +0 -514
  58. package/src/adapters/IAdapter.ts +0 -292
  59. package/src/adapters/StandardAdapter.ts +0 -555
  60. package/src/adapters/X402Adapter.ts +0 -731
  61. package/src/adapters/index.ts +0 -60
  62. package/src/builders/DeliveryProofBuilder.ts +0 -327
  63. package/src/builders/QuoteBuilder.ts +0 -483
  64. package/src/builders/index.ts +0 -17
  65. package/src/cli/commands/balance.ts +0 -110
  66. package/src/cli/commands/batch.ts +0 -487
  67. package/src/cli/commands/config.ts +0 -231
  68. package/src/cli/commands/deploy-check.ts +0 -364
  69. package/src/cli/commands/deploy-env.ts +0 -120
  70. package/src/cli/commands/diff.ts +0 -141
  71. package/src/cli/commands/init.ts +0 -469
  72. package/src/cli/commands/mint.ts +0 -116
  73. package/src/cli/commands/pay.ts +0 -113
  74. package/src/cli/commands/publish.ts +0 -475
  75. package/src/cli/commands/pull.ts +0 -124
  76. package/src/cli/commands/register.ts +0 -247
  77. package/src/cli/commands/simulate.ts +0 -345
  78. package/src/cli/commands/time.ts +0 -302
  79. package/src/cli/commands/tx.ts +0 -448
  80. package/src/cli/commands/watch.ts +0 -211
  81. package/src/cli/index.ts +0 -134
  82. package/src/cli/utils/client.ts +0 -252
  83. package/src/cli/utils/config.ts +0 -389
  84. package/src/cli/utils/output.ts +0 -465
  85. package/src/cli/utils/wallet.ts +0 -109
  86. package/src/config/agirailsmd.ts +0 -262
  87. package/src/config/networks.ts +0 -275
  88. package/src/config/pendingPublish.ts +0 -237
  89. package/src/config/publishPipeline.ts +0 -359
  90. package/src/config/syncOperations.ts +0 -279
  91. package/src/erc8004/ERC8004Bridge.ts +0 -462
  92. package/src/erc8004/ReputationReporter.ts +0 -468
  93. package/src/erc8004/index.ts +0 -61
  94. package/src/errors/index.ts +0 -427
  95. package/src/index.ts +0 -364
  96. package/src/level0/Provider.ts +0 -117
  97. package/src/level0/ServiceDirectory.ts +0 -131
  98. package/src/level0/index.ts +0 -10
  99. package/src/level0/provide.ts +0 -132
  100. package/src/level0/request.ts +0 -432
  101. package/src/level1/Agent.ts +0 -1426
  102. package/src/level1/index.ts +0 -10
  103. package/src/level1/pricing/PriceCalculator.ts +0 -255
  104. package/src/level1/pricing/PricingStrategy.ts +0 -198
  105. package/src/level1/types/Job.ts +0 -179
  106. package/src/level1/types/Options.ts +0 -291
  107. package/src/level1/types/index.ts +0 -8
  108. package/src/protocol/ACTPKernel.ts +0 -808
  109. package/src/protocol/AgentRegistry.ts +0 -559
  110. package/src/protocol/DIDManager.ts +0 -629
  111. package/src/protocol/DIDResolver.ts +0 -554
  112. package/src/protocol/EASHelper.ts +0 -378
  113. package/src/protocol/EscrowVault.ts +0 -255
  114. package/src/protocol/EventMonitor.ts +0 -204
  115. package/src/protocol/MessageSigner.ts +0 -510
  116. package/src/protocol/ProofGenerator.ts +0 -339
  117. package/src/protocol/QuoteBuilder.ts +0 -15
  118. package/src/registry/AgentRegistryClient.ts +0 -202
  119. package/src/runtime/BlockchainRuntime.ts +0 -1015
  120. package/src/runtime/IACTPRuntime.ts +0 -306
  121. package/src/runtime/MockRuntime.ts +0 -1298
  122. package/src/runtime/MockStateManager.ts +0 -577
  123. package/src/runtime/index.ts +0 -25
  124. package/src/runtime/types/MockState.ts +0 -237
  125. package/src/storage/ArchiveBundleBuilder.ts +0 -561
  126. package/src/storage/ArweaveClient.ts +0 -946
  127. package/src/storage/FilebaseClient.ts +0 -790
  128. package/src/storage/index.ts +0 -96
  129. package/src/storage/types.ts +0 -348
  130. package/src/types/adapter.ts +0 -310
  131. package/src/types/agent.ts +0 -79
  132. package/src/types/did.ts +0 -223
  133. package/src/types/eip712.ts +0 -175
  134. package/src/types/erc8004.ts +0 -293
  135. package/src/types/escrow.ts +0 -27
  136. package/src/types/index.ts +0 -17
  137. package/src/types/message.ts +0 -145
  138. package/src/types/state.ts +0 -87
  139. package/src/types/transaction.ts +0 -69
  140. package/src/types/x402.ts +0 -251
  141. package/src/utils/ErrorRecoveryGuide.ts +0 -676
  142. package/src/utils/Helpers.ts +0 -688
  143. package/src/utils/IPFSClient.ts +0 -368
  144. package/src/utils/Logger.ts +0 -484
  145. package/src/utils/NonceManager.ts +0 -591
  146. package/src/utils/RateLimiter.ts +0 -534
  147. package/src/utils/ReceivedNonceTracker.ts +0 -567
  148. package/src/utils/SDKLifecycle.ts +0 -416
  149. package/src/utils/SecureNonce.ts +0 -78
  150. package/src/utils/Semaphore.ts +0 -276
  151. package/src/utils/UsedAttestationTracker.ts +0 -385
  152. package/src/utils/canonicalJson.ts +0 -38
  153. package/src/utils/circuitBreaker.ts +0 -324
  154. package/src/utils/computeTypeHash.ts +0 -48
  155. package/src/utils/fsSafe.ts +0 -80
  156. package/src/utils/index.ts +0 -80
  157. package/src/utils/retry.ts +0 -364
  158. package/src/utils/security.ts +0 -418
  159. package/src/utils/validation.ts +0 -540
  160. package/src/wallet/AutoWalletProvider.ts +0 -299
  161. package/src/wallet/EOAWalletProvider.ts +0 -69
  162. package/src/wallet/IWalletProvider.ts +0 -135
  163. package/src/wallet/aa/BundlerClient.ts +0 -274
  164. package/src/wallet/aa/DualNonceManager.ts +0 -173
  165. package/src/wallet/aa/PaymasterClient.ts +0 -174
  166. package/src/wallet/aa/TransactionBatcher.ts +0 -353
  167. package/src/wallet/aa/UserOpBuilder.ts +0 -246
  168. package/src/wallet/aa/constants.ts +0 -60
  169. 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
- }