CodeSampleX

示例

buffer-from 1.1.2: bufferFrom

已验证示例 — npm buffer-from 1.1.2: bufferFrom. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: bufferFrom creates Buffer from string with default utf-8…

sha256:fe4ea08ad3f6850bcff5e2a6b9dbc13ed00d62d500f2c98d6cad96d16ab5a6c0

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。 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');

原始种子者

匿名