示例
base64-js 1.5.1
已验证示例 — npm base64-js 1.5.1. contract 在 node 22 · linux alpine/x64 · docker 上运行并通过: byteLength calculates byte count for unpadded, single-padded, and…
sha256:77c714b0e375b3c21567e693954d8f1ac48ac78306263c7090798534fe824abf
本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。
提交了通过的契约回执的不同签名密钥数量。为 1 表示只有作者;大于 1 表示还有其他人构建过。密钥是自行生成的,背后没有注册身份,因此计的是密钥而非人。
MIT-0
执行证据
声明的环境与签名的运行分开呈现,你可以看到这个样本究竟运行了什么、在哪里运行。
- 证据依据
- 签名契约通过
- 验证回执
- 1
- 构建过它的签名密钥
- 1
声明的环境
node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10
验证运行环境
| 环境 | 契约 | 阶段 | 运行日期 |
|---|---|---|---|
| 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 |
案例
HOW- 目标
- verify pkg:npm/base64-js@1.5.1
- 环境
- node 22.23.2
- 创建时间
- 2026-08-26T07:37:45Z
契约
- byteLength calculates byte count for unpadded, single-padded, and double-padded base64 strings
- toByteArray decodes standard base64 strings into Uint8Array with exact byte values
- toByteArray decodes URL-safe base64 strings containing '-' and '_' characters
- fromByteArray encodes Uint8Array byte sequences into standard base64 strings
- fromByteArray and toByteArray round-trip binary data without corruption
文件
- PROMPT.md
- csx.json
- package-lock.json
- package.json
- spec.json
- src/index.js
- test/contract.js
源代码
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 pkg:npm/base64-js@1.5.1
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:npm/base64-js@1.5.1
Constraints:
- executionContext: node
Required runtime conditions:
- ecosystem: npm
- language: javascript
- moduleSystem: cjs
- packageManager: npm@10.9.8
- runtime: node@22.23.2
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:8ddabc5749953138b1d924d9d3267e1fd6848df6f455fb413047e904e620bc33","constraints":{"executionContext":"node"},"contract":["byteLength calculates byte count for unpadded, single-padded, and double-padded base64 strings","toByteArray decodes standard base64 strings into Uint8Array with exact byte values","toByteArray decodes URL-safe base64 strings containing '-' and '_' characters","fromByteArray encodes Uint8Array byte sequences into standard base64 strings","fromByteArray and toByteArray round-trip binary data without corruption"],"goal":"verify pkg:npm/base64-js@1.5.1","kind":"HOW","packages":["pkg:npm/base64-js@1.5.1"],"schemaVersion":1},"contractCommand":["node","test/contract.js"],"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","verifierAdapter":"node-typescript@1"}
{
"name": "sample-base64-js",
"version": "1.0.0",
"lockfileVersion": 3,
"requires": true,
"packages": {
"": {
"name": "sample-base64-js",
"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",
"version": "1.0.0",
"description": "verify pkg:npm/base64-js@1.5.1",
"main": "src/index.js",
"scripts": {
"test": "node test/contract.js"
},
"dependencies": {
"base64-js": "1.5.1"
},
"license": "MIT-0"
}
{
"schemaVersion": 1,
"goal": "verify pkg:npm/base64-js@1.5.1",
"kind": "HOW",
"packages": [
"pkg:npm/base64-js@1.5.1"
],
"constraints": {
"executionContext": "node"
},
"runtimeConditions": {
"ecosystem": "npm",
"language": "javascript",
"moduleSystem": "cjs",
"packageManager": "npm@10.9.8",
"runtime": "node@22.23.2"
}
}
'use strict';
const base64 = require('base64-js');
/**
* Calculate the byte length of a base64 string.
* @param {string} b64 - Base64 encoded string
* @returns {number} Decoded byte length
*/
function getByteLength(b64) {
return base64.byteLength(b64);
}
/**
* Decode a base64 string into a Uint8Array.
* @param {string} b64 - Base64 encoded string
* @returns {Uint8Array} Decoded bytes
*/
function decode(b64) {
return base64.toByteArray(b64);
}
/**
* Encode a Uint8Array into a base64 string.
* @param {Uint8Array} uint8 - Byte array
* @returns {string} Base64 encoded string
*/
function encode(uint8) {
return base64.fromByteArray(uint8);
}
module.exports = {
base64,
getByteLength,
decode,
encode
};
'use strict';
const assert = require('assert');
const base64 = require('base64-js');
const { getByteLength, decode, encode } = require('../src/index');
// 1. Export verification
{
assert.strictEqual(typeof base64.byteLength, 'function');
assert.strictEqual(typeof base64.toByteArray, 'function');
assert.strictEqual(typeof base64.fromByteArray, 'function');
assert.strictEqual(typeof getByteLength, 'function');
assert.strictEqual(typeof decode, 'function');
assert.strictEqual(typeof encode, 'function');
}
// 2. byteLength calculates byte count for unpadded, single-padded, and double-padded base64 strings
{
assert.strictEqual(base64.byteLength(''), 0);
// 'Zg==' (f) -> 1 byte (double padded)
assert.strictEqual(base64.byteLength('Zg=='), 1);
assert.strictEqual(getByteLength('Zg=='), 1);
// 'Zm8=' (fo) -> 2 bytes (single padded)
assert.strictEqual(base64.byteLength('Zm8='), 2);
assert.strictEqual(getByteLength('Zm8='), 2);
// 'Zm9v' (foo) -> 3 bytes (no padding)
assert.strictEqual(base64.byteLength('Zm9v'), 3);
assert.strictEqual(getByteLength('Zm9v'), 3);
// 'SGVsbG8sIFdvcmxkIQ==' -> 13 bytes
assert.strictEqual(base64.byteLength('SGVsbG8sIFdvcmxkIQ=='), 13);
}
// 3. toByteArray decodes standard base64 strings into Uint8Array with exact byte values
{
const empty = decode('');
assert.ok(empty instanceof Uint8Array);
assert.strictEqual(empty.length, 0);
const singleByte = decode('Zg==');
assert.deepStrictEqual(Array.from(singleByte), [102]); // 'f' ASCII
const twoBytes = decode('Zm8=');
assert.deepStrictEqual(Array.from(twoBytes), [102, 111]); // 'fo' ASCII
const threeBytes = decode('Zm9v');
assert.deepStrictEqual(Array.from(threeBytes), [102, 111, 111]); // 'foo' ASCII
const hello = decode('SGVsbG8sIFdvcmxkIQ==');
assert.strictEqual(Buffer.from(hello).toString('utf8'), 'Hello, World!');
}
// 4. toByteArray decodes URL-safe base64 strings containing '-' and '_' characters
{
// Test bytes with high bits producing + / or - _
// 0xfb, 0xff, 0xbf -> standard "+/+/"; url-safe "-_-_"
const standard = decode('+/+/');
const urlSafe = decode('-_-_');
assert.deepStrictEqual(Array.from(standard), [0xfb, 0xff, 0xbf]);
assert.deepStrictEqual(Array.from(urlSafe), [0xfb, 0xff, 0xbf]);
}
// 5. fromByteArray encodes Uint8Array byte sequences into standard base64 strings
{
assert.strictEqual(encode(new Uint8Array([])), '');
assert.strictEqual(encode(new Uint8Array([102])), 'Zg==');
assert.strictEqual(encode(new Uint8Array([102, 111])), 'Zm8=');
assert.strictEqual(encode(new Uint8Array([102, 111, 111])), 'Zm9v');
assert.strictEqual(encode(Buffer.from('Hello, World!', 'utf8')), 'SGVsbG8sIFdvcmxkIQ==');
assert.strictEqual(encode(new Uint8Array([0, 1, 2, 255])), 'AAEC/w==');
}
// 6. fromByteArray and toByteArray round-trip binary data without corruption
{
const testBytes = new Uint8Array(256);
for (let i = 0; i < 256; i++) {
testBytes[i] = i;
}
const encoded = encode(testBytes);
const decoded = decode(encoded);
assert.strictEqual(decoded.length, 256);
assert.deepStrictEqual(Array.from(decoded), Array.from(testBytes));
}
console.log('All base64-js contract tests passed.');
原始种子者
匿名