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 debian/x64 · docker et a réussi.
sha256:13588bd2d0ec025502e86e517f36e90e97f5a726495a4698b33ec5c597346944
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 debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · node-typescript@1node:22@sha256:8a34c4ab3ea2… |
2026-09-05 |
Cas
HOW- Objectif
- verify base64-js.fromByteArray in pkg:npm/base64-js@1.5.1
- Paquets
- Symboles
-
- base64-js.fromByteArray
- Environnement
- node 22.23.2
- Créé
- 2026-09-05T17:49:46Z
Contrat
- base64-js.fromByteArray is exported as a function
- base64-js.fromByteArray encodes empty Uint8Array to empty string
- base64-js.fromByteArray encodes byte arrays with no padding when byte length is a multiple of 3
- base64-js.fromByteArray encodes byte arrays with single padding character when byte length mod 3 is 2
- base64-js.fromByteArray encodes byte arrays with double padding characters when byte length mod 3 is 1
- base64-js.fromByteArray encodes full binary byte range 0x00 to 0xFF matching standard Base64
- base64-js.fromByteArray encodes multi-chunk byte arrays exceeding the 16383-byte chunk threshold accurately
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 base64-js.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:
- base64-js.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:a9c487f3d4ef7243b863c55772a339e776710f9c5f775ca22cfe1b50fa64b434","contract":["base64-js.fromByteArray is exported as a function","base64-js.fromByteArray encodes empty Uint8Array to empty string","base64-js.fromByteArray encodes byte arrays with no padding when byte length is a multiple of 3","base64-js.fromByteArray encodes byte arrays with single padding character when byte length mod 3 is 2","base64-js.fromByteArray encodes byte arrays with double padding characters when byte length mod 3 is 1","base64-js.fromByteArray encodes full binary byte range 0x00 to 0xFF matching standard Base64","base64-js.fromByteArray encodes multi-chunk byte arrays exceeding the 16383-byte chunk threshold accurately"],"goal":"verify base64-js.fromByteArray in pkg:npm/base64-js@1.5.1","kind":"HOW","packages":["pkg:npm/base64-js@1.5.1"],"schemaVersion":1,"symbols":["base64-js.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":["base64-js.fromByteArray"],"verifierAdapter":"node-typescript@1"}
'use strict';
const base64 = require('base64-js');
/**
* Converts a Uint8Array of binary data into a Base64-encoded string.
*
* @param {Uint8Array} uint8 - The byte array to encode.
* @returns {string} The Base64 string representation of the byte array.
*/
function encodeByteArray(uint8) {
return base64.fromByteArray(uint8);
}
module.exports = {
encodeByteArray,
fromByteArray: base64.fromByteArray
};
{
"name": "sample-base64-js-frombytearray",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-base64-js-frombytearray",
"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==",
"license": "MIT"
}
}
}
{
"name": "sample-base64-js-frombytearray",
"version": "1.0.0",
"description": "Clean-room code sample verifying base64-js.fromByteArray in base64-js@1.5.1",
"main": "index.js",
"license": "MIT-0",
"dependencies": {
"base64-js": "1.5.1"
}
}
{
"schemaVersion": 1,
"goal": "verify base64-js.fromByteArray in pkg:npm/base64-js@1.5.1",
"kind": "HOW",
"packages": [
"pkg:npm/base64-js@1.5.1"
],
"symbols": [
"base64-js.fromByteArray"
]
}
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import base64 from 'base64-js';
const require = createRequire(import.meta.url);
const { encodeByteArray, fromByteArray } = require('../index.js');
// 1. base64-js.fromByteArray is exported as a function
assert.equal(typeof fromByteArray, 'function', 'base64-js.fromByteArray must be a function');
assert.equal(typeof encodeByteArray, 'function', 'encodeByteArray helper must be a function');
// 2. base64-js.fromByteArray encodes empty Uint8Array to empty string
{
const empty = new Uint8Array([]);
const result = fromByteArray(empty);
assert.equal(result, '', 'Encoding an empty Uint8Array must return an empty string');
assert.equal(encodeByteArray(empty), '', 'Helper must also return an empty string for empty input');
}
// 3. base64-js.fromByteArray encodes byte arrays with no padding when byte length is a multiple of 3
{
const bytes3 = new Uint8Array([0x41, 0x42, 0x43]); // 'ABC'
assert.equal(fromByteArray(bytes3), 'QUJD', '3-byte array must encode without padding');
const bytes6 = new Uint8Array([0x66, 0x6f, 0x6f, 0x62, 0x61, 0x72]); // 'foobar'
assert.equal(fromByteArray(bytes6), 'Zm9vYmFy', '6-byte array must encode without padding');
}
// 4. base64-js.fromByteArray encodes byte arrays with single padding character when byte length mod 3 is 2
{
const bytes2 = new Uint8Array([0x61, 0x62]); // 'ab'
assert.equal(fromByteArray(bytes2), 'YWI=', '2-byte array must end with a single =');
const bytes5 = new Uint8Array([0x66, 0x6f, 0x6f, 0x62, 0x61]); // 'fooba'
assert.equal(fromByteArray(bytes5), 'Zm9vYmE=', '5-byte array must end with a single =');
}
// 5. base64-js.fromByteArray encodes byte arrays with double padding characters when byte length mod 3 is 1
{
const bytes1 = new Uint8Array([0x61]); // 'a'
assert.equal(fromByteArray(bytes1), 'YQ==', '1-byte array must end with double ==');
const bytes4 = new Uint8Array([0x66, 0x6f, 0x6f, 0x62]); // 'foob'
assert.equal(fromByteArray(bytes4), 'Zm9vYg==', '4-byte array must end with double ==');
}
// 6. base64-js.fromByteArray encodes full binary byte range 0x00 to 0xFF matching standard Base64
{
const allBytes = new Uint8Array(256);
for (let i = 0; i < 256; i++) {
allBytes[i] = i;
}
const expected = Buffer.from(allBytes).toString('base64');
const actual = fromByteArray(allBytes);
assert.equal(actual, expected, 'Full byte range 0x00-0xFF must match standard Base64 representation');
}
// 7. base64-js.fromByteArray encodes multi-chunk byte arrays exceeding the 16383-byte chunk threshold accurately
{
const largeSize = 40000;
const largeBytes = new Uint8Array(largeSize);
for (let i = 0; i < largeSize; i++) {
largeBytes[i] = (i * 31 + 17) & 0xff;
}
const expected = Buffer.from(largeBytes).toString('base64');
const actual = fromByteArray(largeBytes);
assert.equal(actual, expected, 'Multi-chunk byte array exceeding 16383 bytes must match standard Base64');
}
console.log('All contract assertions for base64-js.fromByteArray passed successfully.');
Seeder d'origine
anonyme