@1money/protocol-ts-sdk 1.1.2 → 2.0.1

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 (69) hide show
  1. package/.claude/settings.local.json +18 -1
  2. package/README.md +216 -134
  3. package/es/__integration__/helpers.d.ts +0 -7
  4. package/es/api/checkpoints/types.d.ts +0 -1
  5. package/es/api/index.js +49 -10
  6. package/es/api/tokens/index.d.ts +7 -1
  7. package/es/api/tokens/types.d.ts +21 -6
  8. package/es/api/transactions/index.d.ts +4 -3
  9. package/es/api/transactions/types.d.ts +14 -5
  10. package/es/client/core.d.ts +2 -4
  11. package/es/client/index.js +36 -4
  12. package/es/index.d.ts +1 -0
  13. package/es/index.js +513 -22
  14. package/es/signing/builders/index.d.ts +11 -0
  15. package/es/signing/builders/payment.d.ts +3 -0
  16. package/es/signing/builders/tokenAuthority.d.ts +3 -0
  17. package/es/signing/builders/tokenBridgeAndMint.d.ts +3 -0
  18. package/es/signing/builders/tokenBurn.d.ts +3 -0
  19. package/es/signing/builders/tokenBurnAndBridge.d.ts +3 -0
  20. package/es/signing/builders/tokenClawback.d.ts +3 -0
  21. package/es/signing/builders/tokenIssue.d.ts +3 -0
  22. package/es/signing/builders/tokenManageList.d.ts +3 -0
  23. package/es/signing/builders/tokenMetadata.d.ts +3 -0
  24. package/es/signing/builders/tokenMint.d.ts +3 -0
  25. package/es/signing/builders/tokenPause.d.ts +3 -0
  26. package/es/signing/builders/validate.d.ts +18 -0
  27. package/es/signing/core.d.ts +27 -0
  28. package/es/signing/index.d.ts +18 -0
  29. package/es/signing/signer.d.ts +3 -0
  30. package/es/utils/encode.d.ts +11 -0
  31. package/es/utils/index.d.ts +2 -1
  32. package/es/utils/index.js +90 -10
  33. package/es/utils/interface.d.ts +27 -0
  34. package/es/utils/sign.d.ts +6 -1
  35. package/eslint.config.mjs +101 -0
  36. package/lib/__integration__/helpers.d.ts +0 -7
  37. package/lib/api/checkpoints/types.d.ts +0 -1
  38. package/lib/api/index.js +59 -10
  39. package/lib/api/tokens/index.d.ts +7 -1
  40. package/lib/api/tokens/types.d.ts +21 -6
  41. package/lib/api/transactions/index.d.ts +4 -3
  42. package/lib/api/transactions/types.d.ts +14 -5
  43. package/lib/client/core.d.ts +2 -4
  44. package/lib/client/index.js +46 -4
  45. package/lib/index.d.ts +1 -0
  46. package/lib/index.js +511 -21
  47. package/lib/signing/builders/index.d.ts +11 -0
  48. package/lib/signing/builders/payment.d.ts +3 -0
  49. package/lib/signing/builders/tokenAuthority.d.ts +3 -0
  50. package/lib/signing/builders/tokenBridgeAndMint.d.ts +3 -0
  51. package/lib/signing/builders/tokenBurn.d.ts +3 -0
  52. package/lib/signing/builders/tokenBurnAndBridge.d.ts +3 -0
  53. package/lib/signing/builders/tokenClawback.d.ts +3 -0
  54. package/lib/signing/builders/tokenIssue.d.ts +3 -0
  55. package/lib/signing/builders/tokenManageList.d.ts +3 -0
  56. package/lib/signing/builders/tokenMetadata.d.ts +3 -0
  57. package/lib/signing/builders/tokenMint.d.ts +3 -0
  58. package/lib/signing/builders/tokenPause.d.ts +3 -0
  59. package/lib/signing/builders/validate.d.ts +18 -0
  60. package/lib/signing/core.d.ts +27 -0
  61. package/lib/signing/index.d.ts +18 -0
  62. package/lib/signing/signer.d.ts +3 -0
  63. package/lib/utils/encode.d.ts +11 -0
  64. package/lib/utils/index.d.ts +2 -1
  65. package/lib/utils/index.js +90 -10
  66. package/lib/utils/interface.d.ts +27 -0
  67. package/lib/utils/sign.d.ts +6 -1
  68. package/package.json +26 -15
  69. package/umd/1money-protocol-ts-sdk.min.js +4 -2
