diff --git a/__tests__/unit/Keys.test.ts b/__tests__/unit/Keys.test.ts index ac917d4e1..b24c464d4 100644 --- a/__tests__/unit/Keys.test.ts +++ b/__tests__/unit/Keys.test.ts @@ -120,13 +120,13 @@ describe("Ed25519PrivateKey", () => { it("derive() produces correct value", async() => { const iosKey = await Ed25519PrivateKey.fromMnemonic(iosWalletMnemonic, ""); - const iosChildKey = await iosKey.derive(0); + const iosChildKey = await iosKey.derive2(0); expect(iosChildKey.toBytes()).toStrictEqual(iosWalletPrivKeyBytes); expect(iosChildKey.publicKey.toBytes()).toStrictEqual(iosWalletPubKeyBytes); const androidKey = await Ed25519PrivateKey.fromMnemonic(androidWalletMnemonic, ""); - const androidChildKey = await androidKey.derive(0); + const androidChildKey = await androidKey.derive2(0); expect(androidChildKey.toBytes()).toStrictEqual(androidWalletPrivKeyBytes); expect(androidChildKey.publicKey.toBytes()).toStrictEqual(androidWalletPubKeyBytes); diff --git a/src/crypto/Ed25519PrivateKey.ts b/src/crypto/Ed25519PrivateKey.ts index 7e1acc6e1..619ff8e81 100644 --- a/src/crypto/Ed25519PrivateKey.ts +++ b/src/crypto/Ed25519PrivateKey.ts @@ -5,8 +5,7 @@ import { arraysEqual, deriveChildKey, deriveChildKey2, - ed25519PrivKeyPrefix, - randomBytes + ed25519PrivKeyPrefix } from "./util"; import { RawKeyPair } from "./RawKeyPair"; import { createKeystore, loadKeystore } from "./Keystore"; @@ -168,8 +167,9 @@ export class Ed25519PrivateKey { * * This key will _not_ support child key derivation. */ + // eslint-disable-next-line require-await public static async generate(): Promise { - return this.fromBytes(await randomBytes(32)); + return this.fromBytes(nacl.randomBytes(32)); } /** diff --git a/src/crypto/Keystore.ts b/src/crypto/Keystore.ts index 8d35de181..f9217cf6d 100644 --- a/src/crypto/Keystore.ts +++ b/src/crypto/Keystore.ts @@ -1,6 +1,5 @@ import * as crypto from "crypto"; import * as nacl from "tweetnacl"; -import { randomBytes } from "./util"; import { RawKeyPair } from "./RawKeyPair"; import { KeyMismatchError } from "./KeyMismatchError"; import * as hex from "@stablelib/hex"; @@ -45,11 +44,11 @@ export async function createKeystore( const dkLen = 32; const c = 262144; const saltLen = 32; - const salt = await randomBytes(saltLen); + const salt = nacl.randomBytes(saltLen); const key = await Pbkdf2.deriveKey(HashAlgorithm.Sha256, passphrase, salt, c, dkLen); - const iv = await randomBytes(16); + const iv = nacl.randomBytes(16); // AES-128-CTR with the first half of the derived key and a random IV const cipher = crypto.createCipheriv(AES_128_CTR, key.slice(0, 16), iv); diff --git a/src/crypto/util.ts b/src/crypto/util.ts index ec1340cab..29011d071 100644 --- a/src/crypto/util.ts +++ b/src/crypto/util.ts @@ -1,9 +1,6 @@ import * as crypto from "crypto"; -import { promisify } from "util"; import { Hmac, HashAlgorithm } from "./Hmac"; -export const randomBytes = promisify(crypto.randomBytes); - // we could go through the whole BS of producing a DER-encoded structure but it's quite simple // for Ed25519 keys and we don't have to shell out to a potentially broken lib // https://github.com/PeculiarVentures/pvutils/issues/8