mmn-client-js 1.0.0 → 1.0.2

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/README.md CHANGED
@@ -1,85 +1,218 @@
1
- # @mezon/mmn-client-js
1
+ # mmn-client-js
2
2
 
3
- A TypeScript client for interacting with the MMN blockchain via JSON-RPC. It supports creating, signing, and submitting transactions, plus basic account and transaction queries.
3
+ A comprehensive TypeScript client for interacting with the MMN blockchain ecosystem. It provides complete functionality for blockchain transactions, account management, indexer queries, and ZK proof generation.
4
4
 
5
5
  ## Features
6
6
 
7
- - 🔐 Transaction signing (Ed25519)
8
- - 📝 Create and sign transactions
9
- - 🚀 JSON-RPC client for MMN
10
- - 📦 TypeScript with exported types
11
- - 🌐 Browser & Node.js compatible
7
+ - 🔐 **Transaction signing** (Ed25519 with NaCl)
8
+ - 📝 **Complete transaction lifecycle** (create, sign, submit)
9
+ - 🚀 **JSON-RPC client** for MMN blockchain
10
+ - 📊 **Indexer client** for transaction history and wallet details
11
+ - **ZK proof generation** for privacy-preserving authentication
12
+ - 💰 **Wallet management** with BIP39 mnemonic support
13
+ - 🎯 **User ID to address conversion** with SHA256 hashing
14
+ - �📦 **Full TypeScript support** with exported types
15
+ - 🌐 **Cross-platform** (Browser & Node.js compatible)
12
16
 
13
17
  ## Installation
14
18
 
15
19
  ```bash
16
- npm install @mezonai/mmn-client-js
20
+ npm install mmn-client-js
21
+ ```
22
+
23
+ Or using yarn:
24
+
25
+ ```bash
26
+ yarn add mmn-client-js
17
27
  ```
18
28
 
19
29
  ## Quick Start
20
30
 
31
+ ### Basic MMN Client Usage
32
+
21
33
  ```typescript
22
- import { MmnClient } from '@mezonai/mmn-client-js';
34
+ import { MmnClient, IndexerClient, ZkClient } from 'mmn-client-js';
23
35
 
24
- // Create a client instance
25
- const client = new MmnClient({
36
+ // Create MMN client for blockchain operations
37
+ const mmnClient = new MmnClient({
26
38
  baseUrl: 'http://localhost:8080',
27
- timeout: 30000
39
+ timeout: 30000,
28
40
  });
29
41
 
42
+ // Generate ephemeral key pair for ZK authentication
43
+ const keyPair = mmnClient.generateEphemeralKeyPair();
44
+ console.log('Public Key:', keyPair.publicKey);
45
+
46
+ // Convert user ID to blockchain address
47
+ const senderAddress = mmnClient.getAddressFromUserId('user123');
48
+ const recipientAddress = mmnClient.getAddressFromUserId('user456');
49
+
50
+ // Get current nonce for sender
51
+ const nonceResponse = await mmnClient.getCurrentNonce(senderAddress);
52
+ const currentNonce = nonceResponse.nonce;
53
+
54
+ // Get account information by user ID
55
+ const account = await mmnClient.getAccountByUserId('user123');
56
+ console.log('Balance:', account.balance);
57
+
30
58
  // Send a transaction
31
- const response = await client.sendTransaction({
32
- sender: 'sender-address',
33
- recipient: 'recipient-address',
59
+ const response = await mmnClient.sendTransaction({
60
+ sender: 'user123',
61
+ recipient: 'user456',
34
62
  amount: '1000000000000000000',
63
+ nonce: currentNonce + 1,
35
64
  textData: 'Hello MMN!',
36
- privateKey: 'private-key-hex'
65
+ publicKey: keyPair.publicKey,
66
+ privateKey: keyPair.privateKey,
67
+ zkProof: 'zk-proof-string',
68
+ zkPub: 'zk-public-string',
37
69
  });
38
70
 
39
71
  if (response.ok) {
40
72
  console.log('Transaction Hash:', response.tx_hash);
41
73
  } else {
42
- console.error('Error:', response.error);
74
+ console.error('Transaction failed:', response.error);
43
75
  }
44
76
  ```
45
77
 
78
+ ### Indexer Client Usage
79
+
80
+ ```typescript
81
+ // Create indexer client for transaction history
82
+ const indexerClient = new IndexerClient({
83
+ endpoint: 'https://indexer.mmn.network',
84
+ chainId: 'mmn-mainnet',
85
+ });
86
+
87
+ // Get transaction history for a wallet
88
+ const transactions = await indexerClient.getTransactionByWallet(
89
+ 'wallet-address',
90
+ 1, // page
91
+ 50, // limit
92
+ 0 // filter: 0=all, 1=received, 2=sent
93
+ );
94
+
95
+ // Get specific transaction details
96
+ const tx = await indexerClient.getTransactionByHash('tx-hash');
97
+
98
+ // Get wallet details
99
+ const walletInfo = await indexerClient.getWalletDetail('wallet-address');
100
+ ```
101
+
102
+ ### ZK Proof Client Usage
103
+
104
+ ```typescript
105
+ // Create ZK client for proof generation
106
+ const zkClient = new ZkClient({
107
+ endpoint: 'https://zk.mmn.network',
108
+ chainId: 'mmn-mainnet',
109
+ });
110
+
111
+ // Generate ZK proof for authentication
112
+ const zkProof = await zkClient.getZkProofs({
113
+ userId: 'user123',
114
+ ephemeralPublicKey: keyPair.publicKey,
115
+ jwt: 'jwt-token',
116
+ address: 'wallet-address',
117
+ });
118
+ ```
119
+
46
120
  ## API Reference
