CodeSampleX

샘플

node-int64 0.4.0: Int64

검증된 샘플 — npm node-int64 0.4.0: Int64. node 22 · linux alpine/x64 · docker에서 contract를 실행해 통과했습니다: new Int64(number) converts a JavaScript number to a 64-bit…

sha256:9bb6093f86aa6e7899c2aed876490385e978917a43c3724955f557a5f0274b92

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

케이스

HOW
목표
verify pkg:npm/node-int64@0.4.0
패키지
심벌
  • Int64
생성일
2026-08-26T08:20:22Z

컨트랙트

  1. new Int64(number) converts a JavaScript number to a 64-bit integer representation
  2. new Int64(hi, lo) constructs an Int64 from high and low 32-bit integer values
  3. new Int64(string) parses a hexadecimal string into an Int64 value
  4. new Int64(buffer, offset) reads an 8-byte big-endian integer from a Buffer at the given offset
  5. Int64.prototype.toOctetString(separator) formats the 64-bit integer as an octet hex string
  6. Int64.prototype.toNumber(allowImprecise) converts to a JavaScript number or returns Infinity for values outside safe integer precision
  7. Int64.prototype.toBuffer() returns an 8-byte Buffer copy containing the raw int64 bytes
  8. Int64.prototype.copy(targetBuffer, targetOffset) writes the 8 int64 bytes into a destination buffer
  9. Int64.prototype.compare(other) and equals(other) perform signed 64-bit integer comparisons

파일

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

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

소스

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 pkg:npm/node-int64@0.4.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/node-int64@0.4.0
Demonstrate these symbols/APIs:
  - Int64

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:9e301c89115a0d3f104c76d13997830b8e2b9c13e6c9a10abd77f21a12d8383c","contract":["new Int64(number) converts a JavaScript number to a 64-bit integer representation","new Int64(hi, lo) constructs an Int64 from high and low 32-bit integer values","new Int64(string) parses a hexadecimal string into an Int64 value","new Int64(buffer, offset) reads an 8-byte big-endian integer from a Buffer at the given offset","Int64.prototype.toOctetString(separator) formats the 64-bit integer as an octet hex string","Int64.prototype.toNumber(allowImprecise) converts to a JavaScript number or returns Infinity for values outside safe integer precision","Int64.prototype.toBuffer() returns an 8-byte Buffer copy containing the raw int64 bytes","Int64.prototype.copy(targetBuffer, targetOffset) writes the 8 int64 bytes into a destination buffer","Int64.prototype.compare(other) and equals(other) perform signed 64-bit integer comparisons"],"goal":"verify pkg:npm/node-int64@0.4.0","kind":"HOW","packages":["pkg:npm/node-int64@0.4.0"],"schemaVersion":1,"symbols":["Int64"]},"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/node-int64@0.4.0"],"schemaVersion":1,"subject":"pkg:npm/node-int64@0.4.0","symbols":["Int64"],"verifierAdapter":"node-typescript@1"}
index.mjs
import Int64 from 'node-int64';

export function createInt64(value, low) {
  if (low !== undefined) {
    return new Int64(value, low);
  }
  return new Int64(value);
}

export function fromBuffer(buf, offset = 0) {
  return new Int64(buf, offset);
}

export function formatHex(int64, sep = '') {
  return int64.toOctetString(sep);
}

export function toNativeNumber(int64, allowImprecise = false) {
  return int64.toNumber(allowImprecise);
}

export function compareInt64(a, b) {
  return a.compare(b);
}

export function equalsInt64(a, b) {
  return a.equals(b);
}

export { Int64 };
package-lock.json
{
  "name": "sample-node-int64",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-node-int64",
      "version": "1.0.0",
      "dependencies": {
        "node-int64": "0.4.0"
      }
    },
    "node_modules/node-int64": {
      "version": "0.4.0",
      "resolved": "https://registry.npmjs.org/node-int64/-/node-int64-0.4.0.tgz",
      "integrity": "sha512-O5lz91xSOeoXP6DulyHfllpq+Eg00MWitZIbtPfoSEvqIHdl5gfcY6hYzDWnj0qD5tz52PI08u9qUvSVeUBeHw==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "sample-node-int64",
  "version": "1.0.0",
  "type": "module",
  "private": true,
  "dependencies": {
    "node-int64": "0.4.0"
  },
  "scripts": {
    "test": "node test/contract.mjs"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/node-int64@0.4.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/node-int64@0.4.0"
  ],
  "symbols": [
    "Int64"
  ]
}
test/contract.mjs
import assert from 'node:assert/strict';
import Int64 from 'node-int64';
import {
  createInt64,
  fromBuffer,
  formatHex,
  toNativeNumber,
  compareInt64,
  equalsInt64
} from '../index.mjs';

