@enbox/dwn-server 0.0.6 → 0.0.7

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.
@@ -5,6 +5,7 @@ import type { ProcessHandlers } from './process-handlers.js';
5
5
  import type { Server } from 'bun';
6
6
  import type { WsData } from './http-api.js';
7
7
  import { Dwn } from '@enbox/dwn-sdk-js';
8
+ import { OpenAuthHandler } from './registration/open-auth-handler.js';
8
9
  import { RegistrationManager } from './registration/registration-manager.js';
9
10
  /**
10
11
  * Options for the DwnServer constructor.
@@ -26,6 +27,22 @@ export type DwnServerOptions = {
26
27
  * are appended after the DeliveryService hook.
27
28
  */
28
29
  messageProcessedHooks?: MessageProcessedHook[];
30
+ /**
31
+ * An externally created RegistrationManager to use as the tenant gate and
32
+ * registration endpoint handler. When a pre-built `dwn` is provided, the
33
+ * server cannot create its own RegistrationManager (because it doesn't
34
+ * control the DWN's TenantGate). Pass one here to enable registration
35
+ * endpoints (`POST /registration`, etc.) with a pre-built DWN.
36
+ */
37
+ registrationManager?: RegistrationManager;
38
+ /**
39
+ * An externally created OpenAuthHandler for the built-in provider-auth
40
+ * endpoints (`/provider-auth/authorize`, `/provider-auth/token`,
41
+ * `/provider-auth/refresh`). When a pre-built `dwn` is provided, the
42
+ * server skips creating this handler. Pass one here to enable the
43
+ * open-auth flow with a pre-built DWN.
44
+ */
45
+ openAuthHandler?: OpenAuthHandler;
29
46
  };
30
47
  /**
31
48
  * State of the DwnServer, either Stopped or Started, to help short-circuit start and stop logic.
@@ -46,7 +63,9 @@ export declare class DwnServer {
46
63
  dwn?: Dwn;
47
64
  config: DwnServerConfig;
48
65
  /**
49
- * @param options.dwn - Dwn instance to use as an override. Registration endpoint will not be enabled if this is provided.
66
+ * @param options.dwn - Dwn instance to use as an override.
67
+ * @param options.registrationManager - External RegistrationManager to use with a pre-built DWN.
68
+ * @param options.openAuthHandler - External OpenAuthHandler to use with a pre-built DWN.
50
69
  */
