From be96cd00c32b5188b43dc870ba1d0fe694a6dccc Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 2 Dec 2024 21:31:55 -0800 Subject: [PATCH] Fix public key and checksum extraction from address. --- src/lib/account.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/lib/account.ts b/src/lib/account.ts index 2c84da7..8c1d94b 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -228,16 +228,16 @@ export class Account { } static #addressToKey (v: string): string { - const keyBytes = base32.toBytes(v.substring(0, 52)) - const checksumBytes = base32.toBytes(v.substring(52, 60)) - const blakeHash = new Blake2b(5).update(keyBytes).digest() + const publicKeyBytes = base32.toBytes(v.substring(-60, -8)) + const checksumBytes = base32.toBytes(v.slice(-8)) + const blakeHash = new Blake2b(5).update(publicKeyBytes).digest() blakeHash.reverse() console.log(`checksumBytes: ${checksumBytes}`) console.log(`blakeHash: ${blakeHash}`) if (bytes.toHex(checksumBytes) !== bytes.toHex(blakeHash)) { throw new Error('Checksum mismatch in address') } - return bytes.toHex(keyBytes) + return bytes.toHex(publicKeyBytes) } static #keyToAddress (key: string): string { -- 2.34.1