From 6db5d8eb74f59731c391108c87ab2b4a2d7e7c1f Mon Sep 17 00:00:00 2001 From: Simon Chan <1330321+yume-chan@users.noreply.github.com> Date: Mon, 29 Sep 2025 13:25:19 +0800 Subject: [PATCH] feat(credential): expose key name for varies password-related operations --- .../adb-credential-web/src/storage/password.ts | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/libraries/adb-credential-web/src/storage/password.ts b/libraries/adb-credential-web/src/storage/password.ts index 42069f3c..e8431798 100644 --- a/libraries/adb-credential-web/src/storage/password.ts +++ b/libraries/adb-credential-web/src/storage/password.ts @@ -55,8 +55,14 @@ async function deriveAesKey(password: string, salt?: Uint8Array) { } class PasswordIncorrectError extends Error { - constructor() { + #keyName: string | undefined; + get keyName() { + return this.#keyName; + } + + constructor(keyName: string | undefined) { super("Password incorrect"); + this.#keyName = keyName; } } @@ -78,7 +84,7 @@ export class TangoPasswordProtectedStorage implements TangoKeyStorage { privateKey: Uint8Array, name: string | undefined, ): Promise { - const password = await this.#requestPassword("save"); + const password = await this.#requestPassword("save", name); const { salt, aesKey } = await deriveAesKey(password); const iv = new Uint8Array(AesIvLength); @@ -118,7 +124,7 @@ export class TangoPasswordProtectedStorage implements TangoKeyStorage { new Uint8ArrayExactReadable(serialized), ); - const password = await this.#requestPassword("load"); + const password = await this.#requestPassword("load", name); const { aesKey } = await deriveAesKey( password, bundle.pbkdf2Salt as Uint8Array, @@ -147,7 +153,7 @@ export class TangoPasswordProtectedStorage implements TangoKeyStorage { } } catch (e) { if (e instanceof DOMException && e.name === "OperationError") { - yield new PasswordIncorrectError(); + yield new PasswordIncorrectError(name); continue; } @@ -162,6 +168,7 @@ export class TangoPasswordProtectedStorage implements TangoKeyStorage { export namespace TangoPasswordProtectedStorage { export type RequestPassword = ( reason: "save" | "load", + name: string | undefined, ) => MaybePromiseLike; export type PasswordIncorrectError = typeof PasswordIncorrectError;