mmn-client-js 1.0.9 → 1.0.11

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