CodeSampleX

示例

@electron/fuses 1.8.0: getCurrentFuseWire

已验证示例 — npm @electron/fuses 1.8.0: getCurrentFuseWire. contract 在 node 22 · linux debian/x64 · docker 上运行并通过: getCurrentFuseWire is exported as a function…

sha256:c45f7e0d50234146b9a9097bd1d1ecdc2c49c3c5b33c416cd885d3cf6d6b8df1

本网络只提供一件事:能构建的样本。它在沙箱中运行并保留签名回执。它不评级、不担保——同样的代码能否在你的环境构建,它没有测量过。 提交了通过的契约回执的不同签名密钥数量。为 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 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

案例

HOW
目标
verify @electron/fuses.getCurrentFuseWire in pkg:npm/%40electron/fuses@1.8.0
包
符号
  • @electron/fuses.getCurrentFuseWire
环境
node 22.23.2
创建时间
2026-09-04T10:04:06Z

契约

  1. getCurrentFuseWire is exported as a function from @electron/fuses
  2. getCurrentFuseWire decodes fuse version and wire states from binary containing fuse sentinel
  3. getCurrentFuseWire decodes enable, disable, inherit, and removed fuse states correctly
  4. getCurrentFuseWire resolves internal binary path when given macOS .app bundle directory
  5. getCurrentFuseWire rejects when sentinel magic bytes are absent in target binary
  6. getCurrentFuseWire rejects when target binary path does not exist

文件

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

下载源代码构件 (tar.gz)

源代码

