@hsuite/smart-engines-sdk 3.5.0 → 3.6.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/dist/index.js CHANGED
@@ -5674,7 +5674,7 @@ var CreateAccountRequestSchema = zod.z.object({
5674
5674
  * Smart node security mode for the account key structure.
5675
5675
  * - 'partial': threshold(2, [appOwnerKey, tssKeyList]) — co-control
5676
5676
  * - 'full': TSS KeyList only — full validator network control
5677
- * Default: 'full' (Arc 5 §7.5.2: 'none' removed).
5677
+ * @defaultValue 'full'
5678
5678
  */
5679
5679
  securityMode: zod.z.enum(["partial", "full"]).default("full"),
5680
5680
  /**
@@ -6701,14 +6701,34 @@ function createHttpClient(config) {
6701
6701
  throw new SdkHttpError(`Upload error: ${err.message}`, 0, error);
6702
6702
  }
6703
6703
  }
6704
+ let reauthInFlight = null;
6705
+ async function withAuthRetry(path, op) {
6706
+ try {
6707
+ return await op();
6708
+ } catch (error) {
6709
+ const refreshable = !!config.onUnauthorized && !path.startsWith("/api/auth/") && error instanceof SdkHttpError && error.statusCode === 401;
6710
+ if (!refreshable) throw error;
6711
+ if (!reauthInFlight) {
6712
+ reauthInFlight = Promise.resolve(config.onUnauthorized()).finally(() => {
6713
+ reauthInFlight = null;
6714
+ });
6715
+ }
6716
+ try {
6717
+ await reauthInFlight;
6718
+ } catch {
6719
+ throw error;
6720
+ }
6721
+ return await op();
6722
+ }
6723
+ }
6704
6724
  const client = {
6705
- post: (path, body) => request("POST", path, body),
6706
- get: (path) => request("GET", path),
6707
- put: (path, body) => request("PUT", path, body),
6708
- patch: (path, body) => request("PATCH", path, body),
6709
- delete: (path) => request("DELETE", path),
6710
- getText,
6711
- upload: ((path, file, filename, metadata, fieldName) => upload(path, file, filename, metadata, fieldName)),
6725
+ post: (path, body) => withAuthRetry(path, () => request("POST", path, body)),
6726
+ get: (path) => withAuthRetry(path, () => request("GET", path)),
6727
+ put: (path, body) => withAuthRetry(path, () => request("PUT", path, body)),
6728
+ patch: (path, body) => withAuthRetry(path, () => request("PATCH", path, body)),
6729
+ delete: (path) => withAuthRetry(path, () => request("DELETE", path)),
6730
+ getText: (path) => withAuthRetry(path, () => getText(path)),
6731
+ upload: ((path, file, filename, metadata, fieldName) => withAuthRetry(path, () => upload(path, file, filename, metadata, fieldName))),
6712
6732
  setAuthToken,
6713
6733
  getAuthToken
6714
6734
  };
@@ -7116,8 +7136,8 @@ var ValidatorAuthClient = class {
7116
7136
  *
7117
7137
  * Structurally typed against the surface of xrpl's `Wallet` — see the
7118
7138
  * comment on {@link HederaSigner} for the "no direct import" rationale.
7119
- * Accepts both the modern `{ signedTransaction }` envelope and the
7120
- * legacy bare-string return shape.
7139
+ * Accepts both the `{ signedTransaction }` envelope and the bare-string
7140
+ * return shapes that xrpl signer libraries expose.
7121
7141
  *
7122
7142
  * @param challenge - Challenge string from validator
7123
7143
  * @param wallet - XRPL Wallet instance (or compatible signer)
@@ -7360,6 +7380,44 @@ var SubscriptionClient = class {
7360
7380
  }
7361
7381
  };
7362
7382
 
7383
+ // src/faucet/index.ts
7384
+ var faucet_exports = {};
7385
+ __export(faucet_exports, {
7386
+ FaucetClient: () => FaucetClient
7387
+ });
7388
+ var FaucetClient = class {
7389
+ constructor(http) {
7390
+ this.http = http;
7391
+ }
7392
+ http;
7393
+ /**
7394
+ * Request a signing challenge for a recipient address. The returned
7395
+ * `message` must be signed by the key controlling `recipientAddress`.
7396
+ */
7397
+ async requestChallenge(chain, recipientAddress) {
7398
+ return this.http.post("/faucet/hsuite/challenge", { chain, recipientAddress });
7399
+ }
7400
+ /**
7401
+ * Submit a signed challenge to dispense HST. The result is a discriminated
7402
+ * union on `status` — branch on `'dispensed' | 'trustline_required' |
7403
+ * 'rate_limited'`. On `'trustline_required'`, set the returned trust line on
7404
+ * the recipient and re-dispense with a fresh challenge.
7405
+ */
7406
+ async dispense(req) {
7407
+ return this.http.post("/faucet/hsuite", req);
7408
+ }
7409
+ /**
7410
+ * Get today's dispense status for a recipient (e.g. amount already
7411
+ * dispensed today).
7412
+ */
7413
+ async getStatus(chain, recipientAddress) {
7414
+ const params = new URLSearchParams();
7415
+ params.append("chain", chain);
7416
+ params.append("recipientAddress", recipientAddress);
7417
+ return this.http.get(`/faucet/hsuite/status?${params.toString()}`);
7418
+ }
7419
+ };
7420
+
7363
7421
  // src/tss/index.ts
7364
7422
  var TSSClient = class {
7365
7423
  constructor(http) {
@@ -7367,20 +7425,29 @@ var TSSClient = class {
7367
7425
  }
7368
7426
  http;
7369
7427
  /**
7370
- * Create a multi-sig entity with TSS
7428
+ * Create a multi-sig entity via a synchronous DKG ceremony.
7429
+ *
7430
+ * @param options Entity-creation parameters (chain, threshold, participants).
7431
+ * @returns The created entity's identity (ids + group public keys).
7371
7432
  */
7372
7433
  async createEntity(options) {
7373
7434
  return this.http.post("/tss/entity/create", options);
7374
7435
  }
7375
7436
  /**
7376
- * Reshare keys when cluster membership changes.
7377
- * Redistributes secret shares WITHOUT changing public keys.
7437
+ * Reshare keys when cluster membership changes. Redistributes secret shares
7438
+ * WITHOUT changing public keys.
7439
+ *
7440
+ * @param request The new membership / threshold to reshare to.
7441
+ * @returns The reshare outcome.
7378
7442
  */
7379
7443
  async reshareCluster(request) {
7380
7444
  return this.http.post("/tss/cluster/reshare", request);
7381
7445
  }
7382
7446
  /**
7383
- * Get entity details by ID
7447
+ * Get entity details by id.
7448
+ *
7449
+ * @param entityId The entity id to look up.
7450
+ * @returns The entity's details.
7384
7451
  */
7385
7452
  async getEntity(entityId) {
7386
7453
  return this.http.get(`/tss/entity/${encodePathParam(entityId)}`);
@@ -7389,55 +7456,71 @@ var TSSClient = class {
7389
7456
  * Sign a transaction using MPC.
7390
7457
  *
7391
7458
  * Routes to `POST /api/v3/tss/hedera/sign-mpc`. Only `'hedera'` is wired
7392
- * server-side today (see
7393
- * `apps/smart-validator/src/tss/tss.controller.ts:279`); other chain
7394
- * signing paths run via their own controllers (XRPL multisig, Polkadot
7395
- * MPC) and are not exposed through this sub-client. The `chain` field is
7396
- * carried into the request body so the validator can log + route, but
7397
- * any non-`'hedera'` value will 404.
7459
+ * server-side; other chain signing paths run via their own controllers (XRPL
7460
+ * multisig, Polkadot MPC) and are not exposed through this sub-client. The
7461
+ * `chain` field is carried into the request body so the validator can log +
7462
+ * route, but any non-`'hedera'` value will 404.
7463
+ *
7464
+ * @param request The MPC signing request; `chain` is forced to `'hedera'`.
7465
+ * @returns The MPC signing result.
7398
7466
  */
7399
7467
  async signMPC(request) {
7400
7468
  const chain = "hedera";
7401
7469
  return this.http.post(`/tss/${chain}/sign-mpc`, { ...request, chain });
7402
7470
  }
7403
7471
  /**
7404
- * Get known validators and their public keys
7472
+ * Get known validators and their public keys.
7473
+ *
7474
+ * @returns The validator list with public keys.
7405
7475
  */
7406
7476
  async getValidators() {
7407
7477
  return this.http.get("/tss/validators");
7408
7478
  }
7409
7479
  /**
7410
- * Force announcement of this node's public key
7480
+ * Force announcement of this node's public key.
7481
+ *
7482
+ * @returns Whether the announcement was accepted, plus a status message.
7411
7483
  */
7412
7484
  async announceKey() {
7413
7485
  return this.http.post("/tss/announce", {});
7414
7486
  }
7415
7487
  /**
7416
- * Get TSS statistics
7488
+ * Get TSS statistics.
7489
+ *
7490
+ * @returns Aggregate TSS statistics.
7417
7491
  */
7418
7492
  async getStats() {
7419
7493
  return this.http.get("/tss/stats");
7420
7494
  }
7421
7495
  /**
7422
- * List all TSS entities
7496
+ * List all TSS entities.
7497
+ *
7498
+ * @returns The full entity list.
7423
7499
  */
7424
7500
  async listEntities() {
7425
7501
  return this.http.get("/tss/entities");
7426
7502
  }
7427
7503
  /**
7428
- * TSS health check
7504
+ * TSS health check.
7505
+ *
7506
+ * @returns The TSS subsystem health report.
7429
7507
  */
7430
7508
  async getHealth() {
7431
7509
  return this.http.get("/tss/health");
7432
7510
  }
7433
7511
  /**
7434
- * List DKG ceremonies and their statistics
7512
+ * List DKG ceremonies and their statistics.
7513
+ *
7514
+ * @returns The ceremony list.
7435
7515
  */
7436
7516
  async listCeremonies() {
7437
7517
  return this.http.get("/tss/multisig/ceremonies");
7438
7518
  }
7439
7519
  /**
7440
- * Get multi-sig transaction status by transaction ID
7520
+ * Get multi-sig transaction status by transaction id.
7521
+ *
7522
+ * @param txId The multi-sig transaction id.
7523
+ * @returns The current status of that transaction.
7441
7524
  */
7442
7525
  async getMultiSigStatus(txId) {
7443
7526
  return this.http.get(`/tss/multisig/transactions/${encodePathParam(txId)}`);
@@ -7448,6 +7531,9 @@ var TSSClient = class {
7448
7531
  * Server returns 202 + `{ jobId, statusUrl, status: 'pending' }` immediately;
7449
7532
  * the DKG ceremony runs in the background. Poll {@link getJob} until the
7450
7533
  * status reaches `'success'` or `'failed'`.
7534
+ *
7535
+ * @param options Entity-creation parameters.
7536
+ * @returns A job descriptor (`jobId`, `statusUrl`, initial status).
7451
7537
  */
7452
7538
  async createEntityAsync(options) {
7453
7539
  return this.http.post("/tss/entity/create/async", options);
@@ -7455,6 +7541,9 @@ var TSSClient = class {
7455
7541
  /**
7456
7542
  * Async-job variant of {@link reshareCluster}. Returns 202 + a polling
7457
7543
  * descriptor; resharing runs in the background.
7544
+ *
7545
+ * @param request The new membership / threshold to reshare to.
7546
+ * @returns A job descriptor to poll via {@link getJob}.
7458
7547
  */
7459
7548
  async reshareClusterAsync(request) {
7460
7549
  return this.http.post("/tss/cluster/reshare/async", request);
@@ -7462,6 +7551,9 @@ var TSSClient = class {
7462
7551
  /**
7463
7552
  * Poll the status of an async TSS-ceremony job kicked off via
7464
7553
  * {@link createEntityAsync} or {@link reshareClusterAsync}.
7554
+ *
7555
+ * @param jobId The job id returned by the async kickoff call.
7556
+ * @returns The job's current status (and result once terminal).
7465
7557
  */
7466
7558
  async getJob(jobId) {
7467
7559
  return this.http.get(`/tss/jobs/${encodePathParam(jobId)}`);
@@ -7474,6 +7566,10 @@ var TSSClient = class {
7474
7566
  * Payload constraints (enforced server-side):
7475
7567
  * - even-length lowercase hex
7476
7568
  * - ≥32 bytes, ≤8KB
7569
+ *
7570
+ * @param appId The smart-app entity id to sign as.
7571
+ * @param request The hex payload to sign.
7572
+ * @returns The aggregate signature over the payload.
7477
7573
  */
7478
7574
  async signForApp(appId, request) {
7479
7575
  return this.http.post(`/tss/entity/${encodePathParam(appId)}/sign`, request);
@@ -8546,25 +8642,29 @@ var DeploymentClient = class {
8546
8642
  return this.http.get(`/api/deployment/apps/${encodePathParam(appId)}`);
8547
8643
  }
8548
8644
  /**
8549
- * Update app configuration. Runtime effect lands in PR-H.
8645
+ * Update app configuration.
8646
+ *
8647
+ * @param appId - The app to update.
8648
+ * @param updates - Partial deploy-request fields to apply.
8649
+ * @returns The updated app info.
8550
8650
  */
8551
8651
  async update(appId, updates) {
8552
8652
  return this.http.put(`/api/deployment/apps/${encodePathParam(appId)}`, updates);
8553
8653
  }
8554
8654
  /**
8555
- * Delete an app. Runtime effect (namespace teardown) lands in PR-H.
8655
+ * Delete an app (runtime effect: namespace teardown).
8556
8656
  */
8557
8657
  async delete(appId) {
8558
8658
  return this.http.delete(`/api/deployment/apps/${encodePathParam(appId)}`);
8559
8659
  }
8560
8660
  /**
8561
- * Suspend an app. Runtime effect (scale to zero) lands in PR-H.
8661
+ * Suspend an app (runtime effect: scale to zero).
8562
8662
  */
8563
8663
  async suspend(appId) {
8564
8664
  return this.http.post(`/api/deployment/apps/${encodePathParam(appId)}/suspend`, {});
8565
8665
  }
8566
8666
  /**
8567
- * Resume a suspended app. Runtime effect (scale back up) lands in PR-H.
8667
+ * Resume a suspended app (runtime effect: scale back up).
8568
8668
  */
8569
8669
  async resume(appId) {
8570
8670
  return this.http.post(`/api/deployment/apps/${encodePathParam(appId)}/resume`, {});
@@ -8613,7 +8713,7 @@ var DeploymentClient = class {
8613
8713
  return this.http.getText(`/api/deployment/apps/${encodePathParam(appId)}/metrics`);
8614
8714
  }
8615
8715
  /**
8616
- * Rotate the smart-app's tenant-secret KEK (ADR-011 Phase 6).
8716
+ * Rotate the smart-app's tenant-secret KEK.
8617
8717
  *
8618
8718
  * Re-encrypts every `runtime.env` envelope at the new KEK version
8619
8719
  * transparently. Previous versions remain valid until explicitly
@@ -8626,7 +8726,7 @@ var DeploymentClient = class {
8626
8726
  );
8627
8727
  }
8628
8728
  /**
8629
- * Revoke a tenant-secret KEK version (ADR-011 Phase 6 emergency burn).
8729
+ * Revoke a tenant-secret KEK version (emergency burn).
8630
8730
  *
8631
8731
  * Envelopes at the revoked version become operationally dead —
8632
8732
  * decryption inside the smart-app pod fails. Owner-only and
@@ -8879,6 +8979,8 @@ var SmartEngineClient = class _SmartEngineClient {
8879
8979
  // ========== Sub-Clients ==========
8880
8980
  /** Application subscription management */
8881
8981
  subscription;
8982
+ /** Testnet HST faucet (challenge -> sign -> dispense) */
8983
+ faucet;
8882
8984
  /** Threshold Signature Scheme — chain-agnostic MPC operations */
8883
8985
  tss;
8884
8986
  /** IPFS decentralized file storage */
@@ -8937,6 +9039,7 @@ var SmartEngineClient = class _SmartEngineClient {
8937
9039
  timeout: config.timeout
8938
9040
  });
8939
9041
  this.subscription = new SubscriptionClient(this.http);
9042
+ this.faucet = new FaucetClient(this.http);
8940
9043
  this.tss = new TSSClient(this.http);
8941
9044
  this.ipfs = new IPFSClient(this.http);
8942
9045
  this.transactions = new TransactionsClient(this.txHttp);
@@ -8992,13 +9095,17 @@ var SmartEngineClient = class _SmartEngineClient {
8992
9095
  });
8993
9096
  }
8994
9097
  /**
8995
- * Connect to the smart-engines network with auto-discovery and authentication
9098
+ * Connect to the smart-engines network with auto-discovery and authentication.
8996
9099
  *
8997
- * This method:
8998
- * 1. Discovers validators via HCS registry topic
8999
- * 2. Selects a random validator with API endpoint
9000
- * 3. Authenticates with Web3-style challenge-response
9001
- * 4. Returns a configured client ready to use
9100
+ * Steps:
9101
+ * 1. Discovers validators via the HCS registry topic.
9102
+ * 2. Selects a random validator with an API endpoint.
9103
+ * 3. Authenticates with Web3-style challenge-response.
9104
+ * 4. Returns a configured client ready to use.
9105
+ *
9106
+ * @param config - Network, registry topic, and auth signer config.
9107
+ * @returns The configured client, the chosen validator, and the auth session.
9108
+ * @throws SmartEngineError 503 if no validator with an API endpoint is found.
9002
9109
  */
9003
9110
  static async connectToNetwork(config) {
9004
9111
  const allowInsecure = config.allowInsecure ?? false;
@@ -9035,18 +9142,22 @@ var SmartEngineClient = class _SmartEngineClient {
9035
9142
  return { client, validator, session };
9036
9143
  }
9037
9144
  /**
9038
- * Connect to the smart-engines network via the **service-registry**
9039
- * (PR-1 of the cluster-discovery arc). Preferred over
9040
- * {@link connectToNetwork} once the validator pods in the target network
9041
- * have published their cluster endpoints the SDK auto-balances across
9042
- * the active cluster set and rides permissionless cluster join/leave
9043
- * without code edits.
9145
+ * Connect to the smart-engines network via the **service-registry**.
9146
+ * Preferred over {@link connectToNetwork} once the validator pods in the
9147
+ * target network have published their cluster endpoints the SDK
9148
+ * auto-balances across the active cluster set and rides permissionless
9149
+ * cluster join/leave without code edits.
9044
9150
  *
9045
- * Fallback ladder (per `docs/ops/HANDOFF-service-registry-distribution-layer.md` §6):
9151
+ * Resolution ladder:
9046
9152
  * 1. HTTP fetch `/api/v3/discovery/clusters` from each bootstrap seed.
9047
9153
  * 2. (Optional) HCS trust-anchor membership cross-check.
9048
9154
  * 3. Random-pick over the verified set.
9049
9155
  *
9156
+ * @param config - Seed + auth config. See {@link ClusterConnectionConfig}.
9157
+ * @returns The configured client, the selected cluster, and the auth session.
9158
+ * @throws SmartEngineError 400 if neither `bootstrap` nor `network` is given.
9159
+ * @throws SmartEngineError 503 if no active cluster can be reached.
9160
+ *
9050
9161
  * @example Zero-config (recommended for smart-app callers)
9051
9162
  * ```ts
9052
9163
  * const { client, cluster, session } = await SmartEngineClient.connectToCluster({
@@ -9175,17 +9286,11 @@ var SmartEngineClient = class _SmartEngineClient {
9175
9286
  return this.http.post("/tokens/mint", validated);
9176
9287
  }
9177
9288
  /**
9178
- * Get token information.
9289
+ * Get token information for a token on the given chain.
9179
9290
  *
9180
- * Route `GET /api/v3/tokens/:chain/:tokenId` is registered twice on the
9181
- * validator: by `ValidatorController` at
9182
- * `apps/smart-validator/src/validator.controller.ts:497` and by
9183
- * `TokenMigrationController` at
9184
- * `apps/smart-validator/src/token-migration/token-migration.controller.ts:173`.
9185
- * Nest resolves routes in `controllers: [...]` order — `ValidatorController`
9186
- * is registered first (`apps/smart-validator/src/smart-validator.module.ts:1222`),
9187
- * so `multiChain.getTokenInfo(chain, tokenId)` wins and the
9188
- * token-migration handler is unreachable via this path.
9291
+ * @param chain - Chain identifier (e.g. `'hedera'`, `'xrpl'`).
9292
+ * @param tokenId - Chain-native token identifier.
9293
+ * @returns Token metadata and supply information.
9189
9294
  */
9190
9295
  async getTokenInfo(chain, tokenId) {
9191
9296
  return this.http.get(`/tokens/${encodePathParam(chain)}/${encodePathParam(tokenId)}`);
@@ -9414,8 +9519,7 @@ var DomainsClient = class {
9414
9519
  }
9415
9520
  /**
9416
9521
  * Generate a verification token. Server accepts one of `dns-txt`,
9417
- * `dns-cname`, `http-file`, `email` (see controller Swagger enum at
9418
- * `apps/smart-gateway/src/domains/domains.controller.ts:226-234`).
9522
+ * `dns-cname`, `http-file`, `email`.
9419
9523
  */
9420
9524
  async generateVerificationToken(domain, method) {
9421
9525
  return this.http.post(`/domains/${encodePathParam(domain)}/verification`, { method });
@@ -9539,10 +9643,8 @@ var HealthClient = class {
9539
9643
  }
9540
9644
  http;
9541
9645
  /**
9542
- * Per-cluster aggregate health probe. Wraps
9543
- * `GET /api/v3/cluster/health` see
9544
- * `apps/smart-gateway/src/health/health.controller.ts:213-263`. Returns
9545
- * local validator + host + genesis state in a single payload.
9646
+ * Per-cluster aggregate health probe. Wraps `GET /api/v3/cluster/health`.
9647
+ * Returns local validator + host + genesis state in a single payload.
9546
9648
  */
9547
9649
  async getCluster() {
9548
9650
  return this.http.get("/cluster/health");
@@ -9586,11 +9688,28 @@ var SmartGatewayClient = class {
9586
9688
  return this.http.get("/status");
9587
9689
  }
9588
9690
  /**
9589
- * Check gateway readiness. Returns either `{ status: 'ready', ... }` with
9590
- * a verified host count or `{ status: 'not_ready', reason, ... }`.
9691
+ * Check gateway readiness. Resolves to either `{ status: 'ready', ... }`
9692
+ * with a verified host count or `{ status: 'not_ready', reason, ... }`.
9693
+ *
9694
+ * NOTE: `/api/v3/ready` returns **HTTP 503** when not ready (so load
9695
+ * balancers / k8s probes drain the origin). This method unwraps that 503's
9696
+ * body and still RESOLVES to a `GatewayReadinessResponse` — it does not
9697
+ * throw for a not-ready gateway. Genuine errors (non-readiness 503s, 5xx,
9698
+ * network) still throw.
9591
9699
  */
9592
9700
  async getReadiness() {
9593
- return this.http.get("/ready");
9701
+ try {
9702
+ return await this.http.get("/ready");
9703
+ } catch (err) {
9704
+ if (err instanceof SdkHttpError && err.statusCode === 503) {
9705
+ const d = err.details;
9706
+ const body = d?.context ?? d;
9707
+ if (body?.status === "not_ready") {
9708
+ return body;
9709
+ }
9710
+ }
9711
+ throw err;
9712
+ }
9594
9713
  }
9595
9714
  /** Check gateway liveness. */
9596
9715
  async getLiveness() {
@@ -10287,23 +10406,11 @@ var StorageClient = class {
10287
10406
  return this.http.delete(`/api/storage/${encodePathParam(appId)}/${encodePathParam(cid)}`);
10288
10407
  }
10289
10408
  /**
10290
- * Get file info.
10409
+ * List all files for the app.
10291
10410
  *
10292
- * @deprecated The smart-host storage controller does not expose a
10293
- * bare-CID metadata route — every metadata lookup must go through
10294
- * `getMetadata(cid)` (`/api/storage/:appId/metadata/:cid`) or the
10295
- * stream body via `download(cid)`. This alias forwards to `download`
10296
- * for back-compat; **scheduled for removal in 4.0.0**.
10297
- */
10298
- async getFile(cid) {
10299
- return this.download(cid);
10300
- }
10301
- /**
10302
- * List all files for the app
10303
- *
10304
- * @param pagination.offset Server reads `offset`; the legacy `skip`
10305
- * option was a client-only synonym that the server silently ignored.
10306
- * Use `offset` going forward.
10411
+ * @param pagination - Optional `limit` and `offset` (the server reads
10412
+ * `offset` for pagination).
10413
+ * @returns The file list and total count.
10307
10414
  */
10308
10415
  async listFiles(pagination) {
10309
10416
  const appId = this.getAppId();
@@ -10684,6 +10791,13 @@ var BaasClient = class _BaasClient {
10684
10791
  http;
10685
10792
  /** Last HTTP error (for getHttpHealth) */
10686
10793
  lastHttpError;
10794
+ /**
10795
+ * Auth options from the last {@link authenticate} call, retained so the
10796
+ * client can transparently re-authenticate when the session token expires
10797
+ * (the http client invokes {@link reauthenticate} on a 401). Undefined until
10798
+ * the first successful authenticate.
10799
+ */
10800
+ authContext;
10687
10801
  // ========== Sub-Clients ==========
10688
10802
  /** Trustless database with state proofs and Merkle verification */
10689
10803
  db;
@@ -10713,7 +10827,11 @@ var BaasClient = class _BaasClient {
10713
10827
  const baseUrlWithPrefix = this.pathPrefix ? this.hostUrl.replace(/\/$/, "") + this.pathPrefix : this.hostUrl;
10714
10828
  this.http = createHttpClient({
10715
10829
  baseUrl: baseUrlWithPrefix,
10716
- timeout: this.timeout
10830
+ timeout: this.timeout,
10831
+ // Transparent session refresh: on a 401, re-run the challenge-response
10832
+ // with the retained signer and retry once. No-op until authenticate() has
10833
+ // been called (authContext set). Excludes /api/auth/* (see http client).
10834
+ onUnauthorized: () => this.reauthenticate()
10717
10835
  });
10718
10836
  const getAppId = () => this.requireAppId();
10719
10837
  this.db = new DatabaseClient(this.http, getAppId);
@@ -10849,6 +10967,7 @@ var BaasClient = class _BaasClient {
10849
10967
  */
10850
10968
  async authenticate(options) {
10851
10969
  const { chain, walletAddress, publicKey, signFn } = options;
10970
+ this.authContext = options;
10852
10971
  let challenge;
10853
10972
  try {
10854
10973
  challenge = await this.http.post("/api/auth/challenge", {
@@ -10873,6 +10992,30 @@ var BaasClient = class _BaasClient {
10873
10992
  this.http.setAuthToken(result.token);
10874
10993
  return result;
10875
10994
  }
10995
+ /**
10996
+ * Re-run the challenge-response with the retained signer to mint a fresh
10997
+ * session token. Invoked by the http client's `onUnauthorized` hook when a
10998
+ * request 401s because the token expired — so long-lived clients keep working
10999
+ * without the caller re-implementing refresh. No-op if {@link authenticate}
11000
+ * was never called. The `/api/auth/*` calls below are excluded from the http
11001
+ * client's 401-retry path, so this can never recurse.
11002
+ */
11003
+ async reauthenticate() {
11004
+ const ctx = this.authContext;
11005
+ if (!ctx) return;
11006
+ const challenge = await this.http.post("/api/auth/challenge", {
11007
+ chain: ctx.chain,
11008
+ walletAddress: ctx.walletAddress,
11009
+ appId: this.appId
11010
+ });
11011
+ const signature = await ctx.signFn(challenge.message);
11012
+ const result = await this.http.post("/api/auth/verify", {
11013
+ challengeId: challenge.challengeId,
11014
+ signature,
11015
+ publicKey: ctx.publicKey
11016
+ });
11017
+ this.http.setAuthToken(result.token);
11018
+ }
10876
11019
  /** Validate the current session */
10877
11020
  async validateSession() {
10878
11021
  this.requireAuth();
@@ -11149,9 +11292,6 @@ function validateEnvelopeSchema(envelope) {
11149
11292
  if (version === "kyber-aes-v1") {
11150
11293
  return validateKyberAesV1(envelope);
11151
11294
  }
11152
- if (version === "aes-v0") {
11153
- return validateAesV0(envelope);
11154
- }
11155
11295
  return {
11156
11296
  ok: false,
11157
11297
  reason: `unknown envelope version: ${JSON.stringify(version)}`
@@ -11245,38 +11385,6 @@ function validateKyberAesV1(env) {
11245
11385
  }
11246
11386
  return { ok: true, version: "kyber-aes-v1" };
11247
11387
  }
11248
- function validateAesV0(env) {
11249
- if (!isNonEmptyString(env.aesIv)) {
11250
- return { ok: false, reason: "aesIv must be a non-empty base64 string" };
11251
- }
11252
- const ivBytes = tryDecodeBase64(env.aesIv);
11253
- if (!ivBytes) return { ok: false, reason: "aesIv is not valid base64" };
11254
- if (ivBytes.length !== AES_IV_LEN) {
11255
- return {
11256
- ok: false,
11257
- reason: `aesIv length ${ivBytes.length} != expected ${AES_IV_LEN} (AES-GCM 96-bit nonce)`
11258
- };
11259
- }
11260
- if (typeof env.aesCiphertext !== "string") {
11261
- return { ok: false, reason: "aesCiphertext must be a base64 string" };
11262
- }
11263
- if (env.aesCiphertext.length > 0) {
11264
- const ctBytes = tryDecodeBase64(env.aesCiphertext);
11265
- if (!ctBytes) return { ok: false, reason: "aesCiphertext is not valid base64" };
11266
- }
11267
- if (!isNonEmptyString(env.aesAuthTag)) {
11268
- return { ok: false, reason: "aesAuthTag must be a non-empty base64 string" };
11269
- }
11270
- const tagBytes = tryDecodeBase64(env.aesAuthTag);
11271
- if (!tagBytes) return { ok: false, reason: "aesAuthTag is not valid base64" };
11272
- if (tagBytes.length !== AES_TAG_LEN) {
11273
- return {
11274
- ok: false,
11275
- reason: `aesAuthTag length ${tagBytes.length} != expected ${AES_TAG_LEN} (AES-GCM 128-bit tag)`
11276
- };
11277
- }
11278
- return { ok: true, version: "aes-v0" };
11279
- }
11280
11388
 
11281
11389
  // src/pqc-verify-envelope/verify-pqc-envelope.ts
11282
11390
  var KYBER_MIN_TIMESTAMP_MS = 17040672e5;
@@ -11295,10 +11403,10 @@ async function verifyPqcEnvelope(envelope, options = {}) {
11295
11403
  version,
11296
11404
  schemaValid: true,
11297
11405
  base64Valid: true,
11298
- // computed below for kyber-aes-v1; legacy has no encryptedAt so treat as plausible.
11406
+ // Set to false below if the timestamp plausibility check fails.
11299
11407
  timestampPlausible: true
11300
11408
  };
11301
- if (version === "kyber-aes-v1") {
11409
+ {
11302
11410
  details.kemAlgorithm = env.kemAlgorithm;
11303
11411
  details.recipientPkFingerprint = env.recipientPkFingerprint;
11304
11412
  details.kdfLabel = env.kdfLabel;
@@ -12160,17 +12268,13 @@ var AgentRulesBuilder = class extends BaseRuleBuilder {
12160
12268
  return this;
12161
12269
  }
12162
12270
  // ────────────────────────────────────────────────────────────────────────
12163
- // PR F — Phase-6.6 AI atom shortcuts
12271
+ // AI atom shortcuts
12164
12272
  //
12165
12273
  // `MaxTradesPerWindow` and `RequireStructuredOutput` are optional atoms
12166
12274
  // (NOT registered as builtin organism modules) wired in the AI-inference
12167
12275
  // path of the smart-app's BaaS function. Attached here as canonical
12168
12276
  // `ModuleEntry`s so they ship inside the published rule and the cluster's
12169
12277
  // canonical evaluator can dispatch them.
12170
- //
12171
- // Atom sources:
12172
- // libs/rules-engine/src/atoms/max-trades-per-window.atom.ts
12173
- // libs/rules-engine/src/atoms/require-structured-output.atom.ts
12174
12278
  // ────────────────────────────────────────────────────────────────────────
12175
12279
  /**
12176
12280
  * Cap the agent at `maxTradesPerWindow` trades within a rolling `windowMs`
@@ -12282,7 +12386,7 @@ var module_ = {
12282
12386
  version: "1.0.0",
12283
12387
  config: withDexDefaults(config)
12284
12388
  })
12285
- // PR F — `agent` retired per Arc 6 Phase 6.5. Use `Rules.forAgent()` instead.
12389
+ // No `agent` module use `Rules.forAgent()` instead.
12286
12390
  };
12287
12391
 
12288
12392
  // src/rules/templates/index.ts
@@ -12770,6 +12874,7 @@ exports.DomainsClient = DomainsClient;
12770
12874
  exports.EntitiesClient = EntitiesClient;
12771
12875
  exports.EnvelopeClient = EnvelopeClient;
12772
12876
  exports.ErrorCode = ErrorCode;
12877
+ exports.FaucetClient = FaucetClient;
12773
12878
  exports.FeeConditionsSchema = FeeConditionsSchema;
12774
12879
  exports.FixedFeeConditionSchema = FixedFeeConditionSchema;
12775
12880
  exports.FractionalFeeConditionSchema = FractionalFeeConditionSchema;
@@ -12862,6 +12967,7 @@ exports.discovery = discovery_exports;
12862
12967
  exports.encodePathParam = encodePathParam;
12863
12968
  exports.envelope = envelope_exports;
12864
12969
  exports.fairLaunch = fairLaunch;
12970
+ exports.faucet = faucet_exports;
12865
12971
  exports.fetchRegistrySnapshot = fetchRegistrySnapshot;
12866
12972
  exports.forAccount = forAccount;
12867
12973
  exports.forAgent = forAgent;