From fab1315c167f5b2596888f5a0092dbe3656d4a4c Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Mon, 2 Dec 2024 11:47:36 -0800 Subject: [PATCH] Remove type assertions rendered unnecessary by improvements to blake2b typings. --- src/lib/account.ts | 6 +++--- src/lib/tools.ts | 9 ++++----- src/lib/wallet.ts | 2 +- 3 files changed, 8 insertions(+), 9 deletions(-) diff --git a/src/lib/account.ts b/src/lib/account.ts index 197553d..8afda65 100644 --- a/src/lib/account.ts +++ b/src/lib/account.ts @@ -186,7 +186,7 @@ export class Account { const expectedChecksum = address.slice(-8) const keyBase32 = address.slice(address.indexOf('_') + 1, -8) const keyBuf = base32.toBytes(keyBase32) - const actualChecksumBuf = new Blake2b(5).update(keyBuf).digest() as Uint8Array + const actualChecksumBuf = new Blake2b(5).update(keyBuf).digest() actualChecksumBuf.reverse() const actualChecksum = bytes.toBase32(actualChecksumBuf) @@ -230,7 +230,7 @@ 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() as Uint8Array + const blakeHash = new Blake2b(5).update(keyBytes).digest() blakeHash.reverse() if (bytes.toHex(checksumBytes) !== bytes.toHex(blakeHash)) { throw new Error('Checksum mismatch in address') @@ -240,7 +240,7 @@ export class Account { static #keyToAddress (key: string): string { const publicKeyBytes = hex.toBytes(key) - const checksum = new Blake2b(5).update(publicKeyBytes).digest() as Uint8Array + const checksum = new Blake2b(5).update(publicKeyBytes).digest() checksum.reverse() const encoded = bytes.toBase32(publicKeyBytes) const encodedChecksum = bytes.toBase32(checksum) diff --git a/src/lib/tools.ts b/src/lib/tools.ts index 9c168ec..26c7789 100644 --- a/src/lib/tools.ts +++ b/src/lib/tools.ts @@ -68,15 +68,14 @@ export async function convert (amount: bigint | string, inputUnit: string, outpu */ export async function hash (data: string | string[], encoding?: 'hex'): Promise { if (!Array.isArray(data)) data = [data] - const stream = new Blake2b(32) + const hash = new Blake2b(32) if (encoding === 'hex') { - data.forEach(str => stream.update(hex.toBytes(str))) + data.forEach(str => hash.update(hex.toBytes(str))) } else { const enc = new TextEncoder() - data.forEach(str => stream.update(enc.encode(str))) + data.forEach(str => hash.update(enc.encode(str))) } - const hash = stream.digest('hex') as string - return hash.toUpperCase() + return hash.digest('hex').toUpperCase() } /** diff --git a/src/lib/wallet.ts b/src/lib/wallet.ts index 5b97b21..59eaa48 100644 --- a/src/lib/wallet.ts +++ b/src/lib/wallet.ts @@ -580,7 +580,7 @@ export class Blake2bWallet extends Wallet { const inputHex = `${this.seed}${indexHex}`.padStart(72, '0') const inputArray = (inputHex.match(/.{1,2}/g) ?? []).map(h => parseInt(h, 16)) const inputBytes = Uint8Array.from(inputArray) - const privateKey: string = new Blake2b(32).update(inputBytes).digest('hex') as string + const privateKey: string = new Blake2b(32).update(inputBytes).digest('hex') return { privateKey, index } }) console.log(`ckd: ${-now + (now = performance.now())} ms`) -- 2.34.1