@tinycloud/node-sdk 3.8.0 → 3.8.1-beta.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.
@@ -1191,6 +1191,12 @@ interface DelegateToResult {
1191
1191
  interface RuntimePermissionGrantOptions {
1192
1192
  /** Override expiry. ms-format string ("7d", "1h") or raw milliseconds. */
1193
1193
  expiry?: string | number;
1194
+ /**
1195
+ * Signs the prepared SIWE and returns the EIP-191 signature, in place of the connected signer's `signMessage`.
1196
+ * For a session whose wallet provider does not sign (an OpenKey session). The signature must recover to the
1197
+ * session's address.
1198
+ */
1199
+ signMessage?: (siwe: string) => Promise<string>;
1194
1200
  /** In-memory key snapshot captured when exact Share-key consent opened. */
1195
1201
  expectedSessionKey?: Readonly<TinyCloudSession["jwk"]>;
1196
1202
  }
@@ -2560,6 +2566,12 @@ declare class TinyCloudNode {
2560
2566
  private createDelegationViaRuntimeGrant;
2561
2567
  private resolvePermissionSpace;
2562
2568
  private expandPermissionEntries;
2569
+ /**
2570
+ * Checks the SIWE text a caller-supplied signer is asked to sign: it must be in canonical form (parsing and
2571
+ * re-serializing it gives the same bytes) and name the session's account and chain. The caller then checks the
2572
+ * signature against these exact bytes.
2573
+ */
2574
+ private assertRuntimeGrantMessage;
2563
2575
  /**
2564
2576
  * The current WASM child-delegation APIs accept action-only maps. Refuse any
2565
2577
  * constrained branch rather than signing a broader action-only child UCAN.
@@ -1191,6 +1191,12 @@ interface DelegateToResult {
1191
1191
  interface RuntimePermissionGrantOptions {
1192
1192
  /** Override expiry. ms-format string ("7d", "1h") or raw milliseconds. */
1193
1193
  expiry?: string | number;
1194
+ /**
1195
+ * Signs the prepared SIWE and returns the EIP-191 signature, in place of the connected signer's `signMessage`.
1196
+ * For a session whose wallet provider does not sign (an OpenKey session). The signature must recover to the
1197
+ * session's address.
1198
+ */
1199
+ signMessage?: (siwe: string) => Promise<string>;
1194
1200
  /** In-memory key snapshot captured when exact Share-key consent opened. */
1195
1201
  expectedSessionKey?: Readonly<TinyCloudSession["jwk"]>;
1196
1202
  }
@@ -2560,6 +2566,12 @@ declare class TinyCloudNode {
2560
2566
  private createDelegationViaRuntimeGrant;
2561
2567
  private resolvePermissionSpace;
2562
2568
  private expandPermissionEntries;
2569
+ /**
2570
+ * Checks the SIWE text a caller-supplied signer is asked to sign: it must be in canonical form (parsing and
2571
+ * re-serializing it gives the same bytes) and name the session's account and chain. The caller then checks the
2572
+ * signature against these exact bytes.
2573
+ */
2574
+ private assertRuntimeGrantMessage;
2563
2575
  /**
2564
2576
  * The current WASM child-delegation APIs accept action-only maps. Refuse any
2565
2577
  * constrained branch rather than signing a broader action-only child UCAN.
@@ -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 { ReplicaLocalEraseOutcome, ReplicaPurgeLocalCopyResult, ReplicaPurgeTrigger, ReplicaPurgeFailedEvent, ReplicaSessionStamp, ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
4
- import { T as TinyCloudNode } from './TinyCloudNode-k3TbBwwj.js';
4
+ import { T as TinyCloudNode } from './TinyCloudNode-BjJJIifr.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 & {
@@ -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 { ReplicaLocalEraseOutcome, ReplicaPurgeLocalCopyResult, ReplicaPurgeTrigger, ReplicaPurgeFailedEvent, ReplicaSessionStamp, ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
4
- import { T as TinyCloudNode } from './TinyCloudNode-DaD5vJhL.cjs';
4
+ import { T as TinyCloudNode } from './TinyCloudNode-BhWBbCay.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 & {
package/dist/core.cjs CHANGED
@@ -8508,7 +8508,7 @@ var _TinyCloudNode = class _TinyCloudNode {
8508
8508
  if (existingGrants.length > 0) {
8509
8509
  return existingGrants.map((grant) => grant.delegation);
8510
8510
  }
8511
- if (!this.signer) {
8511
+ if (!this.signer && options?.signMessage === void 0) {
8512
8512
  throw new Error(
8513
8513
  "grantRuntimePermissions requires wallet mode with a signer or privateKey."
8514
8514
  );
@@ -8572,7 +8572,13 @@ var _TinyCloudNode = class _TinyCloudNode {
8572
8572
  throw new Error("Prepared runtime permission targets a different session key.");
8573
8573
  }
8574
8574
  assertCapturedKey?.();
8575
- const signature = await this.signer.signMessage(prepared.siwe);
8575
+ if (options?.signMessage !== void 0) {
8576
+ this.assertRuntimeGrantMessage(prepared.siwe, session);
8577
+ }
8578
+ const signature = options?.signMessage !== void 0 ? await options.signMessage(prepared.siwe) : await this.signer.signMessage(prepared.siwe);
8579
+ if (options?.signMessage !== void 0 && !await (0, import_sdk_core11.verifyEip191MessageSignature)(prepared.siwe, signature, session.address)) {
8580
+ throw new Error("The signature does not match the account that owns this session.");
8581
+ }
8576
8582
  graph.assertActive();
8577
8583
  assertCapturedKey?.();
8578
8584
  const delegatedSession = this.wasmBindings.completeSessionSetup({
@@ -9390,6 +9396,25 @@ var _TinyCloudNode = class _TinyCloudNode {
9390
9396
  expandPermissionEntries(permissions) {
9391
9397
  return (0, import_sdk_core11.expandPermissionEntries)(permissions);
9392
9398
  }
9399
+ /**
9400
+ * Checks the SIWE text a caller-supplied signer is asked to sign: it must be in canonical form (parsing and
9401
+ * re-serializing it gives the same bytes) and name the session's account and chain. The caller then checks the
9402
+ * signature against these exact bytes.
9403
+ */
9404
+ assertRuntimeGrantMessage(siwe, session) {
9405
+ let parsed;
9406
+ try {
9407
+ parsed = new import_siwe2.SiweMessage(siwe);
9408
+ } catch {
9409
+ throw new Error("The prepared sign-in message is not a valid SIWE message.");
9410
+ }
9411
+ if (parsed.prepareMessage() !== siwe) {
9412
+ throw new Error("The prepared sign-in message is not in canonical form.");
9413
+ }
9414
+ if (parsed.chainId !== session.chainId || (0, import_sdk_core11.canonicalizeAddress)(parsed.address) !== (0, import_sdk_core11.canonicalizeAddress)(session.address)) {
9415
+ throw new Error("The prepared sign-in message is for a different account or chain than this session.");
9416
+ }
9417
+ }
9393
9418
  /**
9394
9419
  * The current WASM child-delegation APIs accept action-only maps. Refuse any
9395
9420
  * constrained branch rather than signing a broader action-only child UCAN.