]> zoso.dev Git - libnemo.git/commitdiff
Fix public key and checksum extraction from address.
authorChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 05:31:55 +0000 (21:31 -0800)
committerChris Duncan <chris@zoso.dev>
Tue, 3 Dec 2024 05:31:55 +0000 (21:31 -0800)
src/lib/account.ts

index 2c84da73aca12bd7b44ff5cab27db7fd24fb0d99..8c1d94b3867833ce676543ab0c8a73456cbb1343 100644 (file)
@@ -228,16 +228,16 @@ export class Account {
        }\r
 \r
        static #addressToKey (v: string): string {\r
-               const keyBytes = base32.toBytes(v.substring(0, 52))\r
-               const checksumBytes = base32.toBytes(v.substring(52, 60))\r
-               const blakeHash = new Blake2b(5).update(keyBytes).digest()\r
+               const publicKeyBytes = base32.toBytes(v.substring(-60, -8))\r
+               const checksumBytes = base32.toBytes(v.slice(-8))\r
+               const blakeHash = new Blake2b(5).update(publicKeyBytes).digest()\r
                blakeHash.reverse()\r
                console.log(`checksumBytes: ${checksumBytes}`)\r
                console.log(`blakeHash: ${blakeHash}`)\r
                if (bytes.toHex(checksumBytes) !== bytes.toHex(blakeHash)) {\r
                        throw new Error('Checksum mismatch in address')\r
                }\r
-               return bytes.toHex(keyBytes)\r
+               return bytes.toHex(publicKeyBytes)\r
        }\r
 \r
        static #keyToAddress (key: string): string {\r