@tinycloud/sdk-services 3.7.0-beta.3 → 3.7.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,332 +1,9 @@
1
1
  import { B as BaseService } from '../BaseService-D-29xShG.cjs';
2
- import { P as PermissionHint, c as IService, h as Result } from '../types-DAOyIbXu.cjs';
2
+ import { c as IService, h as Result } from '../types-DAOyIbXu.cjs';
3
+ import { N as NetworkDescriptor, n as EncryptionError, I as InlineEncryptedEnvelope, D as DecryptCapabilityProof, j as DecryptResponseBody, E as EncryptionCrypto, h as DecryptInvocationSigner, p as ReceiverKeySigner, R as ReceiverKeyPair, i as DecryptRequestBody, g as DecryptInvocationFact, B as BuildDecryptInvocationInput, a as BuiltDecryptInvocation } from '../types-B_rbS4XE.cjs';
4
+ export { C as CanonicalJson, b as DECRYPT_ACTION, c as DECRYPT_FACT_TYPE, d as DECRYPT_RESULT_TYPE, e as DEFAULT_ENCRYPTION_ALG, f as DEFAULT_KEY_VERSION, k as ENCRYPTION_SERVICE, l as ENCRYPTION_SERVICE_SHORT, m as ENVELOPE_VERSION, o as EncryptionErrorInput, J as Json, q as base64Decode, r as base64Encode, s as canonicalHashHex, t as canonicalize, u as encryptionError, v as hexDecode, w as hexEncode, x as utf8Decode, y as utf8Encode } from '../types-B_rbS4XE.cjs';
3
5
  export { DecryptTransportResponseError } from '@tinycloud/sdk-services/internal/decrypt-transport-response-error';
4
6
 
