CodeSampleX

サンプル

electron 43.8.8

検証済みサンプル — npm electron 43.8.8. node 22 · linux debian/x64 · docker で contract を実行し、成功しました: resolveElectronExecutable loads electron/index.js with…

sha256:cee2b9187bf9bc885742ebd6567ff6dd13618671bc60250f5a9603a85be1f41b

このネットワークが提供するのは一つだけです。ビルドされるサンプル。サンドボックスで実行し、署名済みの受領証を保管します。等級はつけず、何も保証しません — 同じコードがあなたの環境でビルドされるかは測定していません。 合格した契約受領証を提出した異なる署名鍵の数です。1 なら作者だけ、2 以上なら他の誰かもビルドしています。鍵は自己生成で背後に登録された身元がないため、数えているのは人ではなく鍵です。 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-11-29

ケース

HOW
ゴール
verify pkg:npm/electron@43.8.8
パッケージ
環境
node 22.23.2
作成日
2026-11-29T04:05:31Z

コントラクト

  1. resolveElectronExecutable loads electron/index.js with ELECTRON_OVERRIDE_DIST_PATH offline and returns the overridden electron executable path without downloading
  2. runElectronCli invokes electron/cli.js against an overridden executable, forwards CLI arguments verbatim, and propagates exit codes
  3. readElectronPackageInfo reports electron version 43.8.8, main index.js, types electron.d.ts, cli.js and install.js bin entries, node >= 22.12.0 engine constraint, and ABI version 148
  4. verifyBundledTypeDefinitionsChecksum confirms installed electron.d.ts matches its SHA-256 entry in checksums.json
  5. getReleaseArtifactChecksum returns exact SHA-256 digests for linux-x64, darwin-arm64, and win32-x64 electron@43.8.8 release archives and null for unknown targets

ファイル

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

ソースアーティファクトをダウンロード (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 pkg:npm/electron@43.8.8
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:npm/electron@43.8.8
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.
csx.json
{"case":{"caseId":"case:sha256:57e23fe4a3092a282b52a8c61dd4fe1d6f87617747f1cbeed5e586c60296b510","constraints":{"executionContext":"node"},"contract":["resolveElectronExecutable loads electron/index.js with ELECTRON_OVERRIDE_DIST_PATH offline and returns the overridden electron executable path without downloading","runElectronCli invokes electron/cli.js against an overridden executable, forwards CLI arguments verbatim, and propagates exit codes","readElectronPackageInfo reports electron version 43.8.8, main index.js, types electron.d.ts, cli.js and install.js bin entries, node \u003e= 22.12.0 engine constraint, and ABI version 148","verifyBundledTypeDefinitionsChecksum confirms installed electron.d.ts matches its SHA-256 entry in checksums.json","getReleaseArtifactChecksum returns exact SHA-256 digests for linux-x64, darwin-arm64, and win32-x64 electron@43.8.8 release archives and null for unknown targets"],"goal":"verify pkg:npm/electron@43.8.8","kind":"HOW","packages":["pkg:npm/electron@43.8.8"],"schemaVersion":1},"contractCommand":["node","test/contract.cjs"],"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/electron@43.8.8"],"schemaVersion":1,"subject":"pkg:npm/electron@43.8.8","verifierAdapter":"node-typescript@1"}
index.js
'use strict';

const { spawnSync } = require('child_process');
const crypto = require('crypto');
const fs = require('fs');
const path = require('path');

function getElectronPackageDir() {
  return path.dirname(require.resolve('electron/package.json'));
}

/**
 * Resolve the Electron executable path through electron/index.js using
 * ELECTRON_OVERRIDE_DIST_PATH without triggering a network download.
 */
function resolveElectronExecutable(overrideDistDir) {
  if (typeof overrideDistDir !== 'string' || overrideDistDir.trim().length === 0) {
    throw new TypeError('overrideDistDir must be a non-empty string');
  }

  const entryPath = require.resolve('electron');
  const hadOverride = Object.prototype.hasOwnProperty.call(
    process.env,
    'ELECTRON_OVERRIDE_DIST_PATH'
  );
  const previousOverride = process.env.ELECTRON_OVERRIDE_DIST_PATH;
  const previousCache = require.cache[entryPath];

  try {
    process.env.ELECTRON_OVERRIDE_DIST_PATH = overrideDistDir;
    delete require.cache[entryPath];
    return require('electron');
  } finally {
    delete require.cache[entryPath];
    if (previousCache) {
      require.cache[entryPath] = previousCache;
    }
    if (hadOverride) {
      process.env.ELECTRON_OVERRIDE_DIST_PATH = previousOverride;
    } else {
      delete process.env.ELECTRON_OVERRIDE_DIST_PATH;
    }
  }
}

