UNPKG

@sebastianp265/safe-server-side-storage-client

Version:

Library for Confidential Server-Side Message Storage Using the Labyrinth Protocol

22 lines (21 loc) 937 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.KEY_LENGTH_BYTES = void 0; exports.kdfOneKey = kdfOneKey; exports.kdfTwoKeys = kdfTwoKeys; const sha256_1 = require("@noble/hashes/sha256"); const hkdf_1 = require("@noble/hashes/hkdf"); exports.KEY_LENGTH_BYTES = sha256_1.sha256.outputLen; function kdfOneKey(ikm, salt, info, key_length = exports.KEY_LENGTH_BYTES) { return hkdfSHA256(ikm, salt, info, key_length); } function kdfTwoKeys(ikm, salt, info, first_key_length = exports.KEY_LENGTH_BYTES, second_key_length = exports.KEY_LENGTH_BYTES) { const full_key = hkdfSHA256(ikm, salt, info, first_key_length + second_key_length); return [ full_key.subarray(0, first_key_length), full_key.subarray(first_key_length), ]; } function hkdfSHA256(ikm, salt, info, keyLength) { return (0, hkdf_1.hkdf)(sha256_1.sha256, ikm, salt ?? new Uint8Array(0), info, keyLength); }