@1money/protocol-ts-sdk 1.1.2 → 2.0.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 (66) hide show
  1. package/.claude/settings.local.json +2 -1
  2. package/README.md +216 -134
  3. package/es/__integration__/helpers.d.ts +0 -7
  4. package/es/api/checkpoints/types.d.ts +0 -1
  5. package/es/api/index.js +17 -10
  6. package/es/api/tokens/index.d.ts +7 -1
  7. package/es/api/tokens/types.d.ts +21 -6
  8. package/es/api/transactions/index.d.ts +4 -3
  9. package/es/api/transactions/types.d.ts +14 -5
  10. package/es/client/index.js +4 -4
  11. package/es/index.d.ts +1 -0
  12. package/es/index.js +481 -22
  13. package/es/signing/builders/index.d.ts +11 -0
  14. package/es/signing/builders/payment.d.ts +3 -0
  15. package/es/signing/builders/tokenAuthority.d.ts +3 -0
  16. package/es/signing/builders/tokenBridgeAndMint.d.ts +3 -0
  17. package/es/signing/builders/tokenBurn.d.ts +3 -0
  18. package/es/signing/builders/tokenBurnAndBridge.d.ts +3 -0
  19. package/es/signing/builders/tokenClawback.d.ts +3 -0
  20. package/es/signing/builders/tokenIssue.d.ts +3 -0
  21. package/es/signing/builders/tokenManageList.d.ts +3 -0
  22. package/es/signing/builders/tokenMetadata.d.ts +3 -0
  23. package/es/signing/builders/tokenMint.d.ts +3 -0
  24. package/es/signing/builders/tokenPause.d.ts +3 -0
  25. package/es/signing/builders/validate.d.ts +18 -0
  26. package/es/signing/core.d.ts +27 -0
  27. package/es/signing/index.d.ts +18 -0
  28. package/es/signing/signer.d.ts +3 -0
  29. package/es/utils/encode.d.ts +11 -0
  30. package/es/utils/index.d.ts +2 -1
  31. package/es/utils/index.js +90 -10
  32. package/es/utils/interface.d.ts +27 -0
  33. package/es/utils/sign.d.ts +6 -1
  34. package/lib/__integration__/helpers.d.ts +0 -7
  35. package/lib/api/checkpoints/types.d.ts +0 -1
  36. package/lib/api/index.js +17 -10
  37. package/lib/api/tokens/index.d.ts +7 -1
  38. package/lib/api/tokens/types.d.ts +21 -6
  39. package/lib/api/transactions/index.d.ts +4 -3
  40. package/lib/api/transactions/types.d.ts +14 -5
  41. package/lib/client/index.js +4 -4
  42. package/lib/index.d.ts +1 -0
  43. package/lib/index.js +469 -21
  44. package/lib/signing/builders/index.d.ts +11 -0
  45. package/lib/signing/builders/payment.d.ts +3 -0
  46. package/lib/signing/builders/tokenAuthority.d.ts +3 -0
  47. package/lib/signing/builders/tokenBridgeAndMint.d.ts +3 -0
  48. package/lib/signing/builders/tokenBurn.d.ts +3 -0
  49. package/lib/signing/builders/tokenBurnAndBridge.d.ts +3 -0
  50. package/lib/signing/builders/tokenClawback.d.ts +3 -0
  51. package/lib/signing/builders/tokenIssue.d.ts +3 -0
  52. package/lib/signing/builders/tokenManageList.d.ts +3 -0
  53. package/lib/signing/builders/tokenMetadata.d.ts +3 -0
  54. package/lib/signing/builders/tokenMint.d.ts +3 -0
  55. package/lib/signing/builders/tokenPause.d.ts +3 -0
  56. package/lib/signing/builders/validate.d.ts +18 -0
  57. package/lib/signing/core.d.ts +27 -0
  58. package/lib/signing/index.d.ts +18 -0
  59. package/lib/signing/signer.d.ts +3 -0
  60. package/lib/utils/encode.d.ts +11 -0
  61. package/lib/utils/index.d.ts +2 -1
  62. package/lib/utils/index.js +90 -10
  63. package/lib/utils/interface.d.ts +27 -0
  64. package/lib/utils/sign.d.ts +6 -1
  65. package/package.json +2 -2
  66. package/umd/1money-protocol-ts-sdk.min.js +3 -2
