]> zoso.dev Git - libnemo.git/commitdiff
Fix import paths. Fix entropy usage. Ensure blake2b is always included in NanoNaCl...
authorChris Duncan <chris@zoso.dev>
Mon, 9 Dec 2024 16:04:41 +0000 (08:04 -0800)
committerChris Duncan <chris@zoso.dev>
Mon, 9 Dec 2024 16:04:41 +0000 (08:04 -0800)
src/lib/account.ts
src/lib/bip39-mnemonic.ts
src/lib/block.ts
src/lib/safe.ts
src/lib/tools.ts
src/lib/wallet.ts
src/lib/workers/nano-nacl.ts

index 3e3d932acbb857334510facb7a5addbe8a97572f..001208c98d7dfaf71c3b4f7a36df04dba31cfd81 100644 (file)
@@ -6,7 +6,7 @@ import { ACCOUNT_KEY_LENGTH, ALPHABET, PREFIX, PREFIX_LEGACY } from './constants
 import { base32, bytes, hex } from './convert.js'\r
 import { Rpc } from './rpc.js'\r
 import { Safe } from './safe.js'\r
-import { NanoNaCl } from './nano-nacl.js'\r
+import { NanoNaCl } from './workers/nano-nacl.js'\r
 \r
 /**\r
 * Represents a single Nano address and the associated public key. To include the\r
index 87ac879dd3fba69d27ef0617c09f9dde7ed00b80..1d9fe2d8e7c6983b101653ce98415d985ca9a049 100644 (file)
@@ -119,7 +119,7 @@ export class Bip39Mnemonic {
                        return false\r
                }\r
 \r
-               const entropy = new Entropy(bin.toBytes(entropyBits))\r
+               const entropy = await Entropy.import(bin.toBytes(entropyBits))\r
                const expectedChecksum = await this.checksum(entropy)\r
 \r
                if (expectedChecksum !== checksumBits) {\r
index 58ee6fda375a534c33d20dd7bb03f62cbd9f7ccb..024877b256592e7a125f2be9b2c6ffcd7f5ff84e 100644 (file)
@@ -5,7 +5,7 @@ import { BURN_ADDRESS, PREAMBLE, THRESHOLD_RECEIVE, THRESHOLD_SEND } from './con
 import { Account } from './account.js'
 import { Blake2b } from './blake2b.js'
 import { dec, hex } from './convert.js'
-import { NanoNaCl } from './nano-nacl.js'
+import { NanoNaCl } from './workers/nano-nacl.js'
 import { Pool } from './pool.js'
 import { Rpc } from './rpc.js'
 import { Pow } from './workers.js'
index e22503f4bde4a0018f28fdfb9d4983e85a431674..457dc931f4eeb2ebcaf289d8c987ddf3f4bda6ae 100644 (file)
@@ -41,7 +41,7 @@ export class Safe {
                        throw new Error(ERR_MSG)
                }
 
-               const iv = new Entropy()
+               const iv = await Entropy.create()
                if (typeof passkey === 'string') {
                        try {
                                passkey = await subtle.importKey('raw', utf8.toBytes(passkey), 'PBKDF2', false, ['deriveBits', 'deriveKey'])
@@ -98,7 +98,7 @@ export class Safe {
                }
                const record = JSON.parse(item)
                const encrypted = hex.toBytes(record.encrypted)
-               const iv = new Entropy(record.iv)
+               const iv = await Entropy.import(record.iv)
 
                try {
                        if (typeof passkey === 'string') {
index 69cadcd901cfe01668bad6b5760a14ba87d21483..fe934fe8537c67a05894b20667327ba24734f6ae 100644 (file)
@@ -8,7 +8,7 @@ import { hex } from './convert.js'
 import { Rpc } from './rpc.js'
 import { Bip44Wallet, Blake2bWallet, LedgerWallet } from './wallet.js'
 import { SendBlock } from './block.js'
-import { NanoNaCl } from './nano-nacl.js'
+import { NanoNaCl } from './workers/nano-nacl.js'
 
 function hash (data: string | string[], encoding?: 'hex'): string {
        if (!Array.isArray(data)) data = [data]
index 213b54355b661109bfa27ee2e0f23a851066e2e2..447c2053f96db88b553ff7c535a02c0769ea4cf0 100644 (file)
@@ -93,7 +93,7 @@ abstract class Wallet {
                        let results = await this.ckd(indexes)\r
                        const data: any = []\r
                        results.forEach(r => data.push({ privateKey: r.privateKey, index: r.index }))\r
-                       const pool = new Pool(`const Blake2b = ${Blake2b}\n${NanoNaCl}`)\r
+                       const pool = new Pool(NanoNaCl)\r
                        const keypairs: KeyPair[] = await pool.work('divide', data)\r
                        pool.dismiss()\r
                        for (const keypair of keypairs) {\r
index 2f64ce18e7c8df4a2bb43cf7138a3812229ab3c5..962e1ae1635b5c8212d100a1be73b20300641b48 100644 (file)
@@ -3,7 +3,7 @@
 \r
 'use strict'\r
 \r
-import { Blake2b } from '#src/lib/blake2b.js'\r
+import { Blake2b } from '../blake2b.js'\r
 \r
 // Ported in 2014 by Dmitry Chestnykh and Devi Mandiri.\r
 // Public domain.\r
@@ -854,4 +854,5 @@ export const NanoNaCl = n()
 \r
 const start = n.toString().indexOf('{') + 1\r
 const end = n.toString().lastIndexOf('return')\r
-export const worker = n.toString().substring(start, end)\r
+const blake2b = `const Blake2b = ${Blake2b}\n`\r
+export const worker = `${blake2b}${n.toString().substring(start, end)}`\r