@1money/protocol-ts-sdk 2.0.3 → 2.1.0-beta.0
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.
- package/.claude/settings.local.json +3 -7
- package/es/api/index.js +1 -1
- package/es/api/tokens/types.d.ts +21 -1
- package/es/api/transactions/types.d.ts +14 -0
- package/es/client/index.js +1 -1
- package/es/index.js +206 -113
- package/es/signing/builders/buildTx.d.ts +13 -0
- package/es/signing/builders/payment.d.ts +1 -1
- package/es/signing/builders/tokenAuthority.d.ts +1 -1
- package/es/signing/builders/tokenBridgeAndMint.d.ts +1 -1
- package/es/signing/builders/tokenBurn.d.ts +1 -1
- package/es/signing/builders/tokenBurnAndBridge.d.ts +1 -1
- package/es/signing/builders/tokenClawback.d.ts +1 -1
- package/es/signing/builders/tokenIssue.d.ts +1 -1
- package/es/signing/builders/tokenManageList.d.ts +1 -1
- package/es/signing/builders/tokenMetadata.d.ts +1 -1
- package/es/signing/builders/tokenMint.d.ts +1 -1
- package/es/signing/builders/tokenPause.d.ts +1 -1
- package/es/utils/index.d.ts +1 -0
- package/es/utils/index.js +89 -1
- package/es/utils/memo/index.d.ts +3 -0
- package/es/utils/memo/rlp.d.ts +3 -0
- package/es/utils/memo/types.d.ts +15 -0
- package/es/utils/memo/validate.d.ts +2 -0
- package/lib/api/index.js +24 -1
- package/lib/api/tokens/types.d.ts +21 -1
- package/lib/api/transactions/types.d.ts +14 -0
- package/lib/client/index.js +24 -1
- package/lib/index.js +225 -113
- package/lib/signing/builders/buildTx.d.ts +13 -0
- package/lib/signing/builders/payment.d.ts +1 -1
- package/lib/signing/builders/tokenAuthority.d.ts +1 -1
- package/lib/signing/builders/tokenBridgeAndMint.d.ts +1 -1
- package/lib/signing/builders/tokenBurn.d.ts +1 -1
- package/lib/signing/builders/tokenBurnAndBridge.d.ts +1 -1
- package/lib/signing/builders/tokenClawback.d.ts +1 -1
- package/lib/signing/builders/tokenIssue.d.ts +1 -1
- package/lib/signing/builders/tokenManageList.d.ts +1 -1
- package/lib/signing/builders/tokenMetadata.d.ts +1 -1
- package/lib/signing/builders/tokenMint.d.ts +1 -1
- package/lib/signing/builders/tokenPause.d.ts +1 -1
- package/lib/utils/index.d.ts +1 -0
- package/lib/utils/index.js +110 -2
- package/lib/utils/memo/index.d.ts +3 -0
- package/lib/utils/memo/rlp.d.ts +3 -0
- package/lib/utils/memo/types.d.ts +15 -0
- package/lib/utils/memo/validate.d.ts +2 -0
- package/package.json +1 -1
- package/umd/1money-protocol-ts-sdk.min.js +3 -3
package/lib/index.js
CHANGED
|
@@ -14,6 +14,20 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
14
14
|
***************************************************************************** */
|
|
15
15
|
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
16
16
|
|
|
17
|
+
var extendStatics = function(d, b) {
|
|
18
|
+
extendStatics = Object.setPrototypeOf ||
|
|
19
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
20
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
21
|
+
return extendStatics(d, b);
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
function __extends(d, b) {
|
|
25
|
+
if (typeof b !== "function" && b !== null)
|
|
26
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
27
|
+
extendStatics(d, b);
|
|
28
|
+
function __() { this.constructor = d; }
|
|
29
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
30
|
+
}
|
|
17
31
|
|
|
18
32
|
var __assign = function() {
|
|
19
33
|
__assign = Object.assign || function __assign(t) {
|
|
@@ -191,6 +205,100 @@ var rlpValue = {
|
|
|
191
205
|
};
|
|
192
206
|
function encodeRlpPayload(payload) {
|
|
193
207
|
return rlp.encode(innerEncodeRlpPayload(payload));
|
|
208
|
+
}var MEMO_TYPE_MAX_BYTES = 128;
|
|
209
|
+
var MEMO_FORMAT_MAX_BYTES = 64;
|
|
210
|
+
var MEMO_DATA_MAX_BYTES = 256;
|
|
211
|
+
// Currently unreachable given the per-field caps above (128 + 64 + 256 + 16 =
|
|
212
|
+
// 464); retained as a future-proofing guard matching Rust.
|
|
213
|
+
var MEMO_TOTAL_MAX_BYTES = 512;
|
|
214
|
+
// RLP overhead allowance used by the aggregate size check, matching the
|
|
215
|
+
// Rust `Memo::byte_size` constant so JS and Rust accept/reject the same set
|
|
216
|
+
// of inputs.
|
|
217
|
+
var MEMO_RLP_HEADER_ALLOWANCE = 16;
|
|
218
|
+
var MemoValidationError = /** @class */ (function (_super) {
|
|
219
|
+
__extends(MemoValidationError, _super);
|
|
220
|
+
function MemoValidationError(code, message) {
|
|
221
|
+
var _this = _super.call(this, message) || this;
|
|
222
|
+
_this.code = code;
|
|
223
|
+
_this.name = 'MemoValidationError';
|
|
224
|
+
return _this;
|
|
225
|
+
}
|
|
226
|
+
return MemoValidationError;
|
|
227
|
+
}(Error));var enc = new TextEncoder();
|
|
228
|
+
// RFC 3986 unreserved + gen-delims + sub-delims + percent. Matches
|
|
229
|
+
// `is_url_safe` in `om-primitives-types/.../memo.rs`.
|
|
230
|
+
var URL_SAFE_RE = /^[A-Za-z0-9\-._~:/?#[\]@!$&'()*+,;=%]*$/;
|
|
231
|
+
function utf8Len(s) {
|
|
232
|
+
return enc.encode(s).length;
|
|
233
|
+
}
|
|
234
|
+
// Mirrors Rust `Memo::byte_size`: sum of subfield UTF-8 byte lengths plus a
|
|
235
|
+
// fixed 16-byte allowance for RLP framing. Used only by the aggregate cap.
|
|
236
|
+
function byteSize(memo) {
|
|
237
|
+
var _a, _b, _c;
|
|
238
|
+
return (utf8Len((_a = memo.type) !== null && _a !== void 0 ? _a : '') +
|
|
239
|
+
utf8Len((_b = memo.format) !== null && _b !== void 0 ? _b : '') +
|
|
240
|
+
utf8Len((_c = memo.data) !== null && _c !== void 0 ? _c : '') +
|
|
241
|
+
MEMO_RLP_HEADER_ALLOWANCE);
|
|
242
|
+
}
|
|
243
|
+
// Validate per the same rules as Rust `Memo::validate()`.
|
|
244
|
+
//
|
|
245
|
+
// Per-field checks fire before the aggregate check, matching Rust ordering
|
|
246
|
+
// — clients should expect the same error code the server would return.
|
|
247
|
+
function validateMemo(memo) {
|
|
248
|
+
var _a, _b, _c;
|
|
249
|
+
var t = (_a = memo.type) !== null && _a !== void 0 ? _a : '';
|
|
250
|
+
if (t.length > 0) {
|
|
251
|
+
var len = utf8Len(t);
|
|
252
|
+
if (len > MEMO_TYPE_MAX_BYTES) {
|
|
253
|
+
throw new MemoValidationError('MEMO_TYPE_TOO_LONG', "memo.type exceeds ".concat(MEMO_TYPE_MAX_BYTES, " bytes (got ").concat(len, ")"));
|
|
254
|
+
}
|
|
255
|
+
if (!URL_SAFE_RE.test(t)) {
|
|
256
|
+
throw new MemoValidationError('MEMO_TYPE_INVALID_CHARS', 'memo.type contains non-URL-safe characters');
|
|
257
|
+
}
|
|
258
|
+
}
|
|
259
|
+
var f = (_b = memo.format) !== null && _b !== void 0 ? _b : '';
|
|
260
|
+
if (f.length > 0) {
|
|
261
|
+
var len = utf8Len(f);
|
|
262
|
+
if (len > MEMO_FORMAT_MAX_BYTES) {
|
|
263
|
+
throw new MemoValidationError('MEMO_FORMAT_TOO_LONG', "memo.format exceeds ".concat(MEMO_FORMAT_MAX_BYTES, " bytes (got ").concat(len, ")"));
|
|
264
|
+
}
|
|
265
|
+
if (!URL_SAFE_RE.test(f)) {
|
|
266
|
+
throw new MemoValidationError('MEMO_FORMAT_INVALID_CHARS', 'memo.format contains non-URL-safe characters');
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
var d = (_c = memo.data) !== null && _c !== void 0 ? _c : '';
|
|
270
|
+
if (d.length > 0) {
|
|
271
|
+
var len = utf8Len(d);
|
|
272
|
+
if (len > MEMO_DATA_MAX_BYTES) {
|
|
273
|
+
throw new MemoValidationError('MEMO_DATA_TOO_LONG', "memo.data exceeds ".concat(MEMO_DATA_MAX_BYTES, " bytes (got ").concat(len, ")"));
|
|
274
|
+
}
|
|
275
|
+
// Reject NUL and any C0/C1 control codepoint (Unicode general category
|
|
276
|
+
// Cc). Rust's check is `c == '\0' || c.is_control()`.
|
|
277
|
+
for (var _i = 0, d_1 = d; _i < d_1.length; _i++) {
|
|
278
|
+
var ch = d_1[_i];
|
|
279
|
+
var cp = ch.codePointAt(0);
|
|
280
|
+
if (cp === 0 ||
|
|
281
|
+
cp <= 0x1f ||
|
|
282
|
+
(cp >= 0x7f && cp <= 0x9f) ||
|
|
283
|
+
(cp >= 0xd800 && cp <= 0xdfff)) {
|
|
284
|
+
throw new MemoValidationError('MEMO_DATA_CONTROL_CHARS', 'memo.data contains null bytes or Unicode control/surrogate codepoints');
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
var total = byteSize(memo);
|
|
289
|
+
if (total > MEMO_TOTAL_MAX_BYTES) {
|
|
290
|
+
throw new MemoValidationError('MEMO_TOO_LARGE', "memo object exceeds ".concat(MEMO_TOTAL_MAX_BYTES, " bytes (got ").concat(total, ")"));
|
|
291
|
+
}
|
|
292
|
+
}// RLP encoding of `Memo` matches the Rust `RlpEncodable` derive: a list of
|
|
293
|
+
// three byte strings in field order [type, format, data]. Empty subfields
|
|
294
|
+
// encode as empty byte strings (RLP `0x80`).
|
|
295
|
+
function memoRlpList(memo) {
|
|
296
|
+
var _a, _b, _c;
|
|
297
|
+
return rlpValue.list([
|
|
298
|
+
rlpValue.string((_a = memo.type) !== null && _a !== void 0 ? _a : ''),
|
|
299
|
+
rlpValue.string((_b = memo.format) !== null && _b !== void 0 ? _b : ''),
|
|
300
|
+
rlpValue.string((_c = memo.data) !== null && _c !== void 0 ? _c : ''),
|
|
301
|
+
]);
|
|
194
302
|
}// concurrent
|
|
195
303
|
function safePromiseAll(arr) {
|
|
196
304
|
// @ts-expect-error
|
|
@@ -1813,6 +1921,46 @@ function createPreparedTx(params) {
|
|
|
1813
1921
|
});
|
|
1814
1922
|
}); },
|
|
1815
1923
|
};
|
|
1924
|
+
}// Build a `PreparedTx` for any transaction shape:
|
|
1925
|
+
// 1. Prepend `[chain_id, nonce]` and the caller's `payloadFields` into one
|
|
1926
|
+
// RLP inner list.
|
|
1927
|
+
// 2. Branch on `unsigned.memo`:
|
|
1928
|
+
// - V1 (memo absent): RLP-encode `innerList` directly. Bytes are byte-
|
|
1929
|
+
// identical to the pre-memo SDK. `kind` is `<kindV1>`.
|
|
1930
|
+
// - V2 (memo present): validate the memo, then RLP-encode
|
|
1931
|
+
// `[innerList, memoRlpList(memo)]` — the `WithMemo<T>` envelope shape.
|
|
1932
|
+
// `kind` is `<kindV1>_v2`.
|
|
1933
|
+
// 3. Wire the result into `createPreparedTx`.
|
|
1934
|
+
//
|
|
1935
|
+
// `memo == null` deliberately catches both `null` and `undefined` so untyped
|
|
1936
|
+
// JS callers behave the same as strict TypeScript callers (whose declared
|
|
1937
|
+
// `Memo | undefined` would only ever produce `undefined`).
|
|
1938
|
+
//
|
|
1939
|
+
// Builders only need to call validators, construct `payloadFields`, and pass
|
|
1940
|
+
// `toRequest`.
|
|
1941
|
+
function buildTx(opts) {
|
|
1942
|
+
var innerList = rlpValue.list(__spreadArray([
|
|
1943
|
+
rlpValue.uint(opts.unsigned.chain_id),
|
|
1944
|
+
rlpValue.uint(opts.unsigned.nonce)
|
|
1945
|
+
], opts.payloadFields, true));
|
|
1946
|
+
var memo = opts.unsigned.memo;
|
|
1947
|
+
var rlpBytes;
|
|
1948
|
+
var kind;
|
|
1949
|
+
if (memo == null) {
|
|
1950
|
+
rlpBytes = encodeRlpPayload(innerList);
|
|
1951
|
+
kind = opts.kind;
|
|
1952
|
+
}
|
|
1953
|
+
else {
|
|
1954
|
+
validateMemo(memo);
|
|
1955
|
+
rlpBytes = encodeRlpPayload(rlpValue.list([innerList, memoRlpList(memo)]));
|
|
1956
|
+
kind = "".concat(opts.kind, "_v2");
|
|
1957
|
+
}
|
|
1958
|
+
return createPreparedTx({
|
|
1959
|
+
kind: kind,
|
|
1960
|
+
unsigned: opts.unsigned,
|
|
1961
|
+
rlpBytes: rlpBytes,
|
|
1962
|
+
toRequest: opts.toRequest,
|
|
1963
|
+
});
|
|
1816
1964
|
}var UINT_STRING_RE = /^\d+$/;
|
|
1817
1965
|
function fail(name, value) {
|
|
1818
1966
|
throw new Error("[1Money SDK]: Invalid ".concat(name, ": ").concat(String(value)));
|
|
@@ -1862,17 +2010,14 @@ function validateValueToken(unsigned) {
|
|
|
1862
2010
|
}function preparePaymentTx(unsigned) {
|
|
1863
2011
|
validateChainAndNonce(unsigned);
|
|
1864
2012
|
validateRecipientValueToken(unsigned);
|
|
1865
|
-
|
|
1866
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1867
|
-
rlpValue.uint(unsigned.nonce),
|
|
1868
|
-
rlpValue.address(unsigned.recipient),
|
|
1869
|
-
rlpValue.uint(unsigned.value),
|
|
1870
|
-
rlpValue.address(unsigned.token),
|
|
1871
|
-
]));
|
|
1872
|
-
return createPreparedTx({
|
|
2013
|
+
return buildTx({
|
|
1873
2014
|
kind: 'payment',
|
|
1874
2015
|
unsigned: unsigned,
|
|
1875
|
-
|
|
2016
|
+
payloadFields: [
|
|
2017
|
+
rlpValue.address(unsigned.recipient),
|
|
2018
|
+
rlpValue.uint(unsigned.value),
|
|
2019
|
+
rlpValue.address(unsigned.token),
|
|
2020
|
+
],
|
|
1876
2021
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
1877
2022
|
});
|
|
1878
2023
|
}function prepareTokenAuthorityTx(unsigned) {
|
|
@@ -1880,57 +2025,48 @@ function validateValueToken(unsigned) {
|
|
|
1880
2025
|
assertAddress('authority_address', unsigned.authority_address);
|
|
1881
2026
|
assertAddress('token', unsigned.token);
|
|
1882
2027
|
assertOptionalUintString('value', unsigned.value);
|
|
1883
|
-
var
|
|
1884
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1885
|
-
rlpValue.uint(unsigned.nonce),
|
|
2028
|
+
var payloadFields = [
|
|
1886
2029
|
rlpValue.string(unsigned.action),
|
|
1887
2030
|
rlpValue.string(unsigned.authority_type),
|
|
1888
2031
|
rlpValue.address(unsigned.authority_address),
|
|
1889
2032
|
rlpValue.address(unsigned.token),
|
|
1890
2033
|
];
|
|
1891
2034
|
if (unsigned.value !== undefined) {
|
|
1892
|
-
|
|
2035
|
+
payloadFields.push(rlpValue.uint(unsigned.value));
|
|
1893
2036
|
}
|
|
1894
|
-
|
|
1895
|
-
return createPreparedTx({
|
|
2037
|
+
return buildTx({
|
|
1896
2038
|
kind: 'tokenAuthority',
|
|
1897
2039
|
unsigned: unsigned,
|
|
1898
|
-
|
|
2040
|
+
payloadFields: payloadFields,
|
|
1899
2041
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
1900
2042
|
});
|
|
1901
2043
|
}function prepareTokenBridgeAndMintTx(unsigned) {
|
|
1902
2044
|
validateChainAndNonce(unsigned);
|
|
1903
2045
|
validateRecipientValueToken(unsigned);
|
|
1904
2046
|
assertPositiveInteger('source_chain_id', unsigned.source_chain_id);
|
|
1905
|
-
|
|
1906
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1907
|
-
rlpValue.uint(unsigned.nonce),
|
|
1908
|
-
rlpValue.address(unsigned.recipient),
|
|
1909
|
-
rlpValue.uint(unsigned.value),
|
|
1910
|
-
rlpValue.address(unsigned.token),
|
|
1911
|
-
rlpValue.uint(unsigned.source_chain_id),
|
|
1912
|
-
rlpValue.string(unsigned.source_tx_hash),
|
|
1913
|
-
rlpValue.string(unsigned.bridge_metadata),
|
|
1914
|
-
]));
|
|
1915
|
-
return createPreparedTx({
|
|
2047
|
+
return buildTx({
|
|
1916
2048
|
kind: 'tokenBridgeAndMint',
|
|
1917
2049
|
unsigned: unsigned,
|
|
1918
|
-
|
|
2050
|
+
payloadFields: [
|
|
2051
|
+
rlpValue.address(unsigned.recipient),
|
|
2052
|
+
rlpValue.uint(unsigned.value),
|
|
2053
|
+
rlpValue.address(unsigned.token),
|
|
2054
|
+
rlpValue.uint(unsigned.source_chain_id),
|
|
2055
|
+
rlpValue.string(unsigned.source_tx_hash),
|
|
2056
|
+
rlpValue.string(unsigned.bridge_metadata),
|
|
2057
|
+
],
|
|
1919
2058
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
1920
2059
|
});
|
|
1921
2060
|
}function prepareTokenBurnTx(unsigned) {
|
|
1922
2061
|
validateChainAndNonce(unsigned);
|
|
1923
2062
|
validateValueToken(unsigned);
|
|
1924
|
-
|
|
1925
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1926
|
-
rlpValue.uint(unsigned.nonce),
|
|
1927
|
-
rlpValue.uint(unsigned.value),
|
|
1928
|
-
rlpValue.address(unsigned.token),
|
|
1929
|
-
]));
|
|
1930
|
-
return createPreparedTx({
|
|
2063
|
+
return buildTx({
|
|
1931
2064
|
kind: 'tokenBurn',
|
|
1932
2065
|
unsigned: unsigned,
|
|
1933
|
-
|
|
2066
|
+
payloadFields: [
|
|
2067
|
+
rlpValue.uint(unsigned.value),
|
|
2068
|
+
rlpValue.address(unsigned.token),
|
|
2069
|
+
],
|
|
1934
2070
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
1935
2071
|
});
|
|
1936
2072
|
}function prepareTokenBurnAndBridgeTx(unsigned) {
|
|
@@ -1940,40 +2076,34 @@ function validateValueToken(unsigned) {
|
|
|
1940
2076
|
assertPositiveInteger('destination_chain_id', unsigned.destination_chain_id);
|
|
1941
2077
|
assertAddress('destination_address', unsigned.destination_address);
|
|
1942
2078
|
assertUintString('escrow_fee', unsigned.escrow_fee);
|
|
1943
|
-
|
|
1944
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1945
|
-
rlpValue.uint(unsigned.nonce),
|
|
1946
|
-
rlpValue.address(unsigned.sender),
|
|
1947
|
-
rlpValue.uint(unsigned.value),
|
|
1948
|
-
rlpValue.address(unsigned.token),
|
|
1949
|
-
rlpValue.uint(unsigned.destination_chain_id),
|
|
1950
|
-
rlpValue.string(unsigned.destination_address),
|
|
1951
|
-
rlpValue.uint(unsigned.escrow_fee),
|
|
1952
|
-
rlpValue.string(unsigned.bridge_metadata),
|
|
1953
|
-
rlpValue.hex(unsigned.bridge_param),
|
|
1954
|
-
]));
|
|
1955
|
-
return createPreparedTx({
|
|
2079
|
+
return buildTx({
|
|
1956
2080
|
kind: 'tokenBurnAndBridge',
|
|
1957
2081
|
unsigned: unsigned,
|
|
1958
|
-
|
|
2082
|
+
payloadFields: [
|
|
2083
|
+
rlpValue.address(unsigned.sender),
|
|
2084
|
+
rlpValue.uint(unsigned.value),
|
|
2085
|
+
rlpValue.address(unsigned.token),
|
|
2086
|
+
rlpValue.uint(unsigned.destination_chain_id),
|
|
2087
|
+
rlpValue.string(unsigned.destination_address),
|
|
2088
|
+
rlpValue.uint(unsigned.escrow_fee),
|
|
2089
|
+
rlpValue.string(unsigned.bridge_metadata),
|
|
2090
|
+
rlpValue.hex(unsigned.bridge_param),
|
|
2091
|
+
],
|
|
1959
2092
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
1960
2093
|
});
|
|
1961
2094
|
}function prepareTokenClawbackTx(unsigned) {
|
|
1962
2095
|
validateChainAndNonce(unsigned);
|
|
1963
2096
|
validateRecipientValueToken(unsigned);
|
|
1964
2097
|
assertAddress('from', unsigned.from);
|
|
1965
|
-
|
|
1966
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1967
|
-
rlpValue.uint(unsigned.nonce),
|
|
1968
|
-
rlpValue.address(unsigned.token),
|
|
1969
|
-
rlpValue.address(unsigned.from),
|
|
1970
|
-
rlpValue.address(unsigned.recipient),
|
|
1971
|
-
rlpValue.uint(unsigned.value),
|
|
1972
|
-
]));
|
|
1973
|
-
return createPreparedTx({
|
|
2098
|
+
return buildTx({
|
|
1974
2099
|
kind: 'tokenClawback',
|
|
1975
2100
|
unsigned: unsigned,
|
|
1976
|
-
|
|
2101
|
+
payloadFields: [
|
|
2102
|
+
rlpValue.address(unsigned.token),
|
|
2103
|
+
rlpValue.address(unsigned.from),
|
|
2104
|
+
rlpValue.address(unsigned.recipient),
|
|
2105
|
+
rlpValue.uint(unsigned.value),
|
|
2106
|
+
],
|
|
1977
2107
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
1978
2108
|
});
|
|
1979
2109
|
}function prepareTokenIssueTx(unsigned) {
|
|
@@ -1983,91 +2113,73 @@ function validateValueToken(unsigned) {
|
|
|
1983
2113
|
assertAddress('master_authority', unsigned.master_authority);
|
|
1984
2114
|
var clawbackEnabled = (_a = unsigned.clawback_enabled) !== null && _a !== void 0 ? _a : true;
|
|
1985
2115
|
var unsignedWithDefaults = __assign(__assign({}, unsigned), { clawback_enabled: clawbackEnabled });
|
|
1986
|
-
|
|
1987
|
-
rlpValue.uint(unsignedWithDefaults.chain_id),
|
|
1988
|
-
rlpValue.uint(unsignedWithDefaults.nonce),
|
|
1989
|
-
rlpValue.string(unsignedWithDefaults.symbol),
|
|
1990
|
-
rlpValue.string(unsignedWithDefaults.name),
|
|
1991
|
-
rlpValue.uint(unsignedWithDefaults.decimals),
|
|
1992
|
-
rlpValue.address(unsignedWithDefaults.master_authority),
|
|
1993
|
-
rlpValue.bool(unsignedWithDefaults.is_private),
|
|
1994
|
-
rlpValue.bool(clawbackEnabled),
|
|
1995
|
-
]));
|
|
1996
|
-
return createPreparedTx({
|
|
2116
|
+
return buildTx({
|
|
1997
2117
|
kind: 'tokenIssue',
|
|
1998
2118
|
unsigned: unsignedWithDefaults,
|
|
1999
|
-
|
|
2119
|
+
payloadFields: [
|
|
2120
|
+
rlpValue.string(unsignedWithDefaults.symbol),
|
|
2121
|
+
rlpValue.string(unsignedWithDefaults.name),
|
|
2122
|
+
rlpValue.uint(unsignedWithDefaults.decimals),
|
|
2123
|
+
rlpValue.address(unsignedWithDefaults.master_authority),
|
|
2124
|
+
rlpValue.bool(unsignedWithDefaults.is_private),
|
|
2125
|
+
rlpValue.bool(clawbackEnabled),
|
|
2126
|
+
],
|
|
2000
2127
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
2001
2128
|
});
|
|
2002
2129
|
}function prepareTokenManageListTx(unsigned) {
|
|
2003
2130
|
validateChainAndNonce(unsigned);
|
|
2004
2131
|
assertAddress('address', unsigned.address);
|
|
2005
2132
|
assertAddress('token', unsigned.token);
|
|
2006
|
-
|
|
2007
|
-
rlpValue.uint(unsigned.chain_id),
|
|
2008
|
-
rlpValue.uint(unsigned.nonce),
|
|
2009
|
-
rlpValue.string(unsigned.action),
|
|
2010
|
-
rlpValue.address(unsigned.address),
|
|
2011
|
-
rlpValue.address(unsigned.token),
|
|
2012
|
-
]));
|
|
2013
|
-
return createPreparedTx({
|
|
2133
|
+
return buildTx({
|
|
2014
2134
|
kind: 'tokenManageList',
|
|
2015
2135
|
unsigned: unsigned,
|
|
2016
|
-
|
|
2136
|
+
payloadFields: [
|
|
2137
|
+
rlpValue.string(unsigned.action),
|
|
2138
|
+
rlpValue.address(unsigned.address),
|
|
2139
|
+
rlpValue.address(unsigned.token),
|
|
2140
|
+
],
|
|
2017
2141
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
2018
2142
|
});
|
|
2019
2143
|
}function prepareTokenMetadataTx(unsigned) {
|
|
2020
2144
|
validateChainAndNonce(unsigned);
|
|
2021
2145
|
assertAddress('token', unsigned.token);
|
|
2022
2146
|
var additionalMetadataRlp = unsigned.additional_metadata.map(function (item) {
|
|
2023
|
-
return rlpValue.list([
|
|
2024
|
-
rlpValue.string(item.key),
|
|
2025
|
-
rlpValue.string(item.value),
|
|
2026
|
-
]);
|
|
2147
|
+
return rlpValue.list([rlpValue.string(item.key), rlpValue.string(item.value)]);
|
|
2027
2148
|
});
|
|
2028
|
-
|
|
2029
|
-
rlpValue.uint(unsigned.chain_id),
|
|
2030
|
-
rlpValue.uint(unsigned.nonce),
|
|
2031
|
-
rlpValue.string(unsigned.name),
|
|
2032
|
-
rlpValue.string(unsigned.uri),
|
|
2033
|
-
rlpValue.address(unsigned.token),
|
|
2034
|
-
rlpValue.list(additionalMetadataRlp),
|
|
2035
|
-
]));
|
|
2036
|
-
return createPreparedTx({
|
|
2149
|
+
return buildTx({
|
|
2037
2150
|
kind: 'tokenMetadata',
|
|
2038
2151
|
unsigned: unsigned,
|
|
2039
|
-
|
|
2152
|
+
payloadFields: [
|
|
2153
|
+
rlpValue.string(unsigned.name),
|
|
2154
|
+
rlpValue.string(unsigned.uri),
|
|
2155
|
+
rlpValue.address(unsigned.token),
|
|
2156
|
+
rlpValue.list(additionalMetadataRlp),
|
|
2157
|
+
],
|
|
2040
2158
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
2041
2159
|
});
|
|
2042
2160
|
}function prepareTokenMintTx(unsigned) {
|
|
2043
2161
|
validateChainAndNonce(unsigned);
|
|
2044
2162
|
validateRecipientValueToken(unsigned);
|
|
2045
|
-
|
|
2046
|
-
rlpValue.uint(unsigned.chain_id),
|
|
2047
|
-
rlpValue.uint(unsigned.nonce),
|
|
2048
|
-
rlpValue.address(unsigned.recipient),
|
|
2049
|
-
rlpValue.uint(unsigned.value),
|
|
2050
|
-
rlpValue.address(unsigned.token),
|
|
2051
|
-
]));
|
|
2052
|
-
return createPreparedTx({
|
|
2163
|
+
return buildTx({
|
|
2053
2164
|
kind: 'tokenMint',
|
|
2054
2165
|
unsigned: unsigned,
|
|
2055
|
-
|
|
2166
|
+
payloadFields: [
|
|
2167
|
+
rlpValue.address(unsigned.recipient),
|
|
2168
|
+
rlpValue.uint(unsigned.value),
|
|
2169
|
+
rlpValue.address(unsigned.token),
|
|
2170
|
+
],
|
|
2056
2171
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
2057
2172
|
});
|
|
2058
2173
|
}function prepareTokenPauseTx(unsigned) {
|
|
2059
2174
|
validateChainAndNonce(unsigned);
|
|
2060
2175
|
assertAddress('token', unsigned.token);
|
|
2061
|
-
|
|
2062
|
-
rlpValue.uint(unsigned.chain_id),
|
|
2063
|
-
rlpValue.uint(unsigned.nonce),
|
|
2064
|
-
rlpValue.string(unsigned.action),
|
|
2065
|
-
rlpValue.address(unsigned.token),
|
|
2066
|
-
]));
|
|
2067
|
-
return createPreparedTx({
|
|
2176
|
+
return buildTx({
|
|
2068
2177
|
kind: 'tokenPause',
|
|
2069
2178
|
unsigned: unsigned,
|
|
2070
|
-
|
|
2179
|
+
payloadFields: [
|
|
2180
|
+
rlpValue.string(unsigned.action),
|
|
2181
|
+
rlpValue.address(unsigned.token),
|
|
2182
|
+
],
|
|
2071
2183
|
toRequest: function (payload, signature) { return (__assign(__assign({}, payload), { signature: signature })); },
|
|
2072
2184
|
});
|
|
2073
2185
|
}var DIGEST_HEX_RE = /^0x[0-9a-fA-F]{64}$/;
|
|
@@ -2113,4 +2225,4 @@ function createPrivateKeySigner(privateKey) {
|
|
|
2113
2225
|
};var index = {
|
|
2114
2226
|
api: api,
|
|
2115
2227
|
client: client$1,
|
|
2116
|
-
};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;
|
|
2228
|
+
};exports.MEMO_DATA_MAX_BYTES=MEMO_DATA_MAX_BYTES;exports.MEMO_FORMAT_MAX_BYTES=MEMO_FORMAT_MAX_BYTES;exports.MEMO_RLP_HEADER_ALLOWANCE=MEMO_RLP_HEADER_ALLOWANCE;exports.MEMO_TOTAL_MAX_BYTES=MEMO_TOTAL_MAX_BYTES;exports.MEMO_TYPE_MAX_BYTES=MEMO_TYPE_MAX_BYTES;exports.MemoValidationError=MemoValidationError;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.memoRlpList=memoRlpList;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;exports.validateMemo=validateMemo;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import { type Memo, type PlpPayload, type Signature } from '../../utils/index.js';
|
|
2
|
+
type UnsignedBase = {
|
|
3
|
+
chain_id: number;
|
|
4
|
+
nonce: number;
|
|
5
|
+
memo?: Memo;
|
|
6
|
+
};
|
|
7
|
+
export declare function buildTx<T extends UnsignedBase, R>(opts: {
|
|
8
|
+
kind: string;
|
|
9
|
+
unsigned: T;
|
|
10
|
+
payloadFields: PlpPayload[];
|
|
11
|
+
toRequest: (payload: T, signature: Signature) => R;
|
|
12
|
+
}): import("../core").PreparedTx<T, R>;
|
|
13
|
+
export {};
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { PaymentPayload } from '../../api/transactions/types';
|
|
2
2
|
export type PaymentUnsigned = Omit<PaymentPayload, 'signature'>;
|
|
3
|
-
export declare function preparePaymentTx(unsigned: PaymentUnsigned): import("
|
|
3
|
+
export declare function preparePaymentTx(unsigned: PaymentUnsigned): import("..").PreparedTx<PaymentUnsigned, PaymentPayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenAuthorityPayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenAuthorityUnsigned = Omit<TokenAuthorityPayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenAuthorityTx(unsigned: TokenAuthorityUnsigned): import("
|
|
3
|
+
export declare function prepareTokenAuthorityTx(unsigned: TokenAuthorityUnsigned): import("..").PreparedTx<TokenAuthorityUnsigned, TokenAuthorityPayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenBridgeAndMintPayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenBridgeAndMintUnsigned = Omit<TokenBridgeAndMintPayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenBridgeAndMintTx(unsigned: TokenBridgeAndMintUnsigned): import("
|
|
3
|
+
export declare function prepareTokenBridgeAndMintTx(unsigned: TokenBridgeAndMintUnsigned): import("..").PreparedTx<TokenBridgeAndMintUnsigned, TokenBridgeAndMintPayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenBurnPayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenBurnUnsigned = Omit<TokenBurnPayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenBurnTx(unsigned: TokenBurnUnsigned): import("
|
|
3
|
+
export declare function prepareTokenBurnTx(unsigned: TokenBurnUnsigned): import("..").PreparedTx<TokenBurnUnsigned, TokenBurnPayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenBurnAndBridgePayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenBurnAndBridgeUnsigned = Omit<TokenBurnAndBridgePayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenBurnAndBridgeTx(unsigned: TokenBurnAndBridgeUnsigned): import("
|
|
3
|
+
export declare function prepareTokenBurnAndBridgeTx(unsigned: TokenBurnAndBridgeUnsigned): import("..").PreparedTx<TokenBurnAndBridgeUnsigned, TokenBurnAndBridgePayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenClawbackPayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenClawbackUnsigned = Omit<TokenClawbackPayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenClawbackTx(unsigned: TokenClawbackUnsigned): import("
|
|
3
|
+
export declare function prepareTokenClawbackTx(unsigned: TokenClawbackUnsigned): import("..").PreparedTx<TokenClawbackUnsigned, TokenClawbackPayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenIssuePayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenIssueUnsigned = Omit<TokenIssuePayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenIssueTx(unsigned: TokenIssueUnsigned): import("
|
|
3
|
+
export declare function prepareTokenIssueTx(unsigned: TokenIssueUnsigned): import("..").PreparedTx<TokenIssueUnsigned, TokenIssuePayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenManageListPayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenManageListUnsigned = Omit<TokenManageListPayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenManageListTx(unsigned: TokenManageListUnsigned): import("
|
|
3
|
+
export declare function prepareTokenManageListTx(unsigned: TokenManageListUnsigned): import("..").PreparedTx<TokenManageListUnsigned, TokenManageListPayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenMetadataPayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenMetadataUnsigned = Omit<TokenMetadataPayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenMetadataTx(unsigned: TokenMetadataUnsigned): import("
|
|
3
|
+
export declare function prepareTokenMetadataTx(unsigned: TokenMetadataUnsigned): import("..").PreparedTx<TokenMetadataUnsigned, TokenMetadataPayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenMintPayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenMintUnsigned = Omit<TokenMintPayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenMintTx(unsigned: TokenMintUnsigned): import("
|
|
3
|
+
export declare function prepareTokenMintTx(unsigned: TokenMintUnsigned): import("..").PreparedTx<TokenMintUnsigned, TokenMintPayload>;
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TokenPausePayload } from '../../api/tokens/types';
|
|
2
2
|
export type TokenPauseUnsigned = Omit<TokenPausePayload, 'signature'>;
|
|
3
|
-
export declare function prepareTokenPauseTx(unsigned: TokenPauseUnsigned): import("
|
|
3
|
+
export declare function prepareTokenPauseTx(unsigned: TokenPauseUnsigned): import("..").PreparedTx<TokenPauseUnsigned, TokenPausePayload>;
|