@calimero-network/mero-js 35.2.0 → 35.2.1
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 +34 -6
- package/dist/client/calimero-client.d.ts +1 -0
- package/dist/client/calimero-client.js +5 -2
- package/dist/client/files.d.ts +2 -1
- package/dist/client/files.js +2 -5
- package/dist/index.browser.mjs +3 -3
- package/dist/index.browser.mjs.map +3 -3
- package/dist/index.cjs +6 -8
- package/dist/index.cjs.map +2 -2
- package/dist/index.mjs +6 -8
- package/dist/index.mjs.map +2 -2
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -1,11 +1,29 @@
|
|
|
1
1
|
# Mero.js — the JavaScript client for Calimero 1.0
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
3
|
+
Your app's whole backend, like Firebase. Except nobody can read your data, not even us.
|
|
4
|
+
[Calimero](https://calimero-network.github.io/core/) gives an app auth (passkeys,
|
|
5
|
+
sessions, scoped API keys), a database (replicated app state), functions (Rust app
|
|
6
|
+
methods, compute jobs, timers, pipelines), realtime (events, presence), sealed file
|
|
7
|
+
and blob storage, search, hosting for its frontend and typed clients, all running
|
|
8
|
+
inside attested Intel TDX hardware. Clients check a node's attestation against
|
|
9
|
+
Sigstore-signed releases before they send it anything, then talk to it over a sealed
|
|
10
|
+
Noise channel.
|
|
11
|
+
|
|
12
|
+
This package is the JavaScript/TypeScript client, for the browser and Node 18+.
|
|
13
|
+
`CalimeroClient` verifies the node's TDX attestation, seals every request to it end
|
|
14
|
+
to end (Noise NK, `calimero/sealed-http/v2`), signs people in with WebAuthn passkeys
|
|
15
|
+
and machines with API keys, and calls your app. It is byte-compatible with core's
|
|
16
|
+
`calimero-sealed` and `calimero-client`.
|
|
17
|
+
|
|
18
|
+
What you can do with it:
|
|
19
|
+
|
|
20
|
+
- Connect to a Calimero Cloud cluster by name, with failover between its nodes.
|
|
21
|
+
- Sign up and sign in with passkeys, use API keys, and ask for passkey consent on sensitive calls.
|
|
22
|
+
- Install packages, create app instances, and call and view their methods.
|
|
23
|
+
- Follow an app's events and presence as streams.
|
|
24
|
+
- Upload and download sealed files and blobs.
|
|
25
|
+
- Manage organizations, teams, invites, deployments and every other route of the node, through methods generated from core's OpenAPI document.
|
|
26
|
+
- Build and sign a compute-only pipeline package (`.mpk`).
|
|
9
27
|
|
|
10
28
|
> **From version 27 this is the Calimero 1.0 client only.** The v1 SDK for merod 0.x nodes
|
|
11
29
|
> (`MeroJs`, the admin and auth API clients, JSON-RPC, contexts and namespaces)
|
|
@@ -109,6 +127,7 @@ flows and streams a single route cannot be:
|
|
|
109
127
|
- **Credentials**: `signUp(passkey, name, { invite?, origin?, signal? })`, `signIn(passkey, { origin?, signal? })`, `refresh`, `signOut`, `signOutEverywhere`, `useSession`, `useApiKey`, `addPasskey(newPasskey, approver)`.
|
|
110
128
|
- **Account recovery** (core #4844): signed out, `startAccountRecovery(code, passkey)` and, 72 hours later, `finishAccountRecovery(passkey, accountId?)`. The code itself is `client.auth.recoveryCreate({}, { confirm })`.
|
|
111
129
|
- **Organization recovery**: `startRecovery(org, seed)` (the seed signs here and never leaves the process); `newRecoverySeed`, `recoveryPublicKey`.
|
|
130
|
+
- **Files**: `uploadFile(app, data)` (a large file goes up in parts), `exportFile(app, id)` and `exportFileTo(app, id, sink)` (the plaintext, checked against its id, size and hash).
|
|
112
131
|
- **Blobs**: `downloadBlob(app, id)`, `downloadBlobGranted(app, id, grant)` (bytes; `client.apps.blobDownload` answers a `Blob` with its type).
|
|
113
132
|
- **Streams**: `events(app, from?, signal?)`, `presenceStream(app, signal?)`.
|
|
114
133
|
- **Approvals from an app**: `pendingApprovals(org?)`, `appsReportAll(org)`, then `openConsentPage(request, …)` to send the user to the node's consent page, and `waitForConsent(requestId)`; back on `returnTo`, `resumeConsent()` reads the decision on the request this page started from the node (never from the URL) and refuses a return for another request, one still pending, or one a newer request replaced (`CONSENT_REPLACED`: an account has one undecided request per node). Besides releases, upgrades and outbound hosts, `createOrgConsent`, `createInviteConsent` and `acceptInviteConsent` ask for a new organization, an invite or joining with one, and `leaveOrgConsent`, `removeMemberConsent`, `setMemberRoleConsent`, `setMemberTeamsConsent`, `removeMemberTeamsConsent`, `revokeInviteConsent`, `renameOrgConsent`, `deleteOrgConsent`, `setCapabilitiesConsent` and `setAllAppsConsent` for managing one; the result's `outcome` (`{ orgId }`, `{ token }`, `{ org }`, a rename's `{ orgId, name }`, a deletion's `{ apps }`) is typed by `kind`. Show the answer's `code` to the user before sending them to `url` (`openConsentPage`'s `confirm` hook); they should see the same code on the page (`confirmationCode(requestId)` checks it). See [Ask your users to approve node images and app upgrades](https://calimero-network.github.io/mero-js/guides/user-approvals/).
|
|
@@ -382,6 +401,15 @@ and the `app.wasm` of its `kv-store-test-fixture.mpk` (as `./merod` and
|
|
|
382
401
|
`./kv_store.wasm`), which is what CI runs them against; core's `e2e.yml` runs
|
|
383
402
|
the same suite against core's own tree.
|
|
384
403
|
|
|
404
|
+
## Related repositories
|
|
405
|
+
|
|
406
|
+
- [core](https://github.com/calimero-network/core): the node (`merod`), the Rust SDK and client, `meroctl`, and the [docs](https://calimero-network.github.io/core/).
|
|
407
|
+
- [mero-tee](https://github.com/calimero-network/mero-tee): the TDX node images and the signed releases this client verifies.
|
|
408
|
+
- [app-registry](https://github.com/calimero-network/app-registry): the registry of signed app packages.
|
|
409
|
+
- [mero-react](https://github.com/calimero-network/mero-react): React bindings built on this client.
|
|
410
|
+
- [calimero-client-py](https://github.com/calimero-network/calimero-client-py), [swift-sdk](https://github.com/calimero-network/swift-sdk), [kotlin-sdk](https://github.com/calimero-network/kotlin-sdk): the clients for Python, Swift and Kotlin.
|
|
411
|
+
- [apps](https://github.com/calimero-network/apps): Calimero apps.
|
|
412
|
+
|
|
385
413
|
## License
|
|
386
414
|
|
|
387
415
|
MIT — see [LICENSE](LICENSE).
|
|
@@ -352,6 +352,7 @@ export declare class CalimeroClient {
|
|
|
352
352
|
finishAccountRecovery(passkey: PasskeyProvider, accountId?: string): Promise<CalimeroSession>;
|
|
353
353
|
/** One of `app`'s blobs, by id (base58 or hex). */
|
|
354
354
|
downloadBlob(app: string, id: string): Promise<Uint8Array>;
|
|
355
|
+
private get exportClient();
|
|
355
356
|
/**
|
|
356
357
|
* Write the plaintext of sealed file `id` of component app `app` to `sink`, checked against its id,
|
|
357
358
|
* size and hash. On rejection, discard what `sink` received: it is authentic but may be a prefix of
|
|
@@ -334,17 +334,20 @@ export class CalimeroClient {
|
|
|
334
334
|
async downloadBlob(app, id) {
|
|
335
335
|
return new Uint8Array(await (await this.apps.blobDownload({ app, id })).arrayBuffer());
|
|
336
336
|
}
|
|
337
|
+
get exportClient() {
|
|
338
|
+
return { exportsExport: this.apps.exportsExport, request: this.transport.request.bind(this.transport) };
|
|
339
|
+
}
|
|
337
340
|
/**
|
|
338
341
|
* Write the plaintext of sealed file `id` of component app `app` to `sink`, checked against its id,
|
|
339
342
|
* size and hash. On rejection, discard what `sink` received: it is authentic but may be a prefix of
|
|
340
343
|
* the file. A failed check is an `ExportError`; `signal` aborts the download.
|
|
341
344
|
*/
|
|
342
345
|
exportFileTo(app, id, sink, signal) {
|
|
343
|
-
return exportFileTo(this.
|
|
346
|
+
return exportFileTo(this.exportClient, app, id, sink, signal);
|
|
344
347
|
}
|
|
345
348
|
/** The plaintext of sealed file `id` of component app `app`, in memory; use {@link exportFileTo} for a large one. */
|
|
346
349
|
exportFile(app, id, signal) {
|
|
347
|
-
return exportFile(this.
|
|
350
|
+
return exportFile(this.exportClient, app, id, signal);
|
|
348
351
|
}
|
|
349
352
|
/**
|
|
350
353
|
* Download a component app's blob with a grant one of its runs handed out
|
package/dist/client/files.d.ts
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* for this call, and nothing it says is believed until it checks out.
|
|
5
5
|
*/
|
|
6
6
|
import { type Transport } from '../runtime/transport.js';
|
|
7
|
+
import type { AppsRoutes } from '../generated/methods.js';
|
|
7
8
|
export { ExportError, type ExportErrorCode } from '../sealed/file.js';
|
|
8
9
|
/** Where an export writes the plaintext, in order. A `WritableStreamDefaultWriter` fits. */
|
|
9
10
|
export interface FileSink {
|
|
@@ -15,7 +16,7 @@ export interface ExportedFile {
|
|
|
15
16
|
/** SHA-256 of the plaintext, hex. */
|
|
16
17
|
sha256: string;
|
|
17
18
|
}
|
|
18
|
-
type ExportTransport = Pick<Transport, '
|
|
19
|
+
type ExportTransport = Pick<Transport, 'request'> & Pick<AppsRoutes, 'exportsExport'>;
|
|
19
20
|
/**
|
|
20
21
|
* Write the plaintext of sealed file `id` (64 hex) of app `app` to `sink`, one
|
|
21
22
|
* segment at a time. Each segment is checked against its hash before it is
|
package/dist/client/files.js
CHANGED
|
@@ -96,11 +96,7 @@ export async function exportFileTo(transport, app, id, sink, signal, recipientSe
|
|
|
96
96
|
}
|
|
97
97
|
async function exportChecked(transport, app, id, sink, signal, recipientSecret) {
|
|
98
98
|
const recipient = await x25519KeyPair(recipientSecret);
|
|
99
|
-
|
|
100
|
-
const answer = checked(await transport.json('POST', routePath('apps/{app}/files/{id}/export', { app, id }), {
|
|
101
|
-
body: { recipient: hex(recipient.publicKey) },
|
|
102
|
-
signal,
|
|
103
|
-
}));
|
|
99
|
+
const answer = checked(await transport.exportsExport({ app, id, recipient: hex(recipient.publicKey) }, { signal }));
|
|
104
100
|
const { segments, named } = answer;
|
|
105
101
|
if (segments.length === 0 || hex(await fileId(segments)) !== hex(named) || hex(named) !== id) {
|
|
106
102
|
throw new ExportError('NOT_THE_FILE', `the node answered segments that are not the file ${id}`);
|
|
@@ -110,6 +106,7 @@ async function exportChecked(transport, app, id, sink, signal, recipientSecret)
|
|
|
110
106
|
for (let k = 0; k < segments.length; k += 1) {
|
|
111
107
|
if (signal?.aborted)
|
|
112
108
|
throw aborted();
|
|
109
|
+
// The generated segment method buffers the whole body, so this stays on the streaming request.
|
|
113
110
|
const response = await transport.request('GET', routePath('apps/{app}/files/{id}/segments/{k}', { app, id, k }), {
|
|
114
111
|
signal,
|
|
115
112
|
});
|