/**
* Cross-platform worker for managing wallet secrets.
*/
-export class Safe {
+export class Vault {
static #locked: boolean = true
static #type?: 'BIP-44' | 'BLAKE2b'
static #seed?: ArrayBuffer
}
message.data[key] = undefined
}
- BROWSER: postMessage({ error: 'Failed to process Safe request', cause: err })
- NODE: parentPort?.postMessage({ error: 'Failed to process Safe request', cause: err })
+ BROWSER: postMessage({ error: 'Failed to process Vault request', cause: err })
+ NODE: parentPort?.postMessage({ error: 'Failed to process Vault request', cause: err })
}
}
BROWSER: addEventListener('message', listener)
const Bip44 = ${Bip44}
const Blake2b = ${Blake2b}
const NanoNaCl = ${NanoNaCl}
- const Safe = ${Safe}
+ const Vault = ${Vault}
`
import { Database } from '../database'\r
import { _load } from './load'\r
import { Rpc } from '../rpc'\r
-import { default as SafeWorker } from './safe'\r
+import { default as VaultWorker } from './vault'\r
import { WorkerQueue } from './worker-queue'\r
\r
/**\r
#lockTimer?: any\r
#id: string\r
#mnemonic?: ArrayBuffer\r
- #safe: WorkerQueue\r
+ #vault: WorkerQueue\r
#seed?: ArrayBuffer\r
#type: WalletType\r
\r
get id () { return this.#id }\r
- get safe () { return this.#safe }\r
+ get vault () { return this.#vault }\r
get type () { return this.#type }\r
\r
/** Set when calling `create()` and self-destructs after the first read. */\r
Wallet.#isInternal = false\r
this.#accounts = new AccountList()\r
this.#id = id ?? crypto.randomUUID()\r
- this.#safe = new WorkerQueue(SafeWorker)\r
+ this.#vault = new WorkerQueue(VaultWorker)\r
this.#type = type\r
}\r
\r
if (indexes.length > 0) {\r
const promises = []\r
for (const index of indexes) {\r
- promises.push(this.#safe.request<ArrayBuffer>({\r
+ promises.push(this.#vault.request<ArrayBuffer>({\r
action: 'derive',\r
index\r
}))\r
if (!isDeleted) {\r
throw new Error('Failed to delete wallet from database')\r
}\r
- this.#safe.terminate()\r
+ this.#vault.terminate()\r
clearTimeout(this.#lockTimer)\r
} catch (err) {\r
console.error(err)\r
*/\r
async lock (): Promise<boolean> {\r
try {\r
- const { isLocked } = await this.#safe.request<boolean>({\r
+ const { isLocked } = await this.#vault.request<boolean>({\r
action: 'lock'\r
})\r
if (!isLocked) {\r
- throw new Error('Lock request to Safe failed')\r
+ throw new Error('Lock request to Vault failed')\r
}\r
clearTimeout(this.#lockTimer)\r
return isLocked\r
async sign (index: number, block: Block, format: 'hex'): Promise<string>\r
async sign (index: number, block: Block, format?: 'hex'): Promise<string | Uint8Array<ArrayBuffer>> {\r
try {\r
- const { signature } = await this.#safe.request<ArrayBuffer>({\r
+ const { signature } = await this.#vault.request<ArrayBuffer>({\r
action: 'sign',\r
index,\r
data: hex.toBuffer(block.hash)\r
async unlock (password: string): Promise<boolean> {\r
try {\r
const { iv, salt, encrypted } = await Wallet.#get(this.#id)\r
- const { isUnlocked } = await this.#safe.request<boolean>({\r
+ const { isUnlocked } = await this.#vault.request<boolean>({\r
action: 'unlock',\r
type: this.#type,\r
password: utf8.toBuffer(password),\r
encrypted\r
})\r
if (!isUnlocked) {\r
- throw new Error('Unlock request to Safe failed')\r
+ throw new Error('Unlock request to Vault failed')\r
}\r
clearTimeout(this.#lockTimer)\r
this.#lockTimer = setTimeout(() => this.lock(), 300000)\r
} else {\r
throw new TypeError('Invalid format')\r
}\r
- const result = await this.#safe.request<boolean>(data)\r
+ const result = await this.#vault.request<boolean>(data)\r
const { isVerified } = result\r
return isVerified\r
} catch (err) {\r