@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.
@@ -100,12 +100,12 @@ interface InlineEncryptedEnvelope {
100
100
  /**
101
101
  * Node-published network descriptor. The node DB is authoritative; a
102
102
  * cached copy may also live under
103
- * `.well-known/encryption/network/<name>` in the principal's account
103
+ * `.well-known/encryption/network/<name>` in the owner's account
104
104
  * space (a discovery record only).
105
105
  */
106
106
  interface NetworkDescriptor {
107
107
  networkId: string;
108
- principal: string;
108
+ ownerDid: string;
109
109
  name: string;
110
110
  members: ReadonlyArray<{
111
111
  nodeId: string;
@@ -234,7 +234,7 @@ interface ReceiverKeySigner {
234
234
  }
235
235
  /** Capability proof material accompanying a decrypt invocation. */
236
236
  interface DecryptCapabilityProof {
237
- /** Delegation chain CIDs rooted at the network principal. */
237
+ /** Delegation chain CIDs rooted at the network owner DID. */
238
238
  proofs: ReadonlyArray<string>;
239
239
  /** Optional Authorization header value to use instead of building one. */
240
240
  authorization?: string;
@@ -334,7 +334,7 @@ type CanonicalJson = Json;
334
334
  * descriptor (`state`, `publicEncryptionKey`, `keyVersion`, ...).
335
335
  * 2. If the node is unreachable, fall back to the cached discovery
336
336
  * record at `.well-known/encryption/network/<name>` inside the
337
- * principal's public space.
337
+ * owner's public space.
338
338
  *
339
339
  * The node DB is authoritative on conflict; cached records are
340
340
  * advisory only.
@@ -351,16 +351,16 @@ interface NodeDescriptorFetcher {
351
351
  }
352
352
  interface WellKnownDescriptorFetcher {
353
353
  /**
354
- * Read the cached well-known descriptor by principal + network name.
354
+ * Read the cached well-known descriptor by owner DID + network name.
355
355
  * Returns null if no record exists or the record is unreadable.
356
356
  */
357
- fetchWellKnown(principal: string, discoveryKey: string): Promise<NetworkDescriptor | null>;
357
+ fetchWellKnown(ownerDid: string, discoveryKey: string): Promise<NetworkDescriptor | null>;
358
358
  }
359
359
  interface DiscoverNetworkInput {
360
- /** Either a networkId URN or a bare network name (paired with `principal`). */
360
+ /** Either a networkId URN or a bare network name (paired with `ownerDid`). */
361
361
  identifier: string;
362
362
  /** Required when identifier is a bare name. */
363
- principal?: string;
363
+ ownerDid?: string;
364
364
  node?: NodeDescriptorFetcher;
365
365
  wellKnown?: WellKnownDescriptorFetcher;
366
366
  }
@@ -368,7 +368,7 @@ interface DiscoverNetworkInput {
368
368
  * Resolve a network descriptor. The node fetcher is preferred; the
369
369
  * well-known fallback is used only on transport failure.
370
370
  *
371
- * The returned descriptor is sanity-checked: `networkId`, `principal`,
371
+ * The returned descriptor is sanity-checked: `networkId`, `ownerDid`,
372
372
  * and `name` must agree with the URN, and the public key field must
373
373
  * be non-empty.
374
374
  */
@@ -431,10 +431,10 @@ interface IEncryptionService extends IService {
431
431
  *
432
432
  * `identifier` may be either a full networkId URN
433
433
  * (`urn:tinycloud:encryption:did:key:...:default`) or a bare network
434
- * name. The bare name form requires the principal to be supplied via
435
- * `principal`.
434
+ * name. The bare name form requires the owner DID to be supplied via
435
+ * `ownerDid`.
436
436
  */
437
- discoverNetwork(identifier: string, principal?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
437
+ discoverNetwork(identifier: string, ownerDid?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
438
438
  /**
439
439
  * Encrypt plaintext to the network's public key locally. The result
440
440
  * is an inline envelope ready to persist (KV/SQL).
@@ -447,7 +447,7 @@ interface IEncryptionService extends IService {
447
447
  * decrypt invocation, POST it to the node, verify the signed
448
448
  * response, open `wrappedKey`, and decrypt the payload locally.
449
449
  *
450
- * The capability proof must root at the network principal embedded
450
+ * The capability proof must root at the network owner DID embedded
451
451
  * in the envelope's networkId.
452
452
  */
453
453
  decryptEnvelope(envelope: InlineEncryptedEnvelope, capabilityProof: DecryptCapabilityProof, options?: DecryptEnvelopeOptions): Promise<Result<Uint8Array, EncryptionError>>;
@@ -497,7 +497,7 @@ declare class EncryptionService extends BaseService implements IEncryptionServic
497
497
  constructor(config: EncryptionServiceConfig);
498
498
  get config(): EncryptionServiceConfig;
499
499
  private get crypto();
500
- discoverNetwork(identifier: string, principal?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
500
+ discoverNetwork(identifier: string, ownerDid?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
501
501
  encryptToNetwork(networkId: string, plaintext: Uint8Array, options?: EncryptToNetworkOptions): Promise<Result<InlineEncryptedEnvelope, EncryptionError>>;
502
502
  decryptEnvelope(envelope: InlineEncryptedEnvelope, capabilityProof: DecryptCapabilityProof, options?: DecryptEnvelopeOptions): Promise<Result<Uint8Array, EncryptionError>>;
503
503
  }
@@ -505,27 +505,27 @@ declare class EncryptionService extends BaseService implements IEncryptionServic
505
505
  /**
506
506
  * TinyCloud encryption network identifiers.
507
507
  *
508
- * A network id is `urn:tinycloud:encryption:<principal>:<network>` where
509
- * `principal` is a DID (typically `did:key:...`) and `network` is a
508
+ * A network id is `urn:tinycloud:encryption:<ownerDid>:<network>` where
509
+ * `ownerDid` is the owner's DID and `network` is a
510
510
  * non-empty label drawn from `[a-z0-9][a-z0-9-]*`.
511
511
  *
512
- * The embedded principal is the root authority for the network: any
512
+ * The embedded owner DID is the root authority for the network: any
513
513
  * delegation chain ending in a `tinycloud.encryption/decrypt` grant on
514
- * the network must root at this principal.
514
+ * the network must root at this owner DID.
515
515
  */
516
516
  interface ParsedNetworkId {
517
517
  /** The full URN string. */
518
518
  networkId: string;
519
- /** Principal DID embedded in the URN (the network's root authority). */
520
- principal: string;
521
- /** Network label (the suffix after the principal). */
519
+ /** Owner DID embedded in the URN (the network's root authority). */
520
+ ownerDid: string;
521
+ /** Network label (the suffix after the owner DID). */
522
522
  name: string;
523
523
  }
524
524
  declare class NetworkIdError extends Error {
525
525
  constructor(message: string);
526
526
  }
527
527
  /**
528
- * Parse a network id string into its principal and name components.
528
+ * Parse a network id string into its owner DID and name components.
529
529
  *
530
530
  * Throws {@link NetworkIdError} when the input does not match
531
531
  * `urn:tinycloud:encryption:<did>:<name>`, when the embedded DID is
@@ -533,17 +533,17 @@ declare class NetworkIdError extends Error {
533
533
  */
534
534
  declare function parseNetworkId(networkId: string): ParsedNetworkId;
535
535
  /**
536
- * Construct a network id URN from a principal DID and a network name.
536
+ * Construct a network id URN from an owner DID and a network name.
537
537
  * Validates inputs and throws {@link NetworkIdError} on bad shape.
538
538
  */
539
- declare function buildNetworkId(principal: string, name: string): string;
539
+ declare function buildNetworkId(ownerDid: string, name: string): string;
540
540
  /**
541
541
  * Returns true when {@link networkId} is a syntactically valid network URN.
542
542
  */
543
543
  declare function isNetworkId(networkId: unknown): networkId is string;
544
544
  /**
545
545
  * Resolve the discovery key used to look up a network's descriptor under
546
- * a principal's public account-space.
546
+ * an owner's public account-space.
547
547
  *
548
548
  * Format: `.well-known/encryption/network/<name>`.
549
549
  */
@@ -100,12 +100,12 @@ interface InlineEncryptedEnvelope {
100
100
  /**
101
101
  * Node-published network descriptor. The node DB is authoritative; a
102
102
  * cached copy may also live under
103
- * `.well-known/encryption/network/<name>` in the principal's account
103
+ * `.well-known/encryption/network/<name>` in the owner's account
104
104
  * space (a discovery record only).
105
105
  */
106
106
  interface NetworkDescriptor {
107
107
  networkId: string;
108
- principal: string;
108
+ ownerDid: string;
109
109
  name: string;
110
110
  members: ReadonlyArray<{
111
111
  nodeId: string;
@@ -234,7 +234,7 @@ interface ReceiverKeySigner {
234
234
  }
235
235
  /** Capability proof material accompanying a decrypt invocation. */
236
236
  interface DecryptCapabilityProof {
237
- /** Delegation chain CIDs rooted at the network principal. */
237
+ /** Delegation chain CIDs rooted at the network owner DID. */
238
238
  proofs: ReadonlyArray<string>;
239
239
  /** Optional Authorization header value to use instead of building one. */
240
240
  authorization?: string;
@@ -334,7 +334,7 @@ type CanonicalJson = Json;
334
334
  * descriptor (`state`, `publicEncryptionKey`, `keyVersion`, ...).
335
335
  * 2. If the node is unreachable, fall back to the cached discovery
336
336
  * record at `.well-known/encryption/network/<name>` inside the
337
- * principal's public space.
337
+ * owner's public space.
338
338
  *
339
339
  * The node DB is authoritative on conflict; cached records are
340
340
  * advisory only.
@@ -351,16 +351,16 @@ interface NodeDescriptorFetcher {
351
351
  }
352
352
  interface WellKnownDescriptorFetcher {
353
353
  /**
354
- * Read the cached well-known descriptor by principal + network name.
354
+ * Read the cached well-known descriptor by owner DID + network name.
355
355
  * Returns null if no record exists or the record is unreadable.
356
356
  */
357
- fetchWellKnown(principal: string, discoveryKey: string): Promise<NetworkDescriptor | null>;
357
+ fetchWellKnown(ownerDid: string, discoveryKey: string): Promise<NetworkDescriptor | null>;
358
358
  }
359
359
  interface DiscoverNetworkInput {
360
- /** Either a networkId URN or a bare network name (paired with `principal`). */
360
+ /** Either a networkId URN or a bare network name (paired with `ownerDid`). */
361
361
  identifier: string;
362
362
  /** Required when identifier is a bare name. */
363
- principal?: string;
363
+ ownerDid?: string;
364
364
  node?: NodeDescriptorFetcher;
365
365
  wellKnown?: WellKnownDescriptorFetcher;
366
366
  }
@@ -368,7 +368,7 @@ interface DiscoverNetworkInput {
368
368
  * Resolve a network descriptor. The node fetcher is preferred; the
369
369
  * well-known fallback is used only on transport failure.
370
370
  *
371
- * The returned descriptor is sanity-checked: `networkId`, `principal`,
371
+ * The returned descriptor is sanity-checked: `networkId`, `ownerDid`,
372
372
  * and `name` must agree with the URN, and the public key field must
373
373
  * be non-empty.
374
374
  */
@@ -431,10 +431,10 @@ interface IEncryptionService extends IService {
431
431
  *
432
432
  * `identifier` may be either a full networkId URN
433
433
  * (`urn:tinycloud:encryption:did:key:...:default`) or a bare network
434
- * name. The bare name form requires the principal to be supplied via
435
- * `principal`.
434
+ * name. The bare name form requires the owner DID to be supplied via
435
+ * `ownerDid`.
436
436
  */
437
- discoverNetwork(identifier: string, principal?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
437
+ discoverNetwork(identifier: string, ownerDid?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
438
438
  /**
439
439
  * Encrypt plaintext to the network's public key locally. The result
440
440
  * is an inline envelope ready to persist (KV/SQL).
@@ -447,7 +447,7 @@ interface IEncryptionService extends IService {
447
447
  * decrypt invocation, POST it to the node, verify the signed
448
448
  * response, open `wrappedKey`, and decrypt the payload locally.
449
449
  *
450
- * The capability proof must root at the network principal embedded
450
+ * The capability proof must root at the network owner DID embedded
451
451
  * in the envelope's networkId.
452
452
  */
453
453
  decryptEnvelope(envelope: InlineEncryptedEnvelope, capabilityProof: DecryptCapabilityProof, options?: DecryptEnvelopeOptions): Promise<Result<Uint8Array, EncryptionError>>;
@@ -497,7 +497,7 @@ declare class EncryptionService extends BaseService implements IEncryptionServic
497
497
  constructor(config: EncryptionServiceConfig);
498
498
  get config(): EncryptionServiceConfig;
499
499
  private get crypto();
500
- discoverNetwork(identifier: string, principal?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
500
+ discoverNetwork(identifier: string, ownerDid?: string): Promise<Result<NetworkDescriptor, EncryptionError>>;
501
501
  encryptToNetwork(networkId: string, plaintext: Uint8Array, options?: EncryptToNetworkOptions): Promise<Result<InlineEncryptedEnvelope, EncryptionError>>;
502
502
  decryptEnvelope(envelope: InlineEncryptedEnvelope, capabilityProof: DecryptCapabilityProof, options?: DecryptEnvelopeOptions): Promise<Result<Uint8Array, EncryptionError>>;
503
503
  }
@@ -505,27 +505,27 @@ declare class EncryptionService extends BaseService implements IEncryptionServic
505
505
  /**
506
506
  * TinyCloud encryption network identifiers.
507
507
  *
508
- * A network id is `urn:tinycloud:encryption:<principal>:<network>` where
509
- * `principal` is a DID (typically `did:key:...`) and `network` is a
508
+ * A network id is `urn:tinycloud:encryption:<ownerDid>:<network>` where
509
+ * `ownerDid` is the owner's DID and `network` is a
510
510
  * non-empty label drawn from `[a-z0-9][a-z0-9-]*`.
511
511
  *
512
- * The embedded principal is the root authority for the network: any
512
+ * The embedded owner DID is the root authority for the network: any
513
513
  * delegation chain ending in a `tinycloud.encryption/decrypt` grant on
514
- * the network must root at this principal.
514
+ * the network must root at this owner DID.
515
515
  */
516
516
  interface ParsedNetworkId {
517
517
  /** The full URN string. */
518
518
  networkId: string;
519
- /** Principal DID embedded in the URN (the network's root authority). */
520
- principal: string;
521
- /** Network label (the suffix after the principal). */
519
+ /** Owner DID embedded in the URN (the network's root authority). */
520
+ ownerDid: string;
521
+ /** Network label (the suffix after the owner DID). */
522
522
  name: string;
523
523
  }
524
524
  declare class NetworkIdError extends Error {
525
525
  constructor(message: string);
526
526
  }
527
527
  /**
528
- * Parse a network id string into its principal and name components.
528
+ * Parse a network id string into its owner DID and name components.
529
529
  *
530
530
  * Throws {@link NetworkIdError} when the input does not match
531
531
  * `urn:tinycloud:encryption:<did>:<name>`, when the embedded DID is
@@ -533,17 +533,17 @@ declare class NetworkIdError extends Error {
533
533
  */
534
534
  declare function parseNetworkId(networkId: string): ParsedNetworkId;
535
535
  /**
536
- * Construct a network id URN from a principal DID and a network name.
536
+ * Construct a network id URN from an owner DID and a network name.
537
537
  * Validates inputs and throws {@link NetworkIdError} on bad shape.
538
538
  */
539
- declare function buildNetworkId(principal: string, name: string): string;
539
+ declare function buildNetworkId(ownerDid: string, name: string): string;
540
540
  /**
541
541
  * Returns true when {@link networkId} is a syntactically valid network URN.
542
542
  */
543
543
  declare function isNetworkId(networkId: unknown): networkId is string;
544
544
  /**
545
545
  * Resolve the discovery key used to look up a network's descriptor under
546
- * a principal's public account-space.
546
+ * an owner's public account-space.
547
547
  *
548
548
  * Format: `.well-known/encryption/network/<name>`.
549
549
  */
@@ -406,20 +406,20 @@ function parseNetworkId(networkId) {
406
406
  const lastColon = body.lastIndexOf(":");
407
407
  if (lastColon <= 0 || lastColon === body.length - 1) {
408
408
  throw new NetworkIdError(
409
- `networkId missing principal or name segment (got ${JSON.stringify(networkId)})`
409
+ `networkId missing ownerDid or name segment (got ${JSON.stringify(networkId)})`
410
410
  );
411
411
  }
412
- const principal = body.slice(0, lastColon);
412
+ const ownerDid = body.slice(0, lastColon);
413
413
  const name = body.slice(lastColon + 1);
414
- if (!principal.startsWith("did:")) {
414
+ if (!ownerDid.startsWith("did:")) {
415
415
  throw new NetworkIdError(
416
- `networkId principal must be a DID (got ${JSON.stringify(principal)})`
416
+ `networkId ownerDid must be a DID (got ${JSON.stringify(ownerDid)})`
417
417
  );
418
418
  }
419
- const didParts = principal.split(":");
419
+ const didParts = ownerDid.split(":");
420
420
  if (didParts.length < 3 || didParts.some((p) => p.length === 0)) {
421
421
  throw new NetworkIdError(
422
- `networkId principal is not a well-formed DID (got ${JSON.stringify(principal)})`
422
+ `networkId ownerDid is not a well-formed DID (got ${JSON.stringify(ownerDid)})`
423
423
  );
424
424
  }
425
425
  if (!NETWORK_NAME_RE.test(name)) {
@@ -427,18 +427,18 @@ function parseNetworkId(networkId) {
427
427
  `networkId name ${JSON.stringify(name)} must match ${NETWORK_NAME_RE.source}`
428
428
  );
429
429
  }
430
- return { networkId, principal, name };
430
+ return { networkId, ownerDid, name };
431
431
  }
432
- function buildNetworkId(principal, name) {
433
- if (typeof principal !== "string" || !principal.startsWith("did:")) {
434
- throw new NetworkIdError("principal must be a DID");
432
+ function buildNetworkId(ownerDid, name) {
433
+ if (typeof ownerDid !== "string" || !ownerDid.startsWith("did:")) {
434
+ throw new NetworkIdError("ownerDid must be a DID");
435
435
  }
436
436
  if (typeof name !== "string" || !NETWORK_NAME_RE.test(name)) {
437
437
  throw new NetworkIdError(
438
438
  `network name ${JSON.stringify(name)} must match ${NETWORK_NAME_RE.source}`
439
439
  );
440
440
  }
441
- const networkId = `${URN_PREFIX}${principal}:${name}`;
441
+ const networkId = `${URN_PREFIX}${ownerDid}:${name}`;
442
442
  parseNetworkId(networkId);
443
443
  return networkId;
444
444
  }
@@ -515,27 +515,27 @@ function toError(error) {
515
515
  // src/encryption/discovery.ts
516
516
  async function discoverNetwork(input) {
517
517
  let networkId;
518
- let principal;
518
+ let ownerDid;
519
519
  let name;
520
520
  try {
521
521
  if (input.identifier.startsWith("urn:tinycloud:encryption:")) {
522
522
  const parsed = parseNetworkId(input.identifier);
523
523
  networkId = parsed.networkId;
524
- principal = parsed.principal;
524
+ ownerDid = parsed.ownerDid;
525
525
  name = parsed.name;
526
526
  } else {
527
- if (input.principal === void 0) {
527
+ if (input.ownerDid === void 0) {
528
528
  return {
529
529
  ok: false,
530
530
  error: encryptionError({
531
531
  code: "INVALID_INPUT",
532
- message: "discoverNetwork requires `principal` when identifier is a bare network name"
532
+ message: "discoverNetwork requires `ownerDid` when identifier is a bare network name"
533
533
  })
534
534
  };
535
535
  }
536
- networkId = `urn:tinycloud:encryption:${input.principal}:${input.identifier}`;
536
+ networkId = `urn:tinycloud:encryption:${input.ownerDid}:${input.identifier}`;
537
537
  const parsed = parseNetworkId(networkId);
538
- principal = parsed.principal;
538
+ ownerDid = parsed.ownerDid;
539
539
  name = parsed.name;
540
540
  }
541
541
  } catch (err2) {
@@ -554,7 +554,7 @@ async function discoverNetwork(input) {
554
554
  try {
555
555
  const descriptor = await input.node.fetchByNetworkId(networkId);
556
556
  if (descriptor !== null) {
557
- const validated = validateDescriptor(descriptor, networkId, principal, name);
557
+ const validated = validateDescriptor(descriptor, networkId, ownerDid, name);
558
558
  if (!validated.ok) return validated;
559
559
  return { ok: true, data: { descriptor: validated.data, source: "node" } };
560
560
  }
@@ -564,11 +564,11 @@ async function discoverNetwork(input) {
564
564
  if (input.wellKnown !== void 0) {
565
565
  try {
566
566
  const descriptor = await input.wellKnown.fetchWellKnown(
567
- principal,
567
+ ownerDid,
568
568
  networkDiscoveryKey(name)
569
569
  );
570
570
  if (descriptor !== null) {
571
- const validated = validateDescriptor(descriptor, networkId, principal, name);
571
+ const validated = validateDescriptor(descriptor, networkId, ownerDid, name);
572
572
  if (!validated.ok) return validated;
573
573
  return {
574
574
  ok: true,
@@ -587,7 +587,7 @@ async function discoverNetwork(input) {
587
587
  })
588
588
  };
589
589
  }
590
- function validateDescriptor(descriptor, networkId, principal, name) {
590
+ function validateDescriptor(descriptor, networkId, ownerDid, name) {
591
591
  if (descriptor.networkId !== networkId) {
592
592
  return {
593
593
  ok: false,
@@ -597,12 +597,12 @@ function validateDescriptor(descriptor, networkId, principal, name) {
597
597
  })
598
598
  };
599
599
  }
600
- if (descriptor.principal !== principal) {
600
+ if (descriptor.ownerDid !== ownerDid) {
601
601
  return {
602
602
  ok: false,
603
603
  error: encryptionError({
604
604
  code: "INVALID_NETWORK_ID",
605
- message: "descriptor principal does not match networkId principal"
605
+ message: "descriptor ownerDid does not match networkId ownerDid"
606
606
  })
607
607
  };
608
608
  }
@@ -1094,10 +1094,10 @@ var EncryptionService = class extends BaseService {
1094
1094
  get crypto() {
1095
1095
  return this._config.crypto;
1096
1096
  }
1097
- async discoverNetwork(identifier, principal) {
1097
+ async discoverNetwork(identifier, ownerDid) {
1098
1098
  const result = await discoverNetwork({
1099
1099
  identifier,
1100
- ...principal !== void 0 ? { principal } : {},
1100
+ ...ownerDid !== void 0 ? { ownerDid } : {},
1101
1101
  ...this._config.node !== void 0 ? { node: this._config.node } : {},
1102
1102
  ...this._config.wellKnown !== void 0 ? { wellKnown: this._config.wellKnown } : {}
1103
1103
  });