@debros/network-ts-sdk 0.6.2 → 0.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.
package/README.md CHANGED
@@ -388,6 +388,197 @@ const client = createClient({
388
388
  });
389
389
  ```
390
390
 
391
+ ### Cache Operations
392
+
393
+ The SDK provides a distributed cache client backed by Olric. Data is organized into distributed maps (dmaps).
394
+
395
+ #### Put a Value
396
+
397
+ ```typescript
398
+ // Put with optional TTL
399
+ await client.cache.put("sessions", "user:alice", { role: "admin" }, "1h");
400
+ ```
401
+
402
+ #### Get a Value
403
+
404
+ ```typescript
405
+ // Returns null on cache miss (not an error)
406
+ const result = await client.cache.get("sessions", "user:alice");
407
+ if (result) {
408
+ console.log(result.value); // { role: "admin" }
409
+ }
410
+ ```
411
+
412
+ #### Delete a Value
413
+
414
+ ```typescript
415
+ await client.cache.delete("sessions", "user:alice");
416
+ ```
417
+
418
+ #### Multi-Get
419
+
420
+ ```typescript
421
+ const results = await client.cache.multiGet("sessions", [
422
+ "user:alice",
423
+ "user:bob",
424
+ ]);
425
+ // Returns Map<string, any | null> — null for misses
426
+ results.forEach((value, key) => {
427
+ console.log(key, value);
428
+ });
429
+ ```
430
+
431
+ #### Scan Keys
432
+
433
+ ```typescript
434
+ // Scan all keys in a dmap, optionally matching a regex
435
+ const scan = await client.cache.scan("sessions", "user:.*");
436
+ console.log(scan.keys); // ["user:alice", "user:bob"]
437
+ console.log(scan.count); // 2
438
+ ```
439
+
440
+ #### Health Check
441
+
442
+ ```typescript
443
+ const health = await client.cache.health();
444
+ console.log(health.status); // "ok"
445
+ ```
446
+
447
+ ### Storage (IPFS)
448
+
449
+ Upload, pin, and retrieve files from decentralized IPFS storage.
450
+
451
+ #### Upload a File
452
+
453
+ ```typescript
454
+ // Browser
455
+ const fileInput = document.querySelector('input[type="file"]');
456
+ const file = fileInput.files[0];
457
+ const result = await client.storage.upload(file, file.name);
458
+ console.log(result.cid); // "Qm..."
459
+
460
+ // Node.js
461
+ import { readFileSync } from "fs";
462
+ const buffer = readFileSync("image.jpg");
463
+ const result = await client.storage.upload(buffer, "image.jpg", { pin: true });
464
+ ```
465
+
466
+ #### Retrieve Content
467
+
468
+ ```typescript
469
+ // Get as ReadableStream
470
+ const stream = await client.storage.get(cid);
471
+ const reader = stream.getReader();
472
+ while (true) {
473
+ const { done, value } = await reader.read();
474
+ if (done) break;
475
+ // Process chunk
476
+ }
477
+
478
+ // Get full Response (for headers like content-length)
479
+ const response = await client.storage.getBinary(cid);
480
+ const contentLength = response.headers.get("content-length");
481
+ ```
482
+
483
+ #### Pin / Unpin / Status
484
+
485
+ ```typescript
486
+ // Pin an existing CID
487
+ await client.storage.pin("QmExampleCid", "my-file");
488
+
489
+ // Check pin status
490
+ const status = await client.storage.status("QmExampleCid");
491
+ console.log(status.status); // "pinned", "pinning", "queued", "unpinned", "error"
492
+
493
+ // Unpin
494
+ await client.storage.unpin("QmExampleCid");
495
+ ```
496
+
497
+ ### Serverless Functions (WASM)
498
+
499
+ Invoke WebAssembly serverless functions deployed on the network.
500
+
501
+ ```typescript
502
+ // Configure functions namespace
503
+ const client = createClient({
504
+ baseURL: "http://localhost:6001",
505
+ apiKey: "ak_your_key:namespace",
506
+ functionsConfig: {
507
+ namespace: "my-namespace",
508
+ },
509
+ });
510
+
511
+ // Invoke a function with typed input/output
512
+ interface PushInput {
513
+ token: string;
514
+ message: string;
515
+ }
516
+ interface PushOutput {
517
+ success: boolean;
518
+ messageId: string;
519
+ }
520
+
521
+ const result = await client.functions.invoke<PushInput, PushOutput>(
522
+ "send-push",
523
+ { token: "device-token", message: "Hello!" }
524
+ );
525
+ console.log(result.messageId);
526
+ ```
527
+
528
+ ### Vault (Distributed Secrets)
529
+
530
+ The vault client provides Shamir-split secret storage across guardian nodes. Secrets are split into shares, distributed to guardians, and reconstructed only when enough shares are collected (quorum).
531
+
532
+ ```typescript
533
+ const client = createClient({
534
+ baseURL: "http://localhost:6001",
535
+ apiKey: "ak_your_key:namespace",
536
+ vaultConfig: {
537
+ guardians: [
538
+ { address: "10.0.0.1", port: 8443 },
539
+ { address: "10.0.0.2", port: 8443 },
540
+ { address: "10.0.0.3", port: 8443 },
541
+ ],
542
+ identityHex: "your-identity-hex",
543
+ },
544
+ });
545
+
546
+ // Store a secret (Shamir-split across guardians)
547
+ const data = new TextEncoder().encode("my-secret-data");
548
+ const storeResult = await client.vault.store("api-key", data, 1);
549
+ console.log(storeResult.quorumMet); // true if enough guardians ACKed
550
+
551
+ // Retrieve and reconstruct a secret
552
+ const retrieved = await client.vault.retrieve("api-key");
553
+ console.log(new TextDecoder().decode(retrieved.data)); // "my-secret-data"
554
+
555
+ // List all secrets for this identity
556
+ const secrets = await client.vault.list();
557
+ console.log(secrets.secrets);
558
+
559
+ // Delete a secret from all guardians
560
+ await client.vault.delete("api-key");
561
+ ```
562
+
563
+ ### Wallet-Based Authentication
564
+
565
+ For wallet-based auth (challenge-response flow):
566
+
567
+ ```typescript
568
+ // 1. Request a challenge
569
+ const challenge = await client.auth.challenge();
570
+
571
+ // 2. Sign the challenge with your wallet (external)
572
+ const signature = await wallet.signMessage(challenge.message);
573
+
574
+ // 3. Verify signature and get JWT
575
+ const session = await client.auth.verify(challenge.id, signature);
576
+ console.log(session.token);
577
+
578
+ // 4. Get an API key for long-lived access
579
+ const apiKey = await client.auth.getApiKey();
580
+ ```
581
+
391
582
  ## Error Handling
392
583
 
393
584
  The SDK throws `SDKError` for all errors:
package/dist/index.d.ts CHANGED
@@ -121,7 +121,7 @@ declare class LocalStorageAdapter implements StorageAdapter {
121
121
  clear(): Promise<void>;
122
122
  }
123
123
 
124
- declare class AuthClient {
124
+ declare class AuthClient$1 {
125
125
  private httpClient;
126
126
  private storage;
127
127
  private currentApiKey?;
@@ -823,6 +823,189 @@ declare class FunctionsClient {
823
823
  invoke<TInput = any, TOutput = any>(functionName: string, input: TInput): Promise<TOutput>;
824
824
  }
825
825
 
826
+ /** A guardian node endpoint. */
827
+ interface GuardianEndpoint {
828
+ address: string;
829
+ port: number;
830
+ }
831
+ /** V1 push response. */
832
+ interface PushResponse {
833
+ status: string;
834
+ }
835
+ /** V1 pull response. */
836
+ interface PullResponse {
837
+ share: string;
838
+ }
839
+ /** V2 store response. */
840
+ interface StoreSecretResponse {
841
+ status: string;
842
+ name: string;
843
+ version: number;
844
+ }
845
+ /** V2 get response. */
846
+ interface GetSecretResponse {
847
+ share: string;
848
+ name: string;
849
+ version: number;
850
+ created_ns: number;
851
+ updated_ns: number;
852
+ }
853
+ /** V2 delete response. */
854
+ interface DeleteSecretResponse {
855
+ status: string;
856
+ name: string;
857
+ }
858
+ /** V2 list response. */
859
+ interface ListSecretsResponse {
860
+ secrets: SecretEntry[];
861
+ }
862
+ /** An entry in the list secrets response. */
863
+ interface SecretEntry {
864
+ name: string;
865
+ version: number;
866
+ size: number;
867
+ }
868
+ /** Health check response. */
869
+ interface HealthResponse {
870
+ status: string;
871
+ version: string;
872
+ }
873
+ /** Status response. */
874
+ interface StatusResponse {
875
+ status: string;
876
+ version: string;
877
+ data_dir: string;
878
+ client_port: number;
879
+ peer_port: number;
880
+ }
881
+ /** Guardian info response. */
882
+ interface GuardianInfo {
883
+ guardians: Array<{
884
+ address: string;
885
+ port: number;
886
+ }>;
887
+ threshold: number;
888
+ total: number;
889
+ }
890
+ /** Challenge response from auth endpoint. */
891
+ interface ChallengeResponse {
892
+ nonce: string;
893
+ created_ns: number;
894
+ tag: string;
895
+ }
896
+ /** Session token response from auth endpoint. */
897
+ interface SessionResponse {
898
+ identity: string;
899
+ expiry_ns: number;
900
+ tag: string;
901
+ }
902
+ /** Error classification codes. */
903
+ type GuardianErrorCode = 'TIMEOUT' | 'NOT_FOUND' | 'AUTH' | 'SERVER_ERROR' | 'NETWORK' | 'CONFLICT';
904
+ /** Fan-out result for a single guardian. */
905
+ interface FanOutResult<T> {
906
+ endpoint: GuardianEndpoint;
907
+ result: T | null;
908
+ error: string | null;
909
+ errorCode?: GuardianErrorCode;
910
+ }
911
+
912
+ /** Configuration for VaultClient. */
913
+ interface VaultConfig {
914
+ /** Guardian endpoints to connect to. */
915
+ guardians: GuardianEndpoint[];
916
+ /** HMAC key for authentication (derived from user's secret). */
917
+ hmacKey: Uint8Array;
918
+ /** Identity hash (hex string, 64 chars). */
919
+ identityHex: string;
920
+ /** Request timeout in ms (default: 10000). */
921
+ timeoutMs?: number;
922
+ }
923
+ /** Metadata for a stored secret. */
924
+ interface SecretMeta {
925
+ name: string;
926
+ version: number;
927
+ size: number;
928
+ }
929
+ /** Result of a store operation. */
930
+ interface StoreResult {
931
+ /** Number of guardians that acknowledged. */
932
+ ackCount: number;
933
+ /** Total guardians contacted. */
934
+ totalContacted: number;
935
+ /** Number of failures. */
936
+ failCount: number;
937
+ /** Whether write quorum was met. */
938
+ quorumMet: boolean;
939
+ /** Per-guardian results. */
940
+ guardianResults: GuardianResult[];
941
+ }
942
+ /** Result of a retrieve operation. */
943
+ interface RetrieveResult {
944
+ /** The reconstructed secret data. */
945
+ data: Uint8Array;
946
+ /** Number of shares collected. */
947
+ sharesCollected: number;
948
+ }
949
+ /** Result of a list operation. */
950
+ interface ListResult {
951
+ secrets: SecretMeta[];
952
+ }
953
+ /** Result of a delete operation. */
954
+ interface DeleteResult {
955
+ /** Number of guardians that acknowledged. */
956
+ ackCount: number;
957
+ totalContacted: number;
958
+ quorumMet: boolean;
959
+ }
960
+ /** Per-guardian operation result. */
961
+ interface GuardianResult {
962
+ endpoint: string;
963
+ success: boolean;
964
+ error?: string;
965
+ }
966
+
967
+ /**
968
+ * High-level client for the orama-vault distributed secrets store.
969
+ *
970
+ * Handles:
971
+ * - Authentication with guardian nodes
972
+ * - Shamir split/combine for data distribution
973
+ * - Quorum-based writes and reads
974
+ * - V2 CRUD operations (store, retrieve, list, delete)
975
+ */
976
+ declare class VaultClient {
977
+ private config;
978
+ private auth;
979
+ constructor(config: VaultConfig);
980
+ /**
981
+ * Store a secret across guardian nodes using Shamir splitting.
982
+ *
983
+ * @param name - Secret name (alphanumeric, _, -, max 128 chars)
984
+ * @param data - Secret data to store
985
+ * @param version - Monotonic version number (must be > previous)
986
+ */
987
+ store(name: string, data: Uint8Array, version: number): Promise<StoreResult>;
988
+ /**
989
+ * Retrieve and reconstruct a secret from guardian nodes.
990
+ *
991
+ * @param name - Secret name
992
+ */
993
+ retrieve(name: string): Promise<RetrieveResult>;
994
+ /**
995
+ * List all secrets for this identity.
996
+ * Queries the first reachable guardian (metadata is replicated).
997
+ */
998
+ list(): Promise<ListResult>;
999
+ /**
1000
+ * Delete a secret from all guardian nodes.
1001
+ *
1002
+ * @param name - Secret name to delete
1003
+ */
1004
+ delete(name: string): Promise<DeleteResult>;
1005
+ /** Clear all cached auth sessions. */
1006
+ clearSessions(): void;
1007
+ }
1008
+
826
1009
  /**
827
1010
  * Serverless Functions Types
828
1011
  * Type definitions for calling serverless functions on the Orama Network
@@ -843,6 +1026,272 @@ interface SuccessResponse {
843
1026
  error?: string;
844
1027
  }
845
1028
 
1029
+ declare class GuardianError extends Error {
1030
+ readonly code: GuardianErrorCode;
1031
+ constructor(code: GuardianErrorCode, message: string);
1032
+ }
1033
+ /**
1034
+ * HTTP client for a single orama-vault guardian node.
1035
+ * Supports V1 (push/pull) and V2 (CRUD secrets) endpoints.
1036
+ */
1037
+ declare class GuardianClient {
1038
+ private baseUrl;
1039
+ private timeoutMs;
1040
+ private sessionToken;
1041
+ constructor(endpoint: GuardianEndpoint, timeoutMs?: number);
1042
+ /** Set a session token for authenticated V2 requests. */
1043
+ setSessionToken(token: string): void;
1044
+ /** Get the current session token. */
1045
+ getSessionToken(): string | null;
1046
+ /** Clear the session token. */
1047
+ clearSessionToken(): void;
1048
+ /** GET /v1/vault/health */
1049
+ health(): Promise<HealthResponse>;
1050
+ /** GET /v1/vault/status */
1051
+ status(): Promise<StatusResponse>;
1052
+ /** GET /v1/vault/guardians */
1053
+ guardians(): Promise<GuardianInfo>;
1054
+ /** POST /v1/vault/push — store a share (V1). */
1055
+ push(identity: string, share: Uint8Array): Promise<PushResponse>;
1056
+ /** POST /v1/vault/pull — retrieve a share (V1). */
1057
+ pull(identity: string): Promise<Uint8Array>;
1058
+ /** Check if this guardian is reachable. */
1059
+ isReachable(): Promise<boolean>;
1060
+ /** POST /v2/vault/auth/challenge — request an auth challenge. */
1061
+ requestChallenge(identity: string): Promise<ChallengeResponse>;
1062
+ /** POST /v2/vault/auth/session — exchange challenge for session token. */
1063
+ createSession(identity: string, nonce: string, created_ns: number, tag: string): Promise<SessionResponse>;
1064
+ /** PUT /v2/vault/secrets/{name} — store a secret. Requires session token. */
1065
+ putSecret(name: string, share: Uint8Array, version: number): Promise<StoreSecretResponse>;
1066
+ /** GET /v2/vault/secrets/{name} — retrieve a secret. Requires session token. */
1067
+ getSecret(name: string): Promise<{
1068
+ share: Uint8Array;
1069
+ name: string;
1070
+ version: number;
1071
+ created_ns: number;
1072
+ updated_ns: number;
1073
+ }>;
1074
+ /** DELETE /v2/vault/secrets/{name} — delete a secret. Requires session token. */
1075
+ deleteSecret(name: string): Promise<DeleteSecretResponse>;
1076
+ /** GET /v2/vault/secrets — list all secrets. Requires session token. */
1077
+ listSecrets(): Promise<ListSecretsResponse>;
1078
+ private authedRequest;
1079
+ private get;
1080
+ private post;
1081
+ }
1082
+
1083
+ /**
1084
+ * Handles challenge-response authentication with guardian nodes.
1085
+ * Caches session tokens per guardian endpoint.
1086
+ *
1087
+ * Auth flow:
1088
+ * 1. POST /v2/vault/auth/challenge with identity → get {nonce, created_ns, tag}
1089
+ * 2. POST /v2/vault/auth/session with identity + challenge fields → get session token
1090
+ * 3. Use session token as X-Session-Token header for V2 requests
1091
+ *
1092
+ * The session token format is: `<identity_hex>:<expiry_ns>:<tag_hex>`
1093
+ */
1094
+ declare class AuthClient {
1095
+ private sessions;
1096
+ private identityHex;
1097
+ private timeoutMs;
1098
+ constructor(identityHex: string, timeoutMs?: number);
1099
+ /**
1100
+ * Authenticate with a guardian and cache the session token.
1101
+ * Returns a GuardianClient with the session token set.
1102
+ */
1103
+ authenticate(endpoint: GuardianEndpoint): Promise<GuardianClient>;
1104
+ /**
1105
+ * Authenticate with multiple guardians in parallel.
1106
+ * Returns authenticated GuardianClients for all that succeed.
1107
+ */
1108
+ authenticateAll(endpoints: GuardianEndpoint[]): Promise<{
1109
+ client: GuardianClient;
1110
+ endpoint: GuardianEndpoint;
1111
+ }[]>;
1112
+ /** Clear all cached sessions. */
1113
+ clearSessions(): void;
1114
+ /** Get the identity hex string. */
1115
+ getIdentityHex(): string;
1116
+ }
1117
+
1118
+ /**
1119
+ * Fan out an operation to multiple guardians in parallel.
1120
+ * Returns results from all guardians (both successes and failures).
1121
+ */
1122
+ declare function fanOut<T>(guardians: GuardianEndpoint[], operation: (client: GuardianClient) => Promise<T>): Promise<FanOutResult<T>[]>;
1123
+ /**
1124
+ * Fan out an indexed operation to multiple guardians in parallel.
1125
+ * The operation receives the index so each guardian can get a different share.
1126
+ */
1127
+ declare function fanOutIndexed<T>(guardians: GuardianEndpoint[], operation: (client: GuardianClient, index: number) => Promise<T>): Promise<FanOutResult<T>[]>;
1128
+ /**
1129
+ * Race a promise against a timeout.
1130
+ */
1131
+ declare function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T>;
1132
+ /**
1133
+ * Retry a function with exponential backoff.
1134
+ * Does not retry auth or not-found errors.
1135
+ */
1136
+ declare function withRetry<T>(fn: () => Promise<T>, attempts?: number): Promise<T>;
1137
+
1138
+ /**
1139
+ * Quorum calculations for distributed vault operations.
1140
+ * Must match orama-vault (Zig side).
1141
+ */
1142
+ /** Adaptive Shamir threshold: max(3, floor(N/3)). */
1143
+ declare function adaptiveThreshold(n: number): number;
1144
+ /** Write quorum: ceil(2N/3). Requires majority for consistency. */
1145
+ declare function writeQuorum(n: number): number;
1146
+
1147
+ /**
1148
+ * AES-256-GCM Encryption
1149
+ *
1150
+ * Implements authenticated encryption using AES-256 in Galois/Counter Mode.
1151
+ * Uses @noble/ciphers for platform-agnostic, audited cryptographic operations.
1152
+ *
1153
+ * Features:
1154
+ * - Authenticated encryption (confidentiality + integrity)
1155
+ * - 256-bit keys for strong security
1156
+ * - 96-bit nonces (randomly generated)
1157
+ * - 128-bit authentication tags
1158
+ *
1159
+ * Security considerations:
1160
+ * - Never reuse a nonce with the same key
1161
+ * - Nonces are randomly generated and prepended to ciphertext
1162
+ * - Authentication tags are verified before decryption
1163
+ */
1164
+ /**
1165
+ * Size constants
1166
+ */
1167
+ declare const KEY_SIZE = 32;
1168
+ declare const NONCE_SIZE = 12;
1169
+ declare const TAG_SIZE = 16;
1170
+ /**
1171
+ * Encrypted data structure
1172
+ */
1173
+ interface EncryptedData {
1174
+ /** Ciphertext including authentication tag */
1175
+ ciphertext: Uint8Array;
1176
+ /** Nonce used for encryption */
1177
+ nonce: Uint8Array;
1178
+ /** Additional authenticated data (optional) */
1179
+ aad?: Uint8Array;
1180
+ }
1181
+ /**
1182
+ * Serialized encrypted data (nonce prepended to ciphertext)
1183
+ */
1184
+ interface SerializedEncryptedData {
1185
+ /** Combined nonce + ciphertext + tag */
1186
+ data: Uint8Array;
1187
+ /** Additional authenticated data (optional) */
1188
+ aad?: Uint8Array;
1189
+ }
1190
+ /**
1191
+ * Encrypts data using AES-256-GCM
1192
+ */
1193
+ declare function encrypt(plaintext: Uint8Array, key: Uint8Array, aad?: Uint8Array): EncryptedData;
1194
+ /**
1195
+ * Decrypts data using AES-256-GCM
1196
+ */
1197
+ declare function decrypt(encryptedData: EncryptedData, key: Uint8Array): Uint8Array;
1198
+ /**
1199
+ * Encrypts a string message
1200
+ */
1201
+ declare function encryptString(message: string, key: Uint8Array, aad?: Uint8Array): EncryptedData;
1202
+ /**
1203
+ * Decrypts to a string message
1204
+ */
1205
+ declare function decryptString(encryptedData: EncryptedData, key: Uint8Array): string;
1206
+ /**
1207
+ * Serializes encrypted data (prepends nonce to ciphertext)
1208
+ */
1209
+ declare function serialize(encryptedData: EncryptedData): SerializedEncryptedData;
1210
+ /**
1211
+ * Deserializes encrypted data
1212
+ */
1213
+ declare function deserialize(serialized: SerializedEncryptedData): EncryptedData;
1214
+ /**
1215
+ * Encrypts and serializes data in one step
1216
+ */
1217
+ declare function encryptAndSerialize(plaintext: Uint8Array, key: Uint8Array, aad?: Uint8Array): SerializedEncryptedData;
1218
+ /**
1219
+ * Deserializes and decrypts data in one step
1220
+ */
1221
+ declare function deserializeAndDecrypt(serialized: SerializedEncryptedData, key: Uint8Array): Uint8Array;
1222
+ /**
1223
+ * Converts encrypted data to hex string
1224
+ */
1225
+ declare function toHex(encryptedData: EncryptedData): string;
1226
+ /**
1227
+ * Parses encrypted data from hex string
1228
+ */
1229
+ declare function fromHex(hex: string, aad?: Uint8Array): EncryptedData;
1230
+ /**
1231
+ * Converts encrypted data to base64 string
1232
+ */
1233
+ declare function toBase64(encryptedData: EncryptedData): string;
1234
+ /**
1235
+ * Parses encrypted data from base64 string
1236
+ */
1237
+ declare function fromBase64(base64: string, aad?: Uint8Array): EncryptedData;
1238
+ /**
1239
+ * Generates a random encryption key
1240
+ */
1241
+ declare function generateKey(): Uint8Array;
1242
+ /**
1243
+ * Generates a random nonce
1244
+ */
1245
+ declare function generateNonce(): Uint8Array;
1246
+ /**
1247
+ * Securely clears a key from memory
1248
+ */
1249
+ declare function clearKey(key: Uint8Array): void;
1250
+ /**
1251
+ * Checks if encrypted data appears valid (basic structure check)
1252
+ */
1253
+ declare function isValidEncryptedData(data: EncryptedData): boolean;
1254
+
1255
+ /**
1256
+ * HKDF Key Derivation
1257
+ *
1258
+ * Derives deterministic sub-keys from a master secret using HKDF-SHA256 (RFC 5869).
1259
+ */
1260
+ /**
1261
+ * Derives a sub-key from input key material using HKDF-SHA256.
1262
+ *
1263
+ * @param ikm - Input key material (e.g., wallet private key). MUST be high-entropy.
1264
+ * @param salt - Domain separation salt. Can be a string or bytes.
1265
+ * @param info - Context-specific info. Can be a string or bytes.
1266
+ * @param length - Output key length in bytes (default: 32).
1267
+ * @returns Derived key as Uint8Array. Caller MUST zero this after use.
1268
+ */
1269
+ declare function deriveKeyHKDF(ikm: Uint8Array, salt: string | Uint8Array, info: string | Uint8Array, length?: number): Uint8Array;
1270
+
1271
+ /** A single Shamir share */
1272
+ interface Share {
1273
+ /** Share index (1..N, never 0) */
1274
+ x: number;
1275
+ /** Share data (same length as secret) */
1276
+ y: Uint8Array;
1277
+ }
1278
+ /**
1279
+ * Splits a secret into N shares with threshold K.
1280
+ *
1281
+ * @param secret - Secret bytes to split (any length)
1282
+ * @param n - Total number of shares to create (2..255)
1283
+ * @param k - Minimum shares needed for reconstruction (2..n)
1284
+ * @returns Array of N shares
1285
+ */
1286
+ declare function split(secret: Uint8Array, n: number, k: number): Share[];
1287
+ /**
1288
+ * Reconstructs a secret from K or more shares using Lagrange interpolation.
1289
+ *
1290
+ * @param shares - Array of K or more shares (must all have same y.length)
1291
+ * @returns Reconstructed secret
1292
+ */
1293
+ declare function combine(shares: Share[]): Uint8Array;
1294
+
846
1295
  interface ClientConfig extends Omit<HttpClientConfig, "fetch"> {
847
1296
  apiKey?: string;
848
1297
  jwt?: string;
@@ -855,16 +1304,19 @@ interface ClientConfig extends Omit<HttpClientConfig, "fetch"> {
855
1304
  * Use this to trigger gateway failover at the application layer.
856
1305
  */
857
1306
  onNetworkError?: NetworkErrorCallback;
1307
+ /** Configuration for the vault (distributed secrets store). */
1308
+ vaultConfig?: VaultConfig;
858
1309
  }
859
1310
  interface Client {
860
- auth: AuthClient;
1311
+ auth: AuthClient$1;
861
1312
  db: DBClient;
862
1313
  pubsub: PubSubClient;
863
1314
  network: NetworkClient;
864
1315
  cache: CacheClient;
865
1316
  storage: StorageClient;
866
1317
  functions: FunctionsClient;
1318
+ vault: VaultClient | null;
867
1319
  }
868
1320
  declare function createClient(config: ClientConfig): Client;
869
1321
 
870
- export { AuthClient, type AuthConfig, CacheClient, type CacheDeleteRequest, type CacheDeleteResponse, type CacheGetRequest, type CacheGetResponse, type CacheHealthResponse, type CacheMultiGetRequest, type CacheMultiGetResponse, type CachePutRequest, type CachePutResponse, type CacheScanRequest, type CacheScanResponse, type Client, type ClientConfig, type CloseHandler, type ColumnDefinition, DBClient, type Entity, type ErrorHandler, type FindOptions, type FunctionResponse, FunctionsClient, type FunctionsClientConfig, HttpClient, LocalStorageAdapter, MemoryStorage, type MessageHandler, NetworkClient, type NetworkErrorCallback, type NetworkErrorContext, type NetworkStatus, type PeerInfo, type PresenceMember, type PresenceOptions, type PresenceResponse, type ProxyRequest, type ProxyResponse, PubSubClient, type PubSubMessage, QueryBuilder, type QueryResponse, Repository, SDKError, type SelectOptions, type StorageAdapter, StorageClient, type StoragePinRequest, type StoragePinResponse, type StorageStatus, type StorageUploadResponse, type SubscribeOptions, Subscription, type SuccessResponse, type TransactionOp, type TransactionRequest, WSClient, type WhoAmI, createClient, extractPrimaryKey, extractTableName };
1322
+ export { AuthClient$1 as AuthClient, type AuthConfig, CacheClient, type CacheDeleteRequest, type CacheDeleteResponse, type CacheGetRequest, type CacheGetResponse, type CacheHealthResponse, type CacheMultiGetRequest, type CacheMultiGetResponse, type CachePutRequest, type CachePutResponse, type CacheScanRequest, type CacheScanResponse, type Client, type ClientConfig, type CloseHandler, type ColumnDefinition, DBClient, type DeleteResult, type DeleteSecretResponse, type EncryptedData, type Entity, type ErrorHandler, type FanOutResult, type FindOptions, type FunctionResponse, FunctionsClient, type FunctionsClientConfig, type GetSecretResponse, type ChallengeResponse as GuardianChallengeResponse, GuardianClient, type GuardianEndpoint, GuardianError, type GuardianErrorCode, type HealthResponse as GuardianHealthResponse, type GuardianInfo, type SessionResponse as GuardianSessionResponse, type StatusResponse as GuardianStatusResponse, HttpClient, KEY_SIZE, type ListResult, type ListSecretsResponse, LocalStorageAdapter, MemoryStorage, type MessageHandler, NONCE_SIZE, NetworkClient, type NetworkErrorCallback, type NetworkErrorContext, type NetworkStatus, type PeerInfo, type PresenceMember, type PresenceOptions, type PresenceResponse, type ProxyRequest, type ProxyResponse, PubSubClient, type PubSubMessage, type PullResponse, type PushResponse, QueryBuilder, type QueryResponse, Repository, type RetrieveResult, SDKError, type SecretEntry, type SecretMeta, type SelectOptions, type SerializedEncryptedData, type Share as ShamirShare, type StorageAdapter, StorageClient, type StoragePinRequest, type StoragePinResponse, type StorageStatus, type StorageUploadResponse, type StoreResult, type StoreSecretResponse, type SubscribeOptions, Subscription, type SuccessResponse, TAG_SIZE, type TransactionOp, type TransactionRequest, AuthClient as VaultAuthClient, VaultClient, type VaultConfig, type GuardianResult as VaultGuardianResult, WSClient, type WhoAmI, adaptiveThreshold, clearKey, createClient, decrypt, decryptString, deriveKeyHKDF, deserializeAndDecrypt, deserialize as deserializeEncrypted, encrypt, encryptAndSerialize, encryptString, fromBase64 as encryptedFromBase64, fromHex as encryptedFromHex, toBase64 as encryptedToBase64, toHex as encryptedToHex, extractPrimaryKey, extractTableName, fanOut, fanOutIndexed, generateKey, generateNonce, isValidEncryptedData, serialize as serializeEncrypted, combine as shamirCombine, split as shamirSplit, withRetry, withTimeout, writeQuorum };