CodeSampleX

サンプル

buffer-from 1.1.2: bufferFrom

検証済みサンプル — npm buffer-from 1.1.2: bufferFrom. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: bufferFrom creates Buffer from string with default…

sha256:fe4ea08ad3f6850bcff5e2a6b9dbc13ed00d62d500f2c98d6cad96d16ab5a6c0

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 MIT-0

実行証拠

宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。

証拠の基準
署名済みコントラクト合格
検証レシート
2
ビルドした署名鍵
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
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-07

ケース

HOW
ゴール
verify pkg:npm/buffer-from@1.1.2
パッケージ
シンボル
  • bufferFrom
作成日
2026-08-26T09:14:34Z

コントラクト

  1. bufferFrom creates Buffer from string with default utf-8 encoding
  2. bufferFrom creates Buffer from string with custom encoding like hex and base64
  3. bufferFrom creates Buffer from array of byte values
  4. bufferFrom creates Buffer from existing Buffer making a copy
  5. bufferFrom creates Buffer from ArrayBuffer with offset and length slicing
  6. bufferFrom throws TypeError when value is a number
  7. bufferFrom throws TypeError when encoding is invalid
  8. bufferFrom throws RangeError when ArrayBuffer offset or length is out of bounds

ファイル

  • PROMPT.md
  • csx.json
  • 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/buffer-from@1.1.2
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/buffer-from@1.1.2
Demonstrate these symbols/APIs:
  - bufferFrom

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:b6013ceeb11829d4e3316de54d4782829f32fe434f115fb36b42507b597f7c0a","contract":["bufferFrom creates Buffer from string with default utf-8 encoding","bufferFrom creates Buffer from string with custom encoding like hex and base64","bufferFrom creates Buffer from array of byte values","bufferFrom creates Buffer from existing Buffer making a copy","bufferFrom creates Buffer from ArrayBuffer with offset and length slicing","bufferFrom throws TypeError when value is a number","bufferFrom throws TypeError when encoding is invalid","bufferFrom throws RangeError when ArrayBuffer offset or length is out of bounds"],"goal":"verify pkg:npm/buffer-from@1.1.2","kind":"HOW","packages":["pkg:npm/buffer-from@1.1.2"],"schemaVersion":1,"symbols":["bufferFrom"]},"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/buffer-from@1.1.2"],"schemaVersion":1,"subject":"pkg:npm/buffer-from@1.1.2","symbols":["bufferFrom"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "buffer-from-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "buffer-from-verification",
      "version": "1.0.0",
      "dependencies": {
        "buffer-from": "1.1.2"
      }
    },
    "node_modules/buffer-from": {
      "version": "1.1.2",
      "resolved": "https://registry.npmjs.org/buffer-from/-/buffer-from-1.1.2.tgz",
      "integrity": "sha512-E+XQCRwSbaaiChtv6k6Dwgc+bx+Bs6vuKJHHl5kox/BaKbhiXzqQOwK4cO22yElGp2OCmjwVhT3HmxgyPGnJfQ==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "buffer-from-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for buffer-from",
  "dependencies": {
    "buffer-from": "1.1.2"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/buffer-from@1.1.2",
  "kind": "HOW",
  "packages": [
    "pkg:npm/buffer-from@1.1.2"
  ],
  "symbols": [
    "bufferFrom"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import bufferFrom from 'buffer-from';

// 1. bufferFrom creates Buffer from string with default utf-8 encoding
const strBuf = bufferFrom('hello world');
assert.ok(Buffer.isBuffer(strBuf));
assert.strictEqual(strBuf.toString('utf8'), 'hello world');
assert.strictEqual(strBuf.length, 11);

// 2. bufferFrom creates Buffer from string with custom encoding like hex and base64
const hexBuf = bufferFrom('68656c6c6f', 'hex');
assert.strictEqual(hexBuf.toString('utf8'), 'hello');
const b64Buf = bufferFrom('aGVsbG8=', 'base64');
assert.strictEqual(b64Buf.toString('utf8'), 'hello');

// 3. bufferFrom creates Buffer from array of byte values
const arrBuf = bufferFrom([104, 101, 108, 108, 111]);
assert.ok(Buffer.isBuffer(arrBuf));
assert.strictEqual(arrBuf.toString('utf8'), 'hello');
assert.strictEqual(arrBuf.length, 5);

// 4. bufferFrom creates Buffer from existing Buffer making a copy
const original = Buffer.from('copy-test');
const copied = bufferFrom(original);
assert.ok(Buffer.isBuffer(copied));
assert.strictEqual(copied.toString('utf8'), 'copy-test');
original[0] = 0x78; // mutate original to ensure independent copy
assert.strictEqual(copied.toString('utf8'), 'copy-test');

// 5. bufferFrom creates Buffer from ArrayBuffer with offset and length slicing
const ab = new Uint8Array([1, 2, 3, 4, 5, 6]).buffer;
const abBuf = bufferFrom(ab, 2, 3);
assert.ok(Buffer.isBuffer(abBuf));
assert.strictEqual(abBuf.length, 3);
assert.deepStrictEqual(Array.from(abBuf), [3, 4, 5]);

// 6. bufferFrom throws TypeError when value is a number
assert.throws(
  () => bufferFrom(123),
  {
    name: 'TypeError',
    message: '"value" argument must not be a number'
  }
);

// 7. bufferFrom throws TypeError when encoding is invalid
assert.throws(
  () => bufferFrom('test', 'invalid-encoding-xyz'),
  {
    name: 'TypeError',
    message: '"encoding" must be a valid string encoding'
  }
);

// 8. bufferFrom throws RangeError when ArrayBuffer offset or length is out of bounds
assert.throws(
  () => bufferFrom(new ArrayBuffer(8), 10),
  {
    name: 'RangeError',
    message: "'offset' is out of bounds"
  }
);
assert.throws(
  () => bufferFrom(new ArrayBuffer(8), 2, 10),
  {
    name: 'RangeError',
    message: "'length' is out of bounds"
  }
);

console.log('Contract passed');

オリジンシーダー

匿名