@1money/protocol-ts-sdk 1.1.2-alpha.7 → 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.
- package/.claude/settings.local.json +2 -1
- package/README.md +244 -134
- package/es/__integration__/helpers.d.ts +0 -7
- package/es/api/checkpoints/types.d.ts +0 -1
- package/es/api/index.js +17 -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/index.js +4 -4
- package/es/index.d.ts +1 -0
- package/es/index.js +481 -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/lib/__integration__/helpers.d.ts +0 -7
- package/lib/api/checkpoints/types.d.ts +0 -1
- package/lib/api/index.js +17 -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/index.js +4 -4
- package/lib/index.d.ts +1 -0
- package/lib/index.js +469 -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 +2 -2
- package/umd/1money-protocol-ts-sdk.min.js +3 -2
- package/.env.integration +0 -16
- package/umd/1money-ts-sdk.min.js +0 -2
|
@@ -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
|
|
@@ -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;
|
|
@@ -186,7 +186,7 @@ var Request = /** @class */ (function () {
|
|
|
186
186
|
};
|
|
187
187
|
Request.prototype.setting = function (config) {
|
|
188
188
|
if (!config)
|
|
189
|
-
return console.warn('[1Money
|
|
189
|
+
return console.warn('[1Money SDK]: setting method required correct parameters!');
|
|
190
190
|
this._config = __assign(__assign({}, this._config), config);
|
|
191
191
|
};
|
|
192
192
|
Request.prototype.request = function (options) {
|
|
@@ -363,7 +363,7 @@ var Request = /** @class */ (function () {
|
|
|
363
363
|
return [2 /*return*/];
|
|
364
364
|
cleanup();
|
|
365
365
|
data = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
366
|
-
console.error("[1Money
|
|
366
|
+
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
367
|
status = (_s = (_r = err.response) === null || _r === void 0 ? void 0 : _r.status) !== null && _s !== void 0 ? _s : 500;
|
|
368
368
|
headers = (_u = (_t = err.response) === null || _t === void 0 ? void 0 : _t.headers) !== null && _u !== void 0 ? _u : {};
|
|
369
369
|
_w.label = 1;
|
|
@@ -579,6 +579,14 @@ var tokensApi = {
|
|
|
579
579
|
*/
|
|
580
580
|
burnAndBridge: function (payload) {
|
|
581
581
|
return post("".concat(API_PREFIX$2, "/burn_and_bridge"), payload, { withCredentials: false });
|
|
582
|
+
},
|
|
583
|
+
/**
|
|
584
|
+
* Claw back tokens from a wallet
|
|
585
|
+
* @param payload Token clawback request payload
|
|
586
|
+
* @returns Promise with transaction hash response
|
|
587
|
+
*/
|
|
588
|
+
clawbackToken: function (payload) {
|
|
589
|
+
return post("".concat(API_PREFIX$2, "/clawback"), payload, { withCredentials: false });
|
|
582
590
|
}
|
|
583
591
|
};var API_PREFIX$1 = "/".concat(API_VERSION, "/transactions");
|
|
584
592
|
/**
|
|
@@ -612,15 +620,13 @@ var transactionsApi = {
|
|
|
612
620
|
/**
|
|
613
621
|
* Estimate transaction fee
|
|
614
622
|
* @param from Address of the transaction author
|
|
623
|
+
* @param to Address of the transaction recipient
|
|
615
624
|
* @param value Value of the transaction
|
|
616
|
-
* @param token
|
|
625
|
+
* @param token Token address
|
|
617
626
|
* @returns Promise with fee estimate response
|
|
618
627
|
*/
|
|
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
|
-
}
|
|
628
|
+
estimateFee: function (from, to, value, token) {
|
|
629
|
+
var url = "".concat(API_PREFIX$1, "/estimate_fee?from=").concat(from, "&value=").concat(value, "&to=").concat(to, "&token=").concat(token);
|
|
624
630
|
return get(url, { withCredentials: false });
|
|
625
631
|
},
|
|
626
632
|
/**
|
|
@@ -652,6 +658,7 @@ exports.AuthorityType=void 0;
|
|
|
652
658
|
AuthorityType["ManageList"] = "ManageList";
|
|
653
659
|
AuthorityType["UpdateMetadata"] = "UpdateMetadata";
|
|
654
660
|
AuthorityType["Bridge"] = "Bridge";
|
|
661
|
+
AuthorityType["Clawback"] = "Clawback";
|
|
655
662
|
})(exports.AuthorityType || (exports.AuthorityType = {}));
|
|
656
663
|
exports.AuthorityAction=void 0;
|
|
657
664
|
(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;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { AddressSchema, U256Schema } from '../types';
|
|
1
|
+
import type { AddressSchema, BytesSchema, U256Schema } from '../types';
|
|
2
2
|
import type { Signature } from '../../utils/index.js';
|
|
3
3
|
export interface MetaDataKeyValuePair {
|
|
4
4
|
key: string;
|
|
@@ -28,6 +28,7 @@ export interface MintInfo {
|
|
|
28
28
|
decimals: number;
|
|
29
29
|
is_paused: boolean;
|
|
30
30
|
is_private: boolean;
|
|
31
|
+
clawback_enabled: boolean;
|
|
31
32
|
meta: TokenMetadata;
|
|
32
33
|
}
|
|
33
34
|
export interface KeyValuePair {
|
|
@@ -40,7 +41,8 @@ export declare enum AuthorityType {
|
|
|
40
41
|
Pause = "Pause",
|
|
41
42
|
ManageList = "ManageList",
|
|
42
43
|
UpdateMetadata = "UpdateMetadata",
|
|
43
|
-
Bridge = "Bridge"
|
|
44
|
+
Bridge = "Bridge",
|
|
45
|
+
Clawback = "Clawback"
|
|
44
46
|
}
|
|
45
47
|
export declare enum AuthorityAction {
|
|
46
48
|
Grant = "Grant",
|
|
@@ -67,7 +69,6 @@ export interface TokenManageListPayload {
|
|
|
67
69
|
export interface TokenBurnPayload {
|
|
68
70
|
chain_id: number;
|
|
69
71
|
nonce: number;
|
|
70
|
-
recipient: string;
|
|
71
72
|
value: string;
|
|
72
73
|
token: string;
|
|
73
74
|
signature: RestSignature;
|
|
@@ -90,6 +91,10 @@ export interface TokenIssuePayload {
|
|
|
90
91
|
decimals: number;
|
|
91
92
|
master_authority: string;
|
|
92
93
|
is_private: boolean;
|
|
94
|
+
/**
|
|
95
|
+
* @default true
|
|
96
|
+
*/
|
|
97
|
+
clawback_enabled?: boolean;
|
|
93
98
|
signature: RestSignature;
|
|
94
99
|
}
|
|
95
100
|
export interface TokenMintPayload {
|
|
@@ -128,14 +133,24 @@ export interface TokenBridgeAndMintPayload {
|
|
|
128
133
|
signature: RestSignature;
|
|
129
134
|
}
|
|
130
135
|
export interface TokenBurnAndBridgePayload {
|
|
131
|
-
bridge_metadata: string;
|
|
132
136
|
chain_id: number;
|
|
133
|
-
|
|
137
|
+
nonce: number;
|
|
138
|
+
sender: string;
|
|
139
|
+
value: string;
|
|
140
|
+
token: string;
|
|
134
141
|
destination_chain_id: number;
|
|
142
|
+
destination_address: string;
|
|
135
143
|
escrow_fee: string;
|
|
144
|
+
bridge_metadata: string;
|
|
145
|
+
bridge_param: BytesSchema;
|
|
146
|
+
signature: RestSignature;
|
|
147
|
+
}
|
|
148
|
+
export interface TokenClawbackPayload {
|
|
149
|
+
chain_id: number;
|
|
136
150
|
nonce: number;
|
|
137
|
-
sender: string;
|
|
138
151
|
token: string;
|
|
152
|
+
from: string;
|
|
153
|
+
recipient: string;
|
|
139
154
|
value: string;
|
|
140
155
|
signature: RestSignature;
|
|
141
156
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Hash } from '../../api/types';
|
|
2
|
-
import type { EstimateFee, PaymentPayload, Transaction, TransactionReceipt
|
|
2
|
+
import type { EstimateFee, FinalizedTransactionReceipt, PaymentPayload, Transaction, TransactionReceipt } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Transactions API methods
|
|
5
5
|
*/
|
|
@@ -25,11 +25,12 @@ export declare const transactionsApi: {
|
|
|
25
25
|
/**
|
|
26
26
|
* Estimate transaction fee
|
|
27
27
|
* @param from Address of the transaction author
|
|
28
|
+
* @param to Address of the transaction recipient
|
|
28
29
|
* @param value Value of the transaction
|
|
29
|
-
* @param token
|
|
30
|
+
* @param token Token address
|
|
30
31
|
* @returns Promise with fee estimate response
|
|
31
32
|
*/
|
|
32
|
-
estimateFee: (from: string, value: string, token
|
|
33
|
+
estimateFee: (from: string, to: string, value: string, token: string) => import("../../client/index.js").PromiseWrapper<"custom", EstimateFee, EstimateFee, EstimateFee, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | EstimateFee, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<EstimateFee>;
|
|
33
34
|
/**
|
|
34
35
|
* Submit payment transaction
|
|
35
36
|
* @param payload Payment transaction payload
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { AuthorityType, RestSignature } from '../tokens/types';
|
|
2
|
-
import { AddressSchema, B256Schema } from '../types';
|
|
2
|
+
import type { AddressSchema, B256Schema, BytesSchema } from '../types';
|
|
3
3
|
export interface TransactionReceipt {
|
|
4
4
|
success: boolean;
|
|
5
5
|
transaction_hash: B256Schema;
|
|
@@ -71,18 +71,24 @@ export interface TokenBridgeAndMintData {
|
|
|
71
71
|
value: string;
|
|
72
72
|
}
|
|
73
73
|
export interface TokenBurnData {
|
|
74
|
-
recipient: AddressSchema;
|
|
75
74
|
token: AddressSchema;
|
|
76
75
|
value: string;
|
|
77
76
|
}
|
|
78
77
|
export interface TokenBurnAndBridgeData {
|
|
79
|
-
|
|
80
|
-
|
|
78
|
+
value: string;
|
|
79
|
+
sender: AddressSchema;
|
|
81
80
|
destination_chain_id: number;
|
|
81
|
+
destination_address: AddressSchema;
|
|
82
82
|
escrow_fee: string;
|
|
83
|
-
|
|
83
|
+
bridge_metadata: string | null;
|
|
84
|
+
bridge_param: BytesSchema;
|
|
84
85
|
token: AddressSchema;
|
|
86
|
+
}
|
|
87
|
+
export interface TokenClawbackData {
|
|
88
|
+
from: AddressSchema;
|
|
89
|
+
recipient: AddressSchema;
|
|
85
90
|
value: string;
|
|
91
|
+
token: AddressSchema;
|
|
86
92
|
}
|
|
87
93
|
export interface TokenCloseAccountData {
|
|
88
94
|
token: AddressSchema;
|
|
@@ -152,6 +158,9 @@ export type Transaction = (BaseTransaction & {
|
|
|
152
158
|
}) | (BaseTransaction & {
|
|
153
159
|
transaction_type: 'TokenBurnAndBridge';
|
|
154
160
|
data: TokenBurnAndBridgeData;
|
|
161
|
+
}) | (BaseTransaction & {
|
|
162
|
+
transaction_type: 'TokenClawback';
|
|
163
|
+
data: TokenClawbackData;
|
|
155
164
|
}) | (BaseTransaction & {
|
|
156
165
|
transaction_type: 'TokenCloseAccount';
|
|
157
166
|
data: TokenCloseAccountData;
|
package/lib/client/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;
|
|
@@ -186,7 +186,7 @@ var Request = /** @class */ (function () {
|
|
|
186
186
|
};
|
|
187
187
|
Request.prototype.setting = function (config) {
|
|
188
188
|
if (!config)
|
|
189
|
-
return console.warn('[1Money
|
|
189
|
+
return console.warn('[1Money SDK]: setting method required correct parameters!');
|
|
190
190
|
this._config = __assign(__assign({}, this._config), config);
|
|
191
191
|
};
|
|
192
192
|
Request.prototype.request = function (options) {
|
|
@@ -363,7 +363,7 @@ var Request = /** @class */ (function () {
|
|
|
363
363
|
return [2 /*return*/];
|
|
364
364
|
cleanup();
|
|
365
365
|
data = (_b = (_a = err.response) === null || _a === void 0 ? void 0 : _a.data) !== null && _b !== void 0 ? _b : {};
|
|
366
|
-
console.error("[1Money
|
|
366
|
+
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
367
|
status = (_s = (_r = err.response) === null || _r === void 0 ? void 0 : _r.status) !== null && _s !== void 0 ? _s : 500;
|
|
368
368
|
headers = (_u = (_t = err.response) === null || _t === void 0 ? void 0 : _t.headers) !== null && _u !== void 0 ? _u : {};
|
|
369
369
|
_w.label = 1;
|
package/lib/index.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { api } from './api/index.js';
|
|
2
2
|
export { api } from './api/index.js';
|
|
3
3
|
export { default as client } from './client/index.js';
|
|
4
|
+
export * from './signing';
|
|
4
5
|
export * from './utils/index.js';
|
|
5
6
|
export type { AxiosStatic } from 'axios';
|
|
6
7
|
export type { InitConfig, Options, ParsedError, PromiseWrapper } from './client/core';
|