@argos-js/auth 0.0.0-stage → 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 (147) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +13 -2
  3. package/dist/certificates/cert-parser.d.ts +19 -0
  4. package/dist/certificates/cert-parser.d.ts.map +1 -0
  5. package/dist/certificates/cert-parser.js +192 -0
  6. package/dist/certificates/cert-parser.js.map +1 -0
  7. package/dist/certificates/cert.types.d.ts +60 -0
  8. package/dist/certificates/cert.types.d.ts.map +1 -0
  9. package/dist/certificates/cert.types.js +3 -0
  10. package/dist/certificates/cert.types.js.map +1 -0
  11. package/dist/certificates/index.d.ts +5 -0
  12. package/dist/certificates/index.d.ts.map +1 -0
  13. package/dist/certificates/index.js +21 -0
  14. package/dist/certificates/index.js.map +1 -0
  15. package/dist/certificates/jwks.d.ts +90 -0
  16. package/dist/certificates/jwks.d.ts.map +1 -0
  17. package/dist/certificates/jwks.js +180 -0
  18. package/dist/certificates/jwks.js.map +1 -0
  19. package/dist/certificates/mtls.guard.d.ts +10 -0
  20. package/dist/certificates/mtls.guard.d.ts.map +1 -0
  21. package/dist/certificates/mtls.guard.js +156 -0
  22. package/dist/certificates/mtls.guard.js.map +1 -0
  23. package/dist/config.d.ts +33 -0
  24. package/dist/config.d.ts.map +1 -0
  25. package/dist/config.js +10 -0
  26. package/dist/config.js.map +1 -0
  27. package/dist/guards/api-key.guard.d.ts +21 -0
  28. package/dist/guards/api-key.guard.d.ts.map +1 -0
  29. package/dist/guards/api-key.guard.js +106 -0
  30. package/dist/guards/api-key.guard.js.map +1 -0
  31. package/dist/guards/basic.d.ts +6 -0
  32. package/dist/guards/basic.d.ts.map +1 -0
  33. package/dist/guards/basic.guard.d.ts +26 -0
  34. package/dist/guards/basic.guard.d.ts.map +1 -0
  35. package/dist/guards/basic.guard.js +123 -0
  36. package/dist/guards/basic.guard.js.map +1 -0
  37. package/dist/guards/basic.js +42 -0
  38. package/dist/guards/basic.js.map +1 -0
  39. package/dist/guards/guard.interface.d.ts +21 -0
  40. package/dist/guards/guard.interface.d.ts.map +1 -0
  41. package/dist/guards/guard.interface.js +3 -0
  42. package/dist/guards/guard.interface.js.map +1 -0
  43. package/dist/guards/hmac.guard.d.ts +18 -0
  44. package/dist/guards/hmac.guard.d.ts.map +1 -0
  45. package/dist/guards/hmac.guard.js +111 -0
  46. package/dist/guards/hmac.guard.js.map +1 -0
  47. package/dist/guards/index.d.ts +8 -0
  48. package/dist/guards/index.d.ts.map +1 -0
  49. package/dist/guards/index.js +24 -0
  50. package/dist/guards/index.js.map +1 -0
  51. package/dist/guards/jwt.guard.d.ts +17 -0
  52. package/dist/guards/jwt.guard.d.ts.map +1 -0
  53. package/dist/guards/jwt.guard.js +92 -0
  54. package/dist/guards/jwt.guard.js.map +1 -0
  55. package/dist/hasher/argon2-hasher.d.ts +31 -0
  56. package/dist/hasher/argon2-hasher.d.ts.map +1 -0
  57. package/dist/hasher/argon2-hasher.js +114 -0
  58. package/dist/hasher/argon2-hasher.js.map +1 -0
  59. package/dist/hasher/hasher.interface.d.ts +22 -0
  60. package/dist/hasher/hasher.interface.d.ts.map +1 -0
  61. package/dist/hasher/hasher.interface.js +3 -0
  62. package/dist/hasher/hasher.interface.js.map +1 -0
  63. package/dist/hasher/index.d.ts +5 -0
  64. package/dist/hasher/index.d.ts.map +1 -0
  65. package/dist/hasher/index.js +21 -0
  66. package/dist/hasher/index.js.map +1 -0
  67. package/dist/hasher/password-manager.d.ts +52 -0
  68. package/dist/hasher/password-manager.d.ts.map +1 -0
  69. package/dist/hasher/password-manager.js +126 -0
  70. package/dist/hasher/password-manager.js.map +1 -0
  71. package/dist/hasher/scrypt-hasher.d.ts +30 -0
  72. package/dist/hasher/scrypt-hasher.d.ts.map +1 -0
  73. package/dist/hasher/scrypt-hasher.js +158 -0
  74. package/dist/hasher/scrypt-hasher.js.map +1 -0
  75. package/dist/index.d.ts +9 -0
  76. package/dist/index.d.ts.map +1 -0
  77. package/dist/index.js +32 -0
  78. package/dist/index.js.map +1 -0
  79. package/dist/middleware/auth.middleware.d.ts +42 -0
  80. package/dist/middleware/auth.middleware.d.ts.map +1 -0
  81. package/dist/middleware/auth.middleware.js +142 -0
  82. package/dist/middleware/auth.middleware.js.map +1 -0
  83. package/dist/middleware/index.d.ts +2 -0
  84. package/dist/middleware/index.d.ts.map +1 -0
  85. package/dist/middleware/index.js +18 -0
  86. package/dist/middleware/index.js.map +1 -0
  87. package/dist/oauth/base.provider.d.ts +27 -0
  88. package/dist/oauth/base.provider.d.ts.map +1 -0
  89. package/dist/oauth/base.provider.js +139 -0
  90. package/dist/oauth/base.provider.js.map +1 -0
  91. package/dist/oauth/index.d.ts +6 -0
  92. package/dist/oauth/index.d.ts.map +1 -0
  93. package/dist/oauth/index.js +22 -0
  94. package/dist/oauth/index.js.map +1 -0
  95. package/dist/oauth/oauth-manager.d.ts +41 -0
  96. package/dist/oauth/oauth-manager.d.ts.map +1 -0
  97. package/dist/oauth/oauth-manager.js +58 -0
  98. package/dist/oauth/oauth-manager.js.map +1 -0
  99. package/dist/oauth/oauth.types.d.ts +55 -0
  100. package/dist/oauth/oauth.types.d.ts.map +1 -0
  101. package/dist/oauth/oauth.types.js +3 -0
  102. package/dist/oauth/oauth.types.js.map +1 -0
  103. package/dist/oauth/pkce.d.ts +26 -0
  104. package/dist/oauth/pkce.d.ts.map +1 -0
  105. package/dist/oauth/pkce.js +136 -0
  106. package/dist/oauth/pkce.js.map +1 -0
  107. package/dist/oauth/providers/generic-oidc.provider.d.ts +25 -0
  108. package/dist/oauth/providers/generic-oidc.provider.d.ts.map +1 -0
  109. package/dist/oauth/providers/generic-oidc.provider.js +43 -0
  110. package/dist/oauth/providers/generic-oidc.provider.js.map +1 -0
  111. package/dist/oauth/providers/github.provider.d.ts +15 -0
  112. package/dist/oauth/providers/github.provider.d.ts.map +1 -0
  113. package/dist/oauth/providers/github.provider.js +70 -0
  114. package/dist/oauth/providers/github.provider.js.map +1 -0
  115. package/dist/oauth/providers/google.provider.d.ts +12 -0
  116. package/dist/oauth/providers/google.provider.d.ts.map +1 -0
  117. package/dist/oauth/providers/google.provider.js +27 -0
  118. package/dist/oauth/providers/google.provider.js.map +1 -0
  119. package/dist/oauth/providers/index.d.ts +5 -0
  120. package/dist/oauth/providers/index.d.ts.map +1 -0
  121. package/dist/oauth/providers/index.js +21 -0
  122. package/dist/oauth/providers/index.js.map +1 -0
  123. package/dist/oauth/providers/microsoft.provider.d.ts +13 -0
  124. package/dist/oauth/providers/microsoft.provider.d.ts.map +1 -0
  125. package/dist/oauth/providers/microsoft.provider.js +28 -0
  126. package/dist/oauth/providers/microsoft.provider.js.map +1 -0
  127. package/dist/oauth2/client.d.ts +63 -0
  128. package/dist/oauth2/client.d.ts.map +1 -0
  129. package/dist/oauth2/client.js +150 -0
  130. package/dist/oauth2/client.js.map +1 -0
  131. package/dist/oauth2/index.d.ts +2 -0
  132. package/dist/oauth2/index.d.ts.map +1 -0
  133. package/dist/oauth2/index.js +18 -0
  134. package/dist/oauth2/index.js.map +1 -0
  135. package/dist/tokens/api-key.d.ts +26 -0
  136. package/dist/tokens/api-key.d.ts.map +1 -0
  137. package/dist/tokens/api-key.js +84 -0
  138. package/dist/tokens/api-key.js.map +1 -0
  139. package/dist/tokens/index.d.ts +3 -0
  140. package/dist/tokens/index.d.ts.map +1 -0
  141. package/dist/tokens/index.js +19 -0
  142. package/dist/tokens/index.js.map +1 -0
  143. package/dist/tokens/jwt.d.ts +93 -0
  144. package/dist/tokens/jwt.d.ts.map +1 -0
  145. package/dist/tokens/jwt.js +327 -0
  146. package/dist/tokens/jwt.js.map +1 -0
  147. package/package.json +38 -3
