@1money/protocol-ts-sdk 1.0.16 → 1.1.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 +14 -2
- package/.env.integration.example +19 -0
- package/AGENTS.md +28 -0
- package/LICENSE +21 -0
- package/README.md +21 -55
- package/es/__integration__/config.d.ts +24 -0
- package/es/__integration__/helpers.d.ts +75 -0
- package/es/__integration__/setup.d.ts +26 -0
- package/es/api/accounts/index.d.ts +7 -1
- package/es/api/accounts/types.d.ts +4 -2
- package/es/api/checkpoints/index.d.ts +7 -1
- package/es/api/checkpoints/types.d.ts +4 -16
- package/es/api/index.js +50 -5
- package/es/api/tokens/index.d.ts +13 -1
- package/es/api/tokens/types.d.ts +27 -9
- package/es/api/transactions/index.d.ts +7 -2
- package/es/api/transactions/types.d.ts +149 -2
- package/es/client/core.d.ts +1 -1
- package/es/client/index.js +8 -4
- package/es/index.js +63 -9
- package/es/utils/index.js +13 -4
- package/lib/__integration__/config.d.ts +24 -0
- package/lib/__integration__/helpers.d.ts +75 -0
- package/lib/__integration__/setup.d.ts +26 -0
- package/lib/api/accounts/index.d.ts +7 -1
- package/lib/api/accounts/types.d.ts +4 -2
- package/lib/api/checkpoints/index.d.ts +7 -1
- package/lib/api/checkpoints/types.d.ts +4 -16
- package/lib/api/index.js +48 -7
- package/lib/api/tokens/index.d.ts +13 -1
- package/lib/api/tokens/types.d.ts +27 -9
- package/lib/api/transactions/index.d.ts +7 -2
- package/lib/api/transactions/types.d.ts +149 -2
- package/lib/client/core.d.ts +1 -1
- package/lib/client/index.js +6 -6
- package/lib/index.js +61 -11
- package/lib/utils/index.js +13 -4
- package/package.json +10 -1
- package/umd/1money-protocol-ts-sdk.min.js +2 -2
package/es/api/tokens/types.d.ts
CHANGED
|
@@ -23,6 +23,7 @@ export interface MintInfo {
|
|
|
23
23
|
black_list: AddressSchema[];
|
|
24
24
|
white_list: AddressSchema[];
|
|
25
25
|
metadata_update_authorities: AddressSchema[];
|
|
26
|
+
bridge_mint_authorities: AddressSchema[];
|
|
26
27
|
supply: U256Schema;
|
|
27
28
|
decimals: number;
|
|
28
29
|
is_paused: boolean;
|
|
@@ -34,11 +35,12 @@ export interface KeyValuePair {
|
|
|
34
35
|
value: string;
|
|
35
36
|
}
|
|
36
37
|
export declare enum AuthorityType {
|
|
37
|
-
MasterMint = "
|
|
38
|
+
MasterMint = "MasterMintBurn",
|
|
38
39
|
MintBurnTokens = "MintBurnTokens",
|
|
39
40
|
Pause = "Pause",
|
|
40
41
|
ManageList = "ManageList",
|
|
41
|
-
UpdateMetadata = "UpdateMetadata"
|
|
42
|
+
UpdateMetadata = "UpdateMetadata",
|
|
43
|
+
Bridge = "Bridge"
|
|
42
44
|
}
|
|
43
45
|
export declare enum AuthorityAction {
|
|
44
46
|
Grant = "Grant",
|
|
@@ -55,7 +57,6 @@ export declare enum PauseAction {
|
|
|
55
57
|
export interface RestSignature extends Signature {
|
|
56
58
|
}
|
|
57
59
|
export interface TokenManageListPayload {
|
|
58
|
-
recent_checkpoint: number;
|
|
59
60
|
chain_id: number;
|
|
60
61
|
nonce: number;
|
|
61
62
|
action: ManageListAction;
|
|
@@ -64,7 +65,6 @@ export interface TokenManageListPayload {
|
|
|
64
65
|
signature: RestSignature;
|
|
65
66
|
}
|
|
66
67
|
export interface TokenBurnPayload {
|
|
67
|
-
recent_checkpoint: number;
|
|
68
68
|
chain_id: number;
|
|
69
69
|
nonce: number;
|
|
70
70
|
recipient: string;
|
|
@@ -73,7 +73,6 @@ export interface TokenBurnPayload {
|
|
|
73
73
|
signature: RestSignature;
|
|
74
74
|
}
|
|
75
75
|
export interface TokenAuthorityPayload {
|
|
76
|
-
recent_checkpoint: number;
|
|
77
76
|
chain_id: number;
|
|
78
77
|
nonce: number;
|
|
79
78
|
action: AuthorityAction;
|
|
@@ -84,7 +83,6 @@ export interface TokenAuthorityPayload {
|
|
|
84
83
|
signature: RestSignature;
|
|
85
84
|
}
|
|
86
85
|
export interface TokenIssuePayload {
|
|
87
|
-
recent_checkpoint: number;
|
|
88
86
|
chain_id: number;
|
|
89
87
|
nonce: number;
|
|
90
88
|
symbol: string;
|
|
@@ -95,7 +93,6 @@ export interface TokenIssuePayload {
|
|
|
95
93
|
signature: RestSignature;
|
|
96
94
|
}
|
|
97
95
|
export interface TokenMintPayload {
|
|
98
|
-
recent_checkpoint: number;
|
|
99
96
|
chain_id: number;
|
|
100
97
|
nonce: number;
|
|
101
98
|
recipient: string;
|
|
@@ -104,7 +101,6 @@ export interface TokenMintPayload {
|
|
|
104
101
|
signature: RestSignature;
|
|
105
102
|
}
|
|
106
103
|
export interface TokenPausePayload {
|
|
107
|
-
recent_checkpoint: number;
|
|
108
104
|
chain_id: number;
|
|
109
105
|
nonce: number;
|
|
110
106
|
action: PauseAction;
|
|
@@ -112,7 +108,6 @@ export interface TokenPausePayload {
|
|
|
112
108
|
signature: RestSignature;
|
|
113
109
|
}
|
|
114
110
|
export interface TokenMetadataPayload {
|
|
115
|
-
recent_checkpoint: number;
|
|
116
111
|
chain_id: number;
|
|
117
112
|
nonce: number;
|
|
118
113
|
name: string;
|
|
@@ -121,3 +116,26 @@ export interface TokenMetadataPayload {
|
|
|
121
116
|
additional_metadata: KeyValuePair[];
|
|
122
117
|
signature: RestSignature;
|
|
123
118
|
}
|
|
119
|
+
export interface TokenBridgeAndMintPayload {
|
|
120
|
+
chain_id: number;
|
|
121
|
+
nonce: number;
|
|
122
|
+
recipient: string;
|
|
123
|
+
value: string;
|
|
124
|
+
token: string;
|
|
125
|
+
source_chain_id: number;
|
|
126
|
+
source_tx_hash: string;
|
|
127
|
+
bridge_metadata: string;
|
|
128
|
+
signature: RestSignature;
|
|
129
|
+
}
|
|
130
|
+
export interface TokenBurnAndBridgePayload {
|
|
131
|
+
bridge_metadata: string;
|
|
132
|
+
chain_id: number;
|
|
133
|
+
destination_address: string;
|
|
134
|
+
destination_chain_id: number;
|
|
135
|
+
escrow_fee: string;
|
|
136
|
+
nonce: number;
|
|
137
|
+
sender: string;
|
|
138
|
+
token: string;
|
|
139
|
+
value: string;
|
|
140
|
+
signature: RestSignature;
|
|
141
|
+
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import type { Hash } from '../../api/types';
|
|
2
|
-
import type { Transaction } from '
|
|
3
|
-
import type { TransactionReceipt, EstimateFee, PaymentPayload } from './types';
|
|
2
|
+
import type { EstimateFee, PaymentPayload, Transaction, TransactionReceipt, FinalizedTransactionReceipt } from './types';
|
|
4
3
|
/**
|
|
5
4
|
* Transactions API methods
|
|
6
5
|
*/
|
|
@@ -17,6 +16,12 @@ export declare const transactionsApi: {
|
|
|
17
16
|
* @returns Promise with transaction receipt response
|
|
18
17
|
*/
|
|
19
18
|
getReceiptByHash: (hash: string) => import("../../client/index.js").PromiseWrapper<"custom", TransactionReceipt, TransactionReceipt, TransactionReceipt, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | TransactionReceipt, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<TransactionReceipt>;
|
|
19
|
+
/**
|
|
20
|
+
* Get finalized transaction by hash
|
|
21
|
+
* @param hash Hash of the transaction to lookup
|
|
22
|
+
* @returns Promise with finalized transaction receipt response
|
|
23
|
+
*/
|
|
24
|
+
getFinalizedByHash: (hash: string) => import("../../client/index.js").PromiseWrapper<"custom", FinalizedTransactionReceipt, FinalizedTransactionReceipt, FinalizedTransactionReceipt, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | FinalizedTransactionReceipt, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<FinalizedTransactionReceipt>;
|
|
20
25
|
/**
|
|
21
26
|
* Estimate transaction fee
|
|
22
27
|
* @param from Address of the transaction author
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
+
import { AuthorityType, RestSignature } from '../tokens/types';
|
|
1
2
|
import { AddressSchema, B256Schema } from '../types';
|
|
2
|
-
import { RestSignature } from '../tokens/types';
|
|
3
3
|
export interface TransactionReceipt {
|
|
4
4
|
success: boolean;
|
|
5
5
|
transaction_hash: B256Schema;
|
|
@@ -10,11 +10,14 @@ export interface TransactionReceipt {
|
|
|
10
10
|
to?: AddressSchema;
|
|
11
11
|
token_address?: AddressSchema;
|
|
12
12
|
}
|
|
13
|
+
export interface FinalizedTransactionReceipt extends TransactionReceipt {
|
|
14
|
+
epoch: number;
|
|
15
|
+
counter_signatures: RestSignature[];
|
|
16
|
+
}
|
|
13
17
|
export interface EstimateFee {
|
|
14
18
|
fee: string;
|
|
15
19
|
}
|
|
16
20
|
export interface PaymentPayload {
|
|
17
|
-
recent_checkpoint: number;
|
|
18
21
|
chain_id: number;
|
|
19
22
|
nonce: number;
|
|
20
23
|
recipient: AddressSchema;
|
|
@@ -22,3 +25,147 @@ export interface PaymentPayload {
|
|
|
22
25
|
token: AddressSchema;
|
|
23
26
|
signature: RestSignature;
|
|
24
27
|
}
|
|
28
|
+
export interface TokenCreateData {
|
|
29
|
+
decimals: number;
|
|
30
|
+
is_private: boolean;
|
|
31
|
+
master_authority: AddressSchema;
|
|
32
|
+
name: string;
|
|
33
|
+
symbol: string;
|
|
34
|
+
}
|
|
35
|
+
export interface TokenTransferData {
|
|
36
|
+
recipient: AddressSchema;
|
|
37
|
+
token: AddressSchema;
|
|
38
|
+
value: string;
|
|
39
|
+
}
|
|
40
|
+
export interface TokenMintData {
|
|
41
|
+
recipient: AddressSchema;
|
|
42
|
+
token: AddressSchema;
|
|
43
|
+
value: string;
|
|
44
|
+
}
|
|
45
|
+
export interface TokenGrantAuthorityData {
|
|
46
|
+
authority_address: AddressSchema;
|
|
47
|
+
authority_type: AuthorityType;
|
|
48
|
+
token: AddressSchema;
|
|
49
|
+
value: string;
|
|
50
|
+
}
|
|
51
|
+
export interface TokenRevokeAuthorityData {
|
|
52
|
+
authority_address: AddressSchema;
|
|
53
|
+
authority_type: AuthorityType;
|
|
54
|
+
token: AddressSchema;
|
|
55
|
+
value: string;
|
|
56
|
+
}
|
|
57
|
+
export interface TokenBlacklistAccountData {
|
|
58
|
+
address: AddressSchema;
|
|
59
|
+
token: AddressSchema;
|
|
60
|
+
}
|
|
61
|
+
export interface TokenWhitelistAccountData {
|
|
62
|
+
address: AddressSchema;
|
|
63
|
+
token: AddressSchema;
|
|
64
|
+
}
|
|
65
|
+
export interface TokenBridgeAndMintData {
|
|
66
|
+
bridge_metadata: string | null;
|
|
67
|
+
recipient: AddressSchema;
|
|
68
|
+
source_chain_id: number;
|
|
69
|
+
source_tx_hash: string;
|
|
70
|
+
token: AddressSchema;
|
|
71
|
+
value: string;
|
|
72
|
+
}
|
|
73
|
+
export interface TokenBurnData {
|
|
74
|
+
recipient: AddressSchema;
|
|
75
|
+
token: AddressSchema;
|
|
76
|
+
value: string;
|
|
77
|
+
}
|
|
78
|
+
export interface TokenBurnAndBridgeData {
|
|
79
|
+
bridge_metadata: string | null;
|
|
80
|
+
destination_address: AddressSchema;
|
|
81
|
+
destination_chain_id: number;
|
|
82
|
+
escrow_fee: string;
|
|
83
|
+
sender: AddressSchema;
|
|
84
|
+
token: AddressSchema;
|
|
85
|
+
value: string;
|
|
86
|
+
}
|
|
87
|
+
export interface TokenCloseAccountData {
|
|
88
|
+
token: AddressSchema;
|
|
89
|
+
}
|
|
90
|
+
export interface TokenPauseData {
|
|
91
|
+
token: AddressSchema;
|
|
92
|
+
}
|
|
93
|
+
export interface TokenUpdateMetadataData {
|
|
94
|
+
metadata: {
|
|
95
|
+
name: string;
|
|
96
|
+
uri: string;
|
|
97
|
+
additional_metadata: Array<{
|
|
98
|
+
key: string;
|
|
99
|
+
value: string;
|
|
100
|
+
}>;
|
|
101
|
+
};
|
|
102
|
+
token: AddressSchema;
|
|
103
|
+
}
|
|
104
|
+
export interface RawData {
|
|
105
|
+
input: string;
|
|
106
|
+
token: AddressSchema;
|
|
107
|
+
}
|
|
108
|
+
export interface TokenUnpauseData {
|
|
109
|
+
token: AddressSchema;
|
|
110
|
+
}
|
|
111
|
+
interface BaseTransaction {
|
|
112
|
+
hash: B256Schema;
|
|
113
|
+
checkpoint_hash?: B256Schema;
|
|
114
|
+
checkpoint_number?: number;
|
|
115
|
+
transaction_index?: number;
|
|
116
|
+
chain_id: number;
|
|
117
|
+
from: AddressSchema;
|
|
118
|
+
nonce: number;
|
|
119
|
+
signature: {
|
|
120
|
+
r: string;
|
|
121
|
+
s: string;
|
|
122
|
+
v: number;
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export type Transaction = (BaseTransaction & {
|
|
126
|
+
transaction_type: 'TokenCreate';
|
|
127
|
+
data: TokenCreateData;
|
|
128
|
+
}) | (BaseTransaction & {
|
|
129
|
+
transaction_type: 'TokenTransfer';
|
|
130
|
+
data: TokenTransferData;
|
|
131
|
+
}) | (BaseTransaction & {
|
|
132
|
+
transaction_type: 'TokenMint';
|
|
133
|
+
data: TokenMintData;
|
|
134
|
+
}) | (BaseTransaction & {
|
|
135
|
+
transaction_type: 'TokenGrantAuthority';
|
|
136
|
+
data: TokenGrantAuthorityData;
|
|
137
|
+
}) | (BaseTransaction & {
|
|
138
|
+
transaction_type: 'TokenRevokeAuthority';
|
|
139
|
+
data: TokenRevokeAuthorityData;
|
|
140
|
+
}) | (BaseTransaction & {
|
|
141
|
+
transaction_type: 'TokenBlacklistAccount';
|
|
142
|
+
data: TokenBlacklistAccountData;
|
|
143
|
+
}) | (BaseTransaction & {
|
|
144
|
+
transaction_type: 'TokenWhitelistAccount';
|
|
145
|
+
data: TokenWhitelistAccountData;
|
|
146
|
+
}) | (BaseTransaction & {
|
|
147
|
+
transaction_type: 'TokenBridgeAndMint';
|
|
148
|
+
data: TokenBridgeAndMintData;
|
|
149
|
+
}) | (BaseTransaction & {
|
|
150
|
+
transaction_type: 'TokenBurn';
|
|
151
|
+
data: TokenBurnData;
|
|
152
|
+
}) | (BaseTransaction & {
|
|
153
|
+
transaction_type: 'TokenBurnAndBridge';
|
|
154
|
+
data: TokenBurnAndBridgeData;
|
|
155
|
+
}) | (BaseTransaction & {
|
|
156
|
+
transaction_type: 'TokenCloseAccount';
|
|
157
|
+
data: TokenCloseAccountData;
|
|
158
|
+
}) | (BaseTransaction & {
|
|
159
|
+
transaction_type: 'TokenPause';
|
|
160
|
+
data: TokenPauseData;
|
|
161
|
+
}) | (BaseTransaction & {
|
|
162
|
+
transaction_type: 'TokenUnpause';
|
|
163
|
+
data: TokenUnpauseData;
|
|
164
|
+
}) | (BaseTransaction & {
|
|
165
|
+
transaction_type: 'TokenUpdateMetadata';
|
|
166
|
+
data: TokenUpdateMetadataData;
|
|
167
|
+
}) | (BaseTransaction & {
|
|
168
|
+
transaction_type: 'Raw';
|
|
169
|
+
data: RawData;
|
|
170
|
+
});
|
|
171
|
+
export {};
|
package/es/client/core.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { AxiosRequestConfig, AxiosRequestHeaders, AxiosResponseHeaders, AxiosStatic, RawAxiosRequestHeaders, RawAxiosResponseHeaders } from 'axios';
|
|
2
2
|
export type ParsedError<T extends string = string> = {
|
|
3
3
|
name: T;
|
|
4
4
|
message: string;
|
package/es/client/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import'viem';import'@ethereumjs/rlp';import axios$1 from'axios';function _typeof(ele) {
|
|
2
2
|
if (typeof ele !== 'object')
|
|
3
3
|
return (typeof ele).toLowerCase();
|
|
4
4
|
const typeStr = Object.prototype.toString.call(ele);
|
|
@@ -116,7 +116,11 @@ class Request {
|
|
|
116
116
|
request(options) {
|
|
117
117
|
// Set default security headers
|
|
118
118
|
options.withCredentials = typeof options.withCredentials === 'boolean' ? options.withCredentials : true;
|
|
119
|
-
options.headers =
|
|
119
|
+
options.headers = {
|
|
120
|
+
...axios$1.defaults.headers.common,
|
|
121
|
+
...(options.method ? axios$1.defaults.headers[options.method] : {}),
|
|
122
|
+
...options.headers,
|
|
123
|
+
};
|
|
120
124
|
options.headers['Accept'] = options.headers['Accept'] || '*/*';
|
|
121
125
|
options.headers['X-Requested-With'] = options.headers['X-Requested-With'] || 'XMLHttpRequest';
|
|
122
126
|
options.headers['X-Content-Type-Options'] = options.headers['X-Content-Type-Options'] || 'nosniff';
|
|
@@ -261,9 +265,9 @@ class Request {
|
|
|
261
265
|
if (isTimeout)
|
|
262
266
|
return;
|
|
263
267
|
cleanup();
|
|
264
|
-
console.error(`[1Money client]: Error(${err.status ?? 500}, ${err.code ?? 'UNKNOWN'}), Message: ${err.message}, Config: ${err.config?.method}, ${err.config?.baseURL ?? ''}${err.config?.url ?? ''}, ${JSON.stringify(err.config?.headers ?? {})}, Request: ${JSON.stringify(err.config?.data ?? {})};`);
|
|
265
|
-
const status = err.response?.status ?? 500;
|
|
266
268
|
const data = err.response?.data ?? {};
|
|
269
|
+
console.error(`[1Money client]: Error(${err.status ?? 500}, ${err.code ?? 'UNKNOWN'}), Message: ${err.message}, Config: ${err.config?.method}, ${err.config?.baseURL ?? ''}, ${err.config?.url ?? ''}, ${JSON.stringify(err.config?.headers ?? {})}, Request: ${JSON.stringify(err.config?.data ?? {})}, Response: ${JSON.stringify(data)};`);
|
|
270
|
+
const status = err.response?.status ?? 500;
|
|
267
271
|
const headers = err.response?.headers ?? {};
|
|
268
272
|
try {
|
|
269
273
|
let res = data;
|
package/es/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import {hexToBytes as hexToBytes$1,stringToBytes,keccak256,bytesToHex as bytesToHex$1,numberToHex,stringToHex,boolToHex}from'viem';import {encode}from'@ethereumjs/rlp';import axios$1 from'axios';/**
|
|
2
2
|
* Derives the token account address given the wallet address and mint address.
|
|
3
3
|
*
|
|
4
4
|
* Address is 20 byte, 160 bits. Let's say if we want to support 50 billion
|
|
@@ -719,9 +719,10 @@ function encodePayload(payload) {
|
|
|
719
719
|
// hex-encoded data → raw bytes
|
|
720
720
|
return hexToBytes$1(v);
|
|
721
721
|
}
|
|
722
|
-
else if (
|
|
722
|
+
else if (/^\d+$/.test(v)) {
|
|
723
723
|
// number-like string → hex → bytes
|
|
724
|
-
|
|
724
|
+
// Use BigInt for large numbers to avoid overflow
|
|
725
|
+
return v === '0' ? new Uint8Array([]) : hexToBytes$1(numberToHex(BigInt(v)));
|
|
725
726
|
}
|
|
726
727
|
else {
|
|
727
728
|
// plain string → UTF-8 bytes
|
|
@@ -777,8 +778,16 @@ function toHex(value) {
|
|
|
777
778
|
case 'bigint':
|
|
778
779
|
return numberToHex(value);
|
|
779
780
|
case 'string':
|
|
780
|
-
|
|
781
|
-
|
|
781
|
+
// Only accept valid integer strings (no decimals, no whitespace, no empty)
|
|
782
|
+
if (/^-?\d+$/.test(value)) {
|
|
783
|
+
// Use BigInt for potentially large numbers to avoid overflow
|
|
784
|
+
try {
|
|
785
|
+
return numberToHex(BigInt(value));
|
|
786
|
+
}
|
|
787
|
+
catch {
|
|
788
|
+
return numberToHex(+value);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
782
791
|
return stringToHex(value);
|
|
783
792
|
case 'uint8array':
|
|
784
793
|
case 'uint16array':
|
|
@@ -951,7 +960,11 @@ class Request {
|
|
|
951
960
|
request(options) {
|
|
952
961
|
// Set default security headers
|
|
953
962
|
options.withCredentials = typeof options.withCredentials === 'boolean' ? options.withCredentials : true;
|
|
954
|
-
options.headers =
|
|
963
|
+
options.headers = {
|
|
964
|
+
...axios$1.defaults.headers.common,
|
|
965
|
+
...(options.method ? axios$1.defaults.headers[options.method] : {}),
|
|
966
|
+
...options.headers,
|
|
967
|
+
};
|
|
955
968
|
options.headers['Accept'] = options.headers['Accept'] || '*/*';
|
|
956
969
|
options.headers['X-Requested-With'] = options.headers['X-Requested-With'] || 'XMLHttpRequest';
|
|
957
970
|
options.headers['X-Content-Type-Options'] = options.headers['X-Content-Type-Options'] || 'nosniff';
|
|
@@ -1096,9 +1109,9 @@ class Request {
|
|
|
1096
1109
|
if (isTimeout)
|
|
1097
1110
|
return;
|
|
1098
1111
|
cleanup();
|
|
1099
|
-
console.error(`[1Money client]: Error(${err.status ?? 500}, ${err.code ?? 'UNKNOWN'}), Message: ${err.message}, Config: ${err.config?.method}, ${err.config?.baseURL ?? ''}${err.config?.url ?? ''}, ${JSON.stringify(err.config?.headers ?? {})}, Request: ${JSON.stringify(err.config?.data ?? {})};`);
|
|
1100
|
-
const status = err.response?.status ?? 500;
|
|
1101
1112
|
const data = err.response?.data ?? {};
|
|
1113
|
+
console.error(`[1Money client]: Error(${err.status ?? 500}, ${err.code ?? 'UNKNOWN'}), Message: ${err.message}, Config: ${err.config?.method}, ${err.config?.baseURL ?? ''}, ${err.config?.url ?? ''}, ${JSON.stringify(err.config?.headers ?? {})}, Request: ${JSON.stringify(err.config?.data ?? {})}, Response: ${JSON.stringify(data)};`);
|
|
1114
|
+
const status = err.response?.status ?? 500;
|
|
1102
1115
|
const headers = err.response?.headers ?? {};
|
|
1103
1116
|
try {
|
|
1104
1117
|
let res = data;
|
|
@@ -1223,6 +1236,14 @@ const accountsApi = {
|
|
|
1223
1236
|
getNonce: (address) => {
|
|
1224
1237
|
return get(`${API_PREFIX$4}/nonce?address=${address}`, { withCredentials: false });
|
|
1225
1238
|
},
|
|
1239
|
+
/**
|
|
1240
|
+
* Get account bbnonce
|
|
1241
|
+
* @param address Address of the account to lookup nonce for
|
|
1242
|
+
* @returns Promise with bbnonce info response
|
|
1243
|
+
*/
|
|
1244
|
+
getBbNonce: (address) => {
|
|
1245
|
+
return get(`${API_PREFIX$4}/bbnonce?address=${address}`, { withCredentials: false });
|
|
1246
|
+
},
|
|
1226
1247
|
/**
|
|
1227
1248
|
* Get associated token account
|
|
1228
1249
|
* @param address Address of the account to lookup associated token account for
|
|
@@ -1261,6 +1282,14 @@ const checkpointsApi = {
|
|
|
1261
1282
|
*/
|
|
1262
1283
|
getByNumber: (number, full = false) => {
|
|
1263
1284
|
return get(`${API_PREFIX$3}/by_number?number=${number}&full=${full}`, { withCredentials: false });
|
|
1285
|
+
},
|
|
1286
|
+
/**
|
|
1287
|
+
* Get checkpoint receipts by number
|
|
1288
|
+
* @param number Number of the checkpoint to lookup
|
|
1289
|
+
* @returns Promise with checkpoint receipts response
|
|
1290
|
+
*/
|
|
1291
|
+
getReceiptsByNumber: (number) => {
|
|
1292
|
+
return get(`${API_PREFIX$3}/receipts/by_number?number=${number}`, { withCredentials: false });
|
|
1264
1293
|
}
|
|
1265
1294
|
};const API_PREFIX$2 = `/${API_VERSION}/tokens`;
|
|
1266
1295
|
/**
|
|
@@ -1338,6 +1367,22 @@ const tokensApi = {
|
|
|
1338
1367
|
*/
|
|
1339
1368
|
updateMetadata: (payload) => {
|
|
1340
1369
|
return post(`${API_PREFIX$2}/update_metadata`, payload, { withCredentials: false });
|
|
1370
|
+
},
|
|
1371
|
+
/**
|
|
1372
|
+
* Bridge and mint tokens
|
|
1373
|
+
* @param payload Token bridge and mint request payload
|
|
1374
|
+
* @returns Promise with transaction hash response
|
|
1375
|
+
*/
|
|
1376
|
+
bridgeAndMint: (payload) => {
|
|
1377
|
+
return post(`${API_PREFIX$2}/bridge_and_mint`, payload, { withCredentials: false });
|
|
1378
|
+
},
|
|
1379
|
+
/**
|
|
1380
|
+
* Burn and bridge tokens
|
|
1381
|
+
* @param payload Token burn and bridge request payload
|
|
1382
|
+
* @returns Promise with transaction hash response
|
|
1383
|
+
*/
|
|
1384
|
+
burnAndBridge: (payload) => {
|
|
1385
|
+
return post(`${API_PREFIX$2}/burn_and_bridge`, payload, { withCredentials: false });
|
|
1341
1386
|
}
|
|
1342
1387
|
};const API_PREFIX$1 = `/${API_VERSION}/transactions`;
|
|
1343
1388
|
/**
|
|
@@ -1360,6 +1405,14 @@ const transactionsApi = {
|
|
|
1360
1405
|
getReceiptByHash: (hash) => {
|
|
1361
1406
|
return get(`${API_PREFIX$1}/receipt/by_hash?hash=${hash}`, { withCredentials: false });
|
|
1362
1407
|
},
|
|
1408
|
+
/**
|
|
1409
|
+
* Get finalized transaction by hash
|
|
1410
|
+
* @param hash Hash of the transaction to lookup
|
|
1411
|
+
* @returns Promise with finalized transaction receipt response
|
|
1412
|
+
*/
|
|
1413
|
+
getFinalizedByHash: (hash) => {
|
|
1414
|
+
return get(`${API_PREFIX$1}/finalized/by_hash?hash=${hash}`, { withCredentials: false });
|
|
1415
|
+
},
|
|
1363
1416
|
/**
|
|
1364
1417
|
* Estimate transaction fee
|
|
1365
1418
|
* @param from Address of the transaction author
|
|
@@ -1397,11 +1450,12 @@ const chainApi = {
|
|
|
1397
1450
|
};// Authority types
|
|
1398
1451
|
var AuthorityType;
|
|
1399
1452
|
(function (AuthorityType) {
|
|
1400
|
-
AuthorityType["MasterMint"] = "
|
|
1453
|
+
AuthorityType["MasterMint"] = "MasterMintBurn";
|
|
1401
1454
|
AuthorityType["MintBurnTokens"] = "MintBurnTokens";
|
|
1402
1455
|
AuthorityType["Pause"] = "Pause";
|
|
1403
1456
|
AuthorityType["ManageList"] = "ManageList";
|
|
1404
1457
|
AuthorityType["UpdateMetadata"] = "UpdateMetadata";
|
|
1458
|
+
AuthorityType["Bridge"] = "Bridge";
|
|
1405
1459
|
})(AuthorityType || (AuthorityType = {}));
|
|
1406
1460
|
var AuthorityAction;
|
|
1407
1461
|
(function (AuthorityAction) {
|
package/es/utils/index.js
CHANGED
|
@@ -719,9 +719,10 @@ function encodePayload(payload) {
|
|
|
719
719
|
// hex-encoded data → raw bytes
|
|
720
720
|
return hexToBytes$1(v);
|
|
721
721
|
}
|
|
722
|
-
else if (
|
|
722
|
+
else if (/^\d+$/.test(v)) {
|
|
723
723
|
// number-like string → hex → bytes
|
|
724
|
-
|
|
724
|
+
// Use BigInt for large numbers to avoid overflow
|
|
725
|
+
return v === '0' ? new Uint8Array([]) : hexToBytes$1(numberToHex(BigInt(v)));
|
|
725
726
|
}
|
|
726
727
|
else {
|
|
727
728
|
// plain string → UTF-8 bytes
|
|
@@ -777,8 +778,16 @@ function toHex(value) {
|
|
|
777
778
|
case 'bigint':
|
|
778
779
|
return numberToHex(value);
|
|
779
780
|
case 'string':
|
|
780
|
-
|
|
781
|
-
|
|
781
|
+
// Only accept valid integer strings (no decimals, no whitespace, no empty)
|
|
782
|
+
if (/^-?\d+$/.test(value)) {
|
|
783
|
+
// Use BigInt for potentially large numbers to avoid overflow
|
|
784
|
+
try {
|
|
785
|
+
return numberToHex(BigInt(value));
|
|
786
|
+
}
|
|
787
|
+
catch {
|
|
788
|
+
return numberToHex(+value);
|
|
789
|
+
}
|
|
790
|
+
}
|
|
782
791
|
return stringToHex(value);
|
|
783
792
|
case 'uint8array':
|
|
784
793
|
case 'uint16array':
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test configuration
|
|
3
|
+
*
|
|
4
|
+
* Environment variables:
|
|
5
|
+
* - INTEGRATION_TEST_NETWORK: Network to use (local, testnet, mainnet)
|
|
6
|
+
* - INTEGRATION_TEST_OPERATOR_KEY: Operator private key
|
|
7
|
+
* - INTEGRATION_TEST_MASTER_KEY: Master account private key
|
|
8
|
+
* - RUN_INTEGRATION_TESTS: Set to 'true' to run integration tests
|
|
9
|
+
*/
|
|
10
|
+
export interface IntegrationTestConfig {
|
|
11
|
+
network: 'local' | 'testnet' | 'mainnet';
|
|
12
|
+
operatorKey: string;
|
|
13
|
+
masterKey: string;
|
|
14
|
+
enabled: boolean;
|
|
15
|
+
timeout: number;
|
|
16
|
+
}
|
|
17
|
+
/**
|
|
18
|
+
* Get integration test configuration from environment variables
|
|
19
|
+
*/
|
|
20
|
+
export declare function getConfig(): IntegrationTestConfig;
|
|
21
|
+
/**
|
|
22
|
+
* Check if integration tests should run
|
|
23
|
+
*/
|
|
24
|
+
export declare function shouldRunIntegrationTests(): boolean;
|
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test helper utilities
|
|
3
|
+
*/
|
|
4
|
+
import type { RestSignature } from '../api/tokens/types';
|
|
5
|
+
import type { TestAccount } from './setup';
|
|
6
|
+
import type { Payload } from '../utils/interface';
|
|
7
|
+
/**
|
|
8
|
+
* Create API client for integration tests
|
|
9
|
+
*/
|
|
10
|
+
export declare function createTestClient(): {
|
|
11
|
+
accounts: typeof import("../api/accounts").accountsApi;
|
|
12
|
+
checkpoints: typeof import("../api/checkpoints").checkpointsApi;
|
|
13
|
+
tokens: typeof import("../api/tokens").tokensApi;
|
|
14
|
+
transactions: typeof import("../api/transactions").transactionsApi;
|
|
15
|
+
chain: typeof import("../api/chain").chainApi;
|
|
16
|
+
};
|
|
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
|
+
/**
|
|
22
|
+
* Wait for a transaction to be finalized
|
|
23
|
+
* @param txHash Transaction hash
|
|
24
|
+
* @param maxRetries Maximum number of retries
|
|
25
|
+
* @param retryDelay Delay between retries in milliseconds
|
|
26
|
+
*/
|
|
27
|
+
export declare function waitForFinalization(txHash: string, maxRetries?: number, retryDelay?: number): Promise<boolean>;
|
|
28
|
+
/**
|
|
29
|
+
* Wait for a specific amount of time
|
|
30
|
+
*/
|
|
31
|
+
export declare function wait(ms: number): Promise<void>;
|
|
32
|
+
/**
|
|
33
|
+
* Get current checkpoint number
|
|
34
|
+
*/
|
|
35
|
+
export declare function getCurrentCheckpoint(): Promise<number>;
|
|
36
|
+
/**
|
|
37
|
+
* Get account nonce
|
|
38
|
+
*/
|
|
39
|
+
export declare function getAccountNonce(address: string): Promise<number>;
|
|
40
|
+
/**
|
|
41
|
+
* Get chain ID
|
|
42
|
+
*/
|
|
43
|
+
export declare function getChainId(): Promise<number>;
|
|
44
|
+
/**
|
|
45
|
+
* Derive token address from owner and nonce
|
|
46
|
+
*/
|
|
47
|
+
export declare function deriveTokenAddress(owner: string, nonce: number): string;
|
|
48
|
+
/**
|
|
49
|
+
* Assert that a value is defined (throws if undefined/null)
|
|
50
|
+
*/
|
|
51
|
+
export declare function assertDefined<T>(value: T | undefined | null, message?: string): asserts value is T;
|
|
52
|
+
/**
|
|
53
|
+
* Format test section header
|
|
54
|
+
*/
|
|
55
|
+
export declare function logSection(title: string): void;
|
|
56
|
+
/**
|
|
57
|
+
* Format test step log
|
|
58
|
+
*/
|
|
59
|
+
export declare function logStep(step: string, detail?: string): void;
|
|
60
|
+
/**
|
|
61
|
+
* Generate a random token symbol for testing
|
|
62
|
+
*/
|
|
63
|
+
export declare function generateRandomSymbol(prefix?: string): string;
|
|
64
|
+
/**
|
|
65
|
+
* Normalize an address to checksum format for comparison
|
|
66
|
+
*/
|
|
67
|
+
export declare function normalizeAddress(address: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Check if two addresses are equal (case-insensitive)
|
|
70
|
+
*/
|
|
71
|
+
export declare function addressEquals(addr1: string, addr2: string): boolean;
|
|
72
|
+
/**
|
|
73
|
+
* Check if an array of addresses includes a specific address (case-insensitive)
|
|
74
|
+
*/
|
|
75
|
+
export declare function addressArrayIncludes(addresses: string[], targetAddress: string): boolean;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Integration test setup and account generation
|
|
3
|
+
*/
|
|
4
|
+
import type { PrivateKeyAccount } from 'viem/accounts';
|
|
5
|
+
export interface TestAccount extends PrivateKeyAccount {
|
|
6
|
+
privateKey: `0x${string}`;
|
|
7
|
+
}
|
|
8
|
+
export interface TestAccounts {
|
|
9
|
+
operator: TestAccount;
|
|
10
|
+
master: TestAccount;
|
|
11
|
+
user1: TestAccount;
|
|
12
|
+
user2: TestAccount;
|
|
13
|
+
user3: TestAccount;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Generate and cache test accounts
|
|
17
|
+
*/
|
|
18
|
+
export declare function getTestAccounts(): TestAccounts;
|
|
19
|
+
/**
|
|
20
|
+
* Log test account information
|
|
21
|
+
*/
|
|
22
|
+
export declare function logTestAccounts(): void;
|
|
23
|
+
/**
|
|
24
|
+
* Reset test accounts (for cleanup)
|
|
25
|
+
*/
|
|
26
|
+
export declare function resetTestAccounts(): void;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AccountInfo, AssociatedTokenAccount } from './types';
|
|
1
|
+
import type { AccountInfo, AssociatedTokenAccount, BbNonceInfo } from './types';
|
|
2
2
|
/**
|
|
3
3
|
* Accounts API methods
|
|
4
4
|
*/
|
|
@@ -9,6 +9,12 @@ export declare const accountsApi: {
|
|
|
9
9
|
* @returns Promise with account info response
|
|
10
10
|
*/
|
|
11
11
|
getNonce: (address: string) => import("../../client/index.js").PromiseWrapper<"custom", AccountInfo, AccountInfo, AccountInfo, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | AccountInfo, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<AccountInfo>;
|
|
12
|
+
/**
|
|
13
|
+
* Get account bbnonce
|
|
14
|
+
* @param address Address of the account to lookup nonce for
|
|
15
|
+
* @returns Promise with bbnonce info response
|
|
16
|
+
*/
|
|
17
|
+
getBbNonce: (address: string) => import("../../client/index.js").PromiseWrapper<"custom", BbNonceInfo, BbNonceInfo, BbNonceInfo, import("../../client/index.js").ParsedError<string>, import("../../client/index.js").ParsedError<string> | BbNonceInfo, import("../../client/index.js").ParsedError<"timeout">, ""> & Promise<BbNonceInfo>;
|
|
12
18
|
/**
|
|
13
19
|
* Get associated token account
|
|
14
20
|
* @param address Address of the account to lookup associated token account for
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { U256Schema } from '../types';
|
|
2
2
|
export interface AccountInfo {
|
|
3
3
|
nonce: number;
|
|
4
4
|
}
|
|
5
|
+
export interface BbNonceInfo {
|
|
6
|
+
bbnonce: number;
|
|
7
|
+
}
|
|
5
8
|
export interface AssociatedTokenAccount {
|
|
6
|
-
token_account_address: AddressSchema;
|
|
7
9
|
balance: U256Schema;
|
|
8
10
|
nonce: number;
|
|
9
11
|
}
|