Files
klz-cables.com/.pnpm-store/v10/files/5e/ea7bdc5a5e97c62771b499c9ffa09b342b5f9a794747e7d66e3ba1e1fb03e2c1ce98f8ed1c0b3d143dd66e5cab822745693d0f5819de259ab48d6684eda4b2
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

35 lines
1.1 KiB
Plaintext

import { KeyObject } from 'node:crypto';
import { encode as base64url } from './base64url.js';
import { JOSENotSupported } from '../util/errors.js';
import { isCryptoKey } from './webcrypto.js';
import isKeyObject from './is_key_object.js';
import invalidKeyInput from '../lib/invalid_key_input.js';
import { types } from './is_key_like.js';
const keyToJWK = (key) => {
let keyObject;
if (isCryptoKey(key)) {
if (!key.extractable) {
throw new TypeError('CryptoKey is not extractable');
}
keyObject = KeyObject.from(key);
}
else if (isKeyObject(key)) {
keyObject = key;
}
else if (key instanceof Uint8Array) {
return {
kty: 'oct',
k: base64url(key),
};
}
else {
throw new TypeError(invalidKeyInput(key, ...types, 'Uint8Array'));
}
if (keyObject.type !== 'secret' &&
!['rsa', 'ec', 'ed25519', 'x25519', 'ed448', 'x448'].includes(keyObject.asymmetricKeyType)) {
throw new JOSENotSupported('Unsupported key asymmetricKeyType');
}
return keyObject.export({ format: 'jwk' });
};
export default keyToJWK;