CodeSampleX

Beispiel

@electron/fuses 1.8.0: FuseVersion

Verifiziertes Beispiel für npm @electron/fuses 1.8.0: FuseVersion. Der Vertrag lief auf node 22 · linux debian/x64 · docker und bestand.

sha256:899f0a07e9bc43cba95c846496f181b5cddf0e7b24cb40e4d0194121c49a7a97

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung node 22.23 linux 24 · ubuntu · glibc 2.39 x64 node 22.23 javascript npm 10

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
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-04

Fall

HOW
Ziel
verify @electron/fuses.FuseVersion in pkg:npm/%40electron/fuses@1.8.0
Pakete
Symbole
  • @electron/fuses.FuseVersion
Umgebung
node 22.23.2
Erstellt
2026-09-04T12:20:34Z

Contract

  1. FuseVersion is exported as an object defining V1 with value "1"
  2. getCurrentFuseWire returns wire configuration with version matching FuseVersion.V1 for version 1 binary
  3. configureFusesWithVersion flips fuses in binary when targeting FuseVersion.V1
  4. configureFusesWithVersion throws error when called with unsupported fuse version
  5. configureFusesWithVersion throws error when target binary wire version does not match FuseVersion

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 @electron/fuses.FuseVersion in pkg:npm/%40electron/fuses@1.8.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/%40electron/fuses@1.8.0
Demonstrate these symbols/APIs:
  - @electron/fuses.FuseVersion

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:008f28d903ab44054f54fe02b5a6a316a6d171483ef2d1deb3949efa0656db81","contract":["FuseVersion is exported as an object defining V1 with value \"1\"","getCurrentFuseWire returns wire configuration with version matching FuseVersion.V1 for version 1 binary","configureFusesWithVersion flips fuses in binary when targeting FuseVersion.V1","configureFusesWithVersion throws error when called with unsupported fuse version","configureFusesWithVersion throws error when target binary wire version does not match FuseVersion"],"goal":"verify @electron/fuses.FuseVersion in pkg:npm/%40electron/fuses@1.8.0","kind":"HOW","packages":["pkg:npm/%40electron/fuses@1.8.0"],"schemaVersion":1,"symbols":["@electron/fuses.FuseVersion"]},"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/%40electron/fuses@1.8.0"],"schemaVersion":1,"subject":"pkg:npm/%40electron/fuses@1.8.0","symbols":["@electron/fuses.FuseVersion"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-electron-fuses-version",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-electron-fuses-version",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "@electron/fuses": "1.8.0"
      }
    },
    "node_modules/@electron/fuses": {
      "version": "1.8.0",
      "resolved": "https://registry.npmjs.org/@electron/fuses/-/fuses-1.8.0.tgz",
      "integrity": "sha512-zx0EIq78WlY/lBb1uXlziZmDZI4ubcCXIMJ4uGjXzZW0nS19TjSPeXPAjzzTmKQlJUZm0SbmZhPKP7tuQ1SsEw==",
      "license": "MIT",
      "dependencies": {
        "chalk": "^4.1.1",
        "fs-extra": "^9.0.1",
        "minimist": "^1.2.5"
      },
      "bin": {
        "electron-fuses": "dist/bin.js"
      }
    },
    "node_modules/ansi-styles": {
      "version": "4.3.0",
      "resolved": "https://registry.npmjs.org/ansi-styles/-/ansi-styles-4.3.0.tgz",
      "integrity": "sha512-zbB9rCJAT1rbjiVDb2hqKFHNYLxgtk8NURxZ3IZwD3F6NtxbXZQCnnSi1Lkx+IDohdPlFp222wVALIheZJQSEg==",
      "license": "MIT",
      "dependencies": {
        "color-convert": "^2.0.1"
      },
      "engines": {
        "node": ">=8"
      },
      "funding": {
        "url": "https://github.com/chalk/ansi-styles?sponsor=1"
      }
    },
    "node_modules/at-least-node": {
      "version": "1.0.0",
      "resolved": "https://registry.npmjs.org/at-least-node/-/at-least-node-1.0.0.tgz",
      "integrity": "sha512-+q/t7Ekv1EDY2l6Gda6LLiX14rU9TV20Wa3ofeQmwPFZbOMo9DXrLbOjFaaclkXKWidIaopwAObQDqwWtGUjqg==",
      "license": "ISC",
      "engines": {
        "node": ">= 4.0.0"
      }
    },
    "node_modules/chalk": {
      "version": "4.1.2",
      "resolved": "https://registry.npmjs.org/chalk/-/chalk-4.1.2.tgz",
      "integrity": "sha512-oKnbhFyRIXpUuez8iBMmyEa4nbj4IOQyuhc/wy9kY7/WVPcwIO9VA668Pu8RkO7+0G76SLROeyw9CpQ061i4mA==",
      "license": "MIT",
      "dependencies": {
        "ansi-styles": "^4.1.0",
        "supports-color": "^7.1.0"
      },
      "engines": {
        "node": ">=10"
      },
      "funding": {
        "url": "https://github.com/chalk/chalk?sponsor=1"
      }
    },
    "node_modules/color-convert": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/color-convert/-/color-convert-2.0.1.tgz",
      "integrity": "sha512-RRECPsj7iu/xb5oKYcsFHSppFNnsj/52OVTRKb4zP5onXwVF3zVmmToNcOfGC+CRDpfK/U584fMg38ZHCaElKQ==",
      "license": "MIT",
      "dependencies": {
        "color-name": "~1.1.4"
      },
      "engines": {
        "node": ">=7.0.0"
      }
    },
    "node_modules/color-name": {
      "version": "1.1.4",
      "resolved": "https://registry.npmjs.org/color-name/-/color-name-1.1.4.tgz",
      "integrity": "sha512-dOy+3AuW3a2wNbZHIuMZpTcgjGuLU/uBL/ubcZF9OXbDo8ff4O8yVp5Bf0efS8uEoYo5q4Fx7dY9OgQGXgAsQA==",
      "license": "MIT"
    },
    "node_modules/fs-extra": {
      "version": "9.1.0",
      "resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-9.1.0.tgz",
      "integrity": "sha512-hcg3ZmepS30/7BSFqRvoo3DOMQu7IjqxO5nCDt+zM9XWjb33Wg7ziNT+Qvqbuc3+gWpzO02JubVyk2G4Zvo1OQ==",
      "license": "MIT",
      "dependencies": {
        "at-least-node": "^1.0.0",
        "graceful-fs": "^4.2.0",
        "jsonfile": "^6.0.1",
        "universalify": "^2.0.0"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/graceful-fs": {
      "version": "4.2.11",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
      "integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==",
      "license": "ISC"
    },
    "node_modules/has-flag": {
      "version": "4.0.0",
      "resolved": "https://registry.npmjs.org/has-flag/-/has-flag-4.0.0.tgz",
      "integrity": "sha512-EykJT/Q1KjTWctppgIAgfSO0tKVuZUjhgMr17kqTumMl6Afv3EISleU7qZUzoXDFTAHTDC4NOoG/ZxU3EvlMPQ==",
      "license": "MIT",
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/jsonfile": {
      "version": "6.2.1",
      "resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.2.1.tgz",
      "integrity": "sha512-zwOTdL3rFQ/lRdBnntKVOX6k5cKJwEc1HdilT71BWEu7J41gXIB2MRp+vxduPSwZJPWBxEzv4yH1wYLJGUHX4Q==",
      "license": "MIT",
      "dependencies": {
        "universalify": "^2.0.0"
      },
      "optionalDependencies": {
        "graceful-fs": "^4.1.6"
      }
    },
    "node_modules/minimist": {
      "version": "1.2.8",
      "resolved": "https://registry.npmjs.org/minimist/-/minimist-1.2.8.tgz",
      "integrity": "sha512-2yyAR8qBkN3YuheJanUpWC5U3bb5osDywNB8RzDVlDwDHbocAJveqqj1u8+SVD7jkWT4yvsHCpWqqWqAxb0zCA==",
      "license": "MIT",
      "funding": {
        "url": "https://github.com/sponsors/ljharb"
      }
    },
    "node_modules/supports-color": {
      "version": "7.2.0",
      "resolved": "https://registry.npmjs.org/supports-color/-/supports-color-7.2.0.tgz",
      "integrity": "sha512-qpCAvRl9stuOHveKsn7HncJRvv501qIacKzQlO/+Lwxc9+0q2wLyv4Dfvt80/DPn2pqOBsJdDiogXGR9+OvwRw==",
      "license": "MIT",
      "dependencies": {
        "has-flag": "^4.0.0"
      },
      "engines": {
        "node": ">=8"
      }
    },
    "node_modules/universalify": {
      "version": "2.0.1",
      "resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.1.tgz",
      "integrity": "sha512-gptHNQghINnc/vTGIk0SOFGFNXw7JVrlRUtConJRlvaw6DuX0wO5Jeko9sWrMBhh+PsYAZ7oXAiOnf/UKogyiw==",
      "license": "MIT",
      "engines": {
        "node": ">= 10.0.0"
      }
    }
  }
}
package.json
{
  "name": "sample-electron-fuses-version",
  "version": "1.0.0",
  "private": true,
  "license": "MIT-0",
  "main": "src/index.js",
  "dependencies": {
    "@electron/fuses": "1.8.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @electron/fuses.FuseVersion in pkg:npm/%40electron/fuses@1.8.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40electron/fuses@1.8.0"
  ],
  "symbols": [
    "@electron/fuses.FuseVersion"
  ]
}
src/index.js
const {
  FuseVersion,
  FuseV1Options,
  flipFuses,
  getCurrentFuseWire
} = require('@electron/fuses');

