샘플
jose 6.2.4: generateKeyPair
검증된 샘플 — npm jose 6.2.4: generateKeyPair. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: generateKeyPair generates RSA key pair (RS256, RS384…
sha256:0b8bf9ad97763749b763a64ef8e5844daf463e38b320a7f484bf7ca001595ebd
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
MIT-0
실행 증거
선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.
- 증거 기준
- 서명된 컨트랙트 통과
- 검증 영수증
- 1
- 빌드한 서명 키
- 1
선언된 환경
linux 24 · ubuntu · glibc 2.39 x64 npm
검증 실행 환경
| 환경 | 컨트랙트 | 단계 | 실행일 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-28 |
케이스
HOW- 목표
- verify jose.generateKeyPair in pkg:npm/jose@6.2.4
- 패키지
- 심벌
-
- jose.generateKeyPair
- 생성일
- 2026-08-28T03:24:57Z
컨트랙트
- generateKeyPair generates RSA key pair (RS256, RS384, RS512, PS256, PS384, PS512) with configurable modulusLength compatible with SignJWT and jwtVerify
- generateKeyPair generates Elliptic Curve key pair (ES256, ES384, ES512) compatible with SignJWT and jwtVerify
- generateKeyPair generates Edwards-curve / OKP key pair (EdDSA with Ed25519) compatible with CompactSign and compactVerify
- generateKeyPair generates key pair for asymmetric encryption (RSA-OAEP-256, ECDH-ES with P-256 and X25519) compatible with CompactEncrypt and compactDecrypt
- generateKeyPair respects the extractable option for privateKey export and returns CryptoKey instances with proper type and algorithm properties
- generateKeyPair rejects unsupported, invalid, or symmetric algorithm identifiers with JOSENotSupported (ERR_JOSE_NOT_SUPPORTED)
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.mjs
- test/contract.mjs
소스
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify jose.generateKeyPair in pkg:npm/jose@6.2.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/jose@6.2.4
Demonstrate these symbols/APIs:
- jose.generateKeyPair
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:ea1e31c2c8cca312acb527b7ccc25bcee99a8a154761fe99865ccfa5cdea4fb0","contract":["generateKeyPair generates RSA key pair (RS256, RS384, RS512, PS256, PS384, PS512) with configurable modulusLength compatible with SignJWT and jwtVerify","generateKeyPair generates Elliptic Curve key pair (ES256, ES384, ES512) compatible with SignJWT and jwtVerify","generateKeyPair generates Edwards-curve / OKP key pair (EdDSA with Ed25519) compatible with CompactSign and compactVerify","generateKeyPair generates key pair for asymmetric encryption (RSA-OAEP-256, ECDH-ES with P-256 and X25519) compatible with CompactEncrypt and compactDecrypt","generateKeyPair respects the extractable option for privateKey export and returns CryptoKey instances with proper type and algorithm properties","generateKeyPair rejects unsupported, invalid, or symmetric algorithm identifiers with JOSENotSupported (ERR_JOSE_NOT_SUPPORTED)"],"goal":"verify jose.generateKeyPair in pkg:npm/jose@6.2.4","kind":"HOW","packages":["pkg:npm/jose@6.2.4"],"schemaVersion":1,"symbols":["jose.generateKeyPair"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/jose@6.2.4"],"schemaVersion":1,"subject":"pkg:npm/jose@6.2.4","symbols":["jose.generateKeyPair"],"verifierAdapter":"node-typescript@1"}
{
"name": "verify-jose-generate-key-pair",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "verify-jose-generate-key-pair",
"version": "1.0.0",
"dependencies": {
"jose": "6.2.4"
}
},
"node_modules/jose": {
"version": "6.2.4",
"resolved": "https://registry.npmjs.org/jose/-/jose-6.2.4.tgz",
"integrity": "sha512-N8acGzVsQy6M/fjFcxtysNc4Q379TcM5dM/qKkNtsHFji88yANnXTr7BLeP75iPnFwBfQzM/jg2BZ9+HZrHCZA==",
"license": "MIT",
"funding": {
"url": "https://github.com/sponsors/panva"
}
}
}
}
{
"name": "verify-jose-generate-key-pair",
"version": "1.0.0",
"private": true,
"type": "module",
"dependencies": {
"jose": "6.2.4"
}
}
{
"schemaVersion": 1,
"goal": "verify jose.generateKeyPair in pkg:npm/jose@6.2.4",
"kind": "HOW",
"packages": [
"pkg:npm/jose@6.2.4"
],
"symbols": [
"jose.generateKeyPair"
]
}
import { generateKeyPair, exportJWK, exportPKCS8, exportSPKI } from 'jose';
/**
* Generates an asymmetric public/private key pair for a given algorithm.
*
* @param {string} alg - JWA asymmetric algorithm identifier (e.g. 'RS256', 'PS256', 'ES256', 'EdDSA', 'ECDH-ES')
* @param {object} [options] - Key generation options
* @param {boolean} [options.extractable] - Whether keys are extractable
* @param {number} [options.modulusLength] - Modulus length for RSA algorithms
* @param {string} [options.crv] - Named curve for EC/OKP algorithms
* @returns {Promise<{ publicKey: CryptoKey, privateKey: CryptoKey }>}
*/
export async function createKeyPair(alg, options) {
return generateKeyPair(alg, options);
}
/**
* Exports a key to JSON Web Key (JWK) representation.
*
* @param {CryptoKey} key - The key to export
* @returns {Promise<import('jose').JWK>}
*/
export async function exportKeyJWK(key) {
return exportJWK(key);
}
export { generateKeyPair, exportJWK, exportPKCS8, exportSPKI };
export default generateKeyPair;
import assert from 'node:assert/strict';
import { generateKeyPair, SignJWT, jwtVerify, CompactSign, compactVerify, CompactEncrypt, compactDecrypt, exportJWK, errors } from 'jose';
import { createKeyPair, exportKeyJWK } from '../src/index.mjs';
const encoder = new TextEncoder();
const decoder = new TextDecoder();
// 1. generateKeyPair generates RSA key pair (RS256, RS384, RS512, PS256, PS384, PS512) with configurable modulusLength compatible with SignJWT and jwtVerify
{
const rsaAlgs = ['RS256', 'RS384', 'RS512', 'PS256', 'PS384', 'PS512'];
for (const alg of rsaAlgs) {
const { publicKey, privateKey } = await createKeyPair(alg, { modulusLength: 2048 });
assert.equal(typeof publicKey, 'object');
assert.equal(typeof privateKey, 'object');
assert.equal(publicKey.type, 'public');
assert.equal(privateKey.type, 'private');
const expectedName = alg.startsWith('PS') ? 'RSA-PSS' : 'RSASSA-PKCS1-v1_5';
assert.equal(publicKey.algorithm.name, expectedName);
assert.equal(publicKey.algorithm.modulusLength, 2048);
const token = await new SignJWT({ user: 'rsa-test', alg })
.setProtectedHeader({ alg })
.sign(privateKey);
assert.equal(typeof token, 'string');
const { payload, protectedHeader } = await jwtVerify(token, publicKey);
assert.equal(payload.user, 'rsa-test');
assert.equal(payload.alg, alg);
assert.equal(protectedHeader.alg, alg);
}
}
// 2. generateKeyPair generates Elliptic Curve key pair (ES256, ES384, ES512) compatible with SignJWT and jwtVerify
{
const ecConfigs = [
{ alg: 'ES256', namedCurve: 'P-256' },
{ alg: 'ES384', namedCurve: 'P-384' },
{ alg: 'ES512', namedCurve: 'P-521' },
];
for (const { alg, namedCurve } of ecConfigs) {
const { publicKey, privateKey } = await generateKeyPair(alg);
assert.equal(publicKey.type, 'public');
assert.equal(privateKey.type, 'private');
assert.equal(publicKey.algorithm.name, 'ECDSA');
assert.equal(publicKey.algorithm.namedCurve, namedCurve);
const token = await new SignJWT({ user: 'ec-test', namedCurve })
.setProtectedHeader({ alg })
.sign(privateKey);
const { payload, protectedHeader } = await jwtVerify(token, publicKey);
assert.equal(payload.user, 'ec-test');
assert.equal(payload.namedCurve, namedCurve);
assert.equal(protectedHeader.alg, alg);
}
}
// 3. generateKeyPair generates Edwards-curve / OKP key pair (EdDSA with Ed25519) compatible with CompactSign and compactVerify
{
const { publicKey, privateKey } = await generateKeyPair('EdDSA', { crv: 'Ed25519' });
assert.equal(publicKey.type, 'public');
assert.equal(privateKey.type, 'private');
assert.equal(publicKey.algorithm.name, 'Ed25519');
const rawPayload = encoder.encode('eddsa compact signed message');
const jws = await new CompactSign(rawPayload)
.setProtectedHeader({ alg: 'EdDSA' })
.sign(privateKey);
assert.equal(typeof jws, 'string');
const parts = jws.split('.');
assert.equal(parts.length, 3);
const { payload: verifiedPayload, protectedHeader } = await compactVerify(jws, publicKey);
assert.equal(decoder.decode(verifiedPayload), 'eddsa compact signed message');
assert.equal(protectedHeader.alg, 'EdDSA');
}
// 4. generateKeyPair generates key pair for asymmetric encryption (RSA-OAEP-256, ECDH-ES with P-256 and X25519) compatible with CompactEncrypt and compactDecrypt
{
// RSA-OAEP-256 key pair
{
const { publicKey, privateKey } = await generateKeyPair('RSA-OAEP-256', { modulusLength: 2048 });
assert.equal(publicKey.type, 'public');
assert.equal(privateKey.type, 'private');
assert.equal(publicKey.algorithm.name, 'RSA-OAEP');
const plaintext = encoder.encode('secret rsa-oaep payload');
const jwe = await new CompactEncrypt(plaintext)
.setProtectedHeader({ alg: 'RSA-OAEP-256', enc: 'A256GCM' })
.encrypt(publicKey);
const { plaintext: decrypted, protectedHeader } = await compactDecrypt(jwe, privateKey);
assert.equal(decoder.decode(decrypted), 'secret rsa-oaep payload');
assert.equal(protectedHeader.alg, 'RSA-OAEP-256');
assert.equal(protectedHeader.enc, 'A256GCM');
}
// ECDH-ES with P-256
{
const { publicKey, privateKey } = await generateKeyPair('ECDH-ES', { crv: 'P-256' });
assert.equal(publicKey.type, 'public');
assert.equal(privateKey.type, 'private');
assert.equal(publicKey.algorithm.name, 'ECDH');
assert.equal(publicKey.algorithm.namedCurve, 'P-256');
const plaintext = encoder.encode('secret ecdh p-256 payload');
const jwe = await new CompactEncrypt(plaintext)
.setProtectedHeader({ alg: 'ECDH-ES', enc: 'A128GCM' })
.encrypt(publicKey);
const { plaintext: decrypted, protectedHeader } = await compactDecrypt(jwe, privateKey);
assert.equal(decoder.decode(decrypted), 'secret ecdh p-256 payload');
assert.equal(protectedHeader.alg, 'ECDH-ES');
}
// ECDH-ES with X25519
{
const { publicKey, privateKey } = await generateKeyPair('ECDH-ES', { crv: 'X25519' });
assert.equal(publicKey.type, 'public');
assert.equal(privateKey.type, 'private');
assert.equal(publicKey.algorithm.name, 'X25519');
const plaintext = encoder.encode('secret ecdh x25519 payload');
const jwe = await new CompactEncrypt(plaintext)
.setProtectedHeader({ alg: 'ECDH-ES', enc: 'A256GCM' })
.encrypt(publicKey);
const { plaintext: decrypted, protectedHeader } = await compactDecrypt(jwe, privateKey);
assert.equal(decoder.decode(decrypted), 'secret ecdh x25519 payload');
assert.equal(protectedHeader.alg, 'ECDH-ES');
}
}
// 5. generateKeyPair respects the extractable option for privateKey export and returns CryptoKey instances with proper type and algorithm properties
{
const extractablePair = await generateKeyPair('ES256', { extractable: true });
assert.equal(extractablePair.publicKey.extractable, true);
assert.equal(extractablePair.privateKey.extractable, true);
const publicJWK = await exportKeyJWK(extractablePair.publicKey);
assert.equal(publicJWK.kty, 'EC');
assert.equal(publicJWK.crv, 'P-256');
assert.equal(typeof publicJWK.x, 'string');
assert.equal(typeof publicJWK.y, 'string');
assert.equal(publicJWK.d, undefined);
const privateJWK = await exportKeyJWK(extractablePair.privateKey);
assert.equal(privateJWK.kty, 'EC');
assert.equal(privateJWK.crv, 'P-256');
assert.equal(typeof privateJWK.d, 'string');
const nonExtractablePair = await generateKeyPair('ES256', { extractable: false });
assert.equal(nonExtractablePair.publicKey.extractable, true);
assert.equal(nonExtractablePair.privateKey.extractable, false);
await assert.rejects(
async () => {
await exportJWK(nonExtractablePair.privateKey);
},
(err) => err instanceof TypeError
);
const defaultPair = await generateKeyPair('ES256');
assert.equal(defaultPair.privateKey.extractable, false);
}
// 6. generateKeyPair rejects unsupported, invalid, or symmetric algorithm identifiers with JOSENotSupported (ERR_JOSE_NOT_SUPPORTED)
{
await assert.rejects(
async () => {
await generateKeyPair('HS256');
},
(err) => err instanceof errors.JOSENotSupported && err.code === 'ERR_JOSE_NOT_SUPPORTED'
);
await assert.rejects(
async () => {
await generateKeyPair('A256GCM');
},
(err) => err instanceof errors.JOSENotSupported && err.code === 'ERR_JOSE_NOT_SUPPORTED'
);
await assert.rejects(
async () => {
await generateKeyPair('UNSUPPORTED_ALG');
},
(err) => err instanceof errors.JOSENotSupported && err.code === 'ERR_JOSE_NOT_SUPPORTED'
);
await assert.rejects(
async () => {
await generateKeyPair();
},
(err) => err instanceof errors.JOSENotSupported && err.code === 'ERR_JOSE_NOT_SUPPORTED'
);
}
console.log('Contract tests passed successfully.');
오리진 시더
익명