CodeSampleX

Ejemplo

base64-js 1.5.1: toByteArray

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

sha256:a7030d7ff094896ed803b25ae855d0bc47c55066f08034477e687f90c5eac07f

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 linux 24 · ubuntu · glibc 2.39 x64 npm

Entornos de las ejecuciones de verificación

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

Caso

HOW
Objetivo
verify toByteArray in pkg:npm/base64-js@1.5.1
Paquetes
Símbolos
  • toByteArray
Creado
2026-08-26T11:24:52Z

Contrato

  1. toByteArray decodes standard base64 string into Uint8Array
  2. toByteArray decodes base64 string with double padding into Uint8Array
  3. toByteArray decodes base64 string with single padding into Uint8Array
  4. toByteArray decodes url-safe base64 string containing dash and underscore
  5. toByteArray returns empty Uint8Array for empty string
  6. toByteArray throws Error when base64 string length is not a multiple of 4

Archivos

  • PROMPT.md
  • csx.json
  • 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 toByteArray 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:
  - toByteArray

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:a76a7b735cffb1498525dc32c4ec7f165cee9615783f7a08cffeb2b6c045cf4c","contract":["toByteArray decodes standard base64 string into Uint8Array","toByteArray decodes base64 string with double padding into Uint8Array","toByteArray decodes base64 string with single padding into Uint8Array","toByteArray decodes url-safe base64 string containing dash and underscore","toByteArray returns empty Uint8Array for empty string","toByteArray throws Error when base64 string length is not a multiple of 4"],"goal":"verify toByteArray in pkg:npm/base64-js@1.5.1","kind":"HOW","packages":["pkg:npm/base64-js@1.5.1"],"schemaVersion":1,"symbols":["toByteArray"]},"contractCommand":["node","test/contract.mjs"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"npm","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"npm","schemaVersion":1},"license":"MIT-0","packages":["pkg:npm/base64-js@1.5.1"],"schemaVersion":1,"subject":"pkg:npm/base64-js@1.5.1","symbols":["toByteArray"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "base64-js-verification",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "base64-js-verification",
      "version": "1.0.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"
    }
  }
}
package.json
{
  "name": "base64-js-verification",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification for base64-js toByteArray",
  "dependencies": {
    "base64-js": "1.5.1"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify toByteArray in pkg:npm/base64-js@1.5.1",
  "kind": "HOW",
  "packages": [
    "pkg:npm/base64-js@1.5.1"
  ],
  "symbols": [
    "toByteArray"
  ]
}
test/contract.mjs
import assert from 'node:assert';
import base64 from 'base64-js';

const { toByteArray } = base64;

// 1. toByteArray decodes standard base64 string into Uint8Array
const standardBytes = toByteArray('Zm9vYmFy');
assert.ok(standardBytes instanceof Uint8Array);
assert.strictEqual(standardBytes.length, 6);
assert.deepStrictEqual(Array.from(standardBytes), [102, 111, 111, 98, 97, 114]);

// 2. toByteArray decodes base64 string with double padding into Uint8Array
const doublePadded = toByteArray('AQ==');
assert.ok(doublePadded instanceof Uint8Array);
assert.strictEqual(doublePadded.length, 1);
assert.deepStrictEqual(Array.from(doublePadded), [1]);

// 3. toByteArray decodes base64 string with single padding into Uint8Array
const singlePadded = toByteArray('AQI=');
assert.ok(singlePadded instanceof Uint8Array);
assert.strictEqual(singlePadded.length, 2);
assert.deepStrictEqual(Array.from(singlePadded), [1, 2]);

// 4. toByteArray decodes url-safe base64 string containing dash and underscore
const urlSafeBytes = toByteArray('-_8=');
assert.ok(urlSafeBytes instanceof Uint8Array);
assert.strictEqual(urlSafeBytes.length, 2);
assert.deepStrictEqual(Array.from(urlSafeBytes), [0xFB, 0xFF]);

// 5. toByteArray returns empty Uint8Array for empty string
const emptyBytes = toByteArray('');
assert.ok(emptyBytes instanceof Uint8Array);
assert.strictEqual(emptyBytes.length, 0);

// 6. toByteArray throws Error when base64 string length is not a multiple of 4
assert.throws(
  () => toByteArray('abc'),
  {
    name: 'Error',
    message: 'Invalid string. Length must be a multiple of 4'
  }
);

Seeder de origen

anónimo