@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/lib/index.js CHANGED
@@ -116,6 +116,81 @@ function deriveTokenAddress(walletAddress, mintAddress) {
116
116
  var hashBytes = viem.hexToBytes(hashHex);
117
117
  var addressBytes = hashBytes.slice(12);
118
118
  return viem.bytesToHex(addressBytes);
119
+ }var ADDRESS_HEX_RE = /^0x[0-9a-fA-F]{40}$/;
120
+ var BYTES_HEX_RE = /^0x([0-9a-fA-F]{2})*$/;
121
+ function innerEncodeRlpPayload(value) {
122
+ if (value === null || value === undefined) {
123
+ return new Uint8Array([]);
124
+ }
125
+ switch (value.kind) {
126
+ case 'string':
127
+ return new TextEncoder().encode(value.value);
128
+ case 'uint': {
129
+ if (typeof value.value === 'string' &&
130
+ !/^\d+$/.test(value.value)) {
131
+ throw new Error("[1Money SDK]: Invalid uint string: ".concat(value.value));
132
+ }
133
+ var n = typeof value.value === 'bigint'
134
+ ? value.value
135
+ : BigInt(value.value);
136
+ return n === BigInt(0)
137
+ ? new Uint8Array([])
138
+ : viem.hexToBytes(viem.numberToHex(n));
139
+ }
140
+ case 'bool':
141
+ return value.value
142
+ ? Uint8Array.from([1])
143
+ : new Uint8Array([]);
144
+ case 'bytes':
145
+ return value.value;
146
+ case 'list':
147
+ return value.value.map(function (v) { return innerEncodeRlpPayload(v); });
148
+ case 'address':
149
+ case 'hex':
150
+ if (!BYTES_HEX_RE.test(value.value)) {
151
+ throw new Error("[1Money SDK]: Invalid hex value: ".concat(value.value));
152
+ }
153
+ if (value.kind === 'address' &&
154
+ !ADDRESS_HEX_RE.test(value.value)) {
155
+ throw new Error("[1Money SDK]: Invalid address value: ".concat(value.value));
156
+ }
157
+ return value.value === '0x'
158
+ ? new Uint8Array([])
159
+ : viem.hexToBytes(value.value);
160
+ }
161
+ }
162
+ var rlpValue = {
163
+ address: function (v) { return ({
164
+ kind: 'address',
165
+ value: v
166
+ }); },
167
+ hex: function (v) { return ({
168
+ kind: 'hex',
169
+ value: v
170
+ }); },
171
+ string: function (v) { return ({
172
+ kind: 'string',
173
+ value: v
174
+ }); },
175
+ uint: function (v) { return ({
176
+ kind: 'uint',
177
+ value: v
178
+ }); },
179
+ bool: function (v) { return ({
180
+ kind: 'bool',
181
+ value: v
182
+ }); },
183
+ bytes: function (v) { return ({
184
+ kind: 'bytes',
185
+ value: v
186
+ }); },
187
+ list: function (v) { return ({
188
+ kind: 'list',
189
+ value: v
190
+ }); }
191
+ };
192
+ function encodeRlpPayload(payload) {
193
+ return rlp.encode(innerEncodeRlpPayload(payload));
119
194
  }// concurrent
120
195
  function safePromiseAll(arr) {
121
196
  // @ts-expect-error
@@ -155,11 +230,6 @@ function safePromiseLine(arr) {
155
230
  }
156
231
  });
157
232
  });
158
- }function _typeof(ele) {
159
- if (typeof ele !== 'object')
160
- return (typeof ele).toLowerCase();
161
- var typeStr = Object.prototype.toString.call(ele);
162
- return typeStr.slice(8, typeStr.length - 1).toLowerCase();
163
233
  }/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
164
234
  /**
165
235
  * 4KB JS implementation of secp256k1 ECDSA / Schnorr signatures & ECDH.
@@ -815,8 +885,15 @@ const wNAF = (n) => {
815
885
  }
816
886
  }
817
887
  return { p, f }; // return both real and fake points for JIT
818
- };/**
888
+ };function _typeof(ele) {
889
+ if (typeof ele !== 'object')
890
+ return (typeof ele).toLowerCase();
891
+ var typeStr = Object.prototype.toString.call(ele);
892
+ return typeStr.slice(8, typeStr.length - 1).toLowerCase();
893
+ }/**
819
894
  * RLP encode a payload into a digest
895
+ * @deprecated Prefer the TransactionBuilder flow in `src/signing`
896
+ * (`prepare*Tx` + `.sign(...)`) to build and sign transactions.
820
897
  * @param payload Payload to encode
821
898
  * @returns RLP encoded payload
822
899
  */
