@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
package/es/index.js CHANGED
@@ -1,4 +1,4 @@
1
- import {hexToBytes as hexToBytes$1,stringToBytes,keccak256,bytesToHex as bytesToHex$1,numberToHex,stringToHex,boolToHex}from'viem';import {encode}from'@ethereumjs/rlp';import axios from'axios';/**
1
+ import {hexToBytes as hexToBytes$1,stringToBytes,keccak256,bytesToHex as bytesToHex$1,numberToHex,stringToHex,boolToHex,isAddress}from'viem';import {encode,decode}from'@ethereumjs/rlp';import axios from'axios';/**
2
2
  * Derives the token account address given the wallet address and mint address.
3
3
  *
4
4
  * Address is 20 byte, 160 bits. Let's say if we want to support 50 billion
@@ -25,6 +25,81 @@ function deriveTokenAddress(walletAddress, mintAddress) {
25
25
  const hashBytes = hexToBytes$1(hashHex);
26
26
  const addressBytes = hashBytes.slice(12);
27
27
  return bytesToHex$1(addressBytes);
28
+ }const ADDRESS_HEX_RE = /^0x[0-9a-fA-F]{40}$/;
29
+ const BYTES_HEX_RE = /^0x([0-9a-fA-F]{2})*$/;
30
+ function innerEncodeRlpPayload(value) {
31
+ if (value === null || value === undefined) {
32
+ return new Uint8Array([]);
33
+ }
34
+ switch (value.kind) {
35
+ case 'string':
36
+ return new TextEncoder().encode(value.value);
37
+ case 'uint': {
38
+ if (typeof value.value === 'string' &&
39
+ !/^\d+$/.test(value.value)) {
40
+ throw new Error(`[1Money SDK]: Invalid uint string: ${value.value}`);
41
+ }
42
+ const n = typeof value.value === 'bigint'
43
+ ? value.value
44
+ : BigInt(value.value);
45
+ return n === BigInt(0)
46
+ ? new Uint8Array([])
47
+ : hexToBytes$1(numberToHex(n));
48
+ }
49
+ case 'bool':
50
+ return value.value
51
+ ? Uint8Array.from([1])
52
+ : new Uint8Array([]);
53
+ case 'bytes':
54
+ return value.value;
55
+ case 'list':
56
+ return value.value.map(v => innerEncodeRlpPayload(v));
57
+ case 'address':
58
+ case 'hex':
59
+ if (!BYTES_HEX_RE.test(value.value)) {
60
+ throw new Error(`[1Money SDK]: Invalid hex value: ${value.value}`);
61
+ }
62
+ if (value.kind === 'address' &&
63
+ !ADDRESS_HEX_RE.test(value.value)) {
64
+ throw new Error(`[1Money SDK]: Invalid address value: ${value.value}`);
65
+ }
66
+ return value.value === '0x'
67
+ ? new Uint8Array([])
68
+ : hexToBytes$1(value.value);
69
+ }
70
+ }
71
+ const rlpValue = {
72
+ address: (v) => ({
73
+ kind: 'address',
74
+ value: v
75
+ }),
76
+ hex: (v) => ({
77
+ kind: 'hex',
78
+ value: v
79
+ }),
80
+ string: (v) => ({
81
+ kind: 'string',
82
+ value: v
83
+ }),
84
+ uint: (v) => ({
85
+ kind: 'uint',
86
+ value: v
87
+ }),
88
+ bool: (v) => ({
89
+ kind: 'bool',
90
+ value: v
91
+ }),
92
+ bytes: (v) => ({
93
+ kind: 'bytes',
94
+ value: v
95
+ }),
96
+ list: (v) => ({
97
+ kind: 'list',
98
+ value: v
99
+ })
100
+ };
101
+ function encodeRlpPayload(payload) {
102
+ return encode(innerEncodeRlpPayload(payload));
28
103
  }// concurrent
29
104
  function safePromiseAll(arr) {
30
105
  // @ts-expect-error
@@ -46,11 +121,6 @@ async function safePromiseLine(arr) {
46
121
  }
47
122
  }
48
123
  return res;
49
- }function _typeof(ele) {
50
- if (typeof ele !== 'object')
51
- return (typeof ele).toLowerCase();
52
- const typeStr = Object.prototype.toString.call(ele);
53
- return typeStr.slice(8, typeStr.length - 1).toLowerCase();
54
124
  }/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
55
125
  /**
56
126
  * 4KB JS implementation of secp256k1 ECDSA / Schnorr signatures & ECDH.
@@ -706,8 +776,15 @@ const wNAF = (n) => {
706
776
  }
707
777
  }
708
778
  return { p, f }; // return both real and fake points for JIT
709
- };/**
779
+ };function _typeof(ele) {
780
+ if (typeof ele !== 'object')
781
+ return (typeof ele).toLowerCase();
782
+ const typeStr = Object.prototype.toString.call(ele);
783
+ return typeStr.slice(8, typeStr.length - 1).toLowerCase();
784
+ }/**
710
785
  * RLP encode a payload into a digest
786
+ * @deprecated Prefer the TransactionBuilder flow in `src/signing`
787
+ * (`prepare*Tx` + `.sign(...)`) to build and sign transactions.
711
788
  * @param payload Payload to encode
712
789
  * @returns RLP encoded payload
713
790
  */
