@naylence/runtime 0.3.5-test.911 → 0.3.5-test.913

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 (31) hide show
  1. package/dist/browser/index.cjs +72 -164
  2. package/dist/browser/index.mjs +72 -164
  3. package/dist/cjs/naylence/fame/config/extended-fame-config.js +52 -0
  4. package/dist/cjs/naylence/fame/http/jwks-api-router.js +16 -18
  5. package/dist/cjs/naylence/fame/http/oauth2-server.js +28 -31
  6. package/dist/cjs/naylence/fame/http/oauth2-token-router.js +153 -8
  7. package/dist/cjs/naylence/fame/http/openid-configuration-router.js +30 -32
  8. package/dist/cjs/naylence/fame/node/admission/admission-profile-factory.js +18 -0
  9. package/dist/cjs/naylence/fame/security/crypto/providers/default-crypto-provider.js +0 -162
  10. package/dist/cjs/version.js +2 -2
  11. package/dist/esm/naylence/fame/config/extended-fame-config.js +52 -0
  12. package/dist/esm/naylence/fame/http/jwks-api-router.js +16 -17
  13. package/dist/esm/naylence/fame/http/oauth2-server.js +28 -31
  14. package/dist/esm/naylence/fame/http/oauth2-token-router.js +153 -8
  15. package/dist/esm/naylence/fame/http/openid-configuration-router.js +30 -31
  16. package/dist/esm/naylence/fame/node/admission/admission-profile-factory.js +18 -0
  17. package/dist/esm/naylence/fame/security/crypto/providers/default-crypto-provider.js +0 -162
  18. package/dist/esm/version.js +2 -2
  19. package/dist/node/index.cjs +72 -164
  20. package/dist/node/index.mjs +72 -164
  21. package/dist/node/node.cjs +299 -249
  22. package/dist/node/node.mjs +299 -249
  23. package/dist/types/naylence/fame/http/jwks-api-router.d.ts +8 -8
  24. package/dist/types/naylence/fame/http/oauth2-server.d.ts +3 -3
  25. package/dist/types/naylence/fame/http/oauth2-token-router.d.ts +5 -5
  26. package/dist/types/naylence/fame/http/openid-configuration-router.d.ts +8 -8
  27. package/dist/types/naylence/fame/security/crypto/providers/default-crypto-provider.d.ts +0 -1
  28. package/dist/types/version.d.ts +1 -1
  29. package/package.json +4 -6
  30. package/dist/esm/naylence/fame/fastapi/oauth2-server.js +0 -205
  31. package/dist/types/naylence/fame/fastapi/oauth2-server.d.ts +0 -22
@@ -1,9 +1,8 @@
1
1
  /**
2
- * OpenID Connect Discovery configuration router for Express
2
+ * OpenID Connect Discovery configuration plugin for Fastify
3
3
  *
4
4
  * Provides /.well-known/openid-configuration endpoint for OAuth2/OIDC client auto-discovery
5
5
  */
6
- import express from 'express';
7
6
  import { getLogger } from '../util/logging.js';
8
7
  const logger = getLogger('naylence.fame.http.openid_configuration_router');
9
8
  const DEFAULT_PREFIX = '';
@@ -77,10 +76,10 @@ function getAllowedScopes(configScopes) {
77
76
  return configScopes ?? ['node.connect'];
78
77
  }
79
78
  /**
80
- * Create an Express router that implements OpenID Connect Discovery
79
+ * Create a Fastify plugin that implements OpenID Connect Discovery
81
80
  *
82
81
  * @param options - Router configuration options
83
- * @returns Express router with OpenID configuration endpoint
82
+ * @returns Fastify plugin with OpenID configuration endpoint
84
83
  *
85
84
  * Environment Variables:
86
85
  * FAME_JWT_ISSUER: JWT issuer claim (optional)
@@ -89,17 +88,16 @@ function getAllowedScopes(configScopes) {
89
88
  *
90
89
  * @example
91
90
  * ```typescript
92
- * import express from 'express';
91
+ * import Fastify from 'fastify';
93
92
  * import { createOpenIDConfigurationRouter } from '@naylence/runtime';
94
93
  *
95
- * const app = express();
96
- * app.use(createOpenIDConfigurationRouter({
94
+ * const app = Fastify();
95
+ * app.register(createOpenIDConfigurationRouter({
97
96
  * issuer: 'https://auth.example.com',
98
97
  * }));
99
98
  * ```
100
99
  */
