@dxos/edge-client 0.9.1-main.c7dcc2e112 → 0.10.0

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.
@@ -16,14 +16,14 @@ import "./chunk-J5LGTIGS.mjs";
16
16
  export * from "@dxos/protocols/buf/dxos/edge/messenger_pb";
17
17
 
18
18
  // src/auth.ts
19
- import { createCredential, signPresentation } from "@dxos/credentials";
19
+ import { createCredential, createDidFromIdentityKey, signPresentation } from "@dxos/credentials";
20
20
  import { invariant } from "@dxos/invariant";
21
21
  import { Keyring } from "@dxos/keyring";
22
- import { PublicKey } from "@dxos/keys";
22
+ import { IdentityDid, PublicKey } from "@dxos/keys";
23
23
  var __dxlog_file = "/__w/dxos/dxos/packages/core/mesh/edge-client/src/auth.ts";
24
24
  var createDeviceEdgeIdentity = async (signer, key) => {
25
25
  return {
26
- identityKey: key.toHex(),
26
+ identityDid: await createDidFromIdentityKey(key),
27
27
  peerKey: key.toHex(),
28
28
  presentCredentials: async ({ challenge }) => {
29
29
  return signPresentation({
@@ -61,7 +61,7 @@ var createChainEdgeIdentity = async (signer, identityKey, peerKey, chain, creden
61
61
  })
62
62
  ];
63
63
  return {
64
- identityKey: identityKey.toHex(),
64
+ identityDid: await createDidFromIdentityKey(identityKey),
65
65
  peerKey: peerKey.toHex(),
66
66
  presentCredentials: async ({ challenge }) => {
67
67
  invariant(chain, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file, L: 56, S: void 0, A: ["chain", ""] });
@@ -107,10 +107,10 @@ var createTestHaloEdgeIdentity = async (signer, identityKey, deviceKey) => {
107
107
  ]);
108
108
  };
109
109
  var createStubEdgeIdentity = () => {
110
- const identityKey = PublicKey.random();
111
110
  const deviceKey = PublicKey.random();
112
111
  return {
113
- identityKey: identityKey.toHex(),
112
+ // Random placeholder DID — the stub never authenticates or connects; a real identity replaces it.
113
+ identityDid: IdentityDid.random(),
114
114
  peerKey: deviceKey.toHex(),
115
115
  presentCredentials: async () => {
116
116
  throw new Error("Stub identity does not support authentication.");
@@ -185,7 +185,7 @@ var EdgeWsConnection = class extends Resource {
185
185
  get info() {
186
186
  return {
187
187
  open: this.isOpen,
188
- identity: this._identity.identityKey,
188
+ identity: this._identity.identityDid,
189
189
  device: this._identity.peerKey
190
190
  };
191
191
  }
@@ -460,7 +460,7 @@ var EdgeClient = class extends Resource2 {
460
460
  return {
461
461
  open: this.isOpen,
462
462
  status: this.status,
463
- identity: this._identity.identityKey,
463
+ identity: this._identity.identityDid,
464
464
  device: this._identity.peerKey
465
465
  };
466
466
  }
@@ -475,14 +475,14 @@ var EdgeClient = class extends Resource2 {
475
475
  messagesReceived: this._currentConnection?.messagesReceived ?? 0
476
476
  };
477
477
  }
478
- get identityKey() {
479
- return this._identity.identityKey;
478
+ get identityDid() {
479
+ return this._identity.identityDid;
480
480
  }
481
481
  get peerKey() {
482
482
  return this._identity.peerKey;
483
483
  }
484
484
  setIdentity(identity) {
485
- if (identity.identityKey !== this._identity.identityKey || identity.peerKey !== this._identity.peerKey) {
485
+ if (identity.identityDid !== this._identity.identityDid || identity.peerKey !== this._identity.peerKey) {
486
486
  log2("Edge identity changed", {
487
487
  identity,
488
488
  oldIdentity: this._identity
@@ -506,7 +506,7 @@ var EdgeClient = class extends Resource2 {
506
506
  if (!this._currentConnection) {
507
507
  throw new EdgeConnectionClosedError();
508
508
  }
509
- if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityKey !== this.identityKey)) {
509
+ if (message.source && (message.source.peerKey !== this._identity.peerKey || message.source.identityDid !== this.identityDid)) {
510
510
  throw new EdgeIdentityChangedError();
511
511
  }
512
512
  const traceCtx = ctx.getAttribute(TRACE_SPAN_ATTRIBUTE);
@@ -531,7 +531,7 @@ var EdgeClient = class extends Resource2 {
531
531
  try {
532
532
  listener();
533
533
  } catch (error) {
534
- log2.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 123, S: this });
534
+ log2.catch(error, void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 124, S: this });
535
535
  }
536
536
  }
537
537
  });
@@ -544,11 +544,11 @@ var EdgeClient = class extends Resource2 {
544
544
  async _open() {
545
545
  log2("opening...", {
546
546
  info: this.info
547
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 133, S: this });
547
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 134, S: this });
548
548
  this._persistentLifecycle.open().catch((err) => {
549
549
  log2.warn("Error while opening connection", {
550
550
  err
551
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 137, S: this });
551
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 138, S: this });
552
552
  });
553
553
  scheduleTaskInterval2(this._ctx, async () => {
554
554
  if (!this._currentConnection) {
@@ -563,7 +563,7 @@ var EdgeClient = class extends Resource2 {
563
563
  async _close() {
564
564
  log2("closing...", {
565
565
  peerKey: this._identity.peerKey
566
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 152, S: this });
566
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 153, S: this });
567
567
  this._closeCurrentConnection();
568
568
  await this._persistentLifecycle.close();
569
569
  }
@@ -572,10 +572,10 @@ var EdgeClient = class extends Resource2 {
572
572
  return void 0;
573
573
  }
574
574
  const identity = this._identity;
575
- const path = `/ws/${identity.identityKey}/${identity.peerKey}`;
575
+ const path = `/ws/${identity.identityDid}/${identity.peerKey}`;
576
576
  const protocolHeader = this._config.disableAuth ? void 0 : await this._createAuthHeader(path);
577
577
  if (this._identity !== identity) {
578
- log2("identity changed during auth header request", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 166, S: this });
578
+ log2("identity changed during auth header request", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 167, S: this });
579
579
  return void 0;
580
580
  }
581
581
  const restartRequired = new Trigger();
@@ -583,7 +583,7 @@ var EdgeClient = class extends Resource2 {
583
583
  log2("Opening websocket", {
584
584
  url: url.toString(),
585
585
  protocolHeader
586
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 171, S: this });
586
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 172, S: this });
587
587
  const connection = new EdgeWsConnection(identity, {
588
588
  url,
589
589
  protocolHeader,
@@ -596,7 +596,7 @@ var EdgeClient = class extends Resource2 {
596
596
  this._ready.wake();
597
597
  this._notifyReconnected();
598
598
  } else {
599
- log2.verbose("connected callback ignored, because connection is not active", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 187, S: this });
599
+ log2.verbose("connected callback ignored, because connection is not active", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 188, S: this });
600
600
  }
601
601
  },
602
602
  onRestartRequired: () => {
@@ -604,7 +604,7 @@ var EdgeClient = class extends Resource2 {
604
604
  this._closeCurrentConnection();
605
605
  void this._persistentLifecycle.scheduleRestart();
606
606
  } else {
607
- log2.verbose("restart requested by inactive connection", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 195, S: this });
607
+ log2.verbose("restart requested by inactive connection", void 0, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 196, S: this });
608
608
  }
609
609
  restartRequired.wake();
610
610
  },
