@calimero-network/mero-js 35.0.0 → 35.2.0
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/README.md +20 -9
- package/dist/client/recovery-key.d.ts +2 -0
- package/dist/client/recovery-key.js +2 -2
- package/dist/generated/api.d.ts +83 -1
- package/dist/generated/methods.d.ts +7 -0
- package/dist/generated/methods.js +7 -0
- package/dist/index.browser.mjs +3 -3
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +311 -2
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +2 -0
- package/dist/index.js +2 -0
- package/dist/index.mjs +311 -2
- package/dist/index.mjs.map +4 -4
- package/dist/package/pack.d.ts +93 -0
- package/dist/package/pack.js +370 -0
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -61,6 +61,11 @@ __export(index_exports, {
|
|
|
61
61
|
IdempotencyMismatch: () => IdempotencyMismatch,
|
|
62
62
|
KMS_RELEASE_SIGNER: () => KMS_RELEASE_SIGNER,
|
|
63
63
|
LoginRequired: () => LoginRequired,
|
|
64
|
+
MAX_ARCHIVE_BYTES: () => MAX_ARCHIVE_BYTES,
|
|
65
|
+
MAX_MANIFEST_BYTES: () => MAX_MANIFEST_BYTES,
|
|
66
|
+
MAX_MPK_BYTES: () => MAX_MPK_BYTES,
|
|
67
|
+
MAX_PIPELINES_PER_PACKAGE: () => MAX_PIPELINES_PER_PACKAGE,
|
|
68
|
+
MAX_PIPELINE_BYTES: () => MAX_PIPELINE_BYTES,
|
|
64
69
|
MAX_RECOVERY_NONCE_BYTES: () => MAX_RECOVERY_NONCE_BYTES,
|
|
65
70
|
MAX_REPORT_PAGE: () => MAX_REPORT_PAGE,
|
|
66
71
|
MOCK_QUOTE_HEADER: () => MOCK_QUOTE_HEADER,
|
|
@@ -97,6 +102,7 @@ __export(index_exports, {
|
|
|
97
102
|
b64url: () => b64url,
|
|
98
103
|
backupPublicKey: () => backupPublicKey,
|
|
99
104
|
browserPasskey: () => browserPasskey,
|
|
105
|
+
canonicalizeManifest: () => canonicalizeManifest,
|
|
100
106
|
checkOwner: () => checkOwner,
|
|
101
107
|
claimedRelease: () => claimedRelease,
|
|
102
108
|
cloudNodeReleaseUrl: () => cloudNodeReleaseUrl,
|
|
@@ -114,6 +120,7 @@ __export(index_exports, {
|
|
|
114
120
|
deployerKey: () => deployerKey,
|
|
115
121
|
directoryTransport: () => directoryTransport,
|
|
116
122
|
errorFrom: () => errorFrom,
|
|
123
|
+
exportPublisherKey: () => exportPublisherKey,
|
|
117
124
|
fetchAttestedKey: () => fetchAttestedKey,
|
|
118
125
|
fetchGithubNodeRelease: () => fetchGithubNodeRelease,
|
|
119
126
|
fetchNodeRelease: () => fetchNodeRelease,
|
|
@@ -121,8 +128,11 @@ __export(index_exports, {
|
|
|
121
128
|
fromB64url: () => fromB64url,
|
|
122
129
|
frontendManifest: () => frontendManifest,
|
|
123
130
|
generateOwnerKey: () => generateOwnerKey,
|
|
131
|
+
generatePublisherKey: () => generatePublisherKey,
|
|
124
132
|
holderKey: () => holderKey,
|
|
125
133
|
holderRecoveryBody: () => holderRecoveryBody,
|
|
134
|
+
importPublisherKey: () => importPublisherKey,
|
|
135
|
+
isDevPublisherKey: () => isDevPublisherKey,
|
|
126
136
|
leaveOrgConsent: () => leaveOrgConsent,
|
|
127
137
|
newBackupKeyPair: () => newBackupKeyPair,
|
|
128
138
|
newIdempotencyKey: () => newIdempotencyKey,
|
|
@@ -130,6 +140,7 @@ __export(index_exports, {
|
|
|
130
140
|
openDataKey: () => openDataKey,
|
|
131
141
|
orgCapabilities: () => orgCapabilities,
|
|
132
142
|
ownerPublicKey: () => ownerPublicKey,
|
|
143
|
+
packComputePackage: () => packComputePackage,
|
|
133
144
|
pageDeployment: () => pageDeployment,
|
|
134
145
|
pageQuery: () => pageQuery,
|
|
135
146
|
parseRecoverySeed: () => parseRecoverySeed,
|
|
@@ -161,6 +172,8 @@ __export(index_exports, {
|
|
|
161
172
|
setMemberRoleConsent: () => setMemberRoleConsent,
|
|
162
173
|
setMemberTeamsConsent: () => setMemberTeamsConsent,
|
|
163
174
|
signRecovery: () => signRecovery,
|
|
175
|
+
signerIdOf: () => signerIdOf,
|
|
176
|
+
signingPayload: () => signingPayload,
|
|
164
177
|
sseFrames: () => sseFrames,
|
|
165
178
|
stalledBy: () => stalledBy,
|
|
166
179
|
transportKeyBinding: () => transportKeyBinding,
|
|
@@ -173,6 +186,7 @@ __export(index_exports, {
|
|
|
173
186
|
verifyReleaseUrl: () => verifyReleaseUrl,
|
|
174
187
|
verifySignedAgentPolicy: () => verifySignedAgentPolicy,
|
|
175
188
|
verifySignedNodeRelease: () => verifySignedNodeRelease,
|
|
189
|
+
webCryptoPublisherKey: () => webCryptoPublisherKey,
|
|
176
190
|
withdrawConsent: () => withdrawConsent,
|
|
177
191
|
withoutConsentReturn: () => withoutConsentReturn
|
|
178
192
|
});
|
|
@@ -3175,6 +3189,13 @@ function createRoutes(api) {
|
|
|
3175
3189
|
* A `421 WRONG_NODE` moves the client to the next node of the cluster.
|
|
3176
3190
|
*/
|
|
3177
3191
|
run: (args, options) => route(api, { "method": "GET", "path": "/apps/{app}/runs/{run}", "pathParams": ["app", "run"], "query": [], "body": "none", "optionalBody": false, "reply": "json" }, args, options),
|
|
3192
|
+
/**
|
|
3193
|
+
* A compute run's attempt logs.
|
|
3194
|
+
*
|
|
3195
|
+
* `GET /apps/{app}/runs/{run}/logs` (`app_run_logs`). **Who:** signed in (a session or an API key).
|
|
3196
|
+
* A `421 WRONG_NODE` moves the client to the next node of the cluster.
|
|
3197
|
+
*/
|
|
3198
|
+
runLogs: (args, options) => route(api, { "method": "GET", "path": "/apps/{app}/runs/{run}/logs", "pathParams": ["app", "run"], "query": [], "body": "none", "optionalBody": false, "reply": "json" }, args, options),
|
|
3178
3199
|
/**
|
|
3179
3200
|
* An app's compute runs.
|
|
3180
3201
|
*
|
|
@@ -5032,9 +5053,9 @@ function newRecoverySeed() {
|
|
|
5032
5053
|
}
|
|
5033
5054
|
function recoverySeedText(seed) {
|
|
5034
5055
|
checkSeed(seed);
|
|
5035
|
-
const
|
|
5056
|
+
const hex3 = Array.from(seed, (b) => b.toString(16).padStart(2, "0")).join("");
|
|
5036
5057
|
const groups = [];
|
|
5037
|
-
for (let i = 0; i <
|
|
5058
|
+
for (let i = 0; i < hex3.length; i += 8) groups.push(hex3.slice(i, i + 8));
|
|
5038
5059
|
return groups.join("-");
|
|
5039
5060
|
}
|
|
5040
5061
|
function parseRecoverySeed(text) {
|
|
@@ -6442,4 +6463,292 @@ async function verifyRecoveryAttestation(header, verifyQuote) {
|
|
|
6442
6463
|
const ok = await verifyQuote({ quoteB64: doc.quote, nonce: nonce2, reportDataSuffix });
|
|
6443
6464
|
if (!ok) throw new Error("the quote was not accepted");
|
|
6444
6465
|
}
|
|
6466
|
+
|
|
6467
|
+
// src/package/pack.ts
|
|
6468
|
+
var MAX_MANIFEST_BYTES = 1024 * 1024;
|
|
6469
|
+
var MAX_PIPELINES_PER_PACKAGE = 16;
|
|
6470
|
+
var MAX_PIPELINE_BYTES = 64 * 1024;
|
|
6471
|
+
var MAX_ARCHIVE_BYTES = 512 * 1024 * 1024;
|
|
6472
|
+
var MAX_MPK_BYTES = (64 * 1024 * 1024 - 1024 * 1024) / 4 * 3;
|
|
6473
|
+
var DEV_SIGNER_ID = "did:key:z6MknF3p5L5FDHJQ7FREUapuX4Wmp4MtF6WrHYaXS2B3eZQd";
|
|
6474
|
+
var MANIFEST_SIGNING_DOMAIN = new TextEncoder().encode("calimero.bundle.manifest.v1\0");
|
|
6475
|
+
var MIN_RUNTIME_VERSION = "0.1.0";
|
|
6476
|
+
var ED25519_PUB_MULTICODEC = [237, 1];
|
|
6477
|
+
var BASE58 = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz";
|
|
6478
|
+
var COMPONENT_HEADER = [0, 97, 115, 109, 13, 0, 1, 0];
|
|
6479
|
+
var PIPELINE_PATH = /^pipelines\/[A-Za-z0-9._-]+\.yaml$/;
|
|
6480
|
+
var SEED_B64URL = /^[A-Za-z0-9_-]{43}$/;
|
|
6481
|
+
var SEMVER = /^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$/;
|
|
6482
|
+
var utf86 = (s) => new TextEncoder().encode(s);
|
|
6483
|
+
var hex2 = (b) => Array.from(b, (x) => x.toString(16).padStart(2, "0")).join("");
|
|
6484
|
+
var concat2 = (...parts) => {
|
|
6485
|
+
const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
|
|
6486
|
+
let off = 0;
|
|
6487
|
+
for (const p of parts) out.set(p, off), off += p.length;
|
|
6488
|
+
return out;
|
|
6489
|
+
};
|
|
6490
|
+
async function requireEd25519() {
|
|
6491
|
+
const unsupported = new Error("this runtime cannot sign Ed25519 packages (WebCrypto Ed25519 is missing)");
|
|
6492
|
+
if (!globalThis.crypto?.subtle) throw unsupported;
|
|
6493
|
+
try {
|
|
6494
|
+
await privateKey(new Uint8Array(32), false);
|
|
6495
|
+
} catch {
|
|
6496
|
+
throw unsupported;
|
|
6497
|
+
}
|
|
6498
|
+
}
|
|
6499
|
+
async function keyOfSeed(seed) {
|
|
6500
|
+
await requireEd25519();
|
|
6501
|
+
if (seed.length !== 32) throw new Error("a publisher seed is 32 bytes");
|
|
6502
|
+
const publicKey = fromB64url(await recoveryPublicKey(seed));
|
|
6503
|
+
return { seed: Uint8Array.from(seed), publicKey };
|
|
6504
|
+
}
|
|
6505
|
+
async function generatePublisherKey() {
|
|
6506
|
+
await requireEd25519();
|
|
6507
|
+
return keyOfSeed(crypto.getRandomValues(new Uint8Array(32)));
|
|
6508
|
+
}
|
|
6509
|
+
async function webCryptoPublisherKey(key) {
|
|
6510
|
+
await requireEd25519();
|
|
6511
|
+
return { privateKey: await privateKey(Uint8Array.from(key.seed), false), publicKey: Uint8Array.from(key.publicKey) };
|
|
6512
|
+
}
|
|
6513
|
+
function base58(bytes) {
|
|
6514
|
+
let n = 0n;
|
|
6515
|
+
for (const b of bytes) n = n << 8n | BigInt(b);
|
|
6516
|
+
let out = "";
|
|
6517
|
+
for (; n > 0n; n /= 58n) out = BASE58[Number(n % 58n)] + out;
|
|
6518
|
+
return "1".repeat(bytes.findIndex((b) => b !== 0) === -1 ? bytes.length : bytes.findIndex((b) => b !== 0)) + out;
|
|
6519
|
+
}
|
|
6520
|
+
function signerIdOf(key) {
|
|
6521
|
+
return `did:key:z${base58(concat2(Uint8Array.from(ED25519_PUB_MULTICODEC), key.publicKey))}`;
|
|
6522
|
+
}
|
|
6523
|
+
function isDevPublisherKey(key) {
|
|
6524
|
+
return signerIdOf(key) === DEV_SIGNER_ID;
|
|
6525
|
+
}
|
|
6526
|
+
function exportPublisherKey(key) {
|
|
6527
|
+
return utf86(
|
|
6528
|
+
JSON.stringify({ private_key: b64url(key.seed), public_key: b64url(key.publicKey), signer_id: signerIdOf(key) }, null, 2)
|
|
6529
|
+
);
|
|
6530
|
+
}
|
|
6531
|
+
async function importPublisherKey(bytes) {
|
|
6532
|
+
let file;
|
|
6533
|
+
try {
|
|
6534
|
+
file = JSON.parse(new TextDecoder("utf-8", { fatal: true }).decode(bytes));
|
|
6535
|
+
} catch {
|
|
6536
|
+
throw new Error("a publisher key backup is a JSON document");
|
|
6537
|
+
}
|
|
6538
|
+
const seed = file?.private_key;
|
|
6539
|
+
if (typeof seed !== "string" || !SEED_B64URL.test(seed) || b64url(fromB64url(seed)) !== seed) {
|
|
6540
|
+
throw new Error("the backup private_key is not an unpadded base64url 32-byte seed");
|
|
6541
|
+
}
|
|
6542
|
+
const key = await keyOfSeed(fromB64url(seed));
|
|
6543
|
+
if (file.public_key !== void 0 && file.public_key !== b64url(key.publicKey)) {
|
|
6544
|
+
throw new Error("the backup public_key is not the seed's");
|
|
6545
|
+
}
|
|
6546
|
+
if (file.signer_id !== void 0 && file.signer_id !== signerIdOf(key)) {
|
|
6547
|
+
throw new Error("the backup signer_id is not the seed's");
|
|
6548
|
+
}
|
|
6549
|
+
return key;
|
|
6550
|
+
}
|
|
6551
|
+
function canonicalizeManifest(manifest) {
|
|
6552
|
+
const signed = Object.fromEntries(Object.entries(manifest).filter(([k]) => k !== "signature" && !k.startsWith("_")));
|
|
6553
|
+
return utf86(jcs(signed));
|
|
6554
|
+
}
|
|
6555
|
+
function jcs(value) {
|
|
6556
|
+
if (typeof value === "string") {
|
|
6557
|
+
if (/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/.test(value)) {
|
|
6558
|
+
throw new Error("a lone surrogate cannot be canonicalized");
|
|
6559
|
+
}
|
|
6560
|
+
return JSON.stringify(value);
|
|
6561
|
+
}
|
|
6562
|
+
if (typeof value === "number") {
|
|
6563
|
+
if (!Number.isSafeInteger(value)) throw new Error("only safe integers can be canonicalized");
|
|
6564
|
+
return String(value);
|
|
6565
|
+
}
|
|
6566
|
+
if (value === null || typeof value === "boolean") return String(value);
|
|
6567
|
+
if (Array.isArray(value)) return `[${value.map(jcs).join(",")}]`;
|
|
6568
|
+
return `{${Object.keys(value).sort().map((k) => `${jcs(k)}:${jcs(value[k])}`).join(",")}}`;
|
|
6569
|
+
}
|
|
6570
|
+
async function signingPayload(manifest) {
|
|
6571
|
+
return sha2562(concat2(MANIFEST_SIGNING_DOMAIN, canonicalizeManifest(manifest)));
|
|
6572
|
+
}
|
|
6573
|
+
async function verifyManifestSignature(manifest) {
|
|
6574
|
+
await requireEd25519();
|
|
6575
|
+
const sig = manifest.signature;
|
|
6576
|
+
if (!sig) throw new Error("manifest is missing required 'signature' field");
|
|
6577
|
+
if (sig.algorithm !== "ed25519") throw new Error(`unsupported signature algorithm: '${sig.algorithm}'`);
|
|
6578
|
+
const publicKey = fromB64url(sig.publicKey ?? "");
|
|
6579
|
+
const signature = fromB64url(sig.signature ?? "");
|
|
6580
|
+
if (publicKey.length !== 32 || signature.length !== 64) throw new Error("malformed signature field");
|
|
6581
|
+
const key = await crypto.subtle.importKey("raw", buf2(publicKey), { name: "Ed25519" }, false, ["verify"]);
|
|
6582
|
+
const ok = await crypto.subtle.verify("Ed25519", key, buf2(signature), buf2(await signingPayload(manifest)));
|
|
6583
|
+
if (!ok) throw new Error("Ed25519 signature verification failed");
|
|
6584
|
+
const derived = signerIdOf({ publicKey });
|
|
6585
|
+
if (manifest.signerId !== derived) {
|
|
6586
|
+
throw new Error(`signerId mismatch: manifest declares '${manifest.signerId}' but signature public key derives to '${derived}'`);
|
|
6587
|
+
}
|
|
6588
|
+
return derived;
|
|
6589
|
+
}
|
|
6590
|
+
function checkPathComponent(value, field) {
|
|
6591
|
+
if (!value) throw new Error(`${field} is empty`);
|
|
6592
|
+
if (value.includes("..")) throw new Error(`${field} contains path traversal sequence '..'`);
|
|
6593
|
+
if (value.includes("/") || value.includes("\\")) throw new Error(`${field} contains directory separator`);
|
|
6594
|
+
if (value.includes("\0")) throw new Error(`${field} contains null byte`);
|
|
6595
|
+
if (value.length >= 2 && value[1] === ":") throw new Error(`${field} appears to be an absolute path`);
|
|
6596
|
+
}
|
|
6597
|
+
function checkPipelinePath(value, field) {
|
|
6598
|
+
if (!value) throw new Error(`${field} is empty`);
|
|
6599
|
+
if (value.includes("\0")) throw new Error(`${field} contains null byte`);
|
|
6600
|
+
if (value.includes("\\")) throw new Error(`${field} contains backslash (use forward slashes)`);
|
|
6601
|
+
if (value.startsWith("/")) throw new Error(`${field} is an absolute path`);
|
|
6602
|
+
if (value[1] === ":") throw new Error(`${field} appears to be an absolute Windows path`);
|
|
6603
|
+
if (value.split("/").includes("..")) throw new Error(`${field} contains path traversal component '..'`);
|
|
6604
|
+
if (!PIPELINE_PATH.test(value) || utf86(value).length > 100) {
|
|
6605
|
+
throw new Error(`${field} must be pipelines/<name>.yaml (A-Z a-z 0-9 . _ -), at most 100 bytes`);
|
|
6606
|
+
}
|
|
6607
|
+
}
|
|
6608
|
+
var METADATA_STRINGS = ["name", "description", "author", "icon", "license", "category", "guide"];
|
|
6609
|
+
function normalizeMetadata(m) {
|
|
6610
|
+
const bad = (what) => new Error(`metadata ${what}`);
|
|
6611
|
+
if (typeof m !== "object" || m === null || Array.isArray(m)) throw bad("must be an object");
|
|
6612
|
+
const known = /* @__PURE__ */ new Set([...METADATA_STRINGS, "tags"]);
|
|
6613
|
+
const unknown = Object.keys(m).find((k) => !known.has(k));
|
|
6614
|
+
if (unknown !== void 0) throw bad(`has an unknown field '${unknown}'`);
|
|
6615
|
+
const out = {};
|
|
6616
|
+
for (const k of METADATA_STRINGS) {
|
|
6617
|
+
const v = m[k];
|
|
6618
|
+
if (v === void 0) continue;
|
|
6619
|
+
if (typeof v !== "string") throw bad(`${k} must be a string`);
|
|
6620
|
+
out[k] = v;
|
|
6621
|
+
}
|
|
6622
|
+
if (typeof out.name !== "string") throw bad("name is required");
|
|
6623
|
+
if (m.tags !== void 0) {
|
|
6624
|
+
if (!Array.isArray(m.tags) || m.tags.some((t) => typeof t !== "string")) throw bad("tags must be an array of strings");
|
|
6625
|
+
out.tags = [...m.tags];
|
|
6626
|
+
}
|
|
6627
|
+
return out;
|
|
6628
|
+
}
|
|
6629
|
+
var artifact = (path, bytes) => ({ path, hash: hex2(sha2562(bytes)), size: bytes.length });
|
|
6630
|
+
var padded = (n) => 512 + Math.ceil(n / 512) * 512;
|
|
6631
|
+
function tarEntry(name, data) {
|
|
6632
|
+
const header = new Uint8Array(512);
|
|
6633
|
+
const put = (off, text) => header.set(utf86(text), off);
|
|
6634
|
+
put(0, name);
|
|
6635
|
+
put(100, "0000644\0");
|
|
6636
|
+
put(108, "0000000\0");
|
|
6637
|
+
put(116, "0000000\0");
|
|
6638
|
+
put(124, `${data.length.toString(8).padStart(11, "0")}\0`);
|
|
6639
|
+
put(136, "00000000000\0");
|
|
6640
|
+
put(148, " ");
|
|
6641
|
+
put(156, "0");
|
|
6642
|
+
put(257, "ustar\0");
|
|
6643
|
+
put(263, "00");
|
|
6644
|
+
put(148, `${header.reduce((n, b) => n + b, 0).toString(8).padStart(6, "0")}\0 `);
|
|
6645
|
+
return concat2(header, data, new Uint8Array((512 - data.length % 512) % 512));
|
|
6646
|
+
}
|
|
6647
|
+
function readTar(tar) {
|
|
6648
|
+
const out = /* @__PURE__ */ new Map();
|
|
6649
|
+
const text = (a, b) => new TextDecoder().decode(tar.subarray(a, b)).replace(/\0.*$/s, "");
|
|
6650
|
+
for (let off = 0; off + 512 <= tar.length && tar[off] !== 0; ) {
|
|
6651
|
+
const name = text(off, off + 100);
|
|
6652
|
+
const size = parseInt(text(off + 124, off + 136).trim(), 8);
|
|
6653
|
+
if (out.has(name)) throw new Error(`the archive has more than one entry at '${name}'`);
|
|
6654
|
+
out.set(name, tar.subarray(off + 512, off + 512 + size));
|
|
6655
|
+
off += padded(size);
|
|
6656
|
+
}
|
|
6657
|
+
return out;
|
|
6658
|
+
}
|
|
6659
|
+
async function checkPackage(tar, publicKey) {
|
|
6660
|
+
const entries = readTar(tar);
|
|
6661
|
+
const raw = entries.get("manifest.json");
|
|
6662
|
+
if (!raw) throw new Error("manifest.json not found in bundle");
|
|
6663
|
+
const manifest = JSON.parse(new TextDecoder().decode(raw));
|
|
6664
|
+
await verifyManifestSignature(manifest);
|
|
6665
|
+
if (manifest.signature.publicKey !== b64url(publicKey)) throw new Error("the manifest is not signed by the publisher key");
|
|
6666
|
+
const declared = [manifest.compute, ...manifest.pipelines ?? []];
|
|
6667
|
+
const names = ["manifest.json", ...declared.map((a) => a.path)];
|
|
6668
|
+
if (names.length !== entries.size || names.some((n) => !entries.has(n))) {
|
|
6669
|
+
throw new Error("the archive does not hold exactly the files its manifest declares");
|
|
6670
|
+
}
|
|
6671
|
+
for (const a of declared) {
|
|
6672
|
+
const bytes = entries.get(a.path);
|
|
6673
|
+
if (!bytes || bytes.length !== a.size || hex2(sha2562(bytes)) !== a.hash) {
|
|
6674
|
+
throw new Error(`bundle artifact '${a.path}' failed its integrity check`);
|
|
6675
|
+
}
|
|
6676
|
+
}
|
|
6677
|
+
}
|
|
6678
|
+
async function gzip(bytes) {
|
|
6679
|
+
if (typeof CompressionStream === "undefined") throw new Error("this runtime cannot gzip packages (no CompressionStream)");
|
|
6680
|
+
const stream = new Blob([buf2(bytes)]).stream().pipeThrough(new CompressionStream("gzip"));
|
|
6681
|
+
return new Uint8Array(await new Response(stream).arrayBuffer());
|
|
6682
|
+
}
|
|
6683
|
+
async function signerOf(key, seed, publicKey) {
|
|
6684
|
+
if (seed) {
|
|
6685
|
+
const derived = fromB64url(await recoveryPublicKey(seed));
|
|
6686
|
+
if (hex2(derived) !== hex2(publicKey)) throw new Error("the publisher key's publicKey is not its seed's");
|
|
6687
|
+
return { signing: await privateKey(seed, false), publicKey: derived };
|
|
6688
|
+
}
|
|
6689
|
+
const k = key.privateKey;
|
|
6690
|
+
if (k?.algorithm?.name !== "Ed25519" || k.type !== "private" || !k.usages.includes("sign")) {
|
|
6691
|
+
throw new Error("the publisher key is not an Ed25519 signing key");
|
|
6692
|
+
}
|
|
6693
|
+
return { signing: k, publicKey };
|
|
6694
|
+
}
|
|
6695
|
+
async function packComputePackage(input, key) {
|
|
6696
|
+
const seed = "seed" in key && key.seed ? Uint8Array.from(key.seed) : void 0;
|
|
6697
|
+
const publicKey = Uint8Array.from(key.publicKey);
|
|
6698
|
+
const job = prepare(input);
|
|
6699
|
+
await requireEd25519();
|
|
6700
|
+
const { signing, publicKey: pub } = await signerOf(key, seed, publicKey);
|
|
6701
|
+
const manifest = { ...job.manifest, signerId: signerIdOf({ publicKey: pub }) };
|
|
6702
|
+
const signature = await crypto.subtle.sign("Ed25519", signing, buf2(await signingPayload(manifest)));
|
|
6703
|
+
manifest.signature = { algorithm: "ed25519", publicKey: b64url(pub), signature: b64url(new Uint8Array(signature)) };
|
|
6704
|
+
const manifestBytes = utf86(jcs(manifest));
|
|
6705
|
+
if (manifestBytes.length > MAX_MANIFEST_BYTES) {
|
|
6706
|
+
throw new Error(`bundle manifest.json exceeds the ${MAX_MANIFEST_BYTES} byte cap`);
|
|
6707
|
+
}
|
|
6708
|
+
const files = [["manifest.json", manifestBytes], ["compute.wasm", job.compute], ...job.files];
|
|
6709
|
+
checkArchiveSize(files.map(([, b]) => b.length));
|
|
6710
|
+
const tar = concat2(...files.map(([n, b]) => tarEntry(n, b)), new Uint8Array(1024));
|
|
6711
|
+
await checkPackage(tar, pub);
|
|
6712
|
+
const mpk = await gzip(tar);
|
|
6713
|
+
if (mpk.length > MAX_MPK_BYTES) throw new Error(`a package is limited to ${MAX_MPK_BYTES >> 20} MiB`);
|
|
6714
|
+
return mpk;
|
|
6715
|
+
}
|
|
6716
|
+
function checkArchiveSize(sizes) {
|
|
6717
|
+
if (sizes.reduce((n, s) => n + padded(s), 1024) > MAX_ARCHIVE_BYTES) {
|
|
6718
|
+
throw new Error(`bundle archive exceeds the ${MAX_ARCHIVE_BYTES} byte decompressed cap`);
|
|
6719
|
+
}
|
|
6720
|
+
}
|
|
6721
|
+
function prepare(input) {
|
|
6722
|
+
checkPathComponent(input.package, "package");
|
|
6723
|
+
checkPathComponent(input.version, "appVersion");
|
|
6724
|
+
if (!SEMVER.test(input.version)) throw new Error(`appVersion '${input.version}' is not a semantic version`);
|
|
6725
|
+
if (!input.compute?.length) throw new Error("the package ships no WASM");
|
|
6726
|
+
if (input.pipelines.length > MAX_PIPELINES_PER_PACKAGE) {
|
|
6727
|
+
throw new Error(`bundle declares ${input.pipelines.length} pipelines, at most ${MAX_PIPELINES_PER_PACKAGE} are allowed`);
|
|
6728
|
+
}
|
|
6729
|
+
checkArchiveSize([input.compute.length]);
|
|
6730
|
+
const compute = Uint8Array.from(input.compute);
|
|
6731
|
+
if (COMPONENT_HEADER.some((b, i) => compute[i] !== b)) {
|
|
6732
|
+
throw new Error("compute: not a WASM component (an SDK 0.12 core module is refused by the node)");
|
|
6733
|
+
}
|
|
6734
|
+
const files = input.pipelines.map((p, i) => {
|
|
6735
|
+
checkPipelinePath(p.path, `pipelines[${i}].path`);
|
|
6736
|
+
return [p.path, utf86(p.source)];
|
|
6737
|
+
});
|
|
6738
|
+
const big = files.find(([, b]) => b.length > MAX_PIPELINE_BYTES);
|
|
6739
|
+
if (big) throw new Error(`pipeline '${big[0]}' exceeds the ${MAX_PIPELINE_BYTES} byte cap`);
|
|
6740
|
+
const lower = files.map(([n]) => n.toLowerCase());
|
|
6741
|
+
if (new Set(lower).size !== files.length) throw new Error("two pipelines have the same path");
|
|
6742
|
+
const metadata = input.metadata === void 0 ? void 0 : normalizeMetadata(input.metadata);
|
|
6743
|
+
const manifest = {
|
|
6744
|
+
version: "1.0",
|
|
6745
|
+
package: input.package,
|
|
6746
|
+
appVersion: input.version,
|
|
6747
|
+
minRuntimeVersion: MIN_RUNTIME_VERSION,
|
|
6748
|
+
...metadata ? { metadata } : {},
|
|
6749
|
+
compute: artifact("compute.wasm", compute),
|
|
6750
|
+
...files.length ? { pipelines: files.map(([n, b]) => artifact(n, b)) } : {}
|
|
6751
|
+
};
|
|
6752
|
+
return { manifest, compute, files };
|
|
6753
|
+
}
|
|
6445
6754
|
//# sourceMappingURL=index.cjs.map
|