@@ -19,7 +19,24 @@
19
19
  "Bash(cat:*)",
20
20
  "Bash(xargs grep:*)",
21
21
  "Bash(npm run lint:es_fix:*)",
22
- "Bash(node test-encoding.mjs:*)"
22
+ "Bash(node test-encoding.mjs:*)",
23
+ "Bash(npm test:*)",
24
+ "Bash(gh repo view --json name,owner,url,defaultBranchRef)",
25
+ "Bash(gh api:*)",
26
+ "Bash(npm ls:*)",
27
+ "Bash(npm audit:*)",
28
+ "Bash(pnpm why flatted)",
29
+ "Bash(pnpm why:*)",
30
+ "Bash(npm view @commitlint/cli version)",
31
+ "Bash(npm view:*)",
32
+ "Bash(npm view nyc version)",
33
+ "Bash(python3:*)",
34
+ "Bash(pnpm install:*)",
35
+ "Bash(npx mocha:*)",
36
+ "Bash(git add package.json pnpm-lock.yaml)",
37
+ "Bash(git commit -m \"$\\(cat <<''EOF''\nchore: upgrade mocha to v11 for security fixes\n\nCo-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>\nEOF\n\\)\")",
38
+ "Bash(npx commitlint:*)",
39
+ "Bash(npm run lint:es:*)"
23
40
  ],
24
41
  "deny": []
25
42
  }
package/README.md CHANGED
@@ -235,43 +235,40 @@ apiClient.tokens.getTokenMetadata(tokenAddress)
235
235
 
236
236
  #### Issue New Token
237
237
  ```typescript
238
- import { signMessage, toHex } from '@1money/protocol-ts-sdk';
238
+ import {
239
+ TransactionBuilder,
240
+ createPrivateKeySigner
241
+ } from '@1money/protocol-ts-sdk';
239
242
 
240
243
  // Your private key (DO NOT share or commit your private key)
241
244
  const privateKey = 'YOUR_PRIVATE_KEY';
245
+ const masterAuthority = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
242
246
 
243
- // First, get the latest epoch checkpoint
244
- const epochData = await apiClient.state.getLatestEpochCheckpoint()
247
+ // Get chain id and current nonce
248
+ const { chain_id } = await apiClient.chain.getChainId()
249
+ .success(response => response);
250
+ const { nonce } = await apiClient.accounts.getNonce(masterAuthority)
245
251
  .success(response => response);
246
252
 
247
- // Create the payload array for signing
248
- const payload = [
249
- 1, // chain_id
250
- 1, // nonce
251
- 'MTK', // symbol
252
- 'My Token', // name
253
- 18, // decimals
254
- '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // master_authority
255
- true, // is_private
256
- ];
257
-
258
- // Generate signature
259
- const signature = await signMessage(payload, privateKey);
260
- if (!signature) {
261
- throw new Error('Failed to generate signature');
262
- }
263
-
264
- // Create the issue payload
265
- const issuePayload = {
266
- chain_id: 1,
267
- nonce: 1,
268
- name: 'My Token',
253
+ // Build transaction and prepare signature hash internally
254
+ const prepared = TransactionBuilder.tokenIssue({
255
+ chain_id,
256
+ nonce,
269
257
  symbol: 'MTK',
258
+ name: 'My Token',
270
259
  decimals: 18,
271
- master_authority: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
260
+ master_authority: masterAuthority,
272
261
  is_private: true,
273
- signature
274
- };
262
+ clawback_enabled: true
263
+ });
264
+
265
+ // Sign with private key
266
+ const signed = await prepared.sign(
267
+ createPrivateKeySigner(privateKey as `0x${string}`)
268
+ );
269
+
270
+ // Build request body with signature
271
+ const issuePayload = signed.toRequest();
275
272
 
276
273
  apiClient.tokens.issueToken(issuePayload)
277
274
  .success(response => {
@@ -284,40 +281,38 @@ apiClient.tokens.issueToken(issuePayload)
284
281
 
285
282
  #### Manage Token Blacklist/Whitelist
286
283
  ```typescript
