diff --git a/packages/core/src/dapp-relay.ts b/packages/core/src/dapp-relay.ts index 9dc92ce..aa3b836 100644 --- a/packages/core/src/dapp-relay.ts +++ b/packages/core/src/dapp-relay.ts @@ -30,6 +30,7 @@ export interface DappRelayOptions { existingCredentials?: { privateKey: string; secret: string; + walletPublicKey: string; }; } @@ -104,6 +105,13 @@ export function initiateDappRelay( let keyExchanged = false; let walletPublicKeyNostr: Uint8Array | null = null; + if (options.existingCredentials) { + walletPublicKeyNostr = hexToBin( + options.existingCredentials.walletPublicKey, + ); + keyExchanged = true; + } + const wrappedCallback: RelayStatusCallback = ( payload: RelayUpdatePayload, ) => { diff --git a/packages/test-cli/src/cli.ts b/packages/test-cli/src/cli.ts index 05e82e3..a96ce17 100644 --- a/packages/test-cli/src/cli.ts +++ b/packages/test-cli/src/cli.ts @@ -29,6 +29,10 @@ program "Existing dapp private key (64 hex chars) — for reconnection testing", ) .option("--secret ", "Existing secret (hex) — for reconnection testing") + .option( + "--wallet-public-key ", + "Wallet's Nostr public key (hex) — for reconnection testing", + ) .option( "--sign", "Send a dummy sign request after wallet is ready (tests approval flow)", diff --git a/packages/test-cli/src/dapp.ts b/packages/test-cli/src/dapp.ts index 8f19377..ca1ba40 100644 --- a/packages/test-cli/src/dapp.ts +++ b/packages/test-cli/src/dapp.ts @@ -180,6 +180,7 @@ export async function runDappMode(options: { relay: string; privateKey?: string; secret?: string; + walletPublicKey?: string; sign?: boolean; }): Promise { const state = makeState(); @@ -217,8 +218,12 @@ export async function runDappMode(options: { { explicitRelayUrls: [options.relay], existingCredentials: - options.privateKey && options.secret - ? { privateKey: options.privateKey, secret: options.secret } + options.privateKey && options.secret && options.walletPublicKey + ? { + privateKey: options.privateKey, + secret: options.secret, + walletPublicKey: options.walletPublicKey, + } : undefined, }, ); @@ -234,19 +239,11 @@ export async function runDappMode(options: { encodeURIComponent(dappRelay.uri), ), ); - if (options.privateKey) { - console.log( - chalk.dim( - `\nReconnect:\n wiz-test dapp --private-key ${options.privateKey} --secret ${dappRelay.credentials.secret}`, - ), - ); - } else { - console.log( - chalk.dim( - `\nReconnect:\n wiz-test dapp --private-key ${dappRelay.credentials.privateKey} --secret ${dappRelay.credentials.secret}`, - ), - ); - } + console.log( + chalk.dim( + `\nReconnect (after key exchange):\n wiz-test dapp --private-key ${options.privateKey ?? dappRelay.credentials.privateKey} --secret ${dappRelay.credentials.secret} --wallet-public-key `, + ), + ); console.log(); const keySpinner = ora("Waiting for wallet to connect...").start();