@enbox/agent 0.3.1 → 0.4.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.
Files changed (57) hide show
  1. package/dist/browser.mjs +12 -30
  2. package/dist/browser.mjs.map +4 -4
  3. package/dist/esm/connect.js +20 -24
  4. package/dist/esm/connect.js.map +1 -1
  5. package/dist/esm/dwn-api.js +149 -22
  6. package/dist/esm/dwn-api.js.map +1 -1
  7. package/dist/esm/dwn-discovery-file.js +1 -1
  8. package/dist/esm/dwn-discovery-payload.js +20 -21
  9. package/dist/esm/dwn-discovery-payload.js.map +1 -1
  10. package/dist/esm/dwn-key-delivery.js.map +1 -1
  11. package/dist/esm/{oidc.js → enbox-connect-protocol.js} +236 -248
  12. package/dist/esm/enbox-connect-protocol.js.map +1 -0
  13. package/dist/esm/enbox-user-agent.js +18 -5
  14. package/dist/esm/enbox-user-agent.js.map +1 -1
  15. package/dist/esm/index.js +4 -2
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/local-dwn.js +21 -51
  18. package/dist/esm/local-dwn.js.map +1 -1
  19. package/dist/esm/permissions-api.js.map +1 -1
  20. package/dist/esm/store-data.js.map +1 -1
  21. package/dist/esm/sync-engine-level.js +1 -1
  22. package/dist/esm/sync-engine-level.js.map +1 -1
  23. package/dist/esm/sync-messages.js +1 -1
  24. package/dist/esm/sync-messages.js.map +1 -1
  25. package/dist/types/connect.d.ts +15 -19
  26. package/dist/types/connect.d.ts.map +1 -1
  27. package/dist/types/dwn-api.d.ts +46 -6
  28. package/dist/types/dwn-api.d.ts.map +1 -1
  29. package/dist/types/dwn-discovery-file.d.ts +1 -1
  30. package/dist/types/dwn-discovery-payload.d.ts +18 -19
  31. package/dist/types/dwn-discovery-payload.d.ts.map +1 -1
  32. package/dist/types/enbox-connect-protocol.d.ts +220 -0
  33. package/dist/types/enbox-connect-protocol.d.ts.map +1 -0
  34. package/dist/types/enbox-user-agent.d.ts +10 -1
  35. package/dist/types/enbox-user-agent.d.ts.map +1 -1
  36. package/dist/types/index.d.ts +1 -2
  37. package/dist/types/index.d.ts.map +1 -1
  38. package/dist/types/local-dwn.d.ts +16 -32
  39. package/dist/types/local-dwn.d.ts.map +1 -1
  40. package/package.json +9 -11
  41. package/src/connect.ts +38 -47
  42. package/src/dwn-api.ts +175 -29
  43. package/src/dwn-discovery-file.ts +1 -1
  44. package/src/dwn-discovery-payload.ts +23 -24
  45. package/src/dwn-key-delivery.ts +1 -1
  46. package/src/enbox-connect-protocol.ts +778 -0
  47. package/src/enbox-user-agent.ts +27 -4
  48. package/src/index.ts +4 -2
  49. package/src/local-dwn.ts +22 -53
  50. package/src/permissions-api.ts +3 -3
  51. package/src/store-data.ts +1 -1
  52. package/src/sync-engine-level.ts +1 -1
  53. package/src/sync-messages.ts +1 -1
  54. package/dist/esm/oidc.js.map +0 -1
  55. package/dist/types/oidc.d.ts +0 -250
  56. package/dist/types/oidc.d.ts.map +0 -1
  57. package/src/oidc.ts +0 -864
@@ -1,8 +1,8 @@
1
1
  /**
2
- * Shared types and utilities for the `dwn://register` discovery protocol.
2
+ * Shared types and utilities for the `dwn://connect` discovery protocol.
3
3
  *
4
4
  * The payload is the JSON data exchanged between the local DWN server
5
- * (electrobun-dwn) and the requesting app during the `dwn://register`
5
+ * (electrobun-dwn) and the requesting app during the `dwn://connect`
6
6
  * redirect flow. It is encoded as base64url and placed in the URL
7
7
  * fragment (`#`) of the callback URL.
8
8
  *
@@ -10,14 +10,13 @@
10
10
  * consumed from any environment (Bun, browser, Electrobun) without
11
11
  * triggering transitive dependency resolution issues.
12
12
  *
13
- * @see https://github.com/enboxorg/enbox/issues/586
14
13
  * @module
15
14
  */
