Add wallet pubkey to existing session
We need to also know the wallets pubkey if dapp is to connect to an existing session.
This commit is contained in:
parent
0e54217929
commit
d3a1a36163
3 changed files with 24 additions and 15 deletions
|
|
@ -30,6 +30,7 @@ export interface DappRelayOptions {
|
||||||
existingCredentials?: {
|
existingCredentials?: {
|
||||||
privateKey: string;
|
privateKey: string;
|
||||||
secret: string;
|
secret: string;
|
||||||
|
walletPublicKey: string;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -104,6 +105,13 @@ export function initiateDappRelay(
|
||||||
let keyExchanged = false;
|
let keyExchanged = false;
|
||||||
let walletPublicKeyNostr: Uint8Array | null = null;
|
let walletPublicKeyNostr: Uint8Array | null = null;
|
||||||
|
|
||||||
|
if (options.existingCredentials) {
|
||||||
|
walletPublicKeyNostr = hexToBin(
|
||||||
|
options.existingCredentials.walletPublicKey,
|
||||||
|
);
|
||||||
|
keyExchanged = true;
|
||||||
|
}
|
||||||
|
|
||||||
const wrappedCallback: RelayStatusCallback = (
|
const wrappedCallback: RelayStatusCallback = (
|
||||||
payload: RelayUpdatePayload,
|
payload: RelayUpdatePayload,
|
||||||
) => {
|
) => {
|
||||||
|
|
|
||||||
|
|
@ -29,6 +29,10 @@ program
|
||||||
"Existing dapp private key (64 hex chars) — for reconnection testing",
|
"Existing dapp private key (64 hex chars) — for reconnection testing",
|
||||||
)
|
)
|
||||||
.option("--secret <hex>", "Existing secret (hex) — for reconnection testing")
|
.option("--secret <hex>", "Existing secret (hex) — for reconnection testing")
|
||||||
|
.option(
|
||||||
|
"--wallet-public-key <hex>",
|
||||||
|
"Wallet's Nostr public key (hex) — for reconnection testing",
|
||||||
|
)
|
||||||
.option(
|
.option(
|
||||||
"--sign",
|
"--sign",
|
||||||
"Send a dummy sign request after wallet is ready (tests approval flow)",
|
"Send a dummy sign request after wallet is ready (tests approval flow)",
|
||||||
|
|
|
||||||
|
|
@ -180,6 +180,7 @@ export async function runDappMode(options: {
|
||||||
relay: string;
|
relay: string;
|
||||||
privateKey?: string;
|
privateKey?: string;
|
||||||
secret?: string;
|
secret?: string;
|
||||||
|
walletPublicKey?: string;
|
||||||
sign?: boolean;
|
sign?: boolean;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
const state = makeState();
|
const state = makeState();
|
||||||
|
|
@ -217,8 +218,12 @@ export async function runDappMode(options: {
|
||||||
{
|
{
|
||||||
explicitRelayUrls: [options.relay],
|
explicitRelayUrls: [options.relay],
|
||||||
existingCredentials:
|
existingCredentials:
|
||||||
options.privateKey && options.secret
|
options.privateKey && options.secret && options.walletPublicKey
|
||||||
? { privateKey: options.privateKey, secret: options.secret }
|
? {
|
||||||
|
privateKey: options.privateKey,
|
||||||
|
secret: options.secret,
|
||||||
|
walletPublicKey: options.walletPublicKey,
|
||||||
|
}
|
||||||
: undefined,
|
: undefined,
|
||||||
},
|
},
|
||||||
);
|
);
|
||||||
|
|
@ -234,19 +239,11 @@ export async function runDappMode(options: {
|
||||||
encodeURIComponent(dappRelay.uri),
|
encodeURIComponent(dappRelay.uri),
|
||||||
),
|
),
|
||||||
);
|
);
|
||||||
if (options.privateKey) {
|
console.log(
|
||||||
console.log(
|
chalk.dim(
|
||||||
chalk.dim(
|
`\nReconnect (after key exchange):\n wiz-test dapp --private-key ${options.privateKey ?? dappRelay.credentials.privateKey} --secret ${dappRelay.credentials.secret} --wallet-public-key <WALLET_PUBKEY>`,
|
||||||
`\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();
|
console.log();
|
||||||
|
|
||||||
const keySpinner = ora("Waiting for wallet to connect...").start();
|
const keySpinner = ora("Waiting for wallet to connect...").start();
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue