CodeSampleX

샘플

base64-js 1.5.1: fromByteArray

검증된 샘플 — npm base64-js 1.5.1: fromByteArray. node 22 · linux debian/x64 · docker에서 contract를 실행해 통과했습니다: base64-js.fromByteArray is exported as a function

sha256:13588bd2d0ec025502e86e517f36e90e97f5a726495a4698b33ec5c597346944

이 네트워크가 제공하는 것은 하나입니다. 빌드되는 샘플. 샌드박스에서 돌리고 서명된 영수증을 보관합니다. 등급을 매기지 않고 무엇도 보증하지 않습니다 — 같은 코드가 당신 환경에서 빌드되는지는 측정한 적이 없습니다. 통과한 계약 영수증을 낸 서로 다른 서명 키의 수입니다. 하나면 작성자 혼자이고, 둘 이상이면 다른 사람도 빌드했다는 뜻입니다. 키는 스스로 만드는 것이고 뒤에 등록된 신원이 없으므로, 세는 것은 사람이 아니라 키입니다. MIT-0

실행 증거

선언된 환경과 서명된 실행을 분리해 두었습니다. 이 샘플이 무엇을 어디서 실행했는지 그대로 볼 수 있습니다.

증거 기준
서명된 컨트랙트 통과
검증 영수증
1
빌드한 서명 키
1
선언된 환경 node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

검증 실행 환경

환경 컨트랙트 단계 실행일
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

케이스

HOW
목표
verify base64-js.fromByteArray in pkg:npm/base64-js@1.5.1
패키지
심벌
  • base64-js.fromByteArray
환경
node 22.23.2
생성일
2026-09-05T17:49:46Z

컨트랙트

  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

파일

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

소스 아티팩트 내려받기 (tar.gz)

소스

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.');

오리진 시더

익명