CodeSampleX

Ejemplo

base64-js 1.5.1: fromByteArray

Muestra verificada para npm base64-js 1.5.1: fromByteArray. El contrato se ejecutó en node 22 · linux debian/x64 · docker y pasó.

sha256:13588bd2d0ec025502e86e517f36e90e97f5a726495a4698b33ec5c597346944

Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido. Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas. MIT-0

Evidencia de ejecución

El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.

Base de evidencia
Contrato firmado aprobado
Recibos de verificación
1
Claves de firma que lo compilaron
1
Entorno declarado node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Entornos de las ejecuciones de verificación

Entorno Contrato Etapas Ejecución
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

Caso

HOW
Objetivo
verify base64-js.fromByteArray in pkg:npm/base64-js@1.5.1
Paquetes
Símbolos
  • base64-js.fromByteArray
Entorno
node 22.23.2
Creado
2026-09-05T17:49:46Z

Contrato

  1. base64-js.fromByteArray is exported as a function
  2. base64-js.fromByteArray encodes empty Uint8Array to empty string
  3. base64-js.fromByteArray encodes byte arrays with no padding when byte length is a multiple of 3
  4. base64-js.fromByteArray encodes byte arrays with single padding character when byte length mod 3 is 2
  5. base64-js.fromByteArray encodes byte arrays with double padding characters when byte length mod 3 is 1
  6. base64-js.fromByteArray encodes full binary byte range 0x00 to 0xFF matching standard Base64
  7. base64-js.fromByteArray encodes multi-chunk byte arrays exceeding the 16383-byte chunk threshold accurately

Archivos

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

Descargar el artefacto de código fuente (tar.gz)

Código fuente

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 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.
csx.json
{"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"}
index.js
'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
};
package-lock.json
{
  "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"
    }
  }
}
package.json
{
  "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"
  }
}
spec.json
{
  "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"
  ]
}
test/contract.mjs
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 de origen

anónimo