From: Chris Duncan Date: Tue, 3 Dec 2024 05:31:55 +0000 (-0800) Subject: Fix public key and checksum extraction from address. X-Git-Url: https://zoso.dev/?a=commitdiff_plain;h=be96cd00c32b5188b43dc870ba1d0fe694a6dccc;p=libnemo.git Fix public key and checksum extraction from address. --- 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 {