@agirails/sdk 2.5.3 → 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 (166) 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/config/networks.d.ts +2 -2
  20. package/dist/config/networks.d.ts.map +1 -1
  21. package/dist/config/networks.js +27 -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.map +1 -1
  34. package/dist/wallet/AutoWalletProvider.js +52 -18
  35. package/dist/wallet/AutoWalletProvider.js.map +1 -1
  36. package/dist/wallet/SmartWalletRouter.d.ts +116 -0
  37. package/dist/wallet/SmartWalletRouter.d.ts.map +1 -0
  38. package/dist/wallet/SmartWalletRouter.js +212 -0
  39. package/dist/wallet/SmartWalletRouter.js.map +1 -0
  40. package/dist/wallet/aa/DualNonceManager.d.ts +19 -0
  41. package/dist/wallet/aa/DualNonceManager.d.ts.map +1 -1
  42. package/dist/wallet/aa/DualNonceManager.js +100 -5
  43. package/dist/wallet/aa/DualNonceManager.js.map +1 -1
  44. package/package.json +3 -6
  45. package/src/ACTPClient.ts +0 -1579
  46. package/src/abi/ACTPKernel.json +0 -1356
  47. package/src/abi/AgentRegistry.json +0 -915
  48. package/src/abi/ERC20.json +0 -40
  49. package/src/abi/EscrowVault.json +0 -134
  50. package/src/abi/IdentityRegistry.json +0 -316
  51. package/src/adapters/AdapterRegistry.ts +0 -173
  52. package/src/adapters/AdapterRouter.ts +0 -416
  53. package/src/adapters/BaseAdapter.ts +0 -498
  54. package/src/adapters/BasicAdapter.ts +0 -514
  55. package/src/adapters/IAdapter.ts +0 -292
  56. package/src/adapters/StandardAdapter.ts +0 -555
  57. package/src/adapters/X402Adapter.ts +0 -731
  58. package/src/adapters/index.ts +0 -60
  59. package/src/builders/DeliveryProofBuilder.ts +0 -327
  60. package/src/builders/QuoteBuilder.ts +0 -483
  61. package/src/builders/index.ts +0 -17
  62. package/src/cli/commands/balance.ts +0 -110
  63. package/src/cli/commands/batch.ts +0 -487
  64. package/src/cli/commands/config.ts +0 -231
  65. package/src/cli/commands/deploy-check.ts +0 -364
  66. package/src/cli/commands/deploy-env.ts +0 -120
  67. package/src/cli/commands/diff.ts +0 -141
  68. package/src/cli/commands/init.ts +0 -469
  69. package/src/cli/commands/mint.ts +0 -116
  70. package/src/cli/commands/pay.ts +0 -113
  71. package/src/cli/commands/publish.ts +0 -475
  72. package/src/cli/commands/pull.ts +0 -124
  73. package/src/cli/commands/register.ts +0 -247
  74. package/src/cli/commands/simulate.ts +0 -345
  75. package/src/cli/commands/time.ts +0 -302
  76. package/src/cli/commands/tx.ts +0 -448
  77. package/src/cli/commands/watch.ts +0 -211
  78. package/src/cli/index.ts +0 -134
  79. package/src/cli/utils/client.ts +0 -252
  80. package/src/cli/utils/config.ts +0 -389
  81. package/src/cli/utils/output.ts +0 -465
  82. package/src/cli/utils/wallet.ts +0 -109
  83. package/src/config/agirailsmd.ts +0 -262
  84. package/src/config/networks.ts +0 -275
  85. package/src/config/pendingPublish.ts +0 -237
  86. package/src/config/publishPipeline.ts +0 -359
  87. package/src/config/syncOperations.ts +0 -279
  88. package/src/erc8004/ERC8004Bridge.ts +0 -462
  89. package/src/erc8004/ReputationReporter.ts +0 -468
  90. package/src/erc8004/index.ts +0 -61
  91. package/src/errors/index.ts +0 -427
  92. package/src/index.ts +0 -364
  93. package/src/level0/Provider.ts +0 -117
  94. package/src/level0/ServiceDirectory.ts +0 -131
  95. package/src/level0/index.ts +0 -10
  96. package/src/level0/provide.ts +0 -132
  97. package/src/level0/request.ts +0 -432
  98. package/src/level1/Agent.ts +0 -1426
  99. package/src/level1/index.ts +0 -10
  100. package/src/level1/pricing/PriceCalculator.ts +0 -255
  101. package/src/level1/pricing/PricingStrategy.ts +0 -198
  102. package/src/level1/types/Job.ts +0 -179
  103. package/src/level1/types/Options.ts +0 -291
  104. package/src/level1/types/index.ts +0 -8
  105. package/src/protocol/ACTPKernel.ts +0 -808
  106. package/src/protocol/AgentRegistry.ts +0 -559
  107. package/src/protocol/DIDManager.ts +0 -629
  108. package/src/protocol/DIDResolver.ts +0 -554
  109. package/src/protocol/EASHelper.ts +0 -378
  110. package/src/protocol/EscrowVault.ts +0 -255
  111. package/src/protocol/EventMonitor.ts +0 -204
  112. package/src/protocol/MessageSigner.ts +0 -510
  113. package/src/protocol/ProofGenerator.ts +0 -339
  114. package/src/protocol/QuoteBuilder.ts +0 -15
  115. package/src/registry/AgentRegistryClient.ts +0 -202
  116. package/src/runtime/BlockchainRuntime.ts +0 -1015
  117. package/src/runtime/IACTPRuntime.ts +0 -306
  118. package/src/runtime/MockRuntime.ts +0 -1298
  119. package/src/runtime/MockStateManager.ts +0 -577
  120. package/src/runtime/index.ts +0 -25
  121. package/src/runtime/types/MockState.ts +0 -237
  122. package/src/storage/ArchiveBundleBuilder.ts +0 -561
  123. package/src/storage/ArweaveClient.ts +0 -946
  124. package/src/storage/FilebaseClient.ts +0 -790
  125. package/src/storage/index.ts +0 -96
  126. package/src/storage/types.ts +0 -348
  127. package/src/types/adapter.ts +0 -310
  128. package/src/types/agent.ts +0 -79
  129. package/src/types/did.ts +0 -223
  130. package/src/types/eip712.ts +0 -175
  131. package/src/types/erc8004.ts +0 -293
  132. package/src/types/escrow.ts +0 -27
  133. package/src/types/index.ts +0 -17
  134. package/src/types/message.ts +0 -145
  135. package/src/types/state.ts +0 -87
  136. package/src/types/transaction.ts +0 -69
  137. package/src/types/x402.ts +0 -251
  138. package/src/utils/ErrorRecoveryGuide.ts +0 -676
  139. package/src/utils/Helpers.ts +0 -688
  140. package/src/utils/IPFSClient.ts +0 -368
  141. package/src/utils/Logger.ts +0 -484
  142. package/src/utils/NonceManager.ts +0 -591
  143. package/src/utils/RateLimiter.ts +0 -534
  144. package/src/utils/ReceivedNonceTracker.ts +0 -567
  145. package/src/utils/SDKLifecycle.ts +0 -416
  146. package/src/utils/SecureNonce.ts +0 -78
  147. package/src/utils/Semaphore.ts +0 -276
  148. package/src/utils/UsedAttestationTracker.ts +0 -385
  149. package/src/utils/canonicalJson.ts +0 -38
  150. package/src/utils/circuitBreaker.ts +0 -324
  151. package/src/utils/computeTypeHash.ts +0 -48
  152. package/src/utils/fsSafe.ts +0 -80
  153. package/src/utils/index.ts +0 -80
  154. package/src/utils/retry.ts +0 -364
  155. package/src/utils/security.ts +0 -418
  156. package/src/utils/validation.ts +0 -540
  157. package/src/wallet/AutoWalletProvider.ts +0 -299
  158. package/src/wallet/EOAWalletProvider.ts +0 -69
  159. package/src/wallet/IWalletProvider.ts +0 -135
  160. package/src/wallet/aa/BundlerClient.ts +0 -274
  161. package/src/wallet/aa/DualNonceManager.ts +0 -173
  162. package/src/wallet/aa/PaymasterClient.ts +0 -174
  163. package/src/wallet/aa/TransactionBatcher.ts +0 -353
  164. package/src/wallet/aa/UserOpBuilder.ts +0 -246
  165. package/src/wallet/aa/constants.ts +0 -60
  166. package/src/wallet/keystore.ts +0 -240
@@ -1,629 +0,0 @@
1
- import { Contract, Signer, keccak256, toUtf8Bytes } from 'ethers';
2
- import IdentityRegistryABI from '../abi/IdentityRegistry.json';
3
- import {
4
- DelegateType,
5
- AttributeName,
6
- DIDOwnerChangedEvent,
7
- DIDDelegateChangedEvent,
8
- DIDAttributeChangedEvent
9
- } from '../types/did';
10
- import { TransactionRevertedError, ValidationError } from '../errors';
11
- import { validateAddress } from '../utils/validation';
12
-
13
- /**
14
- * Gas options for transactions
15
- */
16
- interface GasOptions {
17
- maxFeePerGas?: bigint;
18
- maxPriorityFeePerGas?: bigint;
19
- }
20
-
21
- /**
22
- * DIDManager - Manage DID attributes and delegates (AIP-7 §2.2)
23
- *
24
- * Interacts with ERC-1056 compatible AGIRAILS Identity Registry.
25
- * Provides key rotation, delegate management, and attribute storage.
26
- *
27
- * @example
28
- * ```typescript
29
- * const manager = new DIDManager(registryAddress, signer);
30
- *
31
- * // Get identity owner
32
- * const owner = await manager.getOwner(myAddress);
33
- *
34
- * // Add delegate (expires in 1 year)
35
- * await manager.addDelegate(
36
- * DelegateType.SIGNING,
37
- * delegateAddress,
38
- * 365 * 24 * 60 * 60
39
- * );
40
- *
41
- * // Set service endpoint
42
- * await manager.setAttribute(
43
- * AttributeName.SERVICE_ENDPOINT,
44
- * 'https://api.example.com',
45
- * 365 * 24 * 60 * 60
46
- * );
47
- * ```
48
- *
49
- * @security
50
- * - Only identity owner can add/revoke delegates
51
- * - Only identity owner can set/revoke attributes
52
- * - All operations wait for 2 confirmations
53
- * - Gas limits include 20% safety buffer
54
- */
55
- export class DIDManager {
56
- private contract: Contract;
57
- private readonly gasSettings?: GasOptions;
58
-
59
- /**
60
- * Create DIDManager instance
61
- *
62
- * @param registryAddress - Address of AGIRAILS Identity Registry (ERC-1056)
63
- * @param signer - Ethers.js signer (must be identity owner for write operations)
64
- * @param gasSettings - Optional gas price settings
65
- */
66
- constructor(
67
- private readonly registryAddress: string,
68
- signer: Signer,
69
- gasSettings?: GasOptions
70
- ) {
71
- validateAddress(registryAddress, 'registryAddress');
72
- this.contract = new Contract(registryAddress, IdentityRegistryABI, signer);
73
- this.gasSettings = gasSettings;
74
- }
75
-
76
- /**
77
- * Get gas buffer multiplier based on operation complexity
78
- */
79
- private getGasBufferMultiplier(operation: string): number {
80
- const buffers: Record<string, number> = {
81
- 'changeOwner': 1.30, // 30% - Ownership transfer
82
- 'addDelegate': 1.25, // 25% - Delegate registration
83
- 'revokeDelegate': 1.20, // 20% - Delegate removal
84
- 'setAttribute': 1.30, // 30% - Attribute storage (variable size)
85
- 'revokeAttribute': 1.20 // 20% - Attribute removal
86
- };
87
-
88
- return buffers[operation] || 1.20;
89
- }
90
-
91
- /**
92
- * Build transaction options with gas settings
93
- */
94
- private buildTxOptions(estimatedGas: bigint, operation: string = 'default'): any {
95
- const bufferMultiplier = this.getGasBufferMultiplier(operation);
96
- let gasLimit = (estimatedGas * BigInt(Math.round(bufferMultiplier * 100))) / 100n;
97
-
98
- // Cap gas limit (Base L2 safety)
99
- const MAX_GAS_LIMIT = 10_000_000n;
100
- if (gasLimit > MAX_GAS_LIMIT) {
101
- throw new ValidationError('gasLimit', `Estimated gas exceeds maximum safe limit (${MAX_GAS_LIMIT})`);
102
- }
103
-
104
- const options: any = { gasLimit };
105
-
106
- if (this.gasSettings?.maxFeePerGas) {
107
- options.maxFeePerGas = this.gasSettings.maxFeePerGas;
108
- }
109
- if (this.gasSettings?.maxPriorityFeePerGas) {
110
- options.maxPriorityFeePerGas = this.gasSettings.maxPriorityFeePerGas;
111
- }
112
-
113
- return options;
114
- }
115
-
116
- /**
117
- * Get registry contract address
118
- */
119
- getAddress(): string {
120
- return this.registryAddress;
121
- }
122
-
123
- /**
124
- * Get identity owner
125
- *
126
- * @param identity - Address to check (if not provided, uses signer address)
127
- * @returns Current owner address
128
- *
129
- * @example
130
- * ```typescript
131
- * const owner = await manager.getOwner('0x742d35cc6634c0532925a3b844bc9e7595f0beb');
132
- * console.log('Identity owner:', owner);
133
- * ```
134
- */
135
- async getOwner(identity?: string): Promise<string> {
136
- let addr = identity;
137
-
138
- // If no identity provided, try to get from signer
139
- if (!addr && this.contract.runner && 'getAddress' in this.contract.runner) {
140
- addr = await (this.contract.runner as Signer).getAddress();
141
- }
142
-
143
- if (!addr) {
144
- throw new ValidationError('identity', 'Must provide identity address or signer');
145
- }
146
-
147
- validateAddress(addr, 'identity');
148
- const owner = await this.contract.identityOwner(addr);
149
- return owner;
150
- }
151
-
152
- /**
153
- * Change identity owner (key rotation)
154
- *
155
- * @param identity - Identity address to update
156
- * @param newOwner - New owner address
157
- * @returns Transaction hash
158
- * @throws TransactionRevertedError if transaction fails
159
- *
160
- * @security
161
- * - Only current owner can change ownership
162
- * - Waits for 2 confirmations
163
- * - Validates new owner address
164
- *
165
- * @example
166
- * ```typescript
167
- * // Rotate key to new address
168
- * const txHash = await manager.changeOwner(
169
- * '0x742d35cc6634c0532925a3b844bc9e7595f0beb',
170
- * '0xNewOwnerAddress...'
171
- * );
172
- * console.log('Ownership transferred:', txHash);
173
- * ```
174
- */
175
- async changeOwner(identity: string, newOwner: string): Promise<string> {
176
- validateAddress(identity, 'identity');
177
- validateAddress(newOwner, 'newOwner');
178
-
179
- try {
180
- // Estimate gas
181
- const estimatedGas = await this.contract.changeOwner.estimateGas(identity, newOwner);
182
- const options = this.buildTxOptions(estimatedGas, 'changeOwner');
183
-
184
- // Send transaction
185
- const tx = await this.contract.changeOwner(identity, newOwner, options);
186
-
187
- // Wait for 2 confirmations
188
- await tx.wait(2);
189
-
190
- return tx.hash;
191
- } catch (error) {
192
- throw new TransactionRevertedError(
193
- 'changeOwner',
194
- error instanceof Error ? error.message : 'Transaction failed'
195
- );
196
- }
197
- }
198
-
199
- /**
200
- * Check if delegate is valid
201
- *
202
- * @param identity - Identity address
203
- * @param delegateType - Type of delegate (e.g., DelegateType.SIGNING)
204
- * @param delegate - Delegate address
205
- * @returns True if delegate is currently valid
206
- *
207
- * @example
208
- * ```typescript
209
- * const isValid = await manager.validDelegate(
210
- * '0x742d35cc...',
211
- * DelegateType.SIGNING,
212
- * '0xDelegateAddress...'
213
- * );
214
- * console.log('Delegate valid:', isValid);
215
- * ```
216
- */
217
- async validDelegate(
218
- identity: string,
219
- delegateType: DelegateType | string,
220
- delegate: string
221
- ): Promise<boolean> {
222
- validateAddress(identity, 'identity');
223
- validateAddress(delegate, 'delegate');
224
-
225
- const typeHash = this.stringToBytes32(delegateType);
226
- const isValid = await this.contract.validDelegate(identity, typeHash, delegate);
227
- return isValid;
228
- }
229
-
230
- /**
231
- * Add delegate (for signing on behalf of identity)
232
- *
233
- * @param identity - Identity address
234
- * @param delegateType - Type of delegate (e.g., DelegateType.SIGNING)
235
- * @param delegate - Delegate address
236
- * @param validity - Validity period in seconds
237
- * @returns Transaction hash
238
- * @throws TransactionRevertedError if transaction fails
239
- *
240
- * @security
241
- * - Only identity owner can add delegates
242
- * - Delegate expires after validity period
243
- * - Waits for 2 confirmations
244
- *
245
- * @example
246
- * ```typescript
247
- * // Add signing delegate for 1 year
248
- * const txHash = await manager.addDelegate(
249
- * '0x742d35cc...',
250
- * DelegateType.SIGNING,
251
- * '0xDelegateAddress...',
252
- * 365 * 24 * 60 * 60 // 1 year in seconds
253
- * );
254
- * ```
255
- */
256
- async addDelegate(
257
- identity: string,
258
- delegateType: DelegateType | string,
259
- delegate: string,
260
- validity: number
261
- ): Promise<string> {
262
- validateAddress(identity, 'identity');
263
- validateAddress(delegate, 'delegate');
264
-
265
- if (validity <= 0) {
266
- throw new ValidationError('validity', 'Validity must be positive');
267
- }
268
-
269
- const typeHash = this.stringToBytes32(delegateType);
270
-
271
- try {
272
- // Estimate gas
273
- const estimatedGas = await this.contract.addDelegate.estimateGas(
274
- identity,
275
- typeHash,
276
- delegate,
277
- validity
278
- );
279
- const options = this.buildTxOptions(estimatedGas, 'addDelegate');
280
-
281
- // Send transaction
282
- const tx = await this.contract.addDelegate(identity, typeHash, delegate, validity, options);
283
-
284
- // Wait for 2 confirmations
285
- await tx.wait(2);
286
-
287
- return tx.hash;
288
- } catch (error) {
289
- throw new TransactionRevertedError(
290
- 'addDelegate',
291
- error instanceof Error ? error.message : 'Transaction failed'
292
- );
293
- }
294
- }
295
-
296
- /**
297
- * Revoke delegate
298
- *
299
- * @param identity - Identity address
300
- * @param delegateType - Type of delegate
301
- * @param delegate - Delegate address to revoke
302
- * @returns Transaction hash
303
- * @throws TransactionRevertedError if transaction fails
304
- *
305
- * @security
306
- * - Only identity owner can revoke delegates
307
- * - Waits for 2 confirmations
308
- *
309
- * @example
310
- * ```typescript
311
- * const txHash = await manager.revokeDelegate(
312
- * '0x742d35cc...',
313
- * DelegateType.SIGNING,
314
- * '0xDelegateAddress...'
315
- * );
316
- * ```
317
- */
318
- async revokeDelegate(
319
- identity: string,
320
- delegateType: DelegateType | string,
321
- delegate: string
322
- ): Promise<string> {
323
- validateAddress(identity, 'identity');
324
- validateAddress(delegate, 'delegate');
325
-
326
- const typeHash = this.stringToBytes32(delegateType);
327
-
328
- try {
329
- // Estimate gas
330
- const estimatedGas = await this.contract.revokeDelegate.estimateGas(
331
- identity,
332
- typeHash,
333
- delegate
334
- );
335
- const options = this.buildTxOptions(estimatedGas, 'revokeDelegate');
336
-
337
- // Send transaction
338
- const tx = await this.contract.revokeDelegate(identity, typeHash, delegate, options);
339
-
340
- // Wait for 2 confirmations
341
- await tx.wait(2);
342
-
343
- return tx.hash;
344
- } catch (error) {
345
- throw new TransactionRevertedError(
346
- 'revokeDelegate',
347
- error instanceof Error ? error.message : 'Transaction failed'
348
- );
349
- }
350
- }
351
-
352
- /**
353
- * Set attribute (e.g., service endpoint)
354
- *
355
- * @param identity - Identity address
356
- * @param name - Attribute name (e.g., AttributeName.SERVICE_ENDPOINT)
357
- * @param value - Attribute value (string, will be encoded to bytes)
358
- * @param validity - Validity period in seconds
359
- * @returns Transaction hash
360
- * @throws TransactionRevertedError if transaction fails
361
- *
362
- * @security
363
- * - Only identity owner can set attributes
364
- * - Attribute expires after validity period
365
- * - Waits for 2 confirmations
366
- *
367
- * @example
368
- * ```typescript
369
- * // Set service endpoint for 1 year
370
- * const txHash = await manager.setAttribute(
371
- * '0x742d35cc...',
372
- * AttributeName.SERVICE_ENDPOINT,
373
- * 'https://api.example.com/v1',
374
- * 365 * 24 * 60 * 60
375
- * );
376
- * ```
377
- */
378
- async setAttribute(
379
- identity: string,
380
- name: AttributeName | string,
381
- value: string,
382
- validity: number
383
- ): Promise<string> {
384
- validateAddress(identity, 'identity');
385
-
386
- if (!value || value.length === 0) {
387
- throw new ValidationError('value', 'Attribute value cannot be empty');
388
- }
389
-
390
- if (validity <= 0) {
391
- throw new ValidationError('validity', 'Validity must be positive');
392
- }
393
-
394
- const nameHash = this.stringToBytes32(name);
395
- const valueBytes = toUtf8Bytes(value);
396
-
397
- try {
398
- // Estimate gas
399
- const estimatedGas = await this.contract.setAttribute.estimateGas(
400
- identity,
401
- nameHash,
402
- valueBytes,
403
- validity
404
- );
405
- const options = this.buildTxOptions(estimatedGas, 'setAttribute');
406
-
407
- // Send transaction
408
- const tx = await this.contract.setAttribute(identity, nameHash, valueBytes, validity, options);
409
-
410
- // Wait for 2 confirmations
411
- await tx.wait(2);
412
-
413
- return tx.hash;
414
- } catch (error) {
415
- throw new TransactionRevertedError(
416
- 'setAttribute',
417
- error instanceof Error ? error.message : 'Transaction failed'
418
- );
419
- }
420
- }
421
-
422
- /**
423
- * Revoke attribute
424
- *
425
- * @param identity - Identity address
426
- * @param name - Attribute name to revoke
427
- * @param value - Attribute value (must match value set)
428
- * @returns Transaction hash
429
- * @throws TransactionRevertedError if transaction fails
430
- *
431
- * @security
432
- * - Only identity owner can revoke attributes
433
- * - Waits for 2 confirmations
434
- *
435
- * @example
436
- * ```typescript
437
- * const txHash = await manager.revokeAttribute(
438
- * '0x742d35cc...',
439
- * AttributeName.SERVICE_ENDPOINT,
440
- * 'https://api.example.com/v1'
441
- * );
442
- * ```
443
- */
444
- async revokeAttribute(
445
- identity: string,
446
- name: AttributeName | string,
447
- value: string
448
- ): Promise<string> {
449
- validateAddress(identity, 'identity');
450
-
451
- if (!value || value.length === 0) {
452
- throw new ValidationError('value', 'Attribute value cannot be empty');
453
- }
454
-
455
- const nameHash = this.stringToBytes32(name);
456
- const valueBytes = toUtf8Bytes(value);
457
-
458
- try {
459
- // Estimate gas
460
- const estimatedGas = await this.contract.revokeAttribute.estimateGas(
461
- identity,
462
- nameHash,
463
- valueBytes
464
- );
465
- const options = this.buildTxOptions(estimatedGas, 'revokeAttribute');
466
-
467
- // Send transaction
468
- const tx = await this.contract.revokeAttribute(identity, nameHash, valueBytes, options);
469
-
470
- // Wait for 2 confirmations
471
- await tx.wait(2);
472
-
473
- return tx.hash;
474
- } catch (error) {
475
- throw new TransactionRevertedError(
476
- 'revokeAttribute',
477
- error instanceof Error ? error.message : 'Transaction failed'
478
- );
479
- }
480
- }
481
-
482
- /**
483
- * Get timestamp of last change for identity
484
- *
485
- * @param identity - Identity address
486
- * @returns Timestamp of last change (seconds since Unix epoch)
487
- */
488
- async getChanged(identity: string): Promise<bigint> {
489
- validateAddress(identity, 'identity');
490
- const changed = await this.contract.changed(identity);
491
- return changed;
492
- }
493
-
494
- /**
495
- * Get nonce for identity (for signed operations)
496
- *
497
- * @param identity - Identity address
498
- * @returns Current nonce
499
- */
500
- async getNonce(identity: string): Promise<bigint> {
501
- validateAddress(identity, 'identity');
502
- const nonce = await this.contract.nonce(identity);
503
- return nonce;
504
- }
505
-
506
- /**
507
- * Convert string to bytes32 hash
508
- *
509
- * Used for delegate types and attribute names in ERC-1056
510
- *
511
- * @param str - String to convert
512
- * @returns bytes32 hash (0x-prefixed hex string)
513
- *
514
- * @example
515
- * ```typescript
516
- * const hash = manager.stringToBytes32('veriKey');
517
- * // Returns: '0x...' (keccak256 hash)
518
- * ```
519
- */
520
- stringToBytes32(str: string): string {
521
- // If already a bytes32 hash (0x + 64 hex chars), return as-is
522
- if (/^0x[0-9a-fA-F]{64}$/.test(str)) {
523
- return str;
524
- }
525
-
526
- // Otherwise, hash the string
527
- return keccak256(toUtf8Bytes(str));
528
- }
529
-
530
- /**
531
- * Listen for DIDOwnerChanged events
532
- *
533
- * @param callback - Function to call when owner changes
534
- * @param identity - Optional filter by identity address
535
- * @returns Cleanup function to stop listening
536
- *
537
- * @example
538
- * ```typescript
539
- * const unsubscribe = manager.onOwnerChanged((event) => {
540
- * console.log('Owner changed:', event);
541
- * }, '0x742d35cc...');
542
- *
543
- * // Later: stop listening
544
- * unsubscribe();
545
- * ```
546
- */
547
- onOwnerChanged(
548
- callback: (event: DIDOwnerChangedEvent) => void,
549
- identity?: string
550
- ): () => void {
551
- const filter = identity
552
- ? this.contract.filters.DIDOwnerChanged(identity)
553
- : this.contract.filters.DIDOwnerChanged();
554
-
555
- const listener = (identityAddr: string, owner: string, previousChange: bigint) => {
556
- callback({ identity: identityAddr, owner, previousChange });
557
- };
558
-
559
- this.contract.on(filter, listener);
560
-
561
- return () => {
562
- this.contract.off(filter, listener);
563
- };
564
- }
565
-
566
- /**
567
- * Listen for DIDDelegateChanged events
568
- *
569
- * @param callback - Function to call when delegate changes
570
- * @param identity - Optional filter by identity address
571
- * @returns Cleanup function to stop listening
572
- */
573
- onDelegateChanged(
574
- callback: (event: DIDDelegateChangedEvent) => void,
575
- identity?: string
576
- ): () => void {
577
- const filter = identity
578
- ? this.contract.filters.DIDDelegateChanged(identity)
579
- : this.contract.filters.DIDDelegateChanged();
580
-
581
- const listener = (
582
- identityAddr: string,
583
- delegateType: string,
584
- delegate: string,
585
- validTo: bigint,
586
- previousChange: bigint
587
- ) => {
588
- callback({ identity: identityAddr, delegateType, delegate, validTo, previousChange });
589
- };
590
-
591
- this.contract.on(filter, listener);
592
-
593
- return () => {
594
- this.contract.off(filter, listener);
595
- };
596
- }
597
-
598
- /**
599
- * Listen for DIDAttributeChanged events
600
- *
601
- * @param callback - Function to call when attribute changes
602
- * @param identity - Optional filter by identity address
603
- * @returns Cleanup function to stop listening
604
- */
605
- onAttributeChanged(
606
- callback: (event: DIDAttributeChangedEvent) => void,
607
- identity?: string
608
- ): () => void {
609
- const filter = identity
610
- ? this.contract.filters.DIDAttributeChanged(identity)
611
- : this.contract.filters.DIDAttributeChanged();
612
-
613
- const listener = (
614
- identityAddr: string,
615
- name: string,
616
- value: Uint8Array,
617
- validTo: bigint,
618
- previousChange: bigint
619
- ) => {
620
- callback({ identity: identityAddr, name, value, validTo, previousChange });
621
- };
622
-
623
- this.contract.on(filter, listener);
624
-
625
- return () => {
626
- this.contract.off(filter, listener);
627
- };
628
- }
629
- }