@owlmeans/auth 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (86) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +321 -0
  3. package/build/.gitkeep +0 -0
  4. package/build/allowance/index.d.ts +2 -0
  5. package/build/allowance/index.d.ts.map +1 -0
  6. package/build/allowance/index.js +2 -0
  7. package/build/allowance/index.js.map +1 -0
  8. package/build/allowance/model.d.ts +7 -0
  9. package/build/allowance/model.d.ts.map +1 -0
  10. package/build/allowance/model.js +57 -0
  11. package/build/allowance/model.js.map +1 -0
  12. package/build/auth/index.d.ts +2 -0
  13. package/build/auth/index.d.ts.map +1 -0
  14. package/build/auth/index.js +2 -0
  15. package/build/auth/index.js.map +1 -0
  16. package/build/auth/model.d.ts +8 -0
  17. package/build/auth/model.d.ts.map +1 -0
  18. package/build/auth/model.js +55 -0
  19. package/build/auth/model.js.map +1 -0
  20. package/build/consts.d.ts +69 -0
  21. package/build/consts.d.ts.map +1 -0
  22. package/build/consts.js +100 -0
  23. package/build/consts.js.map +1 -0
  24. package/build/entity/index.d.ts +2 -0
  25. package/build/entity/index.d.ts.map +1 -0
  26. package/build/entity/index.js +2 -0
  27. package/build/entity/index.js.map +1 -0
  28. package/build/entity/profile.d.ts +4 -0
  29. package/build/entity/profile.d.ts.map +1 -0
  30. package/build/entity/profile.js +21 -0
  31. package/build/entity/profile.js.map +1 -0
  32. package/build/errors.d.ts +54 -0
  33. package/build/errors.d.ts.map +1 -0
  34. package/build/errors.js +105 -0
  35. package/build/errors.js.map +1 -0
  36. package/build/helper.d.ts +7 -0
  37. package/build/helper.d.ts.map +1 -0
  38. package/build/helper.js +21 -0
  39. package/build/helper.js.map +1 -0
  40. package/build/index.d.ts +10 -0
  41. package/build/index.d.ts.map +1 -0
  42. package/build/index.js +9 -0
  43. package/build/index.js.map +1 -0
  44. package/build/permission/index.d.ts +2 -0
  45. package/build/permission/index.d.ts.map +1 -0
  46. package/build/permission/index.js +2 -0
  47. package/build/permission/index.js.map +1 -0
  48. package/build/permission/model.d.ts +6 -0
  49. package/build/permission/model.d.ts.map +1 -0
  50. package/build/permission/model.js +27 -0
  51. package/build/permission/model.js.map +1 -0
  52. package/build/rely/index.d.ts +3 -0
  53. package/build/rely/index.d.ts.map +1 -0
  54. package/build/rely/index.js +2 -0
  55. package/build/rely/index.js.map +1 -0
  56. package/build/rely/model.d.ts +4 -0
  57. package/build/rely/model.d.ts.map +1 -0
  58. package/build/rely/model.js +12 -0
  59. package/build/rely/model.js.map +1 -0
  60. package/build/rely/types.d.ts +7 -0
  61. package/build/rely/types.d.ts.map +1 -0
  62. package/build/rely/types.js +2 -0
  63. package/build/rely/types.js.map +1 -0
  64. package/build/types.d.ts +81 -0
  65. package/build/types.d.ts.map +1 -0
  66. package/build/types.js +2 -0
  67. package/build/types.js.map +1 -0
  68. package/package.json +38 -0
  69. package/src/allowance/index.ts +2 -0
  70. package/src/allowance/model.ts +65 -0
  71. package/src/auth/index.ts +2 -0
  72. package/src/auth/model.ts +64 -0
  73. package/src/consts.ts +121 -0
  74. package/src/entity/index.ts +2 -0
  75. package/src/entity/profile.ts +24 -0
  76. package/src/errors.ts +132 -0
  77. package/src/helper.ts +32 -0
  78. package/src/index.ts +10 -0
  79. package/src/permission/index.ts +2 -0
  80. package/src/permission/model.ts +31 -0
  81. package/src/rely/index.ts +3 -0
  82. package/src/rely/model.ts +14 -0
  83. package/src/rely/types.ts +7 -0
  84. package/src/types.ts +178 -0
  85. package/tsconfig.json +14 -0
  86. package/tsconfig.tsbuildinfo +1 -0
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2024 OwlMeans Common — Fullstack typescript framework
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,321 @@
1
+ # @owlmeans/auth
2
+
3
+ A comprehensive authentication and authorization library for OwlMeans Common applications. This package provides the foundational authentication subsystem that enables secure user management, credential validation, permission-based access control, and multi-role authorization across fullstack applications.
4
+
5
+ ## Overview
6
+
7
+ The `@owlmeans/auth` package is the core authentication library in the OwlMeans Common ecosystem, designed for fullstack applications with a focus on security and proper authentication/authorization patterns. It provides:
8
+
9
+ - **Multi-Role Authentication**: Support for users, guests, services, admins, and system-level authentication
10
+ - **Cryptographic Security**: Integration with digital signatures and advanced cryptographic methods
11
+ - **Permission-Based Authorization**: Granular permission and capability management
12
+ - **Profile Management**: User profile and group-based access control
13
+ - **Flexible Authentication Types**: Support for multiple authentication methods including Ed25519, one-time tokens, and wallet-based authentication
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install @owlmeans/auth
19
+ ```
20
+
21
+ ## Core Concepts
22
+
23
+ ### Authentication Types
24
+
25
+ The library supports various authentication methods through the `AuthenticationType` enum:
26
+
27
+ - **BasicEd25519**: Cryptographic authentication using Ed25519 signatures
28
+ - **OneTimeToken**: Temporary token-based authentication
29
+ - **ReCaptcha**: CAPTCHA-based verification
30
+ - **WalletDid**: Decentralized identity wallet authentication
31
+ - **RelyHandshake**: Internal cross-authentication for wallet connections
32
+ - **WalletConsumer**: Client-side wallet authentication
33
+ - **WalletProvider**: Provider-side wallet authentication
34
+
35
+ ### Authorization Types
36
+
37
+ Authorization is handled through the `AuthroizationType` enum:
38
+
39
+ - **AuthToken**: Classic bearer token authorization
40
+ - **Ed25519BasicToken**: OwlMeans' primary authorization token
41
+ - **Ed25519BasicSignature**: Signature-based authorization
42
+
43
+ ### User Roles
44
+
45
+ The system supports hierarchical roles via the `AuthRole` enum:
46
+
47
+ - **Guest**: Unauthenticated users with limited access
48
+ - **User**: Authenticated regular users
49
+ - **Service**: Service-to-service authentication
50
+ - **Admin**: Administrative users with elevated privileges
51
+ - **Superuser**: Highest privilege level
52
+ - **System**: System-level processes
53
+ - **Blocked**: Restricted/banned users
54
+
55
+ ## API Reference
56
+
57
+ ### Types
58
+
59
+ #### `AuthCredentials`
60
+ Contains authentication challenge and credential information.
61
+
62
+ ```typescript
63
+ interface AuthCredentials extends AuthPayload {
64
+ challenge: string
65
+ credential: string
66
+ publicKey?: string
67
+ }
68
+ ```
69
+
70
+ #### `AuthPayload`
71
+ Core authentication payload with user and authorization data.
72
+
73
+ ```typescript
74
+ interface AuthPayload extends ProfilePayload {
75
+ type: string
76
+ role: AuthRole
77
+ userId: string
78
+ source?: string
79
+ profileId?: string
80
+ expiresAt?: Date
81
+ }
82
+ ```
83
+
84
+ #### `Auth`
85
+ Complete authentication object with token and metadata.
86
+
87
+ ```typescript
88
+ interface Auth extends AuthPayload {
89
+ token: string
90
+ isUser: boolean
91
+ createdAt: Date
92
+ }
93
+ ```
94
+
95
+ #### `Profile`
96
+ User profile with permissions and group membership.
97
+
98
+ ```typescript
99
+ interface Profile extends ProfilePayload {
100
+ id: string
101
+ name: string
102
+ credential?: string
103
+ secret?: string
104
+ }
105
+ ```
106
+
107
+ #### `Authorization`
108
+ Permission and capability structure for access control.
109
+
110
+ ```typescript
111
+ interface Authorization {
112
+ entityId?: string
113
+ scopes: string[]
114
+ permissions?: PermissionSet[]
115
+ attributes?: AttributeSet[]
116
+ permissioned?: boolean
117
+ denormalized?: boolean
118
+ }
119
+ ```
120
+
121
+ #### `PermissionSet`
122
+ Defines capabilities within a specific scope.
123
+
124
+ ```typescript
125
+ interface PermissionSet {
126
+ scope: string
127
+ title?: string
128
+ permissions: Capabilties
129
+ resources?: string[]
130
+ }
131
+ ```
132
+
133
+ ### Helper Functions
134
+
135
+ #### `verifyAuth(auth: Auth): boolean`
136
+ Validates an authentication object against the defined schema.
137
+
138
+ #### `verifyAuthCredentials(auth: AuthCredentials): boolean`
139
+ Validates authentication credentials against the defined schema.
140
+
141
+ #### `isAuth(auth: unknown): auth is Auth`
142
+ Type guard to check if an object is a valid Auth instance.
143
+
144
+ #### `isAuthCredentials(auth: unknown): auth is AuthCredentials`
145
+ Type guard to check if an object is valid AuthCredentials.
146
+
147
+ #### `isAuthToken(auth: unknown): auth is AuthToken`
148
+ Type guard to check if an object is a valid AuthToken.
149
+
150
+ ### Constants
151
+
152
+ #### Authentication Scopes
153
+ - `ALL_SCOPES`: Wildcard scope (`'*'`)
154
+ - `AUTH_SCOPE`: Authentication-specific scope (`'__auth'`)
155
+
156
+ #### Authentication Stages
157
+ ```typescript
158
+ enum AuthenticationStage {
159
+ Error = 'error',
160
+ Init = 'init',
161
+ Allowence = 'allowence',
162
+ Authenticate = 'authenticate',
163
+ Authentication = 'auhtentication',
164
+ Authenticated = 'authenticated'
165
+ }
166
+ ```
167
+
168
+ #### Module Aliases
169
+ - `AUTHEN`: Authentication module base
170
+ - `AUTHEN_INIT`: Authentication initialization
171
+ - `AUTHEN_AUTHEN`: Authentication execution
172
+ - `CAUTHEN`: Client authentication module base
173
+
174
+ ### Error Types
175
+
176
+ The package provides a comprehensive error hierarchy for authentication failures:
177
+
178
+ #### `AuthError`
179
+ Base error class for all authentication-related errors.
180
+
181
+ #### `AuthUnknown`
182
+ Error for unknown authentication issues.
183
+
184
+ #### `AuthManagerError`
185
+ Errors related to authentication manager operations.
186
+
187
+ #### `AuthManagerUnsupported`
188
+ Error for unsupported authentication methods.
189
+
190
+ #### `AuthenFailed`
191
+ General authentication failure error.
192
+
193
+ #### `AuthenExists`
194
+ Error when attempting to create duplicate authentication.
195
+
196
+ #### `AuthenPayloadError`
197
+ Error for invalid authentication payload.
198
+
199
+ #### `AuthPluginError`
200
+ Errors related to authentication plugins.
201
+
202
+ #### `TypeMissmatchError`
203
+ Error for authentication type mismatches.
204
+
205
+ #### `AuthorizationError`
206
+ Base error for authorization failures.
207
+
208
+ #### `AuthForbidden`
209
+ Error for forbidden access attempts.
210
+
211
+ #### `ProfileError`
212
+ Errors related to user profile operations.
213
+
214
+ #### `ProfileConsistencyError`
215
+ Error for profile data consistency issues.
216
+
217
+ ## Usage Examples
218
+
219
+ ### Basic Authentication Validation
220
+
221
+ ```typescript
222
+ import { verifyAuth, isAuth, AuthRole } from '@owlmeans/auth'
223
+
224
+ // Validate an authentication object
225
+ const auth = {
226
+ type: 'basic-ed25519',
227
+ role: AuthRole.User,
228
+ userId: 'user123',
229
+ token: 'token123',
230
+ isUser: true,
231
+ createdAt: new Date(),
232
+ scopes: ['read', 'write']
233
+ }
234
+
235
+ if (verifyAuth(auth)) {
236
+ console.log('Authentication is valid')
237
+ }
238
+
239
+ // Type checking
240
+ if (isAuth(someObject)) {
241
+ // TypeScript knows someObject is Auth
242
+ console.log(`User ID: ${someObject.userId}`)
243
+ }
244
+ ```
245
+
246
+ ### Permission Checking
247
+
248
+ ```typescript
249
+ import { PermissionSet, AuthRole } from '@owlmeans/auth'
250
+
251
+ const permissions: PermissionSet = {
252
+ scope: 'documents',
253
+ title: 'Document Permissions',
254
+ permissions: {
255
+ read: true,
256
+ write: true,
257
+ delete: false
258
+ },
259
+ resources: ['doc1', 'doc2']
260
+ }
261
+ ```
262
+
263
+ ### Error Handling
264
+
265
+ ```typescript
266
+ import { AuthError, AuthForbidden } from '@owlmeans/auth'
267
+
268
+ try {
269
+ // Authentication operation
270
+ } catch (error) {
271
+ if (error instanceof AuthForbidden) {
272
+ console.log('Access denied')
273
+ } else if (error instanceof AuthError) {
274
+ console.log('Authentication error:', error.message)
275
+ }
276
+ }
277
+ ```
278
+
279
+ ## Integration with OwlMeans Ecosystem
280
+
281
+ The `@owlmeans/auth` package integrates seamlessly with other OwlMeans packages:
282
+
283
+ - **@owlmeans/basic-keys**: Provides cryptographic key management for signature-based authentication
284
+ - **@owlmeans/error**: Uses the ResilientError system for type-safe error handling
285
+ - **@owlmeans/context**: Integrates with the dependency injection system for service registration
286
+ - **@owlmeans/server-auth**: Server-side authentication implementation
287
+ - **@owlmeans/client-auth**: Client-side authentication implementation
288
+
289
+ ## Package Structure
290
+
291
+ The authentication system is organized into several specialized modules:
292
+
293
+ - **allowance/**: Authentication request and response handling
294
+ - **auth/**: Core authentication logic and models
295
+ - **permission/**: Permission and capability management
296
+ - **rely/**: Wallet and third-party authentication rely functionality
297
+ - **entity/**: Entity-based authentication and authorization
298
+
299
+ ## Advanced Features
300
+
301
+ ### Scoped Permissions
302
+ The system supports hierarchical permission scopes with wildcard and specific resource targeting.
303
+
304
+ ### Multi-Entity Authorization
305
+ Support for entity-specific permissions and cross-entity authorization.
306
+
307
+ ### Cryptographic Authentication
308
+ Integration with Ed25519 digital signatures for secure, non-repudiable authentication.
309
+
310
+ ### Wallet Integration
311
+ Built-in support for decentralized identity wallets and blockchain-based authentication.
312
+
313
+ ## Security Considerations
314
+
315
+ - All authentication tokens should be transmitted over HTTPS
316
+ - Store credentials securely using appropriate encryption
317
+ - Implement proper session management and token expiration
318
+ - Use signature-based authentication for high-security requirements
319
+ - Validate all authentication payloads using the provided validation functions
320
+
321
+ Fixes #32.
package/build/.gitkeep ADDED
File without changes
@@ -0,0 +1,2 @@
1
+ export * from './model.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/allowance/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './model.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/allowance/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA"}
@@ -0,0 +1,7 @@
1
+ import type { JSONSchemaType } from 'ajv';
2
+ import type { AllowanceRequest, Auth, AuthCredentials, AuthPayload } from '../types.js';
3
+ export declare const PartialAuthPayloadSchema: JSONSchemaType<Omit<Partial<AuthPayload>, "type">>;
4
+ export declare const AllowanceRequestSchema: JSONSchemaType<AllowanceRequest>;
5
+ export declare const AuthCredentialsSchema: JSONSchemaType<AuthCredentials>;
6
+ export declare const AuthSchema: JSONSchemaType<Auth>;
7
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/allowance/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,KAAK,EAAE,gBAAgB,EAAE,IAAI,EAAE,eAAe,EAAE,WAAW,EAAE,MAAM,aAAa,CAAA;AAQvF,eAAO,MAAM,wBAAwB,EAAE,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,WAAW,CAAC,EAAE,MAAM,CAAC,CAkBvF,CAAA;AAED,eAAO,MAAM,sBAAsB,EAAE,cAAc,CAAC,gBAAgB,CAQnE,CAAA;AAED,eAAO,MAAM,qBAAqB,EAAE,cAAc,CAAC,eAAe,CAUjE,CAAA;AAED,eAAO,MAAM,UAAU,EAAE,cAAc,CAAC,IAAI,CAa3C,CAAA"}
@@ -0,0 +1,57 @@
1
+ import { AuthRoleSchema, EntityValueSchema, GroupValueSchema, IdValueSchema, DateSchema, ScopeValueSchema, TypeNameSchema } from '../consts.js';
2
+ import { AuthPayloadSchema } from '../auth/model.js';
3
+ import { AttributeSetSchema, PermissionSetSchema } from '../permission/model.js';
4
+ export const PartialAuthPayloadSchema = {
5
+ type: 'object',
6
+ properties: {
7
+ role: { ...AuthRoleSchema, nullable: true },
8
+ source: { type: 'string', minLength: 1, maxLength: 1024, nullable: true },
9
+ userId: { ...IdValueSchema, nullable: true },
10
+ profileId: { ...IdValueSchema, nullable: true },
11
+ expiresAt: { ...DateSchema, nullable: true },
12
+ groups: { type: 'array', items: GroupValueSchema, nullable: true },
13
+ entityId: { ...EntityValueSchema, nullable: true },
14
+ scopes: { type: 'array', items: ScopeValueSchema, nullable: true },
15
+ permissions: { type: 'array', nullable: true, items: PermissionSetSchema },
16
+ attributes: { type: 'array', nullable: true, items: AttributeSetSchema },
17
+ permissioned: { type: 'boolean', nullable: true },
18
+ denormalized: { type: 'boolean', nullable: true }
19
+ },
20
+ required: [],
21
+ additionalProperties: false,
22
+ };
23
+ export const AllowanceRequestSchema = {
24
+ type: 'object',
25
+ properties: {
26
+ type: TypeNameSchema,
27
+ ...PartialAuthPayloadSchema.properties,
28
+ },
29
+ required: ['type'],
30
+ additionalProperties: false,
31
+ };
32
+ export const AuthCredentialsSchema = {
33
+ type: 'object',
34
+ properties: {
35
+ challenge: { type: 'string', minLength: 32, maxLength: 1024 },
36
+ credential: { type: 'string', minLength: 16, maxLength: 4096 },
37
+ publicKey: { type: 'string', minLength: 16, maxLength: 1024, nullable: true },
38
+ ...AuthPayloadSchema.properties
39
+ },
40
+ required: ['challenge', 'credential', ...AuthPayloadSchema.required],
41
+ additionalProperties: false,
42
+ };
43
+ export const AuthSchema = {
44
+ type: 'object',
45
+ properties: {
46
+ token: { type: 'string', minLength: 32, maxLength: 1024 },
47
+ isUser: { type: 'boolean' },
48
+ createdAt: DateSchema,
49
+ expiresAt: { ...DateSchema, nullable: true },
50
+ ...AuthPayloadSchema.properties,
51
+ },
52
+ required: [
53
+ 'token', 'isUser', 'createdAt', 'type', 'role', 'userId'
54
+ ],
55
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,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE;QACzD,MAAM,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE;QAC3B,SAAS,EAAE,UAAU;QACrB,SAAS,EAAE,EAAE,GAAG,UAAU,EAAE,QAAQ,EAAE,IAAI,EAAE;QAC5C,GAAG,iBAAiB,CAAC,UAAU;KAChC;IACD,QAAQ,EAAE;QACR,OAAO,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,EAAE,QAAQ;KACzD;IACD,oBAAoB,EAAE,KAAK;CAC5B,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './model.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA"}
@@ -0,0 +1,2 @@
1
+ export * from './model.js';
2
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/auth/index.ts"],"names":[],"mappings":"AACA,cAAc,YAAY,CAAA"}
@@ -0,0 +1,8 @@
1
+ import type { JSONSchemaType } from 'ajv';
2
+ import type { AuthPayload, AuthToken, Authorization, ProfilePayload } from '../types.js';
3
+ export declare const AuthorizationSchema: JSONSchemaType<Authorization>;
4
+ export declare const ProfilePayloadSchema: JSONSchemaType<ProfilePayload>;
5
+ export declare const AuthPayloadSchema: JSONSchemaType<AuthPayload>;
6
+ export declare const AuthTokenSchema: JSONSchemaType<AuthToken>;
7
+ export declare const OptionalAuthTokenSchema: JSONSchemaType<Partial<AuthToken>>;
8
+ //# sourceMappingURL=model.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.d.ts","sourceRoot":"","sources":["../../src/auth/model.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AACzC,OAAO,KAAK,EAAE,WAAW,EAAE,SAAS,EAAE,aAAa,EAAE,cAAc,EAAE,MAAM,aAAa,CAAA;AAOxF,eAAO,MAAM,mBAAmB,EAAE,cAAc,CAAC,aAAa,CAY7D,CAAA;AAED,eAAO,MAAM,oBAAoB,EAAE,cAAc,CAAC,cAAc,CAQ/D,CAAA;AAED,eAAO,MAAM,iBAAiB,EAAE,cAAc,CAAC,WAAW,CAazD,CAAA;AAED,eAAO,MAAM,eAAe,EAAE,cAAc,CAAC,SAAS,CAOrD,CAAA;AAED,eAAO,MAAM,uBAAuB,EAAE,cAAc,CAAC,OAAO,CAAC,SAAS,CAAC,CAOtE,CAAA"}
@@ -0,0 +1,55 @@
1
+ import { EntityValueSchema, EnumValueSchema, GroupValueSchema, IdValueSchema, DateSchema, ScopeValueSchema, TypeNameSchema } from '../consts.js';
2
+ import { AttributeSetSchema, PermissionSetSchema } from '../permission/model.js';
3
+ export const AuthorizationSchema = {
4
+ type: 'object',
5
+ properties: {
6
+ entityId: { ...EntityValueSchema, nullable: true },
7
+ scopes: { type: 'array', items: ScopeValueSchema },
8
+ permissions: { type: 'array', nullable: true, items: PermissionSetSchema },
9
+ attributes: { type: 'array', nullable: true, items: AttributeSetSchema },
10
+ permissioned: { type: 'boolean', nullable: true },
11
+ denormalized: { type: 'boolean', nullable: true }
12
+ },
13
+ required: ['scopes'],
14
+ additionalProperties: false,
15
+ };
16
+ export const ProfilePayloadSchema = {
17
+ type: 'object',
18
+ properties: {
19
+ ...AuthorizationSchema.properties,
20
+ groups: { type: 'array', nullable: true, items: GroupValueSchema },
21
+ },
22
+ required: ['scopes'],
23
+ additionalProperties: false,
24
+ };
25
+ export const AuthPayloadSchema = {
26
+ type: 'object',
27
+ properties: {
28
+ ...ProfilePayloadSchema.properties,
29
+ type: TypeNameSchema,
30
+ role: EnumValueSchema,
31
+ source: { type: 'string', minLength: 1, maxLength: 1024, nullable: true },
32
+ userId: { ...IdValueSchema, nullable: true },
33
+ profileId: { ...IdValueSchema, nullable: true },
34
+ expiresAt: { ...DateSchema, nullable: true },
35
+ },
36
+ required: ['scopes', 'role', 'type'],
37
+ additionalProperties: false,
38
+ };
39
+ export const AuthTokenSchema = {
40
+ type: 'object',
41
+ properties: {
42
+ token: { type: 'string', minLength: 32, maxLength: 1024 },
43
+ },
44
+ required: ['token'],
45
+ additionalProperties: false,
46
+ };
47
+ export const OptionalAuthTokenSchema = {
48
+ type: 'object',
49
+ properties: {
50
+ token: { type: 'string', minLength: 32, maxLength: 1024, nullable: true },
51
+ },
52
+ required: [],
53
+ additionalProperties: false,
54
+ };
55
+ //# sourceMappingURL=model.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"model.js","sourceRoot":"","sources":["../../src/auth/model.ts"],"names":[],"mappings":"AAEA,OAAO,EACL,iBAAiB,EAAE,eAAe,EAAE,gBAAgB,EAAE,aAAa,EAAE,UAAU,EAAE,gBAAgB,EACjG,cAAc,EACf,MAAM,cAAc,CAAA;AACrB,OAAO,EAAE,kBAAkB,EAAE,mBAAmB,EAAE,MAAM,wBAAwB,CAAA;AAEhF,MAAM,CAAC,MAAM,mBAAmB,GAAkC;IAChE,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,QAAQ,EAAE,EAAE,GAAG,iBAAiB,EAAE,QAAQ,EAAE,IAAI,EAAE;QAClD,MAAM,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,gBAAgB,EAAE;QAClD,WAAW,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,mBAAmB,EAAE;QAC1E,UAAU,EAAE,EAAE,IAAI,EAAE,OAAO,EAAE,QAAQ,EAAE,IAAI,EAAE,KAAK,EAAE,kBAAkB,EAAE;QACxE,YAAY,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;QACjD,YAAY,EAAE,EAAE,IAAI,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE;KAClD;IACD,QAAQ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MAAM,uBAAuB,GAAuC;IACzE,IAAI,EAAE,QAAQ;IACd,UAAU,EAAE;QACV,KAAK,EAAE,EAAE,IAAI,EAAE,QAAQ,EAAE,SAAS,EAAE,EAAE,EAAE,SAAS,EAAE,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE;KAC1E;IACD,QAAQ,EAAE,EAAE;IACZ,oBAAoB,EAAE,KAAK;CAC5B,CAAA"}
@@ -0,0 +1,69 @@
1
+ import type { JSONSchemaType } from 'ajv';
2
+ export declare const INCLUDE = "+";
3
+ export declare const EXCLUDE = "-";
4
+ export declare const WILDCARD = "*";
5
+ export declare const DELIMITER = ":";
6
+ export declare const ALL_SCOPES = "*";
7
+ export declare const AUTH_SCOPE = "__auth";
8
+ export declare enum AuthRole {
9
+ User = "user",
10
+ Guest = "guest",
11
+ Service = "service",
12
+ System = "system",
13
+ Admin = "admin",
14
+ Superuser = "superuser",
15
+ Blocked = "blocked"
16
+ }
17
+ export declare enum AuthenticationType {
18
+ BasicEd25519 = "basic-ed25519",
19
+ OneTimeToken = "one-time-token",
20
+ ReCaptcha = "re-captcha",
21
+ WalletDid = "wallet-did",
22
+ RelyHandshake = "rely-handshake",
23
+ WalletConsumer = "wallet-consumer",
24
+ WalletProvider = "wallet-provider"
25
+ }
26
+ export declare enum AuthroizationType {
27
+ AuthToken = "auth-token",
28
+ Ed25519BasicToken = "ed25519-basic-token",
29
+ Ed25519BasicSignature = "ed25519-basic-signature"
30
+ }
31
+ export declare enum AuthenticationStage {
32
+ Error = "error",
33
+ Init = "init",
34
+ Allowence = "allowence",
35
+ Authenticate = "authenticate",
36
+ Authentication = "auhtentication",
37
+ Authenticated = "authenticated"
38
+ }
39
+ export declare const AUTHEN = "authentication";
40
+ export declare const AUTHEN_INIT = "authentication:init";
41
+ export declare const AUTHEN_AUTHEN = "authentication:authenticate";
42
+ export declare const CAUTHEN = "client-authentication";
43
+ export declare const CAUTHEN_AUTHEN = "client-authentication:authentication";
44
+ export declare const CAUTHEN_AUTHEN_DEFAULT = "client-authentication:authentication:default";
45
+ export declare const CAUTHEN_AUTHEN_TYPED = "client-authentication:authentication:typed";
46
+ export declare const CAUTHEN_FLOW_ENTER = "client-authentication:flow:enter";
47
+ export declare const ScopeValueSchema: JSONSchemaType<string>;
48
+ export declare const PermissionValueSchema: JSONSchemaType<string>;
49
+ export declare const ResourceValueSchema: JSONSchemaType<string>;
50
+ export declare const AttributeValueSchema: JSONSchemaType<string>;
51
+ export declare const EntityValueSchema: JSONSchemaType<string>;
52
+ export declare const GroupValueSchema: JSONSchemaType<string>;
53
+ export declare const TypeNameSchema: JSONSchemaType<string>;
54
+ export declare const EnumValueSchema: JSONSchemaType<string>;
55
+ export declare const IdValueSchema: JSONSchemaType<string>;
56
+ export declare const DateSchema: JSONSchemaType<Date>;
57
+ export declare const AuthRoleSchema: JSONSchemaType<AuthRole>;
58
+ export declare const DISPATCHER = "dispatcher";
59
+ export declare const DISPATCHER_AUTHEN = "dispatcher:authentication";
60
+ export declare const AUTHEN_RELY = "authentication-rely";
61
+ export declare const AUTH_HEADER = "authorization";
62
+ export declare const AUTH_QUERY = "token";
63
+ export declare const ENTITY_QUERY = "entity";
64
+ export declare const PROFILE_QUERY = "profile";
65
+ export declare const MOD_RECAPTCHA = "_external:re-captcha";
66
+ export declare const CMOD_RECAPTCHA: string;
67
+ export declare const GUEST_ID = "__guest";
68
+ export declare const RELY_3RD = "rely";
69
+ //# sourceMappingURL=consts.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"consts.d.ts","sourceRoot":"","sources":["../src/consts.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,KAAK,CAAA;AAEzC,eAAO,MAAM,OAAO,MAAM,CAAA;AAC1B,eAAO,MAAM,OAAO,MAAM,CAAA;AAC1B,eAAO,MAAM,QAAQ,MAAM,CAAA;AAC3B,eAAO,MAAM,SAAS,MAAM,CAAA;AAE5B,eAAO,MAAM,UAAU,MAAM,CAAA;AA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