@tinycloud/node-sdk 3.7.0-beta.1 → 3.7.0-beta.2

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.
@@ -1435,6 +1435,13 @@ declare class TinyCloudNode {
1435
1435
  /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
1436
1436
  private get siweDomain();
1437
1437
  private readonly invokeWithRuntimePermissions;
1438
+ /**
1439
+ * The session (key, issuer, proof) that signs an invokeAny call for `entries`:
1440
+ * the explicit revocation authority, else the covering non-primary runtime
1441
+ * grant, else the caller's session. Everything that re-signs the resulting
1442
+ * invocation must use this session's key.
1443
+ */
1444
+ private selectInvokeAnySession;
1438
1445
  private readonly invokeAnyWithRuntimePermissions;
1439
1446
  /**
1440
1447
  * Create a new TinyCloudNode instance.
@@ -1435,6 +1435,13 @@ declare class TinyCloudNode {
1435
1435
  /** SIWE domain — uses config override or defaults to app.tinycloud.xyz */
1436
1436
  private get siweDomain();
1437
1437
  private readonly invokeWithRuntimePermissions;
1438
+ /**
1439
+ * The session (key, issuer, proof) that signs an invokeAny call for `entries`:
1440
+ * the explicit revocation authority, else the covering non-primary runtime
1441
+ * grant, else the caller's session. Everything that re-signs the resulting
1442
+ * invocation must use this session's key.
1443
+ */
1444
+ private selectInvokeAnySession;
1438
1445
  private readonly invokeAnyWithRuntimePermissions;
1439
1446
  /**
1440
1447
  * Create a new TinyCloudNode instance.
@@ -1,7 +1,7 @@
1
1
  import { ReplicationOptions, PermissionEntry, TinyCloudSession, KVReplicaStorage, ServiceContext, IWasmBindings, WasmRecapEntry } from '@tinycloud/sdk-core';
2
2
  import { ReplicaConsentAnchor, AuthorityRefusal, ReplicationAuthority } from '@tinycloud/sdk-services';
3
3
  import { ReplicaSessionStamp, ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
4
- import { T as TinyCloudNode } from './TinyCloudNode-DrLNh4bs.cjs';
4
+ import { T as TinyCloudNode } from './TinyCloudNode-u_PobKS1.cjs';
5
5
 
6
6
  /** Constructor-time validation; the space-dependent secrets check runs at sign-in and open. */
7
7
  declare function assertValidReplicationConfig(replication: (ReplicationOptions & {
@@ -1,7 +1,7 @@
1
1
  import { ReplicationOptions, PermissionEntry, TinyCloudSession, KVReplicaStorage, ServiceContext, IWasmBindings, WasmRecapEntry } from '@tinycloud/sdk-core';
2
2
  import { ReplicaConsentAnchor, AuthorityRefusal, ReplicationAuthority } from '@tinycloud/sdk-services';
3
3
  import { ReplicaSessionStamp, ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
4
- import { T as TinyCloudNode } from './TinyCloudNode-BHiKCQ4W.js';
4
+ import { T as TinyCloudNode } from './TinyCloudNode-CclYdOh4.js';
5
5
 
6
6
  /** Constructor-time validation; the space-dependent secrets check runs at sign-in and open. */
7
7
  declare function assertValidReplicationConfig(replication: (ReplicationOptions & {
package/dist/core.cjs CHANGED
@@ -3886,17 +3886,7 @@ var _TinyCloudNode = class _TinyCloudNode {
3886
3886
  throw new Error("WASM binding does not support invokeAny");
3887
3887
  }
3888
3888
  const routedEntries = entries;
3889
- const operations = routedEntries.flatMap((entry) => {
3890
- const operation = this.operationFromInvokeAnyEntry(entry);
3891
- return operation ? [operation] : [];
3892
- });
3893
- const authorityCid = routedEntries.length === 1 ? routedEntries[0]?.revokeAuthorityCid : void 0;
3894
- const explicitGrant = authorityCid === void 0 ? void 0 : this.runtimePermissionGrants.find((grant2) => grant2.delegation.cid === authorityCid);
3895
- if (authorityCid !== void 0 && !explicitGrant) {
3896
- throw new Error(`Explicit revocation authority ${authorityCid} is not installed.`);
3897
- }
3898
- const grant = explicitGrant ?? this.findGrantForOperations(operations);
3899
- const invocationSession = explicitGrant ? explicitGrant.session : !grant || grant.provenance === "primary" ? session : grant.session;
3889
+ const { session: invocationSession, grant } = this.selectInvokeAnySession(session, entries);
3900
3890
  const caveatPreservingEntries = routedEntries.map(({ revokeAuthorityCid: _cid, ...entry }) => {
3901
3891
  const requested = this.operationFromInvokeAnyEntry(entry);
3902
3892
  const granted = grant && requested && grant.operations.find(
@@ -4134,6 +4124,27 @@ var _TinyCloudNode = class _TinyCloudNode {
4134
4124
  get siweDomain() {
4135
4125
  return this.config.domain ?? "app.tinycloud.xyz";
4136
4126
  }
4127
+ /**
4128
+ * The session (key, issuer, proof) that signs an invokeAny call for `entries`:
4129
+ * the explicit revocation authority, else the covering non-primary runtime
4130
+ * grant, else the caller's session. Everything that re-signs the resulting
4131
+ * invocation must use this session's key.
4132
+ */
4133
+ selectInvokeAnySession(session, entries) {
4134
+ const routedEntries = entries;
4135
+ const operations = routedEntries.flatMap((entry) => {
4136
+ const operation = this.operationFromInvokeAnyEntry(entry);
4137
+ return operation ? [operation] : [];
4138
+ });
4139
+ const authorityCid = routedEntries.length === 1 ? routedEntries[0]?.revokeAuthorityCid : void 0;
4140
+ const explicitGrant = authorityCid === void 0 ? void 0 : this.runtimePermissionGrants.find((grant2) => grant2.delegation.cid === authorityCid);
4141
+ if (authorityCid !== void 0 && !explicitGrant) {
4142
+ throw new Error(`Explicit revocation authority ${authorityCid} is not installed.`);
4143
+ }
4144
+ const grant = explicitGrant ?? this.findGrantForOperations(operations);
4145
+ const invocationSession = explicitGrant ? explicitGrant.session : !grant || grant.provenance === "primary" ? session : grant.session;
4146
+ return { session: invocationSession, grant };
4147
+ }
4137
4148
  /**
4138
4149
  * SharingService for receive-only access (no session required), bound to the
4139
4150
  * current service graph. This lets session-only users receive sharing links
@@ -6553,7 +6564,13 @@ var _TinyCloudNode = class _TinyCloudNode {
6553
6564
  async bindInvocationAudience(authorization, audience) {
6554
6565
  const session = this.currentTinyCloudSession() ?? this._activeServiceSession;
6555
6566
  if (session === void 0) throw new Error("Not signed in. Call signIn() first.");
6556
- return rewriteInvocationAudience(authorization, audience, session.jwk);
6567
+ const payload = JSON.parse(
6568
+ new TextDecoder().decode(base64UrlDecode(authorization.split(".")[1] ?? ""))
6569
+ );
6570
+ const did = (value) => String(value).split("#", 1)[0];
6571
+ const signer = [session, ...this.runtimePermissionGrants.map((grant) => grant.session)].find((candidate) => did(candidate.verificationMethod) === did(payload.iss));
6572
+ if (!signer) throw new Error("invocation issuer does not match a held session");
6573
+ return rewriteInvocationAudience(authorization, audience, signer.jwk);
6557
6574
  }
6558
6575
  /**
6559
6576
  * Connect a wallet to upgrade from session-only mode to wallet mode.
@@ -6888,23 +6905,25 @@ var _TinyCloudNode = class _TinyCloudNode {
6888
6905
  throw new Error("WASM binding does not support invocation CID computation");
6889
6906
  }
6890
6907
  const session = binding?.session ?? this.requireEncryptionSession();
6908
+ const entries = [
6909
+ {
6910
+ resource: input.networkId,
6911
+ service: "encryption",
6912
+ path: input.networkId,
6913
+ action: input.action
6914
+ }
6915
+ ];
6891
6916
  const headers = this.invokeAnyWithRuntimePermissions(
6892
6917
  session,
6893
- [
6894
- {
6895
- resource: input.networkId,
6896
- service: "encryption",
6897
- path: input.networkId,
6898
- action: input.action
6899
- }
6900
- ],
6918
+ entries,
6901
6919
  [input.facts]
6902
6920
  );
6921
+ const signingSession = this.selectInvokeAnySession(session, entries).session;
6903
6922
  const authorization = authorizationHeader(headers);
6904
6923
  const audienceBound = await rewriteInvocationAudience(
6905
6924
  authorization,
6906
6925
  input.targetNode,
6907
- session.jwk
6926
+ signingSession.jwk
6908
6927
  );
6909
6928
  binding?.graph.assertActive();
6910
6929
  return {
@@ -6957,7 +6976,11 @@ var _TinyCloudNode = class _TinyCloudNode {
6957
6976
  path: networkId,
6958
6977
  actions: ["tinycloud.encryption/decrypt"]
6959
6978
  }) : void 0;
6960
- throw new import_sdk_core11.DecryptTransportResponseError(response.status, permissionHint);
6979
+ throw new import_sdk_core11.DecryptTransportResponseError(
6980
+ response.status,
6981
+ permissionHint,
6982
+ response.status === 404 && networkId === this.getDefaultEncryptionNetworkId() && await response.text().catch(() => "") === "network not found" ? `Network not found: ${networkId}. Sign in again with a current SDK to create the account's encryption network.` : void 0
6983
+ );
6961
6984
  }
6962
6985
  return await response.json();
6963
6986
  }