// 1. new Int64(number) converts a JavaScript number to a 64-bit integer representation
{
  const positive = createInt64(12345678);
  assert.equal(positive.toNumber(), 12345678);
  assert.equal(positive.toString(), '12345678');

  const negative = createInt64(-987654);
  assert.equal(negative.toNumber(), -987654);
  assert.equal(negative.toString(), '-987654');
}

// 2. new Int64(hi, lo) constructs an Int64 from high and low 32-bit integer values
{
  const hiLo = createInt64(0x01234567, 0x89abcdef);
  assert.equal(hiLo.toOctetString(), '0123456789abcdef');
}

// 3. new Int64(string) parses a hexadecimal string into an Int64 value
{
  const fromHexStr = createInt64('0x0123456789abcdef');
  const expected = createInt64(0x01234567, 0x89abcdef);
  assert.equal(fromHexStr.toOctetString(), '0123456789abcdef');
  assert.ok(fromHexStr.equals(expected));
}

// 4. new Int64(buffer, offset) reads an 8-byte big-endian integer from a Buffer at the given offset
{
  const raw = Buffer.from([0xaa, 0xbb, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x00]);
  const fromBuf = fromBuffer(raw, 2);
  assert.equal(fromBuf.toNumber(), 256);
  assert.equal(fromBuf.toOctetString(), '0000000000000100');
}

// 5. Int64.prototype.toOctetString(separator) formats the 64-bit integer as an octet hex string
{
  const val = createInt64(0x01234567, 0x89abcdef);
  assert.equal(formatHex(val), '0123456789abcdef');
  assert.equal(formatHex(val, ' '), '01 23 45 67 89 ab cd ef');
  assert.equal(formatHex(val, '-'), '01-23-45-67-89-ab-cd-ef');
}

// 6. Int64.prototype.toNumber(allowImprecise) converts to a JavaScript number or returns Infinity for values outside safe integer precision
{
  const safeVal = createInt64(42);
  assert.equal(toNativeNumber(safeVal), 42);

  const overflow = createInt64('7fffffffffffffff');
  assert.equal(toNativeNumber(overflow, false), Infinity);
  assert.notEqual(toNativeNumber(overflow, true), Infinity);
}

// 7. Int64.prototype.toBuffer() returns an 8-byte Buffer copy containing the raw int64 bytes
{
  const val = createInt64(0x12345678, 0x90abcdef);
  const buf = val.toBuffer();
  assert.ok(Buffer.isBuffer(buf));
  assert.equal(buf.length, 8);
  assert.equal(buf[0], 0x12);
  assert.equal(buf[7], 0xef);
}

// 8. Int64.prototype.copy(targetBuffer, targetOffset) writes the 8 int64 bytes into a destination buffer
{
  const val = createInt64(0x12345678, 0x90abcdef);
  const dest = Buffer.alloc(12, 0);
  val.copy(dest, 2);
  assert.equal(dest[2], 0x12);
  assert.equal(dest[9], 0xef);
  assert.equal(dest[0], 0);
  assert.equal(dest[10], 0);
}

// 9. Int64.prototype.compare(other) and equals(other) perform signed 64-bit integer comparisons
{
  const small = createInt64(100);
  const medium = createInt64(200);
  const duplicateSmall = createInt64(100);

  assert.ok(compareInt64(small, medium) < 0);
  assert.ok(compareInt64(medium, small) > 0);
  assert.equal(compareInt64(small, duplicateSmall), 0);

  assert.equal(equalsInt64(small, duplicateSmall), true);
  assert.equal(equalsInt64(small, medium), false);
}

console.log('Contract tests passed successfully.');

오리진 시더

익명