]> git.codecow.com Git - libnemo.git/commitdiff
Fix account lock and unlock.
authorChris Duncan <chris@zoso.dev>
Tue, 15 Jul 2025 20:54:28 +0000 (13:54 -0700)
committerChris Duncan <chris@zoso.dev>
Tue, 15 Jul 2025 20:54:28 +0000 (13:54 -0700)
src/lib/account.ts
test/test.lock-unlock.mjs

index e9706f74850fbf4794b6dccf5e9a4c20f5f2f405..9f55252125b84be8e015d00f4df3ba2d06bacead 100644 (file)
@@ -163,15 +163,15 @@ export class Account {
                try {\r
                        const headers = {\r
                                method: 'set',\r
-                               name: this.#pub,\r
-                               id: this.#pub\r
+                               name: this.#pub\r
                        }\r
                        const data = {\r
-                               privateKey: this.#prv.buffer,\r
-                               password: password.buffer\r
+                               password: password.buffer,\r
+                               id: hex.toBytes(this.#pub).buffer,\r
+                               privateKey: this.#prv.buffer\r
                        }\r
                        const response = await SafeWorker.add(headers, data)\r
-                       const success = response?.result[0]\r
+                       const success = response[0].result\r
                        if (!success) {\r
                                throw null\r
                        }\r
@@ -238,12 +238,15 @@ export class Account {
                                password: password.buffer\r
                        }\r
                        const response = await SafeWorker.add(headers, data)\r
-                       const { id, privateKey } = response?.result[0]\r
-                       if (id == null || id !== this.#pub) {\r
+                       let { id, privateKey } = response[0].result\r
+                       if (id == null) {\r
+                               throw null\r
+                       }\r
+                       id = bytes.toHex(new Uint8Array(id))\r
+                       if (id !== this.publicKey) {\r
                                throw null\r
                        }\r
-                       debugger\r
-                       this.#prv.set(obj.toBytes(privateKey))\r
+                       this.#prv = new Uint8Array(privateKey as ArrayBuffer)\r
                } catch (err) {\r
                        console.error(`Failed to unlock account ${this.address}`, err)\r
                        return false\r
index 9b980b97c784bd6680a3562a96d8f4568c0ac3fc..f01143175834a80ca097d9db5c919e0c71e25f19 100644 (file)
@@ -60,7 +60,7 @@ await suite('Lock and unlock wallets', async () => {
                assert.equals(lockResult, true)\r
                assert.ok(account.isLocked)\r
                assert.ok('privateKey' in account)\r
-               assert.equals(account.privateKey, '0000000000000000000000000000000000000000000000000000000000000000')\r
+               assert.equals(account.privateKey, '')\r
 \r
                const unlockResult = await account.unlock(NANO_TEST_VECTORS.PASSWORD)\r
 \r
@@ -211,7 +211,7 @@ await suite('Lock and unlock wallets', async () => {
                assert.equals(lockResult, true)\r
                assert.ok(account.isLocked)\r
                assert.ok('privateKey' in account)\r
-               assert.equals(account.privateKey, '0000000000000000000000000000000000000000000000000000000000000000')\r
+               assert.equals(account.privateKey, '')\r
 \r
                const unlockResult = await account.unlock(NANO_TEST_VECTORS.PASSWORD)\r
 \r