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

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