287
- import { signMessage, toHex } from '@1money/protocol-ts-sdk';
288
- import type { ManageListAction } from '@1money/protocol-ts-sdk/api';
284
+ import {
285
+ ManageListAction,
286
+ TransactionBuilder,
287
+ createPrivateKeySigner
288
+ } from '@1money/protocol-ts-sdk';
289
289
 
290
290
  // Your private key (DO NOT share or commit your private key)
291
291
  const privateKey = 'YOUR_PRIVATE_KEY';
292
+ const operatorAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
292
293
 
293
- // First, get the latest epoch checkpoint
294
- const epochData = await apiClient.state.getLatestEpochCheckpoint()
294
+ // Get chain id and current nonce
295
+ const { chain_id } = await apiClient.chain.getChainId()
296
+ .success(response => response);
297
+ const { nonce } = await apiClient.accounts.getNonce(operatorAddress)
295
298
  .success(response => response);
296
299
 
297
- // Create the payload array for signing
298
- const payload = [
299
- 1, // chain_id
300
- 1, // nonce
301
- ManageListAction.Add, // action
302
- '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // address
303
- '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
304
- ];
300
+ // Build transaction and prepare signature hash internally
301
+ const prepared = TransactionBuilder.tokenManageList({
302
+ chain_id,
303
+ nonce,
304
+ action: ManageListAction.Add,
305
+ address: operatorAddress,
306
+ token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F'
307
+ });
305
308
 
306
- // Generate signature
307
- const signature = await signMessage(payload, privateKey);
308
- if (!signature) {
309
- throw new Error('Failed to generate signature');
310
- }
309
+ // Sign with private key
310
+ const signed = await prepared.sign(
311
+ createPrivateKeySigner(privateKey as `0x${string}`)
312
+ );
311
313
 
312
- // Create the manage list payload
313
- const manageListPayload = {
314
- chain_id: 1,
315
- nonce: 1,
316
- action: ManageListAction.Add,
317
- address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
318
- token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
319
- signature
320
- };
314
+ // Build request body with signature
315
+ const manageListPayload = signed.toRequest();
321
316
 
322
317
  // Use manageBlacklist for blacklist operations
323
318
  apiClient.tokens.manageBlacklist(manageListPayload)
@@ -340,39 +335,36 @@ apiClient.tokens.manageWhitelist(manageListPayload)
340
335
 
341
336
  #### Burn Tokens