16
15
 
17
16
  // ─── Types ────────────────────────────────────────────────────────
18
17
 
19
18
  /**
20
- * The JSON payload delivered via the URL fragment in a `dwn://register`
19
+ * The JSON payload delivered via the URL fragment in a `dwn://connect`
21
20
  * callback redirect.
22
21
  *
23
22
  * Intentionally minimal — everything beyond the endpoint (version,
@@ -29,9 +28,9 @@ export type DwnDiscoveryPayload = {
29
28
  };
30
29
 
31
30
  /**
32
- * Parsed result from a `dwn://register` URL.
31
+ * Parsed result from a `dwn://connect` URL.
33
32
  */
34
- export type DwnRegisterUrlParams = {
33
+ export type DwnConnectUrlParams = {
35
34
  /** The callback URL to redirect to with the discovery payload. */
36
35
  callback: string;
37
36
  };
@@ -41,17 +40,17 @@ export type DwnRegisterUrlParams = {
41
40
  /** The URL scheme for DWN discovery protocol handlers. */
42
41
  export const DWN_PROTOCOL_SCHEME = 'dwn';
43
42
 
44
- /** The `dwn://register` path that triggers the discovery handshake. */
45
- export const DWN_REGISTER_PATH = 'register';
43
+ /** The `dwn://connect` path that triggers the discovery handshake. */
44
+ export const DWN_CONNECT_PATH = 'connect';
46
45
 
47
46
  // ─── Register URL construction ───────────────────────────────────
48
47
 
49
48
  /**
50
- * Build a `dwn://register?callback=<url>` URL that, when opened by the OS,
49
+ * Build a `dwn://connect?callback=<url>` URL that, when opened by the OS,
51
50
  * triggers electrobun-dwn (or another `dwn://` scheme handler) to redirect
52
51
  * back to `callbackUrl` with the local DWN endpoint in the URL fragment.
53
52
  *
54
- * This is the **trigger** side of the `dwn://register` browser flow.
53
+ * This is the **trigger** side of the `dwn://connect` browser flow.
55
54
  * The web app opens this URL (e.g. via `window.open()` or `location.href`),
56
55
  * the OS routes it to the registered handler, and the handler redirects
57
56
  * back with the discovery payload.
@@ -59,17 +58,17 @@ export const DWN_REGISTER_PATH = 'register';
59
58
  * @param callbackUrl - The URL to redirect back to after discovery.
60
59
  * This should be the current page (or a dedicated callback page) that
61
60
  * will read the payload from `window.location.hash`.
62
- * @returns The `dwn://register?callback=<encoded-url>` URL string.
61
+ * @returns The `dwn://connect?callback=<encoded-url>` URL string.
63
62
  *
64
63
  * @example
65
64
  * ```ts
66
- * const registerUrl = buildDwnRegisterUrl('https://myapp.com/callback');
67
- * // => 'dwn://register?callback=https%3A%2F%2Fmyapp.com%2Fcallback'
65
+ * const registerUrl = buildDwnConnectUrl('https://myapp.com/callback');
66
+ * // => 'dwn://connect?callback=https%3A%2F%2Fmyapp.com%2Fcallback'
68
67
  * window.open(registerUrl);
69
68
  * ```
70
69
  */
71
- export function buildDwnRegisterUrl(callbackUrl: string): string {
72
- return `${DWN_PROTOCOL_SCHEME}://${DWN_REGISTER_PATH}?callback=${encodeURIComponent(callbackUrl)}`;
70
+ export function buildDwnConnectUrl(callbackUrl: string): string {
71
+ return `${DWN_PROTOCOL_SCHEME}://${DWN_CONNECT_PATH}?callback=${encodeURIComponent(callbackUrl)}`;
73
72
  }
74
73
 
75
74
  // ─── Payload encoding/decoding ───────────────────────────────────
@@ -110,15 +109,15 @@ export function decodeDwnDiscoveryPayload(encoded: string): DwnDiscoveryPayload
110
109
  // ─── URL parsing ─────────────────────────────────────────────────
111
110
 
112
111
  /**
113
- * Parse a `dwn://register?callback=<url>` URL into its components.
112
+ * Parse a `dwn://connect?callback=<url>` URL into its components.
114
113
  *
115
- * @param url - The full `dwn://register?callback=...` URL.
114
+ * @param url - The full `dwn://connect?callback=...` URL.
116
115
  * @returns The parsed parameters, or `undefined` if the URL is not a
117
- * valid `dwn://register` URL or is missing the `callback` parameter.
116
+ * valid `dwn://connect` URL or is missing the `callback` parameter.
118
117
  */
119
- export function parseDwnRegisterUrl(url: string): DwnRegisterUrlParams | undefined {
118
+ export function parseDwnConnectUrl(url: string): DwnConnectUrlParams | undefined {
120
119
  try {
121
- // dwn://register?callback=... is not a standard hierarchical URL, so
120
+ // dwn://connect?callback=... is not a standard hierarchical URL, so
122
121
  // we parse it manually to avoid URL constructor quirks with custom schemes.
123
122
  const schemePrefix = `${DWN_PROTOCOL_SCHEME}://`;
124
123
  if (!url.startsWith(schemePrefix)) {
@@ -134,7 +133,7 @@ export function parseDwnRegisterUrl(url: string): DwnRegisterUrlParams | undefin
134
133
  }
135
134
 
136
135
  const path = withoutScheme.slice(0, questionIndex);
137
- if (path !== DWN_REGISTER_PATH) {
136
+ if (path !== DWN_CONNECT_PATH) {
138
137
  return undefined;
139
138
  }
140
139
 
@@ -156,7 +155,7 @@ export function parseDwnRegisterUrl(url: string): DwnRegisterUrlParams | undefin
156
155
  * Build the full callback redirect URL with the discovery payload
157
156
  * encoded in the URL fragment.
158
157
  *
159
- * @param callbackUrl - The callback URL from the `dwn://register` request.
158
+ * @param callbackUrl - The callback URL from the `dwn://connect` request.
160
159
  * @param payload - The discovery payload to encode in the fragment.
161
160
  * @returns The full redirect URL (e.g. `https://notes.sh/dwn#eyJ...`).
162
161
  */
@@ -202,7 +201,7 @@ export function readDwnDiscoveryPayloadFromUrl(url: string): DwnDiscoveryPayload
202
201
  * Type guard for a valid {@link DwnDiscoveryPayload}.
203
202
  *
204
203
  * The endpoint MUST point to a loopback address (`127.0.0.1`, `[::1]`,
205
- * or `localhost`) because the `dwn://register` payload is only intended
204
+ * or `localhost`) because the `dwn://connect` payload is only intended
206
205
  * for local DWN discovery. Accepting arbitrary hostnames would allow a
207
206
  * malicious payload to redirect agent traffic to a remote server.
208
207
  *
@@ -231,7 +230,7 @@ function isValidPayload(value: unknown): value is DwnDiscoveryPayload {
231
230
  * address. Accepts `127.0.0.1`, `::1` (with or without brackets), and
232
231
  * `localhost` (bare or with any subdomain suffix, per RFC 6761 §6.3).
233
232
  *
234
- * This is a security boundary: the `dwn://register` redirect flow MUST
233
+ * This is a security boundary: the `dwn://connect` redirect flow MUST
235
234
  * NOT allow payloads that point to non-local servers.
236
235
  */
237
236
  function isLoopbackEndpoint(endpoint: string): boolean {
@@ -174,7 +174,7 @@ export async function writeContextKeyRecord(
174
174
  target : tenantDid,
175
175
  messageType : DwnInterface.RecordsWrite,
176
176
  messageParams : { ...contextKeyParams, dataCid, dataSize, encryptionInput },
177
- dataStream : new Blob([encryptedBytes]),
177
+ dataStream : new Blob([encryptedBytes as BlobPart]),
178
178
  }));
179
179
  } else {
180
180
  // --- Fallback: encrypt to the owner's key (local self-delivery) ---