mmn-client-js 1.0.15 → 1.0.16

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
@@ -163,6 +163,11 @@ interface IndexerClientConfig {
163
163
  timeout?: number;
164
164
  headers?: Record<string, string>;
165
165
  }
166
+ interface DongClientConfig {
167
+ endpoint: string;
168
+ timeout?: number;
169
+ headers?: Record<string, string>;
170
+ }
166
171
  interface ZkClientConfig {
167
172
  endpoint: string;
168
173
  timeout?: number;
@@ -183,6 +188,25 @@ interface IZkProof {
183
188
  proof: string;
184
189
  public_input: string;
185
190
  }
191
+ interface ClaimRedEnvelopeQRRequest {
192
+ id: string;
193
+ user_id: string;
194
+ proof_b64: string;
195
+ public_b64: string;
196
+ publickey: string;
197
+ }
198
+ interface ClaimRedEnvelopeQRResponse {
199
+ split_money_id: number;
200
+ amount: number;
201
+ description: string;
202
+ }
203
+ interface ExecuteClaimRedEnvelopeQRRequest {
204
+ split_money_id: number;
205
+ user_id: string;
206
+ proof_b64: string;
207
+ public_b64: string;
208
+ publickey: string;
209
+ }
186
210
 
187
211
  declare class IndexerClient {
188
212
  private endpoint;
@@ -288,5 +312,15 @@ declare class ZkClient {
288
312
  getZkProofs({ userId, ephemeralPublicKey, jwt, address, clientType, }: GetZkProofRequest): Promise<IZkProof>;
289
313
  }
290
314
 
291
- export { ETransferType, EZkClientType, IndexerClient, MmnClient, ZkClient, createMmnClient };
292
- 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 };
315
+ declare class DongClient {
316
+ private endpoint;
317
+ private timeout;
318
+ private headers;
319
+ constructor(config: DongClientConfig);
320
+ private makeRequest;
321
+ claimAmountRedEnvelopeQR(params: ClaimRedEnvelopeQRRequest): Promise<ClaimRedEnvelopeQRResponse>;
322
+ claimRedEnvelopeQR(id: string, params: ExecuteClaimRedEnvelopeQRRequest): Promise<void>;
323
+ }
324
+
325
+ export { DongClient, ETransferType, EZkClientType, IndexerClient, MmnClient, ZkClient, createMmnClient };
326
+ export type { AddTxResponse, ClaimRedEnvelopeQRRequest, ClaimRedEnvelopeQRResponse, DongClientConfig, ExecuteClaimRedEnvelopeQRRequest, ExtraInfo, GetAccountByAddressResponse, GetCurrentNonceResponse, GetZkProofRequest, IEphemeralKeyPair, IZkProof, IndexerClientConfig, JsonRpcError, JsonRpcRequest, JsonRpcResponse, ListTransactionResponse, Meta, MmnClientConfig, SendTransactionBase, SendTransactionRequest, SignedTx, Transaction, TransactionDetailResponse, TxMsg, WalletDetail, WalletDetailResponse, ZkClientConfig };
package/dist/index.esm.js CHANGED
@@ -8207,5 +8207,79 @@ class ZkClient {
8207
8207
  }
8208
8208
  }
8209
8209
 
8210
- export { ETransferType, EZkClientType, IndexerClient, MmnClient, ZkClient, createMmnClient };
8210
+ class DongClient {
8211
+ constructor(config) {
8212
+ this.endpoint = config.endpoint;
8213
+ this.timeout = config.timeout || 30000;
8214
+ this.headers = {
8215
+ Accept: 'application/json',
8216
+ 'Content-Type': 'application/json',
8217
+ ...(config.headers || {}),
8218
+ };
8219
+ }
8220
+ async makeRequest(method, path, params, body) {
8221
+ let url = `${this.endpoint}/${path}`;
8222
+ if (params && Object.keys(params).length > 0) {
8223
+ const searchParams = new URLSearchParams();
8224
+ Object.entries(params).forEach(([key, value]) => {
8225
+ searchParams.append(key, String(value));
8226
+ });
8227
+ url += `?${searchParams.toString()}`;
8228
+ }
8229
+ const controller = new AbortController();
8230
+ const timeoutId = setTimeout(() => controller.abort(), this.timeout);
8231
+ try {
8232
+ const requestOptions = {
8233
+ method,
8234
+ mode: 'cors',
8235
+ credentials: 'omit',
8236
+ signal: controller.signal,
8237
+ headers: {
8238
+ Accept: 'application/json',
8239
+ ...this.headers,
8240
+ },
8241
+ };
8242
+ if (method === 'POST' && body) {
8243
+ requestOptions.body = JSON.stringify(body);
8244
+ requestOptions.headers['Content-Type'] =
8245
+ 'application/json';
8246
+ }
8247
+ const response = await fetch(url, requestOptions);
8248
+ clearTimeout(timeoutId);
8249
+ if (!response.ok) {
8250
+ throw new Error(`HTTP ${response.status}: ${response.statusText}`);
8251
+ }
8252
+ const json = await response.json();
8253
+ return json.data;
8254
+ }
8255
+ catch (error) {
8256
+ clearTimeout(timeoutId);
8257
+ if (error instanceof Error) {
8258
+ if (error.name === 'AbortError') {
8259
+ throw new Error(`Request timeout after ${this.timeout}ms`);
8260
+ }
8261
+ throw error;
8262
+ }
8263
+ throw new Error('Request failed');
8264
+ }
8265
+ }
8266
+ // --- Red Envelope QR APIs ---
8267
+ async claimAmountRedEnvelopeQR(params) {
8268
+ const path = `api/v1/red-envelopes/qr/claim-amount`;
8269
+ const body = {
8270
+ user_id: params.user_id,
8271
+ proof_b64: params.proof_b64,
8272
+ public_b64: params.public_b64,
8273
+ publickey: params.publickey,
8274
+ };
8275
+ const queryParams = { id: params.id };
8276
+ return this.makeRequest('POST', path, queryParams, body);
8277
+ }
8278
+ async claimRedEnvelopeQR(id, params) {
8279
+ const path = `api/v1/red-envelopes/qr/${id}/claim`;
8280
+ await this.makeRequest('POST', path, undefined, params);
8281
+ }
8282
+ }
8283
+
8284
+ export { DongClient, ETransferType, EZkClientType, IndexerClient, MmnClient, ZkClient, createMmnClient };
8211
8285
  //# sourceMappingURL=index.esm.js.map