@tinycloud/sdk-services 3.11.0 → 3.12.0-beta.16

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.
Files changed (71) hide show
  1. package/dist/{BaseService-Ma2MwJAd.d.ts → BaseService-BRDG69KR.d.ts} +1 -1
  2. package/dist/{BaseService-O0iyuFLk.d.cts → BaseService-CdBkfPGE.d.cts} +1 -1
  3. package/dist/{IHooksService-4QNODVy6.d.cts → IHooksService-C9p3stsB.d.cts} +1 -1
  4. package/dist/{IHooksService-CvTpJbQD.d.ts → IHooksService-D6eyZat1.d.ts} +1 -1
  5. package/dist/{ISQLService-Aly1CBsW.d.ts → ISQLService-B_4KcGA-.d.ts} +1 -1
  6. package/dist/{ISQLService-BOgWzHLT.d.cts → ISQLService-C6nNpcls.d.cts} +1 -1
  7. package/dist/context.cjs +4 -0
  8. package/dist/context.cjs.map +1 -1
  9. package/dist/context.d.cts +1 -1
  10. package/dist/context.d.ts +1 -1
  11. package/dist/context.js +4 -0
  12. package/dist/context.js.map +1 -1
  13. package/dist/encryption/index.cjs +276 -14
  14. package/dist/encryption/index.cjs.map +1 -1
  15. package/dist/encryption/index.d.cts +26 -28
  16. package/dist/encryption/index.d.ts +26 -28
  17. package/dist/encryption/index.js +268 -14
  18. package/dist/encryption/index.js.map +1 -1
  19. package/dist/encryption/named-keys.cjs +225 -14
  20. package/dist/encryption/named-keys.cjs.map +1 -1
  21. package/dist/encryption/named-keys.d.cts +7 -2
  22. package/dist/encryption/named-keys.d.ts +7 -2
  23. package/dist/encryption/named-keys.js +225 -14
  24. package/dist/encryption/named-keys.js.map +1 -1
  25. package/dist/encryption/resource.cjs.map +1 -1
  26. package/dist/encryption/resource.js.map +1 -1
  27. package/dist/feed/index.cjs +4 -0
  28. package/dist/feed/index.cjs.map +1 -1
  29. package/dist/feed/index.d.cts +3 -3
  30. package/dist/feed/index.d.ts +3 -3
  31. package/dist/feed/index.js +4 -0
  32. package/dist/feed/index.js.map +1 -1
  33. package/dist/index.cjs +523 -29
  34. package/dist/index.cjs.map +1 -1
  35. package/dist/index.d.cts +14 -12
  36. package/dist/index.d.ts +14 -12
  37. package/dist/index.js +513 -29
  38. package/dist/index.js.map +1 -1
  39. package/dist/internal/decrypt-transport-response-error.d.cts +1 -1
  40. package/dist/internal/decrypt-transport-response-error.d.ts +1 -1
  41. package/dist/kv/index.cjs +48 -11
  42. package/dist/kv/index.cjs.map +1 -1
  43. package/dist/kv/index.d.cts +5 -5
  44. package/dist/kv/index.d.ts +5 -5
  45. package/dist/kv/index.js +48 -11
  46. package/dist/kv/index.js.map +1 -1
  47. package/dist/kv/replication/index.cjs +39 -8
  48. package/dist/kv/replication/index.cjs.map +1 -1
  49. package/dist/kv/replication/index.d.cts +3 -3
  50. package/dist/kv/replication/index.d.ts +3 -3
  51. package/dist/kv/replication/index.js +38 -7
  52. package/dist/kv/replication/index.js.map +1 -1
  53. package/dist/{scope-DEgc9f-W.d.cts → scope-DtcbyRKY.d.cts} +1 -1
  54. package/dist/{scope-BZr0QwxX.d.ts → scope-J20PQP3u.d.ts} +1 -1
  55. package/dist/sql/index.cjs +36 -0
  56. package/dist/sql/index.cjs.map +1 -1
  57. package/dist/sql/index.d.cts +4 -4
  58. package/dist/sql/index.d.ts +4 -4
  59. package/dist/sql/index.js +36 -0
  60. package/dist/sql/index.js.map +1 -1
  61. package/dist/telemetry/requestLog.cjs +4 -0
  62. package/dist/telemetry/requestLog.cjs.map +1 -1
  63. package/dist/telemetry/requestLog.d.cts +1 -1
  64. package/dist/telemetry/requestLog.d.ts +1 -1
  65. package/dist/telemetry/requestLog.js +4 -0
  66. package/dist/telemetry/requestLog.js.map +1 -1
  67. package/dist/{types-D4XbIfFJ.d.cts → types-DfqNz9Nu.d.cts} +135 -6
  68. package/dist/{types-CSd0RYir.d.ts → types-DjAP8dve.d.cts} +4 -0
  69. package/dist/{types-CSd0RYir.d.cts → types-DjAP8dve.d.ts} +4 -0
  70. package/dist/{types-Bf91gup6.d.ts → types-Nvi_RckJ.d.ts} +135 -6
  71. package/package.json +4 -1
