@1money/protocol-ts-sdk 1.1.2 → 2.0.1
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 +18 -1
- package/README.md +216 -134
- package/es/__integration__/helpers.d.ts +0 -7
- package/es/api/checkpoints/types.d.ts +0 -1
- package/es/api/index.js +49 -10
- package/es/api/tokens/index.d.ts +7 -1
- package/es/api/tokens/types.d.ts +21 -6
- package/es/api/transactions/index.d.ts +4 -3
- package/es/api/transactions/types.d.ts +14 -5
- package/es/client/core.d.ts +2 -4
- package/es/client/index.js +36 -4
- package/es/index.d.ts +1 -0
- package/es/index.js +513 -22
- package/es/signing/builders/index.d.ts +11 -0
- package/es/signing/builders/payment.d.ts +3 -0
- package/es/signing/builders/tokenAuthority.d.ts +3 -0
- package/es/signing/builders/tokenBridgeAndMint.d.ts +3 -0
- package/es/signing/builders/tokenBurn.d.ts +3 -0
- package/es/signing/builders/tokenBurnAndBridge.d.ts +3 -0
- package/es/signing/builders/tokenClawback.d.ts +3 -0
- package/es/signing/builders/tokenIssue.d.ts +3 -0
- package/es/signing/builders/tokenManageList.d.ts +3 -0
- package/es/signing/builders/tokenMetadata.d.ts +3 -0
- package/es/signing/builders/tokenMint.d.ts +3 -0
- package/es/signing/builders/tokenPause.d.ts +3 -0
- package/es/signing/builders/validate.d.ts +18 -0
- package/es/signing/core.d.ts +27 -0
- package/es/signing/index.d.ts +18 -0
- package/es/signing/signer.d.ts +3 -0
- package/es/utils/encode.d.ts +11 -0
- package/es/utils/index.d.ts +2 -1
- package/es/utils/index.js +90 -10
- package/es/utils/interface.d.ts +27 -0
- package/es/utils/sign.d.ts +6 -1
- package/eslint.config.mjs +101 -0
- package/lib/__integration__/helpers.d.ts +0 -7
- package/lib/api/checkpoints/types.d.ts +0 -1
- package/lib/api/index.js +59 -10
- package/lib/api/tokens/index.d.ts +7 -1
- package/lib/api/tokens/types.d.ts +21 -6
- package/lib/api/transactions/index.d.ts +4 -3
- package/lib/api/transactions/types.d.ts +14 -5
- package/lib/client/core.d.ts +2 -4
- package/lib/client/index.js +46 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +511 -21
- package/lib/signing/builders/index.d.ts +11 -0
- package/lib/signing/builders/payment.d.ts +3 -0
- package/lib/signing/builders/tokenAuthority.d.ts +3 -0
- package/lib/signing/builders/tokenBridgeAndMint.d.ts +3 -0
- package/lib/signing/builders/tokenBurn.d.ts +3 -0
- package/lib/signing/builders/tokenBurnAndBridge.d.ts +3 -0
- package/lib/signing/builders/tokenClawback.d.ts +3 -0
- package/lib/signing/builders/tokenIssue.d.ts +3 -0
- package/lib/signing/builders/tokenManageList.d.ts +3 -0
- package/lib/signing/builders/tokenMetadata.d.ts +3 -0
- package/lib/signing/builders/tokenMint.d.ts +3 -0
- package/lib/signing/builders/tokenPause.d.ts +3 -0
- package/lib/signing/builders/validate.d.ts +18 -0
- package/lib/signing/core.d.ts +27 -0
- package/lib/signing/index.d.ts +18 -0
- package/lib/signing/signer.d.ts +3 -0
- package/lib/utils/encode.d.ts +11 -0
- package/lib/utils/index.d.ts +2 -1
- package/lib/utils/index.js +90 -10
- package/lib/utils/interface.d.ts +27 -0
- package/lib/utils/sign.d.ts +6 -1
- package/package.json +26 -15
- package/umd/1money-protocol-ts-sdk.min.js +4 -2
|
@@ -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,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>;
|
package/es/utils/index.d.ts
CHANGED
package/es/utils/index.js
CHANGED
|
@@ -25,6 +25,81 @@ function deriveTokenAddress(walletAddress, mintAddress) {
|
|
|
25
25
|
const hashBytes = hexToBytes$1(hashHex);
|
|
26
26
|
const addressBytes = hashBytes.slice(12);
|
|
27
27
|
return bytesToHex$1(addressBytes);
|
|
28
|
+
}const ADDRESS_HEX_RE = /^0x[0-9a-fA-F]{40}$/;
|
|
29
|
+
const 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: ${value.value}`);
|
|
41
|
+
}
|
|
42
|
+
const n = typeof value.value === 'bigint'
|
|
43
|
+
? value.value
|
|
44
|
+
: BigInt(value.value);
|
|
45
|
+
return n === BigInt(0)
|
|
46
|
+
? new Uint8Array([])
|
|
47
|
+
: hexToBytes$1(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(v => 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: ${value.value}`);
|
|
61
|
+
}
|
|
62
|
+
if (value.kind === 'address' &&
|
|
63
|
+
!ADDRESS_HEX_RE.test(value.value)) {
|
|
64
|
+
throw new Error(`[1Money SDK]: Invalid address value: ${value.value}`);
|
|
65
|
+
}
|
|
66
|
+
return value.value === '0x'
|
|
67
|
+
? new Uint8Array([])
|
|
68
|
+
: hexToBytes$1(value.value);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
const rlpValue = {
|
|
72
|
+
address: (v) => ({
|
|
73
|
+
kind: 'address',
|
|
74
|
+
value: v
|
|
75
|
+
}),
|
|
76
|
+
hex: (v) => ({
|
|
77
|
+
kind: 'hex',
|
|
78
|
+
value: v
|
|
79
|
+
}),
|
|
80
|
+
string: (v) => ({
|
|
81
|
+
kind: 'string',
|
|
82
|
+
value: v
|
|
83
|
+
}),
|
|
84
|
+
uint: (v) => ({
|
|
85
|
+
kind: 'uint',
|
|
86
|
+
value: v
|
|
87
|
+
}),
|
|
88
|
+
bool: (v) => ({
|
|
89
|
+
kind: 'bool',
|
|
90
|
+
value: v
|
|
91
|
+
}),
|
|
92
|
+
bytes: (v) => ({
|
|
93
|
+
kind: 'bytes',
|
|
94
|
+
value: v
|
|
95
|
+
}),
|
|
96
|
+
list: (v) => ({
|
|
97
|
+
kind: 'list',
|
|
98
|
+
value: v
|
|
99
|
+
})
|
|
100
|
+
};
|
|
101
|
+
function encodeRlpPayload(payload) {
|
|
102
|
+
return encode(innerEncodeRlpPayload(payload));
|
|
28
103
|
}// concurrent
|
|
29
104
|
function safePromiseAll(arr) {
|
|
30
105
|
// @ts-expect-error
|
|
@@ -46,11 +121,6 @@ async function safePromiseLine(arr) {
|
|
|
46
121
|
}
|
|
47
122
|
}
|
|
48
123
|
return res;
|
|
49
|
-
}function _typeof(ele) {
|
|
50
|
-
if (typeof ele !== 'object')
|
|
51
|
-
return (typeof ele).toLowerCase();
|
|
52
|
-
const typeStr = Object.prototype.toString.call(ele);
|
|
53
|
-
return typeStr.slice(8, typeStr.length - 1).toLowerCase();
|
|
54
124
|
}/*! noble-secp256k1 - MIT License (c) 2019 Paul Miller (paulmillr.com) */
|
|
55
125
|
/**
|
|
56
126
|
* 4KB JS implementation of secp256k1 ECDSA / Schnorr signatures & ECDH.
|
|
@@ -706,8 +776,15 @@ const wNAF = (n) => {
|
|
|
706
776
|
}
|
|
707
777
|
}
|
|
708
778
|
return { p, f }; // return both real and fake points for JIT
|
|
709
|
-
}
|
|
779
|
+
};function _typeof(ele) {
|
|
780
|
+
if (typeof ele !== 'object')
|
|
781
|
+
return (typeof ele).toLowerCase();
|
|
782
|
+
const typeStr = Object.prototype.toString.call(ele);
|
|
783
|
+
return typeStr.slice(8, typeStr.length - 1).toLowerCase();
|
|
784
|
+
}/**
|
|
710
785
|
* RLP encode a payload into a digest
|
|
786
|
+
* @deprecated Prefer the TransactionBuilder flow in `src/signing`
|
|
787
|
+
* (`prepare*Tx` + `.sign(...)`) to build and sign transactions.
|
|
711
788
|
* @param payload Payload to encode
|
|
712
789
|
* @returns RLP encoded payload
|
|
713
790
|
*/
|
|
@@ -715,9 +792,9 @@ function encodePayload(payload) {
|
|
|
715
792
|
if (_typeof(payload) === 'array') {
|
|
716
793
|
const formatted = payload.map((v) => {
|
|
717
794
|
if (_typeof(v) === 'string') {
|
|
718
|
-
if (/^0x[0-9a-fA-F]
|
|
795
|
+
if (/^0x([0-9a-fA-F]{2})*$/.test(v)) {
|
|
719
796
|
// hex-encoded data → raw bytes
|
|
720
|
-
return hexToBytes$1(v);
|
|
797
|
+
return v === '0x' ? new Uint8Array([]) : hexToBytes$1(v);
|
|
721
798
|
}
|
|
722
799
|
else if (/^\d+$/.test(v)) {
|
|
723
800
|
// number-like string → hex → bytes
|
|
@@ -749,6 +826,9 @@ function encodePayload(payload) {
|
|
|
749
826
|
}
|
|
750
827
|
/**
|
|
751
828
|
* Sign a message using the provided private key
|
|
829
|
+
* @deprecated Prefer the TransactionBuilder flow in `src/signing`
|
|
830
|
+
* (`prepare*Tx` + `.sign(createPrivateKeySigner(privateKey))`)
|
|
831
|
+
* for transaction signing.
|
|
752
832
|
* @param payload Payload to sign
|
|
753
833
|
* @param privateKey Private key to sign with
|
|
754
834
|
* @returns Signature object with r, s, v components
|
|
@@ -809,7 +889,7 @@ function toHex(value) {
|
|
|
809
889
|
}
|
|
810
890
|
}
|
|
811
891
|
catch (e) {
|
|
812
|
-
console.error('[1Money
|
|
892
|
+
console.error('[1Money SDK]: toHex error:', e);
|
|
813
893
|
return '0x';
|
|
814
894
|
}
|
|
815
895
|
}function encodeRlpListHeader(length) {
|
|
@@ -847,4 +927,4 @@ function calcTxHash(payload, signature) {
|
|
|
847
927
|
encoded.set(pEncode, header.length);
|
|
848
928
|
encoded.set(vrsBytes, header.length + pEncode.length);
|
|
849
929
|
return keccak256(encoded);
|
|
850
|
-
}export{_typeof,calcTxHash,deriveTokenAddress,encodePayload,safePromiseAll,safePromiseLine,signMessage,toHex};
|
|
930
|
+
}export{_typeof,calcTxHash,deriveTokenAddress,encodePayload,encodeRlpPayload,rlpValue,safePromiseAll,safePromiseLine,signMessage,toHex};
|
package/es/utils/interface.d.ts
CHANGED
|
@@ -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;
|
package/es/utils/sign.d.ts
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import type {
|
|
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
|
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import js from '@eslint/js';
|
|
2
|
+
import tseslint from 'typescript-eslint';
|
|
3
|
+
import eslintPluginPrettierRecommended from 'eslint-plugin-prettier/recommended';
|
|
4
|
+
|
|
5
|
+
export default tseslint.config(
|
|
6
|
+
// Global ignores (replaces .eslintignore)
|
|
7
|
+
{
|
|
8
|
+
ignores: [
|
|
9
|
+
'build/',
|
|
10
|
+
'configs/',
|
|
11
|
+
'es/',
|
|
12
|
+
'lib/',
|
|
13
|
+
'dist/',
|
|
14
|
+
'server/',
|
|
15
|
+
'demo/',
|
|
16
|
+
'node_modules/',
|
|
17
|
+
'src/**/__test__/',
|
|
18
|
+
'src/.umi',
|
|
19
|
+
'*.config.js',
|
|
20
|
+
'*.config.mjs',
|
|
21
|
+
'*.conf.js',
|
|
22
|
+
'mocha.tsx.js',
|
|
23
|
+
'commitlint.config.js',
|
|
24
|
+
],
|
|
25
|
+
},
|
|
26
|
+
|
|
27
|
+
// Base configs
|
|
28
|
+
js.configs.recommended,
|
|
29
|
+
...tseslint.configs.recommended,
|
|
30
|
+
|
|
31
|
+
// Main source config
|
|
32
|
+
{
|
|
33
|
+
files: ['src/**/*.{ts,tsx}'],
|
|
34
|
+
languageOptions: {
|
|
35
|
+
ecmaVersion: 2020,
|
|
36
|
+
sourceType: 'module',
|
|
37
|
+
globals: {
|
|
38
|
+
Atomics: 'readonly',
|
|
39
|
+
SharedArrayBuffer: 'readonly',
|
|
40
|
+
},
|
|
41
|
+
parserOptions: {
|
|
42
|
+
project: './tsconfig.json',
|
|
43
|
+
},
|
|
44
|
+
},
|
|
45
|
+
rules: {
|
|
46
|
+
// TypeScript
|
|
47
|
+
'@typescript-eslint/no-empty-interface': 'off',
|
|
48
|
+
'@typescript-eslint/no-empty-object-type': 'off',
|
|
49
|
+
'@typescript-eslint/restrict-plus-operands': 'warn',
|
|
50
|
+
'@typescript-eslint/array-type': 'off',
|
|
51
|
+
'@typescript-eslint/no-use-before-define': 'off',
|
|
52
|
+
'@typescript-eslint/consistent-type-assertions': 'warn',
|
|
53
|
+
'@typescript-eslint/no-inferrable-types': 'warn',
|
|
54
|
+
'@typescript-eslint/explicit-member-accessibility': 'warn',
|
|
55
|
+
|
|
56
|
+
'@typescript-eslint/no-explicit-any': 'off',
|
|
57
|
+
'@typescript-eslint/no-unused-vars': 'off',
|
|
58
|
+
'@typescript-eslint/no-unused-expressions': 'off',
|
|
59
|
+
'@typescript-eslint/ban-ts-comment': 'off',
|
|
60
|
+
'@typescript-eslint/no-unnecessary-type-constraint': 'off',
|
|
61
|
+
|
|
62
|
+
// Core ESLint
|
|
63
|
+
'no-console': ['error', { allow: ['warn', 'error', 'info'] }],
|
|
64
|
+
'prefer-spread': 'warn',
|
|
65
|
+
'no-unused-vars': 'off',
|
|
66
|
+
},
|
|
67
|
+
},
|
|
68
|
+
|
|
69
|
+
// Integration tests override
|
|
70
|
+
{
|
|
71
|
+
files: ['src/__integration__/**/*.ts'],
|
|
72
|
+
rules: {
|
|
73
|
+
'no-console': 'off',
|
|
74
|
+
'@typescript-eslint/no-inferrable-types': 'off',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
|
|
78
|
+
// Prettier (must be last — disables conflicting rules + adds prettier plugin)
|
|
79
|
+
eslintPluginPrettierRecommended,
|
|
80
|
+
|
|
81
|
+
// Custom prettier options
|
|
82
|
+
{
|
|
83
|
+
files: ['src/**/*.{ts,tsx}'],
|
|
84
|
+
rules: {
|
|
85
|
+
'prettier/prettier': [
|
|
86
|
+
'warn',
|
|
87
|
+
{
|
|
88
|
+
printWidth: 50,
|
|
89
|
+
tabWidth: 2,
|
|
90
|
+
singleQuote: true,
|
|
91
|
+
jsxSingleQuote: true,
|
|
92
|
+
semi: true,
|
|
93
|
+
trailingComma: 'none',
|
|
94
|
+
endOfLine: 'auto',
|
|
95
|
+
arrowParens: 'avoid',
|
|
96
|
+
rangeEnd: 0,
|
|
97
|
+
},
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
);
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Integration test helper utilities
|
|
3
3
|
*/
|
|
4
|
-
import type { RestSignature } from '../api/tokens/types';
|
|
5
|
-
import type { TestAccount } from './setup';
|
|
6
|
-
import type { Payload } from '../utils/interface';
|
|
7
4
|
/**
|
|
8
5
|
* Create API client for integration tests
|
|
9
6
|
*/
|
|
@@ -14,10 +11,6 @@ export declare function createTestClient(): {
|
|
|
14
11
|
transactions: typeof import("../api/transactions").transactionsApi;
|
|
15
12
|
chain: typeof import("../api/chain").chainApi;
|
|
16
13
|
};
|
|
17
|
-
/**
|
|
18
|
-
* Sign a payload with an account and return RestSignature format
|
|
19
|
-
*/
|
|
20
|
-
export declare function signPayload(payload: Payload, account: TestAccount): Promise<RestSignature>;
|
|
21
14
|
/**
|
|
22
15
|
* Wait for a transaction to be finalized
|
|
23
16
|
* @param txHash Transaction hash
|
package/lib/api/index.js
CHANGED
|
@@ -122,7 +122,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
122
122
|
_this._restScope = scope || _this._restScope;
|
|
123
123
|
// @ts-ignore
|
|
124
124
|
if (_this._restScope.length === 0) {
|
|
125
|
-
console.warn('[1Money
|
|
125
|
+
console.warn('[1Money SDK]: The ".rest(cb, scope)" scope is empty and will never be triggered!');
|
|
126
126
|
}
|
|
127
127
|
else {
|
|
128
128
|
var deletedCounter_1 = 0;
|
|
@@ -137,7 +137,7 @@ typeof SuppressedError === "function" ? SuppressedError : function (error, suppr
|
|
|
137
137
|
}
|
|
138
138
|
});
|
|
139
139
|
if (deletedCounter_1 === _this._restScope.length) {
|
|
140
|
-
console.warn("[1Money
|
|
140
|
+
console.warn("[1Money SDK]: The \"".concat(_this._restScope.join(', '), "\" had been called and the \"rest\" will never be triggered!"));
|
|
141
141
|
}
|
|
142
142
|
}
|
|
143
143
|
return wrapper;
|
|
@@ -184,9 +184,36 @@ var Request = /** @class */ (function () {
|
|
|
184
184
|
data: data
|
|
185
185
|
};
|
|
186
186
|
};
|
|
187
|
+
Request.prototype.mergeSignals = function () {
|
|
188
|
+
var signals = [];
|
|
189
|
+
for (var _i = 0; _i < arguments.length; _i++) {
|
|
190
|
+
signals[_i] = arguments[_i];
|
|
191
|
+
}
|
|
192
|
+
var controller = new AbortController();
|
|
193
|
+
var onAbort = function () { return controller.abort(); };
|
|
194
|
+
var cleanups = [];
|
|
195
|
+
var _loop_2 = function (signal) {
|
|
196
|
+
if (signal.aborted) {
|
|
197
|
+
controller.abort();
|
|
198
|
+
return "break";
|
|
199
|
+
}
|
|
200
|
+
signal.addEventListener('abort', onAbort);
|
|
201
|
+
cleanups.push(function () { return signal.removeEventListener('abort', onAbort); });
|
|
202
|
+
};
|
|
203
|
+
for (var _a = 0, signals_1 = signals; _a < signals_1.length; _a++) {
|
|
204
|
+
var signal = signals_1[_a];
|
|
205
|
+
var state_1 = _loop_2(signal);
|
|
206
|
+
if (state_1 === "break")
|
|
207
|
+
break;
|
|
208
|
+
}
|
|
209
|
+
return {
|
|
210
|
+
signal: controller.signal,
|
|
211
|
+
cleanup: function () { return cleanups.forEach(function (fn) { return fn(); }); },
|
|
212
|
+
};
|
|
213
|
+
};
|
|
187
214
|
Request.prototype.setting = function (config) {
|
|
188
215
|
if (!config)
|
|
189
|
-
return console.warn('[1Money
|
|
216
|
+
return console.warn('[1Money SDK]: setting method required correct parameters!');
|
|
190
217
|
this._config = __assign(__assign({}, this._config), config);
|
|
191
218
|
};
|
|
192
219
|
Request.prototype.request = function (options) {
|
|
@@ -272,12 +299,26 @@ var Request = /** @class */ (function () {
|
|
|
272
299
|
var timer = null;
|
|
273
300
|
var isTimeout = false;
|
|
274
301
|
var _timeout = timeout !== null && timeout !== void 0 ? timeout : initTimeout;
|
|
302
|
+
var controller = new AbortController();
|
|
303
|
+
var signalCleanup = null;
|
|
304
|
+
if (options.signal) {
|
|
305
|
+
var merged = _this.mergeSignals(options.signal, controller.signal);
|
|
306
|
+
options.signal = merged.signal;
|
|
307
|
+
signalCleanup = merged.cleanup;
|
|
308
|
+
}
|
|
309
|
+
else {
|
|
310
|
+
options.signal = controller.signal;
|
|
311
|
+
}
|
|
275
312
|
// Cleanup function for timeout
|
|
276
313
|
var cleanup = function () {
|
|
277
314
|
if (timer !== null) {
|
|
278
315
|
clearTimeout(timer);
|
|
279
316
|
timer = null;
|
|
280
317
|
}
|
|
318
|
+
if (signalCleanup) {
|
|
319
|
+
signalCleanup();
|
|
320
|
+
signalCleanup = null;
|
|
321
|
+
}
|
|
281
322
|
};
|
|
282
323
|
if (_timeout) {
|
|
283
324
|
timer = setTimeout(function () { return __awaiter(_this, void 0, void 0, function () {
|
|
@@ -289,6 +330,7 @@ var Request = /** @class */ (function () {
|
|
|
289
330
|
_c.trys.push([0, 2, , 3]);
|
|
290
331
|
isTimeout = true;
|
|
291
332
|
cleanup();
|
|
333
|
+
controller.abort();
|
|
292
334
|
err = this.parseError('timeout');
|
|
293
335
|
return [4 /*yield*/, Promise.resolve(callbacks.timeout(err, (_a = options.headers) !== null && _a !== void 0 ? _a : {}))];
|
|
294
336
|
case 1:
|
|
@@ -363,7 +405,7 @@ var Request = /** @class */ (function () {
|
|
|
363
405
|
return [2 /*return*/];
|
|
364
406
|
cleanup();
|
|
365
407
|
data = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
366
|
-
console.error("[1Money
|
|
408
|
+
console.error("[1Money SDK]: Error(".concat((_c = err.status) !== null && _c !== void 0 ? _c : 500, ", ").concat((_d = err.code) !== null && _d !== void 0 ? _d : 'UNKNOWN', "), Message: ").concat(err.message, ", Config: ").concat((_f = err.config) === null || _f === void 0 ? void 0 : _f.method, ", ").concat((_h = (_g = err.config) === null || _g === void 0 ? void 0 : _g.baseURL) !== null && _h !== void 0 ? _h : '', ", ").concat((_k = (_j = err.config) === null || _j === void 0 ? void 0 : _j.url) !== null && _k !== void 0 ? _k : '', ", ").concat(JSON.stringify((_o = (_l = err.config) === null || _l === void 0 ? void 0 : _l.headers) !== null && _o !== void 0 ? _o : {}), ", Request: ").concat(JSON.stringify((_q = (_p = err.config) === null || _p === void 0 ? void 0 : _p.data) !== null && _q !== void 0 ? _q : {}), ", Response: ").concat(JSON.stringify(data), ";"));
|
|
367
409
|
status = (_s = (_r = err.response) === null || _r === void 0 ? void 0 : _r.status) !== null && _s !== void 0 ? _s : 500;
|
|
368
410
|
headers = (_u = (_t = err.response) === null || _t === void 0 ? void 0 : _t.headers) !== null && _u !== void 0 ? _u : {};
|
|
369
411
|
_w.label = 1;
|
|
@@ -579,6 +621,14 @@ var tokensApi = {
|
|
|
579
621
|
*/
|
|
580
622
|
burnAndBridge: function (payload) {
|
|
581
623
|
return post("".concat(API_PREFIX$2, "/burn_and_bridge"), payload, { withCredentials: false });
|
|
624
|
+
},
|
|
625
|
+
/**
|
|
626
|
+
* Claw back tokens from a wallet
|
|
627
|
+
* @param payload Token clawback request payload
|
|
628
|
+
* @returns Promise with transaction hash response
|
|
629
|
+
*/
|
|
630
|
+
clawbackToken: function (payload) {
|
|
631
|
+
return post("".concat(API_PREFIX$2, "/clawback"), payload, { withCredentials: false });
|
|
582
632
|
}
|
|
583
633
|
};var API_PREFIX$1 = "/".concat(API_VERSION, "/transactions");
|
|
584
634
|
/**
|
|
@@ -612,15 +662,13 @@ var transactionsApi = {
|
|
|
612
662
|
/**
|
|
613
663
|
* Estimate transaction fee
|
|
614
664
|
* @param from Address of the transaction author
|
|
665
|
+
* @param to Address of the transaction recipient
|
|
615
666
|
* @param value Value of the transaction
|
|
616
|
-
* @param token
|
|
667
|
+
* @param token Token address
|
|
617
668
|
* @returns Promise with fee estimate response
|
|
618
669
|
*/
|
|
619
|
-
estimateFee: function (from, value, token) {
|
|
620
|
-
var url = "".concat(API_PREFIX$1, "/estimate_fee?from=").concat(from, "&value=").concat(value);
|
|
621
|
-
if (token) {
|
|
622
|
-
url += "&token=".concat(token);
|
|
623
|
-
}
|
|
670
|
+
estimateFee: function (from, to, value, token) {
|
|
671
|
+
var url = "".concat(API_PREFIX$1, "/estimate_fee?from=").concat(from, "&value=").concat(value, "&to=").concat(to, "&token=").concat(token);
|
|
624
672
|
return get(url, { withCredentials: false });
|
|
625
673
|
},
|
|
626
674
|
/**
|
|
@@ -652,6 +700,7 @@ exports.AuthorityType=void 0;
|
|
|
652
700
|
AuthorityType["ManageList"] = "ManageList";
|
|
653
701
|
AuthorityType["UpdateMetadata"] = "UpdateMetadata";
|
|
654
702
|
AuthorityType["Bridge"] = "Bridge";
|
|
703
|
+
AuthorityType["Clawback"] = "Clawback";
|
|
655
704
|
})(exports.AuthorityType || (exports.AuthorityType = {}));
|
|
656
705
|
exports.AuthorityAction=void 0;
|
|
657
706
|
(function (AuthorityAction) {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hash, HashWithToken } from '../../api/types';
|
|
2
|
-
import type { MintInfo, TokenManageListPayload, TokenBurnPayload, TokenAuthorityPayload, TokenIssuePayload, TokenMintPayload, TokenPausePayload, TokenMetadataPayload, TokenBridgeAndMintPayload, TokenBurnAndBridgePayload } from './types';
|
|
2
|
+
import type { MintInfo, TokenManageListPayload, TokenBurnPayload, TokenAuthorityPayload, TokenIssuePayload, TokenMintPayload, TokenPausePayload, TokenMetadataPayload, TokenBridgeAndMintPayload, TokenBurnAndBridgePayload, TokenClawbackPayload } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Tokens API methods
|
|
5
5
|
*/
|
|
@@ -70,5 +70,11 @@ export declare const tokensApi: {
|
|
|
70
70
|
* @returns Promise with transaction hash response
|
|
71
71
|
*/
|
|
72
72
|
burnAndBridge: (payload: TokenBurnAndBridgePayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
73
|
+
/**
|
|
74
|
+
* Claw back tokens from a wallet
|
|
75
|
+
* @param payload Token clawback request payload
|
|
76
|
+
* @returns Promise with transaction hash response
|
|
77
|
+
*/
|
|
78
|
+
clawbackToken: (payload: TokenClawbackPayload) => import("../../client/index.js").PromiseWrapper<"custom", Hash, Hash, Hash, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | Hash, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<Hash>;
|
|
73
79
|
};
|
|
74
80
|
export default tokensApi;
|