* Configures vault settings. The wallet must be unlocked prior to
* configuration.
*/
-async function config (timeout?: number): Promise<void> {
+function config (timeout?: number): Promise<void> {
try {
_timer?.pause()
if (_locked) {
}
/**
-* 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<Record<string, ArrayBuffer>> {
+ * 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<Record<string, ArrayBuffer>> {
if (type !== 'BIP-44' && type !== 'BLAKE2b') {
throw new TypeError('Unsupported software wallet algorithm', { cause: type })
}
}
/**
-* 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<Record<string, number | 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.
+ */
+function derive (index?: number): Promise<Record<string, number | ArrayBuffer>> {
try {
_timer.pause()
if (_locked) {
}
/**
-* Encrypts an existing seed or mnemonic+salt and returns the initialization
-* vector, salt, and encrypted data representing the wallet in a locked state.
-*/
-async function load (type?: WalletType, key?: CryptoKey, keySalt?: ArrayBuffer, secret?: string | ArrayBuffer, mnemonicSalt?: string): Promise<Record<string, ArrayBuffer>> {
+ * 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<Record<string, ArrayBuffer>> {
if (type !== 'BIP-44' && type !== 'BLAKE2b' && type !== 'Exodus') {
throw new TypeError('Unsupported software wallet algorithm', { cause: type })
}
.finally(() => lock())
}
-async function lock (): Promise<Record<string, boolean>> {
+function lock (): Promise<Record<string, boolean>> {
_mnemonic = undefined
_seed = undefined
_locked = true
}
/**
-* 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<Record<string, ArrayBuffer>> {
+ * 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<Record<string, ArrayBuffer>> {
try {
_timer.pause()
if (_locked) {
}
/**
-* Decrypts the input and sets the seed and, if it is included, the mnemonic.
-*/
-async function unlock (type?: WalletType, key?: CryptoKey, iv?: ArrayBuffer, encrypted?: ArrayBuffer): Promise<Record<string, boolean>> {
+ * 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<Record<string, boolean>> {
if (type == null) {
throw new TypeError('Wallet type is required')
}
}
/**
-* Re-encrypts the wallet with a new password.
-*/
-async function update (key?: CryptoKey, salt?: ArrayBuffer): Promise<Record<string, ArrayBuffer>> {
+ * Re-encrypts the wallet with a new password.
+ */
+function update (key?: CryptoKey, salt?: ArrayBuffer): Promise<Record<string, ArrayBuffer>> {
try {
_timer.pause()
if (_locked) {
}
/**
-* Checks the seed and, if it exists, the mnemonic against input. The wallet
-* must be unlocked prior to verification.
-*/
+ * Checks the seed and, if it exists, the mnemonic against input. The wallet
+ * must be unlocked prior to verification.
+ */
function verify (seed?: ArrayBuffer, mnemonicPhrase?: string): Promise<Record<string, boolean>> {
try {
if (_locked) {
}
}
-async function _autolock (): Promise<void> {
- 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<void> {
+ 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))
*
* @param {number} index - 4-byte index of account to derive
* @returns {Promise<ArrayBuffer>} Private key for the account
-*/
+ */
function _ckd (index: number): Promise<ArrayBuffer> {
if (_seed == null) {
throw new Error('Wallet seed not found')
}
/**
-* 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<Record<string, ArrayBuffer>> {
try {
if (!_locked) {