From d7cdaaf316d4d26ed44860701376d18030030708 Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Wed, 21 Jun 2023 04:32:21 -0400 Subject: [PATCH] feat: add deriveChildKey function --- src/index.ts | 1 + src/keys.ts | 11 +++++++++++ 2 files changed, 12 insertions(+) create mode 100644 src/keys.ts diff --git a/src/index.ts b/src/index.ts index 9e7c71e..a6b27fd 100644 --- a/src/index.ts +++ b/src/index.ts @@ -9,4 +9,5 @@ export * from "./stringifyJSON.js"; export * from "./types.js"; export * from "./cid.js"; export * from "./encoding.js"; +export * from "./keys.js"; export { ed25519, sha512 }; diff --git a/src/keys.ts b/src/keys.ts new file mode 100644 index 0000000..83e3e25 --- /dev/null +++ b/src/keys.ts @@ -0,0 +1,11 @@ +import { blake3 } from "@noble/hashes/blake3"; +import { concatBytes } from "@noble/hashes/utils"; + +export function deriveChildKey( + parentKey: Uint8Array, + tweak: string, +): Uint8Array { + const tweakHash = blake3(tweak); + + return blake3(concatBytes(parentKey, tweakHash)); +}