UNPKG

ts-mls

Version:

[![CI](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml/badge.svg)](https://github.com/LukaJCB/ts-mls/actions/workflows/ci.yml) [![npm version](https://badge.fury.io/js/ts-mls.svg)](https://badge.fury.io/js/ts-mls) [![Coverage Status](https://co

21 lines 1.07 kB
import { deriveSecret } from "./crypto/kdf.js"; import { leafToNodeIndex, toLeafIndex } from "./treemath.js"; /** * Merges PrivateKeyPaths, BEWARE, if there is a conflict, this function will prioritize the second `b` parameter */ export function mergePrivateKeyPaths(a, b) { return { ...a, privateKeys: { ...a.privateKeys, ...b.privateKeys } }; } export function updateLeafKey(path, newKey) { return { ...path, privateKeys: { ...path.privateKeys, [leafToNodeIndex(toLeafIndex(path.leafIndex))]: newKey } }; } export async function toPrivateKeyPath(pathSecrets, leafIndex, cs) { const asArray = await Promise.all(Object.entries(pathSecrets).map(async ([nodeIndex, pathSecret]) => { const nodeSecret = await deriveSecret(pathSecret, "node", cs.kdf); const { privateKey } = await cs.hpke.deriveKeyPair(nodeSecret); return [Number(nodeIndex), await cs.hpke.exportPrivateKey(privateKey)]; })); const privateKeys = Object.fromEntries(asArray); return { leafIndex, privateKeys }; } //# sourceMappingURL=privateKeyPath.js.map