@@ -715,9 +792,9 @@ function encodePayload(payload) {
715
792
  if (_typeof(payload) === 'array') {
716
793
  const formatted = payload.map((v) => {
717
794
  if (_typeof(v) === 'string') {
718
- if (/^0x[0-9a-fA-F]+$/.test(v)) {
795
+ if (/^0x([0-9a-fA-F]{2})*$/.test(v)) {
719
796
  // hex-encoded data → raw bytes
720
- return hexToBytes$1(v);
797
+ return v === '0x' ? new Uint8Array([]) : hexToBytes$1(v);
721
798
  }
722
799
  else if (/^\d+$/.test(v)) {
723
800
  // number-like string → hex → bytes
@@ -749,6 +826,9 @@ function encodePayload(payload) {
749
826
  }
750
827
  /**
751
828
  * Sign a message using the provided private key
829
+ * @deprecated Prefer the TransactionBuilder flow in `src/signing`
830
+ * (`prepare*Tx` + `.sign(createPrivateKeySigner(privateKey))`)
831
+ * for transaction signing.
752
832
  * @param payload Payload to sign
753
833
  * @param privateKey Private key to sign with
754
834
  * @returns Signature object with r, s, v components
@@ -809,7 +889,7 @@ function toHex(value) {
809
889
  }
810
890
  }
811
891
  catch (e) {
812
- console.error('[1Money toHex]: ', e);
892
+ console.error('[1Money SDK]: toHex error:', e);
813
893
  return '0x';
814
894
  }
815
895
  }function encodeRlpListHeader(length) {
@@ -890,7 +970,7 @@ function calcTxHash(payload, signature) {
890
970
  this._restScope = scope || this._restScope;
891
971
  // @ts-ignore
892
972
  if (this._restScope.length === 0) {
893
- console.warn('[1Money client]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
973
+ console.warn('[1Money SDK]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
894
974
  }
895
975
  else {
896
976
  let deletedCounter = 0;
@@ -905,7 +985,7 @@ function calcTxHash(payload, signature) {
905
985
  }
906
986
  });
907
987
  if (deletedCounter === this._restScope.length) {
908
- console.warn(`[1Money client]: The "${this._restScope.join(', ')}" had been called and the "rest" will never be triggered!`);
988
+ console.warn(`[1Money SDK]: The "${this._restScope.join(', ')}" had been called and the "rest" will never be triggered!`);
909
989
  }
910
990
  }
911
991
  return wrapper;
@@ -952,9 +1032,26 @@ class Request {
952
1032
  data
953
1033
  };
954
1034
  }
1035
+ mergeSignals(...signals) {
1036
+ const controller = new AbortController();
1037
+ const onAbort = () => controller.abort();
1038
+ const cleanups = [];
1039
+ for (const signal of signals) {
1040
+ if (signal.aborted) {
1041
+ controller.abort();
1042
+ break;
1043
+ }
1044
+ signal.addEventListener('abort', onAbort);
1045
+ cleanups.push(() => signal.removeEventListener('abort', onAbort));
1046
+ }
1047
+ return {
1048
+ signal: controller.signal,
1049
+ cleanup: () => cleanups.forEach(fn => fn()),
1050
+ };
1051
+ }
955
1052
  setting(config) {
956
1053
  if (!config)
957
- return console.warn('[1Money client]: setting method required correct parameters!');
1054
+ return console.warn('[1Money SDK]: setting method required correct parameters!');
958
1055
  this._config = { ...this._config, ...config };
959
1056
  }
960
1057
  request(options) {
@@ -1052,18 +1149,33 @@ class Request {
1052
1149
  let timer = null;
1053
1150
  let isTimeout = false;
1054
1151
  const _timeout = timeout ?? initTimeout;
1152
+ const controller = new AbortController();
1153
+ let signalCleanup = null;
1154
+ if (options.signal) {
1155
+ const merged = this.mergeSignals(options.signal, controller.signal);
1156
+ options.signal = merged.signal;
1157
+ signalCleanup = merged.cleanup;
1158
+ }
1159
+ else {
1160
+ options.signal = controller.signal;
1161
+ }
1055
1162
  // Cleanup function for timeout
1056
1163
  const cleanup = () => {
1057
1164
  if (timer !== null) {
1058
1165
  clearTimeout(timer);
1059
1166
  timer = null;
1060
1167
  }
1168
+ if (signalCleanup) {
1169
+ signalCleanup();
1170
+ signalCleanup = null;
1171
+ }
1061
1172
  };
1062
1173
  if (_timeout) {
1063
1174
  timer = setTimeout(async () => {
1064
1175
  try {
1065
1176
  isTimeout = true;
1066
1177
  cleanup();
1178
+ controller.abort();
1067
1179
  let err = this.parseError('timeout');
1068
1180
  // @ts-ignore
1069
1181
  const res = await Promise.resolve(callbacks.timeout(err, options.headers ?? {}));
@@ -1110,7 +1222,7 @@ class Request {
1110
1222
  return;
1111
1223
  cleanup();
1112
1224
  const data = err.response?.data ?? {};
1113
- 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)};`);
1225
+ 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)};`);
1114
1226
  const status = err.response?.status ?? 500;
1115
1227
  const headers = err.response?.headers ?? {};
1116
1228
  try {
@@ -1389,6 +1501,14 @@ const tokensApi = {
1389
1501
  */
1390
1502
  burnAndBridge: (payload) => {
1391
1503
  return post(`${API_PREFIX$2}/burn_and_bridge`, payload, { withCredentials: false });
1504
+ },
1505
+ /**
1506
+ * Claw back tokens from a wallet
1507
+ * @param payload Token clawback request payload
1508
+ * @returns Promise with transaction hash response
1509
+ */
1510
+ clawbackToken: (payload) => {
1511
+ return post(`${API_PREFIX$2}/clawback`, payload, { withCredentials: false });
1392
1512
  }
1393
1513
  };const API_PREFIX$1 = `/${API_VERSION}/transactions`;
1394
1514
  /**
@@ -1422,15 +1542,13 @@ const transactionsApi = {
1422
1542
  /**
1423
1543
  * Estimate transaction fee
1424
1544
  * @param from Address of the transaction author
1545
+ * @param to Address of the transaction recipient
1425
1546
  * @param value Value of the transaction
1426
- * @param token Optional token address
1547
+ * @param token Token address
1427
1548
  * @returns Promise with fee estimate response
1428
1549
  */
1429
- estimateFee: (from, value, token) => {
1430
- let url = `${API_PREFIX$1}/estimate_fee?from=${from}&value=${value}`;
1431
- if (token) {
1432
- url += `&token=${token}`;
1433
- }
1550
+ estimateFee: (from, to, value, token) => {
1551
+ const url = `${API_PREFIX$1}/estimate_fee?from=${from}&value=${value}&to=${to}&token=${token}`;
1434
1552
  return get(url, { withCredentials: false });
1435
1553
  },
1436
1554
  /**
@@ -1462,6 +1580,7 @@ var AuthorityType;
1462
1580
  AuthorityType["ManageList"] = "ManageList";
1463
1581
  AuthorityType["UpdateMetadata"] = "UpdateMetadata";
1464
1582
  AuthorityType["Bridge"] = "Bridge";
1583
+ AuthorityType["Clawback"] = "Clawback";
1465
1584
  })(AuthorityType || (AuthorityType = {}));
1466
1585
  var AuthorityAction;
1467
1586
  (function (AuthorityAction) {
@@ -1528,7 +1647,379 @@ function api(options) {
1528
1647
  */
1529
1648
  chain: chainApi,
1530
1649
  };
1531
- }var index = {
1650
+ }// secp256k1 curve order / 2 (maximum value for low-S signatures)
1651
+ // This prevents signature malleability by ensuring S is in the lower half of the curve order
1652
+ const SECP256K1_N_DIV_2 = BigInt('0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0');
1653
+ function validateSignature(signature) {
1654
+ // Validate that S value is in the lower half of the curve order
1655
+ // This prevents signature malleability attacks
1656
+ const s = BigInt(signature.s);
1657
+ if (s > SECP256K1_N_DIV_2) {
1658
+ throw new Error('[1Money SDK]: Invalid signature - high S value detected (potential malleability)');
1659
+ }
1660
+ }
1661
+ function calcSignedTxHash(payloadRlpBytes, signature) {
1662
+ // Decode the payload to get the transaction fields
1663
+ const payloadFields = decode(payloadRlpBytes);
1664
+ // Prepare v value based on its type
1665
+ const v = typeof signature.v === 'boolean'
1666
+ ? signature.v
1667
+ ? Uint8Array.from([1])
1668
+ : new Uint8Array([])
1669
+ : BigInt(signature.v);
1670
+ // Use library's encode to create the signed transaction structure: [[fields], v, r, s]
1671
+ const encoded = encode([
1672
+ payloadFields,
1673
+ v,
1674
+ hexToBytes$1(signature.r),
1675
+ hexToBytes$1(signature.s),
1676
+ ]);
1677
+ return keccak256(encoded);
1678
+ }
1679
+ function createPreparedTx(params) {
1680
+ const signatureHash = keccak256(params.rlpBytes);
1681
+ const attachSignature = (signature) => {
1682
+ // Validate signature to prevent malleability attacks
1683
+ validateSignature(signature);
1684
+ return {
1685
+ kind: params.kind,
1686
+ unsigned: params.unsigned,
1687
+ signatureHash,
1688
+ txHash: calcSignedTxHash(params.rlpBytes, signature),
1689
+ signature,
1690
+ toRequest: () => params.toRequest(params.unsigned, signature),
1691
+ };
1692
+ };
1693
+ return {
1694
+ kind: params.kind,
1695
+ unsigned: params.unsigned,
1696
+ rlpBytes: params.rlpBytes,
1697
+ signatureHash,
1698
+ attachSignature,
1699
+ sign: async (signer) => attachSignature(await signer.signDigest(signatureHash)),
1700
+ };
1701
+ }const UINT_STRING_RE = /^\d+$/;
1702
+ function fail(name, value) {
1703
+ throw new Error(`[1Money SDK]: Invalid ${name}: ${String(value)}`);
1704
+ }
1705
+ function assertPositiveInteger(name, value) {
1706
+ if (!Number.isSafeInteger(value) ||
1707
+ value <= 0) {
1708
+ fail(name, value);
1709
+ }
1710
+ }
1711
+ function assertNonNegativeInteger(name, value) {
1712
+ if (!Number.isSafeInteger(value) ||
1713
+ value < 0) {
1714
+ fail(name, value);
1715
+ }
1716
+ }
1717
+ function assertUintString(name, value) {
1718
+ if (!UINT_STRING_RE.test(value)) {
1719
+ fail(name, value);
1720
+ }
1721
+ }
1722
+ function assertOptionalUintString(name, value) {
1723
+ if (value === undefined)
1724
+ return;
1725
+ assertUintString(name, value);
1726
+ }
1727
+ function assertAddress(name, value) {
1728
+ // viem's isAddress validates both format and EIP-55 checksum
1729
+ // It accepts: lowercase, uppercase, and correctly checksummed addresses
1730
+ // It rejects: invalid format or incorrect checksum (when mixed case is used)
1731
+ if (!isAddress(value)) {
1732
+ fail(name, value);
1733
+ }
1734
+ }
1735
+ function validateChainAndNonce(unsigned) {
1736
+ assertPositiveInteger('chain_id', unsigned.chain_id);
1737
+ assertNonNegativeInteger('nonce', unsigned.nonce);
1738
+ }
1739
+ function validateRecipientValueToken(unsigned) {
1740
+ assertAddress('recipient', unsigned.recipient);
1741
+ assertUintString('value', unsigned.value);
1742
+ assertAddress('token', unsigned.token);
1743
+ }
1744
+ function validateValueToken(unsigned) {
1745
+ assertUintString('value', unsigned.value);
1746
+ assertAddress('token', unsigned.token);
1747
+ }function preparePaymentTx(unsigned) {
1748
+ validateChainAndNonce(unsigned);
1749
+ validateRecipientValueToken(unsigned);
1750
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1751
+ rlpValue.uint(unsigned.chain_id),
1752
+ rlpValue.uint(unsigned.nonce),
1753
+ rlpValue.address(unsigned.recipient),
1754
+ rlpValue.uint(unsigned.value),
1755
+ rlpValue.address(unsigned.token),
1756
+ ]));
1757
+ return createPreparedTx({
1758
+ kind: 'payment',
1759
+ unsigned,
1760
+ rlpBytes,
1761
+ toRequest: (payload, signature) => ({
1762
+ ...payload,
1763
+ signature,
1764
+ }),
1765
+ });
1766
+ }function prepareTokenAuthorityTx(unsigned) {
1767
+ validateChainAndNonce(unsigned);
1768
+ assertAddress('authority_address', unsigned.authority_address);
1769
+ assertAddress('token', unsigned.token);
1770
+ assertOptionalUintString('value', unsigned.value);
1771
+ const values = [
1772
+ rlpValue.uint(unsigned.chain_id),
1773
+ rlpValue.uint(unsigned.nonce),
1774
+ rlpValue.string(unsigned.action),
1775
+ rlpValue.string(unsigned.authority_type),
1776
+ rlpValue.address(unsigned.authority_address),
1777
+ rlpValue.address(unsigned.token),
1778
+ ];
1779
+ if (unsigned.value !== undefined) {
1780
+ values.push(rlpValue.uint(unsigned.value));
1781
+ }
1782
+ const rlpBytes = encodeRlpPayload(rlpValue.list(values));
1783
+ return createPreparedTx({
1784
+ kind: 'tokenAuthority',
1785
+ unsigned,
1786
+ rlpBytes,
1787
+ toRequest: (payload, signature) => ({
1788
+ ...payload,
1789
+ signature,
1790
+ }),
1791
+ });
1792
+ }function prepareTokenBridgeAndMintTx(unsigned) {
1793
+ validateChainAndNonce(unsigned);
1794
+ validateRecipientValueToken(unsigned);
1795
+ assertPositiveInteger('source_chain_id', unsigned.source_chain_id);
1796
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1797
+ rlpValue.uint(unsigned.chain_id),
1798
+ rlpValue.uint(unsigned.nonce),
1799
+ rlpValue.address(unsigned.recipient),
1800
+ rlpValue.uint(unsigned.value),
1801
+ rlpValue.address(unsigned.token),
1802
+ rlpValue.uint(unsigned.source_chain_id),
1803
+ rlpValue.string(unsigned.source_tx_hash),
1804
+ rlpValue.string(unsigned.bridge_metadata),
1805
+ ]));
1806
+ return createPreparedTx({
1807
+ kind: 'tokenBridgeAndMint',
1808
+ unsigned,
1809
+ rlpBytes,
1810
+ toRequest: (payload, signature) => ({
1811
+ ...payload,
1812
+ signature,
1813
+ }),
1814
+ });
1815
+ }function prepareTokenBurnTx(unsigned) {
1816
+ validateChainAndNonce(unsigned);
1817
+ validateValueToken(unsigned);
1818
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1819
+ rlpValue.uint(unsigned.chain_id),
1820
+ rlpValue.uint(unsigned.nonce),
1821
+ rlpValue.uint(unsigned.value),
1822
+ rlpValue.address(unsigned.token),
1823
+ ]));
1824
+ return createPreparedTx({
1825
+ kind: 'tokenBurn',
1826
+ unsigned,
1827
+ rlpBytes,
1828
+ toRequest: (payload, signature) => ({
1829
+ ...payload,
1830
+ signature,
1831
+ }),
1832
+ });
1833
+ }function prepareTokenBurnAndBridgeTx(unsigned) {
1834
+ validateChainAndNonce(unsigned);
1835
+ assertAddress('sender', unsigned.sender);
1836
+ validateValueToken(unsigned);
1837
+ assertPositiveInteger('destination_chain_id', unsigned.destination_chain_id);
1838
+ assertAddress('destination_address', unsigned.destination_address);
1839
+ assertUintString('escrow_fee', unsigned.escrow_fee);
1840
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1841
+ rlpValue.uint(unsigned.chain_id),
1842
+ rlpValue.uint(unsigned.nonce),
1843
+ rlpValue.address(unsigned.sender),
1844
+ rlpValue.uint(unsigned.value),
1845
+ rlpValue.address(unsigned.token),
1846
+ rlpValue.uint(unsigned.destination_chain_id),
1847
+ rlpValue.string(unsigned.destination_address),
1848
+ rlpValue.uint(unsigned.escrow_fee),
1849
+ rlpValue.string(unsigned.bridge_metadata),
1850
+ rlpValue.hex(unsigned.bridge_param),
1851
+ ]));
1852
+ return createPreparedTx({
1853
+ kind: 'tokenBurnAndBridge',
1854
+ unsigned,
1855
+ rlpBytes,
1856
+ toRequest: (payload, signature) => ({
1857
+ ...payload,
1858
+ signature,
1859
+ }),
1860
+ });
1861
+ }function prepareTokenClawbackTx(unsigned) {
1862
+ validateChainAndNonce(unsigned);
1863
+ validateRecipientValueToken(unsigned);
1864
+ assertAddress('from', unsigned.from);
1865
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1866
+ rlpValue.uint(unsigned.chain_id),
1867
+ rlpValue.uint(unsigned.nonce),
1868
+ rlpValue.address(unsigned.token),
1869
+ rlpValue.address(unsigned.from),
1870
+ rlpValue.address(unsigned.recipient),
1871
+ rlpValue.uint(unsigned.value),
1872
+ ]));
1873
+ return createPreparedTx({
1874
+ kind: 'tokenClawback',
1875
+ unsigned,
1876
+ rlpBytes,
1877
+ toRequest: (payload, signature) => ({
1878
+ ...payload,
1879
+ signature,
1880
+ }),
1881
+ });
1882
+ }function prepareTokenIssueTx(unsigned) {
1883
+ validateChainAndNonce(unsigned);
1884
+ assertNonNegativeInteger('decimals', unsigned.decimals);
1885
+ assertAddress('master_authority', unsigned.master_authority);
1886
+ const clawbackEnabled = unsigned.clawback_enabled ?? true;
1887
+ const unsignedWithDefaults = {
1888
+ ...unsigned,
1889
+ clawback_enabled: clawbackEnabled,
1890
+ };
1891
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1892
+ rlpValue.uint(unsignedWithDefaults.chain_id),
1893
+ rlpValue.uint(unsignedWithDefaults.nonce),
1894
+ rlpValue.string(unsignedWithDefaults.symbol),
1895
+ rlpValue.string(unsignedWithDefaults.name),
1896
+ rlpValue.uint(unsignedWithDefaults.decimals),
1897
+ rlpValue.address(unsignedWithDefaults.master_authority),
1898
+ rlpValue.bool(unsignedWithDefaults.is_private),
1899
+ rlpValue.bool(clawbackEnabled),
1900
+ ]));
1901
+ return createPreparedTx({
1902
+ kind: 'tokenIssue',
1903
+ unsigned: unsignedWithDefaults,
1904
+ rlpBytes,
1905
+ toRequest: (payload, signature) => ({
1906
+ ...payload,
1907
+ signature,
1908
+ }),
1909
+ });
1910
+ }function prepareTokenManageListTx(unsigned) {
1911
+ validateChainAndNonce(unsigned);
1912
+ assertAddress('address', unsigned.address);
1913
+ assertAddress('token', unsigned.token);
1914
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1915
+ rlpValue.uint(unsigned.chain_id),
1916
+ rlpValue.uint(unsigned.nonce),
1917
+ rlpValue.string(unsigned.action),
1918
+ rlpValue.address(unsigned.address),
1919
+ rlpValue.address(unsigned.token),
1920
+ ]));
1921
+ return createPreparedTx({
1922
+ kind: 'tokenManageList',
1923
+ unsigned,
1924
+ rlpBytes,
1925
+ toRequest: (payload, signature) => ({
1926
+ ...payload,
1927
+ signature,
1928
+ }),
1929
+ });
1930
+ }function prepareTokenMetadataTx(unsigned) {
1931
+ validateChainAndNonce(unsigned);
1932
+ assertAddress('token', unsigned.token);
1933
+ const additionalMetadataRlp = unsigned.additional_metadata.map(item => rlpValue.list([
1934
+ rlpValue.string(item.key),
1935
+ rlpValue.string(item.value),
1936
+ ]));
1937
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1938
+ rlpValue.uint(unsigned.chain_id),
1939
+ rlpValue.uint(unsigned.nonce),
1940
+ rlpValue.string(unsigned.name),
1941
+ rlpValue.string(unsigned.uri),
1942
+ rlpValue.address(unsigned.token),
1943
+ rlpValue.list(additionalMetadataRlp),
1944
+ ]));
1945
+ return createPreparedTx({
1946
+ kind: 'tokenMetadata',
1947
+ unsigned,
1948
+ rlpBytes,
1949
+ toRequest: (payload, signature) => ({
1950
+ ...payload,
1951
+ signature,
1952
+ }),
1953
+ });
1954
+ }function prepareTokenMintTx(unsigned) {
1955
+ validateChainAndNonce(unsigned);
1956
+ validateRecipientValueToken(unsigned);
1957
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1958
+ rlpValue.uint(unsigned.chain_id),
1959
+ rlpValue.uint(unsigned.nonce),
1960
+ rlpValue.address(unsigned.recipient),
1961
+ rlpValue.uint(unsigned.value),
1962
+ rlpValue.address(unsigned.token),
1963
+ ]));
1964
+ return createPreparedTx({
1965
+ kind: 'tokenMint',
1966
+ unsigned,
1967
+ rlpBytes,
1968
+ toRequest: (payload, signature) => ({
1969
+ ...payload,
1970
+ signature,
1971
+ }),
1972
+ });
1973
+ }function prepareTokenPauseTx(unsigned) {
1974
+ validateChainAndNonce(unsigned);
1975
+ assertAddress('token', unsigned.token);
1976
+ const rlpBytes = encodeRlpPayload(rlpValue.list([
1977
+ rlpValue.uint(unsigned.chain_id),
1978
+ rlpValue.uint(unsigned.nonce),
1979
+ rlpValue.string(unsigned.action),
1980
+ rlpValue.address(unsigned.token),
1981
+ ]));
1982
+ return createPreparedTx({
1983
+ kind: 'tokenPause',
1984
+ unsigned,
1985
+ rlpBytes,
1986
+ toRequest: (payload, signature) => ({
1987
+ ...payload,
1988
+ signature,
1989
+ }),
1990
+ });
1991
+ }const DIGEST_HEX_RE = /^0x[0-9a-fA-F]{64}$/;
1992
+ function createPrivateKeySigner(privateKey) {
1993
+ const privateKeyBytes = hexToBytes$1(privateKey);
1994
+ return {
1995
+ signDigest: async (digest) => {
1996
+ if (!DIGEST_HEX_RE.test(digest)) {
1997
+ throw new Error(`[1Money SDK]: Invalid digest: ${digest}`);
1998
+ }
1999
+ const signature = await signAsync(hexToBytes$1(digest), privateKeyBytes, { lowS: true });
2000
+ const compact = signature.toCompactRawBytes();
2001
+ const rBytes = compact.subarray(0, 32);
2002
+ const sBytes = compact.subarray(32, 64);
2003
+ return {
2004
+ r: bytesToHex$1(rBytes),
2005
+ s: bytesToHex$1(sBytes),
2006
+ v: signature.recovery,
2007
+ };
2008
+ },
2009
+ };
2010
+ }const TransactionBuilder = {
2011
+ payment: preparePaymentTx,
2012
+ tokenManageList: prepareTokenManageListTx,
2013
+ tokenBurn: prepareTokenBurnTx,
2014
+ tokenAuthority: prepareTokenAuthorityTx,
2015
+ tokenIssue: prepareTokenIssueTx,
2016
+ tokenMint: prepareTokenMintTx,
2017
+ tokenPause: prepareTokenPauseTx,
2018
+ tokenMetadata: prepareTokenMetadataTx,
2019
+ tokenBridgeAndMint: prepareTokenBridgeAndMintTx,
2020
+ tokenBurnAndBridge: prepareTokenBurnAndBridgeTx,
2021
+ tokenClawback: prepareTokenClawbackTx,
2022
+ };var index = {
1532
2023
  api,
1533
2024
  client: client$1,
1534
- };export{_typeof,api,calcTxHash,client$1 as client,index as default,deriveTokenAddress,encodePayload,safePromiseAll,safePromiseLine,signMessage,toHex};
2025
+ };export{TransactionBuilder,_typeof,api,calcSignedTxHash,calcTxHash,client$1 as client,createPreparedTx,createPrivateKeySigner,index as default,deriveTokenAddress,encodePayload,encodeRlpPayload,preparePaymentTx,prepareTokenAuthorityTx,prepareTokenBridgeAndMintTx,prepareTokenBurnAndBridgeTx,prepareTokenBurnTx,prepareTokenClawbackTx,prepareTokenIssueTx,prepareTokenManageListTx,prepareTokenMetadataTx,prepareTokenMintTx,prepareTokenPauseTx,rlpValue,safePromiseAll,safePromiseLine,signMessage,toHex};
@@ -0,0 +1,11 @@
1
+ export * from './payment';
2
+ export * from './tokenAuthority';
3
+ export * from './tokenBridgeAndMint';
4
+ export * from './tokenBurn';
5
+ export * from './tokenBurnAndBridge';
6
+ export * from './tokenClawback';
7
+ export * from './tokenIssue';
8
+ export * from './tokenManageList';
9
+ export * from './tokenMetadata';
10
+ export * from './tokenMint';
11
+ export * from './tokenPause';
@@ -0,0 +1,3 @@
1
+ import type { PaymentPayload } from '../../api/transactions/types';
2
+ export type PaymentUnsigned = Omit<PaymentPayload, 'signature'>;
3
+ export declare function preparePaymentTx(unsigned: PaymentUnsigned): import("../core").PreparedTx<PaymentUnsigned, PaymentPayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenAuthorityPayload } from '../../api/tokens/types';
2
+ export type TokenAuthorityUnsigned = Omit<TokenAuthorityPayload, 'signature'>;
3
+ export declare function prepareTokenAuthorityTx(unsigned: TokenAuthorityUnsigned): import("../core").PreparedTx<TokenAuthorityUnsigned, TokenAuthorityPayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenBridgeAndMintPayload } from '../../api/tokens/types';
2
+ export type TokenBridgeAndMintUnsigned = Omit<TokenBridgeAndMintPayload, 'signature'>;
3
+ export declare function prepareTokenBridgeAndMintTx(unsigned: TokenBridgeAndMintUnsigned): import("../core").PreparedTx<TokenBridgeAndMintUnsigned, TokenBridgeAndMintPayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenBurnPayload } from '../../api/tokens/types';
2
+ export type TokenBurnUnsigned = Omit<TokenBurnPayload, 'signature'>;
3
+ export declare function prepareTokenBurnTx(unsigned: TokenBurnUnsigned): import("../core").PreparedTx<TokenBurnUnsigned, TokenBurnPayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenBurnAndBridgePayload } from '../../api/tokens/types';
2
+ export type TokenBurnAndBridgeUnsigned = Omit<TokenBurnAndBridgePayload, 'signature'>;
3
+ export declare function prepareTokenBurnAndBridgeTx(unsigned: TokenBurnAndBridgeUnsigned): import("../core").PreparedTx<TokenBurnAndBridgeUnsigned, TokenBurnAndBridgePayload>;