Exemplo
asn1js 3.0.10: verifySchema
Amostra verificada para npm asn1js 3.0.10: verifySchema. O contrato rodou em node 22 · linux debian/x64 · docker e passou: assert verifySchema validates…
sha256:f3bda1445e82fb4f727bb2bdafe37c2cd5d1c621b2964ce2a9f370cd2a23fdff
Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu.
Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas.
MIT-0
Evidência de execução
O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.
- Base da evidência
- Contrato assinado aprovado
- Recibos de verificação
- 1
- Chaves de assinatura que o compilaram
- 1
Ambiente declarado
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
Ambientes das execuções de verificação
| Ambiente | Contrato | Etapas | Execução |
|---|---|---|---|
| node 22 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-04 |
Caso
HOW- Objetivo
- verify asn1js.verifySchema in pkg:npm/asn1js@3.0.10
- Pacotes
- Símbolos
-
- asn1js.verifySchema
- Ambiente
- node 22.23.2
- Criado
- 2026-09-04T09:36:01Z
Contrato
- assert verifySchema validates matching Sequence structure and extracts named fields
- assert verifySchema validates Choice schema with multiple alternative types
- assert verifySchema handles optional schema elements when omitted or present
- assert verifySchema handles Repeated schema elements for arrays of items
- assert verifySchema rejects mismatched types and reports verified false
- assert verifySchema rejects truncated or malformed BER buffers
- assert verifySchema rejects non-object schema definitions
Arquivos
- .npmrc
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Código-fonte
audit=false
fund=false
update-notifier=false
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 asn1js.verifySchema in pkg:npm/asn1js@3.0.10
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/asn1js@3.0.10
Demonstrate these symbols/APIs:
- asn1js.verifySchema
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:3456aa8eff5a0dac9499163d65f0db22264f36b14681b29edf88a36f23176f12","constraints":{"executionContext":"node"},"contract":["assert verifySchema validates matching Sequence structure and extracts named fields","assert verifySchema validates Choice schema with multiple alternative types","assert verifySchema handles optional schema elements when omitted or present","assert verifySchema handles Repeated schema elements for arrays of items","assert verifySchema rejects mismatched types and reports verified false","assert verifySchema rejects truncated or malformed BER buffers","assert verifySchema rejects non-object schema definitions"],"goal":"verify asn1js.verifySchema in pkg:npm/asn1js@3.0.10","kind":"HOW","packages":["pkg:npm/asn1js@3.0.10"],"schemaVersion":1,"symbols":["asn1js.verifySchema"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","executionContext":"node","language":"javascript","libc":"glibc","libcVersion":"2.39","moduleSystem":"cjs","os":"linux","osVersionBucket":"24","packageManager":"npm","packageManagerVersion":"10.9.8","runtime":"node","runtimeVersion":"22.23.2","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/asn1js@3.0.10"],"schemaVersion":1,"subject":"pkg:npm/asn1js@3.0.10","symbols":["asn1js.verifySchema"],"verifierAdapter":"node-typescript@1"}
'use strict';
const asn1js = require('asn1js');
/**
* Validates a BER-encoded buffer against an ASN.1 schema using asn1js.verifySchema.
* @param {ArrayBuffer|Uint8Array} inputBuffer
* @param {object} schema
* @returns {{ verified: boolean, result?: any }}
*/
function validateData(inputBuffer, schema) {
return asn1js.verifySchema(inputBuffer, schema);
}
/**
* Creates an ASN.1 Sequence schema definition with optional naming.
* @param {Array<any>} elements
* @param {string} [name]
* @returns {asn1js.Sequence}
*/
function createSequenceSchema(elements, name) {
const options = { value: elements };
if (name) {
options.name = name;
}
return new asn1js.Sequence(options);
}
/**
* Creates an ASN.1 Choice schema definition.
* @param {Array<any>} choices
* @param {string} [name]
* @returns {asn1js.Choice}
*/
function createChoiceSchema(choices, name) {
const options = { value: choices };
if (name) {
options.name = name;
}
return new asn1js.Choice(options);
}
/**
* Creates an ASN.1 Sequence schema containing Repeated elements.
* @param {any} itemSchema
* @param {string} name
* @returns {asn1js.Sequence}
*/
function createRepeatedSchema(itemSchema, name) {
return new asn1js.Sequence({
value: [
new asn1js.Repeated({
name,
value: itemSchema
})
]
});
}
module.exports = {
asn1js,
verifySchema: asn1js.verifySchema,
validateData,
createSequenceSchema,
createChoiceSchema,
createRepeatedSchema
};
{
"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",
"description": "Minimal clean-room sample verifying asn1js.verifySchema in asn1js",
"main": "index.js",
"scripts": {
"test": "node test/contract.mjs"
},
"license": "MIT-0",
"dependencies": {
"asn1js": "3.0.10"
}
}
{
"schemaVersion": 1,
"goal": "verify asn1js.verifySchema in pkg:npm/asn1js@3.0.10",
"kind": "HOW",
"packages": [
"pkg:npm/asn1js@3.0.10"
],
"symbols": [
"asn1js.verifySchema"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
import assert from 'node:assert';
import * as asn1js from 'asn1js';
import sample from '../index.js';
const {
validateData,
createSequenceSchema,
createChoiceSchema,
createRepeatedSchema,
} = sample;
// 1. assert verifySchema validates matching Sequence structure and extracts named fields
const seqData = new asn1js.Sequence({
value: [
new asn1js.Integer({ value: 42 }),
new asn1js.Utf8String({ value: 'CodeSampleX' }),
new asn1js.Boolean({ value: true }),
]
});
const seqBuffer = seqData.toBER();
const seqSchema = createSequenceSchema([
new asn1js.Integer({ name: 'id' }),
new asn1js.Utf8String({ name: 'label' }),
new asn1js.Boolean({ name: 'active' }),
], 'Root');
const res1 = validateData(seqBuffer, seqSchema);
assert.strictEqual(res1.verified, true, 'Matching sequence must verify successfully');
assert.strictEqual(res1.result.id.valueBlock.valueDec, 42, 'Named field id must match');
assert.strictEqual(res1.result.label.valueBlock.value, 'CodeSampleX', 'Named field label must match');
assert.strictEqual(res1.result.active.valueBlock.value, true, 'Named field active must match');
// 2. assert verifySchema validates Choice schema with multiple alternative types
const choiceSchema = createSequenceSchema([
createChoiceSchema([
new asn1js.Integer({ name: 'numericVal' }),
new asn1js.Utf8String({ name: 'textVal' }),
])
]);
const intChoiceBuffer = new asn1js.Sequence({
value: [new asn1js.Integer({ value: 100 })]
}).toBER();
const choiceRes1 = validateData(intChoiceBuffer, choiceSchema);
assert.strictEqual(choiceRes1.verified, true, 'Choice must match Integer option');
assert.strictEqual(choiceRes1.result.numericVal.valueBlock.valueDec, 100, 'Matched choice value must be accessible');
const textChoiceBuffer = new asn1js.Sequence({
value: [new asn1js.Utf8String({ value: 'sample-text' })]
}).toBER();
const choiceRes2 = validateData(textChoiceBuffer, choiceSchema);
assert.strictEqual(choiceRes2.verified, true, 'Choice must match Utf8String option');
assert.strictEqual(choiceRes2.result.textVal.valueBlock.value, 'sample-text', 'Matched choice text must be accessible');
const invalidChoiceBuffer = new asn1js.Sequence({
value: [new asn1js.Boolean({ value: false })]
}).toBER();
const choiceRes3 = validateData(invalidChoiceBuffer, choiceSchema);
assert.strictEqual(choiceRes3.verified, false, 'Choice must reject unhandled types');
// 3. assert verifySchema handles optional schema elements when omitted or present
const optionalSchema = createSequenceSchema([
new asn1js.Integer({ name: 'mandatory' }),
new asn1js.Utf8String({ name: 'extra', optional: true }),
]);
const omittedBuffer = new asn1js.Sequence({
value: [new asn1js.Integer({ value: 7 })]
}).toBER();
const optRes1 = validateData(omittedBuffer, optionalSchema);
assert.strictEqual(optRes1.verified, true, 'Sequence with omitted optional element must verify');
assert.strictEqual(optRes1.result.mandatory.valueBlock.valueDec, 7);
assert.strictEqual(optRes1.result.extra, undefined, 'Omitted optional element should be undefined');
const presentBuffer = new asn1js.Sequence({
value: [
new asn1js.Integer({ value: 7 }),
new asn1js.Utf8String({ value: 'present-value' }),
]
}).toBER();
const optRes2 = validateData(presentBuffer, optionalSchema);
assert.strictEqual(optRes2.verified, true, 'Sequence with present optional element must verify');
assert.strictEqual(optRes2.result.mandatory.valueBlock.valueDec, 7);
assert.strictEqual(optRes2.result.extra.valueBlock.value, 'present-value');
// 4. assert verifySchema handles Repeated schema elements for arrays of items
const repeatedSchema = createRepeatedSchema(new asn1js.Integer(), 'entries');
const repeatedBuffer = new asn1js.Sequence({
value: [
new asn1js.Integer({ value: 10 }),
new asn1js.Integer({ value: 20 }),
new asn1js.Integer({ value: 30 }),
]
}).toBER();
const repRes = validateData(repeatedBuffer, repeatedSchema);
assert.strictEqual(repRes.verified, true, 'Repeated schema must verify array of matching elements');
assert.strictEqual(repRes.result.entries.length, 3, 'Repeated items length must be 3');
assert.strictEqual(repRes.result.entries[0].valueBlock.valueDec, 10);
assert.strictEqual(repRes.result.entries[1].valueBlock.valueDec, 20);
assert.strictEqual(repRes.result.entries[2].valueBlock.valueDec, 30);
// 5. assert verifySchema rejects mismatched types and reports verified false
const mismatchedSchema = createSequenceSchema([
new asn1js.Boolean({ name: 'expectedBool' }),
]);
const mismatchRes = validateData(seqBuffer, mismatchedSchema);
assert.strictEqual(mismatchRes.verified, false, 'verifySchema must return verified: false on type mismatch');
// 6. assert verifySchema rejects truncated or malformed BER buffers
const truncatedBuffer = seqBuffer.slice(0, 2);
const malformedRes = validateData(truncatedBuffer, seqSchema);
assert.strictEqual(malformedRes.verified, false, 'verifySchema must return verified: false for truncated BER data');
// 7. assert verifySchema rejects non-object schema definitions
const nonObjectRes = validateData(seqBuffer, 'invalid-schema-string');
assert.strictEqual(nonObjectRes.verified, false, 'verifySchema must reject non-object schema');
assert.strictEqual(nonObjectRes.result.error, 'Wrong ASN.1 schema type', 'Should return expected error message');
console.log('All asn1js.verifySchema contract assertions passed.');
Seeder de origem
anônimo