alepha 0.21.2 → 0.23.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.
- package/README.md +0 -1
- package/dist/api/audits/index.browser.js.map +1 -1
- package/dist/api/audits/index.d.ts +393 -403
- package/dist/api/audits/index.d.ts.map +1 -1
- package/dist/api/audits/index.js +25 -56
- package/dist/api/audits/index.js.map +1 -1
- package/dist/api/files/index.browser.js +31 -1
- package/dist/api/files/index.browser.js.map +1 -1
- package/dist/api/files/index.d.ts +313 -208
- package/dist/api/files/index.d.ts.map +1 -1
- package/dist/api/files/index.js +152 -42
- package/dist/api/files/index.js.map +1 -1
- package/dist/api/jobs/index.browser.js +2 -2
- package/dist/api/jobs/index.browser.js.map +1 -1
- package/dist/api/jobs/index.d.ts +282 -285
- package/dist/api/jobs/index.d.ts.map +1 -1
- package/dist/api/jobs/index.js +39 -33
- package/dist/api/jobs/index.js.map +1 -1
- package/dist/api/keys/index.d.ts +217 -222
- package/dist/api/keys/index.d.ts.map +1 -1
- package/dist/api/keys/index.js.map +1 -1
- package/dist/api/notifications/index.browser.js.map +1 -1
- package/dist/api/notifications/index.d.ts +188 -195
- package/dist/api/notifications/index.d.ts.map +1 -1
- package/dist/api/notifications/index.js.map +1 -1
- package/dist/api/oauth/index.d.ts +71 -76
- package/dist/api/oauth/index.d.ts.map +1 -1
- package/dist/api/oauth/index.js.map +1 -1
- package/dist/api/organizations/index.browser.js.map +1 -1
- package/dist/api/organizations/index.d.ts +104 -109
- package/dist/api/organizations/index.d.ts.map +1 -1
- package/dist/api/organizations/index.js.map +1 -1
- package/dist/api/parameters/index.browser.js +43 -16
- package/dist/api/parameters/index.browser.js.map +1 -1
- package/dist/api/parameters/index.d.ts +488 -344
- package/dist/api/parameters/index.d.ts.map +1 -1
- package/dist/api/parameters/index.js +175 -35
- package/dist/api/parameters/index.js.map +1 -1
- package/dist/api/payments/index.d.ts +396 -402
- package/dist/api/payments/index.d.ts.map +1 -1
- package/dist/api/payments/index.js.map +1 -1
- package/dist/api/subscriptions/index.d.ts +644 -652
- package/dist/api/subscriptions/index.d.ts.map +1 -1
- package/dist/api/subscriptions/index.js +1 -1
- package/dist/api/subscriptions/index.js.map +1 -1
- package/dist/api/users/index.browser.js +7 -0
- package/dist/api/users/index.browser.js.map +1 -1
- package/dist/api/users/index.d.ts +1106 -1005
- package/dist/api/users/index.d.ts.map +1 -1
- package/dist/api/users/index.js +307 -64
- package/dist/api/users/index.js.map +1 -1
- package/dist/api/verifications/index.browser.js.map +1 -1
- package/dist/api/verifications/index.d.ts +137 -143
- package/dist/api/verifications/index.d.ts.map +1 -1
- package/dist/api/verifications/index.js.map +1 -1
- package/dist/background/index.d.ts +95 -0
- package/dist/background/index.d.ts.map +1 -0
- package/dist/background/index.js +121 -0
- package/dist/background/index.js.map +1 -0
- package/dist/background/index.workerd.js +110 -0
- package/dist/background/index.workerd.js.map +1 -0
- package/dist/batch/index.d.ts +5 -7
- package/dist/batch/index.d.ts.map +1 -1
- package/dist/batch/index.js.map +1 -1
- package/dist/bin/index.js.map +1 -1
- package/dist/bucket/index.d.ts +76 -54
- package/dist/bucket/index.d.ts.map +1 -1
- package/dist/bucket/index.js +58 -11
- package/dist/bucket/index.js.map +1 -1
- package/dist/bucket/index.workerd.js +200 -5
- package/dist/bucket/index.workerd.js.map +1 -1
- package/dist/cache/core/index.d.ts +7 -10
- package/dist/cache/core/index.d.ts.map +1 -1
- package/dist/cache/core/index.js.map +1 -1
- package/dist/cache/core/index.workerd.js.map +1 -1
- package/dist/cache/database/index.d.ts +22 -26
- package/dist/cache/database/index.d.ts.map +1 -1
- package/dist/cache/database/index.js.map +1 -1
- package/dist/cache/redis/index.d.ts +4 -7
- package/dist/cache/redis/index.d.ts.map +1 -1
- package/dist/cache/redis/index.js.map +1 -1
- package/dist/captcha/index.d.ts +3 -6
- package/dist/captcha/index.d.ts.map +1 -1
- package/dist/captcha/index.js.map +1 -1
- package/dist/cli/config/index.d.ts.map +1 -1
- package/dist/cli/config/index.js.map +1 -1
- package/dist/cli/core/index.d.ts +458 -249
- package/dist/cli/core/index.d.ts.map +1 -1
- package/dist/cli/core/index.js +372 -660
- package/dist/cli/core/index.js.map +1 -1
- package/dist/cli/devtools/index.d.ts +3 -5
- package/dist/cli/devtools/index.d.ts.map +1 -1
- package/dist/cli/devtools/index.js.map +1 -1
- package/dist/cli/i18n/index.d.ts +20 -17
- package/dist/cli/i18n/index.d.ts.map +1 -1
- package/dist/cli/i18n/index.js +45 -11
- package/dist/cli/i18n/index.js.map +1 -1
- package/dist/cli/platform/index.d.ts +126 -1342
- package/dist/cli/platform/index.d.ts.map +1 -1
- package/dist/cli/platform/index.js +136 -2374
- package/dist/cli/platform/index.js.map +1 -1
- package/dist/cli/platform-lib/index.d.ts +1472 -0
- package/dist/cli/platform-lib/index.d.ts.map +1 -0
- package/dist/cli/platform-lib/index.js +2660 -0
- package/dist/cli/platform-lib/index.js.map +1 -0
- package/dist/cli/vendor/index.d.ts +17 -21
- package/dist/cli/vendor/index.d.ts.map +1 -1
- package/dist/cli/vendor/index.js.map +1 -1
- package/dist/command/index.d.ts +20 -19
- package/dist/command/index.d.ts.map +1 -1
- package/dist/command/index.js +39 -10
- package/dist/command/index.js.map +1 -1
- package/dist/{containers → container}/core/index.d.ts +13 -15
- package/dist/container/core/index.d.ts.map +1 -0
- package/dist/{containers → container}/core/index.js +23 -14
- package/dist/container/core/index.js.map +1 -0
- package/dist/{containers → container}/core/index.workerd.js +37 -22
- package/dist/container/core/index.workerd.js.map +1 -0
- package/dist/core/index.browser.js +27 -1
- package/dist/core/index.browser.js.map +1 -1
- package/dist/core/index.d.ts +48 -24
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +27 -1
- package/dist/core/index.js.map +1 -1
- package/dist/core/index.native.js +27 -1
- package/dist/core/index.native.js.map +1 -1
- package/dist/core/index.workerd.js +27 -1
- package/dist/core/index.workerd.js.map +1 -1
- package/dist/crypto/index.browser.js.map +1 -1
- package/dist/crypto/index.d.ts +5 -8
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js.map +1 -1
- package/dist/datetime/index.d.ts +3 -4
- package/dist/datetime/index.d.ts.map +1 -1
- package/dist/datetime/index.js.map +1 -1
- package/dist/email/brevo/index.d.ts +2 -4
- package/dist/email/brevo/index.d.ts.map +1 -1
- package/dist/email/brevo/index.js.map +1 -1
- package/dist/email/cloudflare/index.d.ts +20 -7
- package/dist/email/cloudflare/index.d.ts.map +1 -1
- package/dist/email/cloudflare/index.js +46 -9
- package/dist/email/cloudflare/index.js.map +1 -1
- package/dist/email/core/index.d.ts +6 -9
- package/dist/email/core/index.d.ts.map +1 -1
- package/dist/email/core/index.js.map +1 -1
- package/dist/email/core/index.workerd.js.map +1 -1
- package/dist/email/smtp/index.d.ts +10 -13
- package/dist/email/smtp/index.d.ts.map +1 -1
- package/dist/email/smtp/index.js +107 -32
- package/dist/email/smtp/index.js.map +1 -1
- package/dist/fake/index.d.ts +1 -2
- package/dist/fake/index.d.ts.map +1 -1
- package/dist/fake/index.js.map +1 -1
- package/dist/lock/core/index.d.ts +9 -14
- package/dist/lock/core/index.d.ts.map +1 -1
- package/dist/lock/core/index.js.map +1 -1
- package/dist/lock/redis/index.d.ts +2 -4
- package/dist/lock/redis/index.d.ts.map +1 -1
- package/dist/lock/redis/index.js.map +1 -1
- package/dist/logger/index.d.ts +105 -76
- package/dist/logger/index.d.ts.map +1 -1
- package/dist/logger/index.js +196 -174
- package/dist/logger/index.js.map +1 -1
- package/dist/mcp/index.d.ts +25 -20
- package/dist/mcp/index.d.ts.map +1 -1
- package/dist/mcp/index.js +23 -0
- package/dist/mcp/index.js.map +1 -1
- package/dist/orm/core/index.browser.js.map +1 -1
- package/dist/orm/core/index.bun.js +19 -1
- package/dist/orm/core/index.bun.js.map +1 -1
- package/dist/orm/core/index.d.ts +76 -62
- package/dist/orm/core/index.d.ts.map +1 -1
- package/dist/orm/core/index.js +20 -2
- package/dist/orm/core/index.js.map +1 -1
- package/dist/orm/postgres/index.bun.js.map +1 -1
- package/dist/orm/postgres/index.d.ts +28 -20
- package/dist/orm/postgres/index.d.ts.map +1 -1
- package/dist/orm/postgres/index.js.map +1 -1
- package/dist/queue/core/index.d.ts +12 -15
- package/dist/queue/core/index.d.ts.map +1 -1
- package/dist/queue/core/index.js.map +1 -1
- package/dist/queue/core/index.workerd.js.map +1 -1
- package/dist/queue/redis/index.d.ts +3 -5
- package/dist/queue/redis/index.d.ts.map +1 -1
- package/dist/queue/redis/index.js.map +1 -1
- package/dist/react/auth/index.browser.js +9 -2
- package/dist/react/auth/index.browser.js.map +1 -1
- package/dist/react/auth/index.d.ts +14 -9
- package/dist/react/auth/index.d.ts.map +1 -1
- package/dist/react/auth/index.js +9 -2
- package/dist/react/auth/index.js.map +1 -1
- package/dist/react/core/index.d.ts +7 -8
- package/dist/react/core/index.d.ts.map +1 -1
- package/dist/react/core/index.js +6 -3
- package/dist/react/core/index.js.map +1 -1
- package/dist/react/form/index.d.ts +2 -5
- package/dist/react/form/index.d.ts.map +1 -1
- package/dist/react/form/index.js +16 -15
- package/dist/react/form/index.js.map +1 -1
- package/dist/react/head/index.browser.js.map +1 -1
- package/dist/react/head/index.d.ts +2 -4
- package/dist/react/head/index.d.ts.map +1 -1
- package/dist/react/head/index.js.map +1 -1
- package/dist/react/i18n/index.d.ts +90 -11
- package/dist/react/i18n/index.d.ts.map +1 -1
- package/dist/react/i18n/index.js +147 -11
- package/dist/react/i18n/index.js.map +1 -1
- package/dist/react/intro/index.d.ts +1 -2
- package/dist/react/intro/index.d.ts.map +1 -1
- package/dist/react/intro/index.js +2 -2
- package/dist/react/intro/index.js.map +1 -1
- package/dist/react/router/index.browser.js +193 -24
- package/dist/react/router/index.browser.js.map +1 -1
- package/dist/react/router/index.d.ts +434 -222
- package/dist/react/router/index.d.ts.map +1 -1
- package/dist/react/router/index.js +249 -35
- package/dist/react/router/index.js.map +1 -1
- package/dist/react/sitemap/index.browser.js +35 -0
- package/dist/react/sitemap/index.browser.js.map +1 -0
- package/dist/react/sitemap/index.d.ts +92 -0
- package/dist/react/sitemap/index.d.ts.map +1 -0
- package/dist/react/sitemap/index.js +131 -0
- package/dist/react/sitemap/index.js.map +1 -0
- package/dist/react/testing/index.d.ts +1 -2
- package/dist/react/testing/index.d.ts.map +1 -1
- package/dist/react/testing/index.js +16 -17
- package/dist/react/testing/index.js.map +1 -1
- package/dist/react/ui/index.d.ts +20 -25
- package/dist/react/ui/index.d.ts.map +1 -1
- package/dist/react/ui/index.js.map +1 -1
- package/dist/redis/index.bun.js.map +1 -1
- package/dist/redis/index.d.ts +17 -19
- package/dist/redis/index.d.ts.map +1 -1
- package/dist/redis/index.js.map +1 -1
- package/dist/retry/index.d.ts +2 -4
- package/dist/retry/index.d.ts.map +1 -1
- package/dist/retry/index.js.map +1 -1
- package/dist/router/index.d.ts.map +1 -1
- package/dist/router/index.js.map +1 -1
- package/dist/scheduler/index.d.ts +10 -13
- package/dist/scheduler/index.d.ts.map +1 -1
- package/dist/scheduler/index.js.map +1 -1
- package/dist/scheduler/index.workerd.js.map +1 -1
- package/dist/security/index.browser.js.map +1 -1
- package/dist/security/index.d.ts +45 -48
- package/dist/security/index.d.ts.map +1 -1
- package/dist/security/index.js.map +1 -1
- package/dist/server/auth/index.browser.js.map +1 -1
- package/dist/server/auth/index.d.ts +272 -173
- package/dist/server/auth/index.d.ts.map +1 -1
- package/dist/server/auth/index.js +1608 -15
- package/dist/server/auth/index.js.map +1 -1
- package/dist/server/cookies/index.browser.js.map +1 -1
- package/dist/server/cookies/index.d.ts +20 -7
- package/dist/server/cookies/index.d.ts.map +1 -1
- package/dist/server/cookies/index.js +22 -3
- package/dist/server/cookies/index.js.map +1 -1
- package/dist/server/core/index.browser.js.map +1 -1
- package/dist/server/core/index.d.ts +106 -73
- package/dist/server/core/index.d.ts.map +1 -1
- package/dist/server/core/index.js +44 -0
- package/dist/server/core/index.js.map +1 -1
- package/dist/server/cors/index.d.ts +11 -14
- package/dist/server/cors/index.d.ts.map +1 -1
- package/dist/server/cors/index.js.map +1 -1
- package/dist/server/etag/index.d.ts +6 -9
- package/dist/server/etag/index.d.ts.map +1 -1
- package/dist/server/etag/index.js.map +1 -1
- package/dist/server/health/index.d.ts +18 -21
- package/dist/server/health/index.d.ts.map +1 -1
- package/dist/server/health/index.js.map +1 -1
- package/dist/server/links/index.browser.js +2 -0
- package/dist/server/links/index.browser.js.map +1 -1
- package/dist/server/links/index.d.ts +63 -67
- package/dist/server/links/index.d.ts.map +1 -1
- package/dist/server/links/index.js +2 -0
- package/dist/server/links/index.js.map +1 -1
- package/dist/server/metrics/index.d.ts +5 -7
- package/dist/server/metrics/index.d.ts.map +1 -1
- package/dist/server/metrics/index.js.map +1 -1
- package/dist/server/proxy/index.d.ts +3 -5
- package/dist/server/proxy/index.d.ts.map +1 -1
- package/dist/server/proxy/index.js.map +1 -1
- package/dist/server/rate-limit/index.d.ts +10 -13
- package/dist/server/rate-limit/index.d.ts.map +1 -1
- package/dist/server/rate-limit/index.js.map +1 -1
- package/dist/server/static/index.d.ts +3 -5
- package/dist/server/static/index.d.ts.map +1 -1
- package/dist/server/static/index.js.map +1 -1
- package/dist/server/swagger/index.d.ts +5 -8
- package/dist/server/swagger/index.d.ts.map +1 -1
- package/dist/server/swagger/index.js.map +1 -1
- package/dist/sms/index.d.ts +3 -5
- package/dist/sms/index.d.ts.map +1 -1
- package/dist/sms/index.js.map +1 -1
- package/dist/system/index.browser.js.map +1 -1
- package/dist/system/index.d.ts +2 -4
- package/dist/system/index.d.ts.map +1 -1
- package/dist/system/index.js.map +1 -1
- package/dist/system/index.workerd.js.map +1 -1
- package/dist/topic/core/index.d.ts +4 -6
- package/dist/topic/core/index.d.ts.map +1 -1
- package/dist/topic/core/index.js.map +1 -1
- package/dist/topic/redis/index.d.ts +5 -8
- package/dist/topic/redis/index.d.ts.map +1 -1
- package/dist/topic/redis/index.js.map +1 -1
- package/package.json +59 -23
- package/src/api/audits/__tests__/AuditService.spec.ts +18 -110
- package/src/api/audits/controllers/AdminAuditController.ts +14 -0
- package/src/api/audits/services/AuditService.ts +21 -88
- package/src/api/files/__tests__/FileService.spec.ts +207 -2
- package/src/api/files/index.ts +3 -0
- package/src/api/files/schemas/fileCreatorSummarySchema.ts +22 -0
- package/src/api/files/schemas/fileResourceSchema.ts +10 -1
- package/src/api/files/services/FileService.ts +170 -72
- package/src/api/jobs/__tests__/$job.spec.ts +24 -1
- package/src/api/jobs/index.ts +4 -3
- package/src/api/jobs/primitives/$job.ts +7 -3
- package/src/api/jobs/providers/DirectJobDispatcher.ts +17 -36
- package/src/api/jobs/providers/JobProvider.ts +53 -24
- package/src/api/jobs/schemas/jobConfigAtom.ts +1 -1
- package/src/api/jobs/schemas/jobExecutionResourceSchema.ts +4 -1
- package/src/api/keys/schemas/adminApiKeyResourceSchema.ts +3 -1
- package/src/api/parameters/__tests__/$parameter.spec.ts +19 -2
- package/src/api/parameters/audits/ParameterAudits.ts +17 -0
- package/src/api/parameters/controllers/AdminParameterController.ts +95 -19
- package/src/api/parameters/index.ts +3 -0
- package/src/api/parameters/schemas/activateParameterBodySchema.ts +3 -3
- package/src/api/parameters/schemas/createParameterVersionBodySchema.ts +3 -2
- package/src/api/parameters/schemas/parameterCreatorSummarySchema.ts +25 -0
- package/src/api/parameters/schemas/parameterResponseSchema.ts +5 -0
- package/src/api/parameters/schemas/rollbackParameterBodySchema.ts +4 -2
- package/src/api/parameters/services/ParameterProvider.ts +69 -6
- package/src/api/subscriptions/jobs/SubscriptionJobs.ts +1 -1
- package/src/api/users/__tests__/AdminSessionController.spec.ts +37 -0
- package/src/api/users/audits/SessionAudits.ts +33 -0
- package/src/api/users/audits/UserAudits.ts +19 -43
- package/src/api/users/controllers/AdminUserController.ts +66 -1
- package/src/api/users/controllers/RealmController.ts +1 -0
- package/src/api/users/entities/sessions.ts +6 -0
- package/src/api/users/entities/users.ts +2 -0
- package/src/api/users/index.ts +9 -1
- package/src/api/users/primitives/$realm.ts +29 -0
- package/src/api/users/providers/RealmProvider.ts +15 -0
- package/src/api/users/schemas/realmConfigSchema.ts +14 -0
- package/src/api/users/schemas/sessionResourceSchema.ts +16 -0
- package/src/api/users/schemas/updateUserSchema.ts +1 -8
- package/src/api/users/schemas/userQuerySchema.ts +7 -0
- package/src/api/users/services/CredentialService.ts +15 -6
- package/src/api/users/services/IdentityService.ts +2 -1
- package/src/api/users/services/RegistrationService.ts +2 -1
- package/src/api/users/services/SessionCrudService.ts +19 -2
- package/src/api/users/services/SessionService.ts +39 -19
- package/src/api/users/services/UserService.ts +106 -8
- package/src/background/__tests__/BackgroundTaskProvider.spec.ts +96 -0
- package/src/background/index.ts +37 -0
- package/src/background/index.workerd.ts +28 -0
- package/src/background/providers/BackgroundTaskProvider.ts +70 -0
- package/src/background/providers/WorkerdBackgroundTaskProvider.ts +43 -0
- package/src/bucket/__tests__/$bucket.spec.ts +18 -0
- package/src/bucket/__tests__/LocalFileStorageProvider.spec.ts +5 -0
- package/src/bucket/__tests__/MemoryFileStorageProvider.spec.ts +5 -0
- package/src/bucket/__tests__/NodeS3BucketProvider.spec.ts +23 -4
- package/src/bucket/__tests__/shared.ts +30 -0
- package/src/bucket/index.ts +5 -5
- package/src/bucket/index.workerd.ts +11 -4
- package/src/bucket/primitives/$bucket.ts +27 -0
- package/src/bucket/providers/FileStorageProvider.ts +13 -0
- package/src/bucket/providers/LocalFileStorageProvider.ts +17 -1
- package/src/bucket/providers/MemoryFileStorageProvider.ts +7 -0
- package/src/bucket/providers/{CloudflareR2Provider.ts → R2FileStorageProvider.ts} +10 -1
- package/src/bucket/providers/{NodeS3BucketProvider.ts → S3FileStorageProvider.ts} +27 -5
- package/src/cli/core/__tests__/BuildDockerTask.spec.ts +25 -1
- package/src/cli/core/__tests__/init.spec.ts +0 -219
- package/src/cli/core/atoms/buildOptions.ts +0 -12
- package/src/cli/core/commands/__tests__/BuildCommand.spec.ts +43 -0
- package/src/cli/core/commands/build.ts +105 -37
- package/src/cli/core/commands/init.ts +0 -12
- package/src/cli/core/commands/pack.ts +133 -0
- package/src/cli/core/index.ts +3 -3
- package/src/cli/core/providers/ViteDevServerProvider.ts +40 -16
- package/src/cli/core/services/PackageManagerUtils.ts +0 -16
- package/src/cli/core/services/ProjectScaffolder.ts +29 -291
- package/src/cli/core/tasks/BuildCloudflareTask.ts +382 -56
- package/src/cli/core/tasks/BuildDockerTask.ts +33 -3
- package/src/cli/core/tasks/BuildPrerenderTask.ts +44 -7
- package/src/cli/core/tasks/BuildTask.ts +34 -0
- package/src/cli/core/templates/apiIndexTs.ts +1 -22
- package/src/cli/core/templates/mainCss.ts +0 -1
- package/src/cli/core/templates/webAppRouterTs.ts +0 -99
- package/src/cli/core/templates/webIndexTs.ts +1 -22
- package/src/cli/i18n/__tests__/I18nCheckService.spec.ts +48 -0
- package/src/cli/i18n/services/I18nCheckService.ts +65 -11
- package/src/cli/platform/__tests__/SecretsCommand.spec.ts +5 -3
- package/src/cli/platform/commands/SecretsCommand.ts +8 -6
- package/src/cli/platform/commands/platform.ts +192 -46
- package/src/cli/platform/index.ts +12 -52
- package/src/cli/{platform → platform-lib}/__tests__/CloudflareAdapter.spec.ts +426 -169
- package/src/cli/{platform → platform-lib}/__tests__/NamingService.spec.ts +91 -4
- package/src/cli/{platform → platform-lib}/__tests__/VercelAdapter.spec.ts +56 -85
- package/src/cli/{platform → platform-lib}/adapters/CloudflareAdapter.ts +519 -190
- package/src/cli/{platform → platform-lib}/adapters/PlatformAdapter.ts +62 -35
- package/src/cli/{platform → platform-lib}/adapters/VercelAdapter.ts +6 -10
- package/src/cli/{platform → platform-lib}/atoms/platformOptions.ts +34 -1
- package/src/cli/platform-lib/index.ts +67 -0
- package/src/cli/platform-lib/services/NamingService.ts +136 -0
- package/src/cli/{platform → platform-lib}/services/PlatformInspector.ts +60 -13
- package/src/cli/{platform → platform-lib}/services/PlatformOrchestrator.ts +54 -43
- package/src/cli/{platform → platform-lib}/services/WranglerApi.ts +4 -2
- package/src/command/__tests__/Runner.spec.ts +20 -0
- package/src/command/helpers/EnvUtils.ts +19 -3
- package/src/command/helpers/Runner.ts +12 -2
- package/src/command/providers/CliProvider.ts +34 -1
- package/src/{containers → container}/core/__tests__/$container.spec.ts +5 -5
- package/src/{containers → container}/core/index.ts +4 -4
- package/src/{containers → container}/core/index.workerd.ts +19 -3
- package/src/{containers → container}/core/primitives/$container.ts +1 -1
- package/src/{containers → container}/core/providers/CloudflareContainerProvider.ts +17 -19
- package/src/{containers → container}/core/providers/ContainerProvider.ts +16 -2
- package/src/{containers → container}/core/providers/MockContainerProvider.ts +1 -1
- package/src/core/Alepha.ts +49 -1
- package/src/core/__tests__/$env.spec.ts +42 -0
- package/src/core/__tests__/dump.spec.ts +47 -0
- package/src/email/cloudflare/__tests__/CloudflareEmailProvider.spec.ts +42 -10
- package/src/email/cloudflare/index.ts +14 -5
- package/src/email/cloudflare/providers/CloudflareEmailProvider.ts +54 -9
- package/src/logger/__tests__/Logger.spec.ts +55 -0
- package/src/logger/index.ts +13 -0
- package/src/logger/services/Logger.ts +31 -1
- package/src/mcp/__tests__/McpServerProvider.spec.ts +71 -0
- package/src/mcp/providers/McpServerProvider.ts +55 -0
- package/src/orm/__tests__/orm-showcase-tests.ts +27 -0
- package/src/orm/__tests__/orm-showcase.spec.ts +12 -0
- package/src/orm/core/interfaces/PgQuery.ts +4 -1
- package/src/orm/core/services/Repository.ts +27 -11
- package/src/react/auth/hooks/useAuth.ts +10 -5
- package/src/react/core/__tests__/useQuery.browser.spec.tsx +25 -0
- package/src/react/core/hooks/useAction.ts +14 -3
- package/src/react/core/hooks/useQuery.ts +24 -4
- package/src/react/form/__tests__/FormModel-submit-loading.spec.ts +71 -0
- package/src/react/form/__tests__/form-submitting-reactive.browser.spec.tsx +96 -0
- package/src/react/form/services/FormModel.ts +57 -39
- package/src/react/i18n/__tests__/I18nProvider.spec.ts +89 -0
- package/src/react/i18n/__tests__/locale-routing.spec.ts +107 -0
- package/src/react/i18n/components/Translate.tsx +47 -0
- package/src/react/i18n/index.ts +2 -0
- package/src/react/i18n/providers/I18nProvider.ts +171 -12
- package/src/react/intro/components/GettingStartedAdminSlide.tsx +2 -2
- package/src/react/router/__tests__/$page.spec.tsx +3 -2
- package/src/react/router/__tests__/RouterLocaleProvider.spec.ts +127 -0
- package/src/react/router/__tests__/page-can.spec.ts +18 -13
- package/src/react/router/hooks/useQueryParams.ts +114 -14
- package/src/react/router/index.browser.ts +4 -0
- package/src/react/router/index.shared.ts +1 -0
- package/src/react/router/index.ts +9 -0
- package/src/react/router/primitives/$page.ts +85 -4
- package/src/react/router/providers/ReactBrowserRouterProvider.ts +18 -8
- package/src/react/router/providers/ReactPageProvider.ts +12 -1
- package/src/react/router/providers/ReactServerProvider.ts +96 -14
- package/src/react/router/providers/RootComponentsProvider.ts +13 -0
- package/src/react/router/providers/RouterLocaleProvider.ts +125 -0
- package/src/react/router/providers/__tests__/RootComponentsProvider.spec.ts +15 -0
- package/src/react/router/providers/__tests__/rootComponents.ssr.browser.spec.tsx +67 -0
- package/src/react/sitemap/__tests__/$sitemap.spec.ts +131 -0
- package/src/react/sitemap/index.browser.ts +21 -0
- package/src/react/sitemap/index.ts +25 -0
- package/src/react/sitemap/primitives/$sitemap.browser.ts +26 -0
- package/src/react/sitemap/primitives/$sitemap.ts +196 -0
- package/src/react/ui/services/SchemaControl.ts +3 -4
- package/src/server/auth/__tests__/appleClientSecret.spec.ts +34 -0
- package/src/server/auth/__tests__/authFederationClient.spec.ts +40 -0
- package/src/server/auth/__tests__/federationAssertion.spec.ts +146 -0
- package/src/server/auth/__tests__/federationRedirectReplay.spec.ts +44 -0
- package/src/server/auth/helpers/appleClientSecret.ts +24 -0
- package/src/server/auth/helpers/federationAssertion.ts +74 -0
- package/src/server/auth/helpers/jtiReplayGuard.ts +41 -0
- package/src/server/auth/helpers/safeRedirectPath.ts +19 -0
- package/src/server/auth/index.ts +4 -0
- package/src/server/auth/primitives/$authFederationBroker.ts +273 -0
- package/src/server/auth/primitives/$authFederationClient.ts +89 -0
- package/src/server/auth/providers/ServerAuthProvider.ts +18 -4
- package/src/server/cookies/__tests__/ServerCookiesProvider.spec.ts +70 -0
- package/src/server/cookies/providers/ServerCookiesProvider.ts +23 -3
- package/src/server/core/interfaces/ServerRequest.ts +8 -0
- package/src/server/core/primitives/$route.ts +27 -0
- package/src/server/core/providers/ServerMultipartProvider.ts +19 -0
- package/src/server/links/providers/LinkProvider.ts +10 -0
- package/dist/containers/core/index.d.ts.map +0 -1
- package/dist/containers/core/index.js.map +0 -1
- package/dist/containers/core/index.workerd.js.map +0 -1
- package/src/cli/core/tasks/BuildSitemapTask.ts +0 -130
- package/src/cli/core/templates/componentsJsonTs.ts +0 -39
- package/src/cli/core/templates/saasAdminLayoutTsx.ts +0 -77
- package/src/cli/core/templates/saasAdminPagesTsx.ts +0 -26
- package/src/cli/core/templates/saasAuthLayoutTsx.ts +0 -22
- package/src/cli/core/templates/saasAuthPagesTsx.ts +0 -62
- package/src/cli/core/templates/saasRealmProviderTs.ts +0 -52
- package/src/cli/platform/services/NamingService.ts +0 -54
- /package/dist/orm/core/{chunk-o8xxKEmq.js → chunk-B4FMCO8f.js} +0 -0
- /package/dist/react/testing/{chunk-6Ep1yQYe.js → chunk-BpyX8vjI.js} +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/GitHubSecretStore.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/PlatformCacheProvider.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/PlatformInspector.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/PlatformOrchestrator.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/SecretFilterService.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/__tests__/detectResources.spec.ts +0 -0
- /package/src/cli/{platform → platform-lib}/providers/GitHubSecretStore.ts +0 -0
- /package/src/cli/{platform → platform-lib}/providers/MemorySecretStore.ts +0 -0
- /package/src/cli/{platform → platform-lib}/providers/PlatformCacheProvider.ts +0 -0
- /package/src/cli/{platform → platform-lib}/providers/SecretStoreProvider.ts +0 -0
- /package/src/cli/{platform → platform-lib}/schemas/cloudflare.ts +0 -0
- /package/src/cli/{platform → platform-lib}/schemas/platform.ts +0 -0
- /package/src/cli/{platform → platform-lib}/schemas/vercel.ts +0 -0
- /package/src/cli/{platform → platform-lib}/services/CloudflareApi.ts +0 -0
- /package/src/cli/{platform → platform-lib}/services/SecretFilterService.ts +0 -0
- /package/src/cli/{platform → platform-lib}/services/VercelApi.ts +0 -0
- /package/src/cli/{platform → platform-lib}/services/VercelCli.ts +0 -0
- /package/src/{containers → container}/core/interfaces/ContainerOptions.ts +0 -0
- /package/src/{containers → container}/core/providers/NodeContainerProvider.ts +0 -0
|
@@ -28,11 +28,11 @@ const clockSkew = Symbol();
|
|
|
28
28
|
const clockTolerance = Symbol();
|
|
29
29
|
const customFetch$1 = Symbol();
|
|
30
30
|
const jweDecrypt = Symbol();
|
|
31
|
-
const encoder = new TextEncoder();
|
|
32
|
-
const decoder$
|
|
31
|
+
const encoder$1 = new TextEncoder();
|
|
32
|
+
const decoder$2 = new TextDecoder();
|
|
33
33
|
function buf(input) {
|
|
34
|
-
if (typeof input === "string") return encoder.encode(input);
|
|
35
|
-
return decoder$
|
|
34
|
+
if (typeof input === "string") return encoder$1.encode(input);
|
|
35
|
+
return decoder$2.decode(input);
|
|
36
36
|
}
|
|
37
37
|
let encodeBase64Url;
|
|
38
38
|
if (Uint8Array.prototype.toBase64) encodeBase64Url = (input) => {
|
|
@@ -336,14 +336,10 @@ var WWWAuthenticateChallengeError = class extends Error {
|
|
|
336
336
|
Error.captureStackTrace?.(this, this.constructor);
|
|
337
337
|
}
|
|
338
338
|
};
|
|
339
|
-
const
|
|
340
|
-
const
|
|
341
|
-
const
|
|
342
|
-
const
|
|
343
|
-
const schemeRE = new RegExp("^[,\\s]*(" + tokenMatch + ")");
|
|
344
|
-
const quotedParamRE = new RegExp("^[,\\s]*" + quotedParamMatcher + "[,\\s]*(.*)");
|
|
345
|
-
const unquotedParamRE = new RegExp("^[,\\s]*" + paramMatcher + "[,\\s]*(.*)");
|
|
346
|
-
const token68ParamRE = new RegExp("^(" + token68Match + ")(?:$|[,\\s])(.*)");
|
|
339
|
+
const schemeRE = /* @__PURE__ */ new RegExp("^[,\\s]*([a-zA-Z0-9!#$%&\\'\\*\\+\\-\\.\\^_`\\|~]+)");
|
|
340
|
+
const quotedParamRE = /* @__PURE__ */ new RegExp("^[,\\s]*([a-zA-Z0-9!#$%&\\'\\*\\+\\-\\.\\^_`\\|~]+)\\s*=\\s*\"((?:[^\"\\\\]|\\\\[\\s\\S])*)\"[,\\s]*(.*)");
|
|
341
|
+
const unquotedParamRE = /* @__PURE__ */ new RegExp("^[,\\s]*([a-zA-Z0-9!#$%&\\'\\*\\+\\-\\.\\^_`\\|~]+)\\s*=\\s*([a-zA-Z0-9!#$%&\\'\\*\\+\\-\\.\\^_`\\|~]+)[,\\s]*(.*)");
|
|
342
|
+
const token68ParamRE = /* @__PURE__ */ new RegExp("^([a-zA-Z0-9\\-\\._\\~\\+\\/]+={0,2})(?:$|[,\\s])(.*)");
|
|
347
343
|
function parseWwwAuthenticateChallenges(response) {
|
|
348
344
|
if (!looseInstanceOf(response, Response)) throw CodedTypeError$1("\"response\" must be an instance of Response", ERR_INVALID_ARG_TYPE$1);
|
|
349
345
|
const header = response.headers.get("www-authenticate");
|
|
@@ -1755,13 +1751,21 @@ var ServerAuthProvider = class {
|
|
|
1755
1751
|
reply.redirect(errorUrl.pathname + errorUrl.search, 302);
|
|
1756
1752
|
return;
|
|
1757
1753
|
}
|
|
1754
|
+
await this.establishSession(user, issuer, provider.name, cookies);
|
|
1755
|
+
reply.redirect(redirectUri, 302);
|
|
1756
|
+
}
|
|
1757
|
+
/**
|
|
1758
|
+
* Establish a local session for an already-resolved user: mint realm tokens
|
|
1759
|
+
* and write the `tokens` cookie. Used by the OAuth callback and by federated
|
|
1760
|
+
* (broker) login. `issuer` is the realm issuer (provider.issuer / realm).
|
|
1761
|
+
*/
|
|
1762
|
+
async establishSession(user, issuer, providerName, cookies) {
|
|
1758
1763
|
const tokens = await issuer.createToken(user);
|
|
1759
1764
|
this.setTokens({
|
|
1760
1765
|
...tokens,
|
|
1761
1766
|
issued_at: this.dateTimeProvider.now().unix(),
|
|
1762
|
-
provider:
|
|
1767
|
+
provider: providerName
|
|
1763
1768
|
}, cookies);
|
|
1764
|
-
reply.redirect(redirectUri, 302);
|
|
1765
1769
|
}
|
|
1766
1770
|
/**
|
|
1767
1771
|
* Callback for OAuth2/OIDC providers.
|
|
@@ -1925,6 +1929,1341 @@ var ServerAuthProvider = class {
|
|
|
1925
1929
|
}
|
|
1926
1930
|
};
|
|
1927
1931
|
//#endregion
|
|
1932
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/buffer_utils.js
|
|
1933
|
+
const encoder = new TextEncoder();
|
|
1934
|
+
const decoder = new TextDecoder();
|
|
1935
|
+
function concat(...buffers) {
|
|
1936
|
+
const size = buffers.reduce((acc, { length }) => acc + length, 0);
|
|
1937
|
+
const buf = new Uint8Array(size);
|
|
1938
|
+
let i = 0;
|
|
1939
|
+
for (const buffer of buffers) {
|
|
1940
|
+
buf.set(buffer, i);
|
|
1941
|
+
i += buffer.length;
|
|
1942
|
+
}
|
|
1943
|
+
return buf;
|
|
1944
|
+
}
|
|
1945
|
+
function encode$1(string) {
|
|
1946
|
+
const bytes = new Uint8Array(string.length);
|
|
1947
|
+
for (let i = 0; i < string.length; i++) {
|
|
1948
|
+
const code = string.charCodeAt(i);
|
|
1949
|
+
if (code > 127) throw new TypeError("non-ASCII string encountered in encode()");
|
|
1950
|
+
bytes[i] = code;
|
|
1951
|
+
}
|
|
1952
|
+
return bytes;
|
|
1953
|
+
}
|
|
1954
|
+
//#endregion
|
|
1955
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/base64.js
|
|
1956
|
+
function encodeBase64(input) {
|
|
1957
|
+
if (Uint8Array.prototype.toBase64) return input.toBase64();
|
|
1958
|
+
const CHUNK_SIZE = 32768;
|
|
1959
|
+
const arr = [];
|
|
1960
|
+
for (let i = 0; i < input.length; i += CHUNK_SIZE) arr.push(String.fromCharCode.apply(null, input.subarray(i, i + CHUNK_SIZE)));
|
|
1961
|
+
return btoa(arr.join(""));
|
|
1962
|
+
}
|
|
1963
|
+
function decodeBase64(encoded) {
|
|
1964
|
+
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(encoded);
|
|
1965
|
+
const binary = atob(encoded);
|
|
1966
|
+
const bytes = new Uint8Array(binary.length);
|
|
1967
|
+
for (let i = 0; i < binary.length; i++) bytes[i] = binary.charCodeAt(i);
|
|
1968
|
+
return bytes;
|
|
1969
|
+
}
|
|
1970
|
+
//#endregion
|
|
1971
|
+
//#region ../../../../node_modules/jose/dist/webapi/util/base64url.js
|
|
1972
|
+
function decode(input) {
|
|
1973
|
+
if (Uint8Array.fromBase64) return Uint8Array.fromBase64(typeof input === "string" ? input : decoder.decode(input), { alphabet: "base64url" });
|
|
1974
|
+
let encoded = input;
|
|
1975
|
+
if (encoded instanceof Uint8Array) encoded = decoder.decode(encoded);
|
|
1976
|
+
encoded = encoded.replace(/-/g, "+").replace(/_/g, "/");
|
|
1977
|
+
try {
|
|
1978
|
+
return decodeBase64(encoded);
|
|
1979
|
+
} catch {
|
|
1980
|
+
throw new TypeError("The input to be decoded is not correctly encoded.");
|
|
1981
|
+
}
|
|
1982
|
+
}
|
|
1983
|
+
function encode(input) {
|
|
1984
|
+
let unencoded = input;
|
|
1985
|
+
if (typeof unencoded === "string") unencoded = encoder.encode(unencoded);
|
|
1986
|
+
if (Uint8Array.prototype.toBase64) return unencoded.toBase64({
|
|
1987
|
+
alphabet: "base64url",
|
|
1988
|
+
omitPadding: true
|
|
1989
|
+
});
|
|
1990
|
+
return encodeBase64(unencoded).replace(/=/g, "").replace(/\+/g, "-").replace(/\//g, "_");
|
|
1991
|
+
}
|
|
1992
|
+
//#endregion
|
|
1993
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/crypto_key.js
|
|
1994
|
+
const unusable = (name, prop = "algorithm.name") => /* @__PURE__ */ new TypeError(`CryptoKey does not support this operation, its ${prop} must be ${name}`);
|
|
1995
|
+
const isAlgorithm = (algorithm, name) => algorithm.name === name;
|
|
1996
|
+
function getHashLength(hash) {
|
|
1997
|
+
return parseInt(hash.name.slice(4), 10);
|
|
1998
|
+
}
|
|
1999
|
+
function checkHashLength(algorithm, expected) {
|
|
2000
|
+
if (getHashLength(algorithm.hash) !== expected) throw unusable(`SHA-${expected}`, "algorithm.hash");
|
|
2001
|
+
}
|
|
2002
|
+
function getNamedCurve(alg) {
|
|
2003
|
+
switch (alg) {
|
|
2004
|
+
case "ES256": return "P-256";
|
|
2005
|
+
case "ES384": return "P-384";
|
|
2006
|
+
case "ES512": return "P-521";
|
|
2007
|
+
default: throw new Error("unreachable");
|
|
2008
|
+
}
|
|
2009
|
+
}
|
|
2010
|
+
function checkUsage(key, usage) {
|
|
2011
|
+
if (usage && !key.usages.includes(usage)) throw new TypeError(`CryptoKey does not support this operation, its usages must include ${usage}.`);
|
|
2012
|
+
}
|
|
2013
|
+
function checkSigCryptoKey(key, alg, usage) {
|
|
2014
|
+
switch (alg) {
|
|
2015
|
+
case "HS256":
|
|
2016
|
+
case "HS384":
|
|
2017
|
+
case "HS512":
|
|
2018
|
+
if (!isAlgorithm(key.algorithm, "HMAC")) throw unusable("HMAC");
|
|
2019
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
2020
|
+
break;
|
|
2021
|
+
case "RS256":
|
|
2022
|
+
case "RS384":
|
|
2023
|
+
case "RS512":
|
|
2024
|
+
if (!isAlgorithm(key.algorithm, "RSASSA-PKCS1-v1_5")) throw unusable("RSASSA-PKCS1-v1_5");
|
|
2025
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
2026
|
+
break;
|
|
2027
|
+
case "PS256":
|
|
2028
|
+
case "PS384":
|
|
2029
|
+
case "PS512":
|
|
2030
|
+
if (!isAlgorithm(key.algorithm, "RSA-PSS")) throw unusable("RSA-PSS");
|
|
2031
|
+
checkHashLength(key.algorithm, parseInt(alg.slice(2), 10));
|
|
2032
|
+
break;
|
|
2033
|
+
case "Ed25519":
|
|
2034
|
+
case "EdDSA":
|
|
2035
|
+
if (!isAlgorithm(key.algorithm, "Ed25519")) throw unusable("Ed25519");
|
|
2036
|
+
break;
|
|
2037
|
+
case "ML-DSA-44":
|
|
2038
|
+
case "ML-DSA-65":
|
|
2039
|
+
case "ML-DSA-87":
|
|
2040
|
+
if (!isAlgorithm(key.algorithm, alg)) throw unusable(alg);
|
|
2041
|
+
break;
|
|
2042
|
+
case "ES256":
|
|
2043
|
+
case "ES384":
|
|
2044
|
+
case "ES512": {
|
|
2045
|
+
if (!isAlgorithm(key.algorithm, "ECDSA")) throw unusable("ECDSA");
|
|
2046
|
+
const expected = getNamedCurve(alg);
|
|
2047
|
+
if (key.algorithm.namedCurve !== expected) throw unusable(expected, "algorithm.namedCurve");
|
|
2048
|
+
break;
|
|
2049
|
+
}
|
|
2050
|
+
default: throw new TypeError("CryptoKey does not support this operation");
|
|
2051
|
+
}
|
|
2052
|
+
checkUsage(key, usage);
|
|
2053
|
+
}
|
|
2054
|
+
//#endregion
|
|
2055
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/invalid_key_input.js
|
|
2056
|
+
function message(msg, actual, ...types) {
|
|
2057
|
+
types = types.filter(Boolean);
|
|
2058
|
+
if (types.length > 2) {
|
|
2059
|
+
const last = types.pop();
|
|
2060
|
+
msg += `one of type ${types.join(", ")}, or ${last}.`;
|
|
2061
|
+
} else if (types.length === 2) msg += `one of type ${types[0]} or ${types[1]}.`;
|
|
2062
|
+
else msg += `of type ${types[0]}.`;
|
|
2063
|
+
if (actual == null) msg += ` Received ${actual}`;
|
|
2064
|
+
else if (typeof actual === "function" && actual.name) msg += ` Received function ${actual.name}`;
|
|
2065
|
+
else if (typeof actual === "object" && actual != null) {
|
|
2066
|
+
if (actual.constructor?.name) msg += ` Received an instance of ${actual.constructor.name}`;
|
|
2067
|
+
}
|
|
2068
|
+
return msg;
|
|
2069
|
+
}
|
|
2070
|
+
const invalidKeyInput = (actual, ...types) => message("Key must be ", actual, ...types);
|
|
2071
|
+
const withAlg = (alg, actual, ...types) => message(`Key for the ${alg} algorithm must be `, actual, ...types);
|
|
2072
|
+
//#endregion
|
|
2073
|
+
//#region ../../../../node_modules/jose/dist/webapi/util/errors.js
|
|
2074
|
+
var JOSEError = class extends Error {
|
|
2075
|
+
static code = "ERR_JOSE_GENERIC";
|
|
2076
|
+
code = "ERR_JOSE_GENERIC";
|
|
2077
|
+
constructor(message, options) {
|
|
2078
|
+
super(message, options);
|
|
2079
|
+
this.name = this.constructor.name;
|
|
2080
|
+
Error.captureStackTrace?.(this, this.constructor);
|
|
2081
|
+
}
|
|
2082
|
+
};
|
|
2083
|
+
var JWTClaimValidationFailed = class extends JOSEError {
|
|
2084
|
+
static code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
2085
|
+
code = "ERR_JWT_CLAIM_VALIDATION_FAILED";
|
|
2086
|
+
claim;
|
|
2087
|
+
reason;
|
|
2088
|
+
payload;
|
|
2089
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
2090
|
+
super(message, { cause: {
|
|
2091
|
+
claim,
|
|
2092
|
+
reason,
|
|
2093
|
+
payload
|
|
2094
|
+
} });
|
|
2095
|
+
this.claim = claim;
|
|
2096
|
+
this.reason = reason;
|
|
2097
|
+
this.payload = payload;
|
|
2098
|
+
}
|
|
2099
|
+
};
|
|
2100
|
+
var JWTExpired = class extends JOSEError {
|
|
2101
|
+
static code = "ERR_JWT_EXPIRED";
|
|
2102
|
+
code = "ERR_JWT_EXPIRED";
|
|
2103
|
+
claim;
|
|
2104
|
+
reason;
|
|
2105
|
+
payload;
|
|
2106
|
+
constructor(message, payload, claim = "unspecified", reason = "unspecified") {
|
|
2107
|
+
super(message, { cause: {
|
|
2108
|
+
claim,
|
|
2109
|
+
reason,
|
|
2110
|
+
payload
|
|
2111
|
+
} });
|
|
2112
|
+
this.claim = claim;
|
|
2113
|
+
this.reason = reason;
|
|
2114
|
+
this.payload = payload;
|
|
2115
|
+
}
|
|
2116
|
+
};
|
|
2117
|
+
var JOSEAlgNotAllowed = class extends JOSEError {
|
|
2118
|
+
static code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
2119
|
+
code = "ERR_JOSE_ALG_NOT_ALLOWED";
|
|
2120
|
+
};
|
|
2121
|
+
var JOSENotSupported = class extends JOSEError {
|
|
2122
|
+
static code = "ERR_JOSE_NOT_SUPPORTED";
|
|
2123
|
+
code = "ERR_JOSE_NOT_SUPPORTED";
|
|
2124
|
+
};
|
|
2125
|
+
var JWSInvalid = class extends JOSEError {
|
|
2126
|
+
static code = "ERR_JWS_INVALID";
|
|
2127
|
+
code = "ERR_JWS_INVALID";
|
|
2128
|
+
};
|
|
2129
|
+
var JWTInvalid = class extends JOSEError {
|
|
2130
|
+
static code = "ERR_JWT_INVALID";
|
|
2131
|
+
code = "ERR_JWT_INVALID";
|
|
2132
|
+
};
|
|
2133
|
+
var JWSSignatureVerificationFailed = class extends JOSEError {
|
|
2134
|
+
static code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
2135
|
+
code = "ERR_JWS_SIGNATURE_VERIFICATION_FAILED";
|
|
2136
|
+
constructor(message = "signature verification failed", options) {
|
|
2137
|
+
super(message, options);
|
|
2138
|
+
}
|
|
2139
|
+
};
|
|
2140
|
+
//#endregion
|
|
2141
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/is_key_like.js
|
|
2142
|
+
const isCryptoKey = (key) => {
|
|
2143
|
+
if (key?.[Symbol.toStringTag] === "CryptoKey") return true;
|
|
2144
|
+
try {
|
|
2145
|
+
return key instanceof CryptoKey;
|
|
2146
|
+
} catch {
|
|
2147
|
+
return false;
|
|
2148
|
+
}
|
|
2149
|
+
};
|
|
2150
|
+
const isKeyObject = (key) => key?.[Symbol.toStringTag] === "KeyObject";
|
|
2151
|
+
const isKeyLike = (key) => isCryptoKey(key) || isKeyObject(key);
|
|
2152
|
+
//#endregion
|
|
2153
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/helpers.js
|
|
2154
|
+
function assertNotSet(value, name) {
|
|
2155
|
+
if (value) throw new TypeError(`${name} can only be called once`);
|
|
2156
|
+
}
|
|
2157
|
+
function decodeBase64url(value, label, ErrorClass) {
|
|
2158
|
+
try {
|
|
2159
|
+
return decode(value);
|
|
2160
|
+
} catch {
|
|
2161
|
+
throw new ErrorClass(`Failed to base64url decode the ${label}`);
|
|
2162
|
+
}
|
|
2163
|
+
}
|
|
2164
|
+
//#endregion
|
|
2165
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/type_checks.js
|
|
2166
|
+
const isObjectLike = (value) => typeof value === "object" && value !== null;
|
|
2167
|
+
function isObject(input) {
|
|
2168
|
+
if (!isObjectLike(input) || Object.prototype.toString.call(input) !== "[object Object]") return false;
|
|
2169
|
+
if (Object.getPrototypeOf(input) === null) return true;
|
|
2170
|
+
let proto = input;
|
|
2171
|
+
while (Object.getPrototypeOf(proto) !== null) proto = Object.getPrototypeOf(proto);
|
|
2172
|
+
return Object.getPrototypeOf(input) === proto;
|
|
2173
|
+
}
|
|
2174
|
+
function isDisjoint(...headers) {
|
|
2175
|
+
const sources = headers.filter(Boolean);
|
|
2176
|
+
if (sources.length === 0 || sources.length === 1) return true;
|
|
2177
|
+
let acc;
|
|
2178
|
+
for (const header of sources) {
|
|
2179
|
+
const parameters = Object.keys(header);
|
|
2180
|
+
if (!acc || acc.size === 0) {
|
|
2181
|
+
acc = new Set(parameters);
|
|
2182
|
+
continue;
|
|
2183
|
+
}
|
|
2184
|
+
for (const parameter of parameters) {
|
|
2185
|
+
if (acc.has(parameter)) return false;
|
|
2186
|
+
acc.add(parameter);
|
|
2187
|
+
}
|
|
2188
|
+
}
|
|
2189
|
+
return true;
|
|
2190
|
+
}
|
|
2191
|
+
const isJWK = (key) => isObject(key) && typeof key.kty === "string";
|
|
2192
|
+
const isPrivateJWK = (key) => key.kty !== "oct" && (key.kty === "AKP" && typeof key.priv === "string" || typeof key.d === "string");
|
|
2193
|
+
const isPublicJWK = (key) => key.kty !== "oct" && key.d === void 0 && key.priv === void 0;
|
|
2194
|
+
const isSecretJWK = (key) => key.kty === "oct" && typeof key.k === "string";
|
|
2195
|
+
//#endregion
|
|
2196
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/signing.js
|
|
2197
|
+
function checkKeyLength(alg, key) {
|
|
2198
|
+
if (alg.startsWith("RS") || alg.startsWith("PS")) {
|
|
2199
|
+
const { modulusLength } = key.algorithm;
|
|
2200
|
+
if (typeof modulusLength !== "number" || modulusLength < 2048) throw new TypeError(`${alg} requires key modulusLength to be 2048 bits or larger`);
|
|
2201
|
+
}
|
|
2202
|
+
}
|
|
2203
|
+
function subtleAlgorithm(alg, algorithm) {
|
|
2204
|
+
const hash = `SHA-${alg.slice(-3)}`;
|
|
2205
|
+
switch (alg) {
|
|
2206
|
+
case "HS256":
|
|
2207
|
+
case "HS384":
|
|
2208
|
+
case "HS512": return {
|
|
2209
|
+
hash,
|
|
2210
|
+
name: "HMAC"
|
|
2211
|
+
};
|
|
2212
|
+
case "PS256":
|
|
2213
|
+
case "PS384":
|
|
2214
|
+
case "PS512": return {
|
|
2215
|
+
hash,
|
|
2216
|
+
name: "RSA-PSS",
|
|
2217
|
+
saltLength: parseInt(alg.slice(-3), 10) >> 3
|
|
2218
|
+
};
|
|
2219
|
+
case "RS256":
|
|
2220
|
+
case "RS384":
|
|
2221
|
+
case "RS512": return {
|
|
2222
|
+
hash,
|
|
2223
|
+
name: "RSASSA-PKCS1-v1_5"
|
|
2224
|
+
};
|
|
2225
|
+
case "ES256":
|
|
2226
|
+
case "ES384":
|
|
2227
|
+
case "ES512": return {
|
|
2228
|
+
hash,
|
|
2229
|
+
name: "ECDSA",
|
|
2230
|
+
namedCurve: algorithm.namedCurve
|
|
2231
|
+
};
|
|
2232
|
+
case "Ed25519":
|
|
2233
|
+
case "EdDSA": return { name: "Ed25519" };
|
|
2234
|
+
case "ML-DSA-44":
|
|
2235
|
+
case "ML-DSA-65":
|
|
2236
|
+
case "ML-DSA-87": return { name: alg };
|
|
2237
|
+
default: throw new JOSENotSupported(`alg ${alg} is not supported either by JOSE or your javascript runtime`);
|
|
2238
|
+
}
|
|
2239
|
+
}
|
|
2240
|
+
async function getSigKey(alg, key, usage) {
|
|
2241
|
+
if (key instanceof Uint8Array) {
|
|
2242
|
+
if (!alg.startsWith("HS")) throw new TypeError(invalidKeyInput(key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
2243
|
+
return crypto.subtle.importKey("raw", key, {
|
|
2244
|
+
hash: `SHA-${alg.slice(-3)}`,
|
|
2245
|
+
name: "HMAC"
|
|
2246
|
+
}, false, [usage]);
|
|
2247
|
+
}
|
|
2248
|
+
checkSigCryptoKey(key, alg, usage);
|
|
2249
|
+
return key;
|
|
2250
|
+
}
|
|
2251
|
+
async function sign(alg, key, data) {
|
|
2252
|
+
const cryptoKey = await getSigKey(alg, key, "sign");
|
|
2253
|
+
checkKeyLength(alg, cryptoKey);
|
|
2254
|
+
const signature = await crypto.subtle.sign(subtleAlgorithm(alg, cryptoKey.algorithm), cryptoKey, data);
|
|
2255
|
+
return new Uint8Array(signature);
|
|
2256
|
+
}
|
|
2257
|
+
async function verify(alg, key, signature, data) {
|
|
2258
|
+
const cryptoKey = await getSigKey(alg, key, "verify");
|
|
2259
|
+
checkKeyLength(alg, cryptoKey);
|
|
2260
|
+
const algorithm = subtleAlgorithm(alg, cryptoKey.algorithm);
|
|
2261
|
+
try {
|
|
2262
|
+
return await crypto.subtle.verify(algorithm, cryptoKey, signature, data);
|
|
2263
|
+
} catch {
|
|
2264
|
+
return false;
|
|
2265
|
+
}
|
|
2266
|
+
}
|
|
2267
|
+
//#endregion
|
|
2268
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/jwk_to_key.js
|
|
2269
|
+
const unsupportedAlg = "Invalid or unsupported JWK \"alg\" (Algorithm) Parameter value";
|
|
2270
|
+
function subtleMapping(jwk) {
|
|
2271
|
+
let algorithm;
|
|
2272
|
+
let keyUsages;
|
|
2273
|
+
switch (jwk.kty) {
|
|
2274
|
+
case "AKP":
|
|
2275
|
+
switch (jwk.alg) {
|
|
2276
|
+
case "ML-DSA-44":
|
|
2277
|
+
case "ML-DSA-65":
|
|
2278
|
+
case "ML-DSA-87":
|
|
2279
|
+
algorithm = { name: jwk.alg };
|
|
2280
|
+
keyUsages = jwk.priv ? ["sign"] : ["verify"];
|
|
2281
|
+
break;
|
|
2282
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
2283
|
+
}
|
|
2284
|
+
break;
|
|
2285
|
+
case "RSA":
|
|
2286
|
+
switch (jwk.alg) {
|
|
2287
|
+
case "PS256":
|
|
2288
|
+
case "PS384":
|
|
2289
|
+
case "PS512":
|
|
2290
|
+
algorithm = {
|
|
2291
|
+
name: "RSA-PSS",
|
|
2292
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
2293
|
+
};
|
|
2294
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
2295
|
+
break;
|
|
2296
|
+
case "RS256":
|
|
2297
|
+
case "RS384":
|
|
2298
|
+
case "RS512":
|
|
2299
|
+
algorithm = {
|
|
2300
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
2301
|
+
hash: `SHA-${jwk.alg.slice(-3)}`
|
|
2302
|
+
};
|
|
2303
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
2304
|
+
break;
|
|
2305
|
+
case "RSA-OAEP":
|
|
2306
|
+
case "RSA-OAEP-256":
|
|
2307
|
+
case "RSA-OAEP-384":
|
|
2308
|
+
case "RSA-OAEP-512":
|
|
2309
|
+
algorithm = {
|
|
2310
|
+
name: "RSA-OAEP",
|
|
2311
|
+
hash: `SHA-${parseInt(jwk.alg.slice(-3), 10) || 1}`
|
|
2312
|
+
};
|
|
2313
|
+
keyUsages = jwk.d ? ["decrypt", "unwrapKey"] : ["encrypt", "wrapKey"];
|
|
2314
|
+
break;
|
|
2315
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
2316
|
+
}
|
|
2317
|
+
break;
|
|
2318
|
+
case "EC":
|
|
2319
|
+
switch (jwk.alg) {
|
|
2320
|
+
case "ES256":
|
|
2321
|
+
case "ES384":
|
|
2322
|
+
case "ES512":
|
|
2323
|
+
algorithm = {
|
|
2324
|
+
name: "ECDSA",
|
|
2325
|
+
namedCurve: {
|
|
2326
|
+
ES256: "P-256",
|
|
2327
|
+
ES384: "P-384",
|
|
2328
|
+
ES512: "P-521"
|
|
2329
|
+
}[jwk.alg]
|
|
2330
|
+
};
|
|
2331
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
2332
|
+
break;
|
|
2333
|
+
case "ECDH-ES":
|
|
2334
|
+
case "ECDH-ES+A128KW":
|
|
2335
|
+
case "ECDH-ES+A192KW":
|
|
2336
|
+
case "ECDH-ES+A256KW":
|
|
2337
|
+
algorithm = {
|
|
2338
|
+
name: "ECDH",
|
|
2339
|
+
namedCurve: jwk.crv
|
|
2340
|
+
};
|
|
2341
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
2342
|
+
break;
|
|
2343
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
2344
|
+
}
|
|
2345
|
+
break;
|
|
2346
|
+
case "OKP":
|
|
2347
|
+
switch (jwk.alg) {
|
|
2348
|
+
case "Ed25519":
|
|
2349
|
+
case "EdDSA":
|
|
2350
|
+
algorithm = { name: "Ed25519" };
|
|
2351
|
+
keyUsages = jwk.d ? ["sign"] : ["verify"];
|
|
2352
|
+
break;
|
|
2353
|
+
case "ECDH-ES":
|
|
2354
|
+
case "ECDH-ES+A128KW":
|
|
2355
|
+
case "ECDH-ES+A192KW":
|
|
2356
|
+
case "ECDH-ES+A256KW":
|
|
2357
|
+
algorithm = { name: jwk.crv };
|
|
2358
|
+
keyUsages = jwk.d ? ["deriveBits"] : [];
|
|
2359
|
+
break;
|
|
2360
|
+
default: throw new JOSENotSupported(unsupportedAlg);
|
|
2361
|
+
}
|
|
2362
|
+
break;
|
|
2363
|
+
default: throw new JOSENotSupported("Invalid or unsupported JWK \"kty\" (Key Type) Parameter value");
|
|
2364
|
+
}
|
|
2365
|
+
return {
|
|
2366
|
+
algorithm,
|
|
2367
|
+
keyUsages
|
|
2368
|
+
};
|
|
2369
|
+
}
|
|
2370
|
+
async function jwkToKey(jwk) {
|
|
2371
|
+
if (!jwk.alg) throw new TypeError("\"alg\" argument is required when \"jwk.alg\" is not present");
|
|
2372
|
+
const { algorithm, keyUsages } = subtleMapping(jwk);
|
|
2373
|
+
const keyData = { ...jwk };
|
|
2374
|
+
if (keyData.kty !== "AKP") delete keyData.alg;
|
|
2375
|
+
delete keyData.use;
|
|
2376
|
+
return crypto.subtle.importKey("jwk", keyData, algorithm, jwk.ext ?? (jwk.d || jwk.priv ? false : true), jwk.key_ops ?? keyUsages);
|
|
2377
|
+
}
|
|
2378
|
+
//#endregion
|
|
2379
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/normalize_key.js
|
|
2380
|
+
const unusableForAlg = "given KeyObject instance cannot be used for this algorithm";
|
|
2381
|
+
let cache;
|
|
2382
|
+
const handleJWK = async (key, jwk, alg, freeze = false) => {
|
|
2383
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
2384
|
+
let cached = cache.get(key);
|
|
2385
|
+
if (cached?.[alg]) return cached[alg];
|
|
2386
|
+
const cryptoKey = await jwkToKey({
|
|
2387
|
+
...jwk,
|
|
2388
|
+
alg
|
|
2389
|
+
});
|
|
2390
|
+
if (freeze) Object.freeze(key);
|
|
2391
|
+
if (!cached) cache.set(key, { [alg]: cryptoKey });
|
|
2392
|
+
else cached[alg] = cryptoKey;
|
|
2393
|
+
return cryptoKey;
|
|
2394
|
+
};
|
|
2395
|
+
const handleKeyObject = (keyObject, alg) => {
|
|
2396
|
+
cache ||= /* @__PURE__ */ new WeakMap();
|
|
2397
|
+
let cached = cache.get(keyObject);
|
|
2398
|
+
if (cached?.[alg]) return cached[alg];
|
|
2399
|
+
const isPublic = keyObject.type === "public";
|
|
2400
|
+
const extractable = isPublic ? true : false;
|
|
2401
|
+
let cryptoKey;
|
|
2402
|
+
if (keyObject.asymmetricKeyType === "x25519") {
|
|
2403
|
+
switch (alg) {
|
|
2404
|
+
case "ECDH-ES":
|
|
2405
|
+
case "ECDH-ES+A128KW":
|
|
2406
|
+
case "ECDH-ES+A192KW":
|
|
2407
|
+
case "ECDH-ES+A256KW": break;
|
|
2408
|
+
default: throw new TypeError(unusableForAlg);
|
|
2409
|
+
}
|
|
2410
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, isPublic ? [] : ["deriveBits"]);
|
|
2411
|
+
}
|
|
2412
|
+
if (keyObject.asymmetricKeyType === "ed25519") {
|
|
2413
|
+
if (alg !== "EdDSA" && alg !== "Ed25519") throw new TypeError(unusableForAlg);
|
|
2414
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
2415
|
+
}
|
|
2416
|
+
switch (keyObject.asymmetricKeyType) {
|
|
2417
|
+
case "ml-dsa-44":
|
|
2418
|
+
case "ml-dsa-65":
|
|
2419
|
+
case "ml-dsa-87":
|
|
2420
|
+
if (alg !== keyObject.asymmetricKeyType.toUpperCase()) throw new TypeError(unusableForAlg);
|
|
2421
|
+
cryptoKey = keyObject.toCryptoKey(keyObject.asymmetricKeyType, extractable, [isPublic ? "verify" : "sign"]);
|
|
2422
|
+
}
|
|
2423
|
+
if (keyObject.asymmetricKeyType === "rsa") {
|
|
2424
|
+
let hash;
|
|
2425
|
+
switch (alg) {
|
|
2426
|
+
case "RSA-OAEP":
|
|
2427
|
+
hash = "SHA-1";
|
|
2428
|
+
break;
|
|
2429
|
+
case "RS256":
|
|
2430
|
+
case "PS256":
|
|
2431
|
+
case "RSA-OAEP-256":
|
|
2432
|
+
hash = "SHA-256";
|
|
2433
|
+
break;
|
|
2434
|
+
case "RS384":
|
|
2435
|
+
case "PS384":
|
|
2436
|
+
case "RSA-OAEP-384":
|
|
2437
|
+
hash = "SHA-384";
|
|
2438
|
+
break;
|
|
2439
|
+
case "RS512":
|
|
2440
|
+
case "PS512":
|
|
2441
|
+
case "RSA-OAEP-512":
|
|
2442
|
+
hash = "SHA-512";
|
|
2443
|
+
break;
|
|
2444
|
+
default: throw new TypeError(unusableForAlg);
|
|
2445
|
+
}
|
|
2446
|
+
if (alg.startsWith("RSA-OAEP")) return keyObject.toCryptoKey({
|
|
2447
|
+
name: "RSA-OAEP",
|
|
2448
|
+
hash
|
|
2449
|
+
}, extractable, isPublic ? ["encrypt"] : ["decrypt"]);
|
|
2450
|
+
cryptoKey = keyObject.toCryptoKey({
|
|
2451
|
+
name: alg.startsWith("PS") ? "RSA-PSS" : "RSASSA-PKCS1-v1_5",
|
|
2452
|
+
hash
|
|
2453
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
2454
|
+
}
|
|
2455
|
+
if (keyObject.asymmetricKeyType === "ec") {
|
|
2456
|
+
const namedCurve = new Map([
|
|
2457
|
+
["prime256v1", "P-256"],
|
|
2458
|
+
["secp384r1", "P-384"],
|
|
2459
|
+
["secp521r1", "P-521"]
|
|
2460
|
+
]).get(keyObject.asymmetricKeyDetails?.namedCurve);
|
|
2461
|
+
if (!namedCurve) throw new TypeError(unusableForAlg);
|
|
2462
|
+
const expectedCurve = {
|
|
2463
|
+
ES256: "P-256",
|
|
2464
|
+
ES384: "P-384",
|
|
2465
|
+
ES512: "P-521"
|
|
2466
|
+
};
|
|
2467
|
+
if (expectedCurve[alg] && namedCurve === expectedCurve[alg]) cryptoKey = keyObject.toCryptoKey({
|
|
2468
|
+
name: "ECDSA",
|
|
2469
|
+
namedCurve
|
|
2470
|
+
}, extractable, [isPublic ? "verify" : "sign"]);
|
|
2471
|
+
if (alg.startsWith("ECDH-ES")) cryptoKey = keyObject.toCryptoKey({
|
|
2472
|
+
name: "ECDH",
|
|
2473
|
+
namedCurve
|
|
2474
|
+
}, extractable, isPublic ? [] : ["deriveBits"]);
|
|
2475
|
+
}
|
|
2476
|
+
if (!cryptoKey) throw new TypeError(unusableForAlg);
|
|
2477
|
+
if (!cached) cache.set(keyObject, { [alg]: cryptoKey });
|
|
2478
|
+
else cached[alg] = cryptoKey;
|
|
2479
|
+
return cryptoKey;
|
|
2480
|
+
};
|
|
2481
|
+
async function normalizeKey(key, alg) {
|
|
2482
|
+
if (key instanceof Uint8Array) return key;
|
|
2483
|
+
if (isCryptoKey(key)) return key;
|
|
2484
|
+
if (isKeyObject(key)) {
|
|
2485
|
+
if (key.type === "secret") return key.export();
|
|
2486
|
+
if ("toCryptoKey" in key && typeof key.toCryptoKey === "function") try {
|
|
2487
|
+
return handleKeyObject(key, alg);
|
|
2488
|
+
} catch (err) {
|
|
2489
|
+
if (err instanceof TypeError) throw err;
|
|
2490
|
+
}
|
|
2491
|
+
return handleJWK(key, key.export({ format: "jwk" }), alg);
|
|
2492
|
+
}
|
|
2493
|
+
if (isJWK(key)) {
|
|
2494
|
+
if (key.k) return decode(key.k);
|
|
2495
|
+
return handleJWK(key, key, alg, true);
|
|
2496
|
+
}
|
|
2497
|
+
throw new Error("unreachable");
|
|
2498
|
+
}
|
|
2499
|
+
//#endregion
|
|
2500
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/asn1.js
|
|
2501
|
+
const bytesEqual = (a, b) => {
|
|
2502
|
+
if (a.byteLength !== b.length) return false;
|
|
2503
|
+
for (let i = 0; i < a.byteLength; i++) if (a[i] !== b[i]) return false;
|
|
2504
|
+
return true;
|
|
2505
|
+
};
|
|
2506
|
+
const createASN1State = (data) => ({
|
|
2507
|
+
data,
|
|
2508
|
+
pos: 0
|
|
2509
|
+
});
|
|
2510
|
+
const parseLength = (state) => {
|
|
2511
|
+
const first = state.data[state.pos++];
|
|
2512
|
+
if (first & 128) {
|
|
2513
|
+
const lengthOfLen = first & 127;
|
|
2514
|
+
let length = 0;
|
|
2515
|
+
for (let i = 0; i < lengthOfLen; i++) length = length << 8 | state.data[state.pos++];
|
|
2516
|
+
return length;
|
|
2517
|
+
}
|
|
2518
|
+
return first;
|
|
2519
|
+
};
|
|
2520
|
+
const expectTag = (state, expectedTag, errorMessage) => {
|
|
2521
|
+
if (state.data[state.pos++] !== expectedTag) throw new Error(errorMessage);
|
|
2522
|
+
};
|
|
2523
|
+
const getSubarray = (state, length) => {
|
|
2524
|
+
const result = state.data.subarray(state.pos, state.pos + length);
|
|
2525
|
+
state.pos += length;
|
|
2526
|
+
return result;
|
|
2527
|
+
};
|
|
2528
|
+
const parseAlgorithmOID = (state) => {
|
|
2529
|
+
expectTag(state, 6, "Expected algorithm OID");
|
|
2530
|
+
return getSubarray(state, parseLength(state));
|
|
2531
|
+
};
|
|
2532
|
+
function parsePKCS8Header(state) {
|
|
2533
|
+
expectTag(state, 48, "Invalid PKCS#8 structure");
|
|
2534
|
+
parseLength(state);
|
|
2535
|
+
expectTag(state, 2, "Expected version field");
|
|
2536
|
+
const verLen = parseLength(state);
|
|
2537
|
+
state.pos += verLen;
|
|
2538
|
+
expectTag(state, 48, "Expected algorithm identifier");
|
|
2539
|
+
const algIdLen = parseLength(state);
|
|
2540
|
+
return {
|
|
2541
|
+
algIdStart: state.pos,
|
|
2542
|
+
algIdLength: algIdLen
|
|
2543
|
+
};
|
|
2544
|
+
}
|
|
2545
|
+
function parseSPKIHeader(state) {
|
|
2546
|
+
expectTag(state, 48, "Invalid SPKI structure");
|
|
2547
|
+
parseLength(state);
|
|
2548
|
+
expectTag(state, 48, "Expected algorithm identifier");
|
|
2549
|
+
const algIdLen = parseLength(state);
|
|
2550
|
+
return {
|
|
2551
|
+
algIdStart: state.pos,
|
|
2552
|
+
algIdLength: algIdLen
|
|
2553
|
+
};
|
|
2554
|
+
}
|
|
2555
|
+
const parseECAlgorithmIdentifier = (state) => {
|
|
2556
|
+
const algOid = parseAlgorithmOID(state);
|
|
2557
|
+
if (bytesEqual(algOid, [
|
|
2558
|
+
43,
|
|
2559
|
+
101,
|
|
2560
|
+
110
|
|
2561
|
+
])) return "X25519";
|
|
2562
|
+
if (!bytesEqual(algOid, [
|
|
2563
|
+
42,
|
|
2564
|
+
134,
|
|
2565
|
+
72,
|
|
2566
|
+
206,
|
|
2567
|
+
61,
|
|
2568
|
+
2,
|
|
2569
|
+
1
|
|
2570
|
+
])) throw new Error("Unsupported key algorithm");
|
|
2571
|
+
expectTag(state, 6, "Expected curve OID");
|
|
2572
|
+
const curveOid = getSubarray(state, parseLength(state));
|
|
2573
|
+
for (const { name, oid } of [
|
|
2574
|
+
{
|
|
2575
|
+
name: "P-256",
|
|
2576
|
+
oid: [
|
|
2577
|
+
42,
|
|
2578
|
+
134,
|
|
2579
|
+
72,
|
|
2580
|
+
206,
|
|
2581
|
+
61,
|
|
2582
|
+
3,
|
|
2583
|
+
1,
|
|
2584
|
+
7
|
|
2585
|
+
]
|
|
2586
|
+
},
|
|
2587
|
+
{
|
|
2588
|
+
name: "P-384",
|
|
2589
|
+
oid: [
|
|
2590
|
+
43,
|
|
2591
|
+
129,
|
|
2592
|
+
4,
|
|
2593
|
+
0,
|
|
2594
|
+
34
|
|
2595
|
+
]
|
|
2596
|
+
},
|
|
2597
|
+
{
|
|
2598
|
+
name: "P-521",
|
|
2599
|
+
oid: [
|
|
2600
|
+
43,
|
|
2601
|
+
129,
|
|
2602
|
+
4,
|
|
2603
|
+
0,
|
|
2604
|
+
35
|
|
2605
|
+
]
|
|
2606
|
+
}
|
|
2607
|
+
]) if (bytesEqual(curveOid, oid)) return name;
|
|
2608
|
+
throw new Error("Unsupported named curve");
|
|
2609
|
+
};
|
|
2610
|
+
const genericImport = async (keyFormat, keyData, alg, options) => {
|
|
2611
|
+
let algorithm;
|
|
2612
|
+
let keyUsages;
|
|
2613
|
+
const isPublic = keyFormat === "spki";
|
|
2614
|
+
const getSigUsages = () => isPublic ? ["verify"] : ["sign"];
|
|
2615
|
+
const getEncUsages = () => isPublic ? ["encrypt", "wrapKey"] : ["decrypt", "unwrapKey"];
|
|
2616
|
+
switch (alg) {
|
|
2617
|
+
case "PS256":
|
|
2618
|
+
case "PS384":
|
|
2619
|
+
case "PS512":
|
|
2620
|
+
algorithm = {
|
|
2621
|
+
name: "RSA-PSS",
|
|
2622
|
+
hash: `SHA-${alg.slice(-3)}`
|
|
2623
|
+
};
|
|
2624
|
+
keyUsages = getSigUsages();
|
|
2625
|
+
break;
|
|
2626
|
+
case "RS256":
|
|
2627
|
+
case "RS384":
|
|
2628
|
+
case "RS512":
|
|
2629
|
+
algorithm = {
|
|
2630
|
+
name: "RSASSA-PKCS1-v1_5",
|
|
2631
|
+
hash: `SHA-${alg.slice(-3)}`
|
|
2632
|
+
};
|
|
2633
|
+
keyUsages = getSigUsages();
|
|
2634
|
+
break;
|
|
2635
|
+
case "RSA-OAEP":
|
|
2636
|
+
case "RSA-OAEP-256":
|
|
2637
|
+
case "RSA-OAEP-384":
|
|
2638
|
+
case "RSA-OAEP-512":
|
|
2639
|
+
algorithm = {
|
|
2640
|
+
name: "RSA-OAEP",
|
|
2641
|
+
hash: `SHA-${parseInt(alg.slice(-3), 10) || 1}`
|
|
2642
|
+
};
|
|
2643
|
+
keyUsages = getEncUsages();
|
|
2644
|
+
break;
|
|
2645
|
+
case "ES256":
|
|
2646
|
+
case "ES384":
|
|
2647
|
+
case "ES512":
|
|
2648
|
+
algorithm = {
|
|
2649
|
+
name: "ECDSA",
|
|
2650
|
+
namedCurve: {
|
|
2651
|
+
ES256: "P-256",
|
|
2652
|
+
ES384: "P-384",
|
|
2653
|
+
ES512: "P-521"
|
|
2654
|
+
}[alg]
|
|
2655
|
+
};
|
|
2656
|
+
keyUsages = getSigUsages();
|
|
2657
|
+
break;
|
|
2658
|
+
case "ECDH-ES":
|
|
2659
|
+
case "ECDH-ES+A128KW":
|
|
2660
|
+
case "ECDH-ES+A192KW":
|
|
2661
|
+
case "ECDH-ES+A256KW":
|
|
2662
|
+
try {
|
|
2663
|
+
const namedCurve = options.getNamedCurve(keyData);
|
|
2664
|
+
algorithm = namedCurve === "X25519" ? { name: "X25519" } : {
|
|
2665
|
+
name: "ECDH",
|
|
2666
|
+
namedCurve
|
|
2667
|
+
};
|
|
2668
|
+
} catch (cause) {
|
|
2669
|
+
throw new JOSENotSupported("Invalid or unsupported key format");
|
|
2670
|
+
}
|
|
2671
|
+
keyUsages = isPublic ? [] : ["deriveBits"];
|
|
2672
|
+
break;
|
|
2673
|
+
case "Ed25519":
|
|
2674
|
+
case "EdDSA":
|
|
2675
|
+
algorithm = { name: "Ed25519" };
|
|
2676
|
+
keyUsages = getSigUsages();
|
|
2677
|
+
break;
|
|
2678
|
+
case "ML-DSA-44":
|
|
2679
|
+
case "ML-DSA-65":
|
|
2680
|
+
case "ML-DSA-87":
|
|
2681
|
+
algorithm = { name: alg };
|
|
2682
|
+
keyUsages = getSigUsages();
|
|
2683
|
+
break;
|
|
2684
|
+
default: throw new JOSENotSupported("Invalid or unsupported \"alg\" (Algorithm) value");
|
|
2685
|
+
}
|
|
2686
|
+
return crypto.subtle.importKey(keyFormat, keyData, algorithm, options?.extractable ?? (isPublic ? true : false), keyUsages);
|
|
2687
|
+
};
|
|
2688
|
+
const processPEMData = (pem, pattern) => {
|
|
2689
|
+
return decodeBase64(pem.replace(pattern, ""));
|
|
2690
|
+
};
|
|
2691
|
+
const fromPKCS8 = (pem, alg, options) => {
|
|
2692
|
+
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PRIVATE KEY-----|\s)/g);
|
|
2693
|
+
let opts = options;
|
|
2694
|
+
if (alg?.startsWith?.("ECDH-ES")) {
|
|
2695
|
+
opts ||= {};
|
|
2696
|
+
opts.getNamedCurve = (keyData) => {
|
|
2697
|
+
const state = createASN1State(keyData);
|
|
2698
|
+
parsePKCS8Header(state);
|
|
2699
|
+
return parseECAlgorithmIdentifier(state);
|
|
2700
|
+
};
|
|
2701
|
+
}
|
|
2702
|
+
return genericImport("pkcs8", keyData, alg, opts);
|
|
2703
|
+
};
|
|
2704
|
+
const fromSPKI = (pem, alg, options) => {
|
|
2705
|
+
const keyData = processPEMData(pem, /(?:-----(?:BEGIN|END) PUBLIC KEY-----|\s)/g);
|
|
2706
|
+
let opts = options;
|
|
2707
|
+
if (alg?.startsWith?.("ECDH-ES")) {
|
|
2708
|
+
opts ||= {};
|
|
2709
|
+
opts.getNamedCurve = (keyData) => {
|
|
2710
|
+
const state = createASN1State(keyData);
|
|
2711
|
+
parseSPKIHeader(state);
|
|
2712
|
+
return parseECAlgorithmIdentifier(state);
|
|
2713
|
+
};
|
|
2714
|
+
}
|
|
2715
|
+
return genericImport("spki", keyData, alg, opts);
|
|
2716
|
+
};
|
|
2717
|
+
//#endregion
|
|
2718
|
+
//#region ../../../../node_modules/jose/dist/webapi/key/import.js
|
|
2719
|
+
async function importSPKI(spki, alg, options) {
|
|
2720
|
+
if (typeof spki !== "string" || spki.indexOf("-----BEGIN PUBLIC KEY-----") !== 0) throw new TypeError("\"spki\" must be SPKI formatted string");
|
|
2721
|
+
return fromSPKI(spki, alg, options);
|
|
2722
|
+
}
|
|
2723
|
+
async function importPKCS8(pkcs8, alg, options) {
|
|
2724
|
+
if (typeof pkcs8 !== "string" || pkcs8.indexOf("-----BEGIN PRIVATE KEY-----") !== 0) throw new TypeError("\"pkcs8\" must be PKCS#8 formatted string");
|
|
2725
|
+
return fromPKCS8(pkcs8, alg, options);
|
|
2726
|
+
}
|
|
2727
|
+
//#endregion
|
|
2728
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/validate_crit.js
|
|
2729
|
+
function validateCrit(Err, recognizedDefault, recognizedOption, protectedHeader, joseHeader) {
|
|
2730
|
+
if (joseHeader.crit !== void 0 && protectedHeader?.crit === void 0) throw new Err("\"crit\" (Critical) Header Parameter MUST be integrity protected");
|
|
2731
|
+
if (!protectedHeader || protectedHeader.crit === void 0) return /* @__PURE__ */ new Set();
|
|
2732
|
+
if (!Array.isArray(protectedHeader.crit) || protectedHeader.crit.length === 0 || protectedHeader.crit.some((input) => typeof input !== "string" || input.length === 0)) throw new Err("\"crit\" (Critical) Header Parameter MUST be an array of non-empty strings when present");
|
|
2733
|
+
let recognized;
|
|
2734
|
+
if (recognizedOption !== void 0) recognized = new Map([...Object.entries(recognizedOption), ...recognizedDefault.entries()]);
|
|
2735
|
+
else recognized = recognizedDefault;
|
|
2736
|
+
for (const parameter of protectedHeader.crit) {
|
|
2737
|
+
if (!recognized.has(parameter)) throw new JOSENotSupported(`Extension Header Parameter "${parameter}" is not recognized`);
|
|
2738
|
+
if (joseHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" is missing`);
|
|
2739
|
+
if (recognized.get(parameter) && protectedHeader[parameter] === void 0) throw new Err(`Extension Header Parameter "${parameter}" MUST be integrity protected`);
|
|
2740
|
+
}
|
|
2741
|
+
return new Set(protectedHeader.crit);
|
|
2742
|
+
}
|
|
2743
|
+
//#endregion
|
|
2744
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/validate_algorithms.js
|
|
2745
|
+
function validateAlgorithms(option, algorithms) {
|
|
2746
|
+
if (algorithms !== void 0 && (!Array.isArray(algorithms) || algorithms.some((s) => typeof s !== "string"))) throw new TypeError(`"${option}" option must be an array of strings`);
|
|
2747
|
+
if (!algorithms) return;
|
|
2748
|
+
return new Set(algorithms);
|
|
2749
|
+
}
|
|
2750
|
+
//#endregion
|
|
2751
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/check_key_type.js
|
|
2752
|
+
const tag = (key) => key?.[Symbol.toStringTag];
|
|
2753
|
+
const jwkMatchesOp = (alg, key, usage) => {
|
|
2754
|
+
if (key.use !== void 0) {
|
|
2755
|
+
let expected;
|
|
2756
|
+
switch (usage) {
|
|
2757
|
+
case "sign":
|
|
2758
|
+
case "verify":
|
|
2759
|
+
expected = "sig";
|
|
2760
|
+
break;
|
|
2761
|
+
case "encrypt":
|
|
2762
|
+
case "decrypt":
|
|
2763
|
+
expected = "enc";
|
|
2764
|
+
break;
|
|
2765
|
+
}
|
|
2766
|
+
if (key.use !== expected) throw new TypeError(`Invalid key for this operation, its "use" must be "${expected}" when present`);
|
|
2767
|
+
}
|
|
2768
|
+
if (key.alg !== void 0 && key.alg !== alg) throw new TypeError(`Invalid key for this operation, its "alg" must be "${alg}" when present`);
|
|
2769
|
+
if (Array.isArray(key.key_ops)) {
|
|
2770
|
+
let expectedKeyOp;
|
|
2771
|
+
switch (true) {
|
|
2772
|
+
case usage === "sign" || usage === "verify":
|
|
2773
|
+
case alg === "dir":
|
|
2774
|
+
case alg.includes("CBC-HS"):
|
|
2775
|
+
expectedKeyOp = usage;
|
|
2776
|
+
break;
|
|
2777
|
+
case alg.startsWith("PBES2"):
|
|
2778
|
+
expectedKeyOp = "deriveBits";
|
|
2779
|
+
break;
|
|
2780
|
+
case /^A\d{3}(?:GCM)?(?:KW)?$/.test(alg):
|
|
2781
|
+
if (!alg.includes("GCM") && alg.endsWith("KW")) expectedKeyOp = usage === "encrypt" ? "wrapKey" : "unwrapKey";
|
|
2782
|
+
else expectedKeyOp = usage;
|
|
2783
|
+
break;
|
|
2784
|
+
case usage === "encrypt" && alg.startsWith("RSA"):
|
|
2785
|
+
expectedKeyOp = "wrapKey";
|
|
2786
|
+
break;
|
|
2787
|
+
case usage === "decrypt":
|
|
2788
|
+
expectedKeyOp = alg.startsWith("RSA") ? "unwrapKey" : "deriveBits";
|
|
2789
|
+
break;
|
|
2790
|
+
}
|
|
2791
|
+
if (expectedKeyOp && key.key_ops?.includes?.(expectedKeyOp) === false) throw new TypeError(`Invalid key for this operation, its "key_ops" must include "${expectedKeyOp}" when present`);
|
|
2792
|
+
}
|
|
2793
|
+
return true;
|
|
2794
|
+
};
|
|
2795
|
+
const symmetricTypeCheck = (alg, key, usage) => {
|
|
2796
|
+
if (key instanceof Uint8Array) return;
|
|
2797
|
+
if (isJWK(key)) {
|
|
2798
|
+
if (isSecretJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
2799
|
+
throw new TypeError(`JSON Web Key for symmetric algorithms must have JWK "kty" (Key Type) equal to "oct" and the JWK "k" (Key Value) present`);
|
|
2800
|
+
}
|
|
2801
|
+
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key", "Uint8Array"));
|
|
2802
|
+
if (key.type !== "secret") throw new TypeError(`${tag(key)} instances for symmetric algorithms must be of type "secret"`);
|
|
2803
|
+
};
|
|
2804
|
+
const asymmetricTypeCheck = (alg, key, usage) => {
|
|
2805
|
+
if (isJWK(key)) switch (usage) {
|
|
2806
|
+
case "decrypt":
|
|
2807
|
+
case "sign":
|
|
2808
|
+
if (isPrivateJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
2809
|
+
throw new TypeError(`JSON Web Key for this operation must be a private JWK`);
|
|
2810
|
+
case "encrypt":
|
|
2811
|
+
case "verify":
|
|
2812
|
+
if (isPublicJWK(key) && jwkMatchesOp(alg, key, usage)) return;
|
|
2813
|
+
throw new TypeError(`JSON Web Key for this operation must be a public JWK`);
|
|
2814
|
+
}
|
|
2815
|
+
if (!isKeyLike(key)) throw new TypeError(withAlg(alg, key, "CryptoKey", "KeyObject", "JSON Web Key"));
|
|
2816
|
+
if (key.type === "secret") throw new TypeError(`${tag(key)} instances for asymmetric algorithms must not be of type "secret"`);
|
|
2817
|
+
if (key.type === "public") switch (usage) {
|
|
2818
|
+
case "sign": throw new TypeError(`${tag(key)} instances for asymmetric algorithm signing must be of type "private"`);
|
|
2819
|
+
case "decrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm decryption must be of type "private"`);
|
|
2820
|
+
}
|
|
2821
|
+
if (key.type === "private") switch (usage) {
|
|
2822
|
+
case "verify": throw new TypeError(`${tag(key)} instances for asymmetric algorithm verifying must be of type "public"`);
|
|
2823
|
+
case "encrypt": throw new TypeError(`${tag(key)} instances for asymmetric algorithm encryption must be of type "public"`);
|
|
2824
|
+
}
|
|
2825
|
+
};
|
|
2826
|
+
function checkKeyType(alg, key, usage) {
|
|
2827
|
+
switch (alg.substring(0, 2)) {
|
|
2828
|
+
case "A1":
|
|
2829
|
+
case "A2":
|
|
2830
|
+
case "di":
|
|
2831
|
+
case "HS":
|
|
2832
|
+
case "PB":
|
|
2833
|
+
symmetricTypeCheck(alg, key, usage);
|
|
2834
|
+
break;
|
|
2835
|
+
default: asymmetricTypeCheck(alg, key, usage);
|
|
2836
|
+
}
|
|
2837
|
+
}
|
|
2838
|
+
//#endregion
|
|
2839
|
+
//#region ../../../../node_modules/jose/dist/webapi/jws/flattened/verify.js
|
|
2840
|
+
async function flattenedVerify(jws, key, options) {
|
|
2841
|
+
if (!isObject(jws)) throw new JWSInvalid("Flattened JWS must be an object");
|
|
2842
|
+
if (jws.protected === void 0 && jws.header === void 0) throw new JWSInvalid("Flattened JWS must have either of the \"protected\" or \"header\" members");
|
|
2843
|
+
if (jws.protected !== void 0 && typeof jws.protected !== "string") throw new JWSInvalid("JWS Protected Header incorrect type");
|
|
2844
|
+
if (jws.payload === void 0) throw new JWSInvalid("JWS Payload missing");
|
|
2845
|
+
if (typeof jws.signature !== "string") throw new JWSInvalid("JWS Signature missing or incorrect type");
|
|
2846
|
+
if (jws.header !== void 0 && !isObject(jws.header)) throw new JWSInvalid("JWS Unprotected Header incorrect type");
|
|
2847
|
+
let parsedProt = {};
|
|
2848
|
+
if (jws.protected) try {
|
|
2849
|
+
const protectedHeader = decode(jws.protected);
|
|
2850
|
+
parsedProt = JSON.parse(decoder.decode(protectedHeader));
|
|
2851
|
+
} catch {
|
|
2852
|
+
throw new JWSInvalid("JWS Protected Header is invalid");
|
|
2853
|
+
}
|
|
2854
|
+
if (!isDisjoint(parsedProt, jws.header)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
2855
|
+
const joseHeader = {
|
|
2856
|
+
...parsedProt,
|
|
2857
|
+
...jws.header
|
|
2858
|
+
};
|
|
2859
|
+
const extensions = validateCrit(JWSInvalid, new Map([["b64", true]]), options?.crit, parsedProt, joseHeader);
|
|
2860
|
+
let b64 = true;
|
|
2861
|
+
if (extensions.has("b64")) {
|
|
2862
|
+
b64 = parsedProt.b64;
|
|
2863
|
+
if (typeof b64 !== "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
|
|
2864
|
+
}
|
|
2865
|
+
const { alg } = joseHeader;
|
|
2866
|
+
if (typeof alg !== "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
2867
|
+
const algorithms = options && validateAlgorithms("algorithms", options.algorithms);
|
|
2868
|
+
if (algorithms && !algorithms.has(alg)) throw new JOSEAlgNotAllowed("\"alg\" (Algorithm) Header Parameter value not allowed");
|
|
2869
|
+
if (b64) {
|
|
2870
|
+
if (typeof jws.payload !== "string") throw new JWSInvalid("JWS Payload must be a string");
|
|
2871
|
+
} else if (typeof jws.payload !== "string" && !(jws.payload instanceof Uint8Array)) throw new JWSInvalid("JWS Payload must be a string or an Uint8Array instance");
|
|
2872
|
+
let resolvedKey = false;
|
|
2873
|
+
if (typeof key === "function") {
|
|
2874
|
+
key = await key(parsedProt, jws);
|
|
2875
|
+
resolvedKey = true;
|
|
2876
|
+
}
|
|
2877
|
+
checkKeyType(alg, key, "verify");
|
|
2878
|
+
const data = concat(jws.protected !== void 0 ? encode$1(jws.protected) : new Uint8Array(), encode$1("."), typeof jws.payload === "string" ? b64 ? encode$1(jws.payload) : encoder.encode(jws.payload) : jws.payload);
|
|
2879
|
+
const signature = decodeBase64url(jws.signature, "signature", JWSInvalid);
|
|
2880
|
+
const k = await normalizeKey(key, alg);
|
|
2881
|
+
if (!await verify(alg, k, signature, data)) throw new JWSSignatureVerificationFailed();
|
|
2882
|
+
let payload;
|
|
2883
|
+
if (b64) payload = decodeBase64url(jws.payload, "payload", JWSInvalid);
|
|
2884
|
+
else if (typeof jws.payload === "string") payload = encoder.encode(jws.payload);
|
|
2885
|
+
else payload = jws.payload;
|
|
2886
|
+
const result = { payload };
|
|
2887
|
+
if (jws.protected !== void 0) result.protectedHeader = parsedProt;
|
|
2888
|
+
if (jws.header !== void 0) result.unprotectedHeader = jws.header;
|
|
2889
|
+
if (resolvedKey) return {
|
|
2890
|
+
...result,
|
|
2891
|
+
key: k
|
|
2892
|
+
};
|
|
2893
|
+
return result;
|
|
2894
|
+
}
|
|
2895
|
+
//#endregion
|
|
2896
|
+
//#region ../../../../node_modules/jose/dist/webapi/jws/compact/verify.js
|
|
2897
|
+
async function compactVerify(jws, key, options) {
|
|
2898
|
+
if (jws instanceof Uint8Array) jws = decoder.decode(jws);
|
|
2899
|
+
if (typeof jws !== "string") throw new JWSInvalid("Compact JWS must be a string or Uint8Array");
|
|
2900
|
+
const { 0: protectedHeader, 1: payload, 2: signature, length } = jws.split(".");
|
|
2901
|
+
if (length !== 3) throw new JWSInvalid("Invalid Compact JWS");
|
|
2902
|
+
const verified = await flattenedVerify({
|
|
2903
|
+
payload,
|
|
2904
|
+
protected: protectedHeader,
|
|
2905
|
+
signature
|
|
2906
|
+
}, key, options);
|
|
2907
|
+
const result = {
|
|
2908
|
+
payload: verified.payload,
|
|
2909
|
+
protectedHeader: verified.protectedHeader
|
|
2910
|
+
};
|
|
2911
|
+
if (typeof key === "function") return {
|
|
2912
|
+
...result,
|
|
2913
|
+
key: verified.key
|
|
2914
|
+
};
|
|
2915
|
+
return result;
|
|
2916
|
+
}
|
|
2917
|
+
//#endregion
|
|
2918
|
+
//#region ../../../../node_modules/jose/dist/webapi/lib/jwt_claims_set.js
|
|
2919
|
+
const epoch = (date) => Math.floor(date.getTime() / 1e3);
|
|
2920
|
+
const minute = 60;
|
|
2921
|
+
const hour = minute * 60;
|
|
2922
|
+
const day = hour * 24;
|
|
2923
|
+
const week = day * 7;
|
|
2924
|
+
const year = day * 365.25;
|
|
2925
|
+
const REGEX = /^(\+|\-)? ?(\d+|\d+\.\d+) ?(seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)(?: (ago|from now))?$/i;
|
|
2926
|
+
function secs(str) {
|
|
2927
|
+
const matched = REGEX.exec(str);
|
|
2928
|
+
if (!matched || matched[4] && matched[1]) throw new TypeError("Invalid time period format");
|
|
2929
|
+
const value = parseFloat(matched[2]);
|
|
2930
|
+
const unit = matched[3].toLowerCase();
|
|
2931
|
+
let numericDate;
|
|
2932
|
+
switch (unit) {
|
|
2933
|
+
case "sec":
|
|
2934
|
+
case "secs":
|
|
2935
|
+
case "second":
|
|
2936
|
+
case "seconds":
|
|
2937
|
+
case "s":
|
|
2938
|
+
numericDate = Math.round(value);
|
|
2939
|
+
break;
|
|
2940
|
+
case "minute":
|
|
2941
|
+
case "minutes":
|
|
2942
|
+
case "min":
|
|
2943
|
+
case "mins":
|
|
2944
|
+
case "m":
|
|
2945
|
+
numericDate = Math.round(value * minute);
|
|
2946
|
+
break;
|
|
2947
|
+
case "hour":
|
|
2948
|
+
case "hours":
|
|
2949
|
+
case "hr":
|
|
2950
|
+
case "hrs":
|
|
2951
|
+
case "h":
|
|
2952
|
+
numericDate = Math.round(value * hour);
|
|
2953
|
+
break;
|
|
2954
|
+
case "day":
|
|
2955
|
+
case "days":
|
|
2956
|
+
case "d":
|
|
2957
|
+
numericDate = Math.round(value * day);
|
|
2958
|
+
break;
|
|
2959
|
+
case "week":
|
|
2960
|
+
case "weeks":
|
|
2961
|
+
case "w":
|
|
2962
|
+
numericDate = Math.round(value * week);
|
|
2963
|
+
break;
|
|
2964
|
+
default:
|
|
2965
|
+
numericDate = Math.round(value * year);
|
|
2966
|
+
break;
|
|
2967
|
+
}
|
|
2968
|
+
if (matched[1] === "-" || matched[4] === "ago") return -numericDate;
|
|
2969
|
+
return numericDate;
|
|
2970
|
+
}
|
|
2971
|
+
function validateInput(label, input) {
|
|
2972
|
+
if (!Number.isFinite(input)) throw new TypeError(`Invalid ${label} input`);
|
|
2973
|
+
return input;
|
|
2974
|
+
}
|
|
2975
|
+
const normalizeTyp = (value) => {
|
|
2976
|
+
if (value.includes("/")) return value.toLowerCase();
|
|
2977
|
+
return `application/${value.toLowerCase()}`;
|
|
2978
|
+
};
|
|
2979
|
+
const checkAudiencePresence = (audPayload, audOption) => {
|
|
2980
|
+
if (typeof audPayload === "string") return audOption.includes(audPayload);
|
|
2981
|
+
if (Array.isArray(audPayload)) return audOption.some(Set.prototype.has.bind(new Set(audPayload)));
|
|
2982
|
+
return false;
|
|
2983
|
+
};
|
|
2984
|
+
function validateClaimsSet(protectedHeader, encodedPayload, options = {}) {
|
|
2985
|
+
let payload;
|
|
2986
|
+
try {
|
|
2987
|
+
payload = JSON.parse(decoder.decode(encodedPayload));
|
|
2988
|
+
} catch {}
|
|
2989
|
+
if (!isObject(payload)) throw new JWTInvalid("JWT Claims Set must be a top-level JSON object");
|
|
2990
|
+
const { typ } = options;
|
|
2991
|
+
if (typ && (typeof protectedHeader.typ !== "string" || normalizeTyp(protectedHeader.typ) !== normalizeTyp(typ))) throw new JWTClaimValidationFailed("unexpected \"typ\" JWT header value", payload, "typ", "check_failed");
|
|
2992
|
+
const { requiredClaims = [], issuer, subject, audience, maxTokenAge } = options;
|
|
2993
|
+
const presenceCheck = [...requiredClaims];
|
|
2994
|
+
if (maxTokenAge !== void 0) presenceCheck.push("iat");
|
|
2995
|
+
if (audience !== void 0) presenceCheck.push("aud");
|
|
2996
|
+
if (subject !== void 0) presenceCheck.push("sub");
|
|
2997
|
+
if (issuer !== void 0) presenceCheck.push("iss");
|
|
2998
|
+
for (const claim of new Set(presenceCheck.reverse())) if (!(claim in payload)) throw new JWTClaimValidationFailed(`missing required "${claim}" claim`, payload, claim, "missing");
|
|
2999
|
+
if (issuer && !(Array.isArray(issuer) ? issuer : [issuer]).includes(payload.iss)) throw new JWTClaimValidationFailed("unexpected \"iss\" claim value", payload, "iss", "check_failed");
|
|
3000
|
+
if (subject && payload.sub !== subject) throw new JWTClaimValidationFailed("unexpected \"sub\" claim value", payload, "sub", "check_failed");
|
|
3001
|
+
if (audience && !checkAudiencePresence(payload.aud, typeof audience === "string" ? [audience] : audience)) throw new JWTClaimValidationFailed("unexpected \"aud\" claim value", payload, "aud", "check_failed");
|
|
3002
|
+
let tolerance;
|
|
3003
|
+
switch (typeof options.clockTolerance) {
|
|
3004
|
+
case "string":
|
|
3005
|
+
tolerance = secs(options.clockTolerance);
|
|
3006
|
+
break;
|
|
3007
|
+
case "number":
|
|
3008
|
+
tolerance = options.clockTolerance;
|
|
3009
|
+
break;
|
|
3010
|
+
case "undefined":
|
|
3011
|
+
tolerance = 0;
|
|
3012
|
+
break;
|
|
3013
|
+
default: throw new TypeError("Invalid clockTolerance option type");
|
|
3014
|
+
}
|
|
3015
|
+
const { currentDate } = options;
|
|
3016
|
+
const now = epoch(currentDate || /* @__PURE__ */ new Date());
|
|
3017
|
+
if ((payload.iat !== void 0 || maxTokenAge) && typeof payload.iat !== "number") throw new JWTClaimValidationFailed("\"iat\" claim must be a number", payload, "iat", "invalid");
|
|
3018
|
+
if (payload.nbf !== void 0) {
|
|
3019
|
+
if (typeof payload.nbf !== "number") throw new JWTClaimValidationFailed("\"nbf\" claim must be a number", payload, "nbf", "invalid");
|
|
3020
|
+
if (payload.nbf > now + tolerance) throw new JWTClaimValidationFailed("\"nbf\" claim timestamp check failed", payload, "nbf", "check_failed");
|
|
3021
|
+
}
|
|
3022
|
+
if (payload.exp !== void 0) {
|
|
3023
|
+
if (typeof payload.exp !== "number") throw new JWTClaimValidationFailed("\"exp\" claim must be a number", payload, "exp", "invalid");
|
|
3024
|
+
if (payload.exp <= now - tolerance) throw new JWTExpired("\"exp\" claim timestamp check failed", payload, "exp", "check_failed");
|
|
3025
|
+
}
|
|
3026
|
+
if (maxTokenAge) {
|
|
3027
|
+
const age = now - payload.iat;
|
|
3028
|
+
const max = typeof maxTokenAge === "number" ? maxTokenAge : secs(maxTokenAge);
|
|
3029
|
+
if (age - tolerance > max) throw new JWTExpired("\"iat\" claim timestamp check failed (too far in the past)", payload, "iat", "check_failed");
|
|
3030
|
+
if (age < 0 - tolerance) throw new JWTClaimValidationFailed("\"iat\" claim timestamp check failed (it should be in the past)", payload, "iat", "check_failed");
|
|
3031
|
+
}
|
|
3032
|
+
return payload;
|
|
3033
|
+
}
|
|
3034
|
+
var JWTClaimsBuilder = class {
|
|
3035
|
+
#payload;
|
|
3036
|
+
constructor(payload) {
|
|
3037
|
+
if (!isObject(payload)) throw new TypeError("JWT Claims Set MUST be an object");
|
|
3038
|
+
this.#payload = structuredClone(payload);
|
|
3039
|
+
}
|
|
3040
|
+
data() {
|
|
3041
|
+
return encoder.encode(JSON.stringify(this.#payload));
|
|
3042
|
+
}
|
|
3043
|
+
get iss() {
|
|
3044
|
+
return this.#payload.iss;
|
|
3045
|
+
}
|
|
3046
|
+
set iss(value) {
|
|
3047
|
+
this.#payload.iss = value;
|
|
3048
|
+
}
|
|
3049
|
+
get sub() {
|
|
3050
|
+
return this.#payload.sub;
|
|
3051
|
+
}
|
|
3052
|
+
set sub(value) {
|
|
3053
|
+
this.#payload.sub = value;
|
|
3054
|
+
}
|
|
3055
|
+
get aud() {
|
|
3056
|
+
return this.#payload.aud;
|
|
3057
|
+
}
|
|
3058
|
+
set aud(value) {
|
|
3059
|
+
this.#payload.aud = value;
|
|
3060
|
+
}
|
|
3061
|
+
set jti(value) {
|
|
3062
|
+
this.#payload.jti = value;
|
|
3063
|
+
}
|
|
3064
|
+
set nbf(value) {
|
|
3065
|
+
if (typeof value === "number") this.#payload.nbf = validateInput("setNotBefore", value);
|
|
3066
|
+
else if (value instanceof Date) this.#payload.nbf = validateInput("setNotBefore", epoch(value));
|
|
3067
|
+
else this.#payload.nbf = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
3068
|
+
}
|
|
3069
|
+
set exp(value) {
|
|
3070
|
+
if (typeof value === "number") this.#payload.exp = validateInput("setExpirationTime", value);
|
|
3071
|
+
else if (value instanceof Date) this.#payload.exp = validateInput("setExpirationTime", epoch(value));
|
|
3072
|
+
else this.#payload.exp = epoch(/* @__PURE__ */ new Date()) + secs(value);
|
|
3073
|
+
}
|
|
3074
|
+
set iat(value) {
|
|
3075
|
+
if (value === void 0) this.#payload.iat = epoch(/* @__PURE__ */ new Date());
|
|
3076
|
+
else if (value instanceof Date) this.#payload.iat = validateInput("setIssuedAt", epoch(value));
|
|
3077
|
+
else if (typeof value === "string") this.#payload.iat = validateInput("setIssuedAt", epoch(/* @__PURE__ */ new Date()) + secs(value));
|
|
3078
|
+
else this.#payload.iat = validateInput("setIssuedAt", value);
|
|
3079
|
+
}
|
|
3080
|
+
};
|
|
3081
|
+
//#endregion
|
|
3082
|
+
//#region ../../../../node_modules/jose/dist/webapi/jwt/verify.js
|
|
3083
|
+
async function jwtVerify(jwt, key, options) {
|
|
3084
|
+
const verified = await compactVerify(jwt, key, options);
|
|
3085
|
+
if (verified.protectedHeader.crit?.includes("b64") && verified.protectedHeader.b64 === false) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
3086
|
+
const result = {
|
|
3087
|
+
payload: validateClaimsSet(verified.protectedHeader, verified.payload, options),
|
|
3088
|
+
protectedHeader: verified.protectedHeader
|
|
3089
|
+
};
|
|
3090
|
+
if (typeof key === "function") return {
|
|
3091
|
+
...result,
|
|
3092
|
+
key: verified.key
|
|
3093
|
+
};
|
|
3094
|
+
return result;
|
|
3095
|
+
}
|
|
3096
|
+
//#endregion
|
|
3097
|
+
//#region ../../../../node_modules/jose/dist/webapi/jws/flattened/sign.js
|
|
3098
|
+
var FlattenedSign = class {
|
|
3099
|
+
#payload;
|
|
3100
|
+
#protectedHeader;
|
|
3101
|
+
#unprotectedHeader;
|
|
3102
|
+
constructor(payload) {
|
|
3103
|
+
if (!(payload instanceof Uint8Array)) throw new TypeError("payload must be an instance of Uint8Array");
|
|
3104
|
+
this.#payload = payload;
|
|
3105
|
+
}
|
|
3106
|
+
setProtectedHeader(protectedHeader) {
|
|
3107
|
+
assertNotSet(this.#protectedHeader, "setProtectedHeader");
|
|
3108
|
+
this.#protectedHeader = protectedHeader;
|
|
3109
|
+
return this;
|
|
3110
|
+
}
|
|
3111
|
+
setUnprotectedHeader(unprotectedHeader) {
|
|
3112
|
+
assertNotSet(this.#unprotectedHeader, "setUnprotectedHeader");
|
|
3113
|
+
this.#unprotectedHeader = unprotectedHeader;
|
|
3114
|
+
return this;
|
|
3115
|
+
}
|
|
3116
|
+
async sign(key, options) {
|
|
3117
|
+
if (!this.#protectedHeader && !this.#unprotectedHeader) throw new JWSInvalid("either setProtectedHeader or setUnprotectedHeader must be called before #sign()");
|
|
3118
|
+
if (!isDisjoint(this.#protectedHeader, this.#unprotectedHeader)) throw new JWSInvalid("JWS Protected and JWS Unprotected Header Parameter names must be disjoint");
|
|
3119
|
+
const joseHeader = {
|
|
3120
|
+
...this.#protectedHeader,
|
|
3121
|
+
...this.#unprotectedHeader
|
|
3122
|
+
};
|
|
3123
|
+
const extensions = validateCrit(JWSInvalid, new Map([["b64", true]]), options?.crit, this.#protectedHeader, joseHeader);
|
|
3124
|
+
let b64 = true;
|
|
3125
|
+
if (extensions.has("b64")) {
|
|
3126
|
+
b64 = this.#protectedHeader.b64;
|
|
3127
|
+
if (typeof b64 !== "boolean") throw new JWSInvalid("The \"b64\" (base64url-encode payload) Header Parameter must be a boolean");
|
|
3128
|
+
}
|
|
3129
|
+
const { alg } = joseHeader;
|
|
3130
|
+
if (typeof alg !== "string" || !alg) throw new JWSInvalid("JWS \"alg\" (Algorithm) Header Parameter missing or invalid");
|
|
3131
|
+
checkKeyType(alg, key, "sign");
|
|
3132
|
+
let payloadS;
|
|
3133
|
+
let payloadB;
|
|
3134
|
+
if (b64) {
|
|
3135
|
+
payloadS = encode(this.#payload);
|
|
3136
|
+
payloadB = encode$1(payloadS);
|
|
3137
|
+
} else {
|
|
3138
|
+
payloadB = this.#payload;
|
|
3139
|
+
payloadS = "";
|
|
3140
|
+
}
|
|
3141
|
+
let protectedHeaderString;
|
|
3142
|
+
let protectedHeaderBytes;
|
|
3143
|
+
if (this.#protectedHeader) {
|
|
3144
|
+
protectedHeaderString = encode(JSON.stringify(this.#protectedHeader));
|
|
3145
|
+
protectedHeaderBytes = encode$1(protectedHeaderString);
|
|
3146
|
+
} else {
|
|
3147
|
+
protectedHeaderString = "";
|
|
3148
|
+
protectedHeaderBytes = new Uint8Array();
|
|
3149
|
+
}
|
|
3150
|
+
const data = concat(protectedHeaderBytes, encode$1("."), payloadB);
|
|
3151
|
+
const jws = {
|
|
3152
|
+
signature: encode(await sign(alg, await normalizeKey(key, alg), data)),
|
|
3153
|
+
payload: payloadS
|
|
3154
|
+
};
|
|
3155
|
+
if (this.#unprotectedHeader) jws.header = this.#unprotectedHeader;
|
|
3156
|
+
if (this.#protectedHeader) jws.protected = protectedHeaderString;
|
|
3157
|
+
return jws;
|
|
3158
|
+
}
|
|
3159
|
+
};
|
|
3160
|
+
//#endregion
|
|
3161
|
+
//#region ../../../../node_modules/jose/dist/webapi/jws/compact/sign.js
|
|
3162
|
+
var CompactSign = class {
|
|
3163
|
+
#flattened;
|
|
3164
|
+
constructor(payload) {
|
|
3165
|
+
this.#flattened = new FlattenedSign(payload);
|
|
3166
|
+
}
|
|
3167
|
+
setProtectedHeader(protectedHeader) {
|
|
3168
|
+
this.#flattened.setProtectedHeader(protectedHeader);
|
|
3169
|
+
return this;
|
|
3170
|
+
}
|
|
3171
|
+
async sign(key, options) {
|
|
3172
|
+
const jws = await this.#flattened.sign(key, options);
|
|
3173
|
+
if (jws.payload === void 0) throw new TypeError("use the flattened module for creating JWS with b64: false");
|
|
3174
|
+
return `${jws.protected}.${jws.payload}.${jws.signature}`;
|
|
3175
|
+
}
|
|
3176
|
+
};
|
|
3177
|
+
//#endregion
|
|
3178
|
+
//#region ../../../../node_modules/jose/dist/webapi/jwt/sign.js
|
|
3179
|
+
var SignJWT = class {
|
|
3180
|
+
#protectedHeader;
|
|
3181
|
+
#jwt;
|
|
3182
|
+
constructor(payload = {}) {
|
|
3183
|
+
this.#jwt = new JWTClaimsBuilder(payload);
|
|
3184
|
+
}
|
|
3185
|
+
setIssuer(issuer) {
|
|
3186
|
+
this.#jwt.iss = issuer;
|
|
3187
|
+
return this;
|
|
3188
|
+
}
|
|
3189
|
+
setSubject(subject) {
|
|
3190
|
+
this.#jwt.sub = subject;
|
|
3191
|
+
return this;
|
|
3192
|
+
}
|
|
3193
|
+
setAudience(audience) {
|
|
3194
|
+
this.#jwt.aud = audience;
|
|
3195
|
+
return this;
|
|
3196
|
+
}
|
|
3197
|
+
setJti(jwtId) {
|
|
3198
|
+
this.#jwt.jti = jwtId;
|
|
3199
|
+
return this;
|
|
3200
|
+
}
|
|
3201
|
+
setNotBefore(input) {
|
|
3202
|
+
this.#jwt.nbf = input;
|
|
3203
|
+
return this;
|
|
3204
|
+
}
|
|
3205
|
+
setExpirationTime(input) {
|
|
3206
|
+
this.#jwt.exp = input;
|
|
3207
|
+
return this;
|
|
3208
|
+
}
|
|
3209
|
+
setIssuedAt(input) {
|
|
3210
|
+
this.#jwt.iat = input;
|
|
3211
|
+
return this;
|
|
3212
|
+
}
|
|
3213
|
+
setProtectedHeader(protectedHeader) {
|
|
3214
|
+
this.#protectedHeader = protectedHeader;
|
|
3215
|
+
return this;
|
|
3216
|
+
}
|
|
3217
|
+
async sign(key, options) {
|
|
3218
|
+
const sig = new CompactSign(this.#jwt.data());
|
|
3219
|
+
sig.setProtectedHeader(this.#protectedHeader);
|
|
3220
|
+
if (Array.isArray(this.#protectedHeader?.crit) && this.#protectedHeader.crit.includes("b64") && this.#protectedHeader.b64 === false) throw new JWTInvalid("JWTs MUST NOT use unencoded payload");
|
|
3221
|
+
return sig.sign(key, options);
|
|
3222
|
+
}
|
|
3223
|
+
};
|
|
3224
|
+
//#endregion
|
|
3225
|
+
//#region ../../src/server/auth/helpers/appleClientSecret.ts
|
|
3226
|
+
/** Signs Apple's short-lived ES256 client_secret JWT on demand (no rotation job). */
|
|
3227
|
+
async function signAppleClientSecret(opts) {
|
|
3228
|
+
const key = await importPKCS8(opts.privateKeyPem, "ES256");
|
|
3229
|
+
return new SignJWT({}).setProtectedHeader({
|
|
3230
|
+
alg: "ES256",
|
|
3231
|
+
kid: opts.keyId,
|
|
3232
|
+
typ: "JWT"
|
|
3233
|
+
}).setIssuer(opts.teamId).setSubject(opts.serviceId).setAudience("https://appleid.apple.com").setIssuedAt().setExpirationTime(`${opts.ttlSeconds ?? 300}s`).sign(key);
|
|
3234
|
+
}
|
|
3235
|
+
//#endregion
|
|
3236
|
+
//#region ../../src/server/auth/helpers/federationAssertion.ts
|
|
3237
|
+
const ALG = "EdDSA";
|
|
3238
|
+
async function signFederationAssertion(profile, opts) {
|
|
3239
|
+
const key = await importPKCS8(opts.privateKeyPem, ALG);
|
|
3240
|
+
const jti = opts.jti ?? crypto.randomUUID();
|
|
3241
|
+
const ttl = opts.ttlSeconds ?? 60;
|
|
3242
|
+
return new SignJWT({ profile }).setProtectedHeader({
|
|
3243
|
+
alg: ALG,
|
|
3244
|
+
typ: "JWT"
|
|
3245
|
+
}).setIssuer(opts.issuer).setAudience(opts.audience).setJti(jti).setIssuedAt().setExpirationTime(`${ttl}s`).sign(key);
|
|
3246
|
+
}
|
|
3247
|
+
async function verifyFederationAssertion(token, opts) {
|
|
3248
|
+
const { payload } = await jwtVerify(token, await importSPKI(opts.publicKeyPem, ALG), {
|
|
3249
|
+
issuer: opts.issuer,
|
|
3250
|
+
audience: opts.audience,
|
|
3251
|
+
algorithms: [ALG],
|
|
3252
|
+
requiredClaims: [
|
|
3253
|
+
"exp",
|
|
3254
|
+
"iat",
|
|
3255
|
+
"jti"
|
|
3256
|
+
]
|
|
3257
|
+
});
|
|
3258
|
+
const profile = payload.profile;
|
|
3259
|
+
if (!profile?.sub || !profile.provider) throw new Error("Federation assertion missing profile.sub/provider");
|
|
3260
|
+
if (!payload.jti) throw new Error("Federation assertion missing jti");
|
|
3261
|
+
return {
|
|
3262
|
+
profile,
|
|
3263
|
+
jti: String(payload.jti)
|
|
3264
|
+
};
|
|
3265
|
+
}
|
|
3266
|
+
//#endregion
|
|
1928
3267
|
//#region ../../src/server/auth/schemas/authenticationProviderSchema.ts
|
|
1929
3268
|
const authenticationProviderSchema = t.object({
|
|
1930
3269
|
name: t.text({ description: "Name of the authentication provider." }),
|
|
@@ -2075,6 +3414,260 @@ const $authFacebook = (realm, options = {}) => {
|
|
|
2075
3414
|
});
|
|
2076
3415
|
};
|
|
2077
3416
|
//#endregion
|
|
3417
|
+
//#region ../../src/server/auth/helpers/safeRedirectPath.ts
|
|
3418
|
+
/**
|
|
3419
|
+
* Returns a safe in-app redirect target: a single absolute path on the current
|
|
3420
|
+
* origin. Rejects protocol-relative (`//host`), absolute URLs, and backslash
|
|
3421
|
+
* tricks so a crafted `redirect` query can't become a post-auth open redirect.
|
|
3422
|
+
*/
|
|
3423
|
+
function safeRedirectPath(redirect, fallback = "/") {
|
|
3424
|
+
if (typeof redirect === "string" && redirect.startsWith("/") && !redirect.startsWith("//") && !redirect.includes("\\")) return redirect;
|
|
3425
|
+
return fallback;
|
|
3426
|
+
}
|
|
3427
|
+
//#endregion
|
|
3428
|
+
//#region ../../src/server/auth/primitives/$authFederationBroker.ts
|
|
3429
|
+
const ISSUERS = {
|
|
3430
|
+
google: "https://accounts.google.com",
|
|
3431
|
+
apple: "https://appleid.apple.com"
|
|
3432
|
+
};
|
|
3433
|
+
const $authFederationBroker = (options) => {
|
|
3434
|
+
const callbackPath = "/auth/federated/callback";
|
|
3435
|
+
if (!options.signingKeyPem) throw new AlephaError("$authFederationBroker requires signingKeyPem");
|
|
3436
|
+
const flow = $cookie({
|
|
3437
|
+
name: "federationFlow",
|
|
3438
|
+
ttl: [15, "minutes"],
|
|
3439
|
+
httpOnly: true,
|
|
3440
|
+
encrypt: true,
|
|
3441
|
+
schema: t.object({
|
|
3442
|
+
provider: t.text(),
|
|
3443
|
+
tenantOrigin: t.text({ size: "long" }),
|
|
3444
|
+
redirectPath: t.text({ size: "long" }),
|
|
3445
|
+
codeVerifier: t.optional(t.text({ size: "long" })),
|
|
3446
|
+
state: t.optional(t.text()),
|
|
3447
|
+
nonce: t.optional(t.text())
|
|
3448
|
+
})
|
|
3449
|
+
});
|
|
3450
|
+
const callbackUri = `${options.issuer}${callbackPath}`;
|
|
3451
|
+
const getConfig = async (provider) => {
|
|
3452
|
+
if (provider === "google") {
|
|
3453
|
+
const g = options.providers.google;
|
|
3454
|
+
if (!g) throw new SecurityError("google federation not configured");
|
|
3455
|
+
return discovery(new URL(ISSUERS.google), g.clientId, g.clientSecret);
|
|
3456
|
+
}
|
|
3457
|
+
const a = options.providers.apple;
|
|
3458
|
+
if (!a) throw new SecurityError("apple federation not configured");
|
|
3459
|
+
const clientSecret = await signAppleClientSecret({
|
|
3460
|
+
privateKeyPem: a.privateKeyPem,
|
|
3461
|
+
teamId: a.teamId,
|
|
3462
|
+
serviceId: a.serviceId,
|
|
3463
|
+
keyId: a.keyId
|
|
3464
|
+
});
|
|
3465
|
+
return discovery(new URL(ISSUERS.apple), a.serviceId, clientSecret);
|
|
3466
|
+
};
|
|
3467
|
+
const scopeFor = (provider) => provider === "apple" ? "name email" : "openid email profile";
|
|
3468
|
+
const start = $route({
|
|
3469
|
+
path: "/auth/federated/start",
|
|
3470
|
+
schema: { query: t.object({
|
|
3471
|
+
provider: t.text(),
|
|
3472
|
+
tenant: t.text(),
|
|
3473
|
+
redirect: t.optional(t.text({ size: "long" }))
|
|
3474
|
+
}) },
|
|
3475
|
+
handler: async ({ query, reply, cookies }) => {
|
|
3476
|
+
if (query.provider !== "google" && query.provider !== "apple") throw new BadRequestError(`Unsupported provider '${query.provider}'`);
|
|
3477
|
+
const tenantOrigin = await options.resolveTenant(query.tenant);
|
|
3478
|
+
if (!tenantOrigin) throw new BadRequestError("Unknown or inactive tenant");
|
|
3479
|
+
const config = await getConfig(query.provider);
|
|
3480
|
+
const codeVerifier = randomPKCECodeVerifier();
|
|
3481
|
+
const codeChallenge = await calculatePKCECodeChallenge(codeVerifier);
|
|
3482
|
+
const parameters = {
|
|
3483
|
+
redirect_uri: callbackUri,
|
|
3484
|
+
scope: scopeFor(query.provider),
|
|
3485
|
+
code_challenge: codeChallenge,
|
|
3486
|
+
code_challenge_method: "S256"
|
|
3487
|
+
};
|
|
3488
|
+
if (query.provider === "apple") parameters.response_mode = "form_post";
|
|
3489
|
+
const usePkce = config.serverMetadata().supportsPKCE();
|
|
3490
|
+
let state;
|
|
3491
|
+
let nonce;
|
|
3492
|
+
if (!usePkce) {
|
|
3493
|
+
state = randomState();
|
|
3494
|
+
nonce = randomState();
|
|
3495
|
+
parameters.state = state;
|
|
3496
|
+
parameters.nonce = nonce;
|
|
3497
|
+
delete parameters.code_challenge;
|
|
3498
|
+
delete parameters.code_challenge_method;
|
|
3499
|
+
}
|
|
3500
|
+
flow.set({
|
|
3501
|
+
provider: query.provider,
|
|
3502
|
+
tenantOrigin,
|
|
3503
|
+
redirectPath: safeRedirectPath(query.redirect),
|
|
3504
|
+
codeVerifier: usePkce ? codeVerifier : void 0,
|
|
3505
|
+
state,
|
|
3506
|
+
nonce
|
|
3507
|
+
}, { cookies });
|
|
3508
|
+
reply.redirect(buildAuthorizationUrl(config, parameters).toString(), 302);
|
|
3509
|
+
}
|
|
3510
|
+
});
|
|
3511
|
+
const handle = async (urlOrReq, cookies, reply, rawProfile) => {
|
|
3512
|
+
const ctx = flow.get({ cookies });
|
|
3513
|
+
if (!ctx) throw new BadRequestError("Missing federation flow");
|
|
3514
|
+
flow.del({ cookies });
|
|
3515
|
+
const provider = ctx.provider;
|
|
3516
|
+
let profile;
|
|
3517
|
+
try {
|
|
3518
|
+
const claims = (await authorizationCodeGrant(await getConfig(provider), urlOrReq, {
|
|
3519
|
+
pkceCodeVerifier: ctx.codeVerifier,
|
|
3520
|
+
expectedState: ctx.state,
|
|
3521
|
+
expectedNonce: ctx.nonce
|
|
3522
|
+
})).claims?.() ?? {};
|
|
3523
|
+
const merged = {
|
|
3524
|
+
...rawProfile,
|
|
3525
|
+
...claims
|
|
3526
|
+
};
|
|
3527
|
+
profile = {
|
|
3528
|
+
provider,
|
|
3529
|
+
sub: String(merged.sub),
|
|
3530
|
+
email: merged.email,
|
|
3531
|
+
email_verified: typeof merged.email_verified === "string" ? merged.email_verified === "true" : merged.email_verified,
|
|
3532
|
+
name: merged.name,
|
|
3533
|
+
given_name: merged.given_name,
|
|
3534
|
+
family_name: merged.family_name,
|
|
3535
|
+
picture: merged.picture,
|
|
3536
|
+
is_private_email: typeof merged.is_private_email === "string" ? merged.is_private_email === "true" : merged.is_private_email
|
|
3537
|
+
};
|
|
3538
|
+
} catch {
|
|
3539
|
+
const fail = new URL(`${ctx.tenantOrigin}${ctx.redirectPath}`);
|
|
3540
|
+
fail.searchParams.set("error", "federation_failed");
|
|
3541
|
+
reply.redirect(fail.toString(), 302);
|
|
3542
|
+
return;
|
|
3543
|
+
}
|
|
3544
|
+
const assertion = await signFederationAssertion(profile, {
|
|
3545
|
+
privateKeyPem: options.signingKeyPem,
|
|
3546
|
+
issuer: options.issuer,
|
|
3547
|
+
audience: ctx.tenantOrigin,
|
|
3548
|
+
ttlSeconds: options.assertionTtlSeconds
|
|
3549
|
+
});
|
|
3550
|
+
const dest = new URL(`${ctx.tenantOrigin}/auth/federated/callback`);
|
|
3551
|
+
dest.searchParams.set("token", assertion);
|
|
3552
|
+
dest.searchParams.set("redirect", ctx.redirectPath);
|
|
3553
|
+
reply.redirect(dest.toString(), 302);
|
|
3554
|
+
};
|
|
3555
|
+
return {
|
|
3556
|
+
start,
|
|
3557
|
+
callback: $route({
|
|
3558
|
+
path: callbackPath,
|
|
3559
|
+
handler: async ({ url, reply, cookies }) => handle(url, cookies, reply)
|
|
3560
|
+
}),
|
|
3561
|
+
callbackPost: $route({
|
|
3562
|
+
path: callbackPath,
|
|
3563
|
+
method: "POST",
|
|
3564
|
+
handler: async ({ reply, cookies, raw }) => {
|
|
3565
|
+
let rawProfile;
|
|
3566
|
+
let req = raw?.web?.req;
|
|
3567
|
+
if (raw?.web?.req) {
|
|
3568
|
+
const cloned = raw.web.req.clone();
|
|
3569
|
+
req = raw.web.req;
|
|
3570
|
+
try {
|
|
3571
|
+
const userField = (await cloned.formData()).get("user");
|
|
3572
|
+
if (typeof userField === "string") {
|
|
3573
|
+
const parsed = JSON.parse(userField);
|
|
3574
|
+
rawProfile = {};
|
|
3575
|
+
if (parsed.name?.firstName) rawProfile.given_name = parsed.name.firstName;
|
|
3576
|
+
if (parsed.name?.lastName) rawProfile.family_name = parsed.name.lastName;
|
|
3577
|
+
if (parsed.name?.firstName || parsed.name?.lastName) rawProfile.name = [parsed.name?.firstName, parsed.name?.lastName].filter(Boolean).join(" ");
|
|
3578
|
+
if (parsed.email) rawProfile.email = parsed.email;
|
|
3579
|
+
}
|
|
3580
|
+
} catch {}
|
|
3581
|
+
}
|
|
3582
|
+
await handle(req, cookies, reply, rawProfile);
|
|
3583
|
+
}
|
|
3584
|
+
})
|
|
3585
|
+
};
|
|
3586
|
+
};
|
|
3587
|
+
//#endregion
|
|
3588
|
+
//#region ../../src/server/auth/helpers/jtiReplayGuard.ts
|
|
3589
|
+
/**
|
|
3590
|
+
* Single-use guard for short-lived assertion `jti`s. Bounded + self-pruning so
|
|
3591
|
+
* it can't grow without limit in a long-lived process. Best-effort per-instance
|
|
3592
|
+
* (assertions are also `aud`-bound + ~60s TTL, so a cross-isolate replay window
|
|
3593
|
+
* is tiny); use a shared store if you need a hard cross-instance guarantee.
|
|
3594
|
+
*/
|
|
3595
|
+
var JtiReplayGuard = class {
|
|
3596
|
+
ttlMs;
|
|
3597
|
+
maxEntries;
|
|
3598
|
+
seen = /* @__PURE__ */ new Map();
|
|
3599
|
+
constructor(ttlMs = 12e4, maxEntries = 1e4) {
|
|
3600
|
+
this.ttlMs = ttlMs;
|
|
3601
|
+
this.maxEntries = maxEntries;
|
|
3602
|
+
}
|
|
3603
|
+
/** Records `jti` and returns true if fresh; false if already used (replay). */
|
|
3604
|
+
check(jti, now = Date.now()) {
|
|
3605
|
+
this.prune(now);
|
|
3606
|
+
if (this.seen.has(jti)) return false;
|
|
3607
|
+
this.seen.set(jti, now + this.ttlMs);
|
|
3608
|
+
return true;
|
|
3609
|
+
}
|
|
3610
|
+
prune(now) {
|
|
3611
|
+
for (const [k, exp] of this.seen) if (exp <= now) this.seen.delete(k);
|
|
3612
|
+
while (this.seen.size >= this.maxEntries) {
|
|
3613
|
+
const oldest = this.seen.keys().next().value;
|
|
3614
|
+
if (oldest === void 0) break;
|
|
3615
|
+
this.seen.delete(oldest);
|
|
3616
|
+
}
|
|
3617
|
+
}
|
|
3618
|
+
};
|
|
3619
|
+
//#endregion
|
|
3620
|
+
//#region ../../src/server/auth/primitives/$authFederationClient.ts
|
|
3621
|
+
async function assertionToProfile(token, opts) {
|
|
3622
|
+
const { profile, jti } = await verifyFederationAssertion(token, opts);
|
|
3623
|
+
return {
|
|
3624
|
+
provider: profile.provider,
|
|
3625
|
+
jti,
|
|
3626
|
+
link: {
|
|
3627
|
+
access_token: "",
|
|
3628
|
+
user: {
|
|
3629
|
+
sub: profile.sub,
|
|
3630
|
+
email: profile.email,
|
|
3631
|
+
email_verified: profile.email_verified,
|
|
3632
|
+
name: profile.name,
|
|
3633
|
+
given_name: profile.given_name,
|
|
3634
|
+
family_name: profile.family_name,
|
|
3635
|
+
picture: profile.picture
|
|
3636
|
+
}
|
|
3637
|
+
}
|
|
3638
|
+
};
|
|
3639
|
+
}
|
|
3640
|
+
const $authFederationClient = (options) => {
|
|
3641
|
+
const { alepha } = $context();
|
|
3642
|
+
const replay = new JtiReplayGuard();
|
|
3643
|
+
return { callback: $route({
|
|
3644
|
+
path: "/auth/federated/callback",
|
|
3645
|
+
schema: { query: t.object({
|
|
3646
|
+
token: t.text({ size: "rich" }),
|
|
3647
|
+
redirect: t.optional(t.text({ size: "long" }))
|
|
3648
|
+
}) },
|
|
3649
|
+
handler: async ({ query, url, reply, cookies }) => {
|
|
3650
|
+
const serverAuth = alepha.inject(ServerAuthProvider);
|
|
3651
|
+
const audience = options.selfOrigin ?? `${url.protocol}//${url.host}`;
|
|
3652
|
+
try {
|
|
3653
|
+
const { provider, jti, link } = await assertionToProfile(query.token, {
|
|
3654
|
+
publicKeyPem: options.publicKeyPem,
|
|
3655
|
+
issuer: options.brokerUrl,
|
|
3656
|
+
audience
|
|
3657
|
+
});
|
|
3658
|
+
if (!replay.check(jti)) throw new BadRequestError("Assertion already used");
|
|
3659
|
+
if (!options.realm.link) throw new BadRequestError("Realm has no link function");
|
|
3660
|
+
const user = await options.realm.link(provider)(link);
|
|
3661
|
+
await serverAuth.establishSession(user, options.realm, provider, cookies);
|
|
3662
|
+
} catch {
|
|
3663
|
+
reply.redirect("/auth/login?error=federation_failed", 302);
|
|
3664
|
+
return;
|
|
3665
|
+
}
|
|
3666
|
+
reply.redirect(safeRedirectPath(query.redirect), 302);
|
|
3667
|
+
}
|
|
3668
|
+
}) };
|
|
3669
|
+
};
|
|
3670
|
+
//#endregion
|
|
2078
3671
|
//#region ../../src/server/auth/primitives/$authFranceConnect.ts
|
|
2079
3672
|
/**
|
|
2080
3673
|
* Creates an authentication provider primitive for France Connect.
|
|
@@ -2310,6 +3903,6 @@ const AlephaServerAuth = $module({
|
|
|
2310
3903
|
services: [AlephaServerCookies, ServerAuthProvider]
|
|
2311
3904
|
});
|
|
2312
3905
|
//#endregion
|
|
2313
|
-
export { $auth, $authApple, $authCredentials, $authFacebook, $authFranceConnect, $authGithub, $authGoogle, $authMicrosoft, AlephaServerAuth, AuthPrimitive, ServerAuthProvider, alephaServerAuthRoutes, authenticationProviderSchema, tokenResponseSchema, tokensSchema, userinfoResponseSchema };
|
|
3906
|
+
export { $auth, $authApple, $authCredentials, $authFacebook, $authFederationBroker, $authFederationClient, $authFranceConnect, $authGithub, $authGoogle, $authMicrosoft, AlephaServerAuth, AuthPrimitive, ServerAuthProvider, alephaServerAuthRoutes, assertionToProfile, authenticationProviderSchema, signAppleClientSecret, signFederationAssertion, tokenResponseSchema, tokensSchema, userinfoResponseSchema, verifyFederationAssertion };
|
|
2314
3907
|
|
|
2315
3908
|
//# sourceMappingURL=index.js.map
|