@@ -1,4 +1,96 @@
1
- import { P as PermissionHint } from './types-CSd0RYir.js';
1
+ import { F as FetchFunction, e as FetchResponse, S as ServiceSession, P as PermissionHint } from './types-DjAP8dve.js';
2
+
3
+ type ResourceAccess = "read" | "write" | "host" | "encryption";
4
+ interface ResourceDestination {
5
+ readonly url: string;
6
+ readonly nodeDid?: string;
7
+ }
8
+ interface ResourceNodeInfo {
9
+ readonly nodeId: string;
10
+ readonly features?: unknown;
11
+ }
12
+ interface ResourceRoutingConfig {
13
+ resolveResource(resource: string, access: ResourceAccess): Promise<readonly ResourceDestination[]>;
14
+ bindAudience(authorization: string, nodeDid: string): Promise<string>;
15
+ /** Defaults to the raw transport's public node identity checks. */
16
+ verifyDestination?(target: ResourceDestination): Promise<void | ResourceNodeInfo>;
17
+ }
18
+ /** An identity-checked destination bound to one live resource-routing decision. */
19
+ interface ResourceTransportTarget {
20
+ readonly url: string;
21
+ readonly nodeDid: string;
22
+ readonly fetch: FetchFunction;
23
+ readonly nodeInfo: ResourceNodeInfo;
24
+ bindAudience(authorization: string): Promise<string>;
25
+ }
26
+ interface ResourceTransportOptions {
27
+ /** CID-only controls are node-local and must not choose among several destinations. */
28
+ readonly nodeLocal?: boolean;
29
+ /** An existing node-bound authority must match the resolved destination. */
30
+ readonly nodeDid?: string;
31
+ /** A verified imported grant activates its resources independently, not atomically. */
32
+ readonly independentResources?: boolean;
33
+ /** Captured, verified share-session key for its own locally created invocations. */
34
+ readonly invocationSession?: ServiceSession;
35
+ }
36
+ type ResourceTransport = (resources: readonly {
37
+ resource: string;
38
+ access: ResourceAccess;
39
+ }[], send: (target: ResourceTransportTarget) => Promise<FetchResponse>, options?: ResourceTransportOptions) => Promise<FetchResponse>;
40
+ /** Compare both public node identity surfaces before sending a capability. */
41
+ declare function verifyResourceDestination(target: ResourceDestination, fetchFn: FetchFunction): Promise<ResourceNodeInfo | undefined>;
42
+ declare class NodeNotRespondingError extends Error {
43
+ readonly hosts: readonly string[];
44
+ readonly cause?: unknown | undefined;
45
+ readonly code = "NODE_NOT_RESPONDING";
46
+ constructor(hosts: readonly string[], cause?: unknown | undefined);
47
+ }
48
+ declare class NodeIdentityMismatchError extends Error {
49
+ readonly url: string;
50
+ readonly expectedDid: string;
51
+ readonly actualDid?: string | undefined;
52
+ readonly code = "NODE_IDENTITY_MISMATCH";
53
+ constructor(url: string, expectedDid: string, actualDid?: string | undefined);
54
+ }
55
+ declare class ResourceNotRoutedError extends Error {
56
+ readonly resource: string;
57
+ readonly code = "RESOURCE_NOT_ROUTED";
58
+ constructor(resource: string);
59
+ }
60
+ declare class PartialNodeWriteError extends Error {
61
+ readonly succeeded: readonly string[];
62
+ readonly failed: readonly {
63
+ url: string;
64
+ status?: number;
65
+ cause?: unknown;
66
+ }[];
67
+ readonly code = "PARTIAL_NODE_WRITE";
68
+ constructor(succeeded: readonly string[], failed: readonly {
69
+ url: string;
70
+ status?: number;
71
+ cause?: unknown;
72
+ }[]);
73
+ }
74
+ type RoutingFailureCode = "NODE_NOT_RESPONDING" | "DECRYPTION_DEPENDENCY_UNAVAILABLE" | "PARTIAL_NODE_WRITE" | "NODE_IDENTITY_MISMATCH" | "RESOURCE_NOT_ROUTED" | "registry_unavailable" | "node_not_found" | "node_registry_entry_exists";
75
+ interface RoutingFailure {
76
+ code: RoutingFailureCode;
77
+ message: string;
78
+ cause?: Error;
79
+ meta?: Record<string, unknown>;
80
+ }
81
+ /** Preserve routing failures through service-specific Result/error adapters. */
82
+ declare function routingFailure(error: unknown): RoutingFailure | undefined;
83
+ /** Extract the signed resource without inferring an account for node-local names. */
84
+ declare function routingResourceOf(uri: string): string;
85
+ /** Share target selection and read/write outcomes with resource-specific adapters. */
86
+ declare function routeResourceRequest(resources: readonly {
87
+ resource: string;
88
+ access: ResourceAccess;
89
+ }[], routing: Pick<ResourceRoutingConfig, "resolveResource">, send: (target: ResourceDestination) => Promise<FetchResponse>, options?: ResourceTransportOptions): Promise<FetchResponse>;
90
+ /** Route only locally generated data invocations through a captured share session. */
91
+ declare function createResourceTransportInvocationFetch(transport: ResourceTransport, session: ServiceSession): FetchFunction;
92
+ /** Route signed /invoke traffic. Non-invocation endpoints retain their own resource-specific adapters. */
93
+ declare function createResourceRoutingFetch(fetchFn: FetchFunction, routing: ResourceRoutingConfig): FetchFunction;
2
94
 
