@tinycloud/node-sdk 2.3.0-beta.2 → 2.3.0-beta.4

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.
@@ -1406,7 +1406,6 @@ declare class TinyCloudNode {
1406
1406
  private findRuntimeGrantsForPermissionEntries;
1407
1407
  private runtimeDelegationFromSession;
1408
1408
  private runtimeGrantFromDelegation;
1409
- private didWithoutFragment;
1410
1409
  private installRuntimeGrantFromServiceSession;
1411
1410
  private delegatedResourcesForEntries;
1412
1411
  private operationsFromDelegation;
@@ -1406,7 +1406,6 @@ declare class TinyCloudNode {
1406
1406
  private findRuntimeGrantsForPermissionEntries;
1407
1407
  private runtimeDelegationFromSession;
1408
1408
  private runtimeGrantFromDelegation;
1409
- private didWithoutFragment;
1410
1409
  private installRuntimeGrantFromServiceSession;
1411
1410
  private delegatedResourcesForEntries;
1412
1411
  private operationsFromDelegation;
package/dist/core.cjs CHANGED
@@ -47,6 +47,7 @@ __export(core_exports, {
47
47
  DuckDbDatabaseHandle: () => import_sdk_core12.DuckDbDatabaseHandle,
48
48
  DuckDbService: () => import_sdk_core12.DuckDbService,
49
49
  FileSessionStorage: () => FileSessionStorage,
50
+ IdentityParseError: () => import_sdk_core8.IdentityParseError,
50
51
  KVService: () => import_sdk_core10.KVService,
51
52
  ManifestValidationError: () => import_sdk_core9.ManifestValidationError,
52
53
  MemorySessionStorage: () => MemorySessionStorage,
@@ -73,7 +74,12 @@ __export(core_exports, {
73
74
  VaultPublicSpaceKVActions: () => import_sdk_core13.VaultPublicSpaceKVActions,
74
75
  VersionCheckError: () => import_sdk_core17.VersionCheckError,
75
76
  WasmKeyProvider: () => WasmKeyProvider,
77
+ addressStorageKey: () => import_sdk_core8.addressStorageKey,
76
78
  buildSpaceUri: () => import_sdk_core16.buildSpaceUri,
79
+ canonicalizeAddress: () => import_sdk_core8.canonicalizeAddress,
80
+ canonicalizeDid: () => import_sdk_core8.canonicalizeDid,
81
+ canonicalizeDidUrl: () => import_sdk_core8.canonicalizeDidUrl,
82
+ canonicalizeNetworkId: () => import_sdk_core8.canonicalizeNetworkId,
77
83
  canonicalizeSecretScope: () => import_sdk_core13.canonicalizeSecretScope,
78
84
  checkNodeInfo: () => import_sdk_core17.checkNodeInfo,
79
85
  composeManifestRequest: () => import_sdk_core9.composeManifestRequest,
@@ -85,14 +91,23 @@ __export(core_exports, {
85
91
  defaultSignStrategy: () => defaultSignStrategy,
86
92
  defaultSpaceCreationHandler: () => import_sdk_core8.defaultSpaceCreationHandler,
87
93
  deserializeDelegation: () => deserializeDelegation,
94
+ didCacheKey: () => import_sdk_core8.didCacheKey,
95
+ didEquals: () => import_sdk_core8.didEquals,
88
96
  expandActionShortNames: () => import_sdk_core9.expandActionShortNames,
89
97
  expandPermissionEntries: () => import_sdk_core9.expandPermissionEntries,
90
98
  expandPermissionEntry: () => import_sdk_core9.expandPermissionEntry,
91
99
  isCapabilitySubset: () => import_sdk_core9.isCapabilitySubset,
100
+ isEvmAddress: () => import_sdk_core8.isEvmAddress,
92
101
  loadManifest: () => import_sdk_core9.loadManifest,
102
+ makePkhSpaceId: () => import_sdk_core8.makePkhSpaceId,
93
103
  makePublicSpaceId: () => import_sdk_core16.makePublicSpaceId,
104
+ parseCanonicalNetworkId: () => import_sdk_core8.parseCanonicalNetworkId,
94
105
  parseExpiry: () => import_sdk_core9.parseExpiry,
106
+ parsePkhDid: () => import_sdk_core8.parsePkhDid,
95
107
  parseSpaceUri: () => import_sdk_core16.parseSpaceUri,
108
+ pkhDid: () => import_sdk_core8.pkhDid,
109
+ principalDid: () => import_sdk_core8.principalDid,
110
+ principalDidEquals: () => import_sdk_core8.principalDidEquals,
96
111
  resolveManifest: () => import_sdk_core9.resolveManifest,
97
112
  resolveSecretListPrefix: () => import_sdk_core13.resolveSecretListPrefix,
98
113
  resolveSecretPath: () => import_sdk_core13.resolveSecretPath,
@@ -421,15 +436,16 @@ var NodeUserAuthorization = class {
421
436
  * expired-at-epoch-zero.
422
437
  */
423
438
  setRestoredTinyCloudSession(session) {
424
- this._tinyCloudSession = session;
425
- this._address = session.address;
439
+ const address = (0, import_sdk_core2.canonicalizeAddress)(session.address);
440
+ this._tinyCloudSession = { ...session, address };
441
+ this._address = address;
426
442
  this._chainId = session.chainId;
427
443
  }
428
444
  async resolveTinyCloudHostsForSignIn(address, chainId) {
429
445
  if (this.tinycloudHosts && this.tinycloudHosts.length > 0) {
430
446
  return;
431
447
  }
432
- const subject = `did:pkh:eip155:${chainId}:${address}`;
448
+ const subject = (0, import_sdk_core2.pkhDid)(address, chainId);
433
449
  const resolved = await (0, import_sdk_core2.resolveTinyCloudHosts)(subject, {
434
450
  registryUrl: this.tinycloudRegistryUrl,
435
451
  fallbackHosts: this.tinycloudFallbackHosts
@@ -493,19 +509,19 @@ var NodeUserAuthorization = class {
493
509
  if (space.startsWith("tinycloud:")) {
494
510
  return space;
495
511
  }
496
- return this.wasm.makeSpaceId(address, chainId, space);
512
+ return (0, import_sdk_core2.makePkhSpaceId)(address, chainId, space);
497
513
  }
498
514
  defaultEncryptionNetworkId(address, chainId) {
499
- return `urn:tinycloud:encryption:did:pkh:eip155:${chainId}:${address}:default`;
515
+ return `urn:tinycloud:encryption:${(0, import_sdk_core2.pkhDid)(address, chainId)}:default`;
500
516
  }
501
517
  resolveSignInCapabilities(address, chainId) {
502
518
  const request = this.getCapabilityRequest();
503
519
  if (request === void 0) {
504
520
  const defaultNetworkId = this.defaultEncryptionNetworkId(address, chainId);
505
- const secretsSpaceId = this.wasm.makeSpaceId(address, chainId, "secrets");
521
+ const secretsSpaceId = (0, import_sdk_core2.makePkhSpaceId)(address, chainId, "secrets");
506
522
  return {
507
523
  abilities: this.defaultActions,
508
- spaceId: this.wasm.makeSpaceId(address, chainId, this.spacePrefix),
524
+ spaceId: (0, import_sdk_core2.makePkhSpaceId)(address, chainId, this.spacePrefix),
509
525
  spaceAbilities: {
510
526
  [secretsSpaceId]: {
511
527
  kv: {
@@ -767,9 +783,9 @@ var NodeUserAuthorization = class {
767
783
  * @param options - Optional per-call SIWE overrides for this sign-in only
768
784
  */
769
785
  async signIn(options) {
770
- this._address = await this.signer.getAddress();
786
+ this._address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
771
787
  this._chainId = await this.signer.getChainId();
772
- const address = this.wasm.ensureEip55(this._address);
788
+ const address = this._address;
773
789
  const chainId = this._chainId;
774
790
  await this.resolveTinyCloudHostsForSignIn(address, chainId);
775
791
  const keyId = `session-${Date.now()}`;
@@ -814,7 +830,7 @@ var NodeUserAuthorization = class {
814
830
  siwe: prepared.siwe,
815
831
  signature
816
832
  };
817
- const spacesMetadata = this.enablePublicSpace ? { public: this.wasm.makeSpaceId(address, chainId, "public") } : void 0;
833
+ const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core2.makePkhSpaceId)(address, chainId, "public") } : void 0;
818
834
  const tinyCloudSession = {
819
835
  address,
820
836
  chainId,
@@ -889,7 +905,7 @@ var NodeUserAuthorization = class {
889
905
  */
890
906
  async signMessage(message) {
891
907
  if (!this._address) {
892
- this._address = await this.signer.getAddress();
908
+ this._address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
893
909
  }
894
910
  if (!this._chainId) {
895
911
  this._chainId = await this.signer.getChainId();
@@ -916,7 +932,7 @@ var NodeUserAuthorization = class {
916
932
  * ```
917
933
  */
918
934
  async prepareSessionForSigning() {
919
- const address = this.wasm.ensureEip55(await this.signer.getAddress());
935
+ const address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
920
936
  const chainId = await this.signer.getChainId();
921
937
  const keyId = `session-${Date.now()}`;
922
938
  this.sessionManager.renameSessionKeyId("default", keyId);
@@ -966,7 +982,7 @@ var NodeUserAuthorization = class {
966
982
  ...prepared,
967
983
  signature
968
984
  });
969
- const address = this.wasm.ensureEip55(await this.signer.getAddress());
985
+ const address = (0, import_sdk_core2.canonicalizeAddress)(await this.signer.getAddress());
970
986
  const chainId = await this.signer.getChainId();
971
987
  await this.resolveTinyCloudHostsForSignIn(address, chainId);
972
988
  const clientSession = {
@@ -977,7 +993,7 @@ var NodeUserAuthorization = class {
977
993
  siwe: prepared.siwe,
978
994
  signature
979
995
  };
980
- const spacesMetadata = this.enablePublicSpace ? { public: this.wasm.makeSpaceId(address, chainId, "public") } : void 0;
996
+ const spacesMetadata = this.enablePublicSpace ? { public: (0, import_sdk_core2.makePkhSpaceId)(address, chainId, "public") } : void 0;
981
997
  const tinyCloudSession = {
982
998
  address,
983
999
  chainId,
@@ -1507,6 +1523,13 @@ var NETWORK_CREATE_ACTION = "tinycloud.encryption/network.create";
1507
1523
  var DECRYPT_ACTION = "tinycloud.encryption/decrypt";
1508
1524
  var NETWORK_ADMIN_TYPE = "tinycloud.encryption.network-admin/v1";
1509
1525
  var DEFAULT_SESSION_EXPIRATION_MS = import_sdk_core6.EXPIRY.SESSION_MS;
1526
+ function didPrincipalMatches(actual, expected) {
1527
+ try {
1528
+ return (0, import_sdk_core6.principalDidEquals)(actual, expected);
1529
+ } catch {
1530
+ return actual === expected;
1531
+ }
1532
+ }
1510
1533
  function base64UrlEncode(bytes) {
1511
1534
  const alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789-_";
1512
1535
  let output = "";
@@ -1803,7 +1826,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1803
1826
  */
1804
1827
  get did() {
1805
1828
  if (this._address) {
1806
- return `did:pkh:eip155:${this._chainId}:${this._address}`;
1829
+ return (0, import_sdk_core6.pkhDid)(this._address, this._chainId);
1807
1830
  }
1808
1831
  return this.sessionManager.getDID(this.sessionKeyId);
1809
1832
  }
@@ -1820,7 +1843,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1820
1843
  * Get the Ethereum address for this user.
1821
1844
  */
1822
1845
  get address() {
1823
- return this._address;
1846
+ return this.auth?.address() ?? this._address;
1824
1847
  }
1825
1848
  /**
1826
1849
  * Check if this instance is in session-only mode (no wallet).
@@ -1858,7 +1881,7 @@ var _TinyCloudNode = class _TinyCloudNode {
1858
1881
  );
1859
1882
  }
1860
1883
  await this.wasmBindings.ensureInitialized?.();
1861
- this._address = await this.signer.getAddress();
1884
+ this._address = (0, import_sdk_core6.canonicalizeAddress)(await this.signer.getAddress());
1862
1885
  this._chainId = await this.signer.getChainId();
1863
1886
  this._kv = void 0;
1864
1887
  this._sql = void 0;
@@ -1965,8 +1988,9 @@ var _TinyCloudNode = class _TinyCloudNode {
1965
1988
  this._spaceService = void 0;
1966
1989
  this._serviceContext = void 0;
1967
1990
  this.runtimePermissionGrants = [];
1968
- if (sessionData.address) {
1969
- this._address = sessionData.address;
1991
+ const restoredAddress = sessionData.address ? (0, import_sdk_core6.canonicalizeAddress)(sessionData.address) : void 0;
1992
+ if (restoredAddress) {
1993
+ this._address = restoredAddress;
1970
1994
  }
1971
1995
  if (sessionData.chainId) {
1972
1996
  this._chainId = sessionData.chainId;
@@ -2001,9 +2025,9 @@ var _TinyCloudNode = class _TinyCloudNode {
2001
2025
  this._vault.initialize(this._serviceContext);
2002
2026
  this._serviceContext.registerService("vault", this._vault);
2003
2027
  this.initializeV2Services(serviceSession);
2004
- if (sessionData.siwe && sessionData.address && sessionData.chainId) {
2028
+ if (sessionData.siwe && restoredAddress && sessionData.chainId) {
2005
2029
  const tcSession = {
2006
- address: sessionData.address,
2030
+ address: restoredAddress,
2007
2031
  chainId: sessionData.chainId,
2008
2032
  sessionKey: JSON.stringify(sessionData.jwk),
2009
2033
  spaceId: sessionData.spaceId,
@@ -2342,8 +2366,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2342
2366
  fetchByNetworkId: (networkId) => this.getEncryptionNetwork(networkId)
2343
2367
  },
2344
2368
  wellKnown: {
2345
- fetchWellKnown: async (ownerDid, discoveryKey) => {
2346
- if (!this._address || ownerDid !== this.did) {
2369
+ fetchWellKnown: async (principal, discoveryKey) => {
2370
+ if (!this._address || !didPrincipalMatches(principal, this.did)) {
2347
2371
  return null;
2348
2372
  }
2349
2373
  if (!this.config.host) {
@@ -2667,7 +2691,7 @@ var _TinyCloudNode = class _TinyCloudNode {
2667
2691
  return {
2668
2692
  cid: delegationSession.delegationCid,
2669
2693
  delegateDID: params.shareKeyDID,
2670
- delegatorDID: `did:pkh:eip155:${session.chainId}:${session.address}`,
2694
+ delegatorDID: (0, import_sdk_core6.pkhDid)(session.address, session.chainId),
2671
2695
  spaceId: params.spaceId,
2672
2696
  path: params.path,
2673
2697
  actions: params.actions,
@@ -2999,13 +3023,8 @@ var _TinyCloudNode = class _TinyCloudNode {
2999
3023
  if (delegation.expiry.getTime() <= Date.now()) {
3000
3024
  throw new import_sdk_core6.SessionExpiredError(delegation.expiry);
3001
3025
  }
3002
- const expectedDids = /* @__PURE__ */ new Set([
3003
- session.verificationMethod,
3004
- this.didWithoutFragment(session.verificationMethod),
3005
- this.sessionDid,
3006
- this.didWithoutFragment(this.sessionDid)
3007
- ]);
3008
- if (!expectedDids.has(delegation.delegateDID)) {
3026
+ const expectedDids = [session.verificationMethod, this.sessionDid];
3027
+ if (!expectedDids.some((did) => didPrincipalMatches(delegation.delegateDID, did))) {
3009
3028
  throw new Error(
3010
3029
  `Runtime delegation targets ${delegation.delegateDID} but this session key is ${session.verificationMethod}.`
3011
3030
  );
@@ -3532,7 +3551,9 @@ var _TinyCloudNode = class _TinyCloudNode {
3532
3551
  "materializeDelegation requires a composed manifest request"
3533
3552
  );
3534
3553
  }
3535
- const target = request.delegationTargets.find((entry) => entry.did === did);
3554
+ const target = request.delegationTargets.find(
3555
+ (entry) => didPrincipalMatches(entry.did, did)
3556
+ );
3536
3557
  if (!target) {
3537
3558
  throw new Error(`No manifest delegation target found for DID ${did}`);
3538
3559
  }
@@ -3840,10 +3861,6 @@ var _TinyCloudNode = class _TinyCloudNode {
3840
3861
  expiresAt: delegation.expiry
3841
3862
  };
3842
3863
  }
3843
- didWithoutFragment(did) {
3844
- const fragment = did.indexOf("#");
3845
- return fragment === -1 ? did : did.slice(0, fragment);
3846
- }
3847
3864
  installRuntimeGrantFromServiceSession(delegation, session, expiresAt) {
3848
3865
  const operations = this.operationsFromDelegation(delegation);
3849
3866
  if (operations.length === 0) {
@@ -4039,7 +4056,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4039
4056
  if (resolvedDelegateDID.endsWith(".eth") && this.config.ensResolver) {
4040
4057
  const address = await this.config.ensResolver.resolveAddress(resolvedDelegateDID);
4041
4058
  if (!address) throw new Error(`Could not resolve ENS name: ${resolvedDelegateDID}`);
4042
- resolvedDelegateDID = `did:pkh:eip155:1:${address}`;
4059
+ resolvedDelegateDID = (0, import_sdk_core6.pkhDid)(address, 1);
4043
4060
  }
4044
4061
  const entries = legacyParamsToPermissionEntries(
4045
4062
  params.actions,
@@ -4196,7 +4213,7 @@ var _TinyCloudNode = class _TinyCloudNode {
4196
4213
  const targetHost = delegation.host ?? this.config.host;
4197
4214
  if (this.isSessionOnly) {
4198
4215
  const myDid = this.did;
4199
- if (delegation.delegateDID !== myDid) {
4216
+ if (!didPrincipalMatches(delegation.delegateDID, myDid)) {
4200
4217
  throw new Error(
4201
4218
  `Delegation targets ${delegation.delegateDID} but this user's DID is ${myDid}. The delegation must target this user's DID.`
4202
4219
  );
@@ -4457,6 +4474,7 @@ var import_sdk_core18 = require("@tinycloud/sdk-core");
4457
4474
  DuckDbDatabaseHandle,
4458
4475
  DuckDbService,
4459
4476
  FileSessionStorage,
4477
+ IdentityParseError,
4460
4478
  KVService,
4461
4479
  ManifestValidationError,
4462
4480
  MemorySessionStorage,
@@ -4483,7 +4501,12 @@ var import_sdk_core18 = require("@tinycloud/sdk-core");
4483
4501
  VaultPublicSpaceKVActions,
4484
4502
  VersionCheckError,
4485
4503
  WasmKeyProvider,
4504
+ addressStorageKey,
4486
4505
  buildSpaceUri,
4506
+ canonicalizeAddress,
4507
+ canonicalizeDid,
4508
+ canonicalizeDidUrl,
4509
+ canonicalizeNetworkId,
4487
4510
  canonicalizeSecretScope,
4488
4511
  checkNodeInfo,
4489
4512
  composeManifestRequest,
@@ -4495,14 +4518,23 @@ var import_sdk_core18 = require("@tinycloud/sdk-core");
4495
4518
  defaultSignStrategy,
4496
4519
  defaultSpaceCreationHandler,
4497
4520
  deserializeDelegation,
4521
+ didCacheKey,
4522
+ didEquals,
4498
4523
  expandActionShortNames,
4499
4524
  expandPermissionEntries,
4500
4525
  expandPermissionEntry,
4501
4526
  isCapabilitySubset,
4527
+ isEvmAddress,
4502
4528
  loadManifest,
4529
+ makePkhSpaceId,
4503
4530
  makePublicSpaceId,
4531
+ parseCanonicalNetworkId,
4504
4532
  parseExpiry,
4533
+ parsePkhDid,
4505
4534
  parseSpaceUri,
4535
+ pkhDid,
4536
+ principalDid,
4537
+ principalDidEquals,
4506
4538
  resolveManifest,
4507
4539
  resolveSecretListPrefix,
4508
4540
  resolveSecretPath,