From fd945757be02df1b1ac734df2f0baf5fe729c3f5 Mon Sep 17 00:00:00 2001 From: fiatjaf Date: Wed, 24 Apr 2024 10:12:31 -0300 Subject: [PATCH] accept localSecretKey as a parameter on nip46.createAccount() fixes https://github.com/nbd-wtf/nostr-tools/issues/401 --- nip46.ts | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/nip46.ts b/nip46.ts index 96d1242..ae42c04 100644 --- a/nip46.ts +++ b/nip46.ts @@ -254,6 +254,8 @@ export class BunkerSigner { * @param username - The username for the account. * @param domain - The domain for the account. * @param email - The optional email for the account. + * @param localSecretKey - Optionally pass a local secret key that will be used to communicate with the bunker, + this will default to generating a random key. * @throws Error if the email is present but invalid. * @returns A Promise that resolves to the auth_url that the client should follow to create an account. */ @@ -263,11 +265,11 @@ export async function createAccount( username: string, domain: string, email?: string, + localSecretKey: Uint8Array = generateSecretKey() ): Promise { if (email && !EMAIL_REGEX.test(email)) throw new Error('Invalid email') - let sk = generateSecretKey() - let rpc = new BunkerSigner(sk, bunker.bunkerPointer, params) + let rpc = new BunkerSigner(localSecretKey, bunker.bunkerPointer, params) let pubkey = await rpc.sendRequest('create_account', [username, domain, email || ''])