mirror of
https://github.com/PR0M3TH3AN/bitvid.git
synced 2026-10-27 16:02:26 +00:00
- NWC connection was fully broken: parseNwcUri passed a hex secret to nostr-tools getPublicKey (needs Uint8Array) and threw. Convert hex->bytes. - A successful zap was shown as a red error when the kind-9735 receipt couldn't be validated. The NWC preimage already proves payment, so a paid-but-unconfirmed share is now a success-with-note, not a failure. - Receipt discovery: query by the reliably-indexed #e/#a/#p tags instead of #bolt11 (which most relays don't index), and poll a few times since the receipt is published shortly after payment. - In-flight "Sending..." status no longer mis-toned as a warning; success path fully resets the form; an in-flight-open click no longer cancels the open (which made the popover need many clicks); fee fallback verified no-bypass. Co-Authored-By: Claude Opus 4.8 <[email protected]>
48 lines
1.9 KiB
JavaScript
48 lines
1.9 KiB
JavaScript
// Real-tools regression test for the NWC URI parse fix. Unlike nwc-client.test.mjs
|
|
// (which mocks nostr-tools and is currently shadowed by the frozen canonical
|
|
// toolkit the bootstrap installs), this runs against the real nostr-tools — which
|
|
// is exactly the environment the production bug occurs in.
|
|
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
|
|
if (typeof globalThis.window === "undefined") {
|
|
globalThis.window = {};
|
|
}
|
|
|
|
const { __TESTING__ } = await import("../js/payments/nwcClient.js");
|
|
const { parseNwcUri } = __TESTING__;
|
|
|
|
test("parseNwcUri derives clientPubkey from a hex secret without throwing", () => {
|
|
// Regression (#3 NWC): nostr-tools >= 2.x getPublicKey requires a Uint8Array,
|
|
// not a hex string. parseNwcUri passed the hex secret directly, so it threw
|
|
// "expected Uint8Array, got type=string" and NWC wallet connection failed
|
|
// entirely (the only zap payment path). The fix converts hex -> bytes.
|
|
const walletPubkey = "b".repeat(64);
|
|
const secretKey = "a".repeat(64); // a valid secp256k1 scalar (0 < k < n)
|
|
const relay = "wss://relay.example";
|
|
const uri =
|
|
`nostr+walletconnect://${walletPubkey}` +
|
|
`?relay=${encodeURIComponent(relay)}` +
|
|
`&secret=${secretKey}`;
|
|
|
|
const parsed = parseNwcUri(uri);
|
|
|
|
assert.equal(parsed.secretKey, secretKey);
|
|
assert.equal(parsed.walletPubkey, walletPubkey);
|
|
assert.deepEqual(parsed.relays, [relay]);
|
|
assert.match(
|
|
parsed.clientPubkey,
|
|
/^[0-9a-f]{64}$/,
|
|
"clientPubkey must be derived as 64-char hex (getPublicKey accepted the secret)",
|
|
);
|
|
});
|
|
|
|
test("parseNwcUri rejects a non-hex / wrong-length secret", () => {
|
|
const walletPubkey = "b".repeat(64);
|
|
const uri =
|
|
`nostr+walletconnect://${walletPubkey}` +
|
|
`?relay=${encodeURIComponent("wss://relay.example")}` +
|
|
`&secret=not-a-valid-secret`;
|
|
assert.throws(() => parseNwcUri(uri), /secret must be a 64 character hex string/i);
|
|
});
|