@@ -0,0 +1,3 @@
1
+ import type { TokenBurnAndBridgePayload } from '../../api/tokens/types';
2
+ export type TokenBurnAndBridgeUnsigned = Omit<TokenBurnAndBridgePayload, 'signature'>;
3
+ export declare function prepareTokenBurnAndBridgeTx(unsigned: TokenBurnAndBridgeUnsigned): import("../core").PreparedTx<TokenBurnAndBridgeUnsigned, TokenBurnAndBridgePayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenClawbackPayload } from '../../api/tokens/types';
2
+ export type TokenClawbackUnsigned = Omit<TokenClawbackPayload, 'signature'>;
3
+ export declare function prepareTokenClawbackTx(unsigned: TokenClawbackUnsigned): import("../core").PreparedTx<TokenClawbackUnsigned, TokenClawbackPayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenIssuePayload } from '../../api/tokens/types';
2
+ export type TokenIssueUnsigned = Omit<TokenIssuePayload, 'signature'>;
3
+ export declare function prepareTokenIssueTx(unsigned: TokenIssueUnsigned): import("../core").PreparedTx<TokenIssueUnsigned, TokenIssuePayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenManageListPayload } from '../../api/tokens/types';
2
+ export type TokenManageListUnsigned = Omit<TokenManageListPayload, 'signature'>;
3
+ export declare function prepareTokenManageListTx(unsigned: TokenManageListUnsigned): import("../core").PreparedTx<TokenManageListUnsigned, TokenManageListPayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenMetadataPayload } from '../../api/tokens/types';
2
+ export type TokenMetadataUnsigned = Omit<TokenMetadataPayload, 'signature'>;
3
+ export declare function prepareTokenMetadataTx(unsigned: TokenMetadataUnsigned): import("../core").PreparedTx<TokenMetadataUnsigned, TokenMetadataPayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenMintPayload } from '../../api/tokens/types';
2
+ export type TokenMintUnsigned = Omit<TokenMintPayload, 'signature'>;
3
+ export declare function prepareTokenMintTx(unsigned: TokenMintUnsigned): import("../core").PreparedTx<TokenMintUnsigned, TokenMintPayload>;
@@ -0,0 +1,3 @@
1
+ import type { TokenPausePayload } from '../../api/tokens/types';
2
+ export type TokenPauseUnsigned = Omit<TokenPausePayload, 'signature'>;
3
+ export declare function prepareTokenPauseTx(unsigned: TokenPauseUnsigned): import("../core").PreparedTx<TokenPauseUnsigned, TokenPausePayload>;
@@ -0,0 +1,18 @@
1
+ export declare function assertPositiveInteger(name: string, value: number): void;
2
+ export declare function assertNonNegativeInteger(name: string, value: number): void;
3
+ export declare function assertUintString(name: string, value: string): void;
4
+ export declare function assertOptionalUintString(name: string, value: string | undefined): void;
5
+ export declare function assertAddress(name: string, value: string): void;
6
+ export declare function validateChainAndNonce(unsigned: {
7
+ chain_id: number;
8
+ nonce: number;
9
+ }): void;
10
+ export declare function validateRecipientValueToken(unsigned: {
11
+ recipient: string;
12
+ value: string;
13
+ token: string;
14
+ }): void;
15
+ export declare function validateValueToken(unsigned: {
16
+ value: string;
17
+ token: string;
18
+ }): void;
@@ -0,0 +1,27 @@
1
+ import type { Signature, ZeroXString } from '../utils/index.js';
2
+ export interface SignerAdapter {
3
+ signDigest: (digest: ZeroXString) => Promise<Signature>;
4
+ }
5
+ export interface SignedTx<TUnsigned, TRequest> {
6
+ kind: string;
7
+ unsigned: TUnsigned;
8
+ signatureHash: ZeroXString;
9
+ txHash: ZeroXString;
10
+ signature: Signature;
11
+ toRequest: () => TRequest;
12
+ }
13
+ export interface PreparedTx<TUnsigned, TRequest> {
14
+ kind: string;
15
+ unsigned: TUnsigned;
16
+ rlpBytes: Uint8Array;
17
+ signatureHash: ZeroXString;
18
+ attachSignature: (signature: Signature) => SignedTx<TUnsigned, TRequest>;
19
+ sign: (signer: SignerAdapter) => Promise<SignedTx<TUnsigned, TRequest>>;
20
+ }
21
+ export declare function calcSignedTxHash(payloadRlpBytes: Uint8Array, signature: Signature): ZeroXString;
22
+ export declare function createPreparedTx<TUnsigned, TRequest>(params: {
23
+ kind: string;
24
+ unsigned: TUnsigned;
25
+ rlpBytes: Uint8Array;
26
+ toRequest: (unsigned: TUnsigned, signature: Signature) => TRequest;
27
+ }): PreparedTx<TUnsigned, TRequest>;
@@ -0,0 +1,18 @@
1
+ import { preparePaymentTx, prepareTokenAuthorityTx, prepareTokenBridgeAndMintTx, prepareTokenBurnAndBridgeTx, prepareTokenBurnTx, prepareTokenClawbackTx, prepareTokenIssueTx, prepareTokenManageListTx, prepareTokenMetadataTx, prepareTokenMintTx, prepareTokenPauseTx } from './builders';
2
+ export * from './builders';
3
+ export * from './core';
4
+ export * from './signer';
5
+ export declare const TransactionBuilder: {
6
+ payment: typeof preparePaymentTx;
7
+ tokenManageList: typeof prepareTokenManageListTx;
8
+ tokenBurn: typeof prepareTokenBurnTx;
9
+ tokenAuthority: typeof prepareTokenAuthorityTx;
10
+ tokenIssue: typeof prepareTokenIssueTx;
11
+ tokenMint: typeof prepareTokenMintTx;
12
+ tokenPause: typeof prepareTokenPauseTx;
13
+ tokenMetadata: typeof prepareTokenMetadataTx;
14
+ tokenBridgeAndMint: typeof prepareTokenBridgeAndMintTx;
15
+ tokenBurnAndBridge: typeof prepareTokenBurnAndBridgeTx;
16
+ tokenClawback: typeof prepareTokenClawbackTx;
17
+ };
18
+ export default TransactionBuilder;
@@ -0,0 +1,3 @@
1
+ import type { ZeroXString } from '../utils/index.js';
2
+ import type { SignerAdapter } from './core';
3
+ export declare function createPrivateKeySigner(privateKey: ZeroXString): SignerAdapter;
@@ -0,0 +1,11 @@
1
+ import type { PlpPayload, ZeroXString } from './interface';
2
+ export declare const rlpValue: {
3
+ address: (v: ZeroXString) => PlpPayload;
4
+ hex: (v: ZeroXString) => PlpPayload;
5
+ string: (v: string) => PlpPayload;
6
+ uint: (v: bigint | number | string) => PlpPayload;
7
+ bool: (v: boolean) => PlpPayload;
8
+ bytes: (v: Uint8Array) => PlpPayload;
9
+ list: (v: PlpPayload[]) => PlpPayload;
10
+ };
11
+ export declare function encodeRlpPayload(payload: PlpPayload): Uint8Array<ArrayBufferLike>;
@@ -1,6 +1,7 @@
1
1
  export * from './address';
