Auto-commit 2026-04-29 16:31
This commit is contained in:
46
node_modules/@panva/hkdf/dist/web/index.js
generated
vendored
Normal file
46
node_modules/@panva/hkdf/dist/web/index.js
generated
vendored
Normal file
@@ -0,0 +1,46 @@
|
||||
import derive from './runtime/hkdf.js';
|
||||
function normalizeDigest(digest) {
|
||||
switch (digest) {
|
||||
case 'sha256':
|
||||
case 'sha384':
|
||||
case 'sha512':
|
||||
case 'sha1':
|
||||
return digest;
|
||||
default:
|
||||
throw new TypeError('unsupported "digest" value');
|
||||
}
|
||||
}
|
||||
function normalizeUint8Array(input, label) {
|
||||
if (typeof input === 'string')
|
||||
return new TextEncoder().encode(input);
|
||||
if (!(input instanceof Uint8Array))
|
||||
throw new TypeError(`"${label}"" must be an instance of Uint8Array or a string`);
|
||||
return input;
|
||||
}
|
||||
function normalizeIkm(input) {
|
||||
const ikm = normalizeUint8Array(input, 'ikm');
|
||||
if (!ikm.byteLength)
|
||||
throw new TypeError(`"ikm" must be at least one byte in length`);
|
||||
return ikm;
|
||||
}
|
||||
function normalizeInfo(input) {
|
||||
const info = normalizeUint8Array(input, 'info');
|
||||
if (info.byteLength > 1024) {
|
||||
throw TypeError('"info" must not contain more than 1024 bytes');
|
||||
}
|
||||
return info;
|
||||
}
|
||||
function normalizeKeylen(input, digest) {
|
||||
if (typeof input !== 'number' || !Number.isInteger(input) || input < 1) {
|
||||
throw new TypeError('"keylen" must be a positive integer');
|
||||
}
|
||||
const hashlen = parseInt(digest.substr(3), 10) >> 3 || 20;
|
||||
if (input > 255 * hashlen) {
|
||||
throw new TypeError('"keylen" too large');
|
||||
}
|
||||
return input;
|
||||
}
|
||||
async function hkdf(digest, ikm, salt, info, keylen) {
|
||||
return derive(normalizeDigest(digest), normalizeIkm(ikm), normalizeUint8Array(salt, 'salt'), normalizeInfo(info), normalizeKeylen(keylen, digest));
|
||||
}
|
||||
export { hkdf, hkdf as default };
|
||||
1
node_modules/@panva/hkdf/dist/web/package.json
generated
vendored
Normal file
1
node_modules/@panva/hkdf/dist/web/package.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"type":"module","sideEffects":false}
|
||||
18
node_modules/@panva/hkdf/dist/web/runtime/hkdf.js
generated
vendored
Normal file
18
node_modules/@panva/hkdf/dist/web/runtime/hkdf.js
generated
vendored
Normal file
@@ -0,0 +1,18 @@
|
||||
const getGlobal = () => {
|
||||
if (typeof globalThis !== 'undefined')
|
||||
return globalThis;
|
||||
if (typeof self !== 'undefined')
|
||||
return self;
|
||||
if (typeof window !== 'undefined')
|
||||
return window;
|
||||
throw new Error('unable to locate global object');
|
||||
};
|
||||
export default async (digest, ikm, salt, info, keylen) => {
|
||||
const { crypto: { subtle }, } = getGlobal();
|
||||
return new Uint8Array(await subtle.deriveBits({
|
||||
name: 'HKDF',
|
||||
hash: `SHA-${digest.substr(3)}`,
|
||||
salt,
|
||||
info,
|
||||
}, await subtle.importKey('raw', ikm, 'HKDF', false, ['deriveBits']), keylen << 3));
|
||||
};
|
||||
Reference in New Issue
Block a user