@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
|
@@ -37,15 +37,11 @@
|
|
|
37
37
|
"Bash(git commit -m \"$\\(cat <<''EOF''\nchore: upgrade mocha to v11 for security fixes\n\nCo-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>\nEOF\n\\)\")",
|
|
38
38
|
"Bash(npx commitlint:*)",
|
|
39
39
|
"Bash(npm run lint:es:*)",
|
|
40
|
-
"Bash(ls -la /Users/bobbytalvin/Desktop/Github/1money-protocol-ts-sdk/.env*)",
|
|
41
|
-
"Bash(ls /Users/bobbytalvin/Desktop/Github/1money-protocol-ts-sdk/.env*)",
|
|
42
|
-
"Bash(git -C /Users/bobbytalvin/Desktop/Github/1money-protocol-ts-sdk log --all --diff-filter=A -- .env*)",
|
|
43
|
-
"Bash(git -C /Users/bobbytalvin/Desktop/Github/1money-protocol-ts-sdk log --all --oneline -- '.env.integration')",
|
|
44
|
-
"Bash(git -C /Users/bobbytalvin/Desktop/Github/1money-protocol-ts-sdk show HEAD:.env)",
|
|
45
|
-
"Bash(git -C /Users/bobbytalvin/Desktop/Github/1money-protocol-ts-sdk show 95cd175:.env.integration)",
|
|
46
40
|
"Bash(pnpm audit *)",
|
|
47
41
|
"Bash(pnpm test *)",
|
|
48
|
-
"Bash(git checkout *)"
|
|
42
|
+
"Bash(git checkout *)",
|
|
43
|
+
"Bash(git *)",
|
|
44
|
+
"Bash(cargo test *)"
|
|
49
45
|
],
|
|
50
46
|
"deny": []
|
|
51
47
|
}
|
package/es/api/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import'viem';import'@ethereumjs/rlp';import axios from'axios';function _typeof(ele) {
|
|
1
|
+
import'viem';import'@ethereumjs/rlp';import axios from'axios';new TextEncoder();function _typeof(ele) {
|
|
2
2
|
if (typeof ele !== 'object')
|
|
3
3
|
return (typeof ele).toLowerCase();
|
|
4
4
|
const typeStr = Object.prototype.toString.call(ele);
|
package/es/api/tokens/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { AddressSchema, BytesSchema, U256Schema } from '../types';
|
|
2
|
-
import type { Signature } from '../../utils/index.js';
|
|
2
|
+
import type { Memo, Signature } from '../../utils/index.js';
|
|
3
3
|
export interface MetaDataKeyValuePair {
|
|
4
4
|
key: string;
|
|
5
5
|
value: string;
|
|
@@ -65,6 +65,8 @@ export interface TokenManageListPayload {
|
|
|
65
65
|
address: string;
|
|
66
66
|
token: string;
|
|
67
67
|
signature: RestSignature;
|
|
68
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
69
|
+
memo?: Memo;
|
|
68
70
|
}
|
|
69
71
|
export interface TokenBurnPayload {
|
|
70
72
|
chain_id: number;
|
|
@@ -72,6 +74,8 @@ export interface TokenBurnPayload {
|
|
|
72
74
|
value: string;
|
|
73
75
|
token: string;
|
|
74
76
|
signature: RestSignature;
|
|
77
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
78
|
+
memo?: Memo;
|
|
75
79
|
}
|
|
76
80
|
export interface TokenAuthorityPayload {
|
|
77
81
|
chain_id: number;
|
|
@@ -82,6 +86,8 @@ export interface TokenAuthorityPayload {
|
|
|
82
86
|
token: string;
|
|
83
87
|
value?: string;
|
|
84
88
|
signature: RestSignature;
|
|
89
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
90
|
+
memo?: Memo;
|
|
85
91
|
}
|
|
86
92
|
export interface TokenIssuePayload {
|
|
87
93
|
chain_id: number;
|
|
@@ -96,6 +102,8 @@ export interface TokenIssuePayload {
|
|
|
96
102
|
*/
|
|
97
103
|
clawback_enabled?: boolean;
|
|
98
104
|
signature: RestSignature;
|
|
105
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
106
|
+
memo?: Memo;
|
|
99
107
|
}
|
|
100
108
|
export interface TokenMintPayload {
|
|
101
109
|
chain_id: number;
|
|
@@ -104,6 +112,8 @@ export interface TokenMintPayload {
|
|
|
104
112
|
value: string;
|
|
105
113
|
token: string;
|
|
106
114
|
signature: RestSignature;
|
|
115
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
116
|
+
memo?: Memo;
|
|
107
117
|
}
|
|
108
118
|
export interface TokenPausePayload {
|
|
109
119
|
chain_id: number;
|
|
@@ -111,6 +121,8 @@ export interface TokenPausePayload {
|
|
|
111
121
|
action: PauseAction;
|
|
112
122
|
token: string;
|
|
113
123
|
signature: RestSignature;
|
|
124
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
125
|
+
memo?: Memo;
|
|
114
126
|
}
|
|
115
127
|
export interface TokenMetadataPayload {
|
|
116
128
|
chain_id: number;
|
|
@@ -120,6 +132,8 @@ export interface TokenMetadataPayload {
|
|
|
120
132
|
token: string;
|
|
121
133
|
additional_metadata: KeyValuePair[];
|
|
122
134
|
signature: RestSignature;
|
|
135
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
136
|
+
memo?: Memo;
|
|
123
137
|
}
|
|
124
138
|
export interface TokenBridgeAndMintPayload {
|
|
125
139
|
chain_id: number;
|
|
@@ -131,6 +145,8 @@ export interface TokenBridgeAndMintPayload {
|
|
|
131
145
|
source_tx_hash: string;
|
|
132
146
|
bridge_metadata: string;
|
|
133
147
|
signature: RestSignature;
|
|
148
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
149
|
+
memo?: Memo;
|
|
134
150
|
}
|
|
135
151
|
export interface TokenBurnAndBridgePayload {
|
|
136
152
|
chain_id: number;
|
|
@@ -144,6 +160,8 @@ export interface TokenBurnAndBridgePayload {
|
|
|
144
160
|
bridge_metadata: string;
|
|
145
161
|
bridge_param: BytesSchema;
|
|
146
162
|
signature: RestSignature;
|
|
163
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
164
|
+
memo?: Memo;
|
|
147
165
|
}
|
|
148
166
|
export interface TokenClawbackPayload {
|
|
149
167
|
chain_id: number;
|
|
@@ -153,4 +171,6 @@ export interface TokenClawbackPayload {
|
|
|
153
171
|
recipient: string;
|
|
154
172
|
value: string;
|
|
155
173
|
signature: RestSignature;
|
|
174
|
+
/** Optional transaction memo (see PaymentPayload.memo). */
|
|
175
|
+
memo?: Memo;
|
|
156
176
|
}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { AuthorityType, RestSignature } from '../tokens/types';
|
|
2
2
|
import type { AddressSchema, B256Schema, BytesSchema } from '../types';
|
|
3
|
+
import type { Memo } from '../../utils/index.js';
|
|
3
4
|
export interface TransactionReceipt {
|
|
4
5
|
success: boolean;
|
|
5
6
|
transaction_hash: B256Schema;
|
|
@@ -24,6 +25,13 @@ export interface PaymentPayload {
|
|
|
24
25
|
value: string;
|
|
25
26
|
token: AddressSchema;
|
|
26
27
|
signature: RestSignature;
|
|
28
|
+
/**
|
|
29
|
+
* Optional transaction memo. When present (even with empty subfields),
|
|
30
|
+
* the request is routed to the V2 envelope variant on-chain and the
|
|
31
|
+
* client MUST sign over the WithMemo<PaymentPayload> RLP shape.
|
|
32
|
+
* When omitted/undefined, the request takes the legacy V1 path.
|
|
33
|
+
*/
|
|
34
|
+
memo?: Memo;
|
|
27
35
|
}
|
|
28
36
|
export interface TokenCreateData {
|
|
29
37
|
decimals: number;
|
|
@@ -127,6 +135,12 @@ interface BaseTransaction {
|
|
|
127
135
|
s: string;
|
|
128
136
|
v: number;
|
|
129
137
|
};
|
|
138
|
+
/**
|
|
139
|
+
* Signed memo attached to the transaction. Populated only for V2
|
|
140
|
+
* (memo-bearing) envelope variants; omitted when the transaction was
|
|
141
|
+
* a legacy variant.
|
|
142
|
+
*/
|
|
143
|
+
memo?: Memo;
|
|
130
144
|
}
|
|
131
145
|
export type Transaction = (BaseTransaction & {
|
|
132
146
|
transaction_type: 'TokenCreate';
|
package/es/client/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import'viem';import'@ethereumjs/rlp';import axios from'axios';function _typeof(ele) {
|
|
1
|
+
import'viem';import'@ethereumjs/rlp';import axios from'axios';new TextEncoder();function _typeof(ele) {
|
|
2
2
|
if (typeof ele !== 'object')
|
|
3
3
|
return (typeof ele).toLowerCase();
|
|
4
4
|
const typeStr = Object.prototype.toString.call(ele);
|
package/es/index.js
CHANGED
|
@@ -100,6 +100,94 @@ const rlpValue = {
|
|
|
100
100
|
};
|
|
101
101
|
function encodeRlpPayload(payload) {
|
|
102
102
|
return encode(innerEncodeRlpPayload(payload));
|
|
103
|
+
}const MEMO_TYPE_MAX_BYTES = 128;
|
|
104
|
+
const MEMO_FORMAT_MAX_BYTES = 64;
|
|
105
|
+
const MEMO_DATA_MAX_BYTES = 256;
|
|
106
|
+
// Currently unreachable given the per-field caps above (128 + 64 + 256 + 16 =
|
|
107
|
+
// 464); retained as a future-proofing guard matching Rust.
|
|
108
|
+
const MEMO_TOTAL_MAX_BYTES = 512;
|
|
109
|
+
// RLP overhead allowance used by the aggregate size check, matching the
|
|
110
|
+
// Rust `Memo::byte_size` constant so JS and Rust accept/reject the same set
|
|
111
|
+
// of inputs.
|
|
112
|
+
const MEMO_RLP_HEADER_ALLOWANCE = 16;
|
|
113
|
+
class MemoValidationError extends Error {
|
|
114
|
+
code;
|
|
115
|
+
constructor(code, message) {
|
|
116
|
+
super(message);
|
|
117
|
+
this.code = code;
|
|
118
|
+
this.name = 'MemoValidationError';
|
|
119
|
+
}
|
|
120
|
+
}const enc = new TextEncoder();
|
|
121
|
+
// RFC 3986 unreserved + gen-delims + sub-delims + percent. Matches
|
|
122
|
+
// `is_url_safe` in `om-primitives-types/.../memo.rs`.
|
|
123
|
+
const URL_SAFE_RE = /^[A-Za-z0-9\-._~:/?#[\]@!$&'()*+,;=%]*$/;
|
|
124
|
+
function utf8Len(s) {
|
|
125
|
+
return enc.encode(s).length;
|
|
126
|
+
}
|
|
127
|
+
// Mirrors Rust `Memo::byte_size`: sum of subfield UTF-8 byte lengths plus a
|
|
128
|
+
// fixed 16-byte allowance for RLP framing. Used only by the aggregate cap.
|
|
129
|
+
function byteSize(memo) {
|
|
130
|
+
return (utf8Len(memo.type ?? '') +
|
|
131
|
+
utf8Len(memo.format ?? '') +
|
|
132
|
+
utf8Len(memo.data ?? '') +
|
|
133
|
+
MEMO_RLP_HEADER_ALLOWANCE);
|
|
134
|
+
}
|
|
135
|
+
// Validate per the same rules as Rust `Memo::validate()`.
|
|
136
|
+
//
|
|
137
|
+
// Per-field checks fire before the aggregate check, matching Rust ordering
|
|
138
|
+
// — clients should expect the same error code the server would return.
|
|
139
|
+
function validateMemo(memo) {
|
|
140
|
+
const t = memo.type ?? '';
|
|
141
|
+
if (t.length > 0) {
|
|
142
|
+
const len = utf8Len(t);
|
|
143
|
+
if (len > MEMO_TYPE_MAX_BYTES) {
|
|
144
|
+
throw new MemoValidationError('MEMO_TYPE_TOO_LONG', `memo.type exceeds ${MEMO_TYPE_MAX_BYTES} bytes (got ${len})`);
|
|
145
|
+
}
|
|
146
|
+
if (!URL_SAFE_RE.test(t)) {
|
|
147
|
+
throw new MemoValidationError('MEMO_TYPE_INVALID_CHARS', 'memo.type contains non-URL-safe characters');
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
const f = memo.format ?? '';
|
|
151
|
+
if (f.length > 0) {
|
|
152
|
+
const len = utf8Len(f);
|
|
153
|
+
if (len > MEMO_FORMAT_MAX_BYTES) {
|
|
154
|
+
throw new MemoValidationError('MEMO_FORMAT_TOO_LONG', `memo.format exceeds ${MEMO_FORMAT_MAX_BYTES} bytes (got ${len})`);
|
|
155
|
+
}
|
|
156
|
+
if (!URL_SAFE_RE.test(f)) {
|
|
157
|
+
throw new MemoValidationError('MEMO_FORMAT_INVALID_CHARS', 'memo.format contains non-URL-safe characters');
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
const d = memo.data ?? '';
|
|
161
|
+
if (d.length > 0) {
|
|
162
|
+
const len = utf8Len(d);
|
|
163
|
+
if (len > MEMO_DATA_MAX_BYTES) {
|
|
164
|
+
throw new MemoValidationError('MEMO_DATA_TOO_LONG', `memo.data exceeds ${MEMO_DATA_MAX_BYTES} bytes (got ${len})`);
|
|
165
|
+
}
|
|
166
|
+
// Reject NUL and any C0/C1 control codepoint (Unicode general category
|
|
167
|
+
// Cc). Rust's check is `c == '\0' || c.is_control()`.
|
|
168
|
+
for (const ch of d) {
|
|
169
|
+
const cp = ch.codePointAt(0);
|
|
170
|
+
if (cp === 0 ||
|
|
171
|
+
cp <= 0x1f ||
|
|
172
|
+
(cp >= 0x7f && cp <= 0x9f) ||
|
|
173
|
+
(cp >= 0xd800 && cp <= 0xdfff)) {
|
|
174
|
+
throw new MemoValidationError('MEMO_DATA_CONTROL_CHARS', 'memo.data contains null bytes or Unicode control/surrogate codepoints');
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
const total = byteSize(memo);
|
|
179
|
+
if (total > MEMO_TOTAL_MAX_BYTES) {
|
|
180
|
+
throw new MemoValidationError('MEMO_TOO_LARGE', `memo object exceeds ${MEMO_TOTAL_MAX_BYTES} bytes (got ${total})`);
|
|
181
|
+
}
|
|
182
|
+
}// RLP encoding of `Memo` matches the Rust `RlpEncodable` derive: a list of
|
|
183
|
+
// three byte strings in field order [type, format, data]. Empty subfields
|
|
184
|
+
// encode as empty byte strings (RLP `0x80`).
|
|
185
|
+
function memoRlpList(memo) {
|
|
186
|
+
return rlpValue.list([
|
|
187
|
+
rlpValue.string(memo.type ?? ''),
|
|
188
|
+
rlpValue.string(memo.format ?? ''),
|
|
189
|
+
rlpValue.string(memo.data ?? ''),
|
|
190
|
+
]);
|
|
103
191
|
}// concurrent
|
|
104
192
|
function safePromiseAll(arr) {
|
|
105
193
|
// @ts-expect-error
|
|
@@ -1696,6 +1784,47 @@ function createPreparedTx(params) {
|
|
|
1696
1784
|
attachSignature,
|
|
1697
1785
|
sign: async (signer) => attachSignature(await signer.signDigest(signatureHash)),
|
|
1698
1786
|
};
|
|
1787
|
+
}// Build a `PreparedTx` for any transaction shape:
|
|
1788
|
+
// 1. Prepend `[chain_id, nonce]` and the caller's `payloadFields` into one
|
|
1789
|
+
// RLP inner list.
|
|
1790
|
+
// 2. Branch on `unsigned.memo`:
|
|
1791
|
+
// - V1 (memo absent): RLP-encode `innerList` directly. Bytes are byte-
|
|
1792
|
+
// identical to the pre-memo SDK. `kind` is `<kindV1>`.
|
|
1793
|
+
// - V2 (memo present): validate the memo, then RLP-encode
|
|
1794
|
+
// `[innerList, memoRlpList(memo)]` — the `WithMemo<T>` envelope shape.
|
|
1795
|
+
// `kind` is `<kindV1>_v2`.
|
|
1796
|
+
// 3. Wire the result into `createPreparedTx`.
|
|
1797
|
+
//
|
|
1798
|
+
// `memo == null` deliberately catches both `null` and `undefined` so untyped
|
|
1799
|
+
// JS callers behave the same as strict TypeScript callers (whose declared
|
|
1800
|
+
// `Memo | undefined` would only ever produce `undefined`).
|
|
1801
|
+
//
|
|
1802
|
+
// Builders only need to call validators, construct `payloadFields`, and pass
|
|
1803
|
+
// `toRequest`.
|
|
1804
|
+
function buildTx(opts) {
|
|
1805
|
+
const innerList = rlpValue.list([
|
|
1806
|
+
rlpValue.uint(opts.unsigned.chain_id),
|
|
1807
|
+
rlpValue.uint(opts.unsigned.nonce),
|
|
1808
|
+
...opts.payloadFields,
|
|
1809
|
+
]);
|
|
1810
|
+
const memo = opts.unsigned.memo;
|
|
1811
|
+
let rlpBytes;
|
|
1812
|
+
let kind;
|
|
1813
|
+
if (memo == null) {
|
|
1814
|
+
rlpBytes = encodeRlpPayload(innerList);
|
|
1815
|
+
kind = opts.kind;
|
|
1816
|
+
}
|
|
1817
|
+
else {
|
|
1818
|
+
validateMemo(memo);
|
|
1819
|
+
rlpBytes = encodeRlpPayload(rlpValue.list([innerList, memoRlpList(memo)]));
|
|
1820
|
+
kind = `${opts.kind}_v2`;
|
|
1821
|
+
}
|
|
1822
|
+
return createPreparedTx({
|
|
1823
|
+
kind,
|
|
1824
|
+
unsigned: opts.unsigned,
|
|
1825
|
+
rlpBytes,
|
|
1826
|
+
toRequest: opts.toRequest,
|
|
1827
|
+
});
|
|
1699
1828
|
}const UINT_STRING_RE = /^\d+$/;
|
|
1700
1829
|
function fail(name, value) {
|
|
1701
1830
|
throw new Error(`[1Money SDK]: Invalid ${name}: ${String(value)}`);
|
|
@@ -1745,17 +1874,14 @@ function validateValueToken(unsigned) {
|
|
|
1745
1874
|
}function preparePaymentTx(unsigned) {
|
|
1746
1875
|
validateChainAndNonce(unsigned);
|
|
1747
1876
|
validateRecipientValueToken(unsigned);
|
|
1748
|
-
|
|
1749
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1750
|
-
rlpValue.uint(unsigned.nonce),
|
|
1751
|
-
rlpValue.address(unsigned.recipient),
|
|
1752
|
-
rlpValue.uint(unsigned.value),
|
|
1753
|
-
rlpValue.address(unsigned.token),
|
|
1754
|
-
]));
|
|
1755
|
-
return createPreparedTx({
|
|
1877
|
+
return buildTx({
|
|
1756
1878
|
kind: 'payment',
|
|
1757
1879
|
unsigned,
|
|
1758
|
-
|
|
1880
|
+
payloadFields: [
|
|
1881
|
+
rlpValue.address(unsigned.recipient),
|
|
1882
|
+
rlpValue.uint(unsigned.value),
|
|
1883
|
+
rlpValue.address(unsigned.token),
|
|
1884
|
+
],
|
|
1759
1885
|
toRequest: (payload, signature) => ({
|
|
1760
1886
|
...payload,
|
|
1761
1887
|
signature,
|
|
@@ -1766,22 +1892,19 @@ function validateValueToken(unsigned) {
|
|
|
1766
1892
|
assertAddress('authority_address', unsigned.authority_address);
|
|
1767
1893
|
assertAddress('token', unsigned.token);
|
|
1768
1894
|
assertOptionalUintString('value', unsigned.value);
|
|
1769
|
-
const
|
|
1770
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1771
|
-
rlpValue.uint(unsigned.nonce),
|
|
1895
|
+
const payloadFields = [
|
|
1772
1896
|
rlpValue.string(unsigned.action),
|
|
1773
1897
|
rlpValue.string(unsigned.authority_type),
|
|
1774
1898
|
rlpValue.address(unsigned.authority_address),
|
|
1775
1899
|
rlpValue.address(unsigned.token),
|
|
1776
1900
|
];
|
|
1777
1901
|
if (unsigned.value !== undefined) {
|
|
1778
|
-
|
|
1902
|
+
payloadFields.push(rlpValue.uint(unsigned.value));
|
|
1779
1903
|
}
|
|
1780
|
-
|
|
1781
|
-
return createPreparedTx({
|
|
1904
|
+
return buildTx({
|
|
1782
1905
|
kind: 'tokenAuthority',
|
|
1783
1906
|
unsigned,
|
|
1784
|
-
|
|
1907
|
+
payloadFields,
|
|
1785
1908
|
toRequest: (payload, signature) => ({
|
|
1786
1909
|
...payload,
|
|
1787
1910
|
signature,
|
|
@@ -1791,20 +1914,17 @@ function validateValueToken(unsigned) {
|
|
|
1791
1914
|
validateChainAndNonce(unsigned);
|
|
1792
1915
|
validateRecipientValueToken(unsigned);
|
|
1793
1916
|
assertPositiveInteger('source_chain_id', unsigned.source_chain_id);
|
|
1794
|
-
|
|
1795
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1796
|
-
rlpValue.uint(unsigned.nonce),
|
|
1797
|
-
rlpValue.address(unsigned.recipient),
|
|
1798
|
-
rlpValue.uint(unsigned.value),
|
|
1799
|
-
rlpValue.address(unsigned.token),
|
|
1800
|
-
rlpValue.uint(unsigned.source_chain_id),
|
|
1801
|
-
rlpValue.string(unsigned.source_tx_hash),
|
|
1802
|
-
rlpValue.string(unsigned.bridge_metadata),
|
|
1803
|
-
]));
|
|
1804
|
-
return createPreparedTx({
|
|
1917
|
+
return buildTx({
|
|
1805
1918
|
kind: 'tokenBridgeAndMint',
|
|
1806
1919
|
unsigned,
|
|
1807
|
-
|
|
1920
|
+
payloadFields: [
|
|
1921
|
+
rlpValue.address(unsigned.recipient),
|
|
1922
|
+
rlpValue.uint(unsigned.value),
|
|
1923
|
+
rlpValue.address(unsigned.token),
|
|
1924
|
+
rlpValue.uint(unsigned.source_chain_id),
|
|
1925
|
+
rlpValue.string(unsigned.source_tx_hash),
|
|
1926
|
+
rlpValue.string(unsigned.bridge_metadata),
|
|
1927
|
+
],
|
|
1808
1928
|
toRequest: (payload, signature) => ({
|
|
1809
1929
|
...payload,
|
|
1810
1930
|
signature,
|
|
@@ -1813,16 +1933,13 @@ function validateValueToken(unsigned) {
|
|
|
1813
1933
|
}function prepareTokenBurnTx(unsigned) {
|
|
1814
1934
|
validateChainAndNonce(unsigned);
|
|
1815
1935
|
validateValueToken(unsigned);
|
|
1816
|
-
|
|
1817
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1818
|
-
rlpValue.uint(unsigned.nonce),
|
|
1819
|
-
rlpValue.uint(unsigned.value),
|
|
1820
|
-
rlpValue.address(unsigned.token),
|
|
1821
|
-
]));
|
|
1822
|
-
return createPreparedTx({
|
|
1936
|
+
return buildTx({
|
|
1823
1937
|
kind: 'tokenBurn',
|
|
1824
1938
|
unsigned,
|
|
1825
|
-
|
|
1939
|
+
payloadFields: [
|
|
1940
|
+
rlpValue.uint(unsigned.value),
|
|
1941
|
+
rlpValue.address(unsigned.token),
|
|
1942
|
+
],
|
|
1826
1943
|
toRequest: (payload, signature) => ({
|
|
1827
1944
|
...payload,
|
|
1828
1945
|
signature,
|
|
@@ -1835,22 +1952,19 @@ function validateValueToken(unsigned) {
|
|
|
1835
1952
|
assertPositiveInteger('destination_chain_id', unsigned.destination_chain_id);
|
|
1836
1953
|
assertAddress('destination_address', unsigned.destination_address);
|
|
1837
1954
|
assertUintString('escrow_fee', unsigned.escrow_fee);
|
|
1838
|
-
|
|
1839
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1840
|
-
rlpValue.uint(unsigned.nonce),
|
|
1841
|
-
rlpValue.address(unsigned.sender),
|
|
1842
|
-
rlpValue.uint(unsigned.value),
|
|
1843
|
-
rlpValue.address(unsigned.token),
|
|
1844
|
-
rlpValue.uint(unsigned.destination_chain_id),
|
|
1845
|
-
rlpValue.string(unsigned.destination_address),
|
|
1846
|
-
rlpValue.uint(unsigned.escrow_fee),
|
|
1847
|
-
rlpValue.string(unsigned.bridge_metadata),
|
|
1848
|
-
rlpValue.hex(unsigned.bridge_param),
|
|
1849
|
-
]));
|
|
1850
|
-
return createPreparedTx({
|
|
1955
|
+
return buildTx({
|
|
1851
1956
|
kind: 'tokenBurnAndBridge',
|
|
1852
1957
|
unsigned,
|
|
1853
|
-
|
|
1958
|
+
payloadFields: [
|
|
1959
|
+
rlpValue.address(unsigned.sender),
|
|
1960
|
+
rlpValue.uint(unsigned.value),
|
|
1961
|
+
rlpValue.address(unsigned.token),
|
|
1962
|
+
rlpValue.uint(unsigned.destination_chain_id),
|
|
1963
|
+
rlpValue.string(unsigned.destination_address),
|
|
1964
|
+
rlpValue.uint(unsigned.escrow_fee),
|
|
1965
|
+
rlpValue.string(unsigned.bridge_metadata),
|
|
1966
|
+
rlpValue.hex(unsigned.bridge_param),
|
|
1967
|
+
],
|
|
1854
1968
|
toRequest: (payload, signature) => ({
|
|
1855
1969
|
...payload,
|
|
1856
1970
|
signature,
|
|
@@ -1860,18 +1974,15 @@ function validateValueToken(unsigned) {
|
|
|
1860
1974
|
validateChainAndNonce(unsigned);
|
|
1861
1975
|
validateRecipientValueToken(unsigned);
|
|
1862
1976
|
assertAddress('from', unsigned.from);
|
|
1863
|
-
|
|
1864
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1865
|
-
rlpValue.uint(unsigned.nonce),
|
|
1866
|
-
rlpValue.address(unsigned.token),
|
|
1867
|
-
rlpValue.address(unsigned.from),
|
|
1868
|
-
rlpValue.address(unsigned.recipient),
|
|
1869
|
-
rlpValue.uint(unsigned.value),
|
|
1870
|
-
]));
|
|
1871
|
-
return createPreparedTx({
|
|
1977
|
+
return buildTx({
|
|
1872
1978
|
kind: 'tokenClawback',
|
|
1873
1979
|
unsigned,
|
|
1874
|
-
|
|
1980
|
+
payloadFields: [
|
|
1981
|
+
rlpValue.address(unsigned.token),
|
|
1982
|
+
rlpValue.address(unsigned.from),
|
|
1983
|
+
rlpValue.address(unsigned.recipient),
|
|
1984
|
+
rlpValue.uint(unsigned.value),
|
|
1985
|
+
],
|
|
1875
1986
|
toRequest: (payload, signature) => ({
|
|
1876
1987
|
...payload,
|
|
1877
1988
|
signature,
|
|
@@ -1886,20 +1997,17 @@ function validateValueToken(unsigned) {
|
|
|
1886
1997
|
...unsigned,
|
|
1887
1998
|
clawback_enabled: clawbackEnabled,
|
|
1888
1999
|
};
|
|
1889
|
-
|
|
1890
|
-
rlpValue.uint(unsignedWithDefaults.chain_id),
|
|
1891
|
-
rlpValue.uint(unsignedWithDefaults.nonce),
|
|
1892
|
-
rlpValue.string(unsignedWithDefaults.symbol),
|
|
1893
|
-
rlpValue.string(unsignedWithDefaults.name),
|
|
1894
|
-
rlpValue.uint(unsignedWithDefaults.decimals),
|
|
1895
|
-
rlpValue.address(unsignedWithDefaults.master_authority),
|
|
1896
|
-
rlpValue.bool(unsignedWithDefaults.is_private),
|
|
1897
|
-
rlpValue.bool(clawbackEnabled),
|
|
1898
|
-
]));
|
|
1899
|
-
return createPreparedTx({
|
|
2000
|
+
return buildTx({
|
|
1900
2001
|
kind: 'tokenIssue',
|
|
1901
2002
|
unsigned: unsignedWithDefaults,
|
|
1902
|
-
|
|
2003
|
+
payloadFields: [
|
|
2004
|
+
rlpValue.string(unsignedWithDefaults.symbol),
|
|
2005
|
+
rlpValue.string(unsignedWithDefaults.name),
|
|
2006
|
+
rlpValue.uint(unsignedWithDefaults.decimals),
|
|
2007
|
+
rlpValue.address(unsignedWithDefaults.master_authority),
|
|
2008
|
+
rlpValue.bool(unsignedWithDefaults.is_private),
|
|
2009
|
+
rlpValue.bool(clawbackEnabled),
|
|
2010
|
+
],
|
|
1903
2011
|
toRequest: (payload, signature) => ({
|
|
1904
2012
|
...payload,
|
|
1905
2013
|
signature,
|
|
@@ -1909,17 +2017,14 @@ function validateValueToken(unsigned) {
|
|
|
1909
2017
|
validateChainAndNonce(unsigned);
|
|
1910
2018
|
assertAddress('address', unsigned.address);
|
|
1911
2019
|
assertAddress('token', unsigned.token);
|
|
1912
|
-
|
|
1913
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1914
|
-
rlpValue.uint(unsigned.nonce),
|
|
1915
|
-
rlpValue.string(unsigned.action),
|
|
1916
|
-
rlpValue.address(unsigned.address),
|
|
1917
|
-
rlpValue.address(unsigned.token),
|
|
1918
|
-
]));
|
|
1919
|
-
return createPreparedTx({
|
|
2020
|
+
return buildTx({
|
|
1920
2021
|
kind: 'tokenManageList',
|
|
1921
2022
|
unsigned,
|
|
1922
|
-
|
|
2023
|
+
payloadFields: [
|
|
2024
|
+
rlpValue.string(unsigned.action),
|
|
2025
|
+
rlpValue.address(unsigned.address),
|
|
2026
|
+
rlpValue.address(unsigned.token),
|
|
2027
|
+
],
|
|
1923
2028
|
toRequest: (payload, signature) => ({
|
|
1924
2029
|
...payload,
|
|
1925
2030
|
signature,
|
|
@@ -1928,22 +2033,16 @@ function validateValueToken(unsigned) {
|
|
|
1928
2033
|
}function prepareTokenMetadataTx(unsigned) {
|
|
1929
2034
|
validateChainAndNonce(unsigned);
|
|
1930
2035
|
assertAddress('token', unsigned.token);
|
|
1931
|
-
const additionalMetadataRlp = unsigned.additional_metadata.map(item => rlpValue.list([
|
|
1932
|
-
|
|
1933
|
-
rlpValue.string(item.value),
|
|
1934
|
-
]));
|
|
1935
|
-
const rlpBytes = encodeRlpPayload(rlpValue.list([
|
|
1936
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1937
|
-
rlpValue.uint(unsigned.nonce),
|
|
1938
|
-
rlpValue.string(unsigned.name),
|
|
1939
|
-
rlpValue.string(unsigned.uri),
|
|
1940
|
-
rlpValue.address(unsigned.token),
|
|
1941
|
-
rlpValue.list(additionalMetadataRlp),
|
|
1942
|
-
]));
|
|
1943
|
-
return createPreparedTx({
|
|
2036
|
+
const additionalMetadataRlp = unsigned.additional_metadata.map((item) => rlpValue.list([rlpValue.string(item.key), rlpValue.string(item.value)]));
|
|
2037
|
+
return buildTx({
|
|
1944
2038
|
kind: 'tokenMetadata',
|
|
1945
2039
|
unsigned,
|
|
1946
|
-
|
|
2040
|
+
payloadFields: [
|
|
2041
|
+
rlpValue.string(unsigned.name),
|
|
2042
|
+
rlpValue.string(unsigned.uri),
|
|
2043
|
+
rlpValue.address(unsigned.token),
|
|
2044
|
+
rlpValue.list(additionalMetadataRlp),
|
|
2045
|
+
],
|
|
1947
2046
|
toRequest: (payload, signature) => ({
|
|
1948
2047
|
...payload,
|
|
1949
2048
|
signature,
|
|
@@ -1952,17 +2051,14 @@ function validateValueToken(unsigned) {
|
|
|
1952
2051
|
}function prepareTokenMintTx(unsigned) {
|
|
1953
2052
|
validateChainAndNonce(unsigned);
|
|
1954
2053
|
validateRecipientValueToken(unsigned);
|
|
1955
|
-
|
|
1956
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1957
|
-
rlpValue.uint(unsigned.nonce),
|
|
1958
|
-
rlpValue.address(unsigned.recipient),
|
|
1959
|
-
rlpValue.uint(unsigned.value),
|
|
1960
|
-
rlpValue.address(unsigned.token),
|
|
1961
|
-
]));
|
|
1962
|
-
return createPreparedTx({
|
|
2054
|
+
return buildTx({
|
|
1963
2055
|
kind: 'tokenMint',
|
|
1964
2056
|
unsigned,
|
|
1965
|
-
|
|
2057
|
+
payloadFields: [
|
|
2058
|
+
rlpValue.address(unsigned.recipient),
|
|
2059
|
+
rlpValue.uint(unsigned.value),
|
|
2060
|
+
rlpValue.address(unsigned.token),
|
|
2061
|
+
],
|
|
1966
2062
|
toRequest: (payload, signature) => ({
|
|
1967
2063
|
...payload,
|
|
1968
2064
|
signature,
|
|
@@ -1971,16 +2067,13 @@ function validateValueToken(unsigned) {
|
|
|
1971
2067
|
}function prepareTokenPauseTx(unsigned) {
|
|
1972
2068
|
validateChainAndNonce(unsigned);
|
|
1973
2069
|
assertAddress('token', unsigned.token);
|
|
1974
|
-
|
|
1975
|
-
rlpValue.uint(unsigned.chain_id),
|
|
1976
|
-
rlpValue.uint(unsigned.nonce),
|
|
1977
|
-
rlpValue.string(unsigned.action),
|
|
1978
|
-
rlpValue.address(unsigned.token),
|
|
1979
|
-
]));
|
|
1980
|
-
return createPreparedTx({
|
|
2070
|
+
return buildTx({
|
|
1981
2071
|
kind: 'tokenPause',
|
|
1982
2072
|
unsigned,
|
|
1983
|
-
|
|
2073
|
+
payloadFields: [
|
|
2074
|
+
rlpValue.string(unsigned.action),
|
|
2075
|
+
rlpValue.address(unsigned.token),
|
|
2076
|
+
],
|
|
1984
2077
|
toRequest: (payload, signature) => ({
|
|
1985
2078
|
...payload,
|
|
1986
2079
|
signature,
|
|
@@ -2020,4 +2113,4 @@ function createPrivateKeySigner(privateKey) {
|
|
|
2020
2113
|
};var index = {
|
|
2021
2114
|
api,
|
|
2022
2115
|
client: client$1,
|
|
2023
|
-
};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};
|
|
2116
|
+
};export{MEMO_DATA_MAX_BYTES,MEMO_FORMAT_MAX_BYTES,MEMO_RLP_HEADER_ALLOWANCE,MEMO_TOTAL_MAX_BYTES,MEMO_TYPE_MAX_BYTES,MemoValidationError,TransactionBuilder,_typeof,api,calcSignedTxHash,calcTxHash,client$1 as client,createPreparedTx,createPrivateKeySigner,index as default,deriveTokenAddress,encodePayload,encodeRlpPayload,memoRlpList,preparePaymentTx,prepareTokenAuthorityTx,prepareTokenBridgeAndMintTx,prepareTokenBurnAndBridgeTx,prepareTokenBurnTx,prepareTokenClawbackTx,prepareTokenIssueTx,prepareTokenManageListTx,prepareTokenMetadataTx,prepareTokenMintTx,prepareTokenPauseTx,rlpValue,safePromiseAll,safePromiseLine,signMessage,toHex,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>;
|