@calimero-network/mero-js 35.3.0 → 35.4.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/dist/client/approvals.d.ts +2 -0
- package/dist/client/calimero-client.d.ts +20 -0
- package/dist/client/calimero-client.js +31 -0
- package/dist/client/index.d.ts +2 -0
- package/dist/client/index.js +1 -0
- package/dist/client/receipts.d.ts +176 -0
- package/dist/client/receipts.js +475 -0
- package/dist/generated/api.d.ts +126 -4
- package/dist/generated/methods.d.ts +7 -1
- package/dist/generated/methods.js +7 -1
- package/dist/index.browser.mjs +4 -4
- package/dist/index.browser.mjs.map +4 -4
- package/dist/index.cjs +2015 -1561
- package/dist/index.cjs.map +4 -4
- package/dist/index.mjs +2015 -1561
- package/dist/index.mjs.map +4 -4
- package/dist/package/pack.d.ts +1 -0
- package/dist/package/pack.js +11 -5
- package/dist/recovery/backup-files.d.ts +4 -1
- package/dist/recovery/backup-files.js +28 -1
- package/dist/runtime/attestation.d.ts +5 -0
- package/dist/runtime/attestation.js +36 -28
- package/dist/runtime/transport.d.ts +2 -0
- package/dist/runtime/transport.js +4 -0
- package/package.json +3 -2
|
@@ -32,6 +32,8 @@ export interface Governance {
|
|
|
32
32
|
deployments?: 'open' | 'granted';
|
|
33
33
|
/** Who grants deployers: the operator (left out) or the cluster's owner. */
|
|
34
34
|
deployers?: 'operator' | 'owner';
|
|
35
|
+
/** Who may create an account: anyone (`open`, left out), invitees or pre-authorized people only. */
|
|
36
|
+
signUp?: 'open' | 'invite' | 'closed';
|
|
35
37
|
}
|
|
36
38
|
/** Whose approvals a report covers: an organization's, or the account's own apps. */
|
|
37
39
|
export type ReportScope = {
|
|
@@ -16,6 +16,7 @@ import { type RouteClientOptions } from '../routes/route-client.js';
|
|
|
16
16
|
import type { PackageCapabilities } from './package-capabilities.js';
|
|
17
17
|
import { type Routes } from '../generated/methods.js';
|
|
18
18
|
import { type ExportedFile, type FileSink } from './files.js';
|
|
19
|
+
import { type AttestedCluster, type PipelineReceipt, type ReceiptAnswer } from './receipts.js';
|
|
19
20
|
import { type AppsReport, type ConsentRequest, type ConsentResult, type ConsentStarted, type OpenConsentOptions, type ResumeConsentOptions, type PendingApprovals } from './approvals.js';
|
|
20
21
|
import type { ApiAnswer, ApiSchema } from '../routes/types.js';
|
|
21
22
|
export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmPromptBlocked, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, FeatureNotActive, NotFound, OriginNotRegistered, OriginTaken, PasskeyUnknownHere, QuotaExceeded, RecoveryNotReady, ReleaseDeadlineError, RuntimeTooOld, SignUpRefused, TrapError, UnavailableError, WrongNode, WrongRecoveryCode, errorFrom, } from '../runtime/errors.js';
|
|
@@ -372,6 +373,25 @@ export declare class CalimeroClient {
|
|
|
372
373
|
exportFileTo(app: string, id: string, sink: FileSink, signal?: AbortSignal): Promise<ExportedFile>;
|
|
373
374
|
/** The plaintext of sealed file `id` of component app `app`, in memory; use {@link exportFileTo} for a large one. */
|
|
374
375
|
exportFile(app: string, id: string, signal?: AbortSignal): Promise<Uint8Array>;
|
|
376
|
+
/** The policy this client attests nodes under; a client without one verifies nothing. */
|
|
377
|
+
private get attestationPolicy();
|
|
378
|
+
/**
|
|
379
|
+
* Verify every replica of `app` under this client's policy: each one's quote binds its receipt key,
|
|
380
|
+
* the cluster's governance, and its cluster and node id. Answers the attested receipt key per node
|
|
381
|
+
* and the governance.
|
|
382
|
+
*/
|
|
383
|
+
verifyAppCluster(app: string): Promise<AttestedCluster>;
|
|
384
|
+
/**
|
|
385
|
+
* The signed receipt of an ended pipeline run, version 2 (`client.apps.pipelineReceiptReceipt`):
|
|
386
|
+
* with each job's report evidence and job node attestation. A version 1 answer does not verify.
|
|
387
|
+
*/
|
|
388
|
+
pipelineReceipt(app: string, run: string): Promise<ReceiptAnswer>;
|
|
389
|
+
/**
|
|
390
|
+
* Verify the receipt of a pipeline run ({@link pipelineReceipt}): signed by the key an attested replica
|
|
391
|
+
* holds, for `app` and `run`, with every job's report signed by a job key a job node attests. Throws
|
|
392
|
+
* when it is not; answers the receipt.
|
|
393
|
+
*/
|
|
394
|
+
verifyPipelineReceipt(app: string, run: string, answer: ReceiptAnswer): Promise<PipelineReceipt>;
|
|
375
395
|
/**
|
|
376
396
|
* Download a component app's blob with a grant one of its runs handed out
|
|
377
397
|
* (`BlobRef::grant`, up to 24 h). No session needed: the grant is the
|
|
@@ -18,6 +18,7 @@ import { createRoutes } from '../generated/methods.js';
|
|
|
18
18
|
import { passkeyConfirm } from '../runtime/passkey.js';
|
|
19
19
|
import { exportFile, exportFileTo } from './files.js';
|
|
20
20
|
import { signRecovery } from './recovery-key.js';
|
|
21
|
+
import { verifyAppCluster, verifyPipelineReceipt } from './receipts.js';
|
|
21
22
|
import { CONSENT_STORAGE_KEY, confirmationCode, pageQuery, pendingApprovalsFrom, withoutConsentReturn, } from './approvals.js';
|
|
22
23
|
export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ConfirmCancelled, ConfirmPromptBlocked, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, FeatureNotActive, NotFound, OriginNotRegistered, OriginTaken, PasskeyUnknownHere, QuotaExceeded, RecoveryNotReady, ReleaseDeadlineError, RuntimeTooOld, SignUpRefused, TrapError, UnavailableError, WrongNode, WrongRecoveryCode, errorFrom, } from '../runtime/errors.js';
|
|
23
24
|
/** The largest file sent as one request, and the part size a session is asked for. */
|
|
@@ -365,6 +366,36 @@ export class CalimeroClient {
|
|
|
365
366
|
exportFile(app, id, signal) {
|
|
366
367
|
return exportFile(this.exportClient, app, id, signal);
|
|
367
368
|
}
|
|
369
|
+
/** The policy this client attests nodes under; a client without one verifies nothing. */
|
|
370
|
+
get attestationPolicy() {
|
|
371
|
+
const policy = this.transport.nodePolicy;
|
|
372
|
+
if (!policy)
|
|
373
|
+
throw new Error('this client has no attestation policy, so it cannot verify an attestation');
|
|
374
|
+
return policy;
|
|
375
|
+
}
|
|
376
|
+
/**
|
|
377
|
+
* Verify every replica of `app` under this client's policy: each one's quote binds its receipt key,
|
|
378
|
+
* the cluster's governance, and its cluster and node id. Answers the attested receipt key per node
|
|
379
|
+
* and the governance.
|
|
380
|
+
*/
|
|
381
|
+
async verifyAppCluster(app) {
|
|
382
|
+
return verifyAppCluster(this, app, this.attestationPolicy);
|
|
383
|
+
}
|
|
384
|
+
/**
|
|
385
|
+
* The signed receipt of an ended pipeline run, version 2 (`client.apps.pipelineReceiptReceipt`):
|
|
386
|
+
* with each job's report evidence and job node attestation. A version 1 answer does not verify.
|
|
387
|
+
*/
|
|
388
|
+
async pipelineReceipt(app, run) {
|
|
389
|
+
return (await this.apps.pipelineReceiptReceipt({ app, run, version: 2 }));
|
|
390
|
+
}
|
|
391
|
+
/**
|
|
392
|
+
* Verify the receipt of a pipeline run ({@link pipelineReceipt}): signed by the key an attested replica
|
|
393
|
+
* holds, for `app` and `run`, with every job's report signed by a job key a job node attests. Throws
|
|
394
|
+
* when it is not; answers the receipt.
|
|
395
|
+
*/
|
|
396
|
+
async verifyPipelineReceipt(app, run, answer) {
|
|
397
|
+
return verifyPipelineReceipt(this, app, run, answer, this.attestationPolicy);
|
|
398
|
+
}
|
|
368
399
|
/**
|
|
369
400
|
* Download a component app's blob with a grant one of its runs handed out
|
|
370
401
|
* (`BlobRef::grant`, up to 24 h). No session needed: the grant is the
|
package/dist/client/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { CalimeroClient, FILE_PART_BYTES, deployerKey, frontendManifest, pageDeployment, presenceState } from './calimero-client.js';
|
|
2
2
|
export { ExportError } from './files.js';
|
|
3
|
+
export { jobKeyBinding, receiptMessage, reportMessage, verifyAppCluster, verifyJobReports, verifyPipelineReceipt, verifyReceiptKey } from './receipts.js';
|
|
4
|
+
export type { AttestedCluster, CachedRun, FileRef, JobAttestationDoc, JobEvidence, JobOutput, PipelineReceipt, ReportFields, StepReceipt, StepRunProof, ReceiptAnswer, ReceiptKeyDoc } from './receipts.js';
|
|
3
5
|
export type { ExportErrorCode, ExportedFile, FileSink } from './files.js';
|
|
4
6
|
export { DEFAULT_DIRECTORY, DirectoryError } from '../runtime/directory.js';
|
|
5
7
|
export type { DirectoryFailure } from '../runtime/directory.js';
|
package/dist/client/index.js
CHANGED
|
@@ -9,6 +9,7 @@
|
|
|
9
9
|
// use. src/routes/index.ts describes the layering.
|
|
10
10
|
export { CalimeroClient, FILE_PART_BYTES, deployerKey, frontendManifest, pageDeployment, presenceState } from './calimero-client.js';
|
|
11
11
|
export { ExportError } from './files.js';
|
|
12
|
+
export { jobKeyBinding, receiptMessage, reportMessage, verifyAppCluster, verifyJobReports, verifyPipelineReceipt, verifyReceiptKey } from './receipts.js';
|
|
12
13
|
export { DEFAULT_DIRECTORY, DirectoryError } from '../runtime/directory.js';
|
|
13
14
|
export { AppError, ArgsTooLarge, BadOrigin, CalimeroError, ClusterNotUpgraded, ConfirmCancelled, ConfirmPromptBlocked, ConfirmRequired, IdempotencyMismatch, LoginRequired, ConsentStale, FeatureNotActive, NotFound, NotServing, OriginNotRegistered, OriginTaken, PasskeyUnknownHere, QuotaExceeded, RecoveryNotReady, ReleaseDeadlineError, RuntimeTooOld, SignUpRefused, TrapError, UnavailableError, WrongNode, WrongRecoveryCode, errorFrom, } from '../runtime/errors.js';
|
|
14
15
|
export { claimedRelease, fetchAttestedKey, freshCollateral, MOCK_QUOTE_HEADER, verifyNode } from '../runtime/attestation.js';
|
|
@@ -0,0 +1,176 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Checking a pipeline run's receipt as core's `calimero-client` does (`Client::verify_app_cluster`,
|
|
3
|
+
* `attest::verify_receipt_key`, `Client::verify_receipt`): the receipt is signed by the answering
|
|
4
|
+
* node's receipt key, and that key is one every replica's quote attests, bound to the cluster and
|
|
5
|
+
* node the entry node names. A quote of the unbound `receipt-key.v2` form is never accepted. A
|
|
6
|
+
* version 2 receipt also proves each job's report: its job key signed what the proof says, and a
|
|
7
|
+
* job node's quote under the client's policy binds that key, node, cluster and cluster identity.
|
|
8
|
+
*/
|
|
9
|
+
import { type AttestationDoc, type NodePolicy } from '../runtime/attestation.js';
|
|
10
|
+
import type { AppsRoutes } from '../generated/methods.js';
|
|
11
|
+
import type { Governance } from './approvals.js';
|
|
12
|
+
/** A receipt-key attestation: the quote binds the key, the governance, and the cluster and node asked for. */
|
|
13
|
+
export type ReceiptKeyDoc = AttestationDoc & {
|
|
14
|
+
receiptKey?: string;
|
|
15
|
+
governance?: Governance;
|
|
16
|
+
};
|
|
17
|
+
/** What `GET /apps/{app}/pipeline-runs/{run}/receipt` answers: the receipt as sent, the signing node, its signature (hex). Checked at run time. */
|
|
18
|
+
export interface ReceiptAnswer {
|
|
19
|
+
receipt: unknown;
|
|
20
|
+
node: unknown;
|
|
21
|
+
signature: unknown;
|
|
22
|
+
}
|
|
23
|
+
/** A file named by id, size and plaintext SHA-256 (hex). */
|
|
24
|
+
export interface FileRef {
|
|
25
|
+
id: string;
|
|
26
|
+
size: number;
|
|
27
|
+
sha256: string;
|
|
28
|
+
}
|
|
29
|
+
/** What one step run's proof records: which job node ran which assignment, and what came out. */
|
|
30
|
+
export interface StepRunProof {
|
|
31
|
+
run: string;
|
|
32
|
+
step: string;
|
|
33
|
+
index: number;
|
|
34
|
+
outcome: string;
|
|
35
|
+
attempt: number;
|
|
36
|
+
node?: number | null;
|
|
37
|
+
jobKey?: string | null;
|
|
38
|
+
assignmentDigest?: string | null;
|
|
39
|
+
reportSha256?: string | null;
|
|
40
|
+
signature?: string | null;
|
|
41
|
+
outputs: FileRef[];
|
|
42
|
+
usage: {
|
|
43
|
+
cpuMicros: string;
|
|
44
|
+
gibMicros: string;
|
|
45
|
+
fuel: string;
|
|
46
|
+
};
|
|
47
|
+
/** What the job's report signs that the fields above do not (version 2 only). */
|
|
48
|
+
job?: JobEvidence | null;
|
|
49
|
+
}
|
|
50
|
+
/** A file as a job's report signs it: id, plaintext size and SHA-256, and each ciphertext segment's SHA-256 (lowercase hex). */
|
|
51
|
+
export interface JobOutput {
|
|
52
|
+
id: string;
|
|
53
|
+
size: number;
|
|
54
|
+
sha256: string;
|
|
55
|
+
segments: string[];
|
|
56
|
+
}
|
|
57
|
+
/** The rest of what a job's report signs: the result's hash, the failure text, each output's segment hashes, the module log. */
|
|
58
|
+
export interface JobEvidence {
|
|
59
|
+
resultSha256: string;
|
|
60
|
+
message?: string;
|
|
61
|
+
segments: string[][];
|
|
62
|
+
log?: JobOutput | null;
|
|
63
|
+
}
|
|
64
|
+
/** A job node's `purpose=jobs` attestation: the quote binds its transport key, job key, release, cluster, node and cluster identity. */
|
|
65
|
+
export type JobAttestationDoc = AttestationDoc & {
|
|
66
|
+
jobKey?: string;
|
|
67
|
+
clusterIdentity?: string;
|
|
68
|
+
};
|
|
69
|
+
/** A run answered from the step cache: it ran nothing, so it has no proof. */
|
|
70
|
+
export interface CachedRun {
|
|
71
|
+
index: number;
|
|
72
|
+
cached: boolean;
|
|
73
|
+
cacheKey: string;
|
|
74
|
+
}
|
|
75
|
+
export interface StepReceipt {
|
|
76
|
+
status: string;
|
|
77
|
+
reason?: string | null;
|
|
78
|
+
runs: (CachedRun | StepRunProof)[];
|
|
79
|
+
}
|
|
80
|
+
/** What the node states about a finished pipeline run (core's `PipelineReceipt`). `cluster` is the cluster identity key, hex. */
|
|
81
|
+
export interface PipelineReceipt {
|
|
82
|
+
version: number;
|
|
83
|
+
cluster: string;
|
|
84
|
+
app: string;
|
|
85
|
+
run: string;
|
|
86
|
+
pipeline: string;
|
|
87
|
+
release: string;
|
|
88
|
+
pipelineHash: string;
|
|
89
|
+
modules: Record<string, string>;
|
|
90
|
+
inputs: Record<string, FileRef[]>;
|
|
91
|
+
params: Record<string, unknown>;
|
|
92
|
+
state: string;
|
|
93
|
+
startTsMs: number;
|
|
94
|
+
endTsMs: number;
|
|
95
|
+
steps: Record<string, StepReceipt>;
|
|
96
|
+
costSoFar?: string | null;
|
|
97
|
+
/** Each job key a proof names, its job node's attestation (version 2 only). */
|
|
98
|
+
jobAttestations?: Record<string, JobAttestationDoc>;
|
|
99
|
+
}
|
|
100
|
+
/** Every replica of an app, attested: its receipt key by node id, the governance they all attest, and the cluster name every quote bound. */
|
|
101
|
+
export interface AttestedCluster {
|
|
102
|
+
keys: Map<number, Uint8Array>;
|
|
103
|
+
governance: Governance;
|
|
104
|
+
cluster: string;
|
|
105
|
+
}
|
|
106
|
+
type AttestationRoutes = Pick<AppsRoutes, 'attestation'>;
|
|
107
|
+
/**
|
|
108
|
+
* Checks a receipt-key attestation as core's `verify_receipt_key` does: its quote binds the key, the
|
|
109
|
+
* governance and the `cluster` and `node` the caller asked for (never the document's own fields, which
|
|
110
|
+
* nothing signs). Answers the key and the governance rebuilt from its canonical fields.
|
|
111
|
+
*/
|
|
112
|
+
export declare function verifyReceiptKey(doc: ReceiptKeyDoc, nonce: Uint8Array, cluster: string, node: number, policy: NodePolicy): Promise<{
|
|
113
|
+
key: Uint8Array;
|
|
114
|
+
governance: Governance;
|
|
115
|
+
}>;
|
|
116
|
+
/**
|
|
117
|
+
* Verifies every replica of `app` (core's `Client::verify_app_cluster`): each one's quote over a fresh
|
|
118
|
+
* nonce, held to `policy`, binding its receipt key, the cluster's governance, and the cluster and node
|
|
119
|
+
* id the entry node names. Any replica error, a node id that differs from the document's, or replicas
|
|
120
|
+
* that attest other governance fails the whole check.
|
|
121
|
+
*/
|
|
122
|
+
export declare function verifyAppCluster(client: {
|
|
123
|
+
apps: AttestationRoutes;
|
|
124
|
+
}, app: string, policy: NodePolicy): Promise<AttestedCluster>;
|
|
125
|
+
/** The bytes a receipt's signature covers (core's `receipt_message`): the domain, then the canonical JSON. */
|
|
126
|
+
export declare const receiptMessage: (receipt: unknown) => Uint8Array;
|
|
127
|
+
/**
|
|
128
|
+
* Whether `answer` is signed by `key` (core's `verify_pipeline_receipt`). Answers the receipt as parsed
|
|
129
|
+
* from the canonical bytes that were verified, checked against core's receipt schema.
|
|
130
|
+
*/
|
|
131
|
+
export declare function verifyReceiptSignature(answer: ReceiptAnswer, key: Uint8Array): Promise<PipelineReceipt>;
|
|
132
|
+
/** One job report's signed fields, in the order {@link reportMessage} writes them (core's `ReportFields`). */
|
|
133
|
+
export interface ReportFields {
|
|
134
|
+
/** SHA-256 of the assignment message the job ran (hex). */
|
|
135
|
+
assignment: string;
|
|
136
|
+
app: string;
|
|
137
|
+
run: string;
|
|
138
|
+
attempt: number;
|
|
139
|
+
/** `null` for a done report, else why it failed. */
|
|
140
|
+
reason: string | null;
|
|
141
|
+
message: string;
|
|
142
|
+
resultSha256: string;
|
|
143
|
+
outputs: JobOutput[];
|
|
144
|
+
/** CPU micros, GiB micros, fuel, as decimal strings. */
|
|
145
|
+
usage: [string, string, string];
|
|
146
|
+
log?: JobOutput | null;
|
|
147
|
+
}
|
|
148
|
+
/**
|
|
149
|
+
* The bytes a job node signs for one report (core's `report_message`): the domain, the assignment digest,
|
|
150
|
+
* the length-prefixed app, run, reason and message, the result's hash, the outputs, the usage, then the
|
|
151
|
+
* log after its own domain; integers big-endian, hashes as their 32 bytes.
|
|
152
|
+
*/
|
|
153
|
+
export declare function reportMessage(f: ReportFields): Uint8Array;
|
|
154
|
+
/**
|
|
155
|
+
* What a job-node attestation's quote binds after the nonce (core's `job_key_binding`): both keys, the
|
|
156
|
+
* release and cluster (length-prefixed), the node id, and the cluster identity when there is one. Hex.
|
|
157
|
+
*/
|
|
158
|
+
export declare function jobKeyBinding(transportKey: Uint8Array, jobKey: Uint8Array, release: string, cluster: string, node: number, clusterIdentity?: Uint8Array): Promise<string>;
|
|
159
|
+
/**
|
|
160
|
+
* Checks every step run's proof of a version 2 receipt (core's `verify_job_reports`), each step's runs
|
|
161
|
+
* listed once in index order, and answers each job key that signed a report with the node it ran on; a
|
|
162
|
+
* key named on two nodes is refused. Whose key each is (its attestation) is for the caller to verify.
|
|
163
|
+
* What a job signed is proven; the rest (step and run states, cached runs, and the node and key a
|
|
164
|
+
* leader-ended run names) is the signing replica's word.
|
|
165
|
+
*/
|
|
166
|
+
export declare function verifyJobReports(receipt: PipelineReceipt): Promise<Map<string, number>>;
|
|
167
|
+
/**
|
|
168
|
+
* Checks that the node that answered holds a receipt key attested under `policy` ({@link verifyAppCluster})
|
|
169
|
+
* and signed `answer` with it, that the receipt is for `app` and `run`, that every job report it names is
|
|
170
|
+
* signed by its job key ({@link verifyJobReports}), and that each such key is a job node's of the attested
|
|
171
|
+
* cluster and the receipt's cluster identity, under `policy`. A version 1 receipt is refused. Answers the receipt.
|
|
172
|
+
*/
|
|
173
|
+
export declare function verifyPipelineReceipt(client: {
|
|
174
|
+
apps: AttestationRoutes;
|
|
175
|
+
}, app: string, run: string, answer: ReceiptAnswer, policy: NodePolicy): Promise<PipelineReceipt>;
|
|
176
|
+
export {};
|