@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.js CHANGED
@@ -4429,20 +4429,20 @@ function parseNetworkId(networkId) {
4429
4429
  const lastColon = body.lastIndexOf(":");
4430
4430
  if (lastColon <= 0 || lastColon === body.length - 1) {
4431
4431
  throw new NetworkIdError(
4432
- `networkId missing principal or name segment (got ${JSON.stringify(networkId)})`
4432
+ `networkId missing ownerDid or name segment (got ${JSON.stringify(networkId)})`
4433
4433
  );
4434
4434
  }
4435
- const principal = body.slice(0, lastColon);
4435
+ const ownerDid = body.slice(0, lastColon);
4436
4436
  const name = body.slice(lastColon + 1);
4437
- if (!principal.startsWith("did:")) {
4437
+ if (!ownerDid.startsWith("did:")) {
4438
4438
  throw new NetworkIdError(
4439
- `networkId principal must be a DID (got ${JSON.stringify(principal)})`
4439
+ `networkId ownerDid must be a DID (got ${JSON.stringify(ownerDid)})`
4440
4440
  );
4441
4441
  }
4442
- const didParts = principal.split(":");
4442
+ const didParts = ownerDid.split(":");
4443
4443
  if (didParts.length < 3 || didParts.some((p) => p.length === 0)) {
4444
4444
  throw new NetworkIdError(
4445
- `networkId principal is not a well-formed DID (got ${JSON.stringify(principal)})`
4445
+ `networkId ownerDid is not a well-formed DID (got ${JSON.stringify(ownerDid)})`
4446
4446
  );
4447
4447
  }
4448
4448
  if (!NETWORK_NAME_RE.test(name)) {
@@ -4450,18 +4450,18 @@ function parseNetworkId(networkId) {
4450
4450
  `networkId name ${JSON.stringify(name)} must match ${NETWORK_NAME_RE.source}`
4451
4451
  );
4452
4452
  }
4453
- return { networkId, principal, name };
4453
+ return { networkId, ownerDid, name };
4454
4454
  }
4455
- function buildNetworkId(principal, name) {
4456
- if (typeof principal !== "string" || !principal.startsWith("did:")) {
4457
- throw new NetworkIdError("principal must be a DID");
4455
+ function buildNetworkId(ownerDid, name) {
4456
+ if (typeof ownerDid !== "string" || !ownerDid.startsWith("did:")) {
4457
+ throw new NetworkIdError("ownerDid must be a DID");
4458
4458
  }
4459
4459
  if (typeof name !== "string" || !NETWORK_NAME_RE.test(name)) {
4460
4460
  throw new NetworkIdError(
4461
4461
  `network name ${JSON.stringify(name)} must match ${NETWORK_NAME_RE.source}`
4462
4462
  );
4463
4463
  }
4464
- const networkId = `${URN_PREFIX}${principal}:${name}`;
4464
+ const networkId = `${URN_PREFIX}${ownerDid}:${name}`;
4465
4465
  parseNetworkId(networkId);
4466
4466
  return networkId;
4467
4467
  }
@@ -4538,27 +4538,27 @@ function toError2(error) {
4538
4538
  // src/encryption/discovery.ts
4539
4539
  async function discoverNetwork(input) {
4540
4540
  let networkId;
4541
- let principal;
4541
+ let ownerDid;
4542
4542
  let name;
4543
4543
  try {
4544
4544
  if (input.identifier.startsWith("urn:tinycloud:encryption:")) {
4545
4545
  const parsed = parseNetworkId(input.identifier);
4546
4546
  networkId = parsed.networkId;
4547
- principal = parsed.principal;
4547
+ ownerDid = parsed.ownerDid;
4548
4548
  name = parsed.name;
4549
4549
  } else {
4550
- if (input.principal === void 0) {
4550
+ if (input.ownerDid === void 0) {
4551
4551
  return {
4552
4552
  ok: false,
4553
4553
  error: encryptionError({
4554
4554
  code: "INVALID_INPUT",
4555
- message: "discoverNetwork requires `principal` when identifier is a bare network name"
4555
+ message: "discoverNetwork requires `ownerDid` when identifier is a bare network name"
4556
4556
  })
4557
4557
  };
4558
4558
  }
4559
- networkId = `urn:tinycloud:encryption:${input.principal}:${input.identifier}`;
4559
+ networkId = `urn:tinycloud:encryption:${input.ownerDid}:${input.identifier}`;
4560
4560
  const parsed = parseNetworkId(networkId);
4561
- principal = parsed.principal;
4561
+ ownerDid = parsed.ownerDid;
4562
4562
  name = parsed.name;
4563
4563
  }
4564
4564
  } catch (err3) {
@@ -4577,7 +4577,7 @@ async function discoverNetwork(input) {
4577
4577
  try {
4578
4578
  const descriptor = await input.node.fetchByNetworkId(networkId);
4579
4579
  if (descriptor !== null) {
4580
- const validated = validateDescriptor(descriptor, networkId, principal, name);
4580
+ const validated = validateDescriptor(descriptor, networkId, ownerDid, name);
4581
4581
  if (!validated.ok) return validated;
4582
4582
  return { ok: true, data: { descriptor: validated.data, source: "node" } };
4583
4583
  }
@@ -4587,11 +4587,11 @@ async function discoverNetwork(input) {
4587
4587
  if (input.wellKnown !== void 0) {
4588
4588
  try {
4589
4589
  const descriptor = await input.wellKnown.fetchWellKnown(
4590
- principal,
4590
+ ownerDid,
4591
4591
  networkDiscoveryKey(name)
4592
4592
  );
4593
4593
  if (descriptor !== null) {
4594
- const validated = validateDescriptor(descriptor, networkId, principal, name);
4594
+ const validated = validateDescriptor(descriptor, networkId, ownerDid, name);
4595
4595
  if (!validated.ok) return validated;
4596
4596
  return {
4597
4597
  ok: true,
@@ -4610,7 +4610,7 @@ async function discoverNetwork(input) {
4610
4610
  })
4611
4611
  };
4612
4612
  }
4613
- function validateDescriptor(descriptor, networkId, principal, name) {
4613
+ function validateDescriptor(descriptor, networkId, ownerDid, name) {
4614
4614
  if (descriptor.networkId !== networkId) {
4615
4615
  return {
4616
4616
  ok: false,
@@ -4620,12 +4620,12 @@ function validateDescriptor(descriptor, networkId, principal, name) {
4620
4620
  })
4621
4621
  };
4622
4622
  }
4623
- if (descriptor.principal !== principal) {
4623
+ if (descriptor.ownerDid !== ownerDid) {
4624
4624
  return {
4625
4625
  ok: false,
4626
4626
  error: encryptionError({
4627
4627
  code: "INVALID_NETWORK_ID",
4628
- message: "descriptor principal does not match networkId principal"
4628
+ message: "descriptor ownerDid does not match networkId ownerDid"
4629
4629
  })
4630
4630
  };
4631
4631
  }
@@ -5117,10 +5117,10 @@ var EncryptionService = class extends BaseService {
5117
5117
  get crypto() {
5118
5118
  return this._config.crypto;
5119
5119
  }
5120
- async discoverNetwork(identifier, principal) {
5120
+ async discoverNetwork(identifier, ownerDid) {
5121
5121
  const result = await discoverNetwork({
5122
5122
  identifier,
5123
- ...principal !== void 0 ? { principal } : {},
5123
+ ...ownerDid !== void 0 ? { ownerDid } : {},
5124
5124
  ...this._config.node !== void 0 ? { node: this._config.node } : {},
5125
5125
  ...this._config.wellKnown !== void 0 ? { wellKnown: this._config.wellKnown } : {}
5126
5126
  });