5
- /**
6
- * Canonical JSON serialization and content hashing for TinyCloud
7
- * encryption requests/responses.
8
- *
9
- * The node and SDK must agree byte-for-byte on the canonical form so
10
- * that body-hash bindings (`bodyHash`, `encryptedSymmetricKeyHash`,
11
- * `receiverPublicKeyHash`) verify on both sides.
12
- *
13
- * Canonical rules:
14
- * - Object keys are sorted lexicographically by code point.
15
- * - Strings are encoded with the JSON.stringify default (RFC 8259).
16
- * - Numbers are emitted via JSON.stringify; callers should restrict to
17
- * integers or use string fields for high-precision values.
18
- * - `undefined` properties are dropped. `null` is preserved.
19
- * - Arrays preserve element order.
20
- *
21
- * Hashing uses SHA-256 supplied by the caller (via an `EncryptionCrypto`
22
- * binding) so this module stays platform-agnostic.
23
- */
24
- type Json = null | boolean | number | string | Json[] | {
25
- [key: string]: Json | undefined;
26
- };
27
- /**
28
- * Produce the canonical JSON string for {@link value}. Object keys are
29
- * sorted, `undefined` properties are dropped, and primitive types are
30
- * encoded by `JSON.stringify`.
31
- */
32
- declare function canonicalize(value: Json | undefined): string;
33
- declare function hexEncode(bytes: Uint8Array): string;
34
- declare function hexDecode(hex: string): Uint8Array;
35
- declare function base64Encode(bytes: Uint8Array): string;
36
- declare function base64Decode(s: string): Uint8Array;
37
- declare function utf8Encode(s: string): Uint8Array;
38
- declare function utf8Decode(b: Uint8Array): string;
39
- /**
40
- * Compute `hexEncode(sha256(canonicalize(value)))`. The SHA-256 binding
41
- * is injected so the module remains usable in both the WASM and pure-JS
42
- * paths.
43
- */
44
- declare function canonicalHashHex(sha256: (bytes: Uint8Array) => Uint8Array, value: Json): string;
45
-
46
- /**
47
- * Type definitions for TinyCloud one-of-one encryption.
48
- *
49
- * Wire shapes mirror the protocol described in the encryption
50
- * architecture: inline envelopes carry the encrypted symmetric key
51
- * alongside the ciphertext; decrypt requests are short-lived UCAN
52
- * invocations against a target node plus networkId.
53
- */
54
-
55
- /** Default ciphersuite identifier for v1 envelopes. */
56
- declare const DEFAULT_ENCRYPTION_ALG: "x25519-aes256gcm/v1";
57
- /** Inline-envelope schema version. */
58
- declare const ENVELOPE_VERSION: 1;
59
- /** Default key version on freshly-created networks. */
60
- declare const DEFAULT_KEY_VERSION: 1;
61
- /** Decrypt-invocation fact type. */
62
- declare const DECRYPT_FACT_TYPE: "tinycloud.encryption.decrypt/v1";
63
- /** Decrypt response type. */
64
- declare const DECRYPT_RESULT_TYPE: "tinycloud.encryption.decrypt-result/v1";
65
- /** Encryption service identifier (manifest long form). */
66
- declare const ENCRYPTION_SERVICE: "tinycloud.encryption";
67
- /** Short form used in recap/abilities maps. */
68
- declare const ENCRYPTION_SERVICE_SHORT: "encryption";
69
- /** Decrypt ability URN. */
70
- declare const DECRYPT_ACTION: "tinycloud.encryption/decrypt";
71
- /**
72
- * Inline encrypted envelope persisted in KV/SQL records.
73
- *
74
- * - `encryptedSymmetricKey` is opaque to the SDK; only the network can
75
- * unwrap it.
76
- * - `encryptedSymmetricKeyHash` is the canonical hash of the wrapped key
77
- * bytes (hex-encoded sha-256 of the base64 string's canonical JSON
78
- * form). The node recomputes this on every decrypt request.
79
- * - `ciphertext` and `aad` are payload bytes only; the node never sees
80
- * them.
81
- */
82
- interface InlineEncryptedEnvelope {
83
- /** Schema version. */
84
- v: typeof ENVELOPE_VERSION;
85
- /** Network id URN. */
86
- networkId: string;
87
- /** Ciphersuite identifier. */
88
- alg: string;
89
- /** Network key version that was used to wrap the symmetric key. */
90
- keyVersion: number;
91
- /** Base64-encoded wrapped symmetric key / capsule. */
92
- encryptedSymmetricKey: string;
93
- /** Hex sha-256 of the canonical encryptedSymmetricKey string. */
94
- encryptedSymmetricKeyHash: string;
95
- /** Base64-encoded payload ciphertext. */
96
- ciphertext: string;
97
- /** Base64-encoded associated data, if any. */
98
- aad?: string;
99
- /** Caller-supplied metadata. Not authenticated against the node. */
100
- metadata?: Record<string, string>;
101
- }
102
- /**
103
- * Node-published network descriptor. The node DB is authoritative; a
104
- * cached copy may also live under
105
- * `.well-known/encryption/network/<name>` in the owner's account
106
- * space (a discovery record only).
107
- */
108
- interface NetworkDescriptor {
109
- networkId: string;
110
- ownerDid: string;
111
- name: string;
112
- members: ReadonlyArray<{
113
- nodeId: string;
114
- role: "primary" | "share";
115
- }>;
116
- threshold: {
117
- n: number;
118
- t: number;
119
- };
120
- state: "pending" | "generating" | "active" | "rotating" | "revoked" | "failed";
121
- /** Base64-encoded network public key. */
122
- publicEncryptionKey: string;
123
- alg: string;
124
- keyVersion: number;
125
- keyBackend: "local-one-of-one" | "dstack" | "threshold";
126
- createdAt: string;
127
- updatedAt: string;
128
- }
129
- /**
130
- * Decrypt-request body sent over the wire. Hashed (canonically) and
131
- * bound to the UCAN invocation via `facts.bodyHash`.
132
- */
133
- interface DecryptRequestBody {
134
- type: typeof DECRYPT_FACT_TYPE;
135
- targetNode: string;
136
- networkId: string;
137
- alg: string;
138
- keyVersion: number;
139
- /** Base64-encoded wrapped symmetric key from the envelope. */
140
- encryptedSymmetricKey: string;
141
- /** Recomputed hash of the wrapped key. */
142
- encryptedSymmetricKeyHash: string;
143
- /** Base64-encoded per-request receiver public key. */
144
- receiverPublicKey: string;
145
- /** Hash of the receiver public key. */
146
- receiverPublicKeyHash: string;
147
- }
148
- /**
149
- * Decrypt-response body returned by the node. The SDK verifies the
150
- * signature, recomputes hashes, then unwraps `wrappedKey` with the
151
- * per-request receiver private key before decrypting the payload.
152
- */
153
- interface DecryptResponseBody {
154
- type: typeof DECRYPT_RESULT_TYPE;
155
- targetNode: string;
156
- networkId: string;
157
- invocationCid: string;
158
- encryptedSymmetricKeyHash: string;
159
- receiverPublicKeyHash: string;
160
- /** Base64-encoded symmetric key re-encrypted to receiverPublicKey. */
161
- wrappedKey: string;
162
- alg: string;
163
- keyVersion: number;
164
- requestHash: string;
165
- nodeId: string;
166
- /** Base64-encoded ed25519 signature over canonical(response - signature field). */
167
- nodeSignature: string;
168
- }
169
- /**
170
- * Decrypt-invocation facts attached to the UCAN. Verifiers recompute
171
- * `bodyHash`, `encryptedSymmetricKeyHash`, and `receiverPublicKeyHash`
172
- * from the request body and reject any mismatch.
173
- */
174
- interface DecryptInvocationFact {
175
- type: typeof DECRYPT_FACT_TYPE;
176
- targetNode: string;
177
- networkId: string;
178
- bodyHash: string;
179
- encryptedSymmetricKeyHash: string;
180
- receiverPublicKeyHash: string;
181
- alg: string;
182
- keyVersion: number;
183
- }
184
- /**
185
- * Per-request receiver key pair (x25519). The private key never
186
- * leaves the SDK; the public key is sent to the node so the node can
187
- * rewrap the symmetric key.
188
- */
189
- interface ReceiverKeyPair {
190
- publicKey: Uint8Array;
191
- privateKey: Uint8Array;
192
- }
193
- /**
194
- * Crypto primitives injected into the encryption module. The SDK
195
- * provides these via WASM bindings; tests provide simple in-memory
196
- * implementations.
197
- */
198
- interface EncryptionCrypto {
199
- /** SHA-256 → 32-byte digest. */
200
- sha256(data: Uint8Array): Uint8Array;
201
- /** Cryptographically secure random bytes. */
202
- randomBytes(length: number): Uint8Array;
203
- /** Derive an x25519 key pair from a 32-byte seed. */
204
- x25519FromSeed(seed: Uint8Array): ReceiverKeyPair;
205
- /** Compute the x25519 ECDH shared secret. */
206
- x25519Dh(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
207
- /** Authenticated symmetric encryption (the node's symmetric scheme). */
208
- authEncrypt(key: Uint8Array, plaintext: Uint8Array, aad?: Uint8Array): Uint8Array;
209
- /** Authenticated symmetric decryption (matched to authEncrypt). */
210
- authDecrypt(key: Uint8Array, ciphertext: Uint8Array, aad?: Uint8Array): Uint8Array;
211
- /**
212
- * Wrap a symmetric key for the network's public encryption key using
213
- * a sealed-box / hpke / x25519+symmetric construction. Implementation
214
- * is opaque; only the node can unwrap.
215
- */
216
- sealToNetworkKey(networkPublicKey: Uint8Array, symmetricKey: Uint8Array): Uint8Array;
217
- /**
218
- * Open a wrapped symmetric key that was re-encrypted to the
219
- * per-request receiver public key. The matching private key must be
220
- * supplied here; the SDK never sends it to the node.
221
- */
222
- openWithReceiverKey(receiverPrivateKey: Uint8Array, wrappedKey: Uint8Array): Uint8Array;
223
- /**
224
- * Verify an ed25519 signature over `message` produced by the node
225
- * identified by `nodeId` (the public-key DID).
226
- */
227
- verifyNodeSignature(nodeId: string, message: Uint8Array, signature: Uint8Array): boolean;
228
- }
229
- /**
230
- * Signer interface used to derive a receiver key pair from a wallet or
231
- * session signer. The signature is HKDF-extracted into the receiver
232
- * seed so the public key is reproducible given the same context.
233
- */
234
- interface ReceiverKeySigner {
235
- signMessage(message: string): Promise<string>;
236
- }
237
- /** Capability proof material accompanying a decrypt invocation. */
238
- interface DecryptCapabilityProof {
239
- /** Delegation chain CIDs rooted at the network owner DID. */
240
- proofs: ReadonlyArray<string>;
241
- /** Optional Authorization header value to use instead of building one. */
242
- authorization?: string;
243
- }
244
- /**
245
- * Inputs to the decrypt invocation builder.
246
- */
247
- interface BuildDecryptInvocationInput {
248
- /** Target node DID — also the UCAN audience. */
249
- targetNode: string;
250
- /** Network id URN — also the recap resource. */
251
- networkId: string;
252
- /** Canonical body that will be POSTed. */
253
- body: DecryptRequestBody;
254
- /** Facts include hashes bound to the canonical body. */
255
- facts: DecryptInvocationFact;
256
- /** Capability proof chain. */
257
- proof: DecryptCapabilityProof;
258
- /** Optional `nbf` UCAN field as an ISO date string. */
259
- notBefore?: string;
260
- /** Optional `exp` UCAN field as an ISO date string. */
261
- expiration?: string;
262
- }
263
- /**
264
- * The output of {@link buildDecryptInvocation}.
265
- */
266
- interface BuiltDecryptInvocation {
267
- /** HTTP `Authorization` header value. */
268
- authorization: string;
269
- /** CID of the invocation (used by the node response binding). */
270
- invocationCid: string;
271
- /** Canonical body string the node will hash. */
272
- canonicalBody: string;
273
- }
274
- /**
275
- * Signer interface for producing the decrypt invocation. WASM bindings
276
- * implement this with the same session signer used for KV/SQL
277
- * invocations; tests can stub it.
278
- */
279
- interface DecryptInvocationSigner {
280
- signDecryptInvocation(input: BuildDecryptInvocationInput): Promise<BuiltDecryptInvocation>;
281
- }
282
- /**
283
- * Errors thrown / returned from the encryption module.
284
- */
285
- type EncryptionErrorInput = {
286
- code: "NETWORK_NOT_FOUND";
287
- networkId?: string;
288
- name?: string;
289
- message?: string;
290
- } | {
291
- code: "NETWORK_NOT_ACTIVE";
292
- state: string;
293
- message?: string;
294
- } | {
295
- code: "INVALID_NETWORK_ID";
296
- message: string;
297
- } | {
298
- code: "INVALID_ENVELOPE";
299
- message: string;
300
- } | {
301
- code: "DECRYPT_DENIED";
302
- message: string;
303
- permissionHint?: PermissionHint;
304
- } | {
305
- code: "INVALID_RESPONSE";
306
- message: string;
307
- } | {
308
- code: "RESPONSE_SIGNATURE_INVALID";
309
- message?: string;
310
- } | {
311
- code: "RESPONSE_BINDING_MISMATCH";
312
- field: string;
313
- message?: string;
314
- } | {
315
- code: "TRANSPORT_ERROR";
316
- cause: Error;
317
- message?: string;
318
- } | {
319
- code: "INVALID_INPUT";
320
- message: string;
321
- };
322
- type EncryptionError = EncryptionErrorInput & {
323
- service: "encryption";
324
- message: string;
325
- };
326
- declare function encryptionError(input: EncryptionErrorInput): EncryptionError;
327
- /** Re-export for ergonomic typing of canonical payloads. */
328
- type CanonicalJson = Json;
329
-
330
7
  /**
331
8
  * Network-descriptor discovery.
332
9
  *
@@ -807,4 +484,4 @@ declare function verifyDecryptResponse(input: VerifyDecryptResponseInput): {
807
484
  */
808
485
  declare function openWrappedKey(crypto: EncryptionCrypto, receiverPrivateKey: Uint8Array, response: DecryptResponseBody): Uint8Array;
809
486
 
810
- export { type BuildCanonicalDecryptRequestInput, type BuildDecryptFactsInput, type BuildDecryptInvocationInput, type BuiltDecryptInvocation, type CanonicalDecryptRequest, type CanonicalJson, DECRYPT_ACTION, DECRYPT_FACT_TYPE, DECRYPT_RESULT_TYPE, DEFAULT_ENCRYPTION_ALG, DEFAULT_KEY_VERSION, type DecryptCapabilityProof, type DecryptEnvelopeOptions, type DecryptInvocationFact, type DecryptInvocationSigner, type DecryptRequestBody, type DecryptResponseBody, type DecryptTransport, type DiscoverNetworkInput, type DiscoveredNetwork, type DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, ENCRYPTION_SERVICE, ENCRYPTION_SERVICE_SHORT, ENVELOPE_VERSION, type EncryptToNetworkInput, type EncryptToNetworkOptions, type EncryptToNetworkResult, type EncryptionCrypto, type EncryptionError, type EncryptionErrorInput, EncryptionService, type EncryptionServiceConfig, type IEncryptionService, type InlineEncryptedEnvelope, type Json, NETWORK_NAME_PATTERN, type NetworkDescriptor, NetworkIdError, type NodeDescriptorFetcher, type ParsedNetworkId, type RandomReceiverKeyInput, type ReceiverKeyPair, type ReceiverKeySigner, type SignedReceiverKeyInput, type VerifyDecryptResponseInput, type WellKnownDescriptorFetcher, base64Decode, base64Encode, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalHashHex, canonicalSignedResponse, canonicalize, checkDecryptInvocationInput, decryptEnvelopeWithKey, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, encryptionError, ensureNetworkUsableForDecrypt, generateRandomReceiverKey, hexDecode, hexEncode, isNetworkId, networkDiscoveryKey, openWrappedKey, parseNetworkId, utf8Decode, utf8Encode, validateEnvelope, verifyDecryptResponse };
487
+ export { type BuildCanonicalDecryptRequestInput, type BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, type CanonicalDecryptRequest, DecryptCapabilityProof, type DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, type DecryptTransport, type DiscoverNetworkInput, type DiscoveredNetwork, type DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, type EncryptToNetworkInput, type EncryptToNetworkOptions, type EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionService, type EncryptionServiceConfig, type IEncryptionService, InlineEncryptedEnvelope, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, type NodeDescriptorFetcher, type ParsedNetworkId, type RandomReceiverKeyInput, ReceiverKeyPair, ReceiverKeySigner, type SignedReceiverKeyInput, type VerifyDecryptResponseInput, type WellKnownDescriptorFetcher, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalSignedResponse, checkDecryptInvocationInput, decryptEnvelopeWithKey, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, ensureNetworkUsableForDecrypt, generateRandomReceiverKey, isNetworkId, networkDiscoveryKey, openWrappedKey, parseNetworkId, validateEnvelope, verifyDecryptResponse };
@@ -1,332 +1,9 @@
1
1
  import { B as BaseService } from '../BaseService-DO7vZ67k.js';
2
- import { P as PermissionHint, c as IService, h as Result } from '../types-DAOyIbXu.js';
2
+ import { c as IService, h as Result } from '../types-DAOyIbXu.js';
3
+ import { N as NetworkDescriptor, n as EncryptionError, I as InlineEncryptedEnvelope, D as DecryptCapabilityProof, j as DecryptResponseBody, E as EncryptionCrypto, h as DecryptInvocationSigner, p as ReceiverKeySigner, R as ReceiverKeyPair, i as DecryptRequestBody, g as DecryptInvocationFact, B as BuildDecryptInvocationInput, a as BuiltDecryptInvocation } from '../types-BGRzS1ob.js';
4
+ export { C as CanonicalJson, b as DECRYPT_ACTION, c as DECRYPT_FACT_TYPE, d as DECRYPT_RESULT_TYPE, e as DEFAULT_ENCRYPTION_ALG, f as DEFAULT_KEY_VERSION, k as ENCRYPTION_SERVICE, l as ENCRYPTION_SERVICE_SHORT, m as ENVELOPE_VERSION, o as EncryptionErrorInput, J as Json, q as base64Decode, r as base64Encode, s as canonicalHashHex, t as canonicalize, u as encryptionError, v as hexDecode, w as hexEncode, x as utf8Decode, y as utf8Encode } from '../types-BGRzS1ob.js';
3
5
  export { DecryptTransportResponseError } from '@tinycloud/sdk-services/internal/decrypt-transport-response-error';
4
6
 
5
- /**
6
- * Canonical JSON serialization and content hashing for TinyCloud
7
- * encryption requests/responses.
8
- *
9
- * The node and SDK must agree byte-for-byte on the canonical form so
10
- * that body-hash bindings (`bodyHash`, `encryptedSymmetricKeyHash`,
11
- * `receiverPublicKeyHash`) verify on both sides.
12
- *
13
- * Canonical rules:
14
- * - Object keys are sorted lexicographically by code point.
15
- * - Strings are encoded with the JSON.stringify default (RFC 8259).
16
- * - Numbers are emitted via JSON.stringify; callers should restrict to
17
- * integers or use string fields for high-precision values.
18
- * - `undefined` properties are dropped. `null` is preserved.
19
- * - Arrays preserve element order.
20
- *
21
- * Hashing uses SHA-256 supplied by the caller (via an `EncryptionCrypto`
22
- * binding) so this module stays platform-agnostic.
23
- */
24
- type Json = null | boolean | number | string | Json[] | {
25
- [key: string]: Json | undefined;
26
- };
27
- /**
28
- * Produce the canonical JSON string for {@link value}. Object keys are
29
- * sorted, `undefined` properties are dropped, and primitive types are
30
- * encoded by `JSON.stringify`.
31
- */
32
- declare function canonicalize(value: Json | undefined): string;
33
- declare function hexEncode(bytes: Uint8Array): string;
34
- declare function hexDecode(hex: string): Uint8Array;
35
- declare function base64Encode(bytes: Uint8Array): string;
36
- declare function base64Decode(s: string): Uint8Array;
37
- declare function utf8Encode(s: string): Uint8Array;
38
- declare function utf8Decode(b: Uint8Array): string;
39
- /**
40
- * Compute `hexEncode(sha256(canonicalize(value)))`. The SHA-256 binding
41
- * is injected so the module remains usable in both the WASM and pure-JS
42
- * paths.
43
- */
44
- declare function canonicalHashHex(sha256: (bytes: Uint8Array) => Uint8Array, value: Json): string;
45
-
46
- /**
47
- * Type definitions for TinyCloud one-of-one encryption.
48
- *
49
- * Wire shapes mirror the protocol described in the encryption
50
- * architecture: inline envelopes carry the encrypted symmetric key
51
- * alongside the ciphertext; decrypt requests are short-lived UCAN
52
- * invocations against a target node plus networkId.
53
- */
54
-
55
- /** Default ciphersuite identifier for v1 envelopes. */
56
- declare const DEFAULT_ENCRYPTION_ALG: "x25519-aes256gcm/v1";
57
- /** Inline-envelope schema version. */
58
- declare const ENVELOPE_VERSION: 1;
59
- /** Default key version on freshly-created networks. */
60
- declare const DEFAULT_KEY_VERSION: 1;
61
- /** Decrypt-invocation fact type. */
62
- declare const DECRYPT_FACT_TYPE: "tinycloud.encryption.decrypt/v1";
63
- /** Decrypt response type. */
64
- declare const DECRYPT_RESULT_TYPE: "tinycloud.encryption.decrypt-result/v1";
65
- /** Encryption service identifier (manifest long form). */
66
- declare const ENCRYPTION_SERVICE: "tinycloud.encryption";
67
- /** Short form used in recap/abilities maps. */
68
- declare const ENCRYPTION_SERVICE_SHORT: "encryption";
69
- /** Decrypt ability URN. */
70
- declare const DECRYPT_ACTION: "tinycloud.encryption/decrypt";
71
- /**
72
- * Inline encrypted envelope persisted in KV/SQL records.
73
- *
74
- * - `encryptedSymmetricKey` is opaque to the SDK; only the network can
75
- * unwrap it.
76
- * - `encryptedSymmetricKeyHash` is the canonical hash of the wrapped key
77
- * bytes (hex-encoded sha-256 of the base64 string's canonical JSON
78
- * form). The node recomputes this on every decrypt request.
79
- * - `ciphertext` and `aad` are payload bytes only; the node never sees
80
- * them.
81
- */
82
- interface InlineEncryptedEnvelope {
83
- /** Schema version. */
84
- v: typeof ENVELOPE_VERSION;
85
- /** Network id URN. */
86
- networkId: string;
87
- /** Ciphersuite identifier. */
88
- alg: string;
89
- /** Network key version that was used to wrap the symmetric key. */
90
- keyVersion: number;
91
- /** Base64-encoded wrapped symmetric key / capsule. */
92
- encryptedSymmetricKey: string;
93
- /** Hex sha-256 of the canonical encryptedSymmetricKey string. */
94
- encryptedSymmetricKeyHash: string;
95
- /** Base64-encoded payload ciphertext. */
96
- ciphertext: string;
97
- /** Base64-encoded associated data, if any. */
98
- aad?: string;
99
- /** Caller-supplied metadata. Not authenticated against the node. */
100
- metadata?: Record<string, string>;
101
- }
102
- /**
103
- * Node-published network descriptor. The node DB is authoritative; a
104
- * cached copy may also live under
105
- * `.well-known/encryption/network/<name>` in the owner's account
106
- * space (a discovery record only).
107
- */
108
- interface NetworkDescriptor {
109
- networkId: string;
110
- ownerDid: string;
111
- name: string;
112
- members: ReadonlyArray<{
113
- nodeId: string;
114
- role: "primary" | "share";
115
- }>;
116
- threshold: {
117
- n: number;
118
- t: number;
119
- };
120
- state: "pending" | "generating" | "active" | "rotating" | "revoked" | "failed";
121
- /** Base64-encoded network public key. */
122
- publicEncryptionKey: string;
123
- alg: string;
124
- keyVersion: number;
125
- keyBackend: "local-one-of-one" | "dstack" | "threshold";
126
- createdAt: string;
127
- updatedAt: string;
128
- }
129
- /**
130
- * Decrypt-request body sent over the wire. Hashed (canonically) and
131
- * bound to the UCAN invocation via `facts.bodyHash`.
132
- */
133
- interface DecryptRequestBody {
134
- type: typeof DECRYPT_FACT_TYPE;
135
- targetNode: string;
136
- networkId: string;
137
- alg: string;
138
- keyVersion: number;
139
- /** Base64-encoded wrapped symmetric key from the envelope. */
140
- encryptedSymmetricKey: string;
141
- /** Recomputed hash of the wrapped key. */
142
- encryptedSymmetricKeyHash: string;
143
- /** Base64-encoded per-request receiver public key. */
144
- receiverPublicKey: string;
145
- /** Hash of the receiver public key. */
146
- receiverPublicKeyHash: string;
147
- }
148
- /**
149
- * Decrypt-response body returned by the node. The SDK verifies the
150
- * signature, recomputes hashes, then unwraps `wrappedKey` with the
151
- * per-request receiver private key before decrypting the payload.
152
- */
153
- interface DecryptResponseBody {
154
- type: typeof DECRYPT_RESULT_TYPE;
155
- targetNode: string;
156
- networkId: string;
157
- invocationCid: string;
158
- encryptedSymmetricKeyHash: string;
159
- receiverPublicKeyHash: string;
160
- /** Base64-encoded symmetric key re-encrypted to receiverPublicKey. */
161
- wrappedKey: string;
162
- alg: string;
163
- keyVersion: number;
164
- requestHash: string;
165
- nodeId: string;
166
- /** Base64-encoded ed25519 signature over canonical(response - signature field). */
167
- nodeSignature: string;
168
- }
169
- /**
170
- * Decrypt-invocation facts attached to the UCAN. Verifiers recompute
171
- * `bodyHash`, `encryptedSymmetricKeyHash`, and `receiverPublicKeyHash`
172
- * from the request body and reject any mismatch.
173
- */
174
- interface DecryptInvocationFact {
175
- type: typeof DECRYPT_FACT_TYPE;
176
- targetNode: string;
177
- networkId: string;
178
- bodyHash: string;
179
- encryptedSymmetricKeyHash: string;
180
- receiverPublicKeyHash: string;
181
- alg: string;
182
- keyVersion: number;
183
- }
184
- /**
185
- * Per-request receiver key pair (x25519). The private key never
186
- * leaves the SDK; the public key is sent to the node so the node can
187
- * rewrap the symmetric key.
188
- */
189
- interface ReceiverKeyPair {
190
- publicKey: Uint8Array;
191
- privateKey: Uint8Array;
192
- }
193
- /**
194
- * Crypto primitives injected into the encryption module. The SDK
195
- * provides these via WASM bindings; tests provide simple in-memory
196
- * implementations.
197
- */
198
- interface EncryptionCrypto {
199
- /** SHA-256 → 32-byte digest. */
200
- sha256(data: Uint8Array): Uint8Array;
201
- /** Cryptographically secure random bytes. */
202
- randomBytes(length: number): Uint8Array;
203
- /** Derive an x25519 key pair from a 32-byte seed. */
204
- x25519FromSeed(seed: Uint8Array): ReceiverKeyPair;
205
- /** Compute the x25519 ECDH shared secret. */
206
- x25519Dh(privateKey: Uint8Array, publicKey: Uint8Array): Uint8Array;
207
- /** Authenticated symmetric encryption (the node's symmetric scheme). */
208
- authEncrypt(key: Uint8Array, plaintext: Uint8Array, aad?: Uint8Array): Uint8Array;
209
- /** Authenticated symmetric decryption (matched to authEncrypt). */
210
- authDecrypt(key: Uint8Array, ciphertext: Uint8Array, aad?: Uint8Array): Uint8Array;
211
- /**
212
- * Wrap a symmetric key for the network's public encryption key using
213
- * a sealed-box / hpke / x25519+symmetric construction. Implementation
214
- * is opaque; only the node can unwrap.
215
- */
216
- sealToNetworkKey(networkPublicKey: Uint8Array, symmetricKey: Uint8Array): Uint8Array;
217
- /**
218
- * Open a wrapped symmetric key that was re-encrypted to the
219
- * per-request receiver public key. The matching private key must be
220
- * supplied here; the SDK never sends it to the node.
221
- */
222
- openWithReceiverKey(receiverPrivateKey: Uint8Array, wrappedKey: Uint8Array): Uint8Array;
223
- /**
224
- * Verify an ed25519 signature over `message` produced by the node
225
- * identified by `nodeId` (the public-key DID).
226
- */
227
- verifyNodeSignature(nodeId: string, message: Uint8Array, signature: Uint8Array): boolean;
228
- }
229
- /**
230
- * Signer interface used to derive a receiver key pair from a wallet or
231
- * session signer. The signature is HKDF-extracted into the receiver
232
- * seed so the public key is reproducible given the same context.
233
- */
234
- interface ReceiverKeySigner {
235
- signMessage(message: string): Promise<string>;
236
- }
237
- /** Capability proof material accompanying a decrypt invocation. */
238
- interface DecryptCapabilityProof {
239
- /** Delegation chain CIDs rooted at the network owner DID. */
240
- proofs: ReadonlyArray<string>;
241
- /** Optional Authorization header value to use instead of building one. */
242
- authorization?: string;
243
- }
244
- /**
245
- * Inputs to the decrypt invocation builder.
246
- */
247
- interface BuildDecryptInvocationInput {
248
- /** Target node DID — also the UCAN audience. */
249
- targetNode: string;
250
- /** Network id URN — also the recap resource. */
251
- networkId: string;
252
- /** Canonical body that will be POSTed. */
253
- body: DecryptRequestBody;
254
- /** Facts include hashes bound to the canonical body. */
255
- facts: DecryptInvocationFact;
256
- /** Capability proof chain. */
257
- proof: DecryptCapabilityProof;
258
- /** Optional `nbf` UCAN field as an ISO date string. */
259
- notBefore?: string;
260
- /** Optional `exp` UCAN field as an ISO date string. */
261
- expiration?: string;
262
- }
263
- /**
264
- * The output of {@link buildDecryptInvocation}.
265
- */
266
- interface BuiltDecryptInvocation {
267
- /** HTTP `Authorization` header value. */
268
- authorization: string;
269
- /** CID of the invocation (used by the node response binding). */
270
- invocationCid: string;
271
- /** Canonical body string the node will hash. */
272
- canonicalBody: string;
273
- }
274
- /**
275
- * Signer interface for producing the decrypt invocation. WASM bindings
276
- * implement this with the same session signer used for KV/SQL
277
- * invocations; tests can stub it.
278
- */
279
- interface DecryptInvocationSigner {
280
- signDecryptInvocation(input: BuildDecryptInvocationInput): Promise<BuiltDecryptInvocation>;
281
- }
282
- /**
283
- * Errors thrown / returned from the encryption module.
284
- */
285
- type EncryptionErrorInput = {
286
- code: "NETWORK_NOT_FOUND";
287
- networkId?: string;
288
- name?: string;
289
- message?: string;
290
- } | {
291
- code: "NETWORK_NOT_ACTIVE";
292
- state: string;
293
- message?: string;
294
- } | {
295
- code: "INVALID_NETWORK_ID";
296
- message: string;
297
- } | {
298
- code: "INVALID_ENVELOPE";
299
- message: string;
300
- } | {
301
- code: "DECRYPT_DENIED";
302
- message: string;
303
- permissionHint?: PermissionHint;
304
- } | {
305
- code: "INVALID_RESPONSE";
306
- message: string;
307
- } | {
308
- code: "RESPONSE_SIGNATURE_INVALID";
309
- message?: string;
310
- } | {
311
- code: "RESPONSE_BINDING_MISMATCH";
312
- field: string;
313
- message?: string;
314
- } | {
315
- code: "TRANSPORT_ERROR";
316
- cause: Error;
317
- message?: string;
318
- } | {
319
- code: "INVALID_INPUT";
320
- message: string;
321
- };
322
- type EncryptionError = EncryptionErrorInput & {
323
- service: "encryption";
324
- message: string;
325
- };
326
- declare function encryptionError(input: EncryptionErrorInput): EncryptionError;
327
- /** Re-export for ergonomic typing of canonical payloads. */
328
- type CanonicalJson = Json;
329
-
330
7
  /**
331
8
  * Network-descriptor discovery.
332
9
  *
@@ -807,4 +484,4 @@ declare function verifyDecryptResponse(input: VerifyDecryptResponseInput): {
807
484
  */
808
485
  declare function openWrappedKey(crypto: EncryptionCrypto, receiverPrivateKey: Uint8Array, response: DecryptResponseBody): Uint8Array;
809
486
 
810
- export { type BuildCanonicalDecryptRequestInput, type BuildDecryptFactsInput, type BuildDecryptInvocationInput, type BuiltDecryptInvocation, type CanonicalDecryptRequest, type CanonicalJson, DECRYPT_ACTION, DECRYPT_FACT_TYPE, DECRYPT_RESULT_TYPE, DEFAULT_ENCRYPTION_ALG, DEFAULT_KEY_VERSION, type DecryptCapabilityProof, type DecryptEnvelopeOptions, type DecryptInvocationFact, type DecryptInvocationSigner, type DecryptRequestBody, type DecryptResponseBody, type DecryptTransport, type DiscoverNetworkInput, type DiscoveredNetwork, type DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, ENCRYPTION_SERVICE, ENCRYPTION_SERVICE_SHORT, ENVELOPE_VERSION, type EncryptToNetworkInput, type EncryptToNetworkOptions, type EncryptToNetworkResult, type EncryptionCrypto, type EncryptionError, type EncryptionErrorInput, EncryptionService, type EncryptionServiceConfig, type IEncryptionService, type InlineEncryptedEnvelope, type Json, NETWORK_NAME_PATTERN, type NetworkDescriptor, NetworkIdError, type NodeDescriptorFetcher, type ParsedNetworkId, type RandomReceiverKeyInput, type ReceiverKeyPair, type ReceiverKeySigner, type SignedReceiverKeyInput, type VerifyDecryptResponseInput, type WellKnownDescriptorFetcher, base64Decode, base64Encode, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalHashHex, canonicalSignedResponse, canonicalize, checkDecryptInvocationInput, decryptEnvelopeWithKey, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, encryptionError, ensureNetworkUsableForDecrypt, generateRandomReceiverKey, hexDecode, hexEncode, isNetworkId, networkDiscoveryKey, openWrappedKey, parseNetworkId, utf8Decode, utf8Encode, validateEnvelope, verifyDecryptResponse };
487
+ export { type BuildCanonicalDecryptRequestInput, type BuildDecryptFactsInput, BuildDecryptInvocationInput, BuiltDecryptInvocation, type CanonicalDecryptRequest, DecryptCapabilityProof, type DecryptEnvelopeOptions, DecryptInvocationFact, DecryptInvocationSigner, DecryptRequestBody, DecryptResponseBody, type DecryptTransport, type DiscoverNetworkInput, type DiscoveredNetwork, type DiscoverySource, ENCRYPTION_NETWORK_URN_PREFIX, type EncryptToNetworkInput, type EncryptToNetworkOptions, type EncryptToNetworkResult, EncryptionCrypto, EncryptionError, EncryptionService, type EncryptionServiceConfig, type IEncryptionService, InlineEncryptedEnvelope, NETWORK_NAME_PATTERN, NetworkDescriptor, NetworkIdError, type NodeDescriptorFetcher, type ParsedNetworkId, type RandomReceiverKeyInput, ReceiverKeyPair, ReceiverKeySigner, type SignedReceiverKeyInput, type VerifyDecryptResponseInput, type WellKnownDescriptorFetcher, buildCanonicalDecryptRequest, buildDecryptAttenuation, buildDecryptFacts, buildDecryptInvocation, buildNetworkId, canonicalSignedResponse, checkDecryptInvocationInput, decryptEnvelopeWithKey, deriveSignedReceiverKey, discoverNetwork, encryptToNetwork, ensureNetworkUsableForDecrypt, generateRandomReceiverKey, isNetworkId, networkDiscoveryKey, openWrappedKey, parseNetworkId, validateEnvelope, verifyDecryptResponse };