51
70
  constructor(options?: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C,EAAE,GAAG,CAAC;IACV,MAAM,EAAE,eAAe,CAAC;IAWxB;;;;OAIG;gBACS,OAAO,GAAE,gBAAqB;IAe1C;;OAEG;IACG,KAAK,IAAI,OAAO,CAAC,IAAI,CAAC;IAmQ5B;;OAEG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAoC3B,IAAI,UAAU,IAAI,MAAM,CAAC,MAAM,CAAC,CAE/B;IAED;;OAEG;IACH,IAAI,mBAAmB,IAAI,mBAAmB,CAE7C;CACF"}
@@ -44,14 +44,20 @@ export class DwnServer {
44
44
  #tenantRateLimiter;
45
45
  #auditLog;
46
46
  #externalHooks;
47
+ #externalRegistrationManager;
48
+ #externalOpenAuthHandler;
47
49
  /**
48
- * @param options.dwn - Dwn instance to use as an override. Registration endpoint will not be enabled if this is provided.
50
+ * @param options.dwn - Dwn instance to use as an override.
51
+ * @param options.registrationManager - External RegistrationManager to use with a pre-built DWN.
52
+ * @param options.openAuthHandler - External OpenAuthHandler to use with a pre-built DWN.
49
53
  */
50
54
  constructor(options = {}) {
51
55
  this.config = options.config ?? defaultConfig;
52
56
  this.didResolver = options.didResolver;
53
57
  this.dwn = options.dwn;
54
58
  this.#externalHooks = options.messageProcessedHooks ?? [];
59
+ this.#externalRegistrationManager = options.registrationManager;
60
+ this.#externalOpenAuthHandler = options.openAuthHandler;
55
61
  log.setLevel(this.config.logLevel);
56
62
  prefix.reg(log);
57
63
  prefix.apply(log);
@@ -74,44 +80,8 @@ export class DwnServer {
74
80
  async #setupServer() {
75
81
  let registrationManager;
76
82
  if (!this.dwn) {
77
- // Load provider auth plugin if configured.
78
- let providerAuthPlugin;
79
- if (this.config.providerAuthEnabled) {
80
- if (this.config.providerAuthPluginPath) {
81
- // Custom external plugin.
82
- providerAuthPlugin = await loadProviderAuthPlugin(this.config.providerAuthPluginPath);
83
- log.info('Provider auth plugin loaded from path');
84
- }
85
- else if (this.config.providerAuthJwtSecret || this.config.providerAuthJwtJwksUrl) {
86
- // Built-in JWT plugin.
87
- providerAuthPlugin = await JwtProviderAuthPlugin.create({
88
- secret: this.config.providerAuthJwtSecret,
89
- jwksUrl: this.config.providerAuthJwtJwksUrl,
90
- issuer: this.config.baseUrl,
91
- audience: this.config.baseUrl,
92
- });
93
- log.info('Built-in JWT provider auth plugin created');
94
- }
95
- }
96
- // undefined registrationStoreUrl is used as a signal that there is no need for tenant registration, DWN is open for all.
97
- registrationManager = await RegistrationManager.create({
98
- registrationStoreUrl: this.config.registrationStoreUrl,
99
- termsOfServiceFilePath: this.config.termsOfServiceFilePath,
100
- proofOfWorkChallengeNonceSeed: this.config.registrationProofOfWorkSeed,
101
- proofOfWorkInitialMaximumAllowedHash: this.config.registrationProofOfWorkInitialMaxHash,
102
- providerAuthPlugin,
103
- });
104
- // Warn if the tenant gate is active but no registration method is enabled.
105
- // This is almost certainly a misconfiguration — new tenants will be rejected
106
- // with 401 and have no way to register.
107
- if (this.config.registrationStoreUrl
108
- && !this.config.registrationProofOfWorkEnabled
109
- && !providerAuthPlugin) {
110
- log.warn('*** WARNING: DWN_REGISTRATION_STORE_URL is set (tenant gate active) but neither ' +
111
- 'proof-of-work (DWN_REGISTRATION_PROOF_OF_WORK_ENABLED) nor provider auth ' +
112
- '(DWN_PROVIDER_AUTH_ENABLED + secret/plugin) is configured. ' +
113
- 'New tenants will be unable to register. ***');
114
- }
83
+ // No pre-built DWN create everything from scratch including registration.
84
+ registrationManager = await this.#createRegistrationManager();
115
85
  let eventLog;
116
86
  if (this.config.webSocketSupport) {
117
87
  // If EventLog plugin is not specified, use `EventEmitterEventLog` implementation as default.
@@ -137,6 +107,12 @@ export class DwnServer {
137
107
  });
138
108
  this.dwn = await Dwn.create(dwnConfig);
139
109
  }
110
+ else if (this.#externalRegistrationManager) {
111
+ // Pre-built DWN with an externally-provided RegistrationManager.
112
+ // The caller is responsible for passing this RegistrationManager as the
113
+ // TenantGate when creating the DWN instance.
114
+ registrationManager = this.#externalRegistrationManager;
115
+ }
140
116
  // Assemble message-processed hooks.
141
117
  const messageProcessedHooks = [];
142
118
  // Add the built-in DeliveryService hook when forwarding or delivery is enabled.
@@ -227,10 +203,13 @@ export class DwnServer {
227
203
  this.#auditLog = auditLog;
228
204
  // Create open-auth handler if provider auth is enabled with a JWT secret
229
205
  // and authorize/token URLs point to this server (or are not set — defaulting to built-in).
230
- let openAuthHandler;
231
- if (this.config.providerAuthEnabled && this.config.providerAuthJwtSecret && !this.config.providerAuthPluginPath) {
206
+ // An externally-provided handler (e.g. from the relay) takes precedence.
207
+ let openAuthHandler = this.#externalOpenAuthHandler;
208
+ if (!openAuthHandler && this.config.providerAuthEnabled && this.config.providerAuthJwtSecret && !this.config.providerAuthPluginPath) {
232
209
  openAuthHandler = OpenAuthHandler.create(this.config.providerAuthJwtSecret, this.config.baseUrl);
233
210
  log.info('Built-in open-auth endpoints enabled');
211
+ }
212
+ if (openAuthHandler) {
234
213
  // Auto-configure authorize/token/refresh URLs if not explicitly set.
235
214
  if (!this.config.providerAuthAuthorizeUrl) {
236
215
  this.config.providerAuthAuthorizeUrl = `${this.config.baseUrl}/provider-auth/authorize`;
@@ -259,6 +238,51 @@ export class DwnServer {
259
238
  adminApi.startMetricsUpdater();
260
239
  }
261
240
  }
241
+ /**
242
+ * Creates a RegistrationManager based on the server config. Factored out of
243
+ * `#setupServer()` so the same logic can be reused regardless of whether the
244
+ * DWN is created internally or externally.
245
+ */
246
+ async #createRegistrationManager() {
247
+ // Load provider auth plugin if configured.
248
+ let providerAuthPlugin;
249
+ if (this.config.providerAuthEnabled) {
250
+ if (this.config.providerAuthPluginPath) {
251
+ // Custom external plugin.
252
+ providerAuthPlugin = await loadProviderAuthPlugin(this.config.providerAuthPluginPath);
253
+ log.info('Provider auth plugin loaded from path');
254
+ }
255
+ else if (this.config.providerAuthJwtSecret || this.config.providerAuthJwtJwksUrl) {
256
+ // Built-in JWT plugin.
257
+ providerAuthPlugin = await JwtProviderAuthPlugin.create({
258
+ secret: this.config.providerAuthJwtSecret,
259
+ jwksUrl: this.config.providerAuthJwtJwksUrl,
260
+ issuer: this.config.baseUrl,
261
+ audience: this.config.baseUrl,
262
+ });
263
+ log.info('Built-in JWT provider auth plugin created');
264
+ }
265
+ }
266
+ // undefined registrationStoreUrl is used as a signal that there is no need
267
+ // for tenant registration, DWN is open for all.
268
+ const registrationManager = await RegistrationManager.create({
269
+ registrationStoreUrl: this.config.registrationStoreUrl,
270
+ termsOfServiceFilePath: this.config.termsOfServiceFilePath,
271
+ proofOfWorkChallengeNonceSeed: this.config.registrationProofOfWorkSeed,
272
+ proofOfWorkInitialMaximumAllowedHash: this.config.registrationProofOfWorkInitialMaxHash,
273
+ providerAuthPlugin,
274
+ });
275
+ // Warn if the tenant gate is active but no registration method is enabled.
276
+ if (this.config.registrationStoreUrl
277
+ && !this.config.registrationProofOfWorkEnabled
278
+ && !providerAuthPlugin) {
279
+ log.warn('*** WARNING: DWN_REGISTRATION_STORE_URL is set (tenant gate active) but neither ' +
280
+ 'proof-of-work (DWN_REGISTRATION_PROOF_OF_WORK_ENABLED) nor provider auth ' +
281
+ '(DWN_PROVIDER_AUTH_ENABLED + secret/plugin) is configured. ' +
282
+ 'New tenants will be unable to register. ***');
283
+ }
284
+ return registrationManager;
285
+ }
262
286
  /**
263
287
  * Stops the DWN server.
264
288
  */
@@ -1 +1 @@
1
- {"version":3,"file":"dwn-server.js","sourceRoot":"","sources":["../../../src/dwn-server.ts"],"names":[],"mappings":"AASA,OAAO,GAAG,MAAM,UAAU,CAAC;AAC3B,OAAO,MAAM,MAAM,wBAAwB,CAAC;AAC5C,OAAO,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,EAAE,sBAAsB,EAAE,MAAM,EAAE,iBAAiB,EAAE,MAAM,aAAa,CAAC;AACxG,OAAO,EAAE,GAAG,EAAE,oBAAoB,EAAE,MAAM,mBAAmB,CAAC;AAI9D,OAAO,EAAE,WAAW,EAAE,MAAM,yBAAyB,CAAC;AACtD,OAAO,EAAE,QAAQ,EAAE,MAAM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AAC;CACF"}
@@ -6,6 +6,8 @@ export { DwnServer, DwnServerOptions } from './dwn-server.js';
6
6
  export { HttpApi } from './http-api.js';
7
7
  export { jsonRpcRouter } from './json-rpc-api.js';
8
8
  export type { MessageProcessedContext, MessageProcessedHook } from './message-processed-hook.js';
9
+ export { OpenAuthHandler } from './registration/open-auth-handler.js';
10
+ export { RegistrationManager } from './registration/registration-manager.js';
9
11
  export { getDwnConfig, StoreType, BackendTypes, DwnStore } from './storage.js';
10
12
  export { WsApi } from './ws-api.js';
11
13
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACrE,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,IAAI,sBAAsB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,YAAY,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACjG,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AACrE,YAAY,EACV,kBAAkB,EAClB,uBAAuB,EACvB,gBAAgB,EAChB,gBAAgB,EAChB,iBAAiB,EACjB,kBAAkB,GACnB,MAAM,kBAAkB,CAAC;AAC1B,OAAO,EAAE,MAAM,IAAI,sBAAsB,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAClD,YAAY,EAAE,uBAAuB,EAAE,oBAAoB,EAAE,MAAM,6BAA6B,CAAC;AACjG,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
@@ -4,6 +4,8 @@ export { DeliveryService } from './delivery-service.js';
4
4
  export { DwnServer } from './dwn-server.js';
5
5
  export { HttpApi } from './http-api.js';
6
6
  export { jsonRpcRouter } from './json-rpc-api.js';
7
+ export { OpenAuthHandler } from './registration/open-auth-handler.js';
8
+ export { RegistrationManager } from './registration/registration-manager.js';
7
9
  export { getDwnConfig, StoreType, BackendTypes } from './storage.js';
8
10
  export { WsApi } from './ws-api.js';
9
11
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AASrE,OAAO,EAAE,MAAM,IAAI,sBAAsB,EAAmB,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAY,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AASrE,OAAO,EAAE,MAAM,IAAI,sBAAsB,EAAmB,MAAM,aAAa,CAAC;AAChF,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,SAAS,EAAoB,MAAM,iBAAiB,CAAC;AAC9D,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,mBAAmB,CAAC;AAElD,OAAO,EAAE,eAAe,EAAE,MAAM,qCAAqC,CAAC;AACtE,OAAO,EAAE,mBAAmB,EAAE,MAAM,wCAAwC,CAAC;AAC7E,OAAO,EAAE,YAAY,EAAE,SAAS,EAAE,YAAY,EAAY,MAAM,cAAc,CAAC;AAC/E,OAAO,EAAE,KAAK,EAAE,MAAM,aAAa,CAAC"}
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@enbox/dwn-server",
3
3
  "type": "module",
4
- "version": "0.0.6",
4
+ "version": "0.0.7",
5
5
  "license": "Apache-2.0",
6
6
  "files": [
7
7
  "dist",
package/src/dwn-server.ts CHANGED
@@ -52,6 +52,24 @@ export type DwnServerOptions = {
52
52
  * are appended after the DeliveryService hook.
53
53
  */
54
54
  messageProcessedHooks?: MessageProcessedHook[];
55
+
56
+ /**
57
+ * An externally created RegistrationManager to use as the tenant gate and
58
+ * registration endpoint handler. When a pre-built `dwn` is provided, the
59
+ * server cannot create its own RegistrationManager (because it doesn't
60
+ * control the DWN's TenantGate). Pass one here to enable registration
61
+ * endpoints (`POST /registration`, etc.) with a pre-built DWN.
62
+ */
63
+ registrationManager?: RegistrationManager;
64
+
65
+ /**
66
+ * An externally created OpenAuthHandler for the built-in provider-auth
67
+ * endpoints (`/provider-auth/authorize`, `/provider-auth/token`,
68
+ * `/provider-auth/refresh`). When a pre-built `dwn` is provided, the
69
+ * server skips creating this handler. Pass one here to enable the
70
+ * open-auth flow with a pre-built DWN.
71
+ */
72
+ openAuthHandler?: OpenAuthHandler;
55
73
  };
56
74
 
57
75
  /**
@@ -80,9 +98,13 @@ export class DwnServer {
80
98
  #tenantRateLimiter: RateLimiter | undefined;
81
99
  #auditLog: AuditLog | undefined;
82
100
  #externalHooks: MessageProcessedHook[];
101
+ #externalRegistrationManager: RegistrationManager | undefined;
102
+ #externalOpenAuthHandler: OpenAuthHandler | undefined;
83
103
 
84
104
  /**
85
- * @param options.dwn - Dwn instance to use as an override. Registration endpoint will not be enabled if this is provided.
105
+ * @param options.dwn - Dwn instance to use as an override.
106
+ * @param options.registrationManager - External RegistrationManager to use with a pre-built DWN.
107
+ * @param options.openAuthHandler - External OpenAuthHandler to use with a pre-built DWN.
86
108
  */
87
109
  constructor(options: DwnServerOptions = {}) {
88
110
  this.config = options.config ?? defaultConfig;
@@ -90,6 +112,8 @@ export class DwnServer {
90
112
  this.didResolver = options.didResolver;
91
113
  this.dwn = options.dwn;
92
114
  this.#externalHooks = options.messageProcessedHooks ?? [];
115
+ this.#externalRegistrationManager = options.registrationManager;
116
+ this.#externalOpenAuthHandler = options.openAuthHandler;
93
117
 
94
118
  log.setLevel(this.config.logLevel as log.LogLevelDesc);
95
119
 
@@ -116,49 +140,11 @@ export class DwnServer {
116
140
  */
117
141
  async #setupServer(): Promise<void> {
118
142
 
119
- let registrationManager: RegistrationManager;
120
- if (!this.dwn) {
121
- // Load provider auth plugin if configured.
122
- let providerAuthPlugin: ProviderAuthPlugin | undefined;
123
- if (this.config.providerAuthEnabled) {
124
- if (this.config.providerAuthPluginPath) {
125
- // Custom external plugin.
126
- providerAuthPlugin = await loadProviderAuthPlugin(this.config.providerAuthPluginPath);
127
- log.info('Provider auth plugin loaded from path');
128
- } else if (this.config.providerAuthJwtSecret || this.config.providerAuthJwtJwksUrl) {
129
- // Built-in JWT plugin.
130
- providerAuthPlugin = await JwtProviderAuthPlugin.create({
131
- secret : this.config.providerAuthJwtSecret,
132
- jwksUrl : this.config.providerAuthJwtJwksUrl,
133
- issuer : this.config.baseUrl,
134
- audience : this.config.baseUrl,
135
- });
136
- log.info('Built-in JWT provider auth plugin created');
137
- }
138
- }
143
+ let registrationManager: RegistrationManager | undefined;
139
144
 
140
- // undefined registrationStoreUrl is used as a signal that there is no need for tenant registration, DWN is open for all.
141
- registrationManager = await RegistrationManager.create({
142
- registrationStoreUrl : this.config.registrationStoreUrl,
143
- termsOfServiceFilePath : this.config.termsOfServiceFilePath,
144
- proofOfWorkChallengeNonceSeed : this.config.registrationProofOfWorkSeed,
145
- proofOfWorkInitialMaximumAllowedHash : this.config.registrationProofOfWorkInitialMaxHash,
146
- providerAuthPlugin,
147
- });
148
-
149
- // Warn if the tenant gate is active but no registration method is enabled.
150
- // This is almost certainly a misconfiguration — new tenants will be rejected
151
- // with 401 and have no way to register.
152
- if (this.config.registrationStoreUrl
153
- && !this.config.registrationProofOfWorkEnabled
154
- && !providerAuthPlugin) {
155
- log.warn(
156
- '*** WARNING: DWN_REGISTRATION_STORE_URL is set (tenant gate active) but neither ' +
157
- 'proof-of-work (DWN_REGISTRATION_PROOF_OF_WORK_ENABLED) nor provider auth ' +
158
- '(DWN_PROVIDER_AUTH_ENABLED + secret/plugin) is configured. ' +
159
- 'New tenants will be unable to register. ***',
160
- );
161
- }
145
+ if (!this.dwn) {
146
+ // No pre-built DWN — create everything from scratch including registration.
147
+ registrationManager = await this.#createRegistrationManager();
162
148
 
163
149
  let eventLog: EventLog | undefined;
164
150
  if (this.config.webSocketSupport) {
@@ -186,6 +172,11 @@ export class DwnServer {
186
172
  eventLog,
187
173
  });
188
174
  this.dwn = await Dwn.create(dwnConfig);
175
+ } else if (this.#externalRegistrationManager) {
176
+ // Pre-built DWN with an externally-provided RegistrationManager.
177
+ // The caller is responsible for passing this RegistrationManager as the
178
+ // TenantGate when creating the DWN instance.
179
+ registrationManager = this.#externalRegistrationManager;
189
180
  }
190
181
 
191
182
  // Assemble message-processed hooks.
@@ -291,14 +282,17 @@ export class DwnServer {
291
282
 
292
283
  // Create open-auth handler if provider auth is enabled with a JWT secret
293
284
  // and authorize/token URLs point to this server (or are not set — defaulting to built-in).
294
- let openAuthHandler: OpenAuthHandler | undefined;
295
- if (this.config.providerAuthEnabled && this.config.providerAuthJwtSecret && !this.config.providerAuthPluginPath) {
285
+ // An externally-provided handler (e.g. from the relay) takes precedence.
286
+ let openAuthHandler: OpenAuthHandler | undefined = this.#externalOpenAuthHandler;
287
+ if (!openAuthHandler && this.config.providerAuthEnabled && this.config.providerAuthJwtSecret && !this.config.providerAuthPluginPath) {
296
288
  openAuthHandler = OpenAuthHandler.create(
297
289
  this.config.providerAuthJwtSecret,
298
290
  this.config.baseUrl,
299
291
  );
300
292
  log.info('Built-in open-auth endpoints enabled');
293
+ }
301
294
 
295
+ if (openAuthHandler) {
302
296
  // Auto-configure authorize/token/refresh URLs if not explicitly set.
303
297
  if (!this.config.providerAuthAuthorizeUrl) {
304
298
  this.config.providerAuthAuthorizeUrl = `${this.config.baseUrl}/provider-auth/authorize`;
@@ -339,6 +333,56 @@ export class DwnServer {
339
333
  }
340
334
  }
341
335
 
336
+ /**
337
+ * Creates a RegistrationManager based on the server config. Factored out of
338
+ * `#setupServer()` so the same logic can be reused regardless of whether the
339
+ * DWN is created internally or externally.
340
+ */
341
+ async #createRegistrationManager(): Promise<RegistrationManager> {
342
+ // Load provider auth plugin if configured.
343
+ let providerAuthPlugin: ProviderAuthPlugin | undefined;
344
+ if (this.config.providerAuthEnabled) {
345
+ if (this.config.providerAuthPluginPath) {
346
+ // Custom external plugin.
347
+ providerAuthPlugin = await loadProviderAuthPlugin(this.config.providerAuthPluginPath);
348
+ log.info('Provider auth plugin loaded from path');
349
+ } else if (this.config.providerAuthJwtSecret || this.config.providerAuthJwtJwksUrl) {
350
+ // Built-in JWT plugin.
351
+ providerAuthPlugin = await JwtProviderAuthPlugin.create({
352
+ secret : this.config.providerAuthJwtSecret,
353
+ jwksUrl : this.config.providerAuthJwtJwksUrl,
354
+ issuer : this.config.baseUrl,
355
+ audience : this.config.baseUrl,
356
+ });
357
+ log.info('Built-in JWT provider auth plugin created');
358
+ }
359
+ }
360
+
361
+ // undefined registrationStoreUrl is used as a signal that there is no need
362
+ // for tenant registration, DWN is open for all.
363
+ const registrationManager = await RegistrationManager.create({
364
+ registrationStoreUrl : this.config.registrationStoreUrl,
365
+ termsOfServiceFilePath : this.config.termsOfServiceFilePath,
366
+ proofOfWorkChallengeNonceSeed : this.config.registrationProofOfWorkSeed,
367
+ proofOfWorkInitialMaximumAllowedHash : this.config.registrationProofOfWorkInitialMaxHash,
368
+ providerAuthPlugin,
369
+ });
370
+
371
+ // Warn if the tenant gate is active but no registration method is enabled.
372
+ if (this.config.registrationStoreUrl
373
+ && !this.config.registrationProofOfWorkEnabled
374
+ && !providerAuthPlugin) {
375
+ log.warn(
376
+ '*** WARNING: DWN_REGISTRATION_STORE_URL is set (tenant gate active) but neither ' +
377
+ 'proof-of-work (DWN_REGISTRATION_PROOF_OF_WORK_ENABLED) nor provider auth ' +
378
+ '(DWN_PROVIDER_AUTH_ENABLED + secret/plugin) is configured. ' +
379
+ 'New tenants will be unable to register. ***',
380
+ );
381
+ }
382
+
383
+ return registrationManager;
384
+ }
385
+
342
386
  /**
343
387
  * Stops the DWN server.
344
388
  */
package/src/index.ts CHANGED
@@ -13,5 +13,7 @@ export { DwnServer, DwnServerOptions } from './dwn-server.js';
13
13
  export { HttpApi } from './http-api.js';
14
14
  export { jsonRpcRouter } from './json-rpc-api.js';
15
15
  export type { MessageProcessedContext, MessageProcessedHook } from './message-processed-hook.js';
16
+ export { OpenAuthHandler } from './registration/open-auth-handler.js';
17
+ export { RegistrationManager } from './registration/registration-manager.js';
16
18
  export { getDwnConfig, StoreType, BackendTypes, DwnStore } from './storage.js';
17
19
  export { WsApi } from './ws-api.js';