]> zoso.dev Git - libnemo.git/commitdiff
Remove type assertions rendered unnecessary by improvements to blake2b typings.
authorChris Duncan <chris@zoso.dev>
Mon, 2 Dec 2024 19:47:36 +0000 (11:47 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 2 Dec 2024 19:47:36 +0000 (11:47 -0800)
src/lib/account.ts
src/lib/tools.ts
src/lib/wallet.ts

index 197553d94c0c0dac962746eb982d1aea3d025335..8afda65c79b66b1ee6f7ae15a4be3ba4d64fc469 100644 (file)
@@ -186,7 +186,7 @@ export class Account {
                const expectedChecksum = address.slice(-8)\r
                const keyBase32 = address.slice(address.indexOf('_') + 1, -8)\r
                const keyBuf = base32.toBytes(keyBase32)\r
-               const actualChecksumBuf = new Blake2b(5).update(keyBuf).digest() as Uint8Array\r
+               const actualChecksumBuf = new Blake2b(5).update(keyBuf).digest()\r
                actualChecksumBuf.reverse()\r
                const actualChecksum = bytes.toBase32(actualChecksumBuf)\r
 \r
@@ -230,7 +230,7 @@ export class Account {
        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() as Uint8Array\r
+               const blakeHash = new Blake2b(5).update(keyBytes).digest()\r
                blakeHash.reverse()\r
                if (bytes.toHex(checksumBytes) !== bytes.toHex(blakeHash)) {\r
                        throw new Error('Checksum mismatch in address')\r
@@ -240,7 +240,7 @@ export class Account {
 \r
        static #keyToAddress (key: string): string {\r
                const publicKeyBytes = hex.toBytes(key)\r
-               const checksum = new Blake2b(5).update(publicKeyBytes).digest() as Uint8Array\r
+               const checksum = new Blake2b(5).update(publicKeyBytes).digest()\r
                checksum.reverse()\r
                const encoded = bytes.toBase32(publicKeyBytes)\r
                const encodedChecksum = bytes.toBase32(checksum)\r
index 9c168ec5c6682ea70fecda6fc456fac99275d68c..26c7789cac8f216117bad1bb4007f223432e22da 100644 (file)
@@ -68,15 +68,14 @@ export async function convert (amount: bigint | string, inputUnit: string, outpu
 */
 export async function hash (data: string | string[], encoding?: 'hex'): Promise<string> {
        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()
 }
 
 /**
index 5b97b215711dc9ced78dccd6fd6617b38325fd69..59eaa480f1ccf0a2f32a44c3c6ed554eb19b4e02 100644 (file)
@@ -580,7 +580,7 @@ export class Blake2bWallet extends Wallet {
                        const inputHex = `${this.seed}${indexHex}`.padStart(72, '0')\r
                        const inputArray = (inputHex.match(/.{1,2}/g) ?? []).map(h => parseInt(h, 16))\r
                        const inputBytes = Uint8Array.from(inputArray)\r
-                       const privateKey: string = new Blake2b(32).update(inputBytes).digest('hex') as string\r
+                       const privateKey: string = new Blake2b(32).update(inputBytes).digest('hex')\r
                        return { privateKey, index }\r
                })\r
                console.log(`ckd: ${-now + (now = performance.now())} ms`)\r