示例
@peculiar/asn1-schema 2.9.4
已验证示例 — npm @peculiar/asn1-schema 2.9.4. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: assert AsnSerializer.serialize and AsnParser.parse encode and…
sha256:1ffa550956831143dd9bc1ad1293dcb1aae3c2ef524ce642ce13d2b2f822d6d3
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
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@1 |
2026-08-21 |
案例
HOW- 目标
- verify pkg:npm/%40peculiar/asn1-schema@2.9.4
- 创建时间
- 2026-08-21T07:17:22Z
契约
- assert AsnSerializer.serialize and AsnParser.parse encode and decode typed class instances with primitive and nested ASN.1 schemas
- assert AsnConvert.serialize, AsnConvert.parse, and AsnConvert.toString provide high-level DER conversion and string visualization
- assert AsnChoiceType supports CHOICE schemas with contextual tags
- assert OctetString and BitString represent binary and bitstring ASN.1 values
- assert AsnParser.parse throws an error when parsing malformed ASN.1 buffers
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- 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 pkg:npm/%40peculiar/asn1-schema@2.9.4
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/%40peculiar/asn1-schema@2.9.4
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:daba7510c3b1107fedd7e8b2204fd0bc69a079801615b85d192d24aa9b6de0d1","contract":["assert AsnSerializer.serialize and AsnParser.parse encode and decode typed class instances with primitive and nested ASN.1 schemas","assert AsnConvert.serialize, AsnConvert.parse, and AsnConvert.toString provide high-level DER conversion and string visualization","assert AsnChoiceType supports CHOICE schemas with contextual tags","assert OctetString and BitString represent binary and bitstring ASN.1 values","assert AsnParser.parse throws an error when parsing malformed ASN.1 buffers"],"goal":"verify pkg:npm/%40peculiar/asn1-schema@2.9.4","kind":"HOW","packages":["pkg:npm/%40peculiar/asn1-schema@2.9.4"],"schemaVersion":1,"symbols":["AsnChoiceType","AsnConvert.parse","AsnConvert.serialize","AsnConvert.toString","AsnParser.parse","AsnProp","AsnPropTypes","AsnSerializer.serialize","AsnType","AsnTypeTypes","BitString","OctetString"]},"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/%40peculiar/asn1-schema@2.9.4"],"schemaVersion":1,"subject":"pkg:npm/%40peculiar/asn1-schema@2.9.4","verifierAdapter":"node-typescript@1"}
{
"name": "sample-peculiar-asn1-schema",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-peculiar-asn1-schema",
"version": "1.0.0",
"dependencies": {
"@peculiar/asn1-schema": "2.9.4"
}
},
"node_modules/@peculiar/asn1-schema": {
"version": "2.9.4",
"resolved": "https://registry.npmjs.org/@peculiar/asn1-schema/-/asn1-schema-2.9.4.tgz",
"integrity": "sha512-GjzePcT9Iw8NzeOPf73iNS9xM+TBhd/FilAfP+RQGkTMQJTVWtytN3JHJACCjf/ABNau5S7mS3g+DcuxmRgYEg==",
"license": "MIT",
"dependencies": {
"@peculiar/utils": "^2.0.2",
"asn1js": "^3.0.10",
"tslib": "^2.8.1"
},
"engines": {
"node": ">=14"
}
},
"node_modules/@peculiar/utils": {
"version": "2.0.3",
"resolved": "https://registry.npmjs.org/@peculiar/utils/-/utils-2.0.3.tgz",
"integrity": "sha512-+oL3HPFRIZ1St2K50lWCXiioIgSoxzz7R1J3uF6neO2yl1sgmpgY6XXJH4BdpoDkMWznQTeYF6oWNDZLCdQ4eQ==",
"license": "MIT",
"dependencies": {
"tslib": "^2.8.1"
}
},
"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-peculiar-asn1-schema",
"version": "1.0.0",
"type": "module",
"dependencies": {
"@peculiar/asn1-schema": "2.9.4"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/%40peculiar/asn1-schema@2.9.4",
"kind": "HOW",
"packages": [
"pkg:npm/%40peculiar/asn1-schema@2.9.4"
]
}
import assert from "node:assert/strict";
import {
AsnProp,
AsnPropTypes,
AsnType,
AsnTypeTypes,
AsnChoiceType,
AsnParser,
AsnSerializer,
AsnConvert,
OctetString,
BitString,
} from "@peculiar/asn1-schema";
// 1. Nested Sequence Schema Definition
class NestedPayload {
constructor() {
this.label = "";
}
}
AsnType({ type: AsnTypeTypes.Sequence })(NestedPayload);
AsnProp({ type: AsnPropTypes.Utf8String })(NestedPayload.prototype, "label");
// Root Sequence Schema Definition
class ContainerRecord {
constructor() {
this.id = 0;
this.name = "";
this.active = false;
this.payload = new NestedPayload();
this.data = new OctetString();
this.optionalComment = undefined;
this.tags = [];
}
}
AsnType({ type: AsnTypeTypes.Sequence })(ContainerRecord);
AsnProp({ type: AsnPropTypes.Integer })(ContainerRecord.prototype, "id");
AsnProp({ type: AsnPropTypes.Utf8String })(ContainerRecord.prototype, "name");
AsnProp({ type: AsnPropTypes.Boolean })(ContainerRecord.prototype, "active");
AsnProp({ type: NestedPayload })(ContainerRecord.prototype, "payload");
AsnProp({ type: OctetString })(ContainerRecord.prototype, "data");
AsnProp({ type: AsnPropTypes.Utf8String, optional: true, context: 0, implicit: true })(ContainerRecord.prototype, "optionalComment");
AsnProp({ type: AsnPropTypes.Utf8String, repeated: "sequence", context: 1 })(ContainerRecord.prototype, "tags");
// Contract 1: AsnSerializer.serialize and AsnParser.parse encode and decode typed class instances with primitive and nested ASN.1 schemas
const record = new ContainerRecord();
record.id = 101;
record.name = "sample-record";
record.active = true;
record.payload.label = "nested-content";
record.data = new OctetString([0xde, 0xad, 0xbe, 0xef]);
record.optionalComment = "optional-info";
record.tags = ["tag-alpha", "tag-beta"];
const serializedDer = AsnSerializer.serialize(record);
assert.ok(serializedDer instanceof ArrayBuffer);
assert.ok(serializedDer.byteLength > 0);
const parsedRecord = AsnParser.parse(serializedDer, ContainerRecord);
assert.ok(parsedRecord instanceof ContainerRecord);
assert.equal(parsedRecord.id, 101);
assert.equal(parsedRecord.name, "sample-record");
assert.equal(parsedRecord.active, true);
assert.ok(parsedRecord.payload instanceof NestedPayload);
assert.equal(parsedRecord.payload.label, "nested-content");
assert.deepEqual(new Uint8Array(parsedRecord.data.buffer), new Uint8Array([0xde, 0xad, 0xbe, 0xef]));
assert.equal(parsedRecord.optionalComment, "optional-info");
assert.deepEqual(parsedRecord.tags, ["tag-alpha", "tag-beta"]);
// Contract 2: AsnConvert.serialize, AsnConvert.parse, and AsnConvert.toString provide high-level DER conversion and string visualization
const convertDer = AsnConvert.serialize(record);
assert.ok(convertDer instanceof ArrayBuffer);
const convertDecoded = AsnConvert.parse(convertDer, ContainerRecord);
assert.equal(convertDecoded.id, 101);
assert.equal(convertDecoded.name, "sample-record");
assert.equal(convertDecoded.active, true);
const derString = AsnConvert.toString(convertDer);
assert.ok(typeof derString === "string");
assert.ok(derString.length > 0);
// Contract 3: AsnChoiceType supports CHOICE schemas with contextual tags
class ChoicePayload {
constructor() {
this.textValue = undefined;
this.numericValue = undefined;
}
}
AsnChoiceType()(ChoicePayload);
AsnProp({ type: AsnPropTypes.Utf8String, context: 0 })(ChoicePayload.prototype, "textValue");
AsnProp({ type: AsnPropTypes.Integer, context: 1 })(ChoicePayload.prototype, "numericValue");
const choiceItem = new ChoicePayload();
choiceItem.textValue = "selected-text-branch";
const choiceDer = AsnConvert.serialize(choiceItem);
const decodedChoice = AsnConvert.parse(choiceDer, ChoicePayload);
assert.equal(decodedChoice.textValue, "selected-text-branch");
assert.equal(decodedChoice.numericValue, undefined);
// Contract 4: OctetString and BitString represent binary and bitstring ASN.1 values
class BinaryContainer {
constructor() {
this.octets = new OctetString();
this.bits = new BitString();
}
}
AsnType({ type: AsnTypeTypes.Sequence })(BinaryContainer);
AsnProp({ type: OctetString })(BinaryContainer.prototype, "octets");
AsnProp({ type: BitString })(BinaryContainer.prototype, "bits");
const binaryObj = new BinaryContainer();
binaryObj.octets = new OctetString(new Uint8Array([0x01, 0x02, 0x03, 0x04]));
binaryObj.bits = new BitString(new Uint8Array([0b11000000]).buffer, 2);
const binaryDer = AsnConvert.serialize(binaryObj);
const decodedBinary = AsnConvert.parse(binaryDer, BinaryContainer);
assert.deepEqual(new Uint8Array(decodedBinary.octets.buffer), new Uint8Array([0x01, 0x02, 0x03, 0x04]));
assert.equal(decodedBinary.bits.unusedBits, 2);
// Contract 5: AsnParser.parse throws an error when parsing malformed ASN.1 buffers
assert.throws(() => {
AsnParser.parse(new Uint8Array([0xff, 0xff, 0xff]), ContainerRecord);
});
console.log("Contract verified: all assertions passed.");
原始种子者
匿名