サンプル
asn1js 3.0.10: Integer
検証済みサンプル — npm asn1js 3.0.10: Integer. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: asn1js.Integer constructs integer ASN.1 elements and…
sha256:2335ee62fb18c5b61662984ebc676c044c2ca4fd33baacdf4191609b82bb1a3a
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
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.Integer in pkg:npm/asn1js@3.0.10
- パッケージ
- シンボル
-
- asn1js.Integer
- 環境
- node 22.23.2
- 作成日
- 2026-09-04T08:48:37Z
コントラクト
- asn1js.Integer constructs integer ASN.1 elements and provides valueBlock.valueDec and toBigInt accessors
- asn1js.Integer toBER encodes integer values into BER/DER format with two's complement sign extension and zero padding
- asn1js.fromBER decodes BER integer buffers into asn1js.Integer instances extracting numeric and BigInt values
- asn1js.verifySchema validates BER integer elements against asn1js.Integer schemas and rejects mismatched types
ファイル
- .npmrc
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
ソース
update-notifier=false
audit=false
fund=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.Integer 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.Integer
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:6590af4711daf51c21b6beaf9826b8be4f577466c6b7c3b43ffdaa55dcc0f1bb","constraints":{"executionContext":"node"},"contract":["asn1js.Integer constructs integer ASN.1 elements and provides valueBlock.valueDec and toBigInt accessors","asn1js.Integer toBER encodes integer values into BER/DER format with two's complement sign extension and zero padding","asn1js.fromBER decodes BER integer buffers into asn1js.Integer instances extracting numeric and BigInt values","asn1js.verifySchema validates BER integer elements against asn1js.Integer schemas and rejects mismatched types"],"goal":"verify asn1js.Integer in pkg:npm/asn1js@3.0.10","kind":"HOW","packages":["pkg:npm/asn1js@3.0.10"],"schemaVersion":1,"symbols":["asn1js.Integer"]},"contractCommand":["node","test/contract.js"],"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.Integer"],"verifierAdapter":"node-typescript@1"}
{
"name": "sample-asn1js-integer",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-asn1js-integer",
"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-integer",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification sample for asn1js.Integer",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"asn1js": "3.0.10"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify asn1js.Integer in pkg:npm/asn1js@3.0.10",
"kind": "HOW",
"packages": [
"pkg:npm/asn1js@3.0.10"
],
"symbols": [
"asn1js.Integer"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const asn1js = require('asn1js');
/**
* Creates an ASN.1 Integer instance.
* @param {number} value
* @returns {asn1js.Integer}
*/
function createInteger(value) {
return new asn1js.Integer({ value });
}
/**
* Encodes an integer value into a BER ArrayBuffer.
* @param {number} value
* @returns {ArrayBuffer}
*/
function encodeInteger(value) {
const intBlock = new asn1js.Integer({ value });
return intBlock.toBER();
}
/**
* Decodes a BER buffer into an asn1js.Integer instance and returns its BigInt value.
* @param {ArrayBuffer|Uint8Array} inputBuffer
* @returns {bigint}
*/
function decodeInteger(inputBuffer) {
const decoded = asn1js.fromBER(inputBuffer);
if (decoded.offset === -1) {
throw new Error('Failed to decode BER buffer');
}
if (!(decoded.result instanceof asn1js.Integer)) {
throw new TypeError('Decoded block is not an ASN.1 Integer');
}
return decoded.result.toBigInt();
}
/**
* Creates an Integer schema element for structure validation.
* @param {string} name
* @returns {asn1js.Integer}
*/
function createIntegerSchema(name) {
return new asn1js.Integer({ name });
}
/**
* Verifies a BER buffer against a schema.
* @param {ArrayBuffer|Uint8Array} inputBuffer
* @param {asn1js.BaseBlock} schema
* @returns {{ verified: boolean, result: any }}
*/
function verifyIntegerSchema(inputBuffer, schema) {
return asn1js.verifySchema(inputBuffer, schema);
}
module.exports = {
createInteger,
encodeInteger,
decodeInteger,
createIntegerSchema,
verifyIntegerSchema,
asn1js
};
'use strict';
const assert = require('node:assert');
const asn1js = require('asn1js');
const {
createInteger,
encodeInteger,
decodeInteger,
createIntegerSchema,
verifyIntegerSchema
} = require('../src/index.js');
// 1. Integer element construction and accessors (valueDec, toBigInt)
const intZero = new asn1js.Integer({ value: 0 });
assert.strictEqual(intZero.valueBlock.valueDec, 0, 'intZero valueDec must be 0');
assert.strictEqual(intZero.toBigInt(), 0n, 'intZero toBigInt() must be 0n');
const intPositive = new asn1js.Integer({ value: 42 });
assert.strictEqual(intPositive.valueBlock.valueDec, 42, 'intPositive valueDec must be 42');
assert.strictEqual(intPositive.toBigInt(), 42n, 'intPositive toBigInt() must be 42n');
const intNegative = new asn1js.Integer({ value: -1 });
assert.strictEqual(intNegative.valueBlock.valueDec, -1, 'intNegative valueDec must be -1');
assert.strictEqual(intNegative.toBigInt(), -1n, 'intNegative toBigInt() must be -1n');
// 2. toBER encoding into standard BER/DER bytes
const berZero = intZero.toBER();
assert(berZero instanceof ArrayBuffer, 'toBER must return ArrayBuffer');
assert.deepStrictEqual(
Array.from(new Uint8Array(berZero)),
[0x02, 0x01, 0x00],
'BER encoding of 0 must be [0x02, 0x01, 0x00]'
);
const ber42 = intPositive.toBER();
assert.deepStrictEqual(
Array.from(new Uint8Array(ber42)),
[0x02, 0x01, 0x2a],
'BER encoding of 42 must be [0x02, 0x01, 0x2a]'
);
const berNeg1 = intNegative.toBER();
assert.deepStrictEqual(
Array.from(new Uint8Array(berNeg1)),
[0x02, 0x01, 0xff],
'BER encoding of -1 must be [0x02, 0x01, 0xff]'
);
// 128 (0x80) requires 0x00 prefix to maintain positive sign in two's complement
const int128 = new asn1js.Integer({ value: 128 });
const ber128 = int128.toBER();
assert.deepStrictEqual(
Array.from(new Uint8Array(ber128)),
[0x02, 0x02, 0x00, 0x80],
'BER encoding of 128 must be [0x02, 0x02, 0x00, 0x80]'
);
// 3. fromBER decoding into asn1js.Integer instances
const dec42 = asn1js.fromBER(ber42);
assert.strictEqual(dec42.offset, 3, 'fromBER must consume 3 bytes');
assert(dec42.result instanceof asn1js.Integer, 'decoded result must be asn1js.Integer');
assert.strictEqual(dec42.result.valueBlock.valueDec, 42, 'decoded valueDec must be 42');
assert.strictEqual(dec42.result.toBigInt(), 42n, 'decoded toBigInt() must be 42n');
const decNeg1 = asn1js.fromBER(berNeg1);
assert.strictEqual(decNeg1.offset, 3, 'fromBER must consume 3 bytes for -1');
assert(decNeg1.result instanceof asn1js.Integer, 'decoded result must be asn1js.Integer');
assert.strictEqual(decNeg1.result.valueBlock.valueDec, -1, 'decoded valueDec must be -1');
assert.strictEqual(decNeg1.result.toBigInt(), -1n, 'decoded toBigInt() must be -1n');
const dec128 = asn1js.fromBER(ber128);
assert.strictEqual(dec128.offset, 4, 'fromBER must consume 4 bytes for 128');
assert(dec128.result instanceof asn1js.Integer, 'decoded result must be asn1js.Integer');
assert.strictEqual(dec128.result.valueBlock.valueDec, 128, 'decoded valueDec must be 128');
assert.strictEqual(dec128.result.toBigInt(), 128n, 'decoded toBigInt() must be 128n');
// Invalid/truncated buffer handling
const truncated = new Uint8Array([0x02, 0x02, 0x00]).buffer;
const decTrunc = asn1js.fromBER(truncated);
assert.strictEqual(decTrunc.offset, -1, 'truncated buffer must return offset -1');
// 4. Schema verification with asn1js.verifySchema
const schema = new asn1js.Integer({ name: 'counter' });
const resValid = asn1js.verifySchema(ber42, schema);
assert.strictEqual(resValid.verified, true, 'schema verification must pass for integer buffer');
assert.strictEqual(resValid.result.counter.toBigInt(), 42n, 'schema result must contain counter with value 42n');
const wrongSchema = new asn1js.Boolean({ name: 'counter' });
const resInvalid = asn1js.verifySchema(ber42, wrongSchema);
assert.strictEqual(resInvalid.verified, false, 'schema verification must fail for mismatched type');
// 5. Helper functions from src/index.js
const created = createInteger(100);
assert(created instanceof asn1js.Integer, 'createInteger must return asn1js.Integer');
assert.strictEqual(created.toBigInt(), 100n);
const encoded = encodeInteger(100);
assert(encoded instanceof ArrayBuffer);
assert.strictEqual(decodeInteger(encoded), 100n);
const schemaHelper = createIntegerSchema('counter');
const validated = verifyIntegerSchema(encoded, schemaHelper);
assert.strictEqual(validated.verified, true);
assert.strictEqual(validated.result.counter.toBigInt(), 100n);
console.log('Contract tests passed successfully.');
オリジンシーダー
匿名