@tinycloud/sdk-services 2.2.1-beta.0 → 2.3.0-beta.2

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.cjs CHANGED
@@ -4557,20 +4557,20 @@ function parseNetworkId(networkId) {
4557
4557
  const lastColon = body.lastIndexOf(":");
4558
4558
  if (lastColon <= 0 || lastColon === body.length - 1) {
4559
4559
  throw new NetworkIdError(
4560
- `networkId missing principal or name segment (got ${JSON.stringify(networkId)})`
4560
+ `networkId missing ownerDid or name segment (got ${JSON.stringify(networkId)})`
4561
4561
  );
4562
4562
  }
4563
- const principal = body.slice(0, lastColon);
4563
+ const ownerDid = body.slice(0, lastColon);
4564
4564
  const name = body.slice(lastColon + 1);
4565
- if (!principal.startsWith("did:")) {
4565
+ if (!ownerDid.startsWith("did:")) {
4566
4566
  throw new NetworkIdError(
4567
- `networkId principal must be a DID (got ${JSON.stringify(principal)})`
4567
+ `networkId ownerDid must be a DID (got ${JSON.stringify(ownerDid)})`
4568
4568
  );
4569
4569
  }
4570
- const didParts = principal.split(":");
4570
+ const didParts = ownerDid.split(":");
4571
4571
  if (didParts.length < 3 || didParts.some((p) => p.length === 0)) {
4572
4572
  throw new NetworkIdError(
4573
- `networkId principal is not a well-formed DID (got ${JSON.stringify(principal)})`
4573
+ `networkId ownerDid is not a well-formed DID (got ${JSON.stringify(ownerDid)})`
4574
4574
  );
4575
4575
  }
4576
4576
  if (!NETWORK_NAME_RE.test(name)) {
@@ -4578,18 +4578,18 @@ function parseNetworkId(networkId) {
4578
4578
  `networkId name ${JSON.stringify(name)} must match ${NETWORK_NAME_RE.source}`
4579
4579
  );
4580
4580
  }
4581
- return { networkId, principal, name };
4581
+ return { networkId, ownerDid, name };
4582
4582
  }
4583
- function buildNetworkId(principal, name) {
4584
- if (typeof principal !== "string" || !principal.startsWith("did:")) {
4585
- throw new NetworkIdError("principal must be a DID");
4583
+ function buildNetworkId(ownerDid, name) {
4584
+ if (typeof ownerDid !== "string" || !ownerDid.startsWith("did:")) {
4585
+ throw new NetworkIdError("ownerDid must be a DID");
4586
4586
  }
4587
4587
  if (typeof name !== "string" || !NETWORK_NAME_RE.test(name)) {
4588
4588
  throw new NetworkIdError(
4589
4589
  `network name ${JSON.stringify(name)} must match ${NETWORK_NAME_RE.source}`
4590
4590
  );
4591
4591
  }
4592
- const networkId = `${URN_PREFIX}${principal}:${name}`;
4592
+ const networkId = `${URN_PREFIX}${ownerDid}:${name}`;
4593
4593
  parseNetworkId(networkId);
4594
4594
  return networkId;
4595
4595
  }
@@ -4666,27 +4666,27 @@ function toError2(error) {
4666
4666
  // src/encryption/discovery.ts
4667
4667
  async function discoverNetwork(input) {
4668
4668
  let networkId;
4669
- let principal;
4669
+ let ownerDid;
4670
4670
  let name;
4671
4671
  try {
4672
4672
  if (input.identifier.startsWith("urn:tinycloud:encryption:")) {
4673
4673
  const parsed = parseNetworkId(input.identifier);
4674
4674
  networkId = parsed.networkId;
4675
- principal = parsed.principal;
4675
+ ownerDid = parsed.ownerDid;
4676
4676
  name = parsed.name;
4677
4677
  } else {
4678
- if (input.principal === void 0) {
4678
+ if (input.ownerDid === void 0) {
4679
4679
  return {
4680
4680
  ok: false,
4681
4681
  error: encryptionError({
4682
4682
  code: "INVALID_INPUT",
4683
- message: "discoverNetwork requires `principal` when identifier is a bare network name"
4683
+ message: "discoverNetwork requires `ownerDid` when identifier is a bare network name"
4684
4684
  })
4685
4685
  };
4686
4686
  }
4687
- networkId = `urn:tinycloud:encryption:${input.principal}:${input.identifier}`;
4687
+ networkId = `urn:tinycloud:encryption:${input.ownerDid}:${input.identifier}`;
4688
4688
  const parsed = parseNetworkId(networkId);
4689
- principal = parsed.principal;
4689
+ ownerDid = parsed.ownerDid;
4690
4690
  name = parsed.name;
4691
4691
  }
4692
4692
  } catch (err3) {
@@ -4705,7 +4705,7 @@ async function discoverNetwork(input) {
4705
4705
  try {
4706
4706
  const descriptor = await input.node.fetchByNetworkId(networkId);
4707
4707
  if (descriptor !== null) {
4708
- const validated = validateDescriptor(descriptor, networkId, principal, name);
4708
+ const validated = validateDescriptor(descriptor, networkId, ownerDid, name);
4709
4709
  if (!validated.ok) return validated;
4710
4710
  return { ok: true, data: { descriptor: validated.data, source: "node" } };
4711
4711
  }
@@ -4715,11 +4715,11 @@ async function discoverNetwork(input) {
4715
4715
  if (input.wellKnown !== void 0) {
4716
4716
  try {
4717
4717
  const descriptor = await input.wellKnown.fetchWellKnown(
4718
- principal,
4718
+ ownerDid,
4719
4719
  networkDiscoveryKey(name)
4720
4720
  );
4721
4721
  if (descriptor !== null) {
4722
- const validated = validateDescriptor(descriptor, networkId, principal, name);
4722
+ const validated = validateDescriptor(descriptor, networkId, ownerDid, name);
4723
4723
  if (!validated.ok) return validated;
4724
4724
  return {
4725
4725
  ok: true,
@@ -4738,7 +4738,7 @@ async function discoverNetwork(input) {
4738
4738
  })
4739
4739
  };
4740
4740
  }
4741
- function validateDescriptor(descriptor, networkId, principal, name) {
4741
+ function validateDescriptor(descriptor, networkId, ownerDid, name) {
4742
4742
  if (descriptor.networkId !== networkId) {
4743
4743
  return {
4744
4744
  ok: false,
@@ -4748,12 +4748,12 @@ function validateDescriptor(descriptor, networkId, principal, name) {
4748
4748
  })
4749
4749
  };
4750
4750
  }
4751
- if (descriptor.principal !== principal) {
4751
+ if (descriptor.ownerDid !== ownerDid) {
4752
4752
  return {
4753
4753
  ok: false,
4754
4754
  error: encryptionError({
4755
4755
  code: "INVALID_NETWORK_ID",
4756
- message: "descriptor principal does not match networkId principal"
4756
+ message: "descriptor ownerDid does not match networkId ownerDid"
4757
4757
  })
4758
4758
  };
4759
4759
  }
@@ -5245,10 +5245,10 @@ var EncryptionService = class extends BaseService {
5245
5245
  get crypto() {
5246
5246
  return this._config.crypto;
5247
5247
  }
5248
- async discoverNetwork(identifier, principal) {
5248
+ async discoverNetwork(identifier, ownerDid) {
5249
5249
  const result = await discoverNetwork({
5250
5250
  identifier,
5251
- ...principal !== void 0 ? { principal } : {},
5251
+ ...ownerDid !== void 0 ? { ownerDid } : {},
5252
5252
  ...this._config.node !== void 0 ? { node: this._config.node } : {},
5253
5253
  ...this._config.wellKnown !== void 0 ? { wellKnown: this._config.wellKnown } : {}
5254
5254
  });