@@ -0,0 +1,18 @@
1
+ import type { AuthGuard, AuthUser, GuardResult } from './guard.interface.js';
2
+ import type { ArgosContext } from '@argos-js/net';
3
+ export interface HmacGuardOptions {
4
+ secret: string | Buffer | ((ctx: ArgosContext) => Promise<string | Buffer> | string | Buffer);
5
+ header?: string;
6
+ algorithm?: string;
7
+ prefix?: string;
8
+ encoding?: 'hex' | 'base64';
9
+ payloadExtractor?: (ctx: ArgosContext) => Promise<string | Buffer> | string | Buffer;
10
+ userResolver?: (ctx: ArgosContext) => Promise<AuthUser> | AuthUser;
11
+ }
12
+ export declare class HmacGuard implements AuthGuard {
13
+ readonly name = "hmac";
14
+ private options;
15
+ constructor(options: HmacGuardOptions);
16
+ authenticate(ctx: ArgosContext): Promise<GuardResult>;
17
+ }
18
+ //# sourceMappingURL=hmac.guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hmac.guard.d.ts","sourceRoot":"","sources":["../../src/guards/hmac.guard.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,MAAM,EAAE,MAAM,GAAG,MAAM,GAAG,CAAC,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC,CAAC;IAC9F,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,SAAS,CAAC,EAAE,MAAM,CAAC;IACnB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,KAAK,GAAG,QAAQ,CAAC;IAC5B,gBAAgB,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,MAAM,GAAG,MAAM,CAAC,GAAG,MAAM,GAAG,MAAM,CAAC;IACrF,YAAY,CAAC,EAAE,CAAC,GAAG,EAAE,YAAY,KAAK,OAAO,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;CACpE;AAED,qBAAa,SAAU,YAAW,SAAS;IACzC,QAAQ,CAAC,IAAI,UAAU;IACvB,OAAO,CAAC,OAAO,CAAmB;gBAEtB,OAAO,EAAE,gBAAgB;IAS/B,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;CAiG5D"}
@@ -0,0 +1,111 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HmacGuard = void 0;
4
+ const node_crypto_1 = require("node:crypto");
5
+ class HmacGuard {
6
+ name = 'hmac';
7
+ options;
8
+ constructor(options) {
9
+ this.options = {
10
+ header: 'x-signature',
11
+ algorithm: 'sha256',
12
+ encoding: 'hex',
13
+ ...options,
14
+ };
15
+ }
16
+ async authenticate(ctx) {
17
+ const headerName = this.options.header.toLowerCase();
18
+ const rawHeader = typeof ctx.getHeader === 'function'
19
+ ? ctx.getHeader(headerName)
20
+ : ctx.headers?.[headerName];
21
+ if (!rawHeader) {
22
+ return {
23
+ authenticated: false,
24
+ error: `Missing HMAC signature header (${this.options.header})`,
25
+ guard: this.name,
26
+ };
27
+ }
28
+ let signature = rawHeader.trim();
29
+ if (this.options.prefix && signature.startsWith(this.options.prefix)) {
30
+ signature = signature.slice(this.options.prefix.length).trim();
31
+ }
32
+ try {
33
+ // 1. Resolve Secret
34
+ const secret = typeof this.options.secret === 'function'
35
+ ? await this.options.secret(ctx)
36
+ : this.options.secret;
37
+ // 2. Extract Raw Payload
38
+ let payloadData;
39
+ if (this.options.payloadExtractor) {
40
+ payloadData = await this.options.payloadExtractor(ctx);
41
+ }
42
+ else {
43
+ const anyCtx = ctx;
44
+ if (anyCtx.rawBody !== undefined) {
45
+ payloadData = anyCtx.rawBody;
46
+ }
47
+ else if (anyCtx.rawText !== undefined) {
48
+ payloadData = anyCtx.rawText;
49
+ }
50
+ else if (typeof ctx.body === 'function') {
51
+ const bodyVal = await ctx.body();
52
+ payloadData = typeof bodyVal === 'string' || Buffer.isBuffer(bodyVal)
53
+ ? bodyVal
54
+ : bodyVal !== undefined && bodyVal !== null
55
+ ? JSON.stringify(bodyVal)
56
+ : '';
57
+ }
58
+ else {
59
+ payloadData = '';
60
+ }
61
+ }
62
+ // 3. Compute HMAC
63
+ const hmac = (0, node_crypto_1.createHmac)(this.options.algorithm || 'sha256', secret);
64
+ hmac.update(payloadData);
65
+ const computedDigest = hmac.digest(this.options.encoding || 'hex');
66
+ // 4. Compare with timingSafeEqual
67
+ const sigBuf = Buffer.from(signature, this.options.encoding || 'hex');
68
+ const compBuf = Buffer.from(computedDigest, this.options.encoding || 'hex');
69
+ if (sigBuf.length !== compBuf.length) {
70
+ const dummy = Buffer.alloc(sigBuf.length);
71
+ (0, node_crypto_1.timingSafeEqual)(sigBuf, dummy);
72
+ return {
73
+ authenticated: false,
74
+ error: 'HMAC signature mismatch',
75
+ guard: this.name,
76
+ };
77
+ }
78
+ if (!(0, node_crypto_1.timingSafeEqual)(sigBuf, compBuf)) {
79
+ return {
80
+ authenticated: false,
81
+ error: 'HMAC signature mismatch',
82
+ guard: this.name,
83
+ };
84
+ }
85
+ let user;
86
+ if (this.options.userResolver) {
87
+ user = await this.options.userResolver(ctx);
88
+ }
89
+ else {
90
+ user = {
91
+ id: 'hmac-client',
92
+ scopes: ['webhook:verified'],
93
+ };
94
+ }
95
+ return {
96
+ authenticated: true,
97
+ user,
98
+ guard: this.name,
99
+ };
100
+ }
101
+ catch (err) {
102
+ return {
103
+ authenticated: false,
104
+ error: err.message || 'Error verifying HMAC signature',
105
+ guard: this.name,
106
+ };
107
+ }
108
+ }
109
+ }
110
+ exports.HmacGuard = HmacGuard;
111
+ //# sourceMappingURL=hmac.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hmac.guard.js","sourceRoot":"","sources":["../../src/guards/hmac.guard.ts"],"names":[],"mappings":";;;AAAA,6CAA0D;AAc1D,MAAa,SAAS;IACX,IAAI,GAAG,MAAM,CAAC;IACf,OAAO,CAAmB;IAElC,YAAY,OAAyB;QACnC,IAAI,CAAC,OAAO,GAAG;YACb,MAAM,EAAE,aAAa;YACrB,SAAS,EAAE,QAAQ;YACnB,QAAQ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@@
1
+ export * from './guard.interface.js';
2
+ export * from './jwt.guard.js';
3
+ export * from './api-key.guard.js';
4
+ export * from './basic.guard.js';
5
+ export * from './basic.js';
6
+ export * from './hmac.guard.js';
7
+ export * from '../certificates/mtls.guard.js';
8
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/guards/index.ts"],"names":[],"mappings":"AAAA,cAAc,sBAAsB,CAAC;AACrC,cAAc,gBAAgB,CAAC;AAC/B,cAAc,oBAAoB,CAAC;AACnC,cAAc,kBAAkB,CAAC;AACjC,cAAc,YAAY,CAAC;AAC3B,cAAc,iBAAiB,CAAC;AAChC,cAAc,+BAA+B,CAAC"}
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./guard.interface.js"), exports);
18
+ __exportStar(require("./jwt.guard.js"), exports);
19
+ __exportStar(require("./api-key.guard.js"), exports);
20
+ __exportStar(require("./basic.guard.js"), exports);
21
+ __exportStar(require("./basic.js"), exports);
22
+ __exportStar(require("./hmac.guard.js"), exports);
23
+ __exportStar(require("../certificates/mtls.guard.js"), exports);
24
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/guards/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,uDAAqC;AACrC,iDAA+B;AAC/B,qDAAmC;AACnC,mDAAiC;AACjC,6CAA2B;AAC3B,kDAAgC;AAChC,gEAA8C"}
@@ -0,0 +1,17 @@
1
+ import { type JwtVerifyOptions } from '../tokens/jwt.js';
2
+ import type { AuthGuard, AuthUser, GuardResult } from './guard.interface.js';
3
+ import type { ArgosContext } from '@argos-js/net';
4
+ export interface JwtGuardOptions extends Omit<JwtVerifyOptions, 'algorithms'> {
5
+ secretOrPublicKey: string | Buffer;
6
+ algorithms?: ('HS256' | 'RS256' | 'EdDSA')[];
7
+ header?: string;
8
+ tokenPrefix?: string;
9
+ userResolver?: (payload: any) => Promise<AuthUser | null> | AuthUser | null;
10
+ }
11
+ export declare class JwtGuard implements AuthGuard {
12
+ readonly name = "jwt";
13
+ private options;
14
+ constructor(options: JwtGuardOptions);
15
+ authenticate(ctx: ArgosContext): Promise<GuardResult>;
16
+ }
17
+ //# sourceMappingURL=jwt.guard.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.guard.d.ts","sourceRoot":"","sources":["../../src/guards/jwt.guard.ts"],"names":[],"mappings":"AAAA,OAAO,EAAe,KAAK,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACtE,OAAO,KAAK,EAAE,SAAS,EAAE,QAAQ,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAC7E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,eAAe,CAAC;AAElD,MAAM,WAAW,eAAgB,SAAQ,IAAI,CAAC,gBAAgB,EAAE,YAAY,CAAC;IAC3E,iBAAiB,EAAE,MAAM,GAAG,MAAM,CAAC;IACnC,UAAU,CAAC,EAAE,CAAC,OAAO,GAAG,OAAO,GAAG,OAAO,CAAC,EAAE,CAAC;IAC7C,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,YAAY,CAAC,EAAE,CAAC,OAAO,EAAE,GAAG,KAAK,OAAO,CAAC,QAAQ,GAAG,IAAI,CAAC,GAAG,QAAQ,GAAG,IAAI,CAAC;CAC7E;AAED,qBAAa,QAAS,YAAW,SAAS;IACxC,QAAQ,CAAC,IAAI,SAAS;IACtB,OAAO,CAAC,OAAO,CAAkB;gBAErB,OAAO,EAAE,eAAe;IAS9B,YAAY,CAAC,GAAG,EAAE,YAAY,GAAG,OAAO,CAAC,WAAW,CAAC;CAgF5D"}
@@ -0,0 +1,92 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.JwtGuard = void 0;
4
+ const jwt_js_1 = require("../tokens/jwt.js");
5
+ class JwtGuard {
6
+ name = 'jwt';
7
+ options;
8
+ constructor(options) {
9
+ this.options = {
10
+ header: 'authorization',
11
+ tokenPrefix: 'Bearer ',
12
+ algorithms: ['HS256'],
13
+ ...options,
14
+ };
15
+ }
16
+ async authenticate(ctx) {
17
+ const headerName = this.options.header.toLowerCase();
18
+ const rawHeader = typeof ctx.getHeader === 'function'
19
+ ? ctx.getHeader(headerName)
20
+ : ctx.headers?.[headerName];
21
+ if (!rawHeader) {
22
+ return {
23
+ authenticated: false,
24
+ error: 'Missing authorization header',
25
+ guard: this.name,
26
+ };
27
+ }
28
+ const prefix = this.options.tokenPrefix || 'Bearer ';
29
+ let token = rawHeader.trim();
30
+ if (token.toLowerCase().startsWith(prefix.toLowerCase())) {
31
+ token = token.slice(prefix.length).trim();
32
+ }
33
+ else if (this.options.tokenPrefix) {
34
+ return {
35
+ authenticated: false,
36
+ error: `Invalid authorization scheme. Expected ${prefix.trim()}`,
37
+ guard: this.name,
38
+ };
39
+ }
40
+ try {
41
+ const payload = await (0, jwt_js_1.verifyToken)(token, this.options.secretOrPublicKey, {
42
+ algorithms: this.options.algorithms,
43
+ issuer: this.options.issuer,
44
+ audience: this.options.audience,
45
+ clockTolerance: this.options.clockTolerance,
46
+ ignoreExpiration: this.options.ignoreExpiration,
47
+ });
48
+ let user;
49
+ if (this.options.userResolver) {
50
+ const resolved = await this.options.userResolver(payload);
51
+ if (!resolved) {
52
+ return {
53
+ authenticated: false,
54
+ error: 'User not found or deactivated',
55
+ guard: this.name,
56
+ };
57
+ }
58
+ user = resolved;
59
+ }
60
+ else {
61
+ const id = (payload.sub ?? payload.id ?? payload.userId);
62
+ user = {
63
+ id: id ?? 'anonymous',
64
+ username: (payload.username ?? payload.name),
65
+ email: payload.email,
66
+ roles: Array.isArray(payload.roles) ? payload.roles : undefined,
67
+ permissions: Array.isArray(payload.permissions) ? payload.permissions : undefined,
68
+ scopes: Array.isArray(payload.scopes)
69
+ ? payload.scopes
70
+ : typeof payload.scope === 'string'
71
+ ? payload.scope.split(' ')
72
+ : undefined,
73
+ ...payload,
74
+ };
75
+ }
76
+ return {
77
+ authenticated: true,
78
+ user,
79
+ guard: this.name,
80
+ };
81
+ }
82
+ catch (err) {
83
+ return {
84
+ authenticated: false,
85
+ error: err.message || 'Invalid token',
86
+ guard: this.name,
87
+ };
88
+ }
89
+ }
90
+ }
91
+ exports.JwtGuard = JwtGuard;
92
+ //# sourceMappingURL=jwt.guard.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"jwt.guard.js","sourceRoot":"","sources":["../../src/guards/jwt.guard.ts"],"names":[],"mappings":";;;AAAA,6CAAsE;AAYtE,MAAa,QAAQ;IACV,IAAI,GAAG,KAAK,CAAC;IACd,OAAO,CAAkB;IAEjC,YAAY,OAAwB;QAClC,IAAI,CAAC,OAAO,GAAG;YACb,MAAM,EAAE,eAAe;YACvB,WAAW,EAAE,SAAS;YACtB,UAAU,EAAE,CAAC,OAAO,CAAC;YACrB,GAAG,OAAO;SACX,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,YAAY,CAAC,GAAiB;QAClC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,MAAO,CAAC,WAAW,EAAE,CAAC;QACtD,MAAM,SAAS,GA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AAC;YACJ,CAAC;YAED,OAAO;gBACL,aAAa,EAAE,IAAI;gBACnB,IAAI;gBACJ,KAAK,EAAE,IAAI,CAAC,IAAI;aACjB,CAAC;QACJ,CAAC;QAAC,OAAO,GAAQ,EAAE,CAAC;YAClB,OAAO;gBACL,aAAa,EAAE,KAAK;gBACpB,KAAK,EAAE,GAAG,CAAC,OAAO,IAAI,eAAe;gBACrC,KAAK,EAAE,IAAI,CAAC,IAAI;aACjB,CAAC;QACJ,CAAC;IACH,CAAC;CACF;AA7FD,4BA6FC"}
@@ -0,0 +1,31 @@
1
+ import type { Hasher } from './hasher.interface';
2
+ export interface Argon2HasherOptions {
3
+ memoryCost?: number;
4
+ timeCost?: number;
5
+ parallelism?: number;
6
+ outputLen?: number;
7
+ }
8
+ /**
9
+ * Enterprise Argon2id password hasher.
10
+ * Utilizes native high-performance `@node-rs/argon2` or `argon2` if available,
11
+ * with graceful fallback to ScryptHasher if native binding is absent.
12
+ */
13
+ export declare class Argon2Hasher implements Hasher {
14
+ readonly algorithm = "argon2id";
15
+ private nativeModule;
16
+ private readonly fallbackScrypt;
17
+ private readonly memoryCost;
18
+ private readonly timeCost;
19
+ private readonly parallelism;
20
+ private readonly outputLen;
21
+ constructor(options?: Argon2HasherOptions);
22
+ private detectModule;
23
+ /**
24
+ * Returns true if a native Argon2 engine is installed and loaded.
25
+ */
26
+ isAvailable(): boolean;
27
+ hash(password: string, customOptions?: Argon2HasherOptions): Promise<string>;
28
+ verify(password: string, hash: string): Promise<boolean>;
29
+ needsRehash(hash: string, customOptions?: Argon2HasherOptions): boolean;
30
+ }
31
+ //# sourceMappingURL=argon2-hasher.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argon2-hasher.d.ts","sourceRoot":"","sources":["../../src/hasher/argon2-hasher.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AAGjD,MAAM,WAAW,mBAAmB;IAClC,UAAU,CAAC,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,EAAE,MAAM,CAAC;IAClB,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED;;;;GAIG;AACH,qBAAa,YAAa,YAAW,MAAM;IACzC,SAAgB,SAAS,cAAc;IAEvC,OAAO,CAAC,YAAY,CAAa;IACjC,OAAO,CAAC,QAAQ,CAAC,cAAc,CAAsB;IACrD,OAAO,CAAC,QAAQ,CAAC,UAAU,CAAS;IACpC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAS;IAClC,OAAO,CAAC,QAAQ,CAAC,WAAW,CAAS;IACrC,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAS;gBAEvB,OAAO,GAAE,mBAAwB;IAS7C,OAAO,CAAC,YAAY;IAgBpB;;OAEG;IACI,WAAW,IAAI,OAAO;IAIhB,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,aAAa,GAAE,mBAAwB,GAAG,OAAO,CAAC,MAAM,CAAC;IAsBhF,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAoB9D,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,aAAa,GAAE,mBAAwB,GAAG,OAAO;CA6BnF"}
@@ -0,0 +1,114 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Argon2Hasher = void 0;
4
+ const scrypt_hasher_1 = require("./scrypt-hasher");
5
+ /**
6
+ * Enterprise Argon2id password hasher.
7
+ * Utilizes native high-performance `@node-rs/argon2` or `argon2` if available,
8
+ * with graceful fallback to ScryptHasher if native binding is absent.
9
+ */
10
+ class Argon2Hasher {
11
+ algorithm = 'argon2id';
12
+ nativeModule = null;
13
+ fallbackScrypt = new scrypt_hasher_1.ScryptHasher();
14
+ memoryCost;
15
+ timeCost;
16
+ parallelism;
17
+ outputLen;
18
+ constructor(options = {}) {
19
+ this.memoryCost = options.memoryCost ?? 65536;
20
+ this.timeCost = options.timeCost ?? 3;
21
+ this.parallelism = options.parallelism ?? 4;
22
+ this.outputLen = options.outputLen ?? 32;
23
+ this.detectModule();
24
+ }
25
+ detectModule() {
26
+ try {
27
+ // 1. Try @node-rs/argon2 (NAPI-RS binding)
28
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
29
+ this.nativeModule = require('@node-rs/argon2');
30
+ }
31
+ catch {
32
+ try {
33
+ // 2. Try standard argon2 package
34
+ // eslint-disable-next-line @typescript-eslint/no-var-requires
35
+ this.nativeModule = require('argon2');
36
+ }
37
+ catch {
38
+ this.nativeModule = null;
39
+ }
40
+ }
41
+ }
42
+ /**
43
+ * Returns true if a native Argon2 engine is installed and loaded.
44
+ */
45
+ isAvailable() {
46
+ return this.nativeModule !== null;
47
+ }
48
+ async hash(password, customOptions = {}) {
49
+ if (this.nativeModule) {
50
+ const memoryCost = customOptions.memoryCost ?? this.memoryCost;
51
+ const timeCost = customOptions.timeCost ?? this.timeCost;
52
+ const parallelism = customOptions.parallelism ?? this.parallelism;
53
+ const outputLen = customOptions.outputLen ?? this.outputLen;
54
+ if (typeof this.nativeModule.hash === 'function') {
55
+ return this.nativeModule.hash(password, {
56
+ memoryCost,
57
+ timeCost,
58
+ parallelism,
59
+ outputLen,
60
+ algorithm: 2, // Argon2id
61
+ });
62
+ }
63
+ }
64
+ // Graceful fallback to Scrypt if Argon2 binding is not installed in environment
65
+ return this.fallbackScrypt.hash(password);
66
+ }
67
+ async verify(password, hash) {
68
+ if (!hash)
69
+ return false;
70
+ if (hash.startsWith('$argon2') && this.nativeModule) {
71
+ try {
72
+ if (typeof this.nativeModule.verify === 'function') {
73
+ return await this.nativeModule.verify(hash, password);
74
+ }
75
+ }
76
+ catch {
77
+ return false;
78
+ }
79
+ }
80
+ if (hash.startsWith('$scrypt$')) {
81
+ return this.fallbackScrypt.verify(password, hash);
82
+ }
83
+ return false;
84
+ }
85
+ needsRehash(hash, customOptions = {}) {
86
+ if (!hash || !hash.startsWith('$argon2')) {
87
+ return true;
88
+ }
89
+ if (this.nativeModule && typeof this.nativeModule.needsRehash === 'function') {
90
+ const memoryCost = customOptions.memoryCost ?? this.memoryCost;
91
+ const timeCost = customOptions.timeCost ?? this.timeCost;
92
+ return this.nativeModule.needsRehash(hash, { memoryCost, timeCost });
93
+ }
94
+ // Inspect parameter string in PHC format: $argon2id$v=19$m=65536,t=3,p=4$...
95
+ const parts = hash.split('$');
96
+ const paramPart = parts.find((p) => p.includes('m='));
97
+ if (!paramPart)
98
+ return true;
99
+ let m = 0;
100
+ let t = 0;
101
+ for (const item of paramPart.split(',')) {
102
+ const [k, v] = item.split('=');
103
+ if (k === 'm')
104
+ m = parseInt(v, 10);
105
+ if (k === 't')
106
+ t = parseInt(v, 10);
107
+ }
108
+ const targetMemory = customOptions.memoryCost ?? this.memoryCost;
109
+ const targetTime = customOptions.timeCost ?? this.timeCost;
110
+ return m < targetMemory || t < targetTime;
111
+ }
112
+ }
113
+ exports.Argon2Hasher = Argon2Hasher;
114
+ //# sourceMappingURL=argon2-hasher.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"argon2-hasher.js","sourceRoot":"","sources":["../../src/hasher/argon2-hasher.ts"],"names":[],"mappings":";;;AACA,mDAA+C;AAS/C;;;;GAIG;AACH,MAAa,YAAY;IACP,SAAS,GAAG,UAAU,CAAC;IAE/B,YAAY,GAAQ,IAAI,CAAC;IAChB,cAAc,GAAG,IAAI,4BAAY,EAAE,CAAC;IACpC,UAAU,CAAS;IACnB,QAAQ,CAAS;IACjB,WAAW,CAAS;IACpB,SAAS,CAAS;IAEnC,YAAY,UAA+B,EAAE;QAC3C,IAAI,CAAC,UAAU,GAAG,OAAO,CAAC,UAAU,IAAI,KAAK,CAAC;QAC9C,IAAI,CAAC,QAAQ,GAAG,OAAO,CAAC,QAAQ,IAAI,CAAC,CAAC;QACtC,IAAI,CAAC,WAAW,GAAG,OAAO,CAAC,WAAW,IAAI,CA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AAC,CAAC;QACvE,CAAC;QAED,6EAA6E;QAC7E,MAAM,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC9B,MAAM,SAAS,GAAG,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAC,CAAC;QACtD,IAAI,CAAC,SAAS;YAAE,OAAO,IAAI,CAAC;QAE5B,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,IAAI,CAAC,GAAG,CAAC,CAAC;QACV,KAAK,MAAM,IAAI,IAAI,SAAS,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YACxC,MAAM,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YAC/B,IAAI,CAAC,KAAK,GAAG;gBAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;YACnC,IAAI,CAAC,KAAK,GAAG;gBAAE,CAAC,GAAG,QAAQ,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC;QACrC,CAAC;QAED,MAAM,YAAY,GAAG,aAAa,CAAC,UAAU,IAAI,IAAI,CAAC,UAAU,CAAC;QACjE,MAAM,UAAU,GAAG,aAAa,CAAC,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC;QAE3D,OAAO,CAAC,GAAG,YAAY,IAAI,CAAC,GAAG,UAAU,CAAC;IAC5C,CAAC;CACF;AAjHD,oCAiHC"}
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Common interface for password hashing engines.
3
+ */
4
+ export interface Hasher {
5
+ /**
6
+ * Unique identifier for the algorithm (e.g. 'scrypt', 'argon2id', 'bcrypt').
7
+ */
8
+ readonly algorithm: string;
9
+ /**
10
+ * Hashes a plaintext password into a secure PHC formatted string.
11
+ */
12
+ hash(password: string, options?: Record<string, unknown>): Promise<string>;
13
+ /**
14
+ * Verifies a candidate password against an existing hash using timing-safe comparison.
15
+ */
16
+ verify(password: string, hash: string): Promise<boolean>;
17
+ /**
18
+ * Determines if the hash was created with outdated parameters and requires re-hashing.
19
+ */
20
+ needsRehash(hash: string, options?: Record<string, unknown>): boolean;
21
+ }
22
+ //# sourceMappingURL=hasher.interface.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasher.interface.d.ts","sourceRoot":"","sources":["../../src/hasher/hasher.interface.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,MAAM,WAAW,MAAM;IACrB;;OAEG;IACH,QAAQ,CAAC,SAAS,EAAE,MAAM,CAAC;IAE3B;;OAEG;IACH,IAAI,CAAC,QAAQ,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC;IAE3E;;OAEG;IACH,MAAM,CAAC,QAAQ,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC,CAAC;IAEzD;;OAEG;IACH,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,OAAO,CAAC;CACvE"}
@@ -0,0 +1,3 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ //# sourceMappingURL=hasher.interface.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hasher.interface.js","sourceRoot":"","sources":["../../src/hasher/hasher.interface.ts"],"names":[],"mappings":""}
@@ -0,0 +1,5 @@
1
+ export * from './hasher.interface';
2
+ export * from './scrypt-hasher';
3
+ export * from './argon2-hasher';
4
+ export * from './password-manager';
5
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/hasher/index.ts"],"names":[],"mappings":"AAAA,cAAc,oBAAoB,CAAC;AACnC,cAAc,iBAAiB,CAAC;AAChC,cAAc,iBAAiB,CAAC;AAChC,cAAc,oBAAoB,CAAC"}
@@ -0,0 +1,21 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ Object.defineProperty(exports, "__esModule", { value: true });
17
+ __exportStar(require("./hasher.interface"), exports);
18
+ __exportStar(require("./scrypt-hasher"), exports);
19
+ __exportStar(require("./argon2-hasher"), exports);
20
+ __exportStar(require("./password-manager"), exports);
21
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/hasher/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;AAAA,qDAAmC;AACnC,kDAAgC;AAChC,kDAAgC;AAChC,qDAAmC"}
@@ -0,0 +1,52 @@
1
+ import type { Hasher } from './hasher.interface';
2
+ import { type ScryptHasherOptions } from './scrypt-hasher';
3
+ import { type Argon2HasherOptions } from './argon2-hasher';
4
+ export interface PasswordManagerOptions {
5
+ default?: 'argon2' | 'scrypt' | string;
6
+ scrypt?: ScryptHasherOptions;
7
+ argon2?: Argon2HasherOptions;
8
+ }
9
+ /**
10
+ * Unified Password Manager coordinating multi-algorithm hashing and verification.
11
+ * Automatically inspects stored hash prefixes ($argon2id$, $scrypt$, etc.) to verify
12
+ * without requiring the caller to specify which algorithm was used.
13
+ */
14
+ export declare class PasswordManager {
15
+ private hashers;
16
+ private defaultAlgorithm;
17
+ constructor(options?: PasswordManagerOptions);
18
+ /**
19
+ * Registers a custom hasher implementation.
20
+ */
21
+ register(name: string, hasher: Hasher): this;
22
+ /**
23
+ * Hashes a password using the default or specified algorithm.
24
+ */
25
+ hash(password: string, algorithm?: string): Promise<string>;
26
+ /**
27
+ * Verifies a password against any supported stored hash format.
28
+ */
29
+ verify(password: string, hash: string): Promise<boolean>;
30
+ /**
31
+ * Checks if the stored hash should be upgraded (e.g. algorithm migrated or cost increased).
32
+ */
33
+ needsRehash(hash: string): boolean;
34
+ /**
35
+ * Returns the name of the current default algorithm.
36
+ */
37
+ getDefaultAlgorithm(): string;
38
+ }
39
+ export declare const defaultPasswordManager: PasswordManager;
40
+ /**
41
+ * Convenience helper: Hashes password using the default enterprise hasher.
42
+ */
43
+ export declare function hashPassword(password: string, algorithm?: string): Promise<string>;
44
+ /**
45
+ * Convenience helper: Verifies password against stored hash.
46
+ */
47
+ export declare function verifyPassword(password: string, hash: string): Promise<boolean>;
48
+ /**
49
+ * Convenience helper: Checks if hash needs re-hashing.
50
+ */
51
+ export declare function needsRehash(hash: string): boolean;
52
+ //# sourceMappingURL=password-manager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"password-manager.d.ts","sourceRoot":"","sources":["../../src/hasher/password-manager.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AACzE,OAAO,EAAgB,KAAK,mBAAmB,EAAE,MAAM,iBAAiB,CAAC;AAEzE,MAAM,WAAW,sBAAsB;IACrC,OAAO,CAAC,EAAE,QAAQ,GAAG,QAAQ,GAAG,MAAM,CAAC;IACvC,MAAM,CAAC,EAAE,mBAAmB,CAAC;IAC7B,MAAM,CAAC,EAAE,mBAAmB,CAAC;CAC9B;AAED;;;;GAIG;AAC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