47
121
 
48
- ### Client Configuration
122
+ ### MMN Client Configuration
49
123
 
50
124
  ```typescript
51
125
  interface MmnClientConfig {
52
- baseUrl: string; // MMN JSON-RPC base URL
53
- timeout?: number; // Request timeout in ms (default: 30000)
54
- headers?: Record<string, string>; // Additional headers
55
- axiosConfig?: AxiosRequestConfig; // Optional axios overrides
126
+ baseUrl: string; // MMN JSON-RPC base URL
127
+ timeout?: number; // Request timeout in ms (default: 30000)
128
+ headers?: Record<string, string>; // Additional headers
129
+ axiosConfig?: AxiosRequestConfig; // Optional axios overrides
56
130
  }
57
131
  ```
58
132
 
59
- ### Transaction Signing
133
+ ### Indexer Client Configuration
60
134
 
61
- The client signs transactions with Ed25519. Provide a 64‑byte secret key or a 32‑byte seed (as `Uint8Array` or string hex/base58).
135
+ ```typescript
136
+ interface IndexerClientConfig {
137
+ endpoint: string; // Indexer API endpoint
138
+ chainId: string; // Blockchain chain ID
139
+ timeout?: number; // Request timeout in ms (default: 30000)
140
+ headers?: Record<string, string>; // Additional headers
141
+ }
142
+ ```
143
+
144
+ ### Core Methods
145
+
146
+ #### MMN Client Methods
147
+
148
+ **`generateEphemeralKeyPair(): IEphemeralKeyPair`**
149
+ Generate a new Ed25519 key pair using BIP39 mnemonic.
62
150
 
63
- ### Transaction Operations
151
+ ```typescript
152
+ const keyPair = client.generateEphemeralKeyPair();
153
+ // Returns: { privateKey: string, publicKey: string }
154
+ ```
155
+
156
+ **`getAddressFromUserId(userId: string): string`**
157
+ Convert user ID to blockchain address using SHA256 + Base58.
158
+
159
+ ```typescript
160
+ const address = client.getAddressFromUserId('user123');
161
+ ```
64
162
 
65
- #### `sendTransaction(params): Promise<AddTxResponse>`
66
- Create, sign, and submit a transaction in one call.
163
+ **`sendTransaction(params): Promise<AddTxResponse>`**
164
+ Create, sign, and submit a transaction.
67
165
 
68
166
  ```typescript
69
167
  const response = await client.sendTransaction({
70
- sender: 'sender-address',
71
- recipient: 'recipient-address',
168
+ sender: 'user123',
169
+ recipient: 'user456',
72
170
  amount: '1000000000000000000',
73
- nonce,
171
+ nonce: 1,
74
172
  textData: 'Optional message',
75
- extraInfo: 'Optional extra',
76
- privateKey: new Uint8Array(/* 64-byte secretKey */)
173
+ extraInfo: { type: 'transfer_token', UserSenderId: 'user123', ... },
174
+ publicKey: 'public-key-base58',
175
+ privateKey: 'private-key-pkcs8-hex',
176
+ zkProof: 'zk-proof-string',
177
+ zkPub: 'zk-public-string'
77
178
  });
78
179
  ```
79
180
 
80
- ## License
181
+ **`getCurrentNonce(address: string, tag?: 'latest' | 'pending'): Promise<GetCurrentNonceResponse>`**
182
+ Get current nonce for an account.
81
183
 
82
- MIT
184
+ **`getAccountByUserId(userId: string): Promise<GetAccountByAddressResponse>`**
185
+ Get account details by user ID.
186
+
187
+ **`scaleAmountToDecimals(amount: string | number, decimals: number): string`**
188
+ Scale amount to blockchain decimals.
189
+
190
+ #### Indexer Client Methods
191
+
192
+ **`getTransactionByHash(hash: string): Promise<Transaction>`**
193
+ Get transaction details by hash.
194
+
195
+ **`getTransactionByWallet(wallet: string, page: number, limit: number, filter: number): Promise<ListTransactionResponse>`**
196
+ Get transaction history for a wallet.
197
+
198
+ - `filter`: 0=all, 1=received, 2=sent
199
+
200
+ **`getWalletDetail(wallet: string): Promise<WalletDetail>`**
201
+ Get wallet balance and account information.
202
+
203
+ #### ZK Client Methods
204
+
205
+ **`getZkProofs(params): Promise<IZkProof>`**
206
+ Generate ZK proof for authentication.
207
+
208
+ ```typescript
209
+ const zkProof = await zkClient.getZkProofs({
210
+ userId: 'user123',
211
+ ephemeralPublicKey: 'ephemeral-public-key',
212
+ jwt: 'jwt-token',
213
+ address: 'wallet-address',
214
+ });
215
+ ```
83
216
 
