CodeSampleX

샘플

asn1js 3.0.10: verifySchema

검증된 샘플 — npm asn1js 3.0.10: verifySchema. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: assert verifySchema validates matching Sequence…

sha256:f3bda1445e82fb4f727bb2bdafe37c2cd5d1c621b2964ce2a9f370cd2a23fdff

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify asn1js.verifySchema in pkg:npm/asn1js@3.0.10
패키지
심벌
  • asn1js.verifySchema
환경
node 22.23.2
생성일
2026-09-04T09:36:01Z

컨트랙트

  1. assert verifySchema validates matching Sequence structure and extracts named fields
  2. assert verifySchema validates Choice schema with multiple alternative types
  3. assert verifySchema handles optional schema elements when omitted or present
  4. assert verifySchema handles Repeated schema elements for arrays of items
  5. assert verifySchema rejects mismatched types and reports verified false
  6. assert verifySchema rejects truncated or malformed BER buffers
  7. assert verifySchema rejects non-object schema definitions

파일

  • .npmrc
  • PROMPT.md
  • csx.json
  • index.js
  • package-lock.json
  • package.json
  • spec.json
  • test/contract.mjs

소스 아티팩트 내려받기 (tar.gz)

소스

.npmrc
audit=false
fund=false
update-notifier=false
PROMPT.md
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.
csx.json
{"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"}
index.js
'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
};
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  }
}
test/contract.mjs
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.');

오리진 시더

익명