@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.
Files changed (49) hide show
  1. package/.claude/settings.local.json +3 -7
  2. package/es/api/index.js +1 -1
  3. package/es/api/tokens/types.d.ts +21 -1
  4. package/es/api/transactions/types.d.ts +14 -0
  5. package/es/client/index.js +1 -1
  6. package/es/index.js +206 -113
  7. package/es/signing/builders/buildTx.d.ts +13 -0
  8. package/es/signing/builders/payment.d.ts +1 -1
  9. package/es/signing/builders/tokenAuthority.d.ts +1 -1
  10. package/es/signing/builders/tokenBridgeAndMint.d.ts +1 -1
  11. package/es/signing/builders/tokenBurn.d.ts +1 -1
  12. package/es/signing/builders/tokenBurnAndBridge.d.ts +1 -1
  13. package/es/signing/builders/tokenClawback.d.ts +1 -1
  14. package/es/signing/builders/tokenIssue.d.ts +1 -1
  15. package/es/signing/builders/tokenManageList.d.ts +1 -1
  16. package/es/signing/builders/tokenMetadata.d.ts +1 -1
  17. package/es/signing/builders/tokenMint.d.ts +1 -1
  18. package/es/signing/builders/tokenPause.d.ts +1 -1
  19. package/es/utils/index.d.ts +1 -0
  20. package/es/utils/index.js +89 -1
  21. package/es/utils/memo/index.d.ts +3 -0
  22. package/es/utils/memo/rlp.d.ts +3 -0
  23. package/es/utils/memo/types.d.ts +15 -0
  24. package/es/utils/memo/validate.d.ts +2 -0
  25. package/lib/api/index.js +24 -1
  26. package/lib/api/tokens/types.d.ts +21 -1
  27. package/lib/api/transactions/types.d.ts +14 -0
  28. package/lib/client/index.js +24 -1
  29. package/lib/index.js +225 -113
  30. package/lib/signing/builders/buildTx.d.ts +13 -0
  31. package/lib/signing/builders/payment.d.ts +1 -1
  32. package/lib/signing/builders/tokenAuthority.d.ts +1 -1
  33. package/lib/signing/builders/tokenBridgeAndMint.d.ts +1 -1
  34. package/lib/signing/builders/tokenBurn.d.ts +1 -1
  35. package/lib/signing/builders/tokenBurnAndBridge.d.ts +1 -1
  36. package/lib/signing/builders/tokenClawback.d.ts +1 -1
  37. package/lib/signing/builders/tokenIssue.d.ts +1 -1
  38. package/lib/signing/builders/tokenManageList.d.ts +1 -1
  39. package/lib/signing/builders/tokenMetadata.d.ts +1 -1
  40. package/lib/signing/builders/tokenMint.d.ts +1 -1
  41. package/lib/signing/builders/tokenPause.d.ts +1 -1
  42. package/lib/utils/index.d.ts +1 -0
  43. package/lib/utils/index.js +110 -2
  44. package/lib/utils/memo/index.d.ts +3 -0
  45. package/lib/utils/memo/rlp.d.ts +3 -0
  46. package/lib/utils/memo/types.d.ts +15 -0
  47. package/lib/utils/memo/validate.d.ts +2 -0
  48. package/package.json +1 -1
  49. package/umd/1money-protocol-ts-sdk.min.js +3 -3
@@ -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("../core").PreparedTx<TokenMintUnsigned, TokenMintPayload>;
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("../core").PreparedTx<TokenPauseUnsigned, TokenPausePayload>;
3
+ export declare function prepareTokenPauseTx(unsigned: TokenPauseUnsigned): import("..").PreparedTx<TokenPauseUnsigned, TokenPausePayload>;
@@ -1,5 +1,6 @@
1
1
  export * from './address';
2
2
  export * from './encode';
3
+ export * from './memo';
3
4
  export * from './safePromise';
4
5
  export * from './sign';
5
6
  export * from './txHash';
package/es/utils/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
@@ -926,4 +1014,4 @@ function calcTxHash(payload, signature) {
926
1014
  encoded.set(pEncode, header.length);
927
1015
  encoded.set(vrsBytes, header.length + pEncode.length);
928
1016
  return keccak256(encoded);
929
- }export{_typeof,calcTxHash,deriveTokenAddress,encodePayload,encodeRlpPayload,rlpValue,safePromiseAll,safePromiseLine,signMessage,toHex};
1017
+ }export{MEMO_DATA_MAX_BYTES,MEMO_FORMAT_MAX_BYTES,MEMO_RLP_HEADER_ALLOWANCE,MEMO_TOTAL_MAX_BYTES,MEMO_TYPE_MAX_BYTES,MemoValidationError,_typeof,calcTxHash,deriveTokenAddress,encodePayload,encodeRlpPayload,memoRlpList,rlpValue,safePromiseAll,safePromiseLine,signMessage,toHex,validateMemo};
@@ -0,0 +1,3 @@
1
+ export * from './types';
2
+ export * from './validate';
3
+ export * from './rlp';
@@ -0,0 +1,3 @@
1
+ import { type PlpPayload } from '../../utils/index.js';
2
+ import type { Memo } from './types';
3
+ export declare function memoRlpList(memo: Memo): PlpPayload;
@@ -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
+ }
@@ -0,0 +1,2 @@
1
+ import { Memo } from './types';
2
+ export declare function validateMemo(memo: Memo): void;
package/lib/api/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) {
@@ -79,7 +93,16 @@ function __generator(thisArg, body) {
79
93
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
80
94
  var e = new Error(message);
81
95
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
82
- };function _typeof(ele) {
96
+ };/** @class */ ((function (_super) {
97
+ __extends(MemoValidationError, _super);
98
+ function MemoValidationError(code, message) {
99
+ var _this = _super.call(this, message) || this;
100
+ _this.code = code;
101
+ _this.name = 'MemoValidationError';
102
+ return _this;
103
+ }
104
+ return MemoValidationError;
105
+ })(Error));new TextEncoder();function _typeof(ele) {
83
106
  if (typeof ele !== 'object')
84
107
  return (typeof ele).toLowerCase();
85
108
  var typeStr = Object.prototype.toString.call(ele);
@@ -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';
@@ -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) {
@@ -79,7 +93,16 @@ function __generator(thisArg, body) {
79
93
  typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
80
94
  var e = new Error(message);
81
95
  return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
82
- };function _typeof(ele) {
96
+ };/** @class */ ((function (_super) {
97
+ __extends(MemoValidationError, _super);
98
+ function MemoValidationError(code, message) {
99
+ var _this = _super.call(this, message) || this;
100
+ _this.code = code;
101
+ _this.name = 'MemoValidationError';
102
+ return _this;
103
+ }
104
+ return MemoValidationError;
105
+ })(Error));new TextEncoder();function _typeof(ele) {
83
106
  if (typeof ele !== 'object')
84
107
  return (typeof ele).toLowerCase();
85
108
  var typeStr = Object.prototype.toString.call(ele);