/**
 * Invoke electron's cli.js launcher with an overridden distribution directory
 * and forward arguments to the resolved executable.
 */
function runElectronCli(overrideDistDir, args = []) {
  if (typeof overrideDistDir !== 'string' || overrideDistDir.trim().length === 0) {
    throw new TypeError('overrideDistDir must be a non-empty string');
  }

  const pkgDir = getElectronPackageDir();
  const pkg = JSON.parse(fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8'));
  const cliPath = path.join(pkgDir, pkg.bin.electron);

  const result = spawnSync(process.execPath, [cliPath, ...args], {
    encoding: 'utf8',
    env: {
      ...process.env,
      ELECTRON_OVERRIDE_DIST_PATH: overrideDistDir
    }
  });

  if (result.error) {
    throw result.error;
  }

  return {
    status: result.status,
    stdout: result.stdout,
    stderr: result.stderr
  };
}

/**
 * Read installed electron package metadata and ABI version.
 */
function readElectronPackageInfo() {
  const pkgDir = getElectronPackageDir();
  const pkg = JSON.parse(fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8'));
  const abiVersion = fs.readFileSync(path.join(pkgDir, 'abi_version'), 'utf8').trim();

  return {
    name: pkg.name,
    version: pkg.version,
    main: pkg.main,
    types: pkg.types,
    bin: pkg.bin,
    engines: pkg.engines,
    abiVersion
  };
}

/**
 * Verify that the bundled electron.d.ts file matches its SHA-256 entry in checksums.json.
 */
function verifyBundledTypeDefinitionsChecksum() {
  const pkgDir = getElectronPackageDir();
  const checksums = JSON.parse(fs.readFileSync(path.join(pkgDir, 'checksums.json'), 'utf8'));
  const dtsBytes = fs.readFileSync(path.join(pkgDir, 'electron.d.ts'));
  const actual = crypto.createHash('sha256').update(dtsBytes).digest('hex');
  const expected = checksums['electron.d.ts'] || null;

  return {
    expected,
    actual,
    valid: expected !== null && actual === expected,
    artifactCount: Object.keys(checksums).length
  };
}

/**
 * Look up the SHA-256 checksum for a release artifact in checksums.json.
 */
function getReleaseArtifactChecksum(platform, arch, prefix = 'electron') {
  const pkgDir = getElectronPackageDir();
  const pkg = JSON.parse(fs.readFileSync(path.join(pkgDir, 'package.json'), 'utf8'));
  const checksums = JSON.parse(fs.readFileSync(path.join(pkgDir, 'checksums.json'), 'utf8'));
  const filename = `${prefix}-v${pkg.version}-${platform}-${arch}.zip`;

  return {
    filename,
    sha256: Object.prototype.hasOwnProperty.call(checksums, filename) ? checksums[filename] : null
  };
}

module.exports = {
  resolveElectronExecutable,
  runElectronCli,
  readElectronPackageInfo,
  verifyBundledTypeDefinitionsChecksum,
  getReleaseArtifactChecksum
};
package-lock.json
{
  "name": "verify-electron-sample",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "verify-electron-sample",
      "version": "1.0.0",
      "license": "MIT-0",
      "dependencies": {
        "electron": "43.8.8"
      }
    },
    "node_modules/@electron-internal/extract-zip": {
      "version": "1.0.10",
      "resolved": "https://registry.npmjs.org/@electron-internal/extract-zip/-/extract-zip-1.0.10.tgz",
      "integrity": "sha512-3ZpfrVbqRKZ1/K0BjUfziapy3aZQzDeJX70SbsO8tc+gGlzJYnFAgZGE8LtxMV19RsoF8+Uwvd04FtIiMD4KyA==",
      "license": "MIT",
      "engines": {
        "node": ">=22.12.0"
      }
    },
    "node_modules/@electron/get": {
      "version": "5.1.0",
      "resolved": "https://registry.npmjs.org/@electron/get/-/get-5.1.0.tgz",
      "integrity": "sha512-3kSBtG8ObcTVfXanm5vVJ6UnBLEVmVsRk1M+vGqCuMBV+XLCbJYuWQful+yIy0GQDsSlK0kHEriEHn7SPk4EnA==",
      "license": "MIT",
      "dependencies": {
        "debug": "^4.1.1",
        "env-paths": "^3.0.0",
        "graceful-fs": "^4.2.11",
        "progress": "^2.0.3",
        "semver": "^7.6.3",
        "sumchecker": "^3.0.1"
      },
      "engines": {
        "node": ">=22.12.0"
      },
      "optionalDependencies": {
        "undici": "^7.24.4"
      }
    },
    "node_modules/@types/node": {
      "version": "24.19.4",
      "resolved": "https://registry.npmjs.org/@types/node/-/node-24.19.4.tgz",
      "integrity": "sha512-s04odlR3ksJrLu7QLi+pddkWLD0RmSbcP9KuWn2/ozQKAp/YgwBC/6x9kJj8yAzZnGPfxePm7zm7nysVPCRagw==",
      "license": "MIT",
      "dependencies": {
        "undici-types": ">=7.24.0 <7.24.7"
      }
    },
    "node_modules/debug": {
      "version": "4.4.3",
      "resolved": "https://registry.npmjs.org/debug/-/debug-4.4.3.tgz",
      "integrity": "sha512-RGwwWnwQvkVfavKVt22FGLw+xYSdzARwm0ru6DhTVA3umU5hZc28V3kO4stgYryrTlLpuvgI9GiijltAjNbcqA==",
      "license": "MIT",
      "dependencies": {
        "ms": "^2.1.3"
      },
      "engines": {
        "node": ">=6.0"
      },
      "peerDependenciesMeta": {
        "supports-color": {
          "optional": true
        }
      }
    },
    "node_modules/electron": {
      "version": "43.8.8",
      "resolved": "https://registry.npmjs.org/electron/-/electron-43.8.8.tgz",
      "integrity": "sha512-IQV9i7e5M1YJdhRyARa0gZLJ7Y1nD/m43/ywYb22jnyTuW3mKIKrRd93jEmnnj60gM296oVA1Fac6eH0JccW8A==",
      "license": "MIT",
      "dependencies": {
        "@electron-internal/extract-zip": "^1.0.1",
        "@electron/get": "^5.0.0",
        "@types/node": "^24.9.0"
      },
      "bin": {
        "electron": "cli.js",
        "install-electron": "install.js"
      },
      "engines": {
        "node": ">= 22.12.0"
      }
    },
    "node_modules/env-paths": {
      "version": "3.0.0",
      "resolved": "https://registry.npmjs.org/env-paths/-/env-paths-3.0.0.tgz",
      "integrity": "sha512-dtJUTepzMW3Lm/NPxRf3wP4642UWhjL2sQxc+ym2YMj1m/H2zDNQOlezafzkHwn6sMstjHTwG6iQQsctDW/b1A==",
      "license": "MIT",
      "engines": {
        "node": "^12.20.0 || ^14.13.1 || >=16.0.0"
      },
      "funding": {
        "url": "https://github.com/sponsors/sindresorhus"
      }
    },
    "node_modules/graceful-fs": {
      "version": "4.2.12",
      "resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.12.tgz",
      "integrity": "sha512-iuyGF2E4oafQfPsRrG2wtY2ILupMhvtdrhzrxB+0VcjsPpSPttpfYdjnGFGsTi5MaJFjI1jOKHPQ6UTbTj9TAw==",
      "license": "BlueOak-1.0.0"
    },
    "node_modules/ms": {
      "version": "2.1.3",
      "resolved": "https://registry.npmjs.org/ms/-/ms-2.1.3.tgz",
      "integrity": "sha512-6FlzubTLZG3J2a/NVCAleEhjzq5oxgHyaCU9yYXvcLsvoVaHJq/s5xXI6/XXP6tz7R9xAOtHnSO/tXtF3WRTlA==",
      "license": "MIT"
    },
    "node_modules/progress": {
      "version": "2.0.3",
      "resolved": "https://registry.npmjs.org/progress/-/progress-2.0.3.tgz",
      "integrity": "sha512-7PiHtLll5LdnKIMw100I+8xJXR5gW2QwWYkT6iJva0bXitZKa/XMrSbdmg3r2Xnaidz9Qumd0VPaMrZlF9V9sA==",
      "license": "MIT",
      "engines": {
        "node": ">=0.4.0"
      }
    },
    "node_modules/semver": {
      "version": "7.8.6",
      "resolved": "https://registry.npmjs.org/semver/-/semver-7.8.6.tgz",
      "integrity": "sha512-9lpSSU4Mly3mrtruwLs1eLK6+gzbzqeBFwRNjIjE+9LuDpWdYctrQlQ3ej1Ilgi7gknpsTRnPoLP8DpCHqHIJw==",
      "license": "ISC",
      "bin": {
        "semver": "bin/semver.js"
      },
      "engines": {
        "node": ">=10"
      }
    },
    "node_modules/sumchecker": {
      "version": "3.0.1",
      "resolved": "https://registry.npmjs.org/sumchecker/-/sumchecker-3.0.1.tgz",
      "integrity": "sha512-MvjXzkz/BOfyVDkG0oFOtBxHX2u3gKbMHIF/dXblZsgD3BWOFLmHovIpZY7BykJdAjcqRCBi1WYBNdEC9yI7vg==",
      "license": "Apache-2.0",
      "dependencies": {
        "debug": "^4.1.0"
      },
      "engines": {
        "node": ">= 8.0"
      }
    },
    "node_modules/undici": {
      "version": "7.30.2",
      "resolved": "https://registry.npmjs.org/undici/-/undici-7.30.2.tgz",
      "integrity": "sha512-mLyPQnHwUxaM/rideoK/+KL8DaAJLRl4aBCfmX444aCSLnIaomqPLtNRe2jdCYcsk5wZzXrDIQC8ZeYNRAYyIA==",
      "license": "MIT",
      "optional": true,
      "engines": {
        "node": ">=20.18.1"
      }
    },
    "node_modules/undici-types": {
      "version": "7.24.6",
      "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-7.24.6.tgz",
      "integrity": "sha512-WRNW+sJgj5OBN4/0JpHFqtqzhpbnV0GuB+OozA9gCL7a993SmU+1JBZCzLNxYsbMfIeDL+lTsphD5jN5N+n0zg==",
      "license": "MIT"
    }
  }
}
package.json
{
  "name": "verify-electron-sample",
  "version": "1.0.0",
  "private": true,
  "description": "Clean-room verification sample for electron@43.8.8 in Node.js",
  "main": "index.js",
  "scripts": {
    "test": "node test/contract.cjs"
  },
  "dependencies": {
    "electron": "43.8.8"
  },
  "license": "MIT-0"
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:npm/electron@43.8.8",
  "kind": "HOW",
  "packages": [
    "pkg:npm/electron@43.8.8"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.cjs
'use strict';

const assert = require('assert');
const fs = require('fs');
const os = require('os');
const path = require('path');

const {
  resolveElectronExecutable,
  runElectronCli,
  readElectronPackageInfo,
  verifyBundledTypeDefinitionsChecksum,
  getReleaseArtifactChecksum
} = require('../index.js');

function run() {
  // 1. require('electron') resolves ELECTRON_OVERRIDE_DIST_PATH offline via electron/index.js
  const customDistDir = path.join(os.tmpdir(), 'custom-electron-dist');
  const resolved = resolveElectronExecutable(customDistDir);
  assert.strictEqual(
    resolved,
    path.join(customDistDir, 'electron'),
    'require("electron") must join ELECTRON_OVERRIDE_DIST_PATH with electron binary name'
  );
  assert.throws(
    () => resolveElectronExecutable(''),
    TypeError,
    'Empty override directory must throw TypeError'
  );

  // 2. electron/cli.js spawns the overridden executable, forwards arguments, and propagates exit codes
  const tempDist = fs.mkdtempSync(path.join(os.tmpdir(), 'electron-cli-override-'));
  try {
    const stubExecutable = path.join(tempDist, 'electron');
    const stubSource = [
      `#!${process.execPath}`,
      'const args = process.argv.slice(2);',
      'const exitIdx = args.indexOf("--exit-code");',
      'const code = exitIdx >= 0 ? Number(args[exitIdx + 1]) : 0;',
      'process.stdout.write(JSON.stringify({ args }));',
      'process.exit(code);'
    ].join('\n');
    fs.writeFileSync(stubExecutable, stubSource, { mode: 0o755 });
    fs.chmodSync(stubExecutable, 0o755);

    const okRun = runElectronCli(tempDist, ['--version', '--flag=value']);
    assert.strictEqual(okRun.status, 0, 'cli.js must exit 0 when child exits 0');
    assert.deepStrictEqual(
      JSON.parse(okRun.stdout),
      { args: ['--version', '--flag=value'] },
      'cli.js must forward CLI arguments verbatim to the overridden executable'
    );

    const failRun = runElectronCli(tempDist, ['--exit-code', '7']);
    assert.strictEqual(failRun.status, 7, 'cli.js must propagate non-zero child exit codes');
  } finally {
    fs.rmSync(tempDist, { recursive: true, force: true });
  }

  // 3. electron@43.8.8 package metadata and ABI version match release manifest
  const info = readElectronPackageInfo();
  assert.strictEqual(info.name, 'electron', 'Package name must be electron');
  assert.strictEqual(info.version, '43.8.8', 'Package version must be 43.8.8');
  assert.strictEqual(info.main, 'index.js', 'Package main must be index.js');
  assert.strictEqual(info.types, 'electron.d.ts', 'Package types must be electron.d.ts');
  assert.strictEqual(info.bin.electron, 'cli.js', 'bin.electron must point to cli.js');
  assert.strictEqual(
    info.bin['install-electron'],
    'install.js',
    'bin["install-electron"] must point to install.js'
  );
  assert.strictEqual(info.engines.node, '>= 22.12.0', 'engines.node must require >= 22.12.0');
  assert.strictEqual(info.abiVersion, '148', 'electron@43.8.8 ABI version must be 148');

  // 4. Bundled electron.d.ts matches its SHA-256 digest in checksums.json
  const dtsCheck = verifyBundledTypeDefinitionsChecksum();
  assert.strictEqual(dtsCheck.valid, true, 'Bundled electron.d.ts must match checksums.json digest');
  assert.strictEqual(
    dtsCheck.actual,
    '29e50108b1290afbad8dbad91054bd12ee21a6ee864ba5d251c0acdde918864c',
    'electron.d.ts SHA-256 digest must match expected 43.8.8 release hash'
  );
  assert.ok(dtsCheck.artifactCount > 50, 'checksums.json must list release artifacts');

  // 5. checksums.json exposes exact SHA-256 hashes for 43.8.8 release archives and null for unknown targets
  const linuxX64 = getReleaseArtifactChecksum('linux', 'x64');
  assert.strictEqual(linuxX64.filename, 'electron-v43.8.8-linux-x64.zip');
  assert.strictEqual(
    linuxX64.sha256,
    'da1b962020a5a76330ebfca23ddedc4e27f7a1c369fdcff668a8a211792fcf55'
  );

  const darwinArm64 = getReleaseArtifactChecksum('darwin', 'arm64');
  assert.strictEqual(darwinArm64.filename, 'electron-v43.8.8-darwin-arm64.zip');
  assert.strictEqual(
    darwinArm64.sha256,
    '3c6d3425e91885b5c2deecfdb97e4392040785106f10b32cc50c964cdd2203a7'
  );

  const win32X64 = getReleaseArtifactChecksum('win32', 'x64');
  assert.strictEqual(win32X64.filename, 'electron-v43.8.8-win32-x64.zip');
  assert.strictEqual(
    win32X64.sha256,
    '651dda2695f4744b8b055640e475a8de4935a08f18a54a285f55a9b1ed0b157a'
  );

  const unknownTarget = getReleaseArtifactChecksum('plan9', 'mips');
  assert.strictEqual(unknownTarget.sha256, null, 'Unknown release artifact must return null');

  console.log('electron@43.8.8 contract passed');
}

run();

オリジンシーダー

匿名