Auto-commit 2026-04-29 16:31
This commit is contained in:
50
node_modules/@panva/hkdf/dist/node/cjs/index.js
generated
vendored
Normal file
50
node_modules/@panva/hkdf/dist/node/cjs/index.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
exports.default = exports.hkdf = void 0;
|
||||
const hkdf_js_1 = require("./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 (0, hkdf_js_1.default)(normalizeDigest(digest), normalizeIkm(ikm), normalizeUint8Array(salt, 'salt'), normalizeInfo(info), normalizeKeylen(keylen, digest));
|
||||
}
|
||||
exports.hkdf = hkdf;
|
||||
exports.default = hkdf;
|
||||
23
node_modules/@panva/hkdf/dist/node/cjs/runtime/fallback.js
generated
vendored
Normal file
23
node_modules/@panva/hkdf/dist/node/cjs/runtime/fallback.js
generated
vendored
Normal file
@@ -0,0 +1,23 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const crypto_1 = require("crypto");
|
||||
exports.default = (digest, ikm, salt, info, keylen) => {
|
||||
const hashlen = parseInt(digest.substr(3), 10) >> 3 || 20;
|
||||
const prk = (0, crypto_1.createHmac)(digest, salt.byteLength ? salt : new Uint8Array(hashlen))
|
||||
.update(ikm)
|
||||
.digest();
|
||||
const N = Math.ceil(keylen / hashlen);
|
||||
const T = new Uint8Array(hashlen * N + info.byteLength + 1);
|
||||
let prev = 0;
|
||||
let start = 0;
|
||||
for (let c = 1; c <= N; c++) {
|
||||
T.set(info, start);
|
||||
T[start + info.byteLength] = c;
|
||||
T.set((0, crypto_1.createHmac)(digest, prk)
|
||||
.update(T.subarray(prev, start + info.byteLength + 1))
|
||||
.digest(), start);
|
||||
prev = start;
|
||||
start += hashlen;
|
||||
}
|
||||
return T.slice(0, keylen);
|
||||
};
|
||||
16
node_modules/@panva/hkdf/dist/node/cjs/runtime/hkdf.js
generated
vendored
Normal file
16
node_modules/@panva/hkdf/dist/node/cjs/runtime/hkdf.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
"use strict";
|
||||
Object.defineProperty(exports, "__esModule", { value: true });
|
||||
const crypto = require("crypto");
|
||||
const fallback_js_1 = require("./fallback.js");
|
||||
let hkdf;
|
||||
if (typeof crypto.hkdf === 'function' && !process.versions.electron) {
|
||||
hkdf = async (...args) => new Promise((resolve, reject) => {
|
||||
crypto.hkdf(...args, (err, arrayBuffer) => {
|
||||
if (err)
|
||||
reject(err);
|
||||
else
|
||||
resolve(new Uint8Array(arrayBuffer));
|
||||
});
|
||||
});
|
||||
}
|
||||
exports.default = async (digest, ikm, salt, info, keylen) => (hkdf || fallback_js_1.default)(digest, ikm, salt, info, keylen);
|
||||
46
node_modules/@panva/hkdf/dist/node/esm/index.js
generated
vendored
Normal file
46
node_modules/@panva/hkdf/dist/node/esm/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/node/esm/package.json
generated
vendored
Normal file
1
node_modules/@panva/hkdf/dist/node/esm/package.json
generated
vendored
Normal file
@@ -0,0 +1 @@
|
||||
{"type":"module","sideEffects":false}
|
||||
21
node_modules/@panva/hkdf/dist/node/esm/runtime/fallback.js
generated
vendored
Normal file
21
node_modules/@panva/hkdf/dist/node/esm/runtime/fallback.js
generated
vendored
Normal file
@@ -0,0 +1,21 @@
|
||||
import { createHmac } from 'crypto';
|
||||
export default (digest, ikm, salt, info, keylen) => {
|
||||
const hashlen = parseInt(digest.substr(3), 10) >> 3 || 20;
|
||||
const prk = createHmac(digest, salt.byteLength ? salt : new Uint8Array(hashlen))
|
||||
.update(ikm)
|
||||
.digest();
|
||||
const N = Math.ceil(keylen / hashlen);
|
||||
const T = new Uint8Array(hashlen * N + info.byteLength + 1);
|
||||
let prev = 0;
|
||||
let start = 0;
|
||||
for (let c = 1; c <= N; c++) {
|
||||
T.set(info, start);
|
||||
T[start + info.byteLength] = c;
|
||||
T.set(createHmac(digest, prk)
|
||||
.update(T.subarray(prev, start + info.byteLength + 1))
|
||||
.digest(), start);
|
||||
prev = start;
|
||||
start += hashlen;
|
||||
}
|
||||
return T.slice(0, keylen);
|
||||
};
|
||||
14
node_modules/@panva/hkdf/dist/node/esm/runtime/hkdf.js
generated
vendored
Normal file
14
node_modules/@panva/hkdf/dist/node/esm/runtime/hkdf.js
generated
vendored
Normal file
@@ -0,0 +1,14 @@
|
||||
import * as crypto from 'crypto';
|
||||
import fallback from './fallback.js';
|
||||
let hkdf;
|
||||
if (typeof crypto.hkdf === 'function' && !process.versions.electron) {
|
||||
hkdf = async (...args) => new Promise((resolve, reject) => {
|
||||
crypto.hkdf(...args, (err, arrayBuffer) => {
|
||||
if (err)
|
||||
reject(err);
|
||||
else
|
||||
resolve(new Uint8Array(arrayBuffer));
|
||||
});
|
||||
});
|
||||
}
|
||||
export default async (digest, ikm, salt, info, keylen) => (hkdf || fallback)(digest, ikm, salt, info, keylen);
|
||||
2
node_modules/@panva/hkdf/dist/types/index.d.ts
generated
vendored
Normal file
2
node_modules/@panva/hkdf/dist/types/index.d.ts
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
declare function hkdf(digest: 'sha256' | 'sha384' | 'sha512' | 'sha1' | string, ikm: Uint8Array | string, salt: Uint8Array | string, info: Uint8Array | string, keylen: number): Promise<Uint8Array>;
|
||||
export { hkdf, hkdf as default };
|
||||
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