@@ -615,7 +615,7 @@ var EdgeClient = class extends Resource2 {
615
615
  log2.verbose("ignored a message on inactive connection", {
616
616
  from: message.source,
617
617
  type: message.payload?.typeUrl
618
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 203, S: this });
618
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 204, S: this });
619
619
  }
620
620
  }
621
621
  });
@@ -650,7 +650,7 @@ var EdgeClient = class extends Resource2 {
650
650
  } catch (err) {
651
651
  log2.error("ws reconnect listener failed", {
652
652
  err
653
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 244, S: this });
653
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 245, S: this });
654
654
  }
655
655
  }
656
656
  }
@@ -662,7 +662,7 @@ var EdgeClient = class extends Resource2 {
662
662
  log2.error("ws incoming message processing failed", {
663
663
  err,
664
664
  payload: protocol.getPayloadType(message)
665
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 255, S: this });
665
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 256, S: this });
666
666
  }
667
667
  }
668
668
  }
@@ -678,7 +678,7 @@ var EdgeClient = class extends Resource2 {
678
678
  log2.warn("no auth challenge from edge", {
679
679
  status: response.status,
680
680
  statusText: response.statusText
681
- }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 271, S: this });
681
+ }, { "~LogMeta": "~LogMeta", F: __dxlog_file4, L: 272, S: this });
682
682
  return void 0;
683
683
  }
684
684
  }
@@ -760,7 +760,7 @@ var BaseHttpClient = class {
760
760
  return this._baseUrl;
761
761
  }
762
762
  setIdentity(identity) {
763
- if (this._edgeIdentity?.identityKey !== identity.identityKey || this._edgeIdentity?.peerKey !== identity.peerKey) {
763
+ if (this._edgeIdentity?.identityDid !== identity.identityDid || this._edgeIdentity?.peerKey !== identity.peerKey) {
764
764
  this._edgeIdentity = identity;
765
765
  this._authHeader = void 0;
766
766
  }
@@ -1086,7 +1086,7 @@ var EdgeHttpClient = class extends BaseHttpClient {
1086
1086
  });
1087
1087
  }
1088
1088
  getAgentStatus(ctx, request, args) {
1089
- return this._call(ctx, new URL(`/users/${request.ownerIdentityKey.toHex()}/agent/status`, this.baseUrl), {
1089
+ return this._call(ctx, new URL(`/users/${request.ownerIdentityDid}/agent/status`, this.baseUrl), {
1090
1090
  ...args,
1091
1091
  method: "GET"
1092
1092
  });
@@ -1195,7 +1195,8 @@ var EdgeHttpClient = class extends BaseHttpClient {
1195
1195
  const formData = new FormData();
1196
1196
  formData.append("name", body.name ?? "");
1197
1197
  formData.append("version", body.version);
1198
- formData.append("ownerPublicKey", body.ownerPublicKey);
1198
+ const ownerUri = this._edgeIdentity?.identityDid ?? body.ownerUri;
1199
+ formData.append("ownerUri", ownerUri);
1199
1200
  formData.append("entryPoint", body.entryPoint);
1200
1201
  body.runtime && formData.append("runtime", body.runtime);
1201
1202
  for (const [filename, content] of Object.entries(body.assets)) {