@tinycloud/cli 0.6.0-beta.2 → 0.6.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.
package/dist/index.js CHANGED
@@ -549,7 +549,7 @@ var ProfileManager = class _ProfileManager {
549
549
 
550
550
  // src/auth/local-key.ts
551
551
  import { TCWSessionManager, importKey, initPanicHook } from "@tinycloud/node-sdk-wasm";
552
- import { PrivateKeySigner } from "@tinycloud/node-sdk";
552
+ import { PrivateKeySigner, pkhDid } from "@tinycloud/node-sdk";
553
553
  import { randomBytes } from "crypto";
554
554
  var wasmInitialized = false;
555
555
  function ensureWasm() {
@@ -583,7 +583,7 @@ async function deriveAddress(privateKey) {
583
583
  return signer.getAddress();
584
584
  }
585
585
  function addressToDID(address, chainId = 1) {
586
- return `did:pkh:eip155:${chainId}:${address}`;
586
+ return pkhDid(address, chainId);
587
587
  }
588
588
  async function generateLocalIdentity(chainId = 1) {
589
589
  const privateKey = generateEthereumPrivateKey();
@@ -903,13 +903,22 @@ import {
903
903
  } from "@tinycloud/node-sdk";
904
904
 
905
905
  // src/lib/space.ts
906
+ import {
907
+ buildSpaceUri,
908
+ canonicalizeAddress,
909
+ makePkhSpaceId,
910
+ parsePkhDid,
911
+ parseSpaceUri
912
+ } from "@tinycloud/node-sdk";
906
913
  function resolveAddress(profile, session) {
907
914
  const sessAddr = session?.address;
908
- if (typeof sessAddr === "string" && sessAddr.length > 0) return sessAddr;
909
- if (profile.address) return profile.address;
915
+ if (typeof sessAddr === "string" && sessAddr.length > 0) {
916
+ return canonicalizeAddress(sessAddr);
917
+ }
918
+ if (profile.address) return canonicalizeAddress(profile.address);
910
919
  if (profile.ownerDid) {
911
- const match = profile.ownerDid.match(/^did:pkh:eip155:\d+:(0x[a-fA-F0-9]{40})$/);
912
- if (match) return match[1];
920
+ const pkh = parsePkhDid(profile.ownerDid);
921
+ if (pkh) return pkh.address;
913
922
  }
914
923
  throw new CLIError(
915
924
  "ADDRESS_UNKNOWN",
@@ -924,7 +933,17 @@ function resolveChainId(profile, session) {
924
933
  }
925
934
  async function resolveSpaceUri(input, profileName) {
926
935
  if (!input) return void 0;
927
- if (input.startsWith("tinycloud:")) return input;
936
+ if (input.startsWith("tinycloud:")) {
937
+ const parsed = parseSpaceUri(input);
938
+ if (!parsed) {
939
+ throw new CLIError(
940
+ "INVALID_SPACE",
941
+ `Invalid --space "${input}". Use a short name ([A-Za-z0-9_-]) or a full tinycloud:... URI.`,
942
+ ExitCode.USAGE_ERROR
943
+ );
944
+ }
945
+ return buildSpaceUri(parsed.owner, parsed.name);
946
+ }
928
947
  if (!/^[A-Za-z0-9_-]+$/.test(input)) {
929
948
  throw new CLIError(
930
949
  "INVALID_SPACE",
@@ -936,7 +955,7 @@ async function resolveSpaceUri(input, profileName) {
936
955
  const session = await ProfileManager.getSession(profileName);
937
956
  const address = resolveAddress(profile, session);
938
957
  const chainId = resolveChainId(profile, session);
939
- return `tinycloud:pkh:eip155:${chainId}:${address}:${input}`;
958
+ return makePkhSpaceId(address, chainId, input);
940
959
  }
941
960
 
942
961
  // src/lib/permissions.ts
@@ -2452,6 +2471,15 @@ function parseExpiry(input) {
2452
2471
  }
2453
2472
 
2454
2473
  // src/commands/delegation.ts
2474
+ import { principalDidEquals } from "@tinycloud/node-sdk";
2475
+ function didMatches(actual, expected) {
2476
+ if (!actual) return false;
2477
+ try {
2478
+ return principalDidEquals(actual, expected);
2479
+ } catch {
2480
+ return actual === expected;
2481
+ }
2482
+ }
2455
2483
  function registerDelegationCommand(program2) {
2456
2484
  const delegation = program2.command("delegation").description("Manage delegations");
2457
2485
  delegation.command("create").description("Create a delegation").requiredOption("--to <did>", "Recipient DID").requiredOption("--path <path>", "KV path scope").requiredOption("--actions <actions>", "Comma-separated actions (e.g., kv/get,kv/list)").option("--expiry <duration>", "Expiry duration (e.g., 1h, 7d, ISO date)", "1h").action(async (options, cmd) => {
@@ -2496,10 +2524,10 @@ function registerDelegationCommand(program2) {
2496
2524
  let delegations = result.data;
2497
2525
  if (options.granted) {
2498
2526
  const myDid = node.did;
2499
- delegations = delegations.filter((d) => d.delegatorDID === myDid);
2527
+ delegations = delegations.filter((d) => didMatches(d.delegatorDID, myDid));
2500
2528
  } else if (options.received) {
2501
2529
  const myDid = node.did;
2502
- delegations = delegations.filter((d) => d.delegateDID === myDid || d.delegateDID?.includes(myDid));
2530
+ delegations = delegations.filter((d) => didMatches(d.delegateDID, myDid));
2503
2531
  }
2504
2532
  outputJson({
2505
2533
  delegations: delegations.map((d) => ({