this.#threads.push(thread)
Pool.#cores = Math.max(1, Pool.#cores - this.#threads.length)
}
- console.log(this.#url)
}
#assign (thread: Thread, job: Job): void {
}
}
+/**
+* Provides basic worker event messaging to extending classes.
+*
+* In order to be properly bundled in a format that can be used to create an
+* inline Web Worker, the extending classes must export WorkerInterface and
+* themselves as a string:
+*```
+* export default `
+* const WorkerInterface = ${WorkerInterface}
+* const Pow = ${Pow}
+* `
+* ```
+* They must also initialize the event listener by calling their inherited
+* `listen()` function. Finally, they must override the implementation of the
+* `work()` function. See the documentation of those functions for details.
+*/
export class WorkerInterface {
/**
* Processes data through a worker.
*
- * Worker classes should override this template by implementing the same
- * function signature and providing their own processing method in the
- * try-catch block. In order to be properly bundled in a format that can be The classes also need to export WorkerInterface and
- * themselves as a string. For example:
- *
- * `export default `const WorkerInterface
+ * Extending classes must override this template by implementing the same
+ * function signature and providing their own processing call in the try-catch
+ * block.
*
* @param {any[]} data - Array of data to process
* @returns Promise for that data after being processed
}
/**
- * Listens for messages from a calling function.
+ * Listens for messages from the main thread.
+ *
+ * Extending classes must call this in a static initialization block:
+ * ```
+ * static {
+ * Pow.listen()
+ * }
+ * ```
*/
- static {
+ static listen (): void {
addEventListener('message', (message: any): void => {
const { name, buffer } = message.data
if (name === 'STOP') {
static HARDENED_OFFSET = 0x80000000
static SLIP10_ED25519 = 'ed25519 seed'
+ static {
+ Bip44Ckd.listen()
+ }
+
static async work (data: any[]): Promise<any[]> {
for (const d of data) {
if (d.coin != null && d.coin !== this.BIP44_PURPOSE) {
// Original source commit: https://github.com/dchest/tweetnacl-js/blob/71df1d6a1d78236ca3e9f6c788786e21f5a651a6/nacl-fast.js\r
\r
export class NanoNaCl extends WorkerInterface {\r
+ static {\r
+ NanoNaCl.listen()\r
+ }\r
+\r
+ static async work (data: any[]): Promise<any[]> {\r
+ return new Promise(async (resolve, reject): Promise<void> => {\r
+ for (let d of data) {\r
+ try {\r
+ d.publicKey = await this.convert(d.privateKey)\r
+ } catch (err) {\r
+ reject(err)\r
+ }\r
+ }\r
+ resolve(data)\r
+ })\r
+ }\r
+\r
static gf = function (init?: number[]): Float64Array {\r
const r = new Float64Array(16)\r
if (init) for (let i = 0; i < init.length; i++) r[i] = init[i]\r
\r
return this.hexify(pk).toUpperCase()\r
}\r
-\r
- static async work (data: any[]): Promise<any[]> {\r
- return new Promise(async (resolve, reject): Promise<void> => {\r
- for (let d of data) {\r
- try {\r
- d.publicKey = await this.convert(d.privateKey)\r
- } catch (err) {\r
- reject(err)\r
- }\r
- }\r
- resolve(data)\r
- })\r
- }\r
}\r
\r
export default `\r
import { WorkerInterface } from '../pool.js'
export class Pow extends WorkerInterface {
+ static {
+ Pow.listen()
+ }
/**
* Calculates proof-of-work as described by the Nano cryptocurrency protocol.
*
import { NANO_TEST_VECTORS } from '#test/TEST_VECTORS.js'\r
import { Bip44Wallet, Blake2bWallet, LedgerWallet } from '#dist/main.js'\r
\r
-await skip('Create wallets', async () => {\r
+await suite('Create wallets', async () => {\r
await test('BIP-44 wallet with random entropy', async () => {\r
const wallet = await Bip44Wallet.create(NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
assert.equals(accounts[0].address, NANO_TEST_VECTORS.ADDRESS_0)\r
})\r
\r
- await skip('should derive low indexed accounts from the given BIP-44 seed', async () => {\r
+ await test('should derive low indexed accounts from the given BIP-44 seed', async () => {\r
const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(1, 2)\r
assert.equals(accounts[1].address, NANO_TEST_VECTORS.ADDRESS_2)\r
})\r
\r
- await skip('should derive high indexed accounts from the given seed', async () => {\r
+ await test('should derive high indexed accounts from the given seed', async () => {\r
const wallet = await Bip44Wallet.fromSeed(NANO_TEST_VECTORS.PASSWORD, NANO_TEST_VECTORS.BIP39_SEED)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const accounts = await wallet.accounts(0x70000000, 0x700000ff)\r
}\r
})\r
\r
- await skip('should derive accounts for a BLAKE2b wallet', async () => {\r
+ await test('should derive accounts for a BLAKE2b wallet', async () => {\r
const wallet = await Blake2bWallet.create(NANO_TEST_VECTORS.PASSWORD)\r
await wallet.unlock(NANO_TEST_VECTORS.PASSWORD)\r
const lowAccounts = await wallet.accounts(0, 2)\r