@calimero-network/mero-js 19.26.0 → 19.27.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.
@@ -1,4 +1,4 @@
1
- export { HANDSHAKE_PATH, SEALED_CONTENT_TYPE, SEALED_PATH, SealedTransportError, StaleTransportKeyError, createSealedFetch, fetchAttestedTransportKey, transportKeyBinding, } from './sealed.js';
2
- export type { SealedFetchOptions, VerifyTransportQuote } from './sealed.js';
1
+ export { HANDSHAKE_PATH, SEALED_CONTENT_TYPE, SEALED_PATH, SealedTransportError, StaleTransportKeyError, createAttestedSealedFetch, createSealedFetch, fetchAttestedTransportKey, transportKeyBinding, } from './sealed.js';
2
+ export type { AttestedSealedFetchOptions, SealedFetchOptions, VerifyTransportQuote } from './sealed.js';
3
3
  export { createQuoteVerifier } from './verify.js';
4
4
  export type { DcapCollateral, DcapVerifiedReport, DcapVerify, QuoteVerifier, QuoteVerifierOptions, } from './verify.js';
@@ -1,2 +1,2 @@
1
- export { HANDSHAKE_PATH, SEALED_CONTENT_TYPE, SEALED_PATH, SealedTransportError, StaleTransportKeyError, createSealedFetch, fetchAttestedTransportKey, transportKeyBinding, } from './sealed.js';
1
+ export { HANDSHAKE_PATH, SEALED_CONTENT_TYPE, SEALED_PATH, SealedTransportError, StaleTransportKeyError, createAttestedSealedFetch, createSealedFetch, fetchAttestedTransportKey, transportKeyBinding, } from './sealed.js';
2
2
  export { createQuoteVerifier } from './verify.js';
@@ -103,6 +103,38 @@ export declare function fetchAttestedTransportKey(admin: {
103
103
  applicationId?: string;
104
104
  applicationHash?: string;
105
105
  }): Promise<Uint8Array>;
106
+ export interface AttestedSealedFetchOptions {
107
+ /** The node's base URL. */
108
+ baseUrl: string;
109
+ /**
110
+ * Decides whether the node's quote is one you trust — typically
111
+ * {@link createQuoteVerifier}. Asked again whenever the node restarts.
112
+ */
113
+ verify: VerifyTransportQuote;
114
+ /** Also require the node to run this application with this bytecode hash. */
115
+ applicationId?: string;
116
+ applicationHash?: string;
117
+ /** Fetch that carries the attestation and the envelopes. Defaults to global `fetch`. */
118
+ fetch?: typeof fetch;
119
+ }
120
+ /**
121
+ * {@link createSealedFetch} for a node you know only by URL: it attests the
122
+ * node's transport key with `verify`, over `POST /admin-api/tee/attest` (the
123
+ * one call that needs no credential and is never sealed), and seals everything
124
+ * else to it. A restarted node is attested again, through the same verifier.
125
+ *
126
+ * This is what to hand a {@link RelayClient} for a TEE relay, so the warrant
127
+ * and the method's arguments reach only the attested TD:
128
+ *
129
+ * ```ts
130
+ * const relay = new RelayClient({
131
+ * relayUrl,
132
+ * fetch: createAttestedSealedFetch({ baseUrl: relayUrl, verify: createQuoteVerifier(...) }),
133
+ * ...
134
+ * });
135
+ * ```
136
+ */
137
+ export declare function createAttestedSealedFetch(options: AttestedSealedFetchOptions): typeof fetch;
106
138
  export interface SealedFetchOptions {
107
139
  /** The node's base URL, as given to `MeroJsConfig.baseUrl`. */
108
140
  baseUrl: string;
@@ -130,6 +130,51 @@ export async function fetchAttestedTransportKey(admin, verify, options = {}) {
130
130
  }
131
131
  return transportKey;
132
132
  }
133
+ /**
134
+ * {@link createSealedFetch} for a node you know only by URL: it attests the
135
+ * node's transport key with `verify`, over `POST /admin-api/tee/attest` (the
136
+ * one call that needs no credential and is never sealed), and seals everything
137
+ * else to it. A restarted node is attested again, through the same verifier.
138
+ *
139
+ * This is what to hand a {@link RelayClient} for a TEE relay, so the warrant
140
+ * and the method's arguments reach only the attested TD:
141
+ *
142
+ * ```ts
143
+ * const relay = new RelayClient({
144
+ * relayUrl,
145
+ * fetch: createAttestedSealedFetch({ baseUrl: relayUrl, verify: createQuoteVerifier(...) }),
146
+ * ...
147
+ * });
148
+ * ```
149
+ */
150
+ export function createAttestedSealedFetch(options) {
151
+ const baseFetch = options.fetch ?? ((input, init) => fetch(input, init));
152
+ const attestUrl = `${options.baseUrl.replace(/\/+$/, '')}/admin-api/tee/attest`;
153
+ const admin = {
154
+ async teeAttest(request) {
155
+ const response = await baseFetch(attestUrl, {
156
+ method: 'POST',
157
+ headers: { 'content-type': 'application/json' },
158
+ body: JSON.stringify(request),
159
+ });
160
+ if (!response.ok) {
161
+ throw new Error(`The node refused to attest: HTTP ${response.status}`);
162
+ }
163
+ const body = (await response.json());
164
+ if (!body.data)
165
+ throw new Error('The attestation response is malformed');
166
+ return body.data;
167
+ },
168
+ };
169
+ return createSealedFetch({
170
+ baseUrl: options.baseUrl,
171
+ transportPublicKey: () => fetchAttestedTransportKey(admin, options.verify, {
172
+ applicationId: options.applicationId,
173
+ applicationHash: options.applicationHash,
174
+ }),
175
+ fetch: baseFetch,
176
+ });
177
+ }
133
178
  /**
134
179
  * A `fetch` that seals every request to the node's attested transport key.
135
180
  * Pass it as `MeroJsConfig.fetch`.
@@ -146,6 +191,10 @@ export function createSealedFetch(options) {
146
191
  let transportKey = attest
147
192
  ? Promise.resolve().then(attest)
148
193
  : Promise.resolve(options.transportPublicKey);
194
+ // Attesting starts now, before any request awaits it. A node that fails to
195
+ // attest must surface on the request that needed the key, not earlier as an
196
+ // unhandled rejection; the failure is still thrown to every awaiter.
197
+ transportKey.catch(() => undefined);
149
198
  let session;
150
199
  const openSession = async () => {
151
200
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@calimero-network/mero-js",
3
- "version": "19.26.0",
3
+ "version": "19.27.0",
4
4
  "description": "Pure JavaScript SDK for Calimero",
5
5
  "type": "module",
6
6
  "exports": {