CodeSampleX

Exemplo

base64-js 1.5.1: toByteArray

Amostra verificada para npm base64-js 1.5.1: toByteArray. O contrato rodou em node 22 · linux alpine/x64 · docker e passou: toByteArray decodes standard…

sha256:a7030d7ff094896ed803b25ae855d0bc47c55066f08034477e687f90c5eac07f

Esta rede oferece uma coisa: uma amostra que compila. Ela a executou em um sandbox e guardou o recibo assinado. Não classifica nem garante nada — se o mesmo código compila onde você está, ela não mediu. Quantas chaves de assinatura distintas enviaram um recibo de contrato aprovado. Uma é só o autor; mais de uma significa que outra pessoa também o compilou. Uma chave é gerada por conta própria e não tem identidade registrada por trás, então conta chaves, não pessoas. MIT-0

Evidência de execução

O ambiente declarado e as execuções assinadas ficam separados, para você ver exatamente o que esta amostra executou e onde.

Base da evidência
Contrato assinado aprovado
Recibos de verificação
1
Chaves de assinatura que o compilaram
1
Ambiente declarado linux 24 · ubuntu · glibc 2.39 x64 npm

Ambientes das execuções de verificação

Ambiente Contrato Etapas Execução
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
Pacotes
Símbolos
  • toByteArray
Criado
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

Arquivos

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

Baixar o artefato de código-fonte (tar.gz)

Código-fonte

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 origem

anônimo