Exemple
base64-js 1.5.1: fromByteArray
Échantillon vérifié pour npm base64-js 1.5.1: fromByteArray. Le contrat s'est exécuté sur node 22 · linux alpine/x64 · docker et a réussi.
sha256:36598f94f9cdf6646b5ed9a966915bd58f8ec1f5051f737b681510db42dc051c
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
- 1
- Clés de signature qui l’ont compilé
- 1
Environnement déclaré
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
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 |
Cas
HOW- Objectif
- verify fromByteArray in pkg:npm/base64-js@1.5.1
- Paquets
- Symboles
-
- fromByteArray
- Environnement
- node 22.23.2
- Créé
- 2026-08-26T11:24:37Z
Contrat
- 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
Fichiers
- PROMPT.md
- csx.json
- index.js
- package-lock.json
- package.json
- spec.json
- test/contract.mjs
Code source
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.');
Seeder d'origine
anonyme