サンプル
safer-buffer 2.1.2
検証済みサンプル — npm safer-buffer 2.1.2. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: Buffer() and new Buffer() throw TypeError to prevent unsafe…
sha256:af04ae001bb8b7c1ba4fa0f7e991a32d4dfb607f8d02d6694688be4c503ede36
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。
MIT-0
実行証拠
宣言された環境と署名済みの実行を分けてあります。このサンプルが何をどこで実行したかをそのまま確認できます。
- 証拠の基準
- 署名済みコントラクト合格
- 検証レシート
- 1
- ビルドした署名鍵
- 1
宣言された環境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
検証実行環境
| 環境 | コントラクト | ステージ | 実行日 |
|---|---|---|---|
| node 22 · linux alpine/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1 |
2026-08-20 |
ケース
HOW- ゴール
- verify pkg:npm/safer-buffer@2.1.2
- パッケージ
- 環境
- node 22.23.2
- 作成日
- 2026-08-20T14:20:29Z
コントラクト
- Buffer() and new Buffer() throw TypeError to prevent unsafe direct invocation
- Buffer.alloc(size) returns a zero-filled Buffer of the requested size
- Buffer.alloc(size, fill, encoding) returns a Buffer filled with the specified pattern
- Buffer.alloc throws TypeError for non-numeric size and RangeError for negative size
- Buffer.from(string, encoding) returns a Buffer containing encoded string bytes
- Buffer.from(array) returns a Buffer containing elements from array of bytes
- Buffer.from(buffer) creates a copy of an existing Buffer
- Buffer.from(number) throws TypeError to avoid allocating uninitialized memory
- Buffer.concat(list) concatenates multiple Buffer instances into a single Buffer
- Buffer.isBuffer(obj) returns true for Buffer instances and false for other objects
ファイル
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.mjs
ソース
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/safer-buffer@2.1.2
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/safer-buffer@2.1.2
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.
{"case":{"caseId":"case:sha256:46190523cdc28d41c5aa1ab70a80076b78e963063d510448d4b662cf2bc1df5f","constraints":{"executionContext":"node"},"contract":["Buffer() and new Buffer() throw TypeError to prevent unsafe direct invocation","Buffer.alloc(size) returns a zero-filled Buffer of the requested size","Buffer.alloc(size, fill, encoding) returns a Buffer filled with the specified pattern","Buffer.alloc throws TypeError for non-numeric size and RangeError for negative size","Buffer.from(string, encoding) returns a Buffer containing encoded string bytes","Buffer.from(array) returns a Buffer containing elements from array of bytes","Buffer.from(buffer) creates a copy of an existing Buffer","Buffer.from(number) throws TypeError to avoid allocating uninitialized memory","Buffer.concat(list) concatenates multiple Buffer instances into a single Buffer","Buffer.isBuffer(obj) returns true for Buffer instances and false for other objects"],"goal":"verify pkg:npm/safer-buffer@2.1.2","kind":"HOW","packages":["pkg:npm/safer-buffer@2.1.2"],"schemaVersion":1},"contractCommand":["node","test/contract.mjs"],"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/safer-buffer@2.1.2"],"schemaVersion":1,"verifierAdapter":"node-typescript@1"}
{
"name": "sample-safer-buffer",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-safer-buffer",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"safer-buffer": "2.1.2"
}
},
"node_modules/safer-buffer": {
"version": "2.1.2",
"resolved": "https://registry.npmjs.org/safer-buffer/-/safer-buffer-2.1.2.tgz",
"integrity": "sha512-YZo3K82SD7Riyi0E1EQPojLz7kpepnSQI9IyPbHHg1XXXevb5dJI7tpyN2ADxGcQbHG7vcyRHk0cbwqcQriUtg==",
"license": "MIT"
}
}
}
{
"name": "sample-safer-buffer",
"version": "1.0.0",
"private": true,
"description": "Clean-room verification for safer-buffer",
"main": "src/index.js",
"license": "MIT-0",
"dependencies": {
"safer-buffer": "2.1.2"
}
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/safer-buffer@2.1.2",
"kind": "HOW",
"packages": [
"pkg:npm/safer-buffer@2.1.2"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
const safer = require('safer-buffer');
/**
* Allocate a zero-filled or fill-specified buffer using safer-buffer.
* @param {number} size - Buffer byte size
* @param {string|Buffer|number} [fill] - Value to pre-fill buffer with
* @param {string} [encoding] - Encoding for string fill
* @returns {Buffer} Allocated buffer
*/
function allocateBuffer(size, fill, encoding) {
return safer.Buffer.alloc(size, fill, encoding);
}
/**
* Create a buffer from an array, string, or existing buffer.
* @param {Array|ArrayBuffer|Buffer|string} value - Source value
* @param {string|number} [encodingOrOffset] - Encoding or byte offset
* @param {number} [length] - Length when source is ArrayBuffer
* @returns {Buffer} Created buffer
*/
function createBufferFrom(value, encodingOrOffset, length) {
return safer.Buffer.from(value, encodingOrOffset, length);
}
/**
* Concatenate a list of buffer instances into a single buffer.
* @param {Buffer[]} list - Array of buffer instances
* @param {number} [totalLength] - Total byte length
* @returns {Buffer} Concatenated buffer
*/
function concatBuffers(list, totalLength) {
return safer.Buffer.concat(list, totalLength);
}
/**
* Check if the given object is a Buffer instance.
* @param {*} obj - Object to check
* @returns {boolean} True if object is a Buffer
*/
function isBufferInstance(obj) {
return safer.Buffer.isBuffer(obj);
}
module.exports = {
safer,
Buffer: safer.Buffer,
allocateBuffer,
createBufferFrom,
concatBuffers,
isBufferInstance
};
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
const require = createRequire(import.meta.url);
const {
safer,
Buffer,
allocateBuffer,
createBufferFrom,
concatBuffers,
isBufferInstance
} = require('../src/index.js');
// 1. Export and safety checks
assert.equal(typeof safer, 'object', 'safer module export must be an object');
assert.equal(typeof Buffer, 'object', 'safer.Buffer must be an object');
assert.equal(typeof allocateBuffer, 'function', 'allocateBuffer must be a function');
assert.equal(typeof createBufferFrom, 'function', 'createBufferFrom must be a function');
assert.equal(typeof concatBuffers, 'function', 'concatBuffers must be a function');
assert.equal(typeof isBufferInstance, 'function', 'isBufferInstance must be a function');
// 2. Direct constructor invocation throws TypeError
assert.throws(() => Buffer(), TypeError, 'Buffer() without new must throw TypeError');
assert.throws(() => Buffer(10), TypeError, 'Buffer(number) without new must throw TypeError');
assert.throws(() => new Buffer(), TypeError, 'new Buffer() must throw TypeError');
assert.throws(() => new Buffer(10), TypeError, 'new Buffer(number) must throw TypeError');
// 3. Buffer.alloc allocates zero-filled buffer of exact length
const zeroBuf = allocateBuffer(16);
assert.equal(isBufferInstance(zeroBuf), true, 'allocated object must be a Buffer');
assert.equal(zeroBuf.length, 16, 'buffer length must match requested size');
for (let i = 0; i < zeroBuf.length; i++) {
assert.equal(zeroBuf[i], 0, 'allocated buffer must be zero-filled');
}
// 4. Buffer.alloc with custom fill
const filledBuf = allocateBuffer(6, 'xyz', 'utf8');
assert.equal(filledBuf.toString('utf8'), 'xyzxyz', 'buffer should be filled with pattern');
const numericFillBuf = allocateBuffer(4, 0x42);
assert.deepEqual(Array.from(numericFillBuf), [0x42, 0x42, 0x42, 0x42]);
// 5. Buffer.alloc validates size parameter
assert.throws(() => allocateBuffer('invalid'), TypeError, 'Buffer.alloc(string) must throw TypeError');
assert.throws(() => allocateBuffer(-5), RangeError, 'Buffer.alloc(negative) must throw RangeError');
assert.throws(() => allocateBuffer(null), TypeError, 'Buffer.alloc(null) must throw TypeError');
// 6. Buffer.from string with encoding
const strBuf = createBufferFrom('hello world', 'utf8');
assert.equal(isBufferInstance(strBuf), true);
assert.equal(strBuf.toString('utf8'), 'hello world');
assert.equal(strBuf.length, 11);
const base64Buf = createBufferFrom('aGVsbG8=', 'base64');
assert.equal(base64Buf.toString('utf8'), 'hello');
// 7. Buffer.from array of bytes
const arrayBuf = createBufferFrom([0x68, 0x65, 0x6c, 0x6c, 0x6f]);
assert.equal(arrayBuf.toString('utf8'), 'hello');
assert.equal(arrayBuf.length, 5);
// 8. Buffer.from copy of existing buffer
const copyBuf = createBufferFrom(strBuf);
assert.equal(copyBuf.toString('utf8'), 'hello world');
assert.notEqual(copyBuf, strBuf, 'Buffer.from(buffer) should produce a copy');
// 9. Buffer.from number throws TypeError to prevent unsafe uninitialized allocations
assert.throws(() => createBufferFrom(10), TypeError, 'Buffer.from(number) must throw TypeError');
assert.throws(() => createBufferFrom(-1), TypeError, 'Buffer.from(negative) must throw TypeError');
assert.throws(() => createBufferFrom(null), TypeError, 'Buffer.from(null) must throw TypeError');
assert.throws(() => createBufferFrom(undefined), TypeError, 'Buffer.from(undefined) must throw TypeError');
// 10. Buffer.concat combines multiple buffers
const part1 = createBufferFrom('hello ');
const part2 = createBufferFrom('world');
const combined = concatBuffers([part1, part2]);
assert.equal(combined.toString('utf8'), 'hello world');
assert.equal(combined.length, 11);
// 11. Buffer helper methods
assert.equal(Buffer.isEncoding('utf8'), true);
assert.equal(Buffer.isEncoding('invalid-enc'), false);
assert.equal(Buffer.byteLength('hello', 'utf8'), 5);
console.log('Contract tests passed successfully.');
オリジンシーダー
匿名