2
+ export * from './encode';
2
3
  export * from './safePromise';
3
- export * from './typeof';
4
4
  export * from './sign';
5
5
  export * from './txHash';
6
+ export * from './typeof';
6
7
  export type * from './interface';
@@ -25,6 +25,81 @@ function deriveTokenAddress(walletAddress, mintAddress) {
25
25
  var hashBytes = viem.hexToBytes(hashHex);
26
26
  var addressBytes = hashBytes.slice(12);
27
27
  return viem.bytesToHex(addressBytes);
28
+ }var ADDRESS_HEX_RE = /^0x[0-9a-fA-F]{40}$/;
29
+ var BYTES_HEX_RE = /^0x([0-9a-fA-F]{2})*$/;
30
+ function innerEncodeRlpPayload(value) {
31
+ if (value === null || value === undefined) {
32
+ return new Uint8Array([]);
33
+ }
34
+ switch (value.kind) {
35
+ case 'string':
36
+ return new TextEncoder().encode(value.value);
37
+ case 'uint': {
38
+ if (typeof value.value === 'string' &&
39
+ !/^\d+$/.test(value.value)) {
40
+ throw new Error("[1Money SDK]: Invalid uint string: ".concat(value.value));
41
+ }
42
+ var n = typeof value.value === 'bigint'
43
+ ? value.value
44
+ : BigInt(value.value);
45
+ return n === BigInt(0)
46
+ ? new Uint8Array([])
47
+ : viem.hexToBytes(viem.numberToHex(n));
48
+ }
49
+ case 'bool':
50
+ return value.value
51
+ ? Uint8Array.from([1])
52
+ : new Uint8Array([]);
53
+ case 'bytes':
54
+ return value.value;
55
+ case 'list':
56
+ return value.value.map(function (v) { return innerEncodeRlpPayload(v); });
57
+ case 'address':
58
+ case 'hex':
59
+ if (!BYTES_HEX_RE.test(value.value)) {
60
+ throw new Error("[1Money SDK]: Invalid hex value: ".concat(value.value));
61
+ }
62
+ if (value.kind === 'address' &&
63
+ !ADDRESS_HEX_RE.test(value.value)) {
64
+ throw new Error("[1Money SDK]: Invalid address value: ".concat(value.value));
65
+ }
66
+ return value.value === '0x'
67
+ ? new Uint8Array([])
68
+ : viem.hexToBytes(value.value);
69
+ }
70
+ }
71
+ var rlpValue = {
72
+ address: function (v) { return ({
73
+ kind: 'address',
74
+ value: v
75
+ }); },
76
+ hex: function (v) { return ({
77
+ kind: 'hex',
78
+ value: v
79
+ }); },
80
+ string: function (v) { return ({
81
+ kind: 'string',
82
+ value: v
83
+ }); },
84
+ uint: function (v) { return ({
85
+ kind: 'uint',
86
+ value: v
87
+ }); },
88
+ bool: function (v) { return ({
89
+ kind: 'bool',
90
+ value: v
91
+ }); },
92
+ bytes: function (v) { return ({
93
+ kind: 'bytes',
94
+ value: v
95
+ }); },
96
+ list: function (v) { return ({
97
+ kind: 'list',
98
+ value: v
99
+ }); }
100
+ };
101
+ function encodeRlpPayload(payload) {
102
+ return rlp.encode(innerEncodeRlpPayload(payload));
28
103
  }/******************************************************************************
29
104
  Copyright (c) Microsoft Corporation.
30
105
 
@@ -132,11 +207,6 @@ function safePromiseLine(arr) {
132
207
  }
133
208
  });
134
209
  });
135
- }function _typeof(ele) {
136
- if (typeof ele !== 'object')
137
- return (typeof ele).toLowerCase();
138
- var typeStr = Object.prototype.toString.call(ele);
139
- return typeStr.slice(8, typeStr.length - 1).toLowerCase();
140
210
  }/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
141
211
  /**
142
212
  * 4KB JS implementation of secp256k1 ECDSA / Schnorr signatures & ECDH.
@@ -792,8 +862,15 @@ const wNAF = (n) => {
792
862
  }
793
863
  }
794
864
  return { p, f }; // return both real and fake points for JIT
795
- };/**
865
+ };function _typeof(ele) {
866
+ if (typeof ele !== 'object')
867
+ return (typeof ele).toLowerCase();
868
+ var typeStr = Object.prototype.toString.call(ele);
869
+ return typeStr.slice(8, typeStr.length - 1).toLowerCase();
870
+ }/**
796
871
  * RLP encode a payload into a digest
872
+ * @deprecated Prefer the TransactionBuilder flow in `src/signing`
873
+ * (`prepare*Tx` + `.sign(...)`) to build and sign transactions.
797
874
  * @param payload Payload to encode
798
875
  * @returns RLP encoded payload
799
876
  */
