From: Chris Duncan Date: Tue, 15 Jul 2025 20:54:28 +0000 (-0700) Subject: Fix account lock and unlock. X-Git-Tag: v0.10.5~57^2~9 X-Git-Url: https://git.codecow.com/?a=commitdiff_plain;h=80926cfb9e6c19791b256440135005c889be8587;p=libnemo.git Fix account lock and unlock. --- diff --git a/src/lib/account.ts b/src/lib/account.ts index e9706f7..9f55252 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -163,15 +163,15 @@ export class Account { try { const headers = { method: 'set', - name: this.#pub, - id: this.#pub + name: this.#pub } const data = { - privateKey: this.#prv.buffer, - password: password.buffer + password: password.buffer, + id: hex.toBytes(this.#pub).buffer, + privateKey: this.#prv.buffer } const response = await SafeWorker.add(headers, data) - const success = response?.result[0] + const success = response[0].result if (!success) { throw null } @@ -238,12 +238,15 @@ export class Account { password: password.buffer } const response = await SafeWorker.add(headers, data) - const { id, privateKey } = response?.result[0] - if (id == null || id !== this.#pub) { + let { id, privateKey } = response[0].result + if (id == null) { + throw null + } + id = bytes.toHex(new Uint8Array(id)) + if (id !== this.publicKey) { throw null } - debugger - this.#prv.set(obj.toBytes(privateKey)) + this.#prv = new Uint8Array(privateKey as ArrayBuffer) } catch (err) { console.error(`Failed to unlock account ${this.address}`, err) return false diff --git a/test/test.lock-unlock.mjs b/test/test.lock-unlock.mjs index 9b980b9..f011431 100644 --- a/test/test.lock-unlock.mjs +++ b/test/test.lock-unlock.mjs @@ -60,7 +60,7 @@ await suite('Lock and unlock wallets', async () => { assert.equals(lockResult, true) assert.ok(account.isLocked) assert.ok('privateKey' in account) - assert.equals(account.privateKey, '0000000000000000000000000000000000000000000000000000000000000000') + assert.equals(account.privateKey, '') const unlockResult = await account.unlock(NANO_TEST_VECTORS.PASSWORD) @@ -211,7 +211,7 @@ await suite('Lock and unlock wallets', async () => { assert.equals(lockResult, true) assert.ok(account.isLocked) assert.ok('privateKey' in account) - assert.equals(account.privateKey, '0000000000000000000000000000000000000000000000000000000000000000') + assert.equals(account.privateKey, '') const unlockResult = await account.unlock(NANO_TEST_VECTORS.PASSWORD)