*
* Original source commit: https://github.com/emilbayes/blake2b/blob/1f63e02e3f226642959506cdaa67c8819ff145cd/index.js
*/
-
export class Blake2b {
+ /**
+ * Derives account private keys from a wallet seed using the BLAKE2b hashing
+ * algorithm.
+ *
+ * Separately, account public keys are derived from the private key using the
+ * Ed25519 key algorithm, and account addresses are derived from the public key
+ * as described in the Nano documentation.
+ * https://docs.nano.org/integration-guides/the-basics/
+ *
+ * @param {ArrayBuffer} seed - 32-byte secret seed of the wallet
+ * @param {number} index - 4-byte index of account to derive
+ * @returns {ArrayBuffer} Private key for the account
+ */
+ static ckd (seed: ArrayBuffer, index: number): Promise<ArrayBuffer> {
+ const b = new ArrayBuffer(4)
+ new DataView(b).setUint32(0, index, false)
+ const s = new Uint8Array(seed)
+ const i = new Uint8Array(b)
+ const sk = new Blake2b(32).update(s).update(i).digest()
+ return Promise.resolve(sk.buffer)
+ }
+
static get OUTBYTES_MIN (): 1 { return 1 }
static get OUTBYTES_MAX (): 64 { return 64 }
static get KEYBYTES_MIN (): 1 { return 1 }
}
const derive = this.#type === 'BIP-44'
? Bip44.ckd(this.#seed, BIP44_COIN_NANO, index)
- : Promise.resolve(this.#deriveBlake2bPrivateKey(this.#seed, index))
+ : Blake2b.ckd(this.#seed, index)
return derive.then(prv => {
const pub = NanoNaCl.convert(new Uint8Array(prv))
this.#timeout = new VaultTimer(() => this.lock(), 120000)
}
const derive = this.#type === 'BIP-44'
? Bip44.ckd(this.#seed, BIP44_COIN_NANO, index)
- : Promise.resolve(this.#deriveBlake2bPrivateKey(this.#seed, index))
+ : Blake2b.ckd(this.#seed, index)
return derive.then(prv => {
const sig = NanoNaCl.detached(new Uint8Array(data), new Uint8Array(prv))
this.#timeout = new VaultTimer(() => this.lock(), 120000)
})
}
- /**
- * Derives account private keys from a wallet seed using the BLAKE2b hashing
- * algorithm.
- *
- * Separately, account public keys are derived from the private key using the
- * Ed25519 key algorithm, and account addresses are derived from the public key
- * as described in the Nano documentation.
- * https://docs.nano.org/integration-guides/the-basics/
- *
- * @param {ArrayBuffer} seed - 32-byte secret seed of the wallet
- * @param {number} index - 4-byte index of account to derive
- * @returns {ArrayBuffer} Private key for the account
- */
- #deriveBlake2bPrivateKey (seed: ArrayBuffer, index: number): ArrayBuffer {
- const b = new ArrayBuffer(4)
- new DataView(b).setUint32(0, index, false)
- const s = new Uint8Array(seed)
- const i = new Uint8Array(b)
- return new Blake2b(32).update(s).update(i).digest().buffer
- }
-
#encryptWallet (key: CryptoKey): Promise<NamedData<ArrayBuffer>> {
if (this.#type == null) {
throw new Error('Invalid wallet type')