// SPDX-License-Identifier: GPL-3.0-or-later
import { Blake2b } from './blake2b.js'
-import { Entropy } from './entropy.js'
const p = () => {
+ const NONCE_BYTES = 8
+ const RECEIVE_THRESHOLD = 'fffffe0000000000'
+ const SEND_THRESHOLD = 'fffffff800000000'
+
/**
* Listens for messages from a calling function.
*/
postMessage(buf, [buf])
})
- function find (hash: string, threshold: string) {
- let nonce = null
+ async function find (hash: string, threshold: string = SEND_THRESHOLD) {
+ let count = 0
+ let result = null
do {
- const e: Entropy = new Entropy(16)
- const bytes: Uint8Array = parseHex(`${e.hex}${hash}`)
- const result: string = new Blake2b(16).update(bytes).digest('hex') as string
- const delta = BigInt(`0x${result}`) - BigInt(`0x${threshold}`)
- if (delta >= 0) {
- nonce = result
+ count++
+ const nonce: Uint8Array = new Uint8Array(NONCE_BYTES)
+ crypto.getRandomValues(nonce)
+ const test: string = new Blake2b(NONCE_BYTES)
+ .update(nonce)
+ .update(parseHex(hash))
+ .digest('hex') as string
+ if (count % 1000 === 0) console.log(`${count} hashes...`)
+ if (BigInt(`0x${test}`) >= BigInt(`0x${threshold}`)) {
+ result = nonce
}
- } while (nonce == null)
- return nonce
+ } while (result == null)
+ return result
}
function parseHex (hex: string) {
import { Account } from './lib/account.js'
import { SendBlock, ReceiveBlock, ChangeBlock } from './lib/block.js'
+import { Pow } from './lib/pow.js'
import { Rpc } from './lib/rpc.js'
import { Rolodex } from './lib/rolodex.js'
import { Safe } from './lib/safe.js'
import Tools from './lib/tools.js'
import { Bip44Wallet, Blake2bWallet, LedgerWallet } from './lib/wallet.js'
-export { Account, SendBlock, ReceiveBlock, ChangeBlock, Rpc, Rolodex, Safe, Tools, Bip44Wallet, Blake2bWallet, LedgerWallet }
+export { Account, SendBlock, ReceiveBlock, ChangeBlock, Pow, Rpc, Rolodex, Safe, Tools, Bip44Wallet, Blake2bWallet, LedgerWallet }