mmn-client-js 1.0.9 → 1.0.10

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