101
100
  export function createOpenIDConfigurationRouter(options = {}) {
102
- const router = express.Router();
103
101
  const { prefix = DEFAULT_PREFIX, issuer, baseUrl, tokenEndpointPath = '/oauth/token', jwksEndpointPath = '/.well-known/jwks.json', allowedScopes: configAllowedScopes, algorithm: configAlgorithm, } = normalizeOpenIDConfigurationRouterOptions(options);
104
102
  // Resolve configuration with environment variable priority
105
103
  const defaultIssuer = process.env[ENV_VAR_JWT_ISSUER] ?? issuer ?? 'https://auth.fame.fabric';
@@ -115,27 +113,28 @@ export function createOpenIDConfigurationRouter(options = {}) {
115
113
  algorithm,
116
114
  allowedScopes,
117
115
  });
118
- // OpenID Connect Discovery endpoint
119
- router.get(`${prefix}/.well-known/openid-configuration`, (_req, res) => {
120
- // Construct absolute URLs for endpoints
121
- const tokenEndpoint = `${defaultBaseUrl.replace(/\/$/, '')}${tokenEndpointPath}`;
122
- const jwksUri = `${defaultBaseUrl.replace(/\/$/, '')}${jwksEndpointPath}`;
123
- const config = {
124
- issuer: defaultIssuer,
125
- token_endpoint: tokenEndpoint,
126
- jwks_uri: jwksUri,
127
- scopes_supported: allowedScopes,
128
- response_types_supported: ['token'],
129
- grant_types_supported: ['client_credentials'],
130
- token_endpoint_auth_methods_supported: [
131
- 'client_secret_basic',
132
- 'client_secret_post',
133
- ],
134
- subject_types_supported: ['public'],
135
- id_token_signing_alg_values_supported: [algorithm],
136
- };
137
- logger.debug('openid_config_served', { config });
138
- res.json(config);
139
- });
140
- return router;
116
+ const plugin = async (instance) => {
117
+ instance.get(`${prefix}/.well-known/openid-configuration`, async (_request, reply) => {
118
+ // Construct absolute URLs for endpoints
119
+ const tokenEndpoint = `${defaultBaseUrl.replace(/\/$/, '')}${tokenEndpointPath}`;
120
+ const jwksUri = `${defaultBaseUrl.replace(/\/$/, '')}${jwksEndpointPath}`;
121
+ const config = {
122
+ issuer: defaultIssuer,
123
+ token_endpoint: tokenEndpoint,
124
+ jwks_uri: jwksUri,
125
+ scopes_supported: allowedScopes,
126
+ response_types_supported: ['token'],
127
+ grant_types_supported: ['client_credentials'],
128
+ token_endpoint_auth_methods_supported: [
129
+ 'client_secret_basic',
130
+ 'client_secret_post',
131
+ ],
132
+ subject_types_supported: ['public'],
133
+ id_token_signing_alg_values_supported: [algorithm],
134
+ };
135
+ logger.debug('openid_config_served', { config });
136
+ reply.send(config);
137
+ });
138
+ };
139
+ return plugin;
141
140
  }
@@ -19,6 +19,8 @@ const ENV_VAR_DIRECT_INPAGE_CHANNEL = 'FAME_DIRECT_INPAGE_CHANNEL';
19
19
  const ENV_VAR_ADMISSION_SERVICE_URL = 'FAME_ADMISSION_SERVICE_URL';
20
20
  const DEFAULT_INPAGE_CHANNEL = 'naylence-fabric';
21
21
  const PROFILE_NAME_WELCOME = 'welcome';
22
+ const PROFILE_NAME_WELCOME_PKCE = 'welcome-pkce';
23
+ const PROFILE_NAME_WELCOME_PKCE_ALIAS = 'welcome_pkce';
22
24
  const PROFILE_NAME_DIRECT = 'direct';
23
25
  const PROFILE_NAME_DIRECT_HTTP = 'direct-http';
24
26
  const PROFILE_NAME_DIRECT_INPAGE = 'direct-inpage';
@@ -79,6 +81,7 @@ function createOAuthPkceTokenProviderConfig() {
79
81
  }
80
82
  const welcomeIsRoot = Expressions.env(ENV_VAR_IS_ROOT, 'false');
81
83
  const welcomeTokenProvider = createOAuthTokenProviderConfig();
84
+ const welcomePkceTokenProvider = createOAuthPkceTokenProviderConfig();
82
85
  const WELCOME_SERVICE_PROFILE = {
83
86
  type: 'WelcomeServiceClient',
84
87
  is_root: welcomeIsRoot,
@@ -92,6 +95,19 @@ const WELCOME_SERVICE_PROFILE = {
92
95
  tokenProvider: welcomeTokenProvider,
93
96
  },
94
97
  };
