CodeSampleX

샘플

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

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

컨트랙트

  1. asn1js.Integer constructs integer ASN.1 elements and provides valueBlock.valueDec and toBigInt accessors
  2. asn1js.Integer toBER encodes integer values into BER/DER format with two's complement sign extension and zero padding
  3. asn1js.fromBER decodes BER integer buffers into asn1js.Integer instances extracting numeric and BigInt values
  4. 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

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

소스

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

오리진 시더

익명