3
95
  /**
4
96
  * Canonical JSON serialization and content hashing for TinyCloud
@@ -41,6 +133,40 @@ declare function utf8Decode(b: Uint8Array): string;
41
133
  */
42
134
  declare function canonicalHashHex(sha256: (bytes: Uint8Array) => Uint8Array, value: Json): string;
43
135
 
136
+ declare const KEY_WRAP_V2_ALG: "x25519-hkdf-aes256gcm/v2";
137
+ interface KeyWrapContext {
138
+ purpose: "network-key" | "receiver-key";
139
+ networkId: string;
140
+ keyPath: string;
141
+ keyVersion: number;
142
+ metadata: Record<string, string>;
143
+ }
144
+ interface KeyWrapV2Header extends KeyWrapContext {
145
+ v: 2;
146
+ alg: typeof KEY_WRAP_V2_ALG;
147
+ kdf: "hkdf-sha256";
148
+ aead: "aes-256-gcm";
149
+ salt: string;
150
+ ephemeralPublicKey: string;
151
+ recipientPublicKey: string;
152
+ }
153
+ declare function isKeyWrapV2(wrapped: Uint8Array): boolean;
154
+ /** Parse the closed canonical header. Authentication occurs when the node or recipient opens it. */
155
+ declare function readKeyWrapV2(wrapped: Uint8Array): {
156
+ header: KeyWrapV2Header;
157
+ aad: Uint8Array;
158
+ nonce: Uint8Array;
159
+ ciphertext: Uint8Array;
160
+ };
161
+ declare function assertKeyWrapContext(header: KeyWrapV2Header, expected: KeyWrapContext): void;
162
+ declare function sealKeyV2(recipientPublicKey: Uint8Array, plaintext: Uint8Array, context: KeyWrapContext): Uint8Array;
163
+ declare function openKeyV2(recipientPrivateKey: Uint8Array, wrapped: Uint8Array, expected: KeyWrapContext): Uint8Array;
164
+ /** Match the declared algorithm without falling back after a TCW2 marker. */
165
+ declare function assertKeyWrapAlgorithm(wrapped: Uint8Array, alg: string, requireV2?: boolean): void;
166
+ type ColumnFormat = "encrypted" | "legacy-plaintext";
167
+ /** Stored format, not input bytes, determines whether a column is plaintext. */
168
+ declare function decryptColumn(decrypt: (key: Uint8Array, ciphertext: Uint8Array) => Uint8Array, key: Uint8Array, blob: Uint8Array, expectedFormat: ColumnFormat, strictEncryption?: boolean): Uint8Array;
169
+
44
170
  /**
45
171
  * Type definitions for TinyCloud one-of-one encryption.
46
172
  *
@@ -95,7 +221,7 @@ interface InlineEncryptedEnvelope {
95
221
  ciphertext: string;
96
222
  /** Base64-encoded associated data, if any. */
