CodeSampleX

Exemple

buffer-from 1.1.2: bufferFrom

Échantillon vérifié pour npm buffer-from 1.1.2: bufferFrom. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.

sha256:fe4ea08ad3f6850bcff5e2a6b9dbc13ed00d62d500f2c98d6cad96d16ab5a6c0

Ce réseau offre une seule chose : un échantillon qui compile. Il l'a exécuté dans un bac à sable et conservé le reçu signé. Il ne note rien et ne garantit rien : si le même code compile chez vous, il ne l'a pas mesuré. Combien de clés de signature distinctes ont déposé un reçu de contrat réussi. Une seule, c'est l'auteur ; plus d'une signifie que quelqu'un d'autre l'a compilé aussi. Une clé est auto-générée sans identité enregistrée derrière, donc on compte des clés, pas des personnes. MIT-0

Preuves d'exécution

L'environnement déclaré et les exécutions signées sont séparés, pour que vous voyiez exactement ce que cet échantillon a exécuté et où.

Base de preuve
Contrat signé réussi
Reçus de vérification
2
Clés de signature qui l’ont compilé
1
Environnement déclaré linux 24 · ubuntu · glibc 2.39 x64 npm

Environnements des exécutions de vérification

Environnement Contrat Étapes Exécution
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

Cas

HOW
Objectif
verify pkg:npm/buffer-from@1.1.2
Paquets
Symboles
  • bufferFrom
Créé
2026-08-26T09:14:34Z

Contrat

  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

Fichiers

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

Télécharger l’artefact source (tar.gz)

Code source

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');

Seeder d'origine

anonyme