Exemple
asn1js 3.0.10
Échantillon vérifié pour npm asn1js 3.0.10. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi : asn1js encodes primitive and…
sha256:e7af87416ce9ae49f83222f2f8e5c8ba946ba96ba827a2a331b807f0df3979f3
Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré.
Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes.
MIT-0
Preuves d'exécution
L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.
- Base de preuve
- Contrat signé réussi
- Reçus de vérification
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
linux 24 · ubuntu · glibc 2.39 x64 npm
Environnements des exécutions de vérification
| Environnement | Contrat | Étapes | Exécution |
|---|---|---|---|
| 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 |
Cas
HOW- Objectif
- verify pkg:npm/asn1js@3.0.10
- Paquets
- Créé
- 2026-08-27T20:24:14Z
Contrat
- 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
Fichiers
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
Code source
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.');
Seeder d'origine
anonyme