INNER CODE UNIT · TypeScript
deriveMatryoshkaKeys
backbone-hq/minibone · src/core.ts:96
export async function deriveMatryoshkaKeys(masterKey: Uint8Array, outputLengths: number[]): Promise<Uint8Array[]> {
let secretState = masterKey
const secretStateLength = secretState.length
const outputs: Uint8Array[] = []
for (const outputLength of outputLengths) {
const extendedOutputLength = secretStateLength + outputLength
const derivedBytes = await deriveKey(secretState, extendedOutputLength)
const newSecretMaterial = derivedBytes.slice(0, secretStateLength)
const derivedValue = derivedBytes.slice(secretStateLength, secretStateLength + outputLength)
secretState = newSecretMaterial
outputs.push(derivedValue)
}
return outputs
}