@@ -801,9 +878,9 @@ function encodePayload(payload) {
801
878
  if (_typeof(payload) === 'array') {
802
879
  var formatted = payload.map(function (v) {
803
880
  if (_typeof(v) === 'string') {
804
- if (/^0x[0-9a-fA-F]+$/.test(v)) {
881
+ if (/^0x([0-9a-fA-F]{2})*$/.test(v)) {
805
882
  // hex-encoded data → raw bytes
806
- return viem.hexToBytes(v);
883
+ return v === '0x' ? new Uint8Array([]) : viem.hexToBytes(v);
807
884
  }
808
885
  else if (/^\d+$/.test(v)) {
809
886
  // number-like string → hex → bytes
@@ -835,6 +912,9 @@ function encodePayload(payload) {
835
912
  }
836
913
  /**
837
914
  * Sign a message using the provided private key
915
+ * @deprecated Prefer the TransactionBuilder flow in `src/signing`
916
+ * (`prepare*Tx` + `.sign(createPrivateKeySigner(privateKey))`)
917
+ * for transaction signing.
838
918
  * @param payload Payload to sign
839
919
  * @param privateKey Private key to sign with
840
920
  * @returns Signature object with r, s, v components
@@ -905,7 +985,7 @@ function toHex(value) {
905
985
  }
906
986
  }
907
987
  catch (e) {
908
- console.error('[1Money toHex]: ', e);
988
+ console.error('[1Money SDK]: toHex error:', e);
909
989
  return '0x';
910
990
  }
911
991
  }function encodeRlpListHeader(length) {
@@ -943,4 +1023,4 @@ function calcTxHash(payload, signature) {
943
1023
  encoded.set(pEncode, header.length);
944
1024
  encoded.set(vrsBytes, header.length + pEncode.length);
945
1025
  return viem.keccak256(encoded);
946
- }exports._typeof=_typeof;exports.calcTxHash=calcTxHash;exports.deriveTokenAddress=deriveTokenAddress;exports.encodePayload=encodePayload;exports.safePromiseAll=safePromiseAll;exports.safePromiseLine=safePromiseLine;exports.signMessage=signMessage;exports.toHex=toHex;
1026
+ }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;
@@ -4,4 +4,31 @@ export interface Signature {
4
4
  s: ZeroXString;
5
5
  v: number | boolean;
6
6
  }
7
+ /**
8
+ * @deprecated Legacy payload shape used by deprecated `encodePayload`
9
+ * and `signMessage`. Prefer `PlpPayload`/`encodeRlpPayload` and
10
+ * TransactionBuilder in `src/signing`.
11
+ */
7
12
  export type Payload = boolean | string | number | bigint | Uint8Array | Array<Payload> | null | undefined;
13
+ export type PlpPayload = {
14
+ kind: 'address';
15
+ value: ZeroXString;
16
+ } | {
17
+ kind: 'hex';
18
+ value: ZeroXString;
19
+ } | {
20
+ kind: 'string';
21
+ value: string;
22
+ } | {
23
+ kind: 'uint';
24
+ value: bigint | number | string;
25
+ } | {
26
+ kind: 'bool';
27
+ value: boolean;
28
+ } | {
29
+ kind: 'bytes';
30
+ value: Uint8Array;
31
+ } | {
32
+ kind: 'list';
33
+ value: PlpPayload[];
34
+ } | null | undefined;
@@ -1,12 +1,17 @@
1
- import type { ZeroXString, Signature, Payload } from './interface';
1
+ import type { Payload, Signature, ZeroXString } from './interface';
2
2
  /**
3
3
  * RLP encode a payload into a digest
4
+ * @deprecated Prefer the TransactionBuilder flow in `src/signing`
5
+ * (`prepare*Tx` + `.sign(...)`) to build and sign transactions.
4
6
  * @param payload Payload to encode
5
7
  * @returns RLP encoded payload
6
8
  */
7
9
  export declare function encodePayload(payload: Payload): Uint8Array<ArrayBufferLike>;
8
10
  /**
9
11
  * Sign a message using the provided private key
12
+ * @deprecated Prefer the TransactionBuilder flow in `src/signing`
13
+ * (`prepare*Tx` + `.sign(createPrivateKeySigner(privateKey))`)
14
+ * for transaction signing.
10
15
  * @param payload Payload to sign
11
16
  * @param privateKey Private key to sign with
12
17
  * @returns Signature object with r, s, v components
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1money/protocol-ts-sdk",
3
- "version": "1.1.2",
3
+ "version": "2.0.0",
4
4
  "description": "ts sdk for 1Money protocol network",
5
5
  "main": "lib/index.js",
6
6
  "module": "es/index.js",
@@ -75,7 +75,7 @@
75
75
  "@commitlint/cli": "8.3.5",
76
76
  "@ethereumjs/rlp": "^10.0.0",
77
77
  "@noble/secp256k1": "2.3.0",
78
- "@omni-door/cli": "~3.1.1",
78
+ "@omni-door/cli": "~3.2.2",
79
79
  "@rollup/plugin-alias": "~5.1.1",
80
80
  "@rollup/plugin-babel": "~6.0.4",
81
81
  "@rollup/plugin-commonjs": "~28.0.3",