2023-06-21 08:32:21 +00:00
|
|
|
import { blake3 } from "@noble/hashes/blake3";
|
|
|
|
import { concatBytes } from "@noble/hashes/utils";
|
2023-08-20 06:35:17 +00:00
|
|
|
import { hkdf } from "@noble/hashes/hkdf";
|
|
|
|
import { sha256 } from "@noble/hashes/sha256";
|
2023-06-21 08:32:21 +00:00
|
|
|
|
|
|
|
export function deriveChildKey(
|
|
|
|
parentKey: Uint8Array,
|
|
|
|
tweak: string,
|
2023-08-20 06:35:17 +00:00
|
|
|
): Uint8Array {
|
|
|
|
return hkdf(sha256, parentKey, undefined, tweak, 32);
|
|
|
|
}
|
|
|
|
|
|
|
|
export function deriveBlakeChildKey(
|
|
|
|
parentKey: Uint8Array,
|
|
|
|
tweak: string,
|
2023-06-21 08:32:21 +00:00
|
|
|
): Uint8Array {
|
|
|
|
const tweakHash = blake3(tweak);
|
|
|
|
|
|
|
|
return blake3(concatBytes(parentKey, tweakHash));
|
|
|
|
}
|