98
+ const WELCOME_SERVICE_PKCE_PROFILE = {
99
+ type: 'WelcomeServiceClient',
100
+ is_root: welcomeIsRoot,
101
+ isRoot: welcomeIsRoot,
102
+ url: Expressions.env(ENV_VAR_ADMISSION_SERVICE_URL),
103
+ supported_transports: ['websocket'],
104
+ supportedTransports: ['websocket'],
105
+ auth: {
106
+ type: 'BearerTokenHeaderAuth',
107
+ token_provider: welcomePkceTokenProvider,
108
+ tokenProvider: welcomePkceTokenProvider,
109
+ },
110
+ };
95
111
  const directGrantTokenProvider = createOAuthTokenProviderConfig();
96
112
  const directGrant = {
97
113
  type: 'WebSocketConnectionGrant',
@@ -197,6 +213,8 @@ const NOOP_PROFILE = {
197
213
  };
198
214
  const PROFILE_MAP = {
199
215
  [PROFILE_NAME_WELCOME]: WELCOME_SERVICE_PROFILE,
216
+ [PROFILE_NAME_WELCOME_PKCE]: WELCOME_SERVICE_PKCE_PROFILE,
217
+ [PROFILE_NAME_WELCOME_PKCE_ALIAS]: WELCOME_SERVICE_PKCE_PROFILE,
200
218
  [PROFILE_NAME_DIRECT]: DIRECT_PROFILE,
201
219
  [PROFILE_NAME_DIRECT_PKCE]: DIRECT_PKCE_PROFILE,
202
220
  [PROFILE_NAME_DIRECT_PKCE_ALIAS]: DIRECT_PKCE_PROFILE,
@@ -1,6 +1,3 @@
1
- import { AsnConvert, OctetString } from '@peculiar/asn1-schema';
2
- import { AlgorithmIdentifier, Attribute, AttributeTypeAndValue, AttributeValue, Extension, Extensions, GeneralName, Name, RelativeDistinguishedName, SubjectAlternativeName, SubjectPublicKeyInfo, id_ce_subjectAltName, } from '@peculiar/asn1-x509';
3
- import { Attributes, CertificationRequest, CertificationRequestInfo, } from '@peculiar/asn1-csr';
4
1
  import { generateId } from '@naylence/core';
5
2
  import { getLogger } from '../../../util/logging.js';
6
3
  import { secureDigest } from '../../../util/util.js';
@@ -16,11 +13,6 @@ const DEFAULT_AUDIENCE = 'router-dev';
16
13
  const DEFAULT_TTL_SEC = 3600;
17
14
  const DEFAULT_HMAC_SECRET_BYTES = 32;
18
15
  const ENCRYPTION_ALG = 'ECDH-ES';
19
- const EXTENSION_REQUEST_OID = '1.2.840.113549.1.9.14';
20
- const COMMON_NAME_OID = '2.5.4.3';
21
- const ED25519_OID = '1.3.101.112';
22
- const CSR_PEM_TAG = 'CERTIFICATE REQUEST';
23
- const LOGICAL_URI_PREFIX = 'naylence://';
24
16
  function normalizeDefaultCryptoProviderOptions(options) {
25
17
  if (!options) {
26
18
  return {};
@@ -286,76 +278,6 @@ export class DefaultCryptoProvider {
286
278
  has_chain: Boolean(certificateChainPem),
287
279
  });
288
280
  }
289
- async createCsr(nodeId, physicalPath, logicals, subjectName) {
290
- const trimmedNodeId = assertNonEmptyString(nodeId, 'nodeId');
291
- const trimmedPhysicalPath = assertNonEmptyString(physicalPath, 'physicalPath');
292
- try {
293
- if (this.artifacts.signing.algorithm !== 'EdDSA') {
294
- throw new Error('CSR creation only supported for Ed25519 signing keys in the default crypto provider');
295
- }
296
- const cryptoImpl = await ensureWebCrypto();
297
- const privateKey = await cryptoImpl.subtle.importKey('pkcs8', pemToArrayBuffer(this.signingPrivatePem), {
298
- name: 'Ed25519',
299
- }, false, ['sign']);
300
- const publicKeyDer = pemToArrayBuffer(this.signingPublicPem);
301
- const subjectPkInfo = AsnConvert.parse(publicKeyDer, SubjectPublicKeyInfo);
302
- const sanitizedLogicals = Array.isArray(logicals)
303
- ? logicals.filter((value) => typeof value === 'string' && value.trim().length > 0)
304
- : [];
305
- const commonName = typeof subjectName === 'string' && subjectName.trim().length > 0
306
- ? subjectName.trim()
307
- : trimmedNodeId;
308
- const subject = buildSubjectName(commonName);
309
- const attributes = new Attributes();
310
- if (sanitizedLogicals.length > 0) {
311
- const san = new SubjectAlternativeName(sanitizedLogicals.map((logical) => new GeneralName({
312
- uniformResourceIdentifier: `${LOGICAL_URI_PREFIX}${logical}`,
313
- })));
314
- const extensions = new Extensions([
315
- new Extension({
316
- extnID: id_ce_subjectAltName,
317
- critical: false,
318
- extnValue: new OctetString(AsnConvert.serialize(san)),
319
- }),
320
- ]);
321
- attributes.push(new Attribute({
322
- type: EXTENSION_REQUEST_OID,
323
- values: [AsnConvert.serialize(extensions)],
324
- }));
325
- }
326
- const requestInfo = new CertificationRequestInfo({
327
- subject,
328
- subjectPKInfo: subjectPkInfo,
329
- attributes,
330
- });
331
- const requestInfoDer = AsnConvert.serialize(requestInfo);
332
- const signature = await cryptoImpl.subtle.sign('Ed25519', privateKey, requestInfoDer);
333
- const certificationRequest = new CertificationRequest({
334
- certificationRequestInfo: requestInfo,
335
- signatureAlgorithm: new AlgorithmIdentifier({
336
- algorithm: ED25519_OID,
337
- }),
338
- signature: encodeBitString(signature),
339
- });
340
- certificationRequest.certificationRequestInfoRaw = requestInfoDer;
341
- const csrDer = AsnConvert.serialize(certificationRequest);
342
- const csrPem = arrayBufferToPem(csrDer, CSR_PEM_TAG);
343
- logger.debug('csr_created', {
344
- node_id: trimmedNodeId,
345
- physical_path: trimmedPhysicalPath,
346
- logical_count: sanitizedLogicals.length,
347
- });
348
- return csrPem;
349
- }
350
- catch (error) {
351
- logger.error('csr_creation_failed', {
352
- node_id: trimmedNodeId,
353
- physical_path: trimmedPhysicalPath,
354
- error: error instanceof Error ? error.message : String(error),
355
- });
356
- throw error;
357
- }
358
- }
359
281
  }
360
282
  async function buildProviderArtifacts(options) {
361
283
  const algorithm = normalizeAlgorithm(options.algorithm ?? readEnvAlgorithm());
@@ -591,90 +513,6 @@ function pemToDerBase64(pem) {
591
513
  // Ensure the output is valid base64 without whitespace
592
514
  return base64.replace(/\s+/g, '');
593
515
  }
594
- let cryptoPromise = null;
595
- async function ensureWebCrypto() {
596
- if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto?.subtle) {
597
- return globalThis.crypto;
598
- }
599
- if (!cryptoPromise) {
600
- if (typeof process !== 'undefined' &&
601
- typeof process.versions?.node === 'string') {
602
- cryptoPromise = import('node:crypto').then((module) => {
603
- const webcrypto = module.webcrypto;
604
- if (!webcrypto || !webcrypto.subtle) {
605
- throw new Error('WebCrypto API is not available in this Node.js runtime');
606
- }
607
- globalThis.crypto = webcrypto;
608
- return webcrypto;
609
- });
610
- }
611
- else {
612
- cryptoPromise = Promise.reject(new Error('WebCrypto API is not available in this environment'));
613
- }
614
- }
615
- return cryptoPromise;
616
- }
617
- function pemToArrayBuffer(pem) {
618
- const normalized = pem
619
- .replace(/-----BEGIN[^-]+-----/g, '')
620
- .replace(/-----END[^-]+-----/g, '')
621
- .replace(/\s+/g, '');
622
- const bytes = base64ToBytes(normalized);
623
- return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
624
- }
625
- function base64ToBytes(base64) {
626
- if (typeof Buffer !== 'undefined') {
627
- const buffer = Buffer.from(base64, 'base64');
628
- const bytes = new Uint8Array(buffer.length);
629
- for (let i = 0; i < buffer.length; i += 1) {
630
- bytes[i] = buffer[i];
631
- }
632
- return bytes;
633
- }
634
- if (typeof atob === 'function') {
635
- const binary = atob(base64);
636
- const bytes = new Uint8Array(binary.length);
637
- for (let i = 0; i < binary.length; i += 1) {
638
- bytes[i] = binary.charCodeAt(i);
639
- }
640
- return bytes;
641
- }
642
- throw new Error('No base64 decoder available in this environment');
643
- }
644
- function arrayBufferToPem(buffer, tag) {
645
- const base64 = bytesToBase64(new Uint8Array(buffer));
646
- return `-----BEGIN ${tag}-----\n${formatPem(base64)}\n-----END ${tag}-----\n`;
647
- }
648
- function formatPem(base64) {
649
- const lines = [];
650
- for (let i = 0; i < base64.length; i += 64) {
651
- lines.push(base64.slice(i, i + 64));
652
- }
653
- return lines.join('\n');
654
- }
655
- function encodeBitString(signature) {
656
- const bytes = new Uint8Array(signature);
657
- const bitString = new Uint8Array(bytes.length + 1);
658
- bitString.set(bytes, 1);
659
- return bitString.buffer;
660
- }
661
- function buildSubjectName(commonName) {
662
- const attribute = new AttributeTypeAndValue({
663
- type: COMMON_NAME_OID,
664
- value: new AttributeValue({ utf8String: commonName }),
665
- });
666
- return new Name([new RelativeDistinguishedName([attribute])]);
667
- }
668
- function assertNonEmptyString(value, name) {
669
- if (typeof value !== 'string') {
670
- throw new TypeError(`${name} must be a string`);
671
- }
672
- const trimmed = value.trim();
673
- if (trimmed.length === 0) {
674
- throw new TypeError(`${name} must be a non-empty string`);
675
- }
676
- return trimmed;
677
- }
678
516
  function cloneJson(value) {
679
517
  return JSON.parse(JSON.stringify(value));
680
518
  }
@@ -1,7 +1,7 @@
1
1
  // This file is auto-generated during build - do not edit manually
2
- // Generated from package.json version: 0.3.5-test.911
2
+ // Generated from package.json version: 0.3.5-test.913
3
3
  /**
4
4
  * The package version, injected at build time.
5
5
  * @internal
6
6
  */
7
- export const VERSION = '0.3.5-test.911';
7
+ export const VERSION = '0.3.5-test.913';
@@ -8,21 +8,18 @@ var ed25519_js = require('@noble/curves/ed25519.js');
8
8
  var hkdf_js = require('@noble/hashes/hkdf.js');
9
9
  var sha2_js = require('@noble/hashes/sha2.js');
10
10
  var utils_js = require('@noble/hashes/utils.js');
11
- var asn1Schema = require('@peculiar/asn1-schema');
12
- var asn1X509 = require('@peculiar/asn1-x509');
13
- var asn1Csr = require('@peculiar/asn1-csr');
14
11
  var yaml = require('yaml');
15
12
  var fastify = require('fastify');
16
13
  var websocketPlugin = require('@fastify/websocket');
17
14
  var ed25519 = require('@noble/ed25519');
18
15
 
19
16
  // This file is auto-generated during build - do not edit manually
20
- // Generated from package.json version: 0.3.5-test.911
17
+ // Generated from package.json version: 0.3.5-test.913
21
18
  /**
22
19
  * The package version, injected at build time.
23
20
  * @internal
24
21
  */
25
- const VERSION = '0.3.5-test.911';
22
+ const VERSION = '0.3.5-test.913';
26
23
 
27
24
  /**
28
25
  * Fame protocol specific error classes with WebSocket close codes and proper inheritance.
@@ -13009,6 +13006,57 @@ const CONFIG_SEARCH_PATHS = [
13009
13006
  ];
13010
13007
  const fsModuleSpecifier = String.fromCharCode(102) + String.fromCharCode(115);
13011
13008
  let cachedFsModule = null;
13009
+ // Capture this module's URL without triggering TypeScript's import.meta restriction on CJS builds
13010
+ const currentModuleUrl = (() => {
13011
+ try {
13012
+ return (0, eval)('import.meta.url');
13013
+ }
13014
+ catch {
13015
+ return undefined;
13016
+ }
13017
+ })();
13018
+ // Shared flag that allows synchronous waiting for the Node-specific require shim
13019
+ const requireReadyFlag = isNode && typeof SharedArrayBuffer !== 'undefined'
13020
+ ? new Int32Array(new SharedArrayBuffer(Int32Array.BYTES_PER_ELEMENT))
13021
+ : null;
13022
+ if (requireReadyFlag) {
13023
+ // 0 means initializing, 1 means ready (success or failure)
13024
+ Atomics.store(requireReadyFlag, 0, 0);
13025
+ // Prepare a CommonJS-style require when running in pure ESM contexts
13026
+ void (async () => {
13027
+ try {
13028
+ if (typeof require !== 'function') {
13029
+ const moduleNamespace = (await import('node:module'));
13030
+ const createRequire = moduleNamespace.createRequire;
13031
+ if (typeof createRequire === 'function') {
13032
+ const fallbackPath = `${process.cwd()}/.__naylence_require_shim__.mjs`;
13033
+ const nodeRequire = createRequire(currentModuleUrl ?? fallbackPath);
13034
+ globalThis.require = nodeRequire;
13035
+ }
13036
+ }
13037
+ }
13038
+ catch {
13039
+ // Ignore failures – getFsModule will surface a helpful error when needed
13040
+ }
13041
+ })()
13042
+ .catch(() => {
13043
+ // Ignore async errors – the ready flag will still unblock consumers
13044
+ })
13045
+ .finally(() => {
13046
+ Atomics.store(requireReadyFlag, 0, 1);
13047
+ Atomics.notify(requireReadyFlag, 0);
13048
+ });
13049
+ }
13050
+ function ensureRequireReady() {
13051
+ if (!requireReadyFlag) {
13052
+ return;
13053
+ }
13054
+ if (Atomics.load(requireReadyFlag, 0) === 1) {
13055
+ return;
13056
+ }
13057
+ // Block until the asynchronous loader finishes initialising
13058
+ Atomics.wait(requireReadyFlag, 0, 0);
13059
+ }
13012
13060
  function getFsModule() {
13013
13061
  if (cachedFsModule) {
13014
13062
  return cachedFsModule;
@@ -13016,6 +13064,7 @@ function getFsModule() {
13016
13064
  if (!isNode) {
13017
13065
  throw new Error('File system access is not available in this environment');
13018
13066
  }
13067
+ ensureRequireReady();
13019
13068
  if (typeof require === 'function') {
13020
13069
  try {
13021
13070
  cachedFsModule = require(fsModuleSpecifier);
@@ -25394,11 +25443,6 @@ const DEFAULT_AUDIENCE = 'router-dev';
25394
25443
  const DEFAULT_TTL_SEC$1 = 3600;
25395
25444
  const DEFAULT_HMAC_SECRET_BYTES = 32;
25396
25445
  const ENCRYPTION_ALG = 'ECDH-ES';
25397
- const EXTENSION_REQUEST_OID = '1.2.840.113549.1.9.14';
25398
- const COMMON_NAME_OID = '2.5.4.3';
25399
- const ED25519_OID = '1.3.101.112';
25400
- const CSR_PEM_TAG = 'CERTIFICATE REQUEST';
25401
- const LOGICAL_URI_PREFIX = 'naylence://';
25402
25446
  function normalizeDefaultCryptoProviderOptions(options) {
25403
25447
  if (!options) {
25404
25448
  return {};
@@ -25664,76 +25708,6 @@ class DefaultCryptoProvider {
25664
25708
  has_chain: Boolean(certificateChainPem),
25665
25709
  });
25666
25710
  }
25667
- async createCsr(nodeId, physicalPath, logicals, subjectName) {
25668
- const trimmedNodeId = assertNonEmptyString(nodeId, 'nodeId');
25669
- const trimmedPhysicalPath = assertNonEmptyString(physicalPath, 'physicalPath');
25670
- try {
25671
- if (this.artifacts.signing.algorithm !== 'EdDSA') {
25672
- throw new Error('CSR creation only supported for Ed25519 signing keys in the default crypto provider');
25673
- }
25674
- const cryptoImpl = await ensureWebCrypto();
25675
- const privateKey = await cryptoImpl.subtle.importKey('pkcs8', pemToArrayBuffer(this.signingPrivatePem), {
25676
- name: 'Ed25519',
25677
- }, false, ['sign']);
25678
- const publicKeyDer = pemToArrayBuffer(this.signingPublicPem);
25679
- const subjectPkInfo = asn1Schema.AsnConvert.parse(publicKeyDer, asn1X509.SubjectPublicKeyInfo);
25680
- const sanitizedLogicals = Array.isArray(logicals)
25681
- ? logicals.filter((value) => typeof value === 'string' && value.trim().length > 0)
25682
- : [];
25683
- const commonName = typeof subjectName === 'string' && subjectName.trim().length > 0
25684
- ? subjectName.trim()
25685
- : trimmedNodeId;
25686
- const subject = buildSubjectName(commonName);
25687
- const attributes = new asn1Csr.Attributes();
25688
- if (sanitizedLogicals.length > 0) {
25689
- const san = new asn1X509.SubjectAlternativeName(sanitizedLogicals.map((logical) => new asn1X509.GeneralName({
25690
- uniformResourceIdentifier: `${LOGICAL_URI_PREFIX}${logical}`,
25691
- })));
25692
- const extensions = new asn1X509.Extensions([
25693
- new asn1X509.Extension({
25694
- extnID: asn1X509.id_ce_subjectAltName,
25695
- critical: false,
25696
- extnValue: new asn1Schema.OctetString(asn1Schema.AsnConvert.serialize(san)),
25697
- }),
25698
- ]);
25699
- attributes.push(new asn1X509.Attribute({
25700
- type: EXTENSION_REQUEST_OID,
25701
- values: [asn1Schema.AsnConvert.serialize(extensions)],
25702
- }));
25703
- }
25704
- const requestInfo = new asn1Csr.CertificationRequestInfo({
25705
- subject,
25706
- subjectPKInfo: subjectPkInfo,
25707
- attributes,
25708
- });
25709
- const requestInfoDer = asn1Schema.AsnConvert.serialize(requestInfo);
25710
- const signature = await cryptoImpl.subtle.sign('Ed25519', privateKey, requestInfoDer);
25711
- const certificationRequest = new asn1Csr.CertificationRequest({
25712
- certificationRequestInfo: requestInfo,
25713
- signatureAlgorithm: new asn1X509.AlgorithmIdentifier({
25714
- algorithm: ED25519_OID,
25715
- }),
25716
- signature: encodeBitString(signature),
25717
- });
25718
- certificationRequest.certificationRequestInfoRaw = requestInfoDer;
25719
- const csrDer = asn1Schema.AsnConvert.serialize(certificationRequest);
25720
- const csrPem = arrayBufferToPem(csrDer, CSR_PEM_TAG);
25721
- logger$v.debug('csr_created', {
25722
- node_id: trimmedNodeId,
25723
- physical_path: trimmedPhysicalPath,
25724
- logical_count: sanitizedLogicals.length,
25725
- });
25726
- return csrPem;
25727
- }
25728
- catch (error) {
25729
- logger$v.error('csr_creation_failed', {
25730
- node_id: trimmedNodeId,
25731
- physical_path: trimmedPhysicalPath,
25732
- error: error instanceof Error ? error.message : String(error),
25733
- });
25734
- throw error;
25735
- }
25736
- }
25737
25711
  }
25738
25712
  async function buildProviderArtifacts(options) {
25739
25713
  const algorithm = normalizeAlgorithm(options.algorithm ?? readEnvAlgorithm());
@@ -25969,90 +25943,6 @@ function pemToDerBase64(pem) {
25969
25943
  // Ensure the output is valid base64 without whitespace
25970
25944
  return base64.replace(/\s+/g, '');
25971
25945
  }
25972
- let cryptoPromise = null;
25973
- async function ensureWebCrypto() {
25974
- if (typeof globalThis.crypto !== 'undefined' && globalThis.crypto?.subtle) {
25975
- return globalThis.crypto;
25976
- }
25977
- if (!cryptoPromise) {
25978
- if (typeof process !== 'undefined' &&
25979
- typeof process.versions?.node === 'string') {
25980
- cryptoPromise = import('node:crypto').then((module) => {
25981
- const webcrypto = module.webcrypto;
25982
- if (!webcrypto || !webcrypto.subtle) {
25983
- throw new Error('WebCrypto API is not available in this Node.js runtime');
25984
- }
25985
- globalThis.crypto = webcrypto;
25986
- return webcrypto;
25987
- });
25988
- }
25989
- else {
25990
- cryptoPromise = Promise.reject(new Error('WebCrypto API is not available in this environment'));
25991
- }
25992
- }
25993
- return cryptoPromise;
25994
- }
25995
- function pemToArrayBuffer(pem) {
25996
- const normalized = pem
25997
- .replace(/-----BEGIN[^-]+-----/g, '')
25998
- .replace(/-----END[^-]+-----/g, '')
25999
- .replace(/\s+/g, '');
26000
- const bytes = base64ToBytes$1(normalized);
26001
- return bytes.buffer.slice(bytes.byteOffset, bytes.byteOffset + bytes.byteLength);
26002
- }
26003
- function base64ToBytes$1(base64) {
26004
- if (typeof Buffer !== 'undefined') {
26005
- const buffer = Buffer.from(base64, 'base64');
26006
- const bytes = new Uint8Array(buffer.length);
26007
- for (let i = 0; i < buffer.length; i += 1) {
26008
- bytes[i] = buffer[i];
26009
- }
26010
- return bytes;
26011
- }
26012
- if (typeof atob === 'function') {
26013
- const binary = atob(base64);
26014
- const bytes = new Uint8Array(binary.length);
26015
- for (let i = 0; i < binary.length; i += 1) {
26016
- bytes[i] = binary.charCodeAt(i);
26017
- }
26018
- return bytes;
26019
- }
26020
- throw new Error('No base64 decoder available in this environment');
26021
- }
26022
- function arrayBufferToPem(buffer, tag) {
26023
- const base64 = bytesToBase64(new Uint8Array(buffer));
26024
- return `-----BEGIN ${tag}-----\n${formatPem(base64)}\n-----END ${tag}-----\n`;
26025
- }
26026
- function formatPem(base64) {
26027
- const lines = [];
26028
- for (let i = 0; i < base64.length; i += 64) {
26029
- lines.push(base64.slice(i, i + 64));
26030
- }
26031
- return lines.join('\n');
26032
- }
26033
- function encodeBitString(signature) {
26034
- const bytes = new Uint8Array(signature);
26035
- const bitString = new Uint8Array(bytes.length + 1);
26036
- bitString.set(bytes, 1);
26037
- return bitString.buffer;
26038
- }
26039
- function buildSubjectName(commonName) {
26040
- const attribute = new asn1X509.AttributeTypeAndValue({
26041
- type: COMMON_NAME_OID,
26042
- value: new asn1X509.AttributeValue({ utf8String: commonName }),
26043
- });
26044
- return new asn1X509.Name([new asn1X509.RelativeDistinguishedName([attribute])]);
26045
- }
26046
- function assertNonEmptyString(value, name) {
26047
- if (typeof value !== 'string') {
26048
- throw new TypeError(`${name} must be a string`);
26049
- }
26050
- const trimmed = value.trim();
26051
- if (trimmed.length === 0) {
26052
- throw new TypeError(`${name} must be a non-empty string`);
26053
- }
26054
- return trimmed;
26055
- }
26056
25946
  function cloneJson(value) {
26057
25947
  return JSON.parse(JSON.stringify(value));
26058
25948
  }
@@ -30500,6 +30390,8 @@ const ENV_VAR_DIRECT_INPAGE_CHANNEL = 'FAME_DIRECT_INPAGE_CHANNEL';
30500
30390
  const ENV_VAR_ADMISSION_SERVICE_URL = 'FAME_ADMISSION_SERVICE_URL';
30501
30391
  const DEFAULT_INPAGE_CHANNEL = 'naylence-fabric';
30502
30392
  const PROFILE_NAME_WELCOME = 'welcome';
30393
+ const PROFILE_NAME_WELCOME_PKCE = 'welcome-pkce';
30394
+ const PROFILE_NAME_WELCOME_PKCE_ALIAS = 'welcome_pkce';
30503
30395
  const PROFILE_NAME_DIRECT = 'direct';
30504
30396
  const PROFILE_NAME_DIRECT_HTTP = 'direct-http';
30505
30397
  const PROFILE_NAME_DIRECT_INPAGE = 'direct-inpage';
@@ -30560,6 +30452,7 @@ function createOAuthPkceTokenProviderConfig() {
30560
30452
  }
30561
30453
  const welcomeIsRoot = factory.Expressions.env(ENV_VAR_IS_ROOT, 'false');
30562
30454
  const welcomeTokenProvider = createOAuthTokenProviderConfig();
30455
+ const welcomePkceTokenProvider = createOAuthPkceTokenProviderConfig();
30563
30456
  const WELCOME_SERVICE_PROFILE = {
30564
30457
  type: 'WelcomeServiceClient',
30565
30458
  is_root: welcomeIsRoot,
@@ -30573,6 +30466,19 @@ const WELCOME_SERVICE_PROFILE = {
30573
30466
  tokenProvider: welcomeTokenProvider,
30574
30467
  },
30575
30468
  };
30469
+ const WELCOME_SERVICE_PKCE_PROFILE = {
30470
+ type: 'WelcomeServiceClient',
30471
+ is_root: welcomeIsRoot,
30472
+ isRoot: welcomeIsRoot,
30473
+ url: factory.Expressions.env(ENV_VAR_ADMISSION_SERVICE_URL),
30474
+ supported_transports: ['websocket'],
30475
+ supportedTransports: ['websocket'],
30476
+ auth: {
30477
+ type: 'BearerTokenHeaderAuth',
30478
+ token_provider: welcomePkceTokenProvider,
30479
+ tokenProvider: welcomePkceTokenProvider,
30480
+ },
30481
+ };
30576
30482
  const directGrantTokenProvider = createOAuthTokenProviderConfig();
30577
30483
  const directGrant = {
30578
30484
  type: 'WebSocketConnectionGrant',
@@ -30678,6 +30584,8 @@ const NOOP_PROFILE = {
30678
30584
  };
30679
30585
  const PROFILE_MAP$1 = {
30680
30586
  [PROFILE_NAME_WELCOME]: WELCOME_SERVICE_PROFILE,
30587
+ [PROFILE_NAME_WELCOME_PKCE]: WELCOME_SERVICE_PKCE_PROFILE,
30588
+ [PROFILE_NAME_WELCOME_PKCE_ALIAS]: WELCOME_SERVICE_PKCE_PROFILE,
30681
30589
  [PROFILE_NAME_DIRECT]: DIRECT_PROFILE,
30682
30590
  [PROFILE_NAME_DIRECT_PKCE]: DIRECT_PKCE_PROFILE,
30683
30591
  [PROFILE_NAME_DIRECT_PKCE_ALIAS]: DIRECT_PKCE_PROFILE,