.npmrc
audit=false
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.getCurrentFuseWire 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.getCurrentFuseWire
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:d407bf1be31dd180c92c163fa990190758a5d86f12cc40cf02b0a5a254dff423","constraints":{"executionContext":"node"},"contract":["getCurrentFuseWire is exported as a function from @electron/fuses","getCurrentFuseWire decodes fuse version and wire states from binary containing fuse sentinel","getCurrentFuseWire decodes enable, disable, inherit, and removed fuse states correctly","getCurrentFuseWire resolves internal binary path when given macOS .app bundle directory","getCurrentFuseWire rejects when sentinel magic bytes are absent in target binary","getCurrentFuseWire rejects when target binary path does not exist"],"goal":"verify @electron/fuses.getCurrentFuseWire in pkg:npm/%40electron/fuses@1.8.0","kind":"HOW","packages":["pkg:npm/%40electron/fuses@1.8.0"],"schemaVersion":1,"symbols":["@electron/fuses.getCurrentFuseWire"]},"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.getCurrentFuseWire"],"verifierAdapter":"node-typescript@1"}
package-lock.json
{
  "name": "sample-electron-fuses",
  "version": "1.0.0",
  "lockfileVersion": 3,
  "requires": true,
  "packages": {
    "": {
      "name": "sample-electron-fuses",
      "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": "1.0.0",
  "private": true,
  "type": "module",
  "license": "MIT-0",
  "dependencies": {
    "@electron/fuses": "1.8.0"
  }
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify @electron/fuses.getCurrentFuseWire in pkg:npm/%40electron/fuses@1.8.0",
  "kind": "HOW",
  "packages": [
    "pkg:npm/%40electron/fuses@1.8.0"
  ],
  "symbols": [
    "@electron/fuses.getCurrentFuseWire"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.mjs
import assert from 'node:assert/strict';
import fs from 'node:fs/promises';
import path from 'node:path';
import os from 'node:os';
import {
  getCurrentFuseWire,
  FuseVersion,
  FuseV1Options,
} from '@electron/fuses';

const SENTINEL = 'dL7pKGdnNz796PbbjQWNKmHXBZaB9tsX';
const sentinelBuf = Buffer.from(SENTINEL, 'utf8');

const FuseState = {
  DISABLE: 48,
  ENABLE: 49,
  REMOVED: 114,
  INHERIT: 144,
};

const tmpDir = await fs.mkdtemp(path.join(os.tmpdir(), 'fuses-contract-'));

try {
  // 1. getCurrentFuseWire is exported as a function from @electron/fuses
  {
    assert.equal(typeof getCurrentFuseWire, 'function');
  }

  // 2. getCurrentFuseWire decodes fuse version and wire states from binary containing fuse sentinel
  {
    const mockBin = path.join(tmpDir, 'electron-basic');
    const wireBuf = Buffer.from([1, 8, 48, 49, 144, 144, 48, 49, 144, 144]);
    const binData = Buffer.concat([
      Buffer.from('ELF_MAGIC_HEADER'),
      sentinelBuf,
      wireBuf,
      Buffer.from('TRAILING_DATA'),
    ]);
    await fs.writeFile(mockBin, binData);

    const wire = await getCurrentFuseWire(mockBin);
    assert.equal(wire.version, FuseVersion.V1);
    assert.equal(wire[FuseV1Options.RunAsNode], 48);
    assert.equal(wire[FuseV1Options.EnableCookieEncryption], 49);
    assert.equal(wire[FuseV1Options.EnableNodeOptionsEnvironmentVariable], 144);
    assert.equal(wire[FuseV1Options.EnableNodeCliInspectArguments], 144);
    assert.equal(wire[FuseV1Options.EnableEmbeddedAsarIntegrityValidation], 48);
    assert.equal(wire[FuseV1Options.OnlyLoadAppFromAsar], 49);
  }

  // 3. getCurrentFuseWire decodes enable, disable, inherit, and removed fuse states correctly
  {
    const mockBin = path.join(tmpDir, 'electron-states');
    const wireBuf = Buffer.from([
      1,
      8,
      FuseState.DISABLE,
      FuseState.ENABLE,
      FuseState.INHERIT,
      FuseState.REMOVED,
      FuseState.DISABLE,
      FuseState.ENABLE,
      FuseState.INHERIT,
      FuseState.REMOVED,
    ]);
    await fs.writeFile(mockBin, Buffer.concat([sentinelBuf, wireBuf]));

    const wire = await getCurrentFuseWire(mockBin);
    assert.equal(wire[0], FuseState.DISABLE);
    assert.equal(wire[1], FuseState.ENABLE);
    assert.equal(wire[2], FuseState.INHERIT);
    assert.equal(wire[3], FuseState.REMOVED);
    assert.equal(wire[4], FuseState.DISABLE);
    assert.equal(wire[5], FuseState.ENABLE);
    assert.equal(wire[6], FuseState.INHERIT);
    assert.equal(wire[7], FuseState.REMOVED);
  }

  // 4. getCurrentFuseWire resolves internal binary path when given macOS .app bundle directory
  {
    const appDir = path.join(tmpDir, 'TestApp.app');
    const frameworkDir = path.join(appDir, 'Contents', 'Frameworks', 'Electron Framework.framework');
    await fs.mkdir(frameworkDir, { recursive: true });
    const innerBin = path.join(frameworkDir, 'Electron Framework');

    const wireBuf = Buffer.from([1, 4, 49, 48, 49, 48]);
    await fs.writeFile(innerBin, Buffer.concat([Buffer.from('MACHO_HEADER'), sentinelBuf, wireBuf]));

    const wire = await getCurrentFuseWire(appDir);
    assert.equal(wire.version, '1');
    assert.equal(wire[0], 49);
    assert.equal(wire[1], 48);
    assert.equal(wire[2], 49);
    assert.equal(wire[3], 48);
  }

  // 5. getCurrentFuseWire rejects when sentinel magic bytes are absent in target binary
  {
    const noSentinelBin = path.join(tmpDir, 'no-sentinel');
    await fs.writeFile(noSentinelBin, Buffer.from('binary-content-without-magic-bytes'));

    await assert.rejects(
      () => getCurrentFuseWire(noSentinelBin),
      /Could not find sentinel in the provided Electron binary/
    );
  }

  // 6. getCurrentFuseWire rejects when target binary path does not exist
  {
    const nonExistentPath = path.join(tmpDir, 'does-not-exist.bin');
    await assert.rejects(
      () => getCurrentFuseWire(nonExistentPath),
      { code: 'ENOENT' }
    );
  }

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

原始种子者

匿名