@layerzerolabs/vm-tooling-stellar 0.2.113 → 0.2.115
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/6YPWRWU3.js +96 -0
- package/dist/6YPWRWU3.js.map +1 -0
- package/dist/ITF544RZ.js +18485 -0
- package/dist/ITF544RZ.js.map +1 -0
- package/dist/commands/verifiable-build.d.ts +48 -0
- package/dist/commands/verifiable-build.d.ts.map +1 -0
- package/dist/commands/verifiable-build.js +4 -0
- package/dist/commands/verifiable-build.js.map +1 -0
- package/dist/commands/verifiable-build.test.js +120 -0
- package/dist/commands/verifiable-build.test.js.map +1 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -0
- package/dist/index.js.map +1 -1
- package/dist/index.test.js +3 -18480
- package/dist/index.test.js.map +1 -1
- package/package.json +5 -5
package/dist/6YPWRWU3.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import { init_esm_shims, __name } from './2VBLSQAK.js';
|
|
2
|
+
import { execFile, spawn } from 'child_process';
|
|
3
|
+
import { promisify } from 'util';
|
|
4
|
+
|
|
5
|
+
// src/commands/verifiable-build.ts
|
|
6
|
+
init_esm_shims();
|
|
7
|
+
var execFileAsync = promisify(execFile);
|
|
8
|
+
var SOURCE_MOUNT = "/source";
|
|
9
|
+
var VERIFIABLE_BUILD_PLATFORM = "linux/amd64";
|
|
10
|
+
var OFFICIAL_IMAGE_REPO = "stellar/stellar-cli";
|
|
11
|
+
var officialImageTagRef = /* @__PURE__ */ __name((stellarVersion, rustVersion) => `${OFFICIAL_IMAGE_REPO}:${stellarVersion}-rust${rustVersion}-slim-bookworm`, "officialImageTagRef");
|
|
12
|
+
var parseAmd64Digest = /* @__PURE__ */ __name((manifestInspectJson) => {
|
|
13
|
+
const { manifests } = JSON.parse(manifestInspectJson);
|
|
14
|
+
if (!Array.isArray(manifests)) {
|
|
15
|
+
throw new Error("`docker manifest inspect` did not return a multi-arch index (no `manifests` array)");
|
|
16
|
+
}
|
|
17
|
+
const digest = manifests.find(({ platform }) => platform?.os === "linux" && platform?.architecture === "amd64")?.digest;
|
|
18
|
+
if (typeof digest !== "string" || !digest.startsWith("sha256:")) {
|
|
19
|
+
throw new Error("No linux/amd64 manifest digest found in `docker manifest inspect` output");
|
|
20
|
+
}
|
|
21
|
+
return digest;
|
|
22
|
+
}, "parseAmd64Digest");
|
|
23
|
+
var resolveAmd64Digest = /* @__PURE__ */ __name(async (imageTagRef) => {
|
|
24
|
+
try {
|
|
25
|
+
const { stdout } = await execFileAsync("docker", [
|
|
26
|
+
"manifest",
|
|
27
|
+
"inspect",
|
|
28
|
+
imageTagRef
|
|
29
|
+
], {
|
|
30
|
+
maxBuffer: 16 * 1024 * 1024
|
|
31
|
+
});
|
|
32
|
+
return parseAmd64Digest(stdout);
|
|
33
|
+
} catch (cause) {
|
|
34
|
+
throw new Error(`Failed to resolve the linux/amd64 digest of ${imageTagRef} (\`docker manifest inspect\`)`, {
|
|
35
|
+
cause
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
}, "resolveAmd64Digest");
|
|
39
|
+
var buildVerifiableBuildDockerArgs = /* @__PURE__ */ __name(({ imageRef, sourceDir, buildArgs, bldimg }) => [
|
|
40
|
+
"run",
|
|
41
|
+
"--rm",
|
|
42
|
+
"--platform",
|
|
43
|
+
VERIFIABLE_BUILD_PLATFORM,
|
|
44
|
+
"-v",
|
|
45
|
+
`${sourceDir}:${SOURCE_MOUNT}`,
|
|
46
|
+
"-w",
|
|
47
|
+
SOURCE_MOUNT,
|
|
48
|
+
imageRef,
|
|
49
|
+
"contract",
|
|
50
|
+
"build",
|
|
51
|
+
...buildArgs,
|
|
52
|
+
// Embedded by us (not the user): the exact build image, so the WASM records what produced it.
|
|
53
|
+
"--meta",
|
|
54
|
+
`bldimg=${bldimg}`
|
|
55
|
+
], "buildVerifiableBuildDockerArgs");
|
|
56
|
+
var runDocker = /* @__PURE__ */ __name((dockerArgs) => new Promise((resolve, reject) => {
|
|
57
|
+
const child = spawn("docker", dockerArgs, {
|
|
58
|
+
stdio: "inherit"
|
|
59
|
+
});
|
|
60
|
+
child.on("error", (error) => reject(new Error("Failed to spawn docker for the verifiable build", {
|
|
61
|
+
cause: error
|
|
62
|
+
})));
|
|
63
|
+
child.on("close", (code, signal) => {
|
|
64
|
+
if (code === 0) {
|
|
65
|
+
resolve();
|
|
66
|
+
} else {
|
|
67
|
+
reject(new Error(`Verifiable build failed: docker exited with ${signal ? `signal ${signal}` : `code ${code}`}`));
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
}), "runDocker");
|
|
71
|
+
var VerifiableBuildWrapper = class {
|
|
72
|
+
static {
|
|
73
|
+
__name(this, "VerifiableBuildWrapper");
|
|
74
|
+
}
|
|
75
|
+
async run(args, { stellarVersion, rustVersion }, options) {
|
|
76
|
+
const tagRef = officialImageTagRef(stellarVersion, rustVersion);
|
|
77
|
+
const digest = await resolveAmd64Digest(tagRef);
|
|
78
|
+
const imageRef = `${OFFICIAL_IMAGE_REPO}@${digest}`;
|
|
79
|
+
const bldimg = `docker.io/${OFFICIAL_IMAGE_REPO}@${digest}`;
|
|
80
|
+
const dockerArgs = buildVerifiableBuildDockerArgs({
|
|
81
|
+
imageRef,
|
|
82
|
+
sourceDir: options.cwd,
|
|
83
|
+
buildArgs: args,
|
|
84
|
+
bldimg
|
|
85
|
+
});
|
|
86
|
+
console.info("\u{1F512} Verifiable build (official stellar/stellar-cli image, run from host)");
|
|
87
|
+
console.info(` image: ${imageRef} (${VERIFIABLE_BUILD_PLATFORM}, from tag ${tagRef})`);
|
|
88
|
+
console.info(` bldimg: ${bldimg}`);
|
|
89
|
+
console.info(` docker ${dockerArgs.join(" ")}`);
|
|
90
|
+
await runDocker(dockerArgs);
|
|
91
|
+
}
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export { VerifiableBuildWrapper, buildVerifiableBuildDockerArgs, officialImageTagRef, parseAmd64Digest };
|
|
95
|
+
//# sourceMappingURL=6YPWRWU3.js.map
|
|
96
|
+
//# sourceMappingURL=6YPWRWU3.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/commands/verifiable-build.ts"],"names":["execFileAsync","promisify","execFile","SOURCE_MOUNT","VERIFIABLE_BUILD_PLATFORM","OFFICIAL_IMAGE_REPO","officialImageTagRef","stellarVersion","rustVersion","parseAmd64Digest","manifestInspectJson","manifests","JSON","parse","Array","isArray","Error","digest","find","platform","os","architecture","startsWith","resolveAmd64Digest","imageTagRef","stdout","maxBuffer","cause","buildVerifiableBuildDockerArgs","imageRef","sourceDir","buildArgs","bldimg","runDocker","dockerArgs","Promise","resolve","reject","child","spawn","stdio","on","error","code","signal","VerifiableBuildWrapper","run","args","options","tagRef","cwd","console","info","join"],"mappings":";;;;;AAAA,cAAA,EAAA;AAKA,IAAMA,aAAAA,GAAgBC,UAAUC,QAAAA,CAAAA;AAIhC,IAAMC,YAAAA,GAAe,SAAA;AAIrB,IAAMC,yBAAAA,GAA4B,aAAA;AAElC,IAAMC,mBAAAA,GAAsB,qBAAA;AAOrB,IAAMC,mBAAAA,mBAAsB,MAAA,CAAA,CAACC,cAAAA,EAAwBC,WAAAA,KACxD,CAAA,EAAGH,mBAAAA,CAAAA,CAAAA,EAAuBE,cAAAA,CAAAA,KAAAA,EAAsBC,WAAAA,CAAAA,cAAAA,CAAAA,EADjB,qBAAA;AAgB5B,IAAMC,gBAAAA,2BAAoBC,mBAAAA,KAAAA;AAC7B,EAAA,MAAM,EAAEC,SAAAA,EAAS,GAAKC,IAAAA,CAAKC,MAAMH,mBAAAA,CAAAA;AAEjC,EAAA,IAAI,CAACI,KAAAA,CAAMC,OAAAA,CAAQJ,SAAAA,CAAAA,EAAY;AAC3B,IAAA,MAAM,IAAIK,MACN,oFAAA,CAAA;AAER,EAAA;AAEA,EAAA,MAAMC,MAAAA,GAASN,SAAAA,CAAUO,IAAAA,CACrB,CAAC,EAAEC,QAAAA,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AA,CAAAA,CAAAA;AAC3C,IAAA,MAAMe,MAAAA,GAAS,CAAA,UAAA,EAAa3B,mBAAAA,CAAAA,CAAAA,EAAuBY,MAAAA,CAAAA,CAAAA;AAEnD,IAAA,MAAMiB,aAAaN,8BAAAA,CAA+B;AAC9CC,MAAAA,QAAAA;AACAC,MAAAA,SAAAA,EAAWkB,OAAAA,CAAQE,GAAAA;MACnBnB,SAAAA,EAAWgB,IAAAA;AACXf,MAAAA;KACJ,CAAA;AAEAmB,IAAAA,OAAAA,CAAQC,KAAK,gFAAA,CAAA;AACbD,IAAAA,OAAAA,CAAQC,KAAK,CAAA,WAAA,EAAcvB,QAAAA,KAAazB,yBAAAA,CAAAA,WAAAA,EAAuC6C,MAAAA,CAAAA,CAAAA,CAAS,CAAA;AACxFE,IAAAA,OAAAA,CAAQC,IAAAA,CAAK,CAAA,WAAA,EAAcpB,MAAAA,CAAAA,CAAQ,CAAA;AACnCmB,IAAAA,OAAAA,CAAQC,KAAK,CAAA,UAAA,EAAalB,UAAAA,CAAWmB,IAAAA,CAAK,GAAA,CAAA,CAAA,CAAM,CAAA;AAEhD,IAAA,MAAMpB,UAAUC,UAAAA,CAAAA;AACpB,EAAA;AACJ","file":"6YPWRWU3.js","sourcesContent":["import { execFile, spawn } from 'node:child_process';\nimport { promisify } from 'node:util';\n\nimport type { ToolCommandExecutionOptions } from '@layerzerolabs/vm-tooling';\n\nconst execFileAsync = promisify(execFile);\n\n// The self-contained source is mounted here and built in place. The official image's WORKDIR is\n// already /source; we set it explicitly for clarity.\nconst SOURCE_MOUNT = '/source';\n\n// Canonical reproducible platform. External verifiers reproduce the amd64 artifact, so we always\n// run the amd64 image regardless of the host arch (the daemon emulates it when needed).\nconst VERIFIABLE_BUILD_PLATFORM = 'linux/amd64';\n\nconst OFFICIAL_IMAGE_REPO = 'stellar/stellar-cli';\n\n/**\n * The official reproducible image reference for a (Stellar CLI, Rust) version pair, e.g.\n * `stellar/stellar-cli:25.1.0-rust1.90.0-slim-bookworm`. The caller pins both versions; this is the\n * only image the tool builds against.\n */\nexport const officialImageTagRef = (stellarVersion: string, rustVersion: string): string =>\n `${OFFICIAL_IMAGE_REPO}:${stellarVersion}-rust${rustVersion}-slim-bookworm`;\n\n/**\n * Pick the linux/amd64 manifest digest out of `docker manifest inspect` output. Pure/synchronous so\n * the selection (skip the arm64 and the unknown/unknown attestation entries) is unit-testable.\n */\n// The subset of `docker manifest inspect` output (an OCI image index) that we read.\ninterface ManifestDescriptor {\n digest?: string;\n platform?: { os?: string; architecture?: string };\n}\ninterface ManifestIndex {\n manifests?: ManifestDescriptor[];\n}\n\nexport const parseAmd64Digest = (manifestInspectJson: string): string => {\n const { manifests } = JSON.parse(manifestInspectJson) as ManifestIndex;\n\n if (!Array.isArray(manifests)) {\n throw new Error(\n '`docker manifest inspect` did not return a multi-arch index (no `manifests` array)',\n );\n }\n\n const digest = manifests.find(\n ({ platform }) => platform?.os === 'linux' && platform?.architecture === 'amd64',\n )?.digest;\n\n if (typeof digest !== 'string' || !digest.startsWith('sha256:')) {\n throw new Error('No linux/amd64 manifest digest found in `docker manifest inspect` output');\n }\n\n return digest;\n};\n\n/**\n * Resolve the immutable linux/amd64 digest of a `stellar/stellar-cli` tag via a daemon-less\n * registry query (`docker manifest inspect`). This is the reproducible reference an external\n * verifier pins to (SEP-58).\n */\nconst resolveAmd64Digest = async (imageTagRef: string): Promise<string> => {\n try {\n const { stdout } = await execFileAsync('docker', ['manifest', 'inspect', imageTagRef], {\n maxBuffer: 16 * 1024 * 1024,\n });\n return parseAmd64Digest(stdout);\n } catch (cause) {\n throw new Error(\n `Failed to resolve the linux/amd64 digest of ${imageTagRef} (\\`docker manifest inspect\\`)`,\n { cause },\n );\n }\n};\n\n/**\n * Assemble the `docker run` argv for a verifiable build. Kept pure and synchronous so the mount /\n * workdir layout and the tool-injected `--meta bldimg=…` are unit-testable without Docker.\n *\n * The official image's ENTRYPOINT is `stellar`, so the trailing `contract build …` runs under it.\n * The source directory is assumed self-contained, so it is mounted at /source and built in place —\n * no surrounding workspace is required.\n */\nexport const buildVerifiableBuildDockerArgs = ({\n imageRef,\n sourceDir,\n buildArgs,\n bldimg,\n}: {\n imageRef: string;\n sourceDir: string;\n buildArgs: string[];\n bldimg: string;\n}): string[] => [\n 'run',\n '--rm',\n '--platform',\n VERIFIABLE_BUILD_PLATFORM,\n '-v',\n `${sourceDir}:${SOURCE_MOUNT}`,\n '-w',\n SOURCE_MOUNT,\n imageRef,\n 'contract',\n 'build',\n ...buildArgs,\n // Embedded by us (not the user): the exact build image, so the WASM records what produced it.\n '--meta',\n `bldimg=${bldimg}`,\n];\n\nconst runDocker = (dockerArgs: string[]): Promise<void> =>\n new Promise((resolve, reject) => {\n const child = spawn('docker', dockerArgs, { stdio: 'inherit' });\n child.on('error', (error) =>\n reject(new Error('Failed to spawn docker for the verifiable build', { cause: error })),\n );\n child.on('close', (code, signal) => {\n if (code === 0) {\n resolve();\n } else {\n reject(\n new Error(\n `Verifiable build failed: docker exited with ${\n signal ? `signal ${signal}` : `code ${code}`\n }`,\n ),\n );\n }\n });\n });\n\nexport interface VerifiableBuildVersions {\n stellarVersion: string;\n rustVersion: string;\n}\n\n/**\n * Reproducible `stellar contract build` that runs inside the OFFICIAL `stellar/stellar-cli` image —\n * the exact package an external verifier uses — instead of our own dev image (whose sccache/mold\n * layers could change the WASM).\n *\n * The build runs the official image directly from the HOST: our TypeScript CLI already executes on\n * the host runner, so it can `docker run` the official image itself. This is what an external\n * verifier's plain `docker run` does, and it means we never bind-mount the host Docker socket into\n * a container — eliminating the container-escape / secret-leak surface that mounting the socket\n * would create.\n *\n * The image is `stellar/stellar-cli:<stellarVersion>-rust<rustVersion>-slim-bookworm`, pinned by the\n * caller. For a stable reference we resolve it to its linux/amd64 digest and both RUN that digest\n * and embed it as the `bldimg` WASM metadata (`docker.io/stellar/stellar-cli@sha256:…`) — the tool\n * does this automatically so callers never hand-inject `--meta bldimg=…`. The source directory (the\n * cwd, assumed self-contained) is mounted at /source and built in place, and the official image runs\n * as its own user/toolchain.\n */\nexport class VerifiableBuildWrapper {\n public async run(\n args: string[],\n { stellarVersion, rustVersion }: VerifiableBuildVersions,\n options: ToolCommandExecutionOptions,\n ): Promise<void> {\n const tagRef = officialImageTagRef(stellarVersion, rustVersion);\n const digest = await resolveAmd64Digest(tagRef);\n const imageRef = `${OFFICIAL_IMAGE_REPO}@${digest}`;\n const bldimg = `docker.io/${OFFICIAL_IMAGE_REPO}@${digest}`;\n\n const dockerArgs = buildVerifiableBuildDockerArgs({\n imageRef,\n sourceDir: options.cwd,\n buildArgs: args,\n bldimg,\n });\n\n console.info('🔒 Verifiable build (official stellar/stellar-cli image, run from host)');\n console.info(` image: ${imageRef} (${VERIFIABLE_BUILD_PLATFORM}, from tag ${tagRef})`);\n console.info(` bldimg: ${bldimg}`);\n console.info(` docker ${dockerArgs.join(' ')}`);\n\n await runDocker(dockerArgs);\n }\n}\n"]}
|