342
337
  ```typescript
343
- import { signMessage, toHex } from '@1money/protocol-ts-sdk';
338
+ import {
339
+ TransactionBuilder,
340
+ createPrivateKeySigner
341
+ } from '@1money/protocol-ts-sdk';
344
342
 
345
343
  // Your private key (DO NOT share or commit your private key)
346
344
  const privateKey = 'YOUR_PRIVATE_KEY';
345
+ const ownerAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
347
346
 
348
- // First, get the latest epoch checkpoint
349
- const epochData = await apiClient.state.getLatestEpochCheckpoint()
347
+ // Get chain id and current nonce
348
+ const { chain_id } = await apiClient.chain.getChainId()
349
+ .success(response => response);
350
+ const { nonce } = await apiClient.accounts.getNonce(ownerAddress)
350
351
  .success(response => response);
351
352
 
352
- // Create the payload array for signing
353
- const payload = [
354
- 1, // chain_id
355
- 1, // nonce
356
- '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // recipient (for burn, same as sender)
357
- '1000000000000000000', // amount
358
- '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
359
- ];
353
+ // Build transaction and prepare signature hash internally
354
+ const prepared = TransactionBuilder.tokenBurn({
355
+ chain_id,
356
+ nonce,
357
+ value: '1000000000000000000',
358
+ token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F'
359
+ });
360
360
 
361
- // Generate signature
362
- const signature = await signMessage(payload, privateKey);
363
- if (!signature) {
364
- throw new Error('Failed to generate signature');
365
- }
361
+ // Sign with private key
362
+ const signed = await prepared.sign(
363
+ createPrivateKeySigner(privateKey as `0x${string}`)
364
+ );
366
365
 
367
- // Create the burn payload
368
- const burnPayload = {
369
- chain_id: 1,
370
- nonce: 1,
371
- recipient: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
372
- value: '1000000000000000000',
373
- token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
374
- signature
375
- };
366
+ // Build request body with signature
367
+ const burnPayload = signed.toRequest();
376
368
 
377
369
  apiClient.tokens.burnToken(burnPayload)
378
370
  .success(response => {
@@ -385,44 +377,41 @@ apiClient.tokens.burnToken(burnPayload)
385
377
 
386
378
  #### Grant Token Authority
387
379
  ```typescript
388
- import { signMessage, toHex } from '@1money/protocol-ts-sdk';
389
- import type { AuthorityType, AuthorityAction } from '@1money/protocol-ts-sdk/api';
380
+ import {
381
+ AuthorityAction,
382
+ AuthorityType,
383
+ TransactionBuilder,
384
+ createPrivateKeySigner
385
+ } from '@1money/protocol-ts-sdk';
390
386
 
391
387
  // Your private key (DO NOT share or commit your private key)
392
388
  const privateKey = 'YOUR_PRIVATE_KEY';
389
+ const masterAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
393
390
 
394
- // First, get the latest epoch checkpoint
395
- const epochData = await apiClient.state.getLatestEpochCheckpoint()
391
+ // Get chain id and current nonce
392
+ const { chain_id } = await apiClient.chain.getChainId()
393
+ .success(response => response);
394
+ const { nonce } = await apiClient.accounts.getNonce(masterAddress)
396
395
  .success(response => response);
397
396
 
398
- // Create the payload array for signing
399
- const payload = [
400
- 1, // chain_id
401
- 1, // nonce
402
- AuthorityAction.Grant, // action
403
- AuthorityType.MasterMint, // authority_type (sends 'MasterMintBurn')
404
- '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3', // authority_address
405
- '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
406
- '1000000000000000000000', // value (optional, for MintBurnTokens type)
407
- ];
408
-
409
- // Generate signature
410
- const signature = await signMessage(payload, privateKey);
411
- if (!signature) {
412
- throw new Error('Failed to generate signature');
413
- }
414
-
415
- // Create the authority payload
416
- const authorityPayload = {
417
- chain_id: 1,
418
- nonce: 1,
397
+ // Build transaction and prepare signature hash internally
398
+ const prepared = TransactionBuilder.tokenAuthority({
399
+ chain_id,
400
+ nonce,
419
401
  action: AuthorityAction.Grant,
420
- authority_type: AuthorityType.MasterMint, // value is 'MasterMintBurn'
402
+ authority_type: AuthorityType.MasterMint,
421
403
  authority_address: '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3',
422
404
  token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
423
- value: '1000000000000000000000',
424
- signature
425
- };
405
+ value: '1000000000000000000000'
406
+ });
407
+
408
+ // Sign with private key
409
+ const signed = await prepared.sign(
410
+ createPrivateKeySigner(privateKey as `0x${string}`)
411
+ );
412
+
413
+ // Build request body with signature
414
+ const authorityPayload = signed.toRequest();
426
415
 
427
416
  apiClient.tokens.grantAuthority(authorityPayload)
428
417
  .success(response => {
@@ -433,6 +422,100 @@ apiClient.tokens.grantAuthority(authorityPayload)
433
422
  });