84
217
  ## Contributing
85
218
 
package/dist/index.d.ts CHANGED
@@ -17,10 +17,13 @@ interface JsonRpcResponse<T = unknown> {
17
17
  error?: JsonRpcError;
18
18
  id: string | number;
19
19
  }
20
- interface IWallet {
21
- address: string;
20
+ interface IEphemeralKeyPair {
22
21
  privateKey: string;
23
- recoveryPhrase: string;
22
+ publicKey: string;
23
+ }
24
+ interface IZkProof {
25
+ proof: string;
26
+ public_input: string;
24
27
  }
25
28
  declare enum ETransferType {
26
29
  GiveCoffee = "give_coffee",
@@ -47,6 +50,8 @@ interface TxMsg {
47
50
  text_data: string;
48
51
  nonce: number;
49
52
  extra_info: string;
53
+ zk_proof: string;
54
+ zk_pub: string;
50
55
  }
51
56
  interface SignedTx {
52
57
  tx_msg: TxMsg;
@@ -110,6 +115,7 @@ interface Transaction {
110
115
  status?: number;
111
116
  transaction_timestamp: number;
112
117
  text_data: string;
118
+ extra_info: string;
113
119
  }
114
120
  interface Meta {
115
121
  chain_id: number;
@@ -144,6 +150,11 @@ interface IndexerClientConfig {
144
150
  timeout?: number;
145
151
  headers?: Record<string, string>;
146
152
  }
153
+ interface ZkClientConfig {
154
+ endpoint: string;
155
+ timeout?: number;
156
+ headers?: Record<string, string>;
157
+ }
147
158
 
148
159
  declare class IndexerClient {
149
160
  private axiosInstance;
@@ -163,7 +174,8 @@ declare class MmnClient {
163
174
  constructor(config: MmnClientConfig);
164
175
  private makeRequest;
165
176
  private rawEd25519ToPkcs8Hex;
166
- createWallet(): IWallet;
177
+ generateEphemeralKeyPair(): IEphemeralKeyPair;
178
+ getAddressFromUserId(userId: string): string;
167
179
  /**
168
180
  * Create and sign a transaction message
169
181
  */
@@ -191,16 +203,32 @@ declare class MmnClient {
191
203
  timestamp?: number;
192
204
  textData?: string;
193
205
  extraInfo?: ExtraInfo;
206
+ publicKey: string;
194
207
  privateKey: string;
208
+ zkProof: string;
209
+ zkPub: string;
195
210
  }): Promise<AddTxResponse>;
196
211
  /**
197
212
  * Get current nonce for an account
198
213
  */
199
214
  getCurrentNonce(address: string, tag?: 'latest' | 'pending'): Promise<GetCurrentNonceResponse>;
200
- getAccountByAddress(address: string): Promise<GetAccountByAddressResponse>;
215
+ getAccountByUserId(userId: string): Promise<GetAccountByAddressResponse>;
201
216
  scaleAmountToDecimals(originalAmount: string | number, decimals: number): string;
202
217
  }
203
218
  declare function createMmnClient(config: MmnClientConfig): MmnClient;
204
219
 
205
- export { ETransferType, IndexerClient, MmnClient, createMmnClient };
206
- export type { AddTxResponse, ExtraInfo, GetAccountByAddressResponse, GetCurrentNonceResponse, IWallet, IndexerClientConfig, JsonRpcError, JsonRpcRequest, JsonRpcResponse, ListTransactionResponse, Meta, MmnClientConfig, SignedTx, Transaction, TransactionDetailResponse, TxMsg, WalletDetail, WalletDetailResponse };
220
+ declare class ZkClient {
221
+ private axiosInstance;
222
+ private endpoint;
223
+ constructor(config: ZkClientConfig);
224
+ private makeRequest;
225
+ getZkProofs({ userId, ephemeralPublicKey, jwt, address, }: {
226
+ userId: string;
227
+ ephemeralPublicKey: string;
228
+ jwt: string;
229
+ address: string;
230
+ }): Promise<IZkProof>;
231
+ }
232
+
233
+ export { ETransferType, IndexerClient, MmnClient, ZkClient, createMmnClient };
234
+ export type { AddTxResponse, ExtraInfo, GetAccountByAddressResponse, GetCurrentNonceResponse, IEphemeralKeyPair, IZkProof, IndexerClientConfig, JsonRpcError, JsonRpcRequest, JsonRpcResponse, ListTransactionResponse, Meta, MmnClientConfig, SignedTx, Transaction, TransactionDetailResponse, TxMsg, WalletDetail, WalletDetailResponse, ZkClientConfig };