}
async function ckdBip44 () {
- let BIP44_COIN_NANO: any, BIP44_PURPOSE: any, HARDENED_OFFSET: any, SLIP10_ED25519: any
- let bytes: any, dec: any, hex: any, utf8: any
+ const BIP44_COIN_NANO = 165
+ const BIP44_PURPOSE = 44
+ const HARDENED_OFFSET = 0x80000000
+ const SLIP10_ED25519 = 'ed25519 seed'
+ let bytes: any
+ let hex: any
let addEventListener = globalThis.addEventListener
let postMessage = globalThis.postMessage
if (addEventListener == null || postMessage == null) {
- ({ BIP44_COIN_NANO, BIP44_PURPOSE, HARDENED_OFFSET, SLIP10_ED25519 } = await import(new URL('dist/lib/constants.js', import.meta.url).toString()));
- ({ bytes, dec, hex, utf8 } = await import(new URL('./dist/lib/convert.js', import.meta.url).toString()))
+ ({ bytes, hex } = await import(new URL('./dist/lib/convert.js', import.meta.url).toString()))
const { isMainThread, parentPort } = await import('node:worker_threads')
if (!isMainThread && parentPort) {
addEventListener = Object.getPrototypeOf(parentPort).addListener.bind(parentPort)
postMessage = Object.getPrototypeOf(parentPort).postMessage.bind(parentPort)
}
- } else {
- ({ BIP44_COIN_NANO, BIP44_PURPOSE, HARDENED_OFFSET, SLIP10_ED25519 } = await import('../constants.js'));
- ({ bytes, dec, hex, utf8 } = await import('../convert.js'))
}
/**
}
async function slip10 (curve: string, S: string): Promise<ExtendedKey> {
- const key = utf8.toBytes(curve)
+ const key = new TextEncoder().encode(curve)
const data = hex.toBytes(S)
const I = await hmac(key, data)
const IL = I.slice(0, I.length / 2)
if (typeof integer !== 'number') {
throw new TypeError(`Expected a number, received ${typeof integer}`)
}
- const bits = dec.toBin(integer)
- if (bits.length > 32) {
- throw new RangeError(`Expected 32-bit integer, received ${bits.length}-bit value: ${integer}`)
+ if (integer > 0xffffffff) {
+ throw new RangeError(`Expected 32-bit integer, received ${integer.toString(2).length}-bit value: ${integer}`)
}
- return dec.toBytes(integer, 4)
+ const view = new DataView(new ArrayBuffer(4))
+ view.setUint32(0, integer, false)
+ return new Uint8Array(view.buffer)
}
function ser256 (integer: string): Uint8Array {