mmn-client-js 1.0.13 → 1.0.14-node14

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/dist/index.d.ts CHANGED
@@ -1,286 +1,285 @@
1
- interface JsonRpcRequest {
2
- jsonrpc: '2.0';
3
- method: string;
4
- params?: unknown;
5
- id: string | number;
6
- }
7
- interface JsonRpcError {
8
- code: number;
9
- message: string;
10
- data?: unknown;
11
- }
12
- interface JsonRpcResponse<T = unknown> {
13
- jsonrpc: '2.0';
14
- result?: T;
15
- error?: JsonRpcError;
16
- id: string | number;
17
- }
18
- interface IEphemeralKeyPair {
19
- privateKey: string;
20
- publicKey: string;
21
- }
22
- declare enum ETransferType {
23
- GiveCoffee = "give_coffee",
24
- TransferToken = "transfer_token",
25
- UnlockItem = "unlock_item"
26
- }
27
- interface ExtraInfo {
28
- type: ETransferType | string;
29
- ItemId?: string;
30
- ItemType?: string;
31
- ClanId?: string;
32
- UserSenderId?: string;
33
- UserSenderUsername?: string;
34
- UserReceiverId?: string;
35
- ChannelId?: string;
36
- MessageRefId?: string;
37
- ExtraAttribute?: string;
38
- [x: string]: string;
39
- }
40
- interface TxMsg {
41
- type: number;
42
- sender: string;
43
- recipient: string;
44
- amount: string;
45
- timestamp: number;
46
- text_data: string;
47
- nonce: number;
48
- extra_info: string;
49
- zk_proof: string;
50
- zk_pub: string;
51
- }
52
- interface SignedTx {
53
- tx_msg: TxMsg;
54
- signature: string;
55
- }
56
- interface SendTransactionBase {
57
- sender: string;
58
- recipient: string;
59
- amount: string;
60
- nonce: number;
61
- timestamp?: number;
62
- textData?: string;
63
- privateKey: string;
64
- extraInfo?: ExtraInfo;
65
- }
66
- interface SendTransactionRequest extends SendTransactionBase {
67
- zkProof: string;
68
- zkPub: string;
69
- publicKey: string;
70
- }
71
- interface AddTxResponse {
72
- ok: boolean;
73
- tx_hash: string;
74
- error: string;
75
- }
76
- interface GetCurrentNonceResponse {
77
- address: string;
78
- nonce: number;
79
- tag: string;
80
- error: string;
81
- }
82
- interface GetAccountByAddressResponse {
83
- address: string;
84
- balance: string;
85
- nonce: number;
86
- decimals: number;
87
- }
88
- interface MmnClientConfig {
89
- baseUrl: string;
90
- timeout?: number;
91
- headers?: Record<string, string>;
92
- }
93
- interface Transaction {
94
- chain_id: string;
95
- hash: string;
96
- nonce: number;
97
- block_hash: string;
98
- block_number: number;
99
- block_timestamp: number;
100
- transaction_index: number;
101
- from_address: string;
102
- to_address: string;
103
- value: string;
104
- gas: number;
105
- gas_price: string;
106
- data: string;
107
- function_selector: string;
108
- max_fee_per_gas: string;
109
- max_priority_fee_per_gas: string;
110
- max_fee_per_blob_gas?: string;
111
- blob_versioned_hashes?: string[];
112
- transaction_type: number;
113
- r: string;
114
- s: string;
115
- v: string;
116
- access_list_json?: string;
117
- authorization_list_json?: string;
118
- contract_address?: string;
119
- gas_used?: number;
120
- cumulative_gas_used?: number;
121
- effective_gas_price?: string;
122
- blob_gas_used?: number;
123
- blob_gas_price?: string;
124
- logs_bloom?: string;
125
- status?: number;
126
- transaction_timestamp: number;
127
- text_data: string;
128
- extra_info: string;
129
- }
130
- interface Meta {
131
- chain_id: number;
132
- address?: string;
133
- signature?: string;
134
- page: number;
135
- limit?: number;
136
- total_items?: number;
137
- total_pages?: number;
138
- }
139
- interface WalletDetail {
140
- address: string;
141
- balance: string;
142
- account_nonce: number;
143
- last_balance_update: number;
144
- }
145
- interface WalletDetailResponse {
146
- data: WalletDetail;
147
- }
148
- interface ListTransactionResponse {
149
- meta: Meta;
150
- data?: Transaction[];
151
- }
152
- interface TransactionDetailResponse {
153
- data: {
154
- transaction: Transaction;
155
- };
156
- }
157
- interface IndexerClientConfig {
158
- endpoint: string;
159
- chainId: string;
160
- timeout?: number;
161
- headers?: Record<string, string>;
162
- }
163
- interface ZkClientConfig {
164
- endpoint: string;
165
- timeout?: number;
166
- headers?: Record<string, string>;
167
- }
168
- declare enum EZkClientType {
169
- MEZON = "mezon",
170
- OAUTH = "oauth"
171
- }
172
- interface GetZkProofRequest {
173
- userId: string;
174
- ephemeralPublicKey: string;
175
- jwt: string;
176
- address: string;
177
- clientType?: EZkClientType;
178
- }
179
- interface IZkProof {
180
- proof: string;
181
- public_input: string;
1
+ interface JsonRpcRequest {
2
+ jsonrpc: '2.0';
3
+ method: string;
4
+ params?: unknown;
5
+ id: string | number;
6
+ }
7
+ interface JsonRpcError {
8
+ code: number;
9
+ message: string;
10
+ data?: unknown;
11
+ }
12
+ interface JsonRpcResponse<T = unknown> {
13
+ jsonrpc: '2.0';
14
+ result?: T;
15
+ error?: JsonRpcError;
16
+ id: string | number;
17
+ }
18
+ interface IEphemeralKeyPair {
19
+ privateKey: string;
20
+ publicKey: string;
21
+ }
22
+ declare enum ETransferType {
23
+ GiveCoffee = "give_coffee",
24
+ TransferToken = "transfer_token",
25
+ UnlockItem = "unlock_item"
26
+ }
27
+ interface ExtraInfo {
28
+ type: ETransferType | string;
29
+ ItemId?: string;
30
+ ItemType?: string;
31
+ ClanId?: string;
32
+ UserSenderId?: string;
33
+ UserSenderUsername?: string;
34
+ UserReceiverId?: string;
35
+ ChannelId?: string;
36
+ MessageRefId?: string;
37
+ ExtraAttribute?: string;
38
+ [x: string]: string;
39
+ }
40
+ interface TxMsg {
41
+ type: number;
42
+ sender: string;
43
+ recipient: string;
44
+ amount: string;
45
+ timestamp: number;
46
+ text_data: string;
47
+ nonce: number;
48
+ extra_info: string;
49
+ zk_proof: string;
50
+ zk_pub: string;
51
+ }
52
+ interface SignedTx {
53
+ tx_msg: TxMsg;
54
+ signature: string;
55
+ }
56
+ interface SendTransactionBase {
57
+ sender: string;
58
+ recipient: string;
59
+ amount: string;
60
+ nonce: number;
61
+ timestamp?: number;
62
+ textData?: string;
63
+ privateKey: string;
64
+ extraInfo?: ExtraInfo;
65
+ }
66
+ interface SendTransactionRequest extends SendTransactionBase {
67
+ zkProof: string;
68
+ zkPub: string;
69
+ publicKey: string;
70
+ }
71
+ interface AddTxResponse {
72
+ ok: boolean;
73
+ tx_hash: string;
74
+ error: string;
75
+ }
76
+ interface GetCurrentNonceResponse {
77
+ address: string;
78
+ nonce: number;
79
+ tag: string;
80
+ error: string;
81
+ }
82
+ interface GetAccountByAddressResponse {
83
+ address: string;
84
+ balance: string;
85
+ nonce: number;
86
+ decimals: number;
87
+ }
88
+ interface MmnClientConfig {
89
+ baseUrl: string;
90
+ timeout?: number;
91
+ headers?: Record<string, string>;
92
+ }
93
+ interface Transaction {
94
+ chain_id: string;
95
+ hash: string;
96
+ nonce: number;
97
+ block_hash: string;
98
+ block_number: number;
99
+ block_timestamp: number;
100
+ transaction_index: number;
101
+ from_address: string;
102
+ to_address: string;
103
+ value: string;
104
+ gas: number;
105
+ gas_price: string;
106
+ data: string;
107
+ function_selector: string;
108
+ max_fee_per_gas: string;
109
+ max_priority_fee_per_gas: string;
110
+ max_fee_per_blob_gas?: string;
111
+ blob_versioned_hashes?: string[];
112
+ transaction_type: number;
113
+ r: string;
114
+ s: string;
115
+ v: string;
116
+ access_list_json?: string;
117
+ authorization_list_json?: string;
118
+ contract_address?: string;
119
+ gas_used?: number;
120
+ cumulative_gas_used?: number;
121
+ effective_gas_price?: string;
122
+ blob_gas_used?: number;
123
+ blob_gas_price?: string;
124
+ logs_bloom?: string;
125
+ status?: number;
126
+ transaction_timestamp: number;
127
+ text_data: string;
128
+ extra_info: string;
129
+ }
130
+ interface Meta {
131
+ chain_id: number;
132
+ address?: string;
133
+ signature?: string;
134
+ page: number;
135
+ limit?: number;
136
+ total_items?: number;
137
+ total_pages?: number;
138
+ }
139
+ interface WalletDetail {
140
+ address: string;
141
+ balance: string;
142
+ account_nonce: number;
143
+ last_balance_update: number;
144
+ }
145
+ interface WalletDetailResponse {
146
+ data: WalletDetail;
147
+ }
148
+ interface ListTransactionResponse {
149
+ meta: Meta;
150
+ data?: Transaction[];
151
+ }
152
+ interface TransactionDetailResponse {
153
+ data: {
154
+ transaction: Transaction;
155
+ };
156
+ }
157
+ interface IndexerClientConfig {
158
+ endpoint: string;
159
+ chainId: string;
160
+ timeout?: number;
161
+ headers?: Record<string, string>;
162
+ }
163
+ interface ZkClientConfig {
164
+ endpoint: string;
165
+ timeout?: number;
166
+ headers?: Record<string, string>;
167
+ }
168
+ declare enum EZkClientType {
169
+ MEZON = "mezon",
170
+ OAUTH = "oauth"
171
+ }
172
+ interface GetZkProofRequest {
173
+ userId: string;
174
+ ephemeralPublicKey: string;
175
+ jwt: string;
176
+ address: string;
177
+ clientType?: EZkClientType;
178
+ }
179
+ interface IZkProof {
180
+ proof: string;
181
+ public_input: string;
182
182
  }
183
183
 
184
- declare class IndexerClient {
185
- private endpoint;
186
- private chainId;
187
- private timeout;
188
- private headers;
189
- constructor(config: IndexerClientConfig);
190
- /**
191
- * Make HTTP request with automatic CORS handling
192
- * Works out-of-the-box without CORS configuration
193
- * @param method - HTTP method (GET or POST)
194
- * @param path - API endpoint path
195
- * @param params - URL query parameters
196
- * @param body - Request body for POST requests
197
- * @returns Promise resolving to response data
198
- */
199
- private makeRequest;
200
- getTransactionByHash(hash: string): Promise<Transaction>;
201
- getTransactionByWallet(wallet: string, page: number | undefined, limit: number | undefined, filter: number, sortBy?: string, sortOrder?: 'asc' | 'desc'): Promise<ListTransactionResponse>;
202
- getWalletDetail(wallet: string): Promise<WalletDetail>;
184
+ declare class IndexerClient {
185
+ private endpoint;
186
+ private chainId;
187
+ private timeout;
188
+ private headers;
189
+ constructor(config: IndexerClientConfig);
190
+ /**
191
+ * Make HTTP request with automatic CORS handling
192
+ * Works out-of-the-box without CORS configuration
193
+ * @param method - HTTP method (GET or POST)
194
+ * @param path - API endpoint path
195
+ * @param params - URL query parameters
196
+ * @param body - Request body for POST requests
197
+ * @returns Promise resolving to response data
198
+ */
199
+ private makeRequest;
200
+ getTransactionByHash(hash: string): Promise<Transaction>;
201
+ getTransactionByWallet(wallet: string, page: number | undefined, limit: number | undefined, filter: number, sortBy?: string, sortOrder?: 'asc' | 'desc'): Promise<ListTransactionResponse>;
202
+ getWalletDetail(wallet: string): Promise<WalletDetail>;
203
203
  }
204
204
 
205
- declare class MmnClient {
206
- private config;
207
- private requestId;
208
- constructor(config: MmnClientConfig);
209
- private makeRequest;
210
- /**
211
- * Securely convert raw Ed25519 private key to PKCS#8 format
212
- * @param raw - Raw 32-byte Ed25519 private key
213
- * @returns PKCS#8 formatted private key in hex
214
- * @throws Error if input validation fails
215
- */
216
- private rawEd25519ToPkcs8Hex;
217
- /**
218
- * Encode length in ASN.1 DER format
219
- * ASN.1 length encoding rules:
220
- * - Short form (0-127): single byte with the length value
221
- * - Long form (128+): first byte is 0x80 + number of length bytes, followed by length bytes
222
- * @param length - The length value to encode
223
- * @returns ASN.1 DER encoded length bytes
224
- */
225
- private encodeLength;
226
- /**
227
- * Generate secure entropy using multiple sources for maximum compatibility
228
- * @returns Array of 32 random bytes
229
- */
230
- private generateSecureEntropy;
231
- /**
232
- * Securely generate ephemeral key pair with proper entropy
233
- * React Native compatible version with multiple fallbacks
234
- * @returns Ephemeral key pair with private and public keys
235
- * @throws Error if key generation fails
236
- */
237
- generateEphemeralKeyPair(): IEphemeralKeyPair;
238
- getAddressFromUserId(userId: string): string;
239
- /**
240
- * Create and sign a transaction message
241
- */
242
- private createAndSignTx;
243
- /**
244
- * Securely sign a transaction with Ed25519
245
- * @param tx - Transaction message to sign
246
- * @param privateKeyHex - Private key in PKCS#8 hex format
247
- * @returns Base58 encoded signature
248
- * @throws Error if signing fails
249
- */
250
- private signTransaction;
251
- /**
252
- * Serialize transaction for signing
253
- */
254
- private serializeTransaction;
255
- /**
256
- * Add a signed transaction to the blockchain
257
- */
258
- private addTx;
259
- /**
260
- * Send a transaction (create, sign, and submit)
261
- */
262
- sendTransaction(params: SendTransactionRequest): Promise<AddTxResponse>;
263
- sendTransactionByAddress(params: SendTransactionRequest): Promise<AddTxResponse>;
264
- sendTransactionByPrivateKey(params: SendTransactionBase): Promise<AddTxResponse>;
265
- /**
266
- * Get current nonce for an account
267
- */
268
- getCurrentNonce(userId: string, tag?: 'latest' | 'pending'): Promise<GetCurrentNonceResponse>;
269
- getAccountByUserId(userId: string): Promise<GetAccountByAddressResponse>;
270
- scaleAmountToDecimals(originalAmount: string | number, decimals?: number): string;
271
- validateAddress(addr: string): boolean;
272
- validateAmount(balance: string, amount: string | number): boolean;
273
- }
205
+ declare class MmnClient {
206
+ private config;
207
+ private requestId;
208
+ constructor(config: MmnClientConfig);
209
+ private makeRequest;
210
+ /**
211
+ * Securely convert raw Ed25519 private key to PKCS#8 format
212
+ * @param raw - Raw 32-byte Ed25519 private key
213
+ * @returns PKCS#8 formatted private key in hex
214
+ * @throws Error if input validation fails
215
+ */
216
+ private rawEd25519ToPkcs8Hex;
217
+ /**
218
+ * Encode length in ASN.1 DER format
219
+ * ASN.1 length encoding rules:
220
+ * - Short form (0-127): single byte with the length value
221
+ * - Long form (128+): first byte is 0x80 + number of length bytes, followed by length bytes
222
+ * @param length - The length value to encode
223
+ * @returns ASN.1 DER encoded length bytes
224
+ */
225
+ private encodeLength;
226
+ /**
227
+ * Generate secure entropy using multiple sources for maximum compatibility
228
+ * @returns Array of 32 random bytes
229
+ */
230
+ private generateSecureEntropy;
231
+ /**
232
+ * Securely generate ephemeral key pair with proper entropy
233
+ * React Native compatible version with multiple fallbacks
234
+ * @returns Ephemeral key pair with private and public keys
235
+ * @throws Error if key generation fails
236
+ */
237
+ generateEphemeralKeyPair(): IEphemeralKeyPair;
238
+ getAddressFromUserId(userId: string): string;
239
+ /**
240
+ * Create and sign a transaction message
241
+ */
242
+ private createAndSignTx;
243
+ /**
244
+ * Securely sign a transaction with Ed25519
245
+ * @param tx - Transaction message to sign
246
+ * @param privateKeyHex - Private key in PKCS#8 hex format
247
+ * @returns Base58 encoded signature
248
+ * @throws Error if signing fails
249
+ */
250
+ private signTransaction;
251
+ /**
252
+ * Serialize transaction for signing
253
+ */
254
+ private serializeTransaction;
255
+ /**
256
+ * Add a signed transaction to the blockchain
257
+ */
258
+ private addTx;
259
+ /**
260
+ * Send a transaction (create, sign, and submit)
261
+ */
262
+ sendTransaction(params: SendTransactionRequest): Promise<AddTxResponse>;
263
+ sendTransactionByAddress(params: SendTransactionRequest): Promise<AddTxResponse>;
264
+ sendTransactionByPrivateKey(params: SendTransactionBase): Promise<AddTxResponse>;
265
+ /**
266
+ * Get current nonce for an account
267
+ */
268
+ getCurrentNonce(userId: string, tag?: 'latest' | 'pending'): Promise<GetCurrentNonceResponse>;
269
+ getAccountByUserId(userId: string): Promise<GetAccountByAddressResponse>;
270
+ scaleAmountToDecimals(originalAmount: string | number, decimals?: number): string;
271
+ validateAddress(addr: string): boolean;
272
+ validateAmount(balance: string, amount: string | number): boolean;
273
+ }
274
274
  declare function createMmnClient(config: MmnClientConfig): MmnClient;
275
275
 
276
- declare class ZkClient {
277
- private endpoint;
278
- private timeout;
279
- private headers;
280
- constructor(config: ZkClientConfig);
281
- private makeRequest;
282
- getZkProofs({ userId, ephemeralPublicKey, jwt, address, clientType, }: GetZkProofRequest): Promise<IZkProof>;
276
+ declare class ZkClient {
277
+ private endpoint;
278
+ private timeout;
279
+ private headers;
280
+ constructor(config: ZkClientConfig);
281
+ private makeRequest;
282
+ getZkProofs({ userId, ephemeralPublicKey, jwt, address, clientType, }: GetZkProofRequest): Promise<IZkProof>;
283
283
  }
284
284
 
285
- export { ETransferType, EZkClientType, IndexerClient, MmnClient, ZkClient, createMmnClient };
286
- export type { AddTxResponse, ExtraInfo, GetAccountByAddressResponse, GetCurrentNonceResponse, GetZkProofRequest, IEphemeralKeyPair, IZkProof, IndexerClientConfig, JsonRpcError, JsonRpcRequest, JsonRpcResponse, ListTransactionResponse, Meta, MmnClientConfig, SendTransactionBase, SendTransactionRequest, SignedTx, Transaction, TransactionDetailResponse, TxMsg, WalletDetail, WalletDetailResponse, ZkClientConfig };
285
+ export { AddTxResponse, ETransferType, EZkClientType, ExtraInfo, GetAccountByAddressResponse, GetCurrentNonceResponse, GetZkProofRequest, IEphemeralKeyPair, IZkProof, IndexerClient, IndexerClientConfig, JsonRpcError, JsonRpcRequest, JsonRpcResponse, ListTransactionResponse, Meta, MmnClient, MmnClientConfig, SendTransactionBase, SendTransactionRequest, SignedTx, Transaction, TransactionDetailResponse, TxMsg, WalletDetail, WalletDetailResponse, ZkClient, ZkClientConfig, createMmnClient };