@profullstack/coinpay 0.4.4 → 0.4.6

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.
Files changed (2) hide show
  1. package/package.json +1 -1
  2. package/src/wallet.js +17 -10
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@profullstack/coinpay",
3
- "version": "0.4.4",
3
+ "version": "0.4.6",
4
4
  "description": "CoinPay SDK & CLI — Accept cryptocurrency payments (BTC, ETH, SOL, POL, BCH, USDC) with wallet and swap support",
5
5
  "type": "module",
6
6
  "main": "./src/index.js",
package/src/wallet.js CHANGED
@@ -154,11 +154,11 @@ function deriveBCHAddress(compressedPubKey) {
154
154
  checksumInput.set(prefixData);
155
155
  checksumInput.set(payload5, prefixData.length);
156
156
  // Last 8 bytes are zeros for checksum calculation
157
- const polymod = cashAddrPolymod(checksumInput) ^ 1;
157
+ const polymod = cashAddrPolymod(checksumInput) ^ 1n;
158
158
 
159
159
  const checksum = new Uint8Array(8);
160
160
  for (let i = 0; i < 8; i++) {
161
- checksum[i] = (polymod >> (5 * (7 - i))) & 0x1f;
161
+ checksum[i] = Number((polymod >> BigInt(5 * (7 - i))) & 0x1fn);
162
162
  }
163
163
 
164
164
  let encoded = 'bitcoincash:';
@@ -210,7 +210,7 @@ function cashAddrPolymod(values) {
210
210
  }
211
211
  }
212
212
  }
213
- return Number(c);
213
+ return c;
214
214
  }
215
215
 
216
216
  /**
@@ -222,9 +222,14 @@ function deriveETHAddress(compressedPubKey) {
222
222
  const uncompressed = point.toRawBytes(false); // 65 bytes with 04 prefix
223
223
  // Keccak256 of the 64 bytes (without 04 prefix)
224
224
  const hash = keccak_256(uncompressed.slice(1));
225
- // Last 20 bytes
225
+ // Last 20 bytes — EIP-55 checksummed
226
226
  const addr = bytesToHex(hash.slice(12));
227
- return '0x' + addr;
227
+ const addrHash = bytesToHex(keccak_256(new TextEncoder().encode(addr)));
228
+ let checksummed = '';
229
+ for (let i = 0; i < addr.length; i++) {
230
+ checksummed += parseInt(addrHash[i], 16) >= 8 ? addr[i].toUpperCase() : addr[i];
231
+ }
232
+ return '0x' + checksummed;
228
233
  }
229
234
 
230
235
  /**
@@ -518,7 +523,7 @@ export class WalletClient {
518
523
  }),
519
524
  });
520
525
 
521
- client.#walletId = result.wallet_id;
526
+ client.#walletId = result.data?.wallet_id || result.wallet_id;
522
527
 
523
528
  return client;
524
529
  }
@@ -577,7 +582,7 @@ export class WalletClient {
577
582
  }),
578
583
  });
579
584
 
580
- client.#walletId = result.wallet_id;
585
+ client.#walletId = result.data?.wallet_id || result.wallet_id;
581
586
 
582
587
  return client;
583
588
  }
@@ -639,10 +644,12 @@ export class WalletClient {
639
644
  }
640
645
 
641
646
  // Get challenge
642
- const { challenge } = await this.#request(`/web-wallet/auth/challenge`, {
647
+ const challengeRes = await this.#request(`/web-wallet/auth/challenge`, {
643
648
  method: 'POST',
644
649
  body: JSON.stringify({ wallet_id: this.#walletId }),
645
650
  });
651
+ const challenge = challengeRes.data?.challenge || challengeRes.challenge;
652
+ const challengeId = challengeRes.data?.challenge_id || challengeRes.challenge_id;
646
653
 
647
654
  // Sign challenge
648
655
  const { privateKey } = deriveKeyPair(this.#seed, 'ETH', 0);
@@ -653,12 +660,12 @@ export class WalletClient {
653
660
  method: 'POST',
654
661
  body: JSON.stringify({
655
662
  wallet_id: this.#walletId,
656
- challenge_id: result.challenge_id,
663
+ challenge_id: challengeId,
657
664
  signature,
658
665
  }),
659
666
  });
660
667
 
661
- this.#authToken = result.auth_token;
668
+ this.#authToken = result.data?.auth_token || result.auth_token;
662
669
  }
663
670
 
664
671
  /**