/**
 * Returns the list of supported fuse versions.
 *
 * @returns {string[]} Array of supported fuse version identifiers.
 */
function getSupportedFuseVersions() {
  return [FuseVersion.V1];
}

/**
 * Checks whether a given version string is a valid FuseVersion.
 *
 * @param {string} version - The version string to test.
 * @returns {boolean} True if the version is supported.
 */
function isValidFuseVersion(version) {
  return Object.values(FuseVersion).includes(version);
}

/**
 * Reads the fuse wire version from an Electron binary containing fuse wire.
 *
 * @param {string} binaryPath - Path to the Electron executable.
 * @returns {Promise<string>} The fuse version recorded in the binary.
 */
async function readFuseVersion(binaryPath) {
  const wire = await getCurrentFuseWire(binaryPath);
  return wire.version;
}

/**
 * Configures fuse settings in an Electron binary with explicit fuse version validation.
 *
 * @param {string} binaryPath - Path to the Electron executable.
 * @param {string} version - Fuse version to target (e.g. FuseVersion.V1).
 * @param {object} fuseOptions - Fuse options map.
 * @returns {Promise<number>} Number of sentinels modified.
 */
async function configureFusesWithVersion(binaryPath, version, fuseOptions = {}) {
  return flipFuses(binaryPath, {
    version,
    ...fuseOptions
  });
}

