샘플
asn1js 3.0.10
검증된 샘플 — npm asn1js 3.0.10. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: asn1js encodes primitive and constructed ASN.1 structures to BER…
sha256:e7af87416ce9ae49f83222f2f8e5c8ba946ba96ba827a2a331b807f0df3979f3
이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다.
통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다.
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-27 |
케이스
HOW- 목표
- verify pkg:npm/asn1js@3.0.10
- 패키지
- 생성일
- 2026-08-27T20:24:14Z
컨트랙트
- asn1js encodes primitive and constructed ASN.1 structures to BER ArrayBuffer
- fromBER decodes BER ArrayBuffer into corresponding ASN.1 objects
- verifySchema validates BER buffers against declared ASN.1 schemas and rejects invalid buffers or mismatched schemas
파일
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
소스
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 pkg:npm/asn1js@3.0.10
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/asn1js@3.0.10
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:92cca9f7eefca5f246efa2244c4bddefd56c819a5480e0215a9c0bfa11674c16","contract":["asn1js encodes primitive and constructed ASN.1 structures to BER ArrayBuffer","fromBER decodes BER ArrayBuffer into corresponding ASN.1 objects","verifySchema validates BER buffers against declared ASN.1 schemas and rejects invalid buffers or mismatched schemas"],"goal":"verify pkg:npm/asn1js@3.0.10","kind":"HOW","packages":["pkg:npm/asn1js@3.0.10"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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/asn1js@3.0.10"],"schemaVersion":1,"subject":"pkg:npm/asn1js@3.0.10","verifierAdapter":"node-typescript@1"}
{
"name": "sample-asn1js",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-asn1js",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"asn1js": "3.0.10"
}
},
"node_modules/asn1js": {
"version": "3.0.10",
"resolved": "https://registry.npmjs.org/asn1js/-/asn1js-3.0.10.tgz",
"integrity": "sha512-S2s3aOytiKdFRdulw2qPE51MzjzVOisppcVv7jVFR+Kw0kxwvFrDcYA0h7Ndqbmj0HkMIXYWaoj7fli8kgx1eg==",
"license": "BSD-3-Clause",
"dependencies": {
"pvtsutils": "^1.3.6",
"pvutils": "^1.1.5",
"tslib": "^2.8.1"
},
"engines": {
"node": ">=12.0.0"
}
},
"node_modules/pvtsutils": {
"version": "1.3.6",
"resolved": "https://registry.npmjs.org/pvtsutils/-/pvtsutils-1.3.6.tgz",
"integrity": "sha512-PLgQXQ6H2FWCaeRak8vvk1GW462lMxB5s3Jm673N82zI4vqtVUPuZdffdZbPDFRoU8kAhItWFtPCWiPpp4/EDg==",
"license": "MIT",
"dependencies": {
"tslib": "^2.8.1"
}
},
"node_modules/pvutils": {
"version": "1.2.0",
"resolved": "https://registry.npmjs.org/pvutils/-/pvutils-1.2.0.tgz",
"integrity": "sha512-BbubeCEyTuQjVMakvJQ/Sxbc93F2pwmbsxONT/ZRrwU7Ua38d8unYTwXpTVLAKJ4BDuH9IGztCjQcd/N/39Dvg==",
"license": "MIT",
"engines": {
"node": ">=16.0.0"
}
},
"node_modules/tslib": {
"version": "2.8.1",
"resolved": "https://registry.npmjs.org/tslib/-/tslib-2.8.1.tgz",
"integrity": "sha512-oJFu94HQb+KVduSUQL7wnpmqnfmLsOA/nAh6b6EH0wCEoK0/mPeXU6c3wKDV83MkOuHPRHtSXKKU99IBazS/2w==",
"license": "0BSD"
}
}
}
{
"name": "sample-asn1js",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification sample for asn1js",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"asn1js": "3.0.10"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/asn1js@3.0.10",
"kind": "HOW",
"packages": [
"pkg:npm/asn1js@3.0.10"
]
}
'use strict';
const asn1js = require('asn1js');
/**
* Encodes structured data into an ASN.1 Sequence BER buffer.
* @param {object} options
* @param {number} options.id - Integer value
* @param {string} options.name - Utf8String value
* @param {boolean} options.active - Boolean value
* @param {Uint8Array|ArrayBuffer} [options.data] - Optional OctetString payload
* @param {string} [options.oid] - Optional ObjectIdentifier string
* @returns {ArrayBuffer} BER encoded ArrayBuffer
*/
function encodeDataSequence(options) {
const elements = [
new asn1js.Integer({ value: options.id }),
new asn1js.Utf8String({ value: options.name }),
new asn1js.Boolean({ value: options.active })
];
if (options.data) {
elements.push(new asn1js.OctetString({ valueHex: options.data }));
}
if (options.oid) {
elements.push(new asn1js.ObjectIdentifier({ value: options.oid }));
}
const seq = new asn1js.Sequence({
value: elements
});
return seq.toBER();
}
/**
* Decodes a BER ArrayBuffer and parses the structure.
* @param {ArrayBuffer|Uint8Array} inputBuffer
* @returns {{ offset: number, result: any }}
*/
function decodeBER(inputBuffer) {
return asn1js.fromBER(inputBuffer);
}
/**
* Verifies a BER buffer against a predefined ASN.1 schema.
* @param {ArrayBuffer|Uint8Array} inputBuffer
* @param {asn1js.BaseBlock} schema
* @returns {{ verified: boolean, result: any }}
*/
function validateSchema(inputBuffer, schema) {
return asn1js.verifySchema(inputBuffer, schema);
}
module.exports = {
encodeDataSequence,
decodeBER,
validateSchema,
asn1js
};
'use strict';
const assert = require('node:assert');
const asn1js = require('asn1js');
const {
encodeDataSequence,
decodeBER,
validateSchema
} = require('../src/index.js');
// 1. Primitive block construction and serialization
const intBlock = new asn1js.Integer({ value: 42 });
const strBlock = new asn1js.Utf8String({ value: 'hello asn1' });
const boolBlock = new asn1js.Boolean({ value: true });
const octetBlock = new asn1js.OctetString({ valueHex: new Uint8Array([0x01, 0x02, 0x03, 0x04]) });
const oidBlock = new asn1js.ObjectIdentifier({ value: '1.2.840.113549.1.1.1' });
assert.strictEqual(intBlock.valueBlock.valueDec, 42, 'Integer valueDec must match 42');
assert.strictEqual(strBlock.valueBlock.value, 'hello asn1', 'Utf8String value must match');
assert.strictEqual(boolBlock.valueBlock.value, true, 'Boolean value must match true');
assert.strictEqual(oidBlock.getValue(), '1.2.840.113549.1.1.1', 'ObjectIdentifier getValue must match');
// 2. Constructed Sequence encoding to BER
const seq = new asn1js.Sequence({
value: [intBlock, strBlock, boolBlock, octetBlock, oidBlock]
});
const ber = seq.toBER();
assert(ber instanceof ArrayBuffer, 'toBER must return an ArrayBuffer');
assert(ber.byteLength > 0, 'BER buffer length must be positive');
// 3. Decoding BER buffer with fromBER
const decoded = asn1js.fromBER(ber);
assert.strictEqual(decoded.offset, ber.byteLength, 'fromBER must consume the full buffer');
assert(decoded.result instanceof asn1js.Sequence, 'decoded root must be a Sequence');
assert.strictEqual(decoded.result.valueBlock.value.length, 5, 'Sequence must contain 5 elements');
const [decInt, decStr, decBool, decOctet, decOid] = decoded.result.valueBlock.value;
assert(decInt instanceof asn1js.Integer, 'first element must be Integer');
assert.strictEqual(decInt.valueBlock.valueDec, 42, 'decoded integer must be 42');
assert(decStr instanceof asn1js.Utf8String, 'second element must be Utf8String');
assert.strictEqual(decStr.valueBlock.value, 'hello asn1', 'decoded string must match');
assert(decBool instanceof asn1js.Boolean, 'third element must be Boolean');
assert.strictEqual(decBool.valueBlock.value, true, 'decoded boolean must be true');
assert(decOctet instanceof asn1js.OctetString, 'fourth element must be OctetString');
assert.deepStrictEqual(
Array.from(new Uint8Array(decOctet.valueBlock.valueHex)),
[1, 2, 3, 4],
'decoded octet string bytes must match'
);
assert(decOid instanceof asn1js.ObjectIdentifier, 'fifth element must be ObjectIdentifier');
assert.strictEqual(decOid.getValue(), '1.2.840.113549.1.1.1', 'decoded OID must match');
// 4. Schema verification with verifySchema
const schema = new asn1js.Sequence({
name: 'RootRecord',
value: [
new asn1js.Integer({ name: 'id' }),
new asn1js.Utf8String({ name: 'name' }),
new asn1js.Boolean({ name: 'active' }),
new asn1js.OctetString({ name: 'payload' }),
new asn1js.ObjectIdentifier({ name: 'algorithm' })
]
});
const schemaCheck = asn1js.verifySchema(ber, schema);
assert.strictEqual(schemaCheck.verified, true, 'verifySchema must verify matching structure');
assert.strictEqual(schemaCheck.result.id.valueBlock.valueDec, 42, 'named schema field id must match');
assert.strictEqual(schemaCheck.result.name.valueBlock.value, 'hello asn1', 'named schema field name must match');
assert.strictEqual(schemaCheck.result.active.valueBlock.value, true, 'named schema field active must match');
// 5. Incompatible schema rejection
const wrongSchema = new asn1js.Sequence({
name: 'WrongRoot',
value: [
new asn1js.Utf8String({ name: 'wrongType' })
]
});
const wrongCheck = asn1js.verifySchema(ber, wrongSchema);
assert.strictEqual(wrongCheck.verified, false, 'verifySchema must fail on mismatched schema');
// 6. Invalid / truncated BER handling
const truncated = ber.slice(0, 3);
const invalidDecode = asn1js.fromBER(truncated);
assert.strictEqual(invalidDecode.offset, -1, 'fromBER must return offset -1 on truncated buffer');
const invalidSchemaCheck = asn1js.verifySchema(truncated, schema);
assert.strictEqual(invalidSchemaCheck.verified, false, 'verifySchema must fail on invalid buffer');
// 7. Testing helper functions from src/index.js
const helperBuffer = encodeDataSequence({
id: 1001,
name: 'helper-test',
active: false,
data: new Uint8Array([0xaa, 0xbb]),
oid: '1.3.6.1.4.1'
});
assert(helperBuffer instanceof ArrayBuffer, 'encodeDataSequence must return ArrayBuffer');
const helperDecoded = decodeBER(helperBuffer);
assert.strictEqual(helperDecoded.offset, helperBuffer.byteLength, 'decodeBER must consume full buffer');
assert(helperDecoded.result instanceof asn1js.Sequence, 'decodeBER must return Sequence');
const helperSchema = new asn1js.Sequence({
name: 'HelperSeq',
value: [
new asn1js.Integer({ name: 'id' }),
new asn1js.Utf8String({ name: 'name' }),
new asn1js.Boolean({ name: 'active' }),
new asn1js.OctetString({ name: 'data' }),
new asn1js.ObjectIdentifier({ name: 'oid' })
]
});
const helperValidation = validateSchema(helperBuffer, helperSchema);
assert.strictEqual(helperValidation.verified, true, 'validateSchema must succeed');
assert.strictEqual(helperValidation.result.id.valueBlock.valueDec, 1001);
assert.strictEqual(helperValidation.result.name.valueBlock.value, 'helper-test');
assert.strictEqual(helperValidation.result.active.valueBlock.value, false);
assert.strictEqual(helperValidation.result.oid.getValue(), '1.3.6.1.4.1');
console.log('Contract tests passed successfully.');
오리진 시더
익명