97
223
  aad?: string;
98
- /** Caller-supplied metadata. Not authenticated against the node. */
224
+ /** Caller metadata; v2 wraps bind it to the node-authenticated header. */
99
225
  metadata?: Record<string, string>;
100
226
  }
101
227
  /**
@@ -216,13 +342,16 @@ interface EncryptionCrypto {
216
342
  * a sealed-box / hpke / x25519+symmetric construction. Implementation
217
343
  * is opaque; only the node can unwrap.
218
344
  */
219
- sealToNetworkKey(networkPublicKey: Uint8Array, symmetricKey: Uint8Array): Uint8Array;
345
+ sealToNetworkKey(networkPublicKey: Uint8Array, symmetricKey: Uint8Array, options?: {
346
+ keyWrapV2: boolean;
347
+ context: KeyWrapContext;
348
+ }): Uint8Array;
220
349
  /**
221
350
  * Open a wrapped symmetric key that was re-encrypted to the
222
351
  * per-request receiver public key. The matching private key must be
223
352
  * supplied here; the SDK never sends it to the node.
224
353
  */
225
- openWithReceiverKey(receiverPrivateKey: Uint8Array, wrappedKey: Uint8Array): Uint8Array;
354
+ openWithReceiverKey(receiverPrivateKey: Uint8Array, wrappedKey: Uint8Array, expected?: KeyWrapContext): Uint8Array;
226
355
  /**
227
356
  * Verify an ed25519 signature over `message` produced by the node
228
357
  * identified by `nodeId` (the public-key DID).
@@ -285,7 +414,7 @@ interface DecryptInvocationSigner {
285
414
  /**
286
415
  * Errors thrown / returned from the encryption module.
287
416
  */
