From 470aa4a30a1369e46eb15406fb10d38c0396a2f0 Mon Sep 17 00:00:00 2001 From: Chris Duncan Date: Fri, 8 Aug 2025 11:30:13 -0700 Subject: [PATCH] Reorder methods. --- src/lib/safe.ts | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/src/lib/safe.ts b/src/lib/safe.ts index aea0ea9..c6dd767 100644 --- a/src/lib/safe.ts +++ b/src/lib/safe.ts @@ -301,27 +301,6 @@ export class Safe { } } - /** - * 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 #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 - } - static async #createAesKey (purpose: 'encrypt' | 'decrypt', password: ArrayBuffer, keySalt: ArrayBuffer): Promise { const derivationKey = await crypto.subtle.importKey('raw', password, 'PBKDF2', false, ['deriveBits', 'deriveKey']) new Uint8Array(password).fill(0).buffer.transfer() @@ -346,6 +325,27 @@ export class Safe { return { seed, mnemonic } } + /** + * 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 #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 + } + static async #encryptWallet (key: CryptoKey): Promise> { if (this.#seed == null) { throw new Error('Wallet seed not found') -- 2.47.3