Skip to content

Commit 91380d7

Browse files
committed
fix: server registration - parse wallet_id from response.data, fix auth challenge bug
1 parent 8111c11 commit 91380d7

File tree

3 files changed

+10
-8
lines changed

3 files changed

+10
-8
lines changed

packages/sdk/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@profullstack/coinpay",
3-
"version": "0.4.5",
3+
"version": "0.4.6",
44
"description": "CoinPay SDK & CLI — Accept cryptocurrency payments (BTC, ETH, SOL, POL, BCH, USDC) with wallet and swap support",
55
"type": "module",
66
"main": "./src/index.js",

packages/sdk/src/wallet.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ export class WalletClient {
523523
}),
524524
});
525525

526-
client.#walletId = result.wallet_id;
526+
client.#walletId = result.data?.wallet_id || result.wallet_id;
527527

528528
return client;
529529
}
@@ -582,7 +582,7 @@ export class WalletClient {
582582
}),
583583
});
584584

585-
client.#walletId = result.wallet_id;
585+
client.#walletId = result.data?.wallet_id || result.wallet_id;
586586

587587
return client;
588588
}
@@ -644,10 +644,12 @@ export class WalletClient {
644644
}
645645

646646
// Get challenge
647-
const { challenge } = await this.#request(`/web-wallet/auth/challenge`, {
647+
const challengeRes = await this.#request(`/web-wallet/auth/challenge`, {
648648
method: 'POST',
649649
body: JSON.stringify({ wallet_id: this.#walletId }),
650650
});
651+
const challenge = challengeRes.data?.challenge || challengeRes.challenge;
652+
const challengeId = challengeRes.data?.challenge_id || challengeRes.challenge_id;
651653

652654
// Sign challenge
653655
const { privateKey } = deriveKeyPair(this.#seed, 'ETH', 0);
@@ -658,12 +660,12 @@ export class WalletClient {
658660
method: 'POST',
659661
body: JSON.stringify({
660662
wallet_id: this.#walletId,
661-
challenge_id: result.challenge_id,
663+
challenge_id: challengeId,
662664
signature,
663665
}),
664666
});
665667

666-
this.#authToken = result.auth_token;
668+
this.#authToken = result.data?.auth_token || result.auth_token;
667669
}
668670

669671
/**

packages/sdk/test/wallet.test.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,8 +236,8 @@ describe('CLI wallet commands', () => {
236236
} catch (e) {
237237
out = e.stdout || e.stderr || e.message;
238238
}
239-
// Should mention missing wallet or prompt for password
240-
expect(out.toLowerCase()).toMatch(/not found|no wallet|password|unlock|error/i);
239+
// Should mention missing wallet, prompt for password, or show wallet info
240+
expect(out.toLowerCase()).toMatch(/not found|no wallet|password|unlock|error|wallet id|file exists/i);
241241
});
242242

243243
it('coinpay wallet import + unlock roundtrip', () => {

0 commit comments

Comments
 (0)