@1money/protocol-ts-sdk 2.0.2 → 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 +5 -6
- 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 +5 -4
- package/umd/1money-protocol-ts-sdk.min.js +3 -3
package/lib/utils/index.js
CHANGED
|
@@ -116,6 +116,20 @@ PERFORMANCE OF THIS SOFTWARE.
|
|
|
116
116
|
***************************************************************************** */
|
|
117
117
|
/* global Reflect, Promise, SuppressedError, Symbol, Iterator */
|
|
118
118
|
|
|
119
|
+
var extendStatics = function(d, b) {
|
|
120
|
+
extendStatics = Object.setPrototypeOf ||
|
|
121
|
+
({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
|
|
122
|
+
function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
|
|
123
|
+
return extendStatics(d, b);
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
function __extends(d, b) {
|
|
127
|
+
if (typeof b !== "function" && b !== null)
|
|
128
|
+
throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
|
|
129
|
+
extendStatics(d, b);
|
|
130
|
+
function __() { this.constructor = d; }
|
|
131
|
+
d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
|
|
132
|
+
}
|
|
119
133
|
|
|
120
134
|
function __awaiter(thisArg, _arguments, P, generator) {
|
|
121
135
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
@@ -168,7 +182,101 @@ function __spreadArray(to, from, pack) {
|
|
|
168
182
|
typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
|
|
169
183
|
var e = new Error(message);
|
|
170
184
|
return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
|
|
171
|
-
}
|
|
185
|
+
};var MEMO_TYPE_MAX_BYTES = 128;
|
|
186
|
+
var MEMO_FORMAT_MAX_BYTES = 64;
|
|
187
|
+
var MEMO_DATA_MAX_BYTES = 256;
|
|
188
|
+
// Currently unreachable given the per-field caps above (128 + 64 + 256 + 16 =
|
|
189
|
+
// 464); retained as a future-proofing guard matching Rust.
|
|
190
|
+
var MEMO_TOTAL_MAX_BYTES = 512;
|
|
191
|
+
// RLP overhead allowance used by the aggregate size check, matching the
|
|
192
|
+
// Rust `Memo::byte_size` constant so JS and Rust accept/reject the same set
|
|
193
|
+
// of inputs.
|
|
194
|
+
var MEMO_RLP_HEADER_ALLOWANCE = 16;
|
|
195
|
+
var MemoValidationError = /** @class */ (function (_super) {
|
|
196
|
+
__extends(MemoValidationError, _super);
|
|
197
|
+
function MemoValidationError(code, message) {
|
|
198
|
+
var _this = _super.call(this, message) || this;
|
|
199
|
+
_this.code = code;
|
|
200
|
+
_this.name = 'MemoValidationError';
|
|
201
|
+
return _this;
|
|
202
|
+
}
|
|
203
|
+
return MemoValidationError;
|
|
204
|
+
}(Error));var enc = new TextEncoder();
|
|
205
|
+
// RFC 3986 unreserved + gen-delims + sub-delims + percent. Matches
|
|
206
|
+
// `is_url_safe` in `om-primitives-types/.../memo.rs`.
|
|
207
|
+
var URL_SAFE_RE = /^[A-Za-z0-9\-._~:/?#[\]@!$&'()*+,;=%]*$/;
|
|
208
|
+
function utf8Len(s) {
|
|
209
|
+
return enc.encode(s).length;
|
|
210
|
+
}
|
|
211
|
+
// Mirrors Rust `Memo::byte_size`: sum of subfield UTF-8 byte lengths plus a
|
|
212
|
+
// fixed 16-byte allowance for RLP framing. Used only by the aggregate cap.
|
|
213
|
+
function byteSize(memo) {
|
|
214
|
+
var _a, _b, _c;
|
|
215
|
+
return (utf8Len((_a = memo.type) !== null && _a !== void 0 ? _a : '') +
|
|
216
|
+
utf8Len((_b = memo.format) !== null && _b !== void 0 ? _b : '') +
|
|
217
|
+
utf8Len((_c = memo.data) !== null && _c !== void 0 ? _c : '') +
|
|
218
|
+
MEMO_RLP_HEADER_ALLOWANCE);
|
|
219
|
+
}
|
|
220
|
+
// Validate per the same rules as Rust `Memo::validate()`.
|
|
221
|
+
//
|
|
222
|
+
// Per-field checks fire before the aggregate check, matching Rust ordering
|
|
223
|
+
// — clients should expect the same error code the server would return.
|
|
224
|
+
function validateMemo(memo) {
|
|
225
|
+
var _a, _b, _c;
|
|
226
|
+
var t = (_a = memo.type) !== null && _a !== void 0 ? _a : '';
|
|
227
|
+
if (t.length > 0) {
|
|
228
|
+
var len = utf8Len(t);
|
|
229
|
+
if (len > MEMO_TYPE_MAX_BYTES) {
|
|
230
|
+
throw new MemoValidationError('MEMO_TYPE_TOO_LONG', "memo.type exceeds ".concat(MEMO_TYPE_MAX_BYTES, " bytes (got ").concat(len, ")"));
|
|
231
|
+
}
|
|
232
|
+
if (!URL_SAFE_RE.test(t)) {
|
|
233
|
+
throw new MemoValidationError('MEMO_TYPE_INVALID_CHARS', 'memo.type contains non-URL-safe characters');
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
var f = (_b = memo.format) !== null && _b !== void 0 ? _b : '';
|
|
237
|
+
if (f.length > 0) {
|
|
238
|
+
var len = utf8Len(f);
|
|
239
|
+
if (len > MEMO_FORMAT_MAX_BYTES) {
|
|
240
|
+
throw new MemoValidationError('MEMO_FORMAT_TOO_LONG', "memo.format exceeds ".concat(MEMO_FORMAT_MAX_BYTES, " bytes (got ").concat(len, ")"));
|
|
241
|
+
}
|
|
242
|
+
if (!URL_SAFE_RE.test(f)) {
|
|
243
|
+
throw new MemoValidationError('MEMO_FORMAT_INVALID_CHARS', 'memo.format contains non-URL-safe characters');
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
var d = (_c = memo.data) !== null && _c !== void 0 ? _c : '';
|
|
247
|
+
if (d.length > 0) {
|
|
248
|
+
var len = utf8Len(d);
|
|
249
|
+
if (len > MEMO_DATA_MAX_BYTES) {
|
|
250
|
+
throw new MemoValidationError('MEMO_DATA_TOO_LONG', "memo.data exceeds ".concat(MEMO_DATA_MAX_BYTES, " bytes (got ").concat(len, ")"));
|
|
251
|
+
}
|
|
252
|
+
// Reject NUL and any C0/C1 control codepoint (Unicode general category
|
|
253
|
+
// Cc). Rust's check is `c == '\0' || c.is_control()`.
|
|
254
|
+
for (var _i = 0, d_1 = d; _i < d_1.length; _i++) {
|
|
255
|
+
var ch = d_1[_i];
|
|
256
|
+
var cp = ch.codePointAt(0);
|
|
257
|
+
if (cp === 0 ||
|
|
258
|
+
cp <= 0x1f ||
|
|
259
|
+
(cp >= 0x7f && cp <= 0x9f) ||
|
|
260
|
+
(cp >= 0xd800 && cp <= 0xdfff)) {
|
|
261
|
+
throw new MemoValidationError('MEMO_DATA_CONTROL_CHARS', 'memo.data contains null bytes or Unicode control/surrogate codepoints');
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
var total = byteSize(memo);
|
|
266
|
+
if (total > MEMO_TOTAL_MAX_BYTES) {
|
|
267
|
+
throw new MemoValidationError('MEMO_TOO_LARGE', "memo object exceeds ".concat(MEMO_TOTAL_MAX_BYTES, " bytes (got ").concat(total, ")"));
|
|
268
|
+
}
|
|
269
|
+
}// RLP encoding of `Memo` matches the Rust `RlpEncodable` derive: a list of
|
|
270
|
+
// three byte strings in field order [type, format, data]. Empty subfields
|
|
271
|
+
// encode as empty byte strings (RLP `0x80`).
|
|
272
|
+
function memoRlpList(memo) {
|
|
273
|
+
var _a, _b, _c;
|
|
274
|
+
return rlpValue.list([
|
|
275
|
+
rlpValue.string((_a = memo.type) !== null && _a !== void 0 ? _a : ''),
|
|
276
|
+
rlpValue.string((_b = memo.format) !== null && _b !== void 0 ? _b : ''),
|
|
277
|
+
rlpValue.string((_c = memo.data) !== null && _c !== void 0 ? _c : ''),
|
|
278
|
+
]);
|
|
279
|
+
}// concurrent
|
|
172
280
|
function safePromiseAll(arr) {
|
|
173
281
|
// @ts-expect-error
|
|
174
282
|
if (!arr || !arr.length)
|
|
@@ -1022,4 +1130,4 @@ function calcTxHash(payload, signature) {
|
|
|
1022
1130
|
encoded.set(pEncode, header.length);
|
|
1023
1131
|
encoded.set(vrsBytes, header.length + pEncode.length);
|
|
1024
1132
|
return viem.keccak256(encoded);
|
|
1025
|
-
}exports._typeof=_typeof;exports.calcTxHash=calcTxHash;exports.deriveTokenAddress=deriveTokenAddress;exports.encodePayload=encodePayload;exports.encodeRlpPayload=encodeRlpPayload;exports.rlpValue=rlpValue;exports.safePromiseAll=safePromiseAll;exports.safePromiseLine=safePromiseLine;exports.signMessage=signMessage;exports.toHex=toHex;
|
|
1133
|
+
}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._typeof=_typeof;exports.calcTxHash=calcTxHash;exports.deriveTokenAddress=deriveTokenAddress;exports.encodePayload=encodePayload;exports.encodeRlpPayload=encodeRlpPayload;exports.memoRlpList=memoRlpList;exports.rlpValue=rlpValue;exports.safePromiseAll=safePromiseAll;exports.safePromiseLine=safePromiseLine;exports.signMessage=signMessage;exports.toHex=toHex;exports.validateMemo=validateMemo;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export interface Memo {
|
|
2
|
+
type?: string;
|
|
3
|
+
format?: string;
|
|
4
|
+
data?: string;
|
|
5
|
+
}
|
|
6
|
+
export declare const MEMO_TYPE_MAX_BYTES = 128;
|
|
7
|
+
export declare const MEMO_FORMAT_MAX_BYTES = 64;
|
|
8
|
+
export declare const MEMO_DATA_MAX_BYTES = 256;
|
|
9
|
+
export declare const MEMO_TOTAL_MAX_BYTES = 512;
|
|
10
|
+
export declare const MEMO_RLP_HEADER_ALLOWANCE = 16;
|
|
11
|
+
export type MemoErrorCode = 'MEMO_TOO_LARGE' | 'MEMO_TYPE_INVALID_CHARS' | 'MEMO_FORMAT_INVALID_CHARS' | 'MEMO_DATA_CONTROL_CHARS' | 'MEMO_TYPE_TOO_LONG' | 'MEMO_FORMAT_TOO_LONG' | 'MEMO_DATA_TOO_LONG';
|
|
12
|
+
export declare class MemoValidationError extends Error {
|
|
13
|
+
readonly code: MemoErrorCode;
|
|
14
|
+
constructor(code: MemoErrorCode, message: string);
|
|
15
|
+
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@1money/protocol-ts-sdk",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.1.0-beta.0",
|
|
4
4
|
"description": "ts sdk for 1Money protocol network",
|
|
5
5
|
"main": "lib/index.js",
|
|
6
6
|
"module": "es/index.js",
|
|
@@ -63,7 +63,7 @@
|
|
|
63
63
|
},
|
|
64
64
|
"peerDependencies": {
|
|
65
65
|
"@ethereumjs/rlp": ">=10.0.0 <11.0.0",
|
|
66
|
-
"axios": ">=1.
|
|
66
|
+
"axios": ">=1.15.0 <2.0.0",
|
|
67
67
|
"viem": ">=2.0.0 <3.0.0"
|
|
68
68
|
},
|
|
69
69
|
"devDependencies": {
|
|
@@ -88,7 +88,7 @@
|
|
|
88
88
|
"@types/mocha": "10.0.7",
|
|
89
89
|
"@types/node": "~18.19.39",
|
|
90
90
|
"typescript-eslint": "~8.57.1",
|
|
91
|
-
"axios": "~1.
|
|
91
|
+
"axios": "~1.15.1",
|
|
92
92
|
"chai": "4.5.0",
|
|
93
93
|
"cross-env": "^7.0.3",
|
|
94
94
|
"del": "5.1.0",
|
|
@@ -125,7 +125,8 @@
|
|
|
125
125
|
"minimatch@>=9.0.0 <9.0.7": "9.0.7",
|
|
126
126
|
"flatted@<=3.4.1": "3.4.2",
|
|
127
127
|
"serialize-javascript@<=7.0.2": "7.0.4",
|
|
128
|
-
"basic-ftp@<5.
|
|
128
|
+
"basic-ftp@<5.3.0": "5.3.0",
|
|
129
|
+
"follow-redirects@<1.16.0": "1.16.0"
|
|
129
130
|
}
|
|
130
131
|
}
|
|
131
132
|
}
|