@@ -824,9 +901,9 @@ function encodePayload(payload) {
824
901
  if (_typeof(payload) === 'array') {
825
902
  var formatted = payload.map(function (v) {
826
903
  if (_typeof(v) === 'string') {
827
- if (/^0x[0-9a-fA-F]+$/.test(v)) {
904
+ if (/^0x([0-9a-fA-F]{2})*$/.test(v)) {
828
905
  // hex-encoded data → raw bytes
829
- return viem.hexToBytes(v);
906
+ return v === '0x' ? new Uint8Array([]) : viem.hexToBytes(v);
830
907
  }
831
908
  else if (/^\d+$/.test(v)) {
832
909
  // number-like string → hex → bytes
@@ -858,6 +935,9 @@ function encodePayload(payload) {
858
935
  }
859
936
  /**
860
937
  * Sign a message using the provided private key
938
+ * @deprecated Prefer the TransactionBuilder flow in `src/signing`
939
+ * (`prepare*Tx` + `.sign(createPrivateKeySigner(privateKey))`)
940
+ * for transaction signing.
861
941
  * @param payload Payload to sign
862
942
  * @param privateKey Private key to sign with
863
943
  * @returns Signature object with r, s, v components
@@ -928,7 +1008,7 @@ function toHex(value) {
928
1008
  }
929
1009
  }
930
1010
  catch (e) {
931
- console.error('[1Money toHex]: ', e);
1011
+ console.error('[1Money SDK]: toHex error:', e);
932
1012
  return '0x';
933
1013
  }
934
1014
  }function encodeRlpListHeader(length) {
@@ -1004,7 +1084,7 @@ function calcTxHash(payload, signature) {
1004
1084
  _this._restScope = scope || _this._restScope;
1005
1085
  // @ts-ignore
1006
1086
  if (_this._restScope.length === 0) {
1007
- console.warn('[1Money client]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
1087
+ console.warn('[1Money SDK]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
1008
1088
  }
1009
1089
  else {
1010
1090
  var deletedCounter_1 = 0;
@@ -1019,7 +1099,7 @@ function calcTxHash(payload, signature) {
1019
1099
  }
1020
1100
  });
1021
1101
  if (deletedCounter_1 === _this._restScope.length) {
1022
- console.warn("[1Money client]: The \"".concat(_this._restScope.join(', '), "\" had been called and the \"rest\" will never be triggered!"));
1102
+ console.warn("[1Money SDK]: The \"".concat(_this._restScope.join(', '), "\" had been called and the \"rest\" will never be triggered!"));
1023
1103
  }
1024
1104
  }
1025
1105
  return wrapper;
@@ -1066,9 +1146,36 @@ var Request = /** @class */ (function () {
1066
1146
  data: data
1067
1147
  };
1068
1148
  };
1149
+ Request.prototype.mergeSignals = function () {
1150
+ var signals = [];
1151
+ for (var _i = 0; _i < arguments.length; _i++) {
1152
+ signals[_i] = arguments[_i];
1153
+ }
1154
+ var controller = new AbortController();
1155
+ var onAbort = function () { return controller.abort(); };
1156
+ var cleanups = [];
1157
+ var _loop_2 = function (signal) {
1158
+ if (signal.aborted) {
1159
+ controller.abort();
1160
+ return "break";
1161
+ }
1162
+ signal.addEventListener('abort', onAbort);
1163
+ cleanups.push(function () { return signal.removeEventListener('abort', onAbort); });
1164
+ };
1165
+ for (var _a = 0, signals_1 = signals; _a < signals_1.length; _a++) {
1166
+ var signal = signals_1[_a];
1167
+ var state_1 = _loop_2(signal);
1168
+ if (state_1 === "break")
1169
+ break;
1170
+ }
1171
+ return {
1172
+ signal: controller.signal,
1173
+ cleanup: function () { return cleanups.forEach(function (fn) { return fn(); }); },
1174
+ };
1175
+ };
1069
1176
  Request.prototype.setting = function (config) {
1070
1177
  if (!config)
1071
- return console.warn('[1Money client]: setting method required correct parameters!');
1178
+ return console.warn('[1Money SDK]: setting method required correct parameters!');
1072
1179
  this._config = __assign(__assign({}, this._config), config);
1073
1180
  };
1074
1181
  Request.prototype.request = function (options) {
@@ -1154,12 +1261,26 @@ var Request = /** @class */ (function () {
1154
1261
  var timer = null;
1155
1262
  var isTimeout = false;
1156
1263
  var _timeout = timeout !== null && timeout !== void 0 ? timeout : initTimeout;
1264
+ var controller = new AbortController();
1265
+ var signalCleanup = null;
1266
+ if (options.signal) {
1267
+ var merged = _this.mergeSignals(options.signal, controller.signal);
1268
+ options.signal = merged.signal;
1269
+ signalCleanup = merged.cleanup;
1270
+ }
1271
+ else {
1272
+ options.signal = controller.signal;
1273
+ }
1157
1274
  // Cleanup function for timeout
1158
1275
  var cleanup = function () {
1159
1276
  if (timer !== null) {
1160
1277
  clearTimeout(timer);
1161
1278
  timer = null;
1162
1279
  }
1280
+ if (signalCleanup) {
1281
+ signalCleanup();
1282
+ signalCleanup = null;
1283
+ }
1163
1284
  };
1164
1285
  if (_timeout) {
1165
1286
  timer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
@@ -1171,6 +1292,7 @@ var Request = /** @class */ (function () {
1171
1292
  _c.trys.push([0, 2, , 3]);
1172
1293
  isTimeout = true;
1173
1294
  cleanup();
1295
+ controller.abort();
1174
1296
  err = this.parseError('timeout');
1175
1297
  return [4 /*yield*/, Promise.resolve(callbacks.timeout(err, (_a = options.headers) !== null && _a !== void 0 ? _a : {}))];
1176
1298
  case 1:
@@ -1245,7 +1367,7 @@ var Request = /** @class */ (function () {
1245
1367
  return [2 /*return*/];
1246
1368
  cleanup();
1247
1369
  data = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
1248
- console.error("[1Money client]: Error(".concat((_c = err.status) !== null && _c !== void 0 ? _c : 500, ", ").concat((_d = err.code) !== null && _d !== void 0 ? _d : 'UNKNOWN', "), Message: ").concat(err.message, ", Config: ").concat((_f = err.config) === null || _f === void 0 ? void 0 : _f.method, ", ").concat((_h = (_g = err.config) === null || _g === void 0 ? void 0 : _g.baseURL) !== null && _h !== void 0 ? _h : '', ", ").concat((_k = (_j = err.config) === null || _j === void 0 ? void 0 : _j.url) !== null && _k !== void 0 ? _k : '', ", ").concat(JSON.stringify((_o = (_l = err.config) === null || _l === void 0 ? void 0 : _l.headers) !== null && _o !== void 0 ? _o : {}), ", Request: ").concat(JSON.stringify((_q = (_p = err.config) === null || _p === void 0 ? void 0 : _p.data) !== null && _q !== void 0 ? _q : {}), ", Response: ").concat(JSON.stringify(data), ";"));
1370
+ console.error("[1Money SDK]: Error(".concat((_c = err.status) !== null && _c !== void 0 ? _c : 500, ", ").concat((_d = err.code) !== null && _d !== void 0 ? _d : 'UNKNOWN', "), Message: ").concat(err.message, ", Config: ").concat((_f = err.config) === null || _f === void 0 ? void 0 : _f.method, ", ").concat((_h = (_g = err.config) === null || _g === void 0 ? void 0 : _g.baseURL) !== null && _h !== void 0 ? _h : '', ", ").concat((_k = (_j = err.config) === null || _j === void 0 ? void 0 : _j.url) !== null && _k !== void 0 ? _k : '', ", ").concat(JSON.stringify((_o = (_l = err.config) === null || _l === void 0 ? void 0 : _l.headers) !== null && _o !== void 0 ? _o : {}), ", Request: ").concat(JSON.stringify((_q = (_p = err.config) === null || _p === void 0 ? void 0 : _p.data) !== null && _q !== void 0 ? _q : {}), ", Response: ").concat(JSON.stringify(data), ";"));
1249
1371
  status = (_s = (_r = err.response) === null || _r === void 0 ? void 0 : _r.status) !== null && _s !== void 0 ? _s : 500;
1250
1372
  headers = (_u = (_t = err.response) === null || _t === void 0 ? void 0 : _t.headers) !== null && _u !== void 0 ? _u : {};
1251
1373
  _w.label = 1;
@@ -1483,6 +1605,14 @@ var tokensApi = {
1483
1605
  */
1484
1606
  burnAndBridge: function (payload) {
1485
1607
  return post("".concat(API_PREFIX$2, "/burn_and_bridge"), payload, { withCredentials: false });
1608
+ },
1609
+ /**
1610
+ * Claw back tokens from a wallet
1611
+ * @param payload Token clawback request payload
1612
+ * @returns Promise with transaction hash response
1613
+ */
1614
+ clawbackToken: function (payload) {
1615
+ return post("".concat(API_PREFIX$2, "/clawback"), payload, { withCredentials: false });
1486
1616
  }
1487
1617
  };var API_PREFIX$1 = "/".concat(API_VERSION, "/transactions");
1488
1618
  /**
@@ -1516,15 +1646,13 @@ var transactionsApi = {
1516
1646
  /**
1517
1647
  * Estimate transaction fee
1518
1648
  * @param from Address of the transaction author
1649
+ * @param to Address of the transaction recipient
1519
1650
  * @param value Value of the transaction
1520
- * @param token Optional token address
1651
+ * @param token Token address
1521
1652
  * @returns Promise with fee estimate response
1522
1653
  */
1523
- estimateFee: function (from, value, token) {
1524
- var url = "".concat(API_PREFIX$1, "/estimate_fee?from=").concat(from, "&value=").concat(value);
1525
- if (token) {
1526
- url += "&token=".concat(token);
1527
- }
1654
+ estimateFee: function (from, to, value, token) {
1655
+ var url = "".concat(API_PREFIX$1, "/estimate_fee?from=").concat(from, "&value=").concat(value, "&to=").concat(to, "&token=").concat(token);
1528
1656
  return get(url, { withCredentials: false });
1529
1657
  },
1530
1658
  /**
@@ -1556,6 +1684,7 @@ var AuthorityType;
1556
1684
  AuthorityType["ManageList"] = "ManageList";
1557
1685
  AuthorityType["UpdateMetadata"] = "UpdateMetadata";
1558
1686
  AuthorityType["Bridge"] = "Bridge";
1687
+ AuthorityType["Clawback"] = "Clawback";
1559
1688
  })(AuthorityType || (AuthorityType = {}));
1560
1689
  var AuthorityAction;
1561
1690
  (function (AuthorityAction) {
@@ -1622,7 +1751,368 @@ function api(options) {
1622
1751
  */
1623
1752
  chain: chainApi,
1624
1753
  };
1625
- }var index = {
1754
+ }// secp256k1 curve order / 2 (maximum value for low-S signatures)
1755
+ // This prevents signature malleability by ensuring S is in the lower half of the curve order
1756
+ var SECP256K1_N_DIV_2 = BigInt('0x7FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF5D576E7357A4501DDFE92F46681B20A0');
1757
+ function validateSignature(signature) {
1758
+ // Validate that S value is in the lower half of the curve order
1759
+ // This prevents signature malleability attacks
1760
+ var s = BigInt(signature.s);
1761
+ if (s > SECP256K1_N_DIV_2) {
1762
+ throw new Error('[1Money SDK]: Invalid signature - high S value detected (potential malleability)');
1763
+ }
1764
+ }
1765
+ function calcSignedTxHash(payloadRlpBytes, signature) {
1766
+ // Decode the payload to get the transaction fields
1767
+ var payloadFields = rlp.decode(payloadRlpBytes);
1768
+ // Prepare v value based on its type
1769
+ var v = typeof signature.v === 'boolean'
1770
+ ? signature.v
1771
+ ? Uint8Array.from([1])
1772
+ : new Uint8Array([])
1773
+ : BigInt(signature.v);
1774
+ // Use library's encode to create the signed transaction structure: [[fields], v, r, s]
1775
+ var encoded = rlp.encode([
1776
+ payloadFields,
1777
+ v,
1778
+ viem.hexToBytes(signature.r),
1779
+ viem.hexToBytes(signature.s),
1780
+ ]);
1781
+ return viem.keccak256(encoded);
1782
+ }
1783
+ function createPreparedTx(params) {
1784
+ var _this = this;
1785
+ var signatureHash = viem.keccak256(params.rlpBytes);
1786
+ var attachSignature = function (signature) {
1787
+ // Validate signature to prevent malleability attacks
1788
+ validateSignature(signature);
1789
+ return {
1790
+ kind: params.kind,
1791
+ unsigned: params.unsigned,
1792
+ signatureHash: signatureHash,
1793
+ txHash: calcSignedTxHash(params.rlpBytes, signature),
1794
+ signature: signature,
1795
+ toRequest: function () {
1796
+ return params.toRequest(params.unsigned, signature);
1797
+ },
1798
+ };
1799
+ };
1800
+ return {
1801
+ kind: params.kind,
1802
+ unsigned: params.unsigned,
1803
+ rlpBytes: params.rlpBytes,
1804
+ signatureHash: signatureHash,
1805
+ attachSignature: attachSignature,
1806
+ sign: function (signer) { return __awaiter(_this, void 0, void 0, function () {
1807
+ var _a;
1808
+ return __generator(this, function (_b) {
1809
+ switch (_b.label) {
1810
+ case 0:
1811
+ _a = attachSignature;
1812
+ return [4 /*yield*/, signer.signDigest(signatureHash)];
1813
+ case 1: return [2 /*return*/, _a.apply(void 0, [_b.sent()])];
1814
+ }
1815
+ });
1816
+ }); },
1817
+ };
1818
+ }var UINT_STRING_RE = /^\d+$/;
1819
+ function fail(name, value) {
1820
+ throw new Error("[1Money SDK]: Invalid ".concat(name, ": ").concat(String(value)));
1821
+ }
1822
+ function assertPositiveInteger(name, value) {
1823
+ if (!Number.isSafeInteger(value) ||
1824
+ value <= 0) {
1825
+ fail(name, value);
1826
+ }
1827
+ }
1828
+ function assertNonNegativeInteger(name, value) {
1829
+ if (!Number.isSafeInteger(value) ||
1830
+ value < 0) {
1831
+ fail(name, value);
1832
+ }
1833
+ }
1834
+ function assertUintString(name, value) {
1835
+ if (!UINT_STRING_RE.test(value)) {
1836
+ fail(name, value);
1837
+ }
1838
+ }
1839
+ function assertOptionalUintString(name, value) {
1840
+ if (value === undefined)
1841
+ return;
1842
+ assertUintString(name, value);
1843
+ }
1844
+ function assertAddress(name, value) {
1845
+ // viem's isAddress validates both format and EIP-55 checksum
1846
+ // It accepts: lowercase, uppercase, and correctly checksummed addresses
1847
+ // It rejects: invalid format or incorrect checksum (when mixed case is used)
1848
+ if (!viem.isAddress(value)) {
1849
+ fail(name, value);
1850
+ }
1851
+ }
1852
+ function validateChainAndNonce(unsigned) {
1853
+ assertPositiveInteger('chain_id', unsigned.chain_id);
1854
+ assertNonNegativeInteger('nonce', unsigned.nonce);
1855
+ }
1856
+ function validateRecipientValueToken(unsigned) {
1857
+ assertAddress('recipient', unsigned.recipient);
1858
+ assertUintString('value', unsigned.value);
1859
+ assertAddress('token', unsigned.token);
1860
+ }
1861
+ function validateValueToken(unsigned) {
1862
+ assertUintString('value', unsigned.value);
1863
+ assertAddress('token', unsigned.token);
1864
+ }function preparePaymentTx(unsigned) {
1865
+ validateChainAndNonce(unsigned);
1866
+ validateRecipientValueToken(unsigned);
1867
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
1868
+ rlpValue.uint(unsigned.chain_id),
1869
+ rlpValue.uint(unsigned.nonce),
1870
+ rlpValue.address(unsigned.recipient),
1871
+ rlpValue.uint(unsigned.value),
1872
+ rlpValue.address(unsigned.token),
1873
+ ]));
1874
+ return createPreparedTx({
1875
+ kind: 'payment',
1876
+ unsigned: unsigned,
1877
+ rlpBytes: rlpBytes,
1878
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
1879
+ });
1880
+ }function prepareTokenAuthorityTx(unsigned) {
1881
+ validateChainAndNonce(unsigned);
1882
+ assertAddress('authority_address', unsigned.authority_address);
1883
+ assertAddress('token', unsigned.token);
1884
+ assertOptionalUintString('value', unsigned.value);
1885
+ var values = [
1886
+ rlpValue.uint(unsigned.chain_id),
1887
+ rlpValue.uint(unsigned.nonce),
1888
+ rlpValue.string(unsigned.action),
1889
+ rlpValue.string(unsigned.authority_type),
1890
+ rlpValue.address(unsigned.authority_address),
1891
+ rlpValue.address(unsigned.token),
1892
+ ];
1893
+ if (unsigned.value !== undefined) {
1894
+ values.push(rlpValue.uint(unsigned.value));
1895
+ }
1896
+ var rlpBytes = encodeRlpPayload(rlpValue.list(values));
1897
+ return createPreparedTx({
1898
+ kind: 'tokenAuthority',
1899
+ unsigned: unsigned,
1900
+ rlpBytes: rlpBytes,
1901
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
1902
+ });
1903
+ }function prepareTokenBridgeAndMintTx(unsigned) {
1904
+ validateChainAndNonce(unsigned);
1905
+ validateRecipientValueToken(unsigned);
1906
+ assertPositiveInteger('source_chain_id', unsigned.source_chain_id);
1907
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
1908
+ rlpValue.uint(unsigned.chain_id),
1909
+ rlpValue.uint(unsigned.nonce),
1910
+ rlpValue.address(unsigned.recipient),
1911
+ rlpValue.uint(unsigned.value),
1912
+ rlpValue.address(unsigned.token),
1913
+ rlpValue.uint(unsigned.source_chain_id),
1914
+ rlpValue.string(unsigned.source_tx_hash),
1915
+ rlpValue.string(unsigned.bridge_metadata),
1916
+ ]));
1917
+ return createPreparedTx({
1918
+ kind: 'tokenBridgeAndMint',
1919
+ unsigned: unsigned,
1920
+ rlpBytes: rlpBytes,
1921
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
1922
+ });
1923
+ }function prepareTokenBurnTx(unsigned) {
1924
+ validateChainAndNonce(unsigned);
1925
+ validateValueToken(unsigned);
1926
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
1927
+ rlpValue.uint(unsigned.chain_id),
1928
+ rlpValue.uint(unsigned.nonce),
1929
+ rlpValue.uint(unsigned.value),
1930
+ rlpValue.address(unsigned.token),
1931
+ ]));
1932
+ return createPreparedTx({
1933
+ kind: 'tokenBurn',
1934
+ unsigned: unsigned,
1935
+ rlpBytes: rlpBytes,
1936
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
1937
+ });
1938
+ }function prepareTokenBurnAndBridgeTx(unsigned) {
1939
+ validateChainAndNonce(unsigned);
1940
+ assertAddress('sender', unsigned.sender);
1941
+ validateValueToken(unsigned);
1942
+ assertPositiveInteger('destination_chain_id', unsigned.destination_chain_id);
1943
+ assertAddress('destination_address', unsigned.destination_address);
1944
+ assertUintString('escrow_fee', unsigned.escrow_fee);
1945
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
1946
+ rlpValue.uint(unsigned.chain_id),
1947
+ rlpValue.uint(unsigned.nonce),
1948
+ rlpValue.address(unsigned.sender),
1949
+ rlpValue.uint(unsigned.value),
1950
+ rlpValue.address(unsigned.token),
1951
+ rlpValue.uint(unsigned.destination_chain_id),
1952
+ rlpValue.string(unsigned.destination_address),
1953
+ rlpValue.uint(unsigned.escrow_fee),
1954
+ rlpValue.string(unsigned.bridge_metadata),
1955
+ rlpValue.hex(unsigned.bridge_param),
1956
+ ]));
1957
+ return createPreparedTx({
1958
+ kind: 'tokenBurnAndBridge',
1959
+ unsigned: unsigned,
1960
+ rlpBytes: rlpBytes,
1961
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
1962
+ });
1963
+ }function prepareTokenClawbackTx(unsigned) {
1964
+ validateChainAndNonce(unsigned);
1965
+ validateRecipientValueToken(unsigned);
1966
+ assertAddress('from', unsigned.from);
1967
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
1968
+ rlpValue.uint(unsigned.chain_id),
1969
+ rlpValue.uint(unsigned.nonce),
1970
+ rlpValue.address(unsigned.token),
1971
+ rlpValue.address(unsigned.from),
1972
+ rlpValue.address(unsigned.recipient),
1973
+ rlpValue.uint(unsigned.value),
1974
+ ]));
1975
+ return createPreparedTx({
1976
+ kind: 'tokenClawback',
1977
+ unsigned: unsigned,
1978
+ rlpBytes: rlpBytes,
1979
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
1980
+ });
1981
+ }function prepareTokenIssueTx(unsigned) {
1982
+ var _a;
1983
+ validateChainAndNonce(unsigned);
1984
+ assertNonNegativeInteger('decimals', unsigned.decimals);
1985
+ assertAddress('master_authority', unsigned.master_authority);
1986
+ var clawbackEnabled = (_a = unsigned.clawback_enabled) !== null && _a !== void 0 ? _a : true;
1987
+ var unsignedWithDefaults = __assign(__assign({}, unsigned), { clawback_enabled: clawbackEnabled });
1988
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
1989
+ rlpValue.uint(unsignedWithDefaults.chain_id),
1990
+ rlpValue.uint(unsignedWithDefaults.nonce),
1991
+ rlpValue.string(unsignedWithDefaults.symbol),
1992
+ rlpValue.string(unsignedWithDefaults.name),
1993
+ rlpValue.uint(unsignedWithDefaults.decimals),
1994
+ rlpValue.address(unsignedWithDefaults.master_authority),
1995
+ rlpValue.bool(unsignedWithDefaults.is_private),
1996
+ rlpValue.bool(clawbackEnabled),
1997
+ ]));
1998
+ return createPreparedTx({
1999
+ kind: 'tokenIssue',
2000
+ unsigned: unsignedWithDefaults,
2001
+ rlpBytes: rlpBytes,
2002
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
2003
+ });
2004
+ }function prepareTokenManageListTx(unsigned) {
2005
+ validateChainAndNonce(unsigned);
2006
+ assertAddress('address', unsigned.address);
2007
+ assertAddress('token', unsigned.token);
2008
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
2009
+ rlpValue.uint(unsigned.chain_id),
2010
+ rlpValue.uint(unsigned.nonce),
2011
+ rlpValue.string(unsigned.action),
2012
+ rlpValue.address(unsigned.address),
2013
+ rlpValue.address(unsigned.token),
2014
+ ]));
2015
+ return createPreparedTx({
2016
+ kind: 'tokenManageList',
2017
+ unsigned: unsigned,
2018
+ rlpBytes: rlpBytes,
2019
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
2020
+ });
2021
+ }function prepareTokenMetadataTx(unsigned) {
2022
+ validateChainAndNonce(unsigned);
2023
+ assertAddress('token', unsigned.token);
2024
+ var additionalMetadataRlp = unsigned.additional_metadata.map(function (item) {
2025
+ return rlpValue.list([
2026
+ rlpValue.string(item.key),
2027
+ rlpValue.string(item.value),
2028
+ ]);
2029
+ });
2030
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
2031
+ rlpValue.uint(unsigned.chain_id),
2032
+ rlpValue.uint(unsigned.nonce),
2033
+ rlpValue.string(unsigned.name),
2034
+ rlpValue.string(unsigned.uri),
2035
+ rlpValue.address(unsigned.token),
2036
+ rlpValue.list(additionalMetadataRlp),
2037
+ ]));
2038
+ return createPreparedTx({
2039
+ kind: 'tokenMetadata',
2040
+ unsigned: unsigned,
2041
+ rlpBytes: rlpBytes,
2042
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
2043
+ });
2044
+ }function prepareTokenMintTx(unsigned) {
2045
+ validateChainAndNonce(unsigned);
2046
+ validateRecipientValueToken(unsigned);
2047
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
2048
+ rlpValue.uint(unsigned.chain_id),
2049
+ rlpValue.uint(unsigned.nonce),
2050
+ rlpValue.address(unsigned.recipient),
2051
+ rlpValue.uint(unsigned.value),
2052
+ rlpValue.address(unsigned.token),
2053
+ ]));
2054
+ return createPreparedTx({
2055
+ kind: 'tokenMint',
2056
+ unsigned: unsigned,
2057
+ rlpBytes: rlpBytes,
2058
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
2059
+ });
2060
+ }function prepareTokenPauseTx(unsigned) {
2061
+ validateChainAndNonce(unsigned);
2062
+ assertAddress('token', unsigned.token);
2063
+ var rlpBytes = encodeRlpPayload(rlpValue.list([
2064
+ rlpValue.uint(unsigned.chain_id),
2065
+ rlpValue.uint(unsigned.nonce),
2066
+ rlpValue.string(unsigned.action),
2067
+ rlpValue.address(unsigned.token),
2068
+ ]));
2069
+ return createPreparedTx({
2070
+ kind: 'tokenPause',
2071
+ unsigned: unsigned,
2072
+ rlpBytes: rlpBytes,
2073
+ toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
2074
+ });
2075
+ }var DIGEST_HEX_RE = /^0x[0-9a-fA-F]{64}$/;
2076
+ function createPrivateKeySigner(privateKey) {
2077
+ var _this = this;
2078
+ var privateKeyBytes = viem.hexToBytes(privateKey);
2079
+ return {
2080
+ signDigest: function (digest) { return __awaiter(_this, void 0, void 0, function () {
2081
+ var signature, compact, rBytes, sBytes;
2082
+ return __generator(this, function (_a) {
2083
+ switch (_a.label) {
2084
+ case 0:
2085
+ if (!DIGEST_HEX_RE.test(digest)) {
2086
+ throw new Error("[1Money SDK]: Invalid digest: ".concat(digest));
2087
+ }
2088
+ return [4 /*yield*/, signAsync(viem.hexToBytes(digest), privateKeyBytes, { lowS: true })];
2089
+ case 1:
2090
+ signature = _a.sent();
2091
+ compact = signature.toCompactRawBytes();
2092
+ rBytes = compact.subarray(0, 32);
2093
+ sBytes = compact.subarray(32, 64);
2094
+ return [2 /*return*/, {
2095
+ r: viem.bytesToHex(rBytes),
2096
+ s: viem.bytesToHex(sBytes),
2097
+ v: signature.recovery,
2098
+ }];
2099
+ }
2100
+ });
2101
+ }); },
2102
+ };
2103
+ }var TransactionBuilder = {
2104
+ payment: preparePaymentTx,
2105
+ tokenManageList: prepareTokenManageListTx,
2106
+ tokenBurn: prepareTokenBurnTx,
2107
+ tokenAuthority: prepareTokenAuthorityTx,
2108
+ tokenIssue: prepareTokenIssueTx,
2109
+ tokenMint: prepareTokenMintTx,
2110
+ tokenPause: prepareTokenPauseTx,
2111
+ tokenMetadata: prepareTokenMetadataTx,
2112
+ tokenBridgeAndMint: prepareTokenBridgeAndMintTx,
2113
+ tokenBurnAndBridge: prepareTokenBurnAndBridgeTx,
2114
+ tokenClawback: prepareTokenClawbackTx,
2115
+ };var index = {
1626
2116
  api: api,
1627
2117
  client: client$1,
1628
- };exports._typeof=_typeof;exports.api=api;exports.calcTxHash=calcTxHash;exports.client=client$1;exports.default=index;exports.deriveTokenAddress=deriveTokenAddress;exports.encodePayload=encodePayload;exports.safePromiseAll=safePromiseAll;exports.safePromiseLine=safePromiseLine;exports.signMessage=signMessage;exports.toHex=toHex;
2118
+ };exports.TransactionBuilder=TransactionBuilder;exports._typeof=_typeof;exports.api=api;exports.calcSignedTxHash=calcSignedTxHash;exports.calcTxHash=calcTxHash;exports.client=client$1;exports.createPreparedTx=createPreparedTx;exports.createPrivateKeySigner=createPrivateKeySigner;exports.default=index;exports.deriveTokenAddress=deriveTokenAddress;exports.encodePayload=encodePayload;exports.encodeRlpPayload=encodeRlpPayload;exports.preparePaymentTx=preparePaymentTx;exports.prepareTokenAuthorityTx=prepareTokenAuthorityTx;exports.prepareTokenBridgeAndMintTx=prepareTokenBridgeAndMintTx;exports.prepareTokenBurnAndBridgeTx=prepareTokenBurnAndBridgeTx;exports.prepareTokenBurnTx=prepareTokenBurnTx;exports.prepareTokenClawbackTx=prepareTokenClawbackTx;exports.prepareTokenIssueTx=prepareTokenIssueTx;exports.prepareTokenManageListTx=prepareTokenManageListTx;exports.prepareTokenMetadataTx=prepareTokenMetadataTx;exports.prepareTokenMintTx=prepareTokenMintTx;exports.prepareTokenPauseTx=prepareTokenPauseTx;exports.rlpValue=rlpValue;exports.safePromiseAll=safePromiseAll;exports.safePromiseLine=safePromiseLine;exports.signMessage=signMessage;exports.toHex=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>;