From 359042edad921ccff743e7e9488040519c4f44ac Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Sat, 4 Jul 2026 01:44:55 -0700 Subject: [PATCH] Remove async keyword and format comment docs. --- src/lib/vault/vault-worker.ts | 76 ++++++++++++++++++----------------- 1 file changed, 39 insertions(+), 37 deletions(-) diff --git a/src/lib/vault/vault-worker.ts b/src/lib/vault/vault-worker.ts index 6c242c4..621493c 100644 --- a/src/lib/vault/vault-worker.ts +++ b/src/lib/vault/vault-worker.ts @@ -114,7 +114,7 @@ NODE: parentPort?.on('message', listener) * Configures vault settings. The wallet must be unlocked prior to * configuration. */ -async function config (timeout?: number): Promise { +function config (timeout?: number): Promise { try { _timer?.pause() if (_locked) { @@ -139,10 +139,10 @@ async function config (timeout?: number): Promise { } /** -* Generates a new mnemonic and seed and then returns the initialization vector -* vector, salt, and encrypted data representing the wallet in a locked state. -*/ -async function create (type?: WalletType, key?: CryptoKey, keySalt?: ArrayBuffer, mnemonicSalt?: string): Promise> { + * Generates a new mnemonic and seed and then returns the initialization vector + * vector, salt, and encrypted data representing the wallet in a locked state. + */ +function create (type?: WalletType, key?: CryptoKey, keySalt?: ArrayBuffer, mnemonicSalt?: string): Promise> { if (type !== 'BIP-44' && type !== 'BLAKE2b') { throw new TypeError('Unsupported software wallet algorithm', { cause: type }) } @@ -166,11 +166,11 @@ async function create (type?: WalletType, key?: CryptoKey, keySalt?: ArrayBuffer } /** -* Derives the private and public keys of a child account from the current -* wallet seed at a specified index and then returns the public key. The wallet -* must be unlocked prior to derivation. -*/ -async function derive (index?: number): Promise> { + * Derives the private and public keys of a child account from the current + * wallet seed at a specified index and then returns the public key. The wallet + * must be unlocked prior to derivation. + */ +function derive (index?: number): Promise> { try { _timer.pause() if (_locked) { @@ -200,10 +200,10 @@ async function derive (index?: number): Promise> { + * Encrypts an existing seed or mnemonic+salt and returns the initialization + * vector, salt, and encrypted data representing the wallet in a locked state. + */ +function load (type?: WalletType, key?: CryptoKey, keySalt?: ArrayBuffer, secret?: string | ArrayBuffer, mnemonicSalt?: string): Promise> { if (type !== 'BIP-44' && type !== 'BLAKE2b' && type !== 'Exodus') { throw new TypeError('Unsupported software wallet algorithm', { cause: type }) } @@ -221,7 +221,7 @@ async function load (type?: WalletType, key?: CryptoKey, keySalt?: ArrayBuffer, .finally(() => lock()) } -async function lock (): Promise> { +function lock (): Promise> { _mnemonic = undefined _seed = undefined _locked = true @@ -230,10 +230,10 @@ async function lock (): Promise> { } /** -* Derives the account private key at a specified index, signs the input data, -* and returns a signature. The wallet must be unlocked prior to verification. -*/ -async function sign (index?: number, data?: ArrayBuffer): Promise> { + * Derives the account private key at a specified index, signs the input data, + * and returns a signature. The wallet must be unlocked prior to verification. + */ +function sign (index?: number, data?: ArrayBuffer): Promise> { try { _timer.pause() if (_locked) { @@ -264,9 +264,9 @@ async function sign (index?: number, data?: ArrayBuffer): Promise> { + * Decrypts the input and sets the seed and, if it is included, the mnemonic. + */ +function unlock (type?: WalletType, key?: CryptoKey, iv?: ArrayBuffer, encrypted?: ArrayBuffer): Promise> { if (type == null) { throw new TypeError('Wallet type is required') } @@ -307,9 +307,9 @@ async function unlock (type?: WalletType, key?: CryptoKey, iv?: ArrayBuffer, enc } /** -* Re-encrypts the wallet with a new password. -*/ -async function update (key?: CryptoKey, salt?: ArrayBuffer): Promise> { + * Re-encrypts the wallet with a new password. + */ +function update (key?: CryptoKey, salt?: ArrayBuffer): Promise> { try { _timer.pause() if (_locked) { @@ -337,9 +337,9 @@ async function update (key?: CryptoKey, salt?: ArrayBuffer): Promise> { try { if (_locked) { @@ -380,11 +380,13 @@ function verify (seed?: ArrayBuffer, mnemonicPhrase?: string): Promise { - const { isLocked } = await lock() - const id = 'autolock' - BROWSER: self.postMessage({ url: location.href, id, isLocked }) - NODE: parentPort?.postMessage({ data: { url: dec.toString(threadId), id, isLocked } }) +function _autolock (): Promise { + return lock() + .then(isLocked => { + const id = 'autolock' + BROWSER: self.postMessage({ url: location.href, id, isLocked }) + NODE: parentPort?.postMessage({ data: { url: dec.toString(threadId), id, isLocked } }) + }) } const _index = new DataView(new ArrayBuffer(4)) @@ -400,7 +402,7 @@ const _index = new DataView(new ArrayBuffer(4)) * * @param {number} index - 4-byte index of account to derive * @returns {Promise} Private key for the account -*/ + */ function _ckd (index: number): Promise { if (_seed == null) { throw new Error('Wallet seed not found') @@ -422,9 +424,9 @@ function _ckd (index: number): Promise { } /** -* Encrypts an existing seed or mnemonic+salt and returns the initialization -* vector, salt, and encrypted data representing the wallet in a locked state. -*/ + * Encrypts an existing seed or mnemonic+salt and returns the initialization + * vector, salt, and encrypted data representing the wallet in a locked state. + */ function _load (type?: 'BIP-44' | 'BLAKE2b' | 'Exodus', key?: CryptoKey, keySalt?: ArrayBuffer, secret?: string | ArrayBuffer, mnemonicSalt?: string): Promise> { try { if (!_locked) { -- 2.52.0