|
|
|
|
@@ -2843,6 +2843,15 @@ async function publishDirectProofs(debugContext = null) {
|
|
|
|
|
}
|
|
|
|
|
log('delete old 7375 done');
|
|
|
|
|
|
|
|
|
|
// Ensure a nutzap privkey exists before building the wallet payload.
|
|
|
|
|
// If the user's old 17375 didn't have one (or hydration failed),
|
|
|
|
|
// this auto-generates one so it's always included in the republish.
|
|
|
|
|
try {
|
|
|
|
|
ensureDirectNutzapP2pk();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
log('ensureDirectNutzapP2pk failed during publish', { error: err?.message || String(err) });
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// NIP-60 standard: public "mint" tags are visible on the event;
|
|
|
|
|
// the privkey lives in the encrypted content as a "privkey" tag.
|
|
|
|
|
// The "pubkey" tag does NOT belong on kind 17375 (it belongs on
|
|
|
|
|
@@ -4304,6 +4313,16 @@ async function handleWalletCheckProofs(requestId, port) {
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Lightweight republish of ONLY the kind 17375 wallet event.
|
|
|
|
|
*
|
|
|
|
|
* Kind 17375 is a replaceable event (NIP-60, d-tag = ""), so publishing a
|
|
|
|
|
* new one automatically supersedes the old one on relays — no NIP-09
|
|
|
|
|
* deletions needed. This skips the heavy publishDirectProofs() which
|
|
|
|
|
* rewrites all 7375 token events too (100+ signing round-trips).
|
|
|
|
|
*
|
|
|
|
|
* Just: ensure privkey → build tag-array payload → encrypt → sign → publish.
|
|
|
|
|
*/
|
|
|
|
|
async function handleWalletRepublish(requestId, port) {
|
|
|
|
|
try {
|
|
|
|
|
if (!ndk || !currentPubkey) {
|
|
|
|
|
@@ -4311,7 +4330,63 @@ async function handleWalletRepublish(requestId, port) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
await ensureDirectWalletLoaded();
|
|
|
|
|
await publishDirectProofs({ traceId: 'walletRepublish' });
|
|
|
|
|
|
|
|
|
|
// Ensure a nutzap privkey exists (auto-generate if missing)
|
|
|
|
|
try {
|
|
|
|
|
ensureDirectNutzapP2pk();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.warn('[Worker] handleWalletRepublish: ensureDirectNutzapP2pk failed:', err?.message || err);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const NDKEvent = getNDKEventCtor();
|
|
|
|
|
if (!NDKEvent) {
|
|
|
|
|
port.postMessage({ type: 'response', requestId, error: 'NDKEvent constructor not available' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build NIP-60 tag-array payload: [["mint",url],["privkey",hex]]
|
|
|
|
|
const mintTags = getDirectWalletMints().map((mintUrl) => ['mint', mintUrl]);
|
|
|
|
|
const walletPayloadObj = [
|
|
|
|
|
...getDirectWalletMints().map((url) => ['mint', url]),
|
|
|
|
|
...(directNutzapPrivateKeyHex ? [['privkey', directNutzapPrivateKeyHex]] : [])
|
|
|
|
|
];
|
|
|
|
|
const walletPayload = JSON.stringify(walletPayloadObj);
|
|
|
|
|
|
|
|
|
|
// NIP-44 encrypt the payload
|
|
|
|
|
const encryptedWalletResp = await messageSigner.requestFromPage('nip44Encrypt', {
|
|
|
|
|
recipientPubkey: currentPubkey,
|
|
|
|
|
plaintext: walletPayload
|
|
|
|
|
});
|
|
|
|
|
const encryptedWallet = typeof encryptedWalletResp === 'string' ? encryptedWalletResp : encryptedWalletResp?.ciphertext;
|
|
|
|
|
|
|
|
|
|
if (!encryptedWallet) {
|
|
|
|
|
port.postMessage({ type: 'response', requestId, error: 'Failed to encrypt wallet payload' });
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Build and publish the new 17375 event (replaceable — supersedes old one)
|
|
|
|
|
const walletEvent = new NDKEvent(ndk, {
|
|
|
|
|
kind: 17375,
|
|
|
|
|
tags: mintTags,
|
|
|
|
|
content: encryptedWallet,
|
|
|
|
|
created_at: Math.floor(Date.now() / 1000)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
await signEventWithMessageSigner(walletEvent);
|
|
|
|
|
const relaySet = await walletEvent.publish();
|
|
|
|
|
|
|
|
|
|
if (relaySet && relaySet.size > 0) {
|
|
|
|
|
for (const relay of relaySet) {
|
|
|
|
|
trackRelayWrite(relay.url);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
console.log('[Worker] handleWalletRepublish: 17375 published', {
|
|
|
|
|
relayCount: relaySet ? relaySet.size : 0,
|
|
|
|
|
mintCount: mintTags.length,
|
|
|
|
|
hasPrivkey: Boolean(directNutzapPrivateKeyHex)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const payload = getWalletBalancePayload();
|
|
|
|
|
port.postMessage({
|
|
|
|
|
type: 'response',
|
|
|
|
|
@@ -4319,6 +4394,7 @@ async function handleWalletRepublish(requestId, port) {
|
|
|
|
|
data: {
|
|
|
|
|
success: true,
|
|
|
|
|
mints: getDirectWalletMints(),
|
|
|
|
|
relayCount: relaySet ? relaySet.size : 0,
|
|
|
|
|
...payload
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|