288
- type EncryptionErrorInput = {
417
+ type EncryptionErrorInput = RoutingFailure | {
289
418
  code: "NETWORK_NOT_FOUND";
290
419
  networkId?: string;
291
420
  name?: string;
@@ -330,4 +459,4 @@ declare function encryptionError(input: EncryptionErrorInput): EncryptionError;
330
459
  /** Re-export for ergonomic typing of canonical payloads. */
331
460
  type CanonicalJson = Json;
332
461
 
333
- export { type BuildDecryptInvocationInput as B, type CanonicalJson as C, type DecryptCapabilityProof as D, type EncryptionCrypto as E, type InlineEncryptedEnvelope as I, type Json as J, type NetworkDescriptor as N, type ReceiverKeyPair as R, type BuiltDecryptInvocation as a, DECRYPT_ACTION as b, DECRYPT_FACT_TYPE as c, DECRYPT_RESULT_TYPE as d, DEFAULT_ENCRYPTION_ALG as e, DEFAULT_KEY_VERSION as f, type DecryptInvocationFact as g, type DecryptInvocationSigner as h, type DecryptRequestBody as i, type DecryptResponseBody as j, ENCRYPTION_SERVICE as k, ENCRYPTION_SERVICE_SHORT as l, ENVELOPE_VERSION as m, type EncryptionError as n, type EncryptionErrorInput as o, type ReceiverKeySigner as p, base64Decode as q, base64Encode as r, canonicalHashHex as s, canonicalize as t, encryptionError as u, hexDecode as v, hexEncode as w, utf8Decode as x, utf8Encode as y };
462
+ export { KEY_WRAP_V2_ALG as $, type ResourceTransportTarget as A, type BuildDecryptInvocationInput as B, type CanonicalJson as C, type DecryptCapabilityProof as D, type EncryptionCrypto as E, base64Decode as F, base64Encode as G, canonicalHashHex as H, type InlineEncryptedEnvelope as I, type Json as J, canonicalize as K, createResourceRoutingFetch as L, createResourceTransportInvocationFetch as M, type NetworkDescriptor as N, encryptionError as O, PartialNodeWriteError as P, hexDecode as Q, type RoutingFailure as R, hexEncode as S, routeResourceRequest as T, routingFailure as U, routingResourceOf as V, utf8Decode as W, utf8Encode as X, verifyResourceDestination as Y, type KeyWrapContext as Z, type ColumnFormat as _, type BuiltDecryptInvocation as a, type KeyWrapV2Header as a0, assertKeyWrapAlgorithm as a1, assertKeyWrapContext as a2, decryptColumn as a3, isKeyWrapV2 as a4, openKeyV2 as a5, readKeyWrapV2 as a6, sealKeyV2 as a7, DECRYPT_ACTION as b, DECRYPT_FACT_TYPE as c, DECRYPT_RESULT_TYPE as d, DEFAULT_ENCRYPTION_ALG as e, DEFAULT_KEY_VERSION as f, type DecryptInvocationFact as g, type DecryptInvocationSigner as h, type DecryptRequestBody as i, type DecryptResponseBody as j, ENCRYPTION_SERVICE as k, ENCRYPTION_SERVICE_SHORT as l, ENVELOPE_VERSION as m, type EncryptionError as n, type EncryptionErrorInput as o, NodeIdentityMismatchError as p, NodeNotRespondingError as q, type ReceiverKeyPair as r, type ReceiverKeySigner as s, type ResourceAccess as t, type ResourceDestination as u, type ResourceNodeInfo as v, ResourceNotRoutedError as w, type ResourceRoutingConfig as x, type ResourceTransport as y, type ResourceTransportOptions as z };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tinycloud/sdk-services",
3
- "version": "3.11.0",
3
+ "version": "3.12.0-beta.16",
4
4
  "description": "TinyCloud SDK Services - Platform-agnostic service implementations",
5
5
  "author": "TinyCloud, Inc.",
6
6
  "license": "EGPL",
@@ -183,6 +183,9 @@
183
183
  "typecheck:contract": "tsc --noEmit -p tsconfig.contract.json"
184
184
  },
185
185
  "dependencies": {
186
+ "@noble/ciphers": "1.3.0",
187
+ "@noble/curves": "^1.9.7",
188
+ "@noble/hashes": "1.8.0",
186
189
  "@tinycloud/bootstrap": "2.8.0",
187
190
  "zod": "^3.23.0"
188
191
  },