@tinycloud/node-sdk 3.11.0-beta.0 → 3.11.0-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.
@@ -655,6 +655,13 @@ declare class NodeUserAuthorization implements IUserAuthorization {
655
655
  private guardSpaceCreation;
656
656
  private recordActivationSkippedSpaces;
657
657
  createBootstrapSession(options: CreateBootstrapSessionOptions): Promise<TinyCloudSession>;
658
+ /**
659
+ * When a session that starts at `now` ends. Refused with a dated message when
660
+ * the configured lifetime reaches past what a sign-in message can carry,
661
+ * instead of the bare `RangeError` or WASM parse error `toISOString()` and
662
+ * `prepareSession` would otherwise give.
663
+ */
664
+ private sessionExpiryFrom;
658
665
  private persistedData;
659
666
  /**
660
667
  * Sign in and create a new session.
@@ -655,6 +655,13 @@ declare class NodeUserAuthorization implements IUserAuthorization {
655
655
  private guardSpaceCreation;
656
656
  private recordActivationSkippedSpaces;
657
657
  createBootstrapSession(options: CreateBootstrapSessionOptions): Promise<TinyCloudSession>;
658
+ /**
659
+ * When a session that starts at `now` ends. Refused with a dated message when
660
+ * the configured lifetime reaches past what a sign-in message can carry,
661
+ * instead of the bare `RangeError` or WASM parse error `toISOString()` and
662
+ * `prepareSession` would otherwise give.
663
+ */
664
+ private sessionExpiryFrom;
658
665
  private persistedData;
659
666
  /**
660
667
  * Sign in and create a new session.
@@ -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-wAQN1Ndh.cjs';
4
+ import { T as TinyCloudNode } from './TinyCloudNode-CnVaWnAX.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 { ReplicaLocalEraseOutcome, ReplicaPurgeLocalCopyResult, ReplicaPurgeTrigger, ReplicaPurgeFailedEvent, ReplicaSessionStamp, ReplicaDenyInput } from '@tinycloud/sdk-services/kv/replication';
4
- import { T as TinyCloudNode } from './TinyCloudNode-BpolXzu5.js';
4
+ import { T as TinyCloudNode } from './TinyCloudNode-BlNcvo1c.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
@@ -1437,7 +1437,7 @@ var NodeUserAuthorization = class {
1437
1437
  }
1438
1438
  const jwk = JSON.parse(jwkString);
1439
1439
  const now = /* @__PURE__ */ new Date();
1440
- const expirationTime = new Date(now.getTime() + this.sessionExpirationMs);
1440
+ const expirationTime = this.sessionExpiryFrom(now);
1441
1441
  const primaryIdentity = pkhSpaceIdentity(options.spaceId);
1442
1442
  const resourcesBySpace = /* @__PURE__ */ new Map();
1443
1443
  for (const resource of options.capabilityRequest.resources) {
@@ -1492,6 +1492,17 @@ var NodeUserAuthorization = class {
1492
1492
  signature
1493
1493
  };
1494
1494
  }
1495
+ /**
1496
+ * When a session that starts at `now` ends. Refused with a dated message when
1497
+ * the configured lifetime reaches past what a sign-in message can carry,
1498
+ * instead of the bare `RangeError` or WASM parse error `toISOString()` and
1499
+ * `prepareSession` would otherwise give.
1500
+ */
1501
+ sessionExpiryFrom(now) {
1502
+ const expirationTime = new Date(now.getTime() + this.sessionExpirationMs);
1503
+ (0, import_sdk_core5.assertExpiryWithinTechnicalLimit)(expirationTime, "siwe");
1504
+ return expirationTime;
1505
+ }
1495
1506
  persistedData(session, expiresAt, createdAt, replicaStamp) {
1496
1507
  return {
1497
1508
  address: session.address,
@@ -1547,7 +1558,7 @@ var NodeUserAuthorization = class {
1547
1558
  const capabilityPlan = this.resolveSignInCapabilities(address, chainId);
1548
1559
  const spaceId = capabilityPlan.spaceId;
1549
1560
  const now = /* @__PURE__ */ new Date();
1550
- const expirationTime = new Date(now.getTime() + this.sessionExpirationMs);
1561
+ const expirationTime = this.sessionExpiryFrom(now);
1551
1562
  const prepared = this.prepareSessionWithResources({
1552
1563
  abilities: capabilityPlan.abilities,
1553
1564
  ...capabilityPlan.spaceAbilities !== void 0 ? { spaceAbilities: capabilityPlan.spaceAbilities } : {},
@@ -1693,7 +1704,7 @@ var NodeUserAuthorization = class {
1693
1704
  const capabilityPlan = this.resolveSignInCapabilities(address, chainId);
1694
1705
  const spaceId = capabilityPlan.spaceId;
1695
1706
  const now = /* @__PURE__ */ new Date();
1696
- const expirationTime = new Date(now.getTime() + this.sessionExpirationMs);
1707
+ const expirationTime = this.sessionExpiryFrom(now);
1697
1708
  const prepared = this.prepareSessionWithResources({
1698
1709
  abilities: capabilityPlan.abilities,
1699
1710
  ...capabilityPlan.spaceAbilities !== void 0 ? { spaceAbilities: capabilityPlan.spaceAbilities } : {},
@@ -1756,7 +1767,7 @@ var NodeUserAuthorization = class {
1756
1767
  siwe: prepared.siwe,
1757
1768
  signature
1758
1769
  };
1759
- const expiresAt = lastAnchoredLine(prepared.siwe ?? "", /^Expiration Time: (.+)$/gm) ?? new Date(Date.now() + this.sessionExpirationMs).toISOString();
1770
+ const expiresAt = lastAnchoredLine(prepared.siwe ?? "", /^Expiration Time: (.+)$/gm) ?? this.sessionExpiryFrom(/* @__PURE__ */ new Date()).toISOString();
1760
1771
  const createdAt = lastAnchoredLine(prepared.siwe ?? "", /^Issued At: (.+)$/gm) ?? (/* @__PURE__ */ new Date()).toISOString();
1761
1772
  const replicaStamp = await this.establishReplicaStamp?.(tinyCloudSession);
1762
1773
  const persistedData = this.persistedData(tinyCloudSession, expiresAt, createdAt, replicaStamp);
@@ -7730,6 +7741,7 @@ var _TinyCloudNode = class _TinyCloudNode {
7730
7741
  // DID here and rejects the fragment as an invalid audience DID.
7731
7742
  verificationMethod: params.session.verificationMethod.split("#", 1)[0]
7732
7743
  };
7744
+ (0, import_sdk_core11.assertExpiryWithinTechnicalLimit)(params.expirationSecs * 1e3, "ucan");
7733
7745
  const result = this.wasmBindings.createDelegation(
7734
7746
  wasmSession,
7735
7747
  params.delegateDID,
@@ -7762,9 +7774,10 @@ var _TinyCloudNode = class _TinyCloudNode {
7762
7774
  }
7763
7775
  const permissions = ownerDelegationPermissions(params);
7764
7776
  const now = /* @__PURE__ */ new Date();
7765
- if (!(params.expiresAt instanceof Date) || params.expiresAt.getTime() <= now.getTime() || params.expiresAt.getTime() - now.getTime() > import_sdk_core11.EXPIRY.MAX_MS) {
7766
- throw new Error("Owner delegation expiry must be explicit, future, and within EXPIRY.MAX_MS");
7777
+ if (!(params.expiresAt instanceof Date) || params.expiresAt.getTime() <= now.getTime()) {
7778
+ throw new Error("Owner delegation expiry must be explicit, future, and a valid date");
7767
7779
  }
7780
+ (0, import_sdk_core11.assertExpiryWithinTechnicalLimit)(params.expiresAt, "siwe");
7768
7781
  if (!this.signer) throw new Error("Owner wallet signer is required");
7769
7782
  const session = this.currentTinyCloudSession();
7770
7783
  if (!session) throw new Error("Owner session is required");
@@ -7865,6 +7878,7 @@ var _TinyCloudNode = class _TinyCloudNode {
7865
7878
  * not sent.
7866
7879
  */
7867
7880
  async authorizeShareDeliveryV3(input) {
7881
+ (0, import_sdk_core11.assertExpiryWithinTechnicalLimit)(new Date(input.expiresAt), "siwe");
7868
7882
  const envelopeRef = await (0, import_sdk_core11.shortDeliveryLinkBodyCid)(input.shareUrl, input.trustedOrigins);
7869
7883
  const session = this.currentTinyCloudSession();
7870
7884
  const serviceSession = this._serviceContext?.session;
@@ -7917,6 +7931,7 @@ var _TinyCloudNode = class _TinyCloudNode {
7917
7931
  };
7918
7932
  }
7919
7933
  async createRootDelegationForSharing(params, assertActive) {
7934
+ (0, import_sdk_core11.assertExpiryWithinTechnicalLimit)(params.requestedExpiry, "siwe");
7920
7935
  try {
7921
7936
  return (await this.createOwnerDelegation({
7922
7937
  delegateDid: params.shareKeyDID,
@@ -8613,6 +8628,7 @@ var _TinyCloudNode = class _TinyCloudNode {
8613
8628
  if (sessionExpiry !== void 0 && sessionExpiry < expiresAt) {
8614
8629
  expiresAt = sessionExpiry;
8615
8630
  }
8631
+ (0, import_sdk_core11.assertExpiryWithinTechnicalLimit)(expiresAt, "siwe");
8616
8632
  const delegations = [];
8617
8633
  let rawEntriesAttached = false;
8618
8634
  for (const [spaceId, entries] of bySpace) {
@@ -10085,6 +10101,7 @@ var _TinyCloudNode = class _TinyCloudNode {
10085
10101
  const now = /* @__PURE__ */ new Date();
10086
10102
  const expiryMs = params.expiryMs ?? 60 * 60 * 1e3;
10087
10103
  const expirationTime = new Date(now.getTime() + expiryMs);
10104
+ (0, import_sdk_core11.assertExpiryWithinTechnicalLimit)(expirationTime, "siwe");
10088
10105
  const prepared = this.wasmBindings.prepareSession({
10089
10106
  abilities,
10090
10107
  address: this.wasmBindings.ensureEip55(session.address),
@@ -10239,6 +10256,7 @@ var _TinyCloudNode = class _TinyCloudNode {
10239
10256
  const { abilities, rawAbilities } = this.buildActivationAbilities(delegation);
10240
10257
  const now = /* @__PURE__ */ new Date();
10241
10258
  const expirationTime = delegation.expiry;
10259
+ (0, import_sdk_core11.assertExpiryWithinTechnicalLimit)(expirationTime, "siwe");
10242
10260
  const prepared = this.wasmBindings.prepareSession({
10243
10261
  abilities,
10244
10262
  address: this.wasmBindings.ensureEip55(mySession.address),
@@ -10358,6 +10376,7 @@ var _TinyCloudNode = class _TinyCloudNode {
10358
10376
  const now = /* @__PURE__ */ new Date();
10359
10377
  const requestedExpiry = params.expiryMs === void 0 ? parentDelegation.expiry : new Date(now.getTime() + params.expiryMs);
10360
10378
  const actualExpiry = requestedExpiry > parentDelegation.expiry ? parentDelegation.expiry : requestedExpiry;
10379
+ (0, import_sdk_core11.assertExpiryWithinTechnicalLimit)(actualExpiry, "siwe");
10361
10380
  const abilities = {};
10362
10381
  const rawAbilities = {};
10363
10382
  for (const resource of requestedResources) {