module.exports = {
  FuseVersion,
  FuseV1Options,
  flipFuses,
  getCurrentFuseWire,
  getSupportedFuseVersions,
  isValidFuseVersion,
  readFuseVersion,
  configureFusesWithVersion
};
test/contract.mjs
import assert from 'node:assert/strict';
import { createRequire } from 'node:module';
import fs from 'node:fs';
import path from 'node:path';
import os from 'node:os';

const require = createRequire(import.meta.url);
const electronFuses = require('@electron/fuses');
const {
  FuseVersion,
  FuseV1Options,
  flipFuses,
  getCurrentFuseWire,
  getSupportedFuseVersions,
  isValidFuseVersion,
  readFuseVersion,
  configureFusesWithVersion
} = require('../src/index.js');

const SENTINEL = 'dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX';
const tempDir = fs.mkdtempSync(path.join(os.tmpdir(), 'fuses-contract-test-'));

function createMockBinary(filename, version = 1, length = 8, states = [48, 48, 48, 48, 48, 48, 48, 48]) {
  const filePath = path.join(tempDir, filename);
  const header = Buffer.from('MOCK_ELF_HEADER_DATA');
  const sentinel = Buffer.from(SENTINEL, 'utf8');
  const wire = Buffer.from([version, length, ...states]);
  const footer = Buffer.from('TRAILING_BINARY_PAYLOAD');
  fs.writeFileSync(filePath, Buffer.concat([header, sentinel, wire, footer]));
  return filePath;
}

