サンプル
base64-js 1.5.1: fromByteArray
検証済みサンプル — npm base64-js 1.5.1: fromByteArray. node 22 · linux alpine/x64 · docker で contract を実行し、成功しました: assert empty Uint8Array encodes to empty base64…
sha256:36598f94f9cdf6646b5ed9a966915bd58f8ec1f5051f737b681510db42dc051c
このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。
合格した契約受領証を提出した異なる署名鍵の数です。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@1node:22-alpine@sha256:c610fcdfb1d5… |
2026-08-26 |
ケース
HOW- ゴール
- verify fromByteArray in pkg:npm/base64-js@1.5.1
- パッケージ
- シンボル
-
- fromByteArray
- 環境
- node 22.23.2
- 作成日
- 2026-08-26T11:24:37Z
コントラクト
- assert empty Uint8Array encodes to empty base64 string
- assert single byte encodes with double equals padding
- assert two bytes encode with single equals padding
- assert three bytes encode without padding
- assert text converted to Uint8Array encodes to standard base64 string
- assert binary byte sequence with 0x00 and 0xFF encodes correctly
- assert large byte buffer encodes correctly and round-trips with toByteArray
ファイル
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- 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 fromByteArray in pkg:npm/base64-js@1.5.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/base64-js@1.5.1
Demonstrate these symbols/APIs:
- fromByteArray
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:f4eccb31b2f273dc7183ca6fe99791bf9c69b58b74aaef3aaccbb7bab1c7eafb","contract":["assert empty Uint8Array encodes to empty base64 string","assert single byte encodes with double equals padding","assert two bytes encode with single equals padding","assert three bytes encode without padding","assert text converted to Uint8Array encodes to standard base64 string","assert binary byte sequence with 0x00 and 0xFF encodes correctly","assert large byte buffer encodes correctly and round-trips with toByteArray"],"goal":"verify fromByteArray in pkg:npm/base64-js@1.5.1","kind":"HOW","packages":["pkg:npm/base64-js@1.5.1"],"schemaVersion":1,"symbols":["fromByteArray"]},"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/base64-js@1.5.1"],"schemaVersion":1,"subject":"pkg:npm/base64-js@1.5.1","symbols":["fromByteArray"],"verifierAdapter":"node-typescript@1"}
const { fromByteArray, toByteArray, byteLength } = require('base64-js');
function encodeBytes(uint8Array) {
return fromByteArray(uint8Array);
}
function encodeText(text) {
const encoder = new TextEncoder();
const bytes = encoder.encode(text);
return fromByteArray(bytes);
}
function decodeToBytes(base64Str) {
return toByteArray(base64Str);
}
module.exports = {
fromByteArray,
toByteArray,
byteLength,
encodeBytes,
encodeText,
decodeToBytes,
};
{
"name": "sample-base64-js",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-base64-js",
"version": "1.0.0",
"license": "MIT-0",
"dependencies": {
"base64-js": "1.5.1"
}
},
"node_modules/base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA==",
"funding": [
{
"type": "github",
"url": "https://github.com/sponsors/feross"
},
{
"type": "patreon",
"url": "https://www.patreon.com/feross"
},
{
"type": "consulting",
"url": "https://feross.org/support"
}
],
"license": "MIT"
}
}
}
{
"name": "sample-base64-js",
"version": "1.0.0",
"description": "Minimal clean-room sample verifying fromByteArray in base64-js",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"base64-js": "1.5.1"
}
}
{
"schemaVersion": 1,
"goal": "verify fromByteArray in pkg:npm/base64-js@1.5.1",
"kind": "HOW",
"packages": [
"pkg:npm/base64-js@1.5.1"
],
"symbols": [
"fromByteArray"
]
}
import assert from 'node:assert';
import { fromByteArray, toByteArray, byteLength } from 'base64-js';
import { encodeBytes, encodeText, decodeToBytes } from '../index.js';
// 1. Empty Uint8Array encodes to empty base64 string
const emptyBytes = new Uint8Array([]);
const emptyResult = encodeBytes(emptyBytes);
assert.strictEqual(emptyResult, '', 'Empty byte array must produce empty string');
// 2. Single byte encodes with double equals padding
const singleByte = new Uint8Array([72]); // 'H'
const singleResult = encodeBytes(singleByte);
assert.strictEqual(singleResult, 'SA==', '1 byte must encode with == padding');
// 3. Two bytes encode with single equals padding
const twoBytes = new Uint8Array([72, 101]); // 'He'
const twoResult = encodeBytes(twoBytes);
assert.strictEqual(twoResult, 'SGU=', '2 bytes must encode with = padding');
// 4. Three bytes encode without padding
const threeBytes = new Uint8Array([72, 101, 108]); // 'Hel'
const threeResult = encodeBytes(threeBytes);
assert.strictEqual(threeResult, 'SGVs', '3 bytes (multiple of 3) must encode without padding');
// 5. Text converted to Uint8Array encodes to standard base64 string
const helloWorld = encodeText('Hello, World!');
assert.strictEqual(helloWorld, 'SGVsbG8sIFdvcmxkIQ==', 'Hello, World! must encode accurately');
// 6. Binary byte sequence with 0x00 and 0xFF encodes correctly
const binaryBytes = new Uint8Array([0x00, 0x01, 0x02, 0xFE, 0xFF]);
const binaryResult = encodeBytes(binaryBytes);
assert.strictEqual(binaryResult, 'AAEC/v8=', 'Binary byte sequence must encode correctly');
// 7. Large byte buffer encodes correctly and round-trips with toByteArray
const size = 256;
const buffer = new Uint8Array(size);
for (let i = 0; i < size; i++) {
buffer[i] = i & 0xff;
}
const encoded = fromByteArray(buffer);
assert.strictEqual(typeof encoded, 'string', 'fromByteArray must return a string');
const decoded = toByteArray(encoded);
assert.strictEqual(decoded.length, size, 'Decoded byte length must match original');
assert.deepStrictEqual(Array.from(decoded), Array.from(buffer), 'Round-trip decoding must preserve byte values exactly');
console.log('All fromByteArray contract assertions passed.');
オリジンシーダー
匿名