* Listens for messages from a calling function.
*/
addEventListener('message', (message) => {
- const { seed, index } = message.data ?? message
- nanoCKD(seed, index).then(privateKey => postMessage({ privateKey, index }))
+ const data = JSON.parse(new TextDecoder().decode(message.data ?? message))
+ process(data).then(results => {
+ const buf = new TextEncoder().encode(JSON.stringify(data)).buffer
+ //@ts-expect-error
+ postMessage(buf, [buf])
+ })
})
+ async function process (data: any[]): Promise<any[]> {
+ return new Promise(async (resolve) => {
+ for (const d of data) {
+ d.privateKey = await nanoCKD(d.seed, d.index)
+ }
+ resolve(data)
+ })
+ }
+
/**
* Derives a private child key following the BIP-32 and BIP-44 derivation path
* registered to the Nano block lattice. Only hardened child keys are defined.