try {
  // 1. FuseVersion is exported as an object defining V1 with value "1"
  assert.equal(typeof FuseVersion, 'object', 'FuseVersion must be an object');
  assert.strictEqual(FuseVersion.V1, '1', 'FuseVersion.V1 must be "1"');
  assert.strictEqual(FuseVersion, electronFuses.FuseVersion, 'FuseVersion must match package export');
  assert.deepEqual(Object.keys(FuseVersion), ['V1'], 'FuseVersion keys must be [V1]');
  assert.deepEqual(getSupportedFuseVersions(), [FuseVersion.V1], 'supported versions must contain V1');
  assert.strictEqual(isValidFuseVersion(FuseVersion.V1), true, 'FuseVersion.V1 must be valid');
  assert.strictEqual(isValidFuseVersion('2'), false, 'Version 2 must not be valid');

  // 2. getCurrentFuseWire returns wire configuration with version matching FuseVersion.V1 for version 1 binary
  const bin1 = createMockBinary('app_v1.bin', 1);
  const wire = await getCurrentFuseWire(bin1);
  assert.strictEqual(wire.version, FuseVersion.V1, 'wire version must match FuseVersion.V1');
  const detectedVersion = await readFuseVersion(bin1);
  assert.strictEqual(detectedVersion, FuseVersion.V1, 'readFuseVersion must return FuseVersion.V1');

  // 3. configureFusesWithVersion flips fuses in binary when targeting FuseVersion.V1
  const flippedCount = await configureFusesWithVersion(bin1, FuseVersion.V1, {
    [FuseV1Options.RunAsNode]: false,
    [FuseV1Options.EnableCookieEncryption]: true
  });
  assert.equal(flippedCount, 1, 'must flip 1 sentinel');
  const updatedWire = await getCurrentFuseWire(bin1);
  assert.strictEqual(updatedWire.version, FuseVersion.V1, 'wire version must remain FuseVersion.V1');
  assert.strictEqual(updatedWire[FuseV1Options.RunAsNode], 48, 'RunAsNode should be 48 (DISABLE)');
  assert.strictEqual(updatedWire[FuseV1Options.EnableCookieEncryption], 49, 'EnableCookieEncryption should be 49 (ENABLE)');

  // 4. configureFusesWithVersion throws error when called with unsupported fuse version
  await assert.rejects(
    async () => configureFusesWithVersion(bin1, '2', { [FuseV1Options.RunAsNode]: false }),
    /Unsupported fuse version number: 2/,
    'must reject unsupported version number'
  );

  // 5. configureFusesWithVersion throws error when target binary wire version does not match FuseVersion
  const binV2 = createMockBinary('app_v2.bin', 2);
  await assert.rejects(
    async () => configureFusesWithVersion(binV2, FuseVersion.V1, { [FuseV1Options.RunAsNode]: false }),
    /does not match watch was found in the binary "2"/,
    'must reject when binary wire version differs from FuseVersion.V1'
  );

  console.log('Contract tests passed successfully.');
} finally {
  fs.rmSync(tempDir, { recursive: true, force: true });
}

Ursprungs-Seeder

anonym