434
423
  ```
435
424
 
425
+ #### Bridge and Mint
426
+ ```typescript
427
+ import {
428
+ TransactionBuilder,
429
+ createPrivateKeySigner
430
+ } from '@1money/protocol-ts-sdk';
431
+
432
+ // Your private key (DO NOT share or commit your private key)
433
+ const privateKey = 'YOUR_PRIVATE_KEY';
434
+ const bridgeOperatorAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
435
+
436
+ // Get chain id and current nonce
437
+ const { chain_id } = await apiClient.chain.getChainId()
438
+ .success(response => response);
439
+ const { nonce } = await apiClient.accounts.getNonce(bridgeOperatorAddress)
440
+ .success(response => response);
441
+
442
+ // Build transaction and prepare signature hash internally
443
+ const prepared = TransactionBuilder.tokenBridgeAndMint({
444
+ chain_id,
445
+ nonce,
446
+ recipient: '0x6324dAc598f9B637824978eD6b268C896E0c40E0',
447
+ value: '25000000000000000000',
448
+ token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
449
+ source_chain_id: 1,
450
+ source_tx_hash: '0x1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef',
451
+ bridge_metadata: 'bridge_from_chain_1'
452
+ });
453
+
454
+ // Sign with private key
455
+ const signed = await prepared.sign(
456
+ createPrivateKeySigner(privateKey as `0x${string}`)
457
+ );
458
+
459
+ // Build request body with signature
460
+ const bridgeAndMintPayload = signed.toRequest();
461
+
462
+ apiClient.tokens.bridgeAndMint(bridgeAndMintPayload)
463
+ .success(response => {
464
+ console.log('Bridge and mint transaction hash:', response.hash);
465
+ })
466
+ .error(err => {
467
+ console.error('Error:', err);
468
+ });
469
+ ```
470
+
471
+ #### Burn and Bridge
472
+ ```typescript
473
+ import {
474
+ TransactionBuilder,
475
+ createPrivateKeySigner
476
+ } from '@1money/protocol-ts-sdk';
477
+
478
+ // Your private key (DO NOT share or commit your private key)
479
+ const privateKey = 'YOUR_PRIVATE_KEY';
480
+ const senderAddress = '0x6324dAc598f9B637824978eD6b268C896E0c40E0';
481
+
482
+ // Get chain id and current nonce
483
+ const { chain_id } = await apiClient.chain.getChainId()
484
+ .success(response => response);
485
+ const { nonce } = await apiClient.accounts.getNonce(senderAddress)
486
+ .success(response => response);
487
+
488
+ // Build transaction and prepare signature hash internally
489
+ const prepared = TransactionBuilder.tokenBurnAndBridge({
490
+ chain_id,
491
+ nonce,
492
+ sender: senderAddress,
493
+ value: '20000000000000000000',
494
+ token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
495
+ destination_chain_id: 1,
496
+ destination_address: '0x1234567890abcdef1234567890abcdef12345678',
497
+ escrow_fee: '1000000000000000000',
498
+ bridge_metadata: 'bridge_to_chain_1',
499
+ bridge_param: '0x'
500
+ });
501
+
502
+ // Sign with private key
503
+ const signed = await prepared.sign(
504
+ createPrivateKeySigner(privateKey as `0x${string}`)
505
+ );
506
+
507
+ // Build request body with signature
508
+ const burnAndBridgePayload = signed.toRequest();
509
+
510
+ apiClient.tokens.burnAndBridge(burnAndBridgePayload)
511
+ .success(response => {
512
+ console.log('Burn and bridge transaction hash:', response.hash);
513
+ })
514
+ .error(err => {
515
+ console.error('Error:', err);
516
+ });
517
+ ```
518
+
436
519
  ### Transactions API
437
520
 
438
521
  #### Get Transaction Details
@@ -462,10 +545,11 @@ apiClient.transactions.getReceiptByHash(txHash)
462
545
  #### Estimate Transaction Fee
463
546
  ```typescript
464
547
  const fromAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
548
+ const toAddress = '0x6324dAc598f9B637824978eD6b268C896E0c40E0';
465
549
  const value = '1000000000';
466
550
  const tokenAddress = '0x2cd8999Be299373D7881f4aDD11510030ad1412F';
467
551
 
468
- apiClient.transactions.estimateFee(fromAddress, value, tokenAddress)
552
+ apiClient.transactions.estimateFee(fromAddress, toAddress, value, tokenAddress)
469
553
  .success(response => {
470
554
  console.log('Estimated fee:', response);
471
555
  })
@@ -476,39 +560,37 @@ apiClient.transactions.estimateFee(fromAddress, value, tokenAddress)
476
560
 
477
561
  #### Submit Payment Transaction
478
562
  ```typescript
479
- import { signMessage, toHex } from '@1money/protocol-ts-sdk';
563
+ import {
564
+ TransactionBuilder,
565
+ createPrivateKeySigner
566
+ } from '@1money/protocol-ts-sdk';
480
567
 
481
568
  // Your private key (DO NOT share or commit your private key)
482
569
  const privateKey = 'YOUR_PRIVATE_KEY';
570
+ const senderAddress = '0x9E1E9688A44D058fF181Ed64ddFAFbBE5CC74ff3';
483
571
 
484
- // First, get the latest epoch checkpoint
485
- const epochData = await apiClient.state.getLatestEpochCheckpoint()
572
+ // Get chain id and current nonce
573
+ const { chain_id } = await apiClient.chain.getChainId()
574
+ .success(response => response);
575
+ const { nonce } = await apiClient.accounts.getNonce(senderAddress)
486
576
  .success(response => response);
487
577
 
488
- // Create the payload array for signing
489
- const payload = [
490
- 1, // chain_id
491
- 1, // nonce
492
- '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // recipient
493
- '1000000000', // value
494
- '0x2cd8999Be299373D7881f4aDD11510030ad1412F', // token
495
- ];
578
+ // Build transaction and prepare signature hash internally
579
+ const prepared = TransactionBuilder.payment({
580
+ chain_id,
581
+ nonce,
582
+ recipient: '0xa128999Be299373D7881f4aDD11510030ad13512',
583
+ value: '1000000000',
584
+ token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F'
585
+ });
496
586
 
497
- // Generate signature
498
- const signature = await signMessage(payload, privateKey);
499
- if (!signature) {
500
- throw new Error('Failed to generate signature');
501
- }
587
+ // Sign with private key
588
+ const signed = await prepared.sign(
589
+ createPrivateKeySigner(privateKey as `0x${string}`)
590
+ );
502
591
 
503
- // Create the payment payload
504
- const paymentPayload = {
505
- chain_id: 1,
506
- nonce: 1,
507
- recipient: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
508
- value: '1000000000',
509
- token: '0x2cd8999Be299373D7881f4aDD11510030ad1412F',
510
- signature
511
- };
592
+ // Build request body with signature
593
+ const paymentPayload = signed.toRequest();
512
594
 
513
595
  apiClient.transactions.payment(paymentPayload)
514
596
  .success(response => {
@@ -1,9 +1,6 @@
1
1
  /**
2
2
  * Integration test helper utilities
3
3
  */
4
- import type { RestSignature } from '../api/tokens/types';
5
- import type { TestAccount } from './setup';
6
- import type { Payload } from '../utils/interface';
7
4
  /**
8
5
  * Create API client for integration tests
9
6
  */
@@ -14,10 +11,6 @@ export declare function createTestClient(): {
14
11
  transactions: typeof import("../api/transactions").transactionsApi;
15
12
  chain: typeof import("../api/chain").chainApi;
16
13
  };
17
- /**
18
- * Sign a payload with an account and return RestSignature format
19
- */
20
- export declare function signPayload(payload: Payload, account: TestAccount): Promise<RestSignature>;
21
14
  /**
22
15
  * Wait for a transaction to be finalized
23
16
  * @param txHash Transaction hash
@@ -12,7 +12,6 @@ export interface Header {
12
12
  receipts_root: B256Schema;
13
13
  number: number;
14
14
  timestamp: number;
15
- extra_data: string;
16
15
  }
17
16
  export interface Checkpoint extends Header {
18
17
  size?: number;
package/es/api/index.js CHANGED
@@ -46,7 +46,7 @@ import'viem';import'@ethereumjs/rlp';import axios from'axios';function _typeof(e
46
46
  this._restScope = scope || this._restScope;
47
47
  // @ts-ignore
48
48
  if (this._restScope.length === 0) {
49
- console.warn('[1Money client]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
49
+ console.warn('[1Money SDK]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
50
50
  }
51
51
  else {
52
52
  let deletedCounter = 0;
@@ -61,7 +61,7 @@ import'viem';import'@ethereumjs/rlp';import axios from'axios';function _typeof(e
61
61
  }
62
62
  });
63
63
  if (deletedCounter === this._restScope.length) {
64
- console.warn(`[1Money client]: The "${this._restScope.join(', ')}" had been called and the "rest" will never be triggered!`);
64
+ console.warn(`[1Money SDK]: The "${this._restScope.join(', ')}" had been called and the "rest" will never be triggered!`);
65
65
  }
66
66
  }
67
67
  return wrapper;
@@ -108,9 +108,26 @@ class Request {
108
108
  data
109
109
  };
110
110
  }
111
+ mergeSignals(...signals) {
112
+ const controller = new AbortController();
113
+ const onAbort = () => controller.abort();
114
+ const cleanups = [];
115
+ for (const signal of signals) {
116
+ if (signal.aborted) {
117
+ controller.abort();
118
+ break;
119
+ }
120
+ signal.addEventListener('abort', onAbort);
121
+ cleanups.push(() => signal.removeEventListener('abort', onAbort));
122
+ }
123
+ return {
124
+ signal: controller.signal,
125
+ cleanup: () => cleanups.forEach(fn => fn()),
126
+ };
127
+ }
111
128
  setting(config) {
112
129
  if (!config)
113
- return console.warn('[1Money client]: setting method required correct parameters!');
130
+ return console.warn('[1Money SDK]: setting method required correct parameters!');
114
131
  this._config = { ...this._config, ...config };
115
132
  }
116
133
  request(options) {
@@ -208,18 +225,33 @@ class Request {
208
225
  let timer = null;
209
226
  let isTimeout = false;
210
227
  const _timeout = timeout ?? initTimeout;
228
+ const controller = new AbortController();
229
+ let signalCleanup = null;
230
+ if (options.signal) {
231
+ const merged = this.mergeSignals(options.signal, controller.signal);
232
+ options.signal = merged.signal;
233
+ signalCleanup = merged.cleanup;
234
+ }
235
+ else {
236
+ options.signal = controller.signal;
237
+ }
211
238
  // Cleanup function for timeout
212
239
  const cleanup = () => {
213
240
  if (timer !== null) {
214
241
  clearTimeout(timer);
215
242
  timer = null;
216
243
  }
244
+ if (signalCleanup) {
245
+ signalCleanup();
246
+ signalCleanup = null;
247
+ }
217
248
  };
218
249
  if (_timeout) {
219
250
  timer = setTimeout(async () => {
220
251
  try {
221
252
  isTimeout = true;
222
253
  cleanup();
254
+ controller.abort();
223
255
  let err = this.parseError('timeout');
224
256
  // @ts-ignore
225
257
  const res = await Promise.resolve(callbacks.timeout(err, options.headers ?? {}));
@@ -266,7 +298,7 @@ class Request {
266
298
  return;
267
299
  cleanup();
268
300
  const data = err.response?.data ?? {};
269
- console.error(`[1Money client]: Error(${err.status ?? 500}, ${err.code ?? 'UNKNOWN'}), Message: ${err.message}, Config: ${err.config?.method}, ${err.config?.baseURL ?? ''}, ${err.config?.url ?? ''}, ${JSON.stringify(err.config?.headers ?? {})}, Request: ${JSON.stringify(err.config?.data ?? {})}, Response: ${JSON.stringify(data)};`);
301
+ console.error(`[1Money SDK]: Error(${err.status ?? 500}, ${err.code ?? 'UNKNOWN'}), Message: ${err.message}, Config: ${err.config?.method}, ${err.config?.baseURL ?? ''}, ${err.config?.url ?? ''}, ${JSON.stringify(err.config?.headers ?? {})}, Request: ${JSON.stringify(err.config?.data ?? {})}, Response: ${JSON.stringify(data)};`);
270
302
  const status = err.response?.status ?? 500;
271
303
  const headers = err.response?.headers ?? {};
272
304
  try {
@@ -487,6 +519,14 @@ const tokensApi = {
487
519
  */
488
520
  burnAndBridge: (payload) => {
489
521
  return post(`${API_PREFIX$2}/burn_and_bridge`, payload, { withCredentials: false });
522
+ },
523
+ /**
524
+ * Claw back tokens from a wallet
525
+ * @param payload Token clawback request payload
526
+ * @returns Promise with transaction hash response
527
+ */
528
+ clawbackToken: (payload) => {
529
+ return post(`${API_PREFIX$2}/clawback`, payload, { withCredentials: false });
490
530
  }
491
531
  };const API_PREFIX$1 = `/${API_VERSION}/transactions`;
492
532
  /**
@@ -520,15 +560,13 @@ const transactionsApi = {
520
560
  /**
521
561
  * Estimate transaction fee
522
562
  * @param from Address of the transaction author
563
+ * @param to Address of the transaction recipient
523
564
  * @param value Value of the transaction
524
- * @param token Optional token address
565
+ * @param token Token address
525
566
  * @returns Promise with fee estimate response
526
567
  */
527
- estimateFee: (from, value, token) => {
528
- let url = `${API_PREFIX$1}/estimate_fee?from=${from}&value=${value}`;
529
- if (token) {
530
- url += `&token=${token}`;
531
- }
568
+ estimateFee: (from, to, value, token) => {
569
+ const url = `${API_PREFIX$1}/estimate_fee?from=${from}&value=${value}&to=${to}&token=${token}`;
532
570
  return get(url, { withCredentials: false });
533
571
  },
534
572
  /**
@@ -560,6 +598,7 @@ var AuthorityType;
560
598
  AuthorityType["ManageList"] = "ManageList";
561
599
  AuthorityType["UpdateMetadata"] = "UpdateMetadata";
562
600
  AuthorityType["Bridge"] = "Bridge";
601
+ AuthorityType["Clawback"] = "Clawback";
563
602
  })(AuthorityType || (AuthorityType = {}));
564
603
  var AuthorityAction;
565
604
  (function (AuthorityAction) {
@@ -1,5 +1,5 @@
1
1
  import type { Hash, HashWithToken } from '../../api/types';
2
- import type { MintInfo, TokenManageListPayload, TokenBurnPayload, TokenAuthorityPayload, TokenIssuePayload, TokenMintPayload, TokenPausePayload, TokenMetadataPayload, TokenBridgeAndMintPayload, TokenBurnAndBridgePayload } from './types';
2
+ import type { MintInfo, TokenManageListPayload, TokenBurnPayload, TokenAuthorityPayload, TokenIssuePayload, TokenMintPayload, TokenPausePayload, TokenMetadataPayload, TokenBridgeAndMintPayload, TokenBurnAndBridgePayload, TokenClawbackPayload } from './types';
3
3
  /**
4
4
  * Tokens API methods
5
5
  */
@@ -70,5 +70,11 @@ export declare const tokensApi: {
70
70
  * @returns Promise with transaction hash response
71
71
  */
72
72
  burnAndBridge: (payload: TokenBurnAndBridgePayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
73
+ /**
74
+ * Claw back tokens from a wallet
75
+ * @param payload Token clawback request payload
76
+ * @returns Promise with transaction hash response
77
+ */
78
+ clawbackToken: (payload: TokenClawbackPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
73
79
  };
74
80
  export default tokensApi;