@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.
@@ -0,0 +1,93 @@
1
+ /**
2
+ * Building and signing a compute-only pipeline package (`.mpk`), byte-compatible
3
+ * with core's `calimero-bundle`: the manifest, its RFC 8785 canonical form, the
4
+ * domain-tagged signing payload and the archive layout are the ones core's
5
+ * `scripts/pack-component.py` and `mero-sign` produce and its node verifies.
6
+ *
7
+ * A publisher key is an Ed25519 seed. Its backup ({@link exportPublisherKey})
8
+ * is the JSON `mero-sign` reads as a key file: `{ private_key, public_key,
9
+ * signer_id }`, the seed and public key base64url, the signer id a `did:key`.
10
+ */
11
+ export declare const MAX_MANIFEST_BYTES: number;
12
+ export declare const MAX_PIPELINES_PER_PACKAGE = 16;
13
+ export declare const MAX_PIPELINE_BYTES: number;
14
+ export declare const MAX_ARCHIVE_BYTES: number;
15
+ export declare const MAX_MPK_BYTES: number;
16
+ export interface PublisherKey {
17
+ /** The 32-byte Ed25519 seed. Keep it secret. */
18
+ readonly seed: Uint8Array;
19
+ /** The 32-byte Ed25519 public key. */
20
+ readonly publicKey: Uint8Array;
21
+ }
22
+ /** A non-extractable signing key (for a console that keeps it in IndexedDB) and its public key. */
23
+ export interface WebCryptoPublisherKey {
24
+ readonly privateKey: CryptoKey;
25
+ readonly publicKey: Uint8Array;
26
+ }
27
+ export type PackKey = PublisherKey | WebCryptoPublisherKey;
28
+ export interface PackageMetadata {
29
+ name: string;
30
+ description?: string;
31
+ author?: string;
32
+ icon?: string;
33
+ tags?: string[];
34
+ license?: string;
35
+ category?: string;
36
+ guide?: string;
37
+ }
38
+ export interface ComputePackageInput {
39
+ /** The package id, e.g. `com.example.pipeline`. */
40
+ package: string;
41
+ /** The release's version, a semver such as `1.0.0`. */
42
+ version: string;
43
+ /** The compute component (a `calimero:app` WASM component). */
44
+ compute: Uint8Array;
45
+ /** Pipeline YAML files, each at `pipelines/<name>.yaml`. */
46
+ pipelines: {
47
+ path: string;
48
+ source: string;
49
+ }[];
50
+ metadata?: PackageMetadata;
51
+ }
52
+ type Json = null | boolean | number | string | Json[] | {
53
+ [key: string]: Json;
54
+ };
55
+ export declare function generatePublisherKey(): Promise<PublisherKey>;
56
+ /** The same key as a non-extractable WebCrypto key, after which the seed can be dropped. */
57
+ export declare function webCryptoPublisherKey(key: PublisherKey): Promise<WebCryptoPublisherKey>;
58
+ /** The `did:key` of the key, as core's `derive_signer_id_did_key` derives it. */
59
+ export declare function signerIdOf(key: Pick<PublisherKey, 'publicKey'>): string;
60
+ /** Whether this is `mero-sign --dev`'s public key: a registry and a production node refuse what it signs. */
61
+ export declare function isDevPublisherKey(key: Pick<PublisherKey, 'publicKey'>): boolean;
62
+ /** The key's backup: UTF-8 JSON in `mero-sign`'s key-file shape. */
63
+ export declare function exportPublisherKey(key: PublisherKey): Uint8Array;
64
+ /** Restores a key from its backup; the public key and signer id, when present, must be the seed's. Other fields are ignored, as `mero-sign` does. */
65
+ export declare function importPublisherKey(bytes: Uint8Array): Promise<PublisherKey>;
66
+ /** RFC 8785 canonical bytes of the manifest without `signature` and `_`-prefixed fields, as core's `canonicalize_manifest`. */
67
+ export declare function canonicalizeManifest(manifest: {
68
+ [key: string]: Json;
69
+ }): Uint8Array;
70
+ /** What Ed25519 signs: `sha256(domain || canonical bytes)`, as core's `compute_signing_payload`. */
71
+ export declare function signingPayload(manifest: {
72
+ [key: string]: Json;
73
+ }): Promise<Uint8Array>;
74
+ /**
75
+ * Checks a manifest's signature and that its `signerId` is the signing key's; returns the signer id.
76
+ * Not core's `verify_strict`, and it does not look at artifact digests: use {@link checkPackage} for those.
77
+ */
78
+ export declare function verifyManifestSignature(manifest: {
79
+ [key: string]: Json;
80
+ }): Promise<string>;
81
+ /**
82
+ * Checks an uncompressed archive as the node will: one manifest, its signature by `publicKey`,
83
+ * exactly the files it declares, each with the declared size and SHA-256.
84
+ */
85
+ export declare function checkPackage(tar: Uint8Array, publicKey: Uint8Array): Promise<void>;
86
+ /**
87
+ * A signed compute-only `.mpk`: `manifest.json`, `compute.wasm` and the pipelines, as a tar.gz.
88
+ * Refuses what core's node refuses at install, with core's messages, and checks its own output
89
+ * before returning. It cannot check what the node compiles: that the component declares
90
+ * compute methods and that the pipelines fit them.
91
+ */
92
+ export declare function packComputePackage(input: ComputePackageInput, key: PackKey): Promise<Uint8Array>;
93
+ export {};
@@ -0,0 +1,370 @@
1
+ /**
2
+ * Building and signing a compute-only pipeline package (`.mpk`), byte-compatible
3
+ * with core's `calimero-bundle`: the manifest, its RFC 8785 canonical form, the
4
+ * domain-tagged signing payload and the archive layout are the ones core's
5
+ * `scripts/pack-component.py` and `mero-sign` produce and its node verifies.
6
+ *
7
+ * A publisher key is an Ed25519 seed. Its backup ({@link exportPublisherKey})
8
+ * is the JSON `mero-sign` reads as a key file: `{ private_key, public_key,
9
+ * signer_id }`, the seed and public key base64url, the signer id a `did:key`.
10
+ */
11
+ import { sha256 } from '@noble/hashes/sha2.js';
12
+ import { privateKey, buf, recoveryPublicKey } from '../client/recovery-key.js';
13
+ import { b64url, fromB64url } from '../runtime/passkey.js';
14
+ export const MAX_MANIFEST_BYTES = 1024 * 1024;
15
+ export const MAX_PIPELINES_PER_PACKAGE = 16;
16
+ export const MAX_PIPELINE_BYTES = 64 * 1024;
17
+ export const MAX_ARCHIVE_BYTES = 512 * 1024 * 1024; // decompressed
18
+ export const MAX_MPK_BYTES = ((64 * 1024 * 1024 - 1024 * 1024) / 4) * 3; // what a node takes, compressed
19
+ const DEV_SIGNER_ID = 'did:key:z6MknF3p5L5FDHJQ7FREUapuX4Wmp4MtF6WrHYaXS2B3eZQd'; // mero-sign --dev's public key
20
+ const MANIFEST_SIGNING_DOMAIN = new TextEncoder().encode('calimero.bundle.manifest.v1\0');
21
+ const MIN_RUNTIME_VERSION = '0.1.0';
22
+ const ED25519_PUB_MULTICODEC = [0xed, 0x01];
23
+ const BASE58 = '123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz';
24
+ const COMPONENT_HEADER = [0, 0x61, 0x73, 0x6d, 0x0d, 0, 0x01, 0]; // "\0asm" + component version 13, layer 1
25
+ const PIPELINE_PATH = /^pipelines\/[A-Za-z0-9._-]+\.yaml$/;
26
+ const SEED_B64URL = /^[A-Za-z0-9_-]{43}$/;
27
+ const 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-]+)*))?$/;
28
+ const utf8 = (s) => new TextEncoder().encode(s);
29
+ const hex = (b) => Array.from(b, (x) => x.toString(16).padStart(2, '0')).join('');
30
+ const concat = (...parts) => {
31
+ const out = new Uint8Array(parts.reduce((n, p) => n + p.length, 0));
32
+ let off = 0;
33
+ for (const p of parts)
34
+ (out.set(p, off), (off += p.length));
35
+ return out;
36
+ };
37
+ async function requireEd25519() {
38
+ const unsupported = new Error('this runtime cannot sign Ed25519 packages (WebCrypto Ed25519 is missing)');
39
+ if (!globalThis.crypto?.subtle)
40
+ throw unsupported;
41
+ try {
42
+ await privateKey(new Uint8Array(32), false);
43
+ }
44
+ catch {
45
+ throw unsupported;
46
+ }
47
+ }
48
+ async function keyOfSeed(seed) {
49
+ await requireEd25519();
50
+ if (seed.length !== 32)
51
+ throw new Error('a publisher seed is 32 bytes');
52
+ const publicKey = fromB64url(await recoveryPublicKey(seed));
53
+ return { seed: Uint8Array.from(seed), publicKey };
54
+ }
55
+ export async function generatePublisherKey() {
56
+ await requireEd25519();
57
+ return keyOfSeed(crypto.getRandomValues(new Uint8Array(32)));
58
+ }
59
+ /** The same key as a non-extractable WebCrypto key, after which the seed can be dropped. */
60
+ export async function webCryptoPublisherKey(key) {
61
+ await requireEd25519();
62
+ return { privateKey: await privateKey(Uint8Array.from(key.seed), false), publicKey: Uint8Array.from(key.publicKey) };
63
+ }
64
+ function base58(bytes) {
65
+ let n = 0n;
66
+ for (const b of bytes)
67
+ n = (n << 8n) | BigInt(b);
68
+ let out = '';
69
+ for (; n > 0n; n /= 58n)
70
+ out = BASE58[Number(n % 58n)] + out;
71
+ return '1'.repeat(bytes.findIndex((b) => b !== 0) === -1 ? bytes.length : bytes.findIndex((b) => b !== 0)) + out;
72
+ }
73
+ /** The `did:key` of the key, as core's `derive_signer_id_did_key` derives it. */
74
+ export function signerIdOf(key) {
75
+ return `did:key:z${base58(concat(Uint8Array.from(ED25519_PUB_MULTICODEC), key.publicKey))}`;
76
+ }
77
+ /** Whether this is `mero-sign --dev`'s public key: a registry and a production node refuse what it signs. */
78
+ export function isDevPublisherKey(key) {
79
+ return signerIdOf(key) === DEV_SIGNER_ID;
80
+ }
81
+ /** The key's backup: UTF-8 JSON in `mero-sign`'s key-file shape. */
82
+ export function exportPublisherKey(key) {
83
+ return utf8(JSON.stringify({ private_key: b64url(key.seed), public_key: b64url(key.publicKey), signer_id: signerIdOf(key) }, null, 2));
84
+ }
85
+ /** Restores a key from its backup; the public key and signer id, when present, must be the seed's. Other fields are ignored, as `mero-sign` does. */
86
+ export async function importPublisherKey(bytes) {
87
+ let file;
88
+ try {
89
+ file = JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes));
90
+ }
91
+ catch {
92
+ throw new Error('a publisher key backup is a JSON document');
93
+ }
94
+ const seed = file?.private_key;
95
+ if (typeof seed !== 'string' || !SEED_B64URL.test(seed) || b64url(fromB64url(seed)) !== seed) {
96
+ throw new Error('the backup private_key is not an unpadded base64url 32-byte seed');
97
+ }
98
+ const key = await keyOfSeed(fromB64url(seed));
99
+ if (file.public_key !== undefined && file.public_key !== b64url(key.publicKey)) {
100
+ throw new Error("the backup public_key is not the seed's");
101
+ }
102
+ if (file.signer_id !== undefined && file.signer_id !== signerIdOf(key)) {
103
+ throw new Error("the backup signer_id is not the seed's");
104
+ }
105
+ return key;
106
+ }
107
+ /** RFC 8785 canonical bytes of the manifest without `signature` and `_`-prefixed fields, as core's `canonicalize_manifest`. */
108
+ export function canonicalizeManifest(manifest) {
109
+ const signed = Object.fromEntries(Object.entries(manifest).filter(([k]) => k !== 'signature' && !k.startsWith('_')));
110
+ return utf8(jcs(signed));
111
+ }
112
+ // Manifests hold only strings, safe integers, arrays and objects, where JSON.stringify's
113
+ // string and integer forms are RFC 8785's; keys sort by UTF-16 code unit, the default order.
114
+ function jcs(value) {
115
+ if (typeof value === 'string') {
116
+ if (/[\ud800-\udbff](?![\udc00-\udfff])|(?<![\ud800-\udbff])[\udc00-\udfff]/.test(value)) {
117
+ throw new Error('a lone surrogate cannot be canonicalized');
118
+ }
119
+ return JSON.stringify(value);
120
+ }
121
+ if (typeof value === 'number') {
122
+ if (!Number.isSafeInteger(value))
123
+ throw new Error('only safe integers can be canonicalized');
124
+ return String(value);
125
+ }
126
+ if (value === null || typeof value === 'boolean')
127
+ return String(value);
128
+ if (Array.isArray(value))
129
+ return `[${value.map(jcs).join(',')}]`;
130
+ return `{${Object.keys(value)
131
+ .sort()
132
+ .map((k) => `${jcs(k)}:${jcs(value[k])}`)
133
+ .join(',')}}`;
134
+ }
135
+ /** What Ed25519 signs: `sha256(domain || canonical bytes)`, as core's `compute_signing_payload`. */
136
+ export async function signingPayload(manifest) {
137
+ return sha256(concat(MANIFEST_SIGNING_DOMAIN, canonicalizeManifest(manifest)));
138
+ }
139
+ /**
140
+ * Checks a manifest's signature and that its `signerId` is the signing key's; returns the signer id.
141
+ * Not core's `verify_strict`, and it does not look at artifact digests: use {@link checkPackage} for those.
142
+ */
143
+ export async function verifyManifestSignature(manifest) {
144
+ await requireEd25519();
145
+ const sig = manifest.signature;
146
+ if (!sig)
147
+ throw new Error("manifest is missing required 'signature' field");
148
+ if (sig.algorithm !== 'ed25519')
149
+ throw new Error(`unsupported signature algorithm: '${sig.algorithm}'`);
150
+ const publicKey = fromB64url(sig.publicKey ?? '');
151
+ const signature = fromB64url(sig.signature ?? '');
152
+ if (publicKey.length !== 32 || signature.length !== 64)
153
+ throw new Error('malformed signature field');
154
+ const key = await crypto.subtle.importKey('raw', buf(publicKey), { name: 'Ed25519' }, false, ['verify']);
155
+ const ok = await crypto.subtle.verify('Ed25519', key, buf(signature), buf(await signingPayload(manifest)));
156
+ if (!ok)
157
+ throw new Error('Ed25519 signature verification failed');
158
+ const derived = signerIdOf({ publicKey });
159
+ if (manifest.signerId !== derived) {
160
+ throw new Error(`signerId mismatch: manifest declares '${manifest.signerId}' but signature public key derives to '${derived}'`);
161
+ }
162
+ return derived;
163
+ }
164
+ function checkPathComponent(value, field) {
165
+ if (!value)
166
+ throw new Error(`${field} is empty`);
167
+ if (value.includes('..'))
168
+ throw new Error(`${field} contains path traversal sequence '..'`);
169
+ if (value.includes('/') || value.includes('\\'))
170
+ throw new Error(`${field} contains directory separator`);
171
+ if (value.includes('\0'))
172
+ throw new Error(`${field} contains null byte`);
173
+ if (value.length >= 2 && value[1] === ':')
174
+ throw new Error(`${field} appears to be an absolute path`);
175
+ }
176
+ // core's validate_artifact_path, then the layout a pipeline file must have.
177
+ function checkPipelinePath(value, field) {
178
+ if (!value)
179
+ throw new Error(`${field} is empty`);
180
+ if (value.includes('\0'))
181
+ throw new Error(`${field} contains null byte`);
182
+ if (value.includes('\\'))
183
+ throw new Error(`${field} contains backslash (use forward slashes)`);
184
+ if (value.startsWith('/'))
185
+ throw new Error(`${field} is an absolute path`);
186
+ if (value[1] === ':')
187
+ throw new Error(`${field} appears to be an absolute Windows path`);
188
+ if (value.split('/').includes('..'))
189
+ throw new Error(`${field} contains path traversal component '..'`);
190
+ if (!PIPELINE_PATH.test(value) || utf8(value).length > 100) {
191
+ throw new Error(`${field} must be pipelines/<name>.yaml (A-Z a-z 0-9 . _ -), at most 100 bytes`);
192
+ }
193
+ }
194
+ const METADATA_STRINGS = ['name', 'description', 'author', 'icon', 'license', 'category', 'guide'];
195
+ // Copies only the known string fields into a fresh object, so what is signed is what is archived.
196
+ function normalizeMetadata(m) {
197
+ const bad = (what) => new Error(`metadata ${what}`);
198
+ if (typeof m !== 'object' || m === null || Array.isArray(m))
199
+ throw bad('must be an object');
200
+ const known = new Set([...METADATA_STRINGS, 'tags']);
201
+ const unknown = Object.keys(m).find((k) => !known.has(k));
202
+ if (unknown !== undefined)
203
+ throw bad(`has an unknown field '${unknown}'`);
204
+ const out = {};
205
+ for (const k of METADATA_STRINGS) {
206
+ const v = m[k];
207
+ if (v === undefined)
208
+ continue;
209
+ if (typeof v !== 'string')
210
+ throw bad(`${k} must be a string`);
211
+ out[k] = v;
212
+ }
213
+ if (typeof out.name !== 'string')
214
+ throw bad('name is required');
215
+ if (m.tags !== undefined) {
216
+ if (!Array.isArray(m.tags) || m.tags.some((t) => typeof t !== 'string'))
217
+ throw bad('tags must be an array of strings');
218
+ out.tags = [...m.tags];
219
+ }
220
+ return out;
221
+ }
222
+ const artifact = (path, bytes) => ({ path, hash: hex(sha256(bytes)), size: bytes.length });
223
+ const padded = (n) => 512 + Math.ceil(n / 512) * 512;
224
+ function tarEntry(name, data) {
225
+ const header = new Uint8Array(512);
226
+ const put = (off, text) => header.set(utf8(text), off);
227
+ put(0, name);
228
+ put(100, '0000644\0');
229
+ put(108, '0000000\0');
230
+ put(116, '0000000\0');
231
+ put(124, `${data.length.toString(8).padStart(11, '0')}\0`);
232
+ put(136, '00000000000\0');
233
+ put(148, ' ');
234
+ put(156, '0');
235
+ put(257, 'ustar\0');
236
+ put(263, '00');
237
+ put(148, `${header.reduce((n, b) => n + b, 0).toString(8).padStart(6, '0')}\0 `);
238
+ return concat(header, data, new Uint8Array((512 - (data.length % 512)) % 512));
239
+ }
240
+ // The entries of a tar this module wrote; a repeated name is refused.
241
+ function readTar(tar) {
242
+ const out = new Map();
243
+ const text = (a, b) => new TextDecoder().decode(tar.subarray(a, b)).replace(/\0.*$/s, '');
244
+ for (let off = 0; off + 512 <= tar.length && tar[off] !== 0;) {
245
+ const name = text(off, off + 100);
246
+ const size = parseInt(text(off + 124, off + 136).trim(), 8);
247
+ if (out.has(name))
248
+ throw new Error(`the archive has more than one entry at '${name}'`);
249
+ out.set(name, tar.subarray(off + 512, off + 512 + size));
250
+ off += padded(size);
251
+ }
252
+ return out;
253
+ }
254
+ /**
255
+ * Checks an uncompressed archive as the node will: one manifest, its signature by `publicKey`,
256
+ * exactly the files it declares, each with the declared size and SHA-256.
257
+ */
258
+ export async function checkPackage(tar, publicKey) {
259
+ const entries = readTar(tar);
260
+ const raw = entries.get('manifest.json');
261
+ if (!raw)
262
+ throw new Error('manifest.json not found in bundle');
263
+ const manifest = JSON.parse(new TextDecoder().decode(raw));
264
+ await verifyManifestSignature(manifest);
265
+ if (manifest.signature.publicKey !== b64url(publicKey))
266
+ throw new Error('the manifest is not signed by the publisher key');
267
+ const declared = [manifest.compute, ...(manifest.pipelines ?? [])];
268
+ const names = ['manifest.json', ...declared.map((a) => a.path)];
269
+ if (names.length !== entries.size || names.some((n) => !entries.has(n))) {
270
+ throw new Error('the archive does not hold exactly the files its manifest declares');
271
+ }
272
+ for (const a of declared) {
273
+ const bytes = entries.get(a.path);
274
+ if (!bytes || bytes.length !== a.size || hex(sha256(bytes)) !== a.hash) {
275
+ throw new Error(`bundle artifact '${a.path}' failed its integrity check`);
276
+ }
277
+ }
278
+ }
279
+ async function gzip(bytes) {
280
+ if (typeof CompressionStream === 'undefined')
281
+ throw new Error('this runtime cannot gzip packages (no CompressionStream)');
282
+ const stream = new Blob([buf(bytes)]).stream().pipeThrough(new CompressionStream('gzip'));
283
+ return new Uint8Array(await new Response(stream).arrayBuffer());
284
+ }
285
+ async function signerOf(key, seed, publicKey) {
286
+ if (seed) {
287
+ const derived = fromB64url(await recoveryPublicKey(seed));
288
+ if (hex(derived) !== hex(publicKey))
289
+ throw new Error("the publisher key's publicKey is not its seed's");
290
+ return { signing: await privateKey(seed, false), publicKey: derived };
291
+ }
292
+ const k = key.privateKey;
293
+ if (k?.algorithm?.name !== 'Ed25519' || k.type !== 'private' || !k.usages.includes('sign')) {
294
+ throw new Error('the publisher key is not an Ed25519 signing key');
295
+ }
296
+ return { signing: k, publicKey };
297
+ }
298
+ /**
299
+ * A signed compute-only `.mpk`: `manifest.json`, `compute.wasm` and the pipelines, as a tar.gz.
300
+ * Refuses what core's node refuses at install, with core's messages, and checks its own output
301
+ * before returning. It cannot check what the node compiles: that the component declares
302
+ * compute methods and that the pipelines fit them.
303
+ */
304
+ export async function packComputePackage(input, key) {
305
+ // Everything up to the first await copies and validates, so the caller's buffers cannot change under us.
306
+ const seed = 'seed' in key && key.seed ? Uint8Array.from(key.seed) : undefined;
307
+ const publicKey = Uint8Array.from(key.publicKey);
308
+ const job = prepare(input);
309
+ await requireEd25519();
310
+ const { signing, publicKey: pub } = await signerOf(key, seed, publicKey);
311
+ const manifest = { ...job.manifest, signerId: signerIdOf({ publicKey: pub }) };
312
+ const signature = await crypto.subtle.sign('Ed25519', signing, buf(await signingPayload(manifest)));
313
+ manifest.signature = { algorithm: 'ed25519', publicKey: b64url(pub), signature: b64url(new Uint8Array(signature)) };
314
+ // The archived manifest is the canonical form of the signed document, never a second serialization.
315
+ const manifestBytes = utf8(jcs(manifest));
316
+ if (manifestBytes.length > MAX_MANIFEST_BYTES) {
317
+ throw new Error(`bundle manifest.json exceeds the ${MAX_MANIFEST_BYTES} byte cap`);
318
+ }
319
+ const files = [['manifest.json', manifestBytes], ['compute.wasm', job.compute], ...job.files];
320
+ checkArchiveSize(files.map(([, b]) => b.length));
321
+ const tar = concat(...files.map(([n, b]) => tarEntry(n, b)), new Uint8Array(1024));
322
+ await checkPackage(tar, pub);
323
+ const mpk = await gzip(tar);
324
+ if (mpk.length > MAX_MPK_BYTES)
325
+ throw new Error(`a package is limited to ${MAX_MPK_BYTES >> 20} MiB`);
326
+ return mpk;
327
+ }
328
+ function checkArchiveSize(sizes) {
329
+ if (sizes.reduce((n, s) => n + padded(s), 1024) > MAX_ARCHIVE_BYTES) {
330
+ throw new Error(`bundle archive exceeds the ${MAX_ARCHIVE_BYTES} byte decompressed cap`);
331
+ }
332
+ }
333
+ // Validates the input and returns copies of what it archives, with the unsigned manifest.
334
+ function prepare(input) {
335
+ checkPathComponent(input.package, 'package');
336
+ checkPathComponent(input.version, 'appVersion');
337
+ if (!SEMVER.test(input.version))
338
+ throw new Error(`appVersion '${input.version}' is not a semantic version`);
339
+ if (!input.compute?.length)
340
+ throw new Error('the package ships no WASM');
341
+ if (input.pipelines.length > MAX_PIPELINES_PER_PACKAGE) {
342
+ throw new Error(`bundle declares ${input.pipelines.length} pipelines, at most ${MAX_PIPELINES_PER_PACKAGE} are allowed`);
343
+ }
344
+ checkArchiveSize([input.compute.length]);
345
+ const compute = Uint8Array.from(input.compute);
346
+ if (COMPONENT_HEADER.some((b, i) => compute[i] !== b)) {
347
+ throw new Error('compute: not a WASM component (an SDK 0.12 core module is refused by the node)');
348
+ }
349
+ const files = input.pipelines.map((p, i) => {
350
+ checkPipelinePath(p.path, `pipelines[${i}].path`);
351
+ return [p.path, utf8(p.source)];
352
+ });
353
+ const big = files.find(([, b]) => b.length > MAX_PIPELINE_BYTES);
354
+ if (big)
355
+ throw new Error(`pipeline '${big[0]}' exceeds the ${MAX_PIPELINE_BYTES} byte cap`);
356
+ const lower = files.map(([n]) => n.toLowerCase());
357
+ if (new Set(lower).size !== files.length)
358
+ throw new Error('two pipelines have the same path');
359
+ const metadata = input.metadata === undefined ? undefined : normalizeMetadata(input.metadata);
360
+ const manifest = {
361
+ version: '1.0',
362
+ package: input.package,
363
+ appVersion: input.version,
364
+ minRuntimeVersion: MIN_RUNTIME_VERSION,
365
+ ...(metadata ? { metadata } : {}),
366
+ compute: artifact('compute.wasm', compute),
367
+ ...(files.length ? { pipelines: files.map(([n, b]) => artifact(n, b)) } : {}),
368
+ };
369
+ return { manifest, compute, files };
370
+ }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calimero-network/mero-js",
3
- "version": "35.0.0",
3
+ "version": "35.2.0",
4
4
  "description": "JavaScript client for Calimero 1.0: attested TEE nodes, a sealed channel, passkeys and API keys",
5
5
  "type": "module",
6
6
  "exports": {