@degenerate/generic 0.1.2 → 0.1.4
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/dist/_settings/authorization-settings.d.ts +17 -0
- package/dist/_settings/authorization-settings.d.ts.map +1 -0
- package/dist/_settings/authorization-settings.js +20 -0
- package/dist/_settings/cryptography-settings.d.ts +15 -3
- package/dist/_settings/cryptography-settings.d.ts.map +1 -1
- package/dist/_settings/cryptography-settings.js +16 -2
- package/dist/application/database/firestore/generics/get-items-from-database.d.ts.map +1 -1
- package/dist/application/database/firestore/generics/get-items-from-database.js +0 -3
- package/dist/authorization/index.d.ts +24 -0
- package/dist/authorization/index.d.ts.map +1 -0
- package/dist/authorization/index.js +61 -0
- package/dist/authorization/jwt/keys/create-public-key-pem.d.ts +9 -0
- package/dist/authorization/jwt/keys/create-public-key-pem.d.ts.map +1 -0
- package/dist/authorization/jwt/keys/create-public-key-pem.js +25 -0
- package/dist/authorization/jwt/keys/create-secret-key-pem.d.ts +9 -0
- package/dist/authorization/jwt/keys/create-secret-key-pem.d.ts.map +1 -0
- package/dist/authorization/jwt/keys/create-secret-key-pem.js +24 -0
- package/dist/authorization/jwt/sign/create-authorization-issuer.d.ts +10 -0
- package/dist/authorization/jwt/sign/create-authorization-issuer.d.ts.map +1 -0
- package/dist/authorization/jwt/sign/create-authorization-issuer.js +26 -0
- package/dist/authorization/jwt/sign/create-authorization-subject.d.ts +12 -0
- package/dist/authorization/jwt/sign/create-authorization-subject.d.ts.map +1 -0
- package/dist/authorization/jwt/sign/create-authorization-subject.js +19 -0
- package/dist/authorization/jwt/sign/create-jwt-options.d.ts +17 -0
- package/dist/authorization/jwt/sign/create-jwt-options.d.ts.map +1 -0
- package/dist/authorization/jwt/sign/create-jwt-options.js +43 -0
- package/dist/authorization/jwt/sign/create-jwt-signed-token.d.ts +13 -0
- package/dist/authorization/jwt/sign/create-jwt-signed-token.d.ts.map +1 -0
- package/dist/authorization/jwt/sign/create-jwt-signed-token.js +22 -0
- package/dist/authorization/jwt/transform/transform-token-payload-to-safe-payload.d.ts +10 -0
- package/dist/authorization/jwt/transform/transform-token-payload-to-safe-payload.d.ts.map +1 -0
- package/dist/authorization/jwt/transform/transform-token-payload-to-safe-payload.js +31 -0
- package/dist/authorization/jwt/verify/get-decoded-jwt-header.d.ts +10 -0
- package/dist/authorization/jwt/verify/get-decoded-jwt-header.d.ts.map +1 -0
- package/dist/authorization/jwt/verify/get-decoded-jwt-header.js +20 -0
- package/dist/authorization/jwt/verify/get-decoded-jwt-signed-token-payload.d.ts +9 -0
- package/dist/authorization/jwt/verify/get-decoded-jwt-signed-token-payload.d.ts.map +1 -0
- package/dist/authorization/jwt/verify/get-decoded-jwt-signed-token-payload.js +17 -0
- package/dist/authorization/jwt/verify/verify-jwt-signed-token.d.ts +12 -0
- package/dist/authorization/jwt/verify/verify-jwt-signed-token.d.ts.map +1 -0
- package/dist/authorization/jwt/verify/verify-jwt-signed-token.js +34 -0
- package/dist/authorization/safe/authorization/authorized-authorities.d.ts +39 -0
- package/dist/authorization/safe/authorization/authorized-authorities.d.ts.map +1 -0
- package/dist/authorization/safe/authorization/authorized-authorities.js +56 -0
- package/dist/authorization/safe/request/decode-bearer-token.d.ts +11 -0
- package/dist/authorization/safe/request/decode-bearer-token.d.ts.map +1 -0
- package/dist/authorization/safe/request/decode-bearer-token.js +31 -0
- package/dist/authorization/safe/request/decode-safe-request.d.ts +11 -0
- package/dist/authorization/safe/request/decode-safe-request.d.ts.map +1 -0
- package/dist/authorization/safe/request/decode-safe-request.js +30 -0
- package/dist/authorization/safe/request/determine-issuer-from-request.d.ts +10 -0
- package/dist/authorization/safe/request/determine-issuer-from-request.d.ts.map +1 -0
- package/dist/authorization/safe/request/determine-issuer-from-request.js +29 -0
- package/dist/authorization/safe/request/issuer/determine-issuer-from-bearer-token.d.ts +12 -0
- package/dist/authorization/safe/request/issuer/determine-issuer-from-bearer-token.d.ts.map +1 -0
- package/dist/authorization/safe/request/issuer/determine-issuer-from-bearer-token.js +30 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-audience.d.ts +10 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-audience.d.ts.map +1 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-audience.js +24 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.d.ts +8 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.d.ts.map +1 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.js +23 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.d.ts +9 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.d.ts.map +1 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.js +24 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issuer.d.ts +10 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issuer.d.ts.map +1 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issuer.js +25 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.d.ts +8 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.d.ts.map +1 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.js +23 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-subject.d.ts +10 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-subject.d.ts.map +1 -0
- package/dist/authorization/safe/validation/jwt/payload/verify-authorization-subject.js +22 -0
- package/dist/authorization/safe/validation/jwt/verify-token-header.d.ts +9 -0
- package/dist/authorization/safe/validation/jwt/verify-token-header.d.ts.map +1 -0
- package/dist/authorization/safe/validation/jwt/verify-token-header.js +25 -0
- package/dist/authorization/safe/validation/jwt/verify-token-payload.d.ts +11 -0
- package/dist/authorization/safe/validation/jwt/verify-token-payload.d.ts.map +1 -0
- package/dist/authorization/safe/validation/jwt/verify-token-payload.js +30 -0
- package/dist/crypto/index.d.ts +1 -0
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/index.js +1 -0
- package/dist/crypto/private-public-keys/create-key-pair-from-private-key.d.ts.map +1 -1
- package/dist/crypto/private-public-keys/generation/create-256-private-key-from-mnemonic.d.ts +1 -1
- package/dist/crypto/private-public-keys/generation/create-256-private-key-from-mnemonic.js +1 -1
- package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts +1 -1
- package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.d.ts.map +1 -1
- package/dist/crypto/private-public-keys/generation/create-entropy-for-elliptical-curve.js +3 -2
- package/dist/crypto/private-public-keys/generation/create-random-512-key-pair.d.ts +9 -0
- package/dist/crypto/private-public-keys/generation/create-random-512-key-pair.d.ts.map +1 -0
- package/dist/crypto/private-public-keys/generation/create-random-512-key-pair.js +46 -0
- package/dist/errors/authorization/authorization-errors.d.ts +106 -0
- package/dist/errors/authorization/authorization-errors.d.ts.map +1 -0
- package/dist/errors/authorization/authorization-errors.js +160 -0
- package/dist/errors/index.d.ts +1 -0
- package/dist/errors/index.d.ts.map +1 -1
- package/dist/errors/index.js +1 -0
- package/dist/errors/safe/safe-rules-errors.d.ts +72 -0
- package/dist/errors/safe/safe-rules-errors.d.ts.map +1 -1
- package/dist/errors/safe/safe-rules-errors.js +113 -1
- package/dist/helpers/crypto/cryptography-helpers.d.ts +37 -0
- package/dist/helpers/crypto/cryptography-helpers.d.ts.map +1 -0
- package/dist/helpers/crypto/cryptography-helpers.js +65 -0
- package/dist/helpers/index.d.ts +1 -0
- package/dist/helpers/index.d.ts.map +1 -1
- package/dist/helpers/index.js +1 -0
- package/dist/helpers/object-validation-helpers.d.ts +8 -1
- package/dist/helpers/object-validation-helpers.d.ts.map +1 -1
- package/dist/helpers/object-validation-helpers.js +22 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +5 -0
- package/dist/models/authorization/authorization-models.d.ts +81 -0
- package/dist/models/authorization/authorization-models.d.ts.map +1 -0
- package/dist/models/authorization/authorization-models.js +33 -0
- package/dist/models/crypto/crypto-models.d.ts +5 -0
- package/dist/models/crypto/crypto-models.d.ts.map +1 -0
- package/dist/models/crypto/crypto-models.js +3 -0
- package/dist/models/index.d.ts +5 -0
- package/dist/models/index.d.ts.map +1 -1
- package/dist/models/index.js +5 -0
- package/dist/models/rules/share-rule-models.d.ts +42 -19
- package/dist/models/rules/share-rule-models.d.ts.map +1 -1
- package/dist/models/rules/share-rule-models.js +9 -8
- package/dist/models/safe/safe-transactions.d.ts +81 -0
- package/dist/models/safe/safe-transactions.d.ts.map +1 -0
- package/dist/models/safe/safe-transactions.js +26 -0
- package/dist/models/share-data/share-data.d.ts +1 -0
- package/dist/models/share-data/share-data.d.ts.map +1 -1
- package/dist/models/share-data/share-data.js +1 -0
- package/package.json +4 -3
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.getDecodedJwtSignedTokenPayload = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
/**
|
|
9
|
+
* This function gets the decoded payload from a signed JWT token.
|
|
10
|
+
*
|
|
11
|
+
* @param token the token to get the payload from
|
|
12
|
+
*/
|
|
13
|
+
const getDecodedJwtSignedTokenPayload = (token) => {
|
|
14
|
+
const payload = jsonwebtoken_1.default.decode(token);
|
|
15
|
+
return payload;
|
|
16
|
+
};
|
|
17
|
+
exports.getDecodedJwtSignedTokenPayload = getDecodedJwtSignedTokenPayload;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import jwt from 'jsonwebtoken';
|
|
2
|
+
/**
|
|
3
|
+
* This verifies a JWT signed token with the given secret key or public key.
|
|
4
|
+
*
|
|
5
|
+
* @param tokenToVerify the jwt token to verify
|
|
6
|
+
* @param secretKey the secret key to verify the token with
|
|
7
|
+
* @param publicKey the public key to verify the token with
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
declare const verifyJwtSignedToken: (tokenToVerify: string, secretKey?: string, publicKey?: string) => string | jwt.JwtPayload;
|
|
11
|
+
export { verifyJwtSignedToken };
|
|
12
|
+
//# sourceMappingURL=verify-jwt-signed-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-jwt-signed-token.d.ts","sourceRoot":"","sources":["../../../../src/authorization/jwt/verify/verify-jwt-signed-token.ts"],"names":[],"mappings":"AAAA,OAAO,GAAG,MAAM,cAAc,CAAC;AAQ/B;;;;;;;GAOG;AACH,QAAA,MAAM,oBAAoB,kBACP,MAAM,cACT,MAAM,cACN,MAAM,KACnB,MAAM,GAAG,GAAG,CAAC,UAgBf,CAAC;AAEF,OAAO,EAAE,oBAAoB,EAAE,CAAC"}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.verifyJwtSignedToken = void 0;
|
|
7
|
+
const jsonwebtoken_1 = __importDefault(require("jsonwebtoken"));
|
|
8
|
+
const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
|
|
9
|
+
const create_public_key_pem_1 = require("../keys/create-public-key-pem");
|
|
10
|
+
const create_secret_key_pem_1 = require("../keys/create-secret-key-pem");
|
|
11
|
+
/**
|
|
12
|
+
* This verifies a JWT signed token with the given secret key or public key.
|
|
13
|
+
*
|
|
14
|
+
* @param tokenToVerify the jwt token to verify
|
|
15
|
+
* @param secretKey the secret key to verify the token with
|
|
16
|
+
* @param publicKey the public key to verify the token with
|
|
17
|
+
* @returns
|
|
18
|
+
*/
|
|
19
|
+
const verifyJwtSignedToken = (tokenToVerify, secretKey, publicKey) => {
|
|
20
|
+
// break the token apart
|
|
21
|
+
const jwtTokenParts = tokenToVerify.split('.');
|
|
22
|
+
if (jwtTokenParts.length !== 3) {
|
|
23
|
+
throw new authorization_errors_1.SafeAuthorizationTokenNotBase64Error();
|
|
24
|
+
}
|
|
25
|
+
if (!secretKey && !publicKey) {
|
|
26
|
+
throw new authorization_errors_1.SafeAuthorizationKeyNotIncludedForVerificationError();
|
|
27
|
+
}
|
|
28
|
+
// create the key
|
|
29
|
+
const jwtKey = (secretKey) ? (0, create_secret_key_pem_1.createSecretKeyPem)(secretKey) : (0, create_public_key_pem_1.createPublicKeyPem)(publicKey);
|
|
30
|
+
// verify the token
|
|
31
|
+
const payload = jsonwebtoken_1.default.verify(tokenToVerify, jwtKey);
|
|
32
|
+
return payload;
|
|
33
|
+
};
|
|
34
|
+
exports.verifyJwtSignedToken = verifyJwtSignedToken;
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { IAuthorizationIssuer, IJWTAuthority } from '../../../models/authorization/authorization-models';
|
|
2
|
+
/**
|
|
3
|
+
* This class is used to keep and maintain the authorized authorities in the SAFE system.
|
|
4
|
+
*/
|
|
5
|
+
export declare class AuthorizedAuthorities {
|
|
6
|
+
private _authorizedJWTProviders;
|
|
7
|
+
private _currentJWTProvidersHash;
|
|
8
|
+
constructor();
|
|
9
|
+
/**
|
|
10
|
+
* This adds a JWT authority to the authorized authorities.
|
|
11
|
+
* @param authority the authority to add
|
|
12
|
+
* @param publicKey the public key for the authority
|
|
13
|
+
*/
|
|
14
|
+
addJWTAuthority(authority: IAuthorizationIssuer, publicKey: string): void;
|
|
15
|
+
/**
|
|
16
|
+
* This removes a JWT authority from the authorized authorities.
|
|
17
|
+
*
|
|
18
|
+
* @param authority the authority to remove
|
|
19
|
+
*/
|
|
20
|
+
removeJWTAuthority(authority: IAuthorizationIssuer): void;
|
|
21
|
+
/**
|
|
22
|
+
* This gets the public key for the given authority.
|
|
23
|
+
*
|
|
24
|
+
* @param authority the authority to get the public key for
|
|
25
|
+
* @returns
|
|
26
|
+
*/
|
|
27
|
+
getJWTAuthorityPublicKey(authority: IAuthorizationIssuer): string | undefined;
|
|
28
|
+
/**
|
|
29
|
+
* This gets all the authorized JWT providers.
|
|
30
|
+
* @returns
|
|
31
|
+
*/
|
|
32
|
+
getJWTProviders(): IJWTAuthority;
|
|
33
|
+
/**
|
|
34
|
+
* This gets the number of authorized JWT providers.
|
|
35
|
+
* @returns
|
|
36
|
+
*/
|
|
37
|
+
getJWTProviderCount(): number;
|
|
38
|
+
}
|
|
39
|
+
//# sourceMappingURL=authorized-authorities.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"authorized-authorities.d.ts","sourceRoot":"","sources":["../../../../src/authorization/safe/authorization/authorized-authorities.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,oBAAoB,EAAE,aAAa,EAAE,MAAM,oDAAoD,CAAC;AAEzG;;GAEG;AACH,qBAAa,qBAAqB;IAC9B,OAAO,CAAC,uBAAuB,CAAgB;IAC/C,OAAO,CAAC,wBAAwB,CAAS;;IAOzC;;;;OAIG;IACI,eAAe,CAAC,SAAS,EAAE,oBAAoB,EAAE,SAAS,EAAE,MAAM,GAAG,IAAI;IAIhF;;;;OAIG;IACI,kBAAkB,CAAC,SAAS,EAAE,oBAAoB,GAAG,IAAI;IAOhE;;;;;OAKG;IACI,wBAAwB,CAAC,SAAS,EAAE,oBAAoB,GAAG,MAAM,GAAG,SAAS;IAIpF;;;OAGG;IACI,eAAe,IAAI,aAAa;IAIvC;;;OAGG;IACI,mBAAmB,IAAI,MAAM;CAMvC"}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.AuthorizedAuthorities = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
|
|
5
|
+
/**
|
|
6
|
+
* This class is used to keep and maintain the authorized authorities in the SAFE system.
|
|
7
|
+
*/
|
|
8
|
+
class AuthorizedAuthorities {
|
|
9
|
+
constructor() {
|
|
10
|
+
this._authorizedJWTProviders = new Map();
|
|
11
|
+
this._currentJWTProvidersHash = '';
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* This adds a JWT authority to the authorized authorities.
|
|
15
|
+
* @param authority the authority to add
|
|
16
|
+
* @param publicKey the public key for the authority
|
|
17
|
+
*/
|
|
18
|
+
addJWTAuthority(authority, publicKey) {
|
|
19
|
+
this._authorizedJWTProviders.set(authority, publicKey);
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* This removes a JWT authority from the authorized authorities.
|
|
23
|
+
*
|
|
24
|
+
* @param authority the authority to remove
|
|
25
|
+
*/
|
|
26
|
+
removeJWTAuthority(authority) {
|
|
27
|
+
const removed = this._authorizedJWTProviders.delete(authority);
|
|
28
|
+
if (!removed) {
|
|
29
|
+
throw new authorization_errors_1.SafeAuthorizationIssuerDoesNotExistError(authority);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
/**
|
|
33
|
+
* This gets the public key for the given authority.
|
|
34
|
+
*
|
|
35
|
+
* @param authority the authority to get the public key for
|
|
36
|
+
* @returns
|
|
37
|
+
*/
|
|
38
|
+
getJWTAuthorityPublicKey(authority) {
|
|
39
|
+
return this._authorizedJWTProviders.get(authority);
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* This gets all the authorized JWT providers.
|
|
43
|
+
* @returns
|
|
44
|
+
*/
|
|
45
|
+
getJWTProviders() {
|
|
46
|
+
return this._authorizedJWTProviders;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* This gets the number of authorized JWT providers.
|
|
50
|
+
* @returns
|
|
51
|
+
*/
|
|
52
|
+
getJWTProviderCount() {
|
|
53
|
+
return this._authorizedJWTProviders.size;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
exports.AuthorizedAuthorities = AuthorizedAuthorities;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IDecodedJwtToken } from '../../../models/authorization/authorization-models';
|
|
2
|
+
/**
|
|
3
|
+
* This function decodes the bearer token and verifies the issuer is as expected.
|
|
4
|
+
*
|
|
5
|
+
* @param bearerToken the bearer token to decode
|
|
6
|
+
* @param verificationKey the key to verify the token with
|
|
7
|
+
* @param issuerExpected the expected issuer of the token
|
|
8
|
+
*/
|
|
9
|
+
declare const decodeBearerToken: (bearerToken: string, verificationKey: string, issuerExpected: string) => IDecodedJwtToken;
|
|
10
|
+
export { decodeBearerToken };
|
|
11
|
+
//# sourceMappingURL=decode-bearer-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-bearer-token.d.ts","sourceRoot":"","sources":["../../../../src/authorization/safe/request/decode-bearer-token.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AAKtF;;;;;;GAMG;AACH,QAAA,MAAM,iBAAiB,gBAAiB,MAAM,mBAAmB,MAAM,kBAAkB,MAAM,KAAG,gBAkBjG,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeBearerToken = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
|
|
5
|
+
const transform_token_payload_to_safe_payload_1 = require("../../jwt/transform/transform-token-payload-to-safe-payload");
|
|
6
|
+
const verify_jwt_signed_token_1 = require("../../jwt/verify/verify-jwt-signed-token");
|
|
7
|
+
const verify_token_payload_1 = require("../validation/jwt/verify-token-payload");
|
|
8
|
+
/**
|
|
9
|
+
* This function decodes the bearer token and verifies the issuer is as expected.
|
|
10
|
+
*
|
|
11
|
+
* @param bearerToken the bearer token to decode
|
|
12
|
+
* @param verificationKey the key to verify the token with
|
|
13
|
+
* @param issuerExpected the expected issuer of the token
|
|
14
|
+
*/
|
|
15
|
+
const decodeBearerToken = (bearerToken, verificationKey, issuerExpected) => {
|
|
16
|
+
const decodedToken = (0, verify_jwt_signed_token_1.verifyJwtSignedToken)(bearerToken, verificationKey);
|
|
17
|
+
if (!decodedToken || typeof decodedToken === 'string') {
|
|
18
|
+
throw new authorization_errors_1.SafeAuthorizationTokenNotObjectError();
|
|
19
|
+
}
|
|
20
|
+
if (issuerExpected !== decodedToken.iss) {
|
|
21
|
+
throw new authorization_errors_1.SafeAuthorizationIssuerNotMatchingExpectedError(issuerExpected, decodedToken.iss.toString());
|
|
22
|
+
}
|
|
23
|
+
// validate the token payload
|
|
24
|
+
if (!(0, verify_token_payload_1.verifyTokenPayload)(decodedToken)) {
|
|
25
|
+
throw new authorization_errors_1.SafeAuthorizationPayloadNotValidError();
|
|
26
|
+
}
|
|
27
|
+
// transform the token payload to a safe payload
|
|
28
|
+
const decodedTokenPayload = (0, transform_token_payload_to_safe_payload_1.transformTokenPayloadToSafePayload)(decodedToken);
|
|
29
|
+
return decodedTokenPayload;
|
|
30
|
+
};
|
|
31
|
+
exports.decodeBearerToken = decodeBearerToken;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { IDecodedJwtToken } from '../../../models/authorization/authorization-models';
|
|
2
|
+
/**
|
|
3
|
+
* This function decodes the safe request and returns the decoded token.
|
|
4
|
+
* This will throw an error if the request is not authorized.
|
|
5
|
+
*
|
|
6
|
+
* @param req the request to ensure authorization exists on.
|
|
7
|
+
* @returns
|
|
8
|
+
*/
|
|
9
|
+
declare const decodeSafeRequest: (req: any, verificationKey: string, issuerExpected: string) => IDecodedJwtToken;
|
|
10
|
+
export { decodeSafeRequest };
|
|
11
|
+
//# sourceMappingURL=decode-safe-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"decode-safe-request.d.ts","sourceRoot":"","sources":["../../../../src/authorization/safe/request/decode-safe-request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,gBAAgB,EAAE,MAAM,oDAAoD,CAAC;AAEtF;;;;;;GAMG;AACH,QAAA,MAAM,iBAAiB,QAAS,GAAG,mBAAmB,MAAM,kBAAkB,MAAM,KAAG,gBAatF,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.decodeSafeRequest = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
|
|
5
|
+
const decode_bearer_token_1 = require("./decode-bearer-token");
|
|
6
|
+
/**
|
|
7
|
+
* This function decodes the safe request and returns the decoded token.
|
|
8
|
+
* This will throw an error if the request is not authorized.
|
|
9
|
+
*
|
|
10
|
+
* @param req the request to ensure authorization exists on.
|
|
11
|
+
* @returns
|
|
12
|
+
*/
|
|
13
|
+
const decodeSafeRequest = (req, verificationKey, issuerExpected) => {
|
|
14
|
+
if (!req.headers)
|
|
15
|
+
throw new authorization_errors_1.SafeRequestAuthorizationHeadersNotFound();
|
|
16
|
+
if (!req.headers.authorization)
|
|
17
|
+
throw new authorization_errors_1.SafeRequestAuthorizationHeaderNotFound();
|
|
18
|
+
if (typeof req.headers.authorization === 'string' && req.headers.authorization.startsWith('Bearer ')) {
|
|
19
|
+
const bearerToken = req.headers.authorization.split('Bearer ')[1];
|
|
20
|
+
if (!bearerToken) {
|
|
21
|
+
throw new authorization_errors_1.SafeAuthorizationBearerTokenNotFound();
|
|
22
|
+
}
|
|
23
|
+
const decodedToken = (0, decode_bearer_token_1.decodeBearerToken)(bearerToken, verificationKey, issuerExpected);
|
|
24
|
+
return decodedToken;
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new authorization_errors_1.SafeAuthorizationBearerTokenNotFound();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
exports.decodeSafeRequest = decodeSafeRequest;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IAuthorizationIssuer } from '../../../models/authorization/authorization-models';
|
|
2
|
+
/**
|
|
3
|
+
* This function determines the issuer from the request.
|
|
4
|
+
*
|
|
5
|
+
* @param req the request to determine the issuer from
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
declare const determineIssuerFromRequest: (req: any) => IAuthorizationIssuer;
|
|
9
|
+
export { determineIssuerFromRequest };
|
|
10
|
+
//# sourceMappingURL=determine-issuer-from-request.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"determine-issuer-from-request.d.ts","sourceRoot":"","sources":["../../../../src/authorization/safe/request/determine-issuer-from-request.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,oDAAoD,CAAC;AAG1F;;;;;GAKG;AACH,QAAA,MAAM,0BAA0B,QAAS,GAAG,KAAG,oBAa9C,CAAA;AAED,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.determineIssuerFromRequest = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../errors/authorization/authorization-errors");
|
|
5
|
+
const determine_issuer_from_bearer_token_1 = require("./issuer/determine-issuer-from-bearer-token");
|
|
6
|
+
/**
|
|
7
|
+
* This function determines the issuer from the request.
|
|
8
|
+
*
|
|
9
|
+
* @param req the request to determine the issuer from
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
const determineIssuerFromRequest = (req) => {
|
|
13
|
+
if (!req.headers)
|
|
14
|
+
throw new authorization_errors_1.SafeRequestAuthorizationHeadersNotFound();
|
|
15
|
+
if (!req.headers.authorization)
|
|
16
|
+
throw new authorization_errors_1.SafeRequestAuthorizationHeaderNotFound();
|
|
17
|
+
if (typeof req.headers.authorization === 'string' && req.headers.authorization.startsWith('Bearer ')) {
|
|
18
|
+
const bearerToken = req.headers.authorization.split('Bearer ')[1];
|
|
19
|
+
if (!bearerToken) {
|
|
20
|
+
throw new authorization_errors_1.SafeAuthorizationBearerTokenNotFound();
|
|
21
|
+
}
|
|
22
|
+
const issuer = (0, determine_issuer_from_bearer_token_1.determineIssuerFromBearerToken)(bearerToken);
|
|
23
|
+
return issuer;
|
|
24
|
+
}
|
|
25
|
+
else {
|
|
26
|
+
throw new authorization_errors_1.SafeAuthorizationBearerTokenNotFound();
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.determineIssuerFromRequest = determineIssuerFromRequest;
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { IAuthorizationIssuer } from '../../../../models/authorization/authorization-models';
|
|
2
|
+
/**
|
|
3
|
+
* This function determines the issuer from the bearer token (if it exists).
|
|
4
|
+
* doesn't validate the signature of the token, just that the shape is correct and
|
|
5
|
+
* can be used to determine the signature to use to validate the token.
|
|
6
|
+
*
|
|
7
|
+
* @param bearerToken the bearer token to determine the issuer from
|
|
8
|
+
* @returns
|
|
9
|
+
*/
|
|
10
|
+
declare const determineIssuerFromBearerToken: (bearerToken: string) => IAuthorizationIssuer;
|
|
11
|
+
export { determineIssuerFromBearerToken };
|
|
12
|
+
//# sourceMappingURL=determine-issuer-from-bearer-token.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"determine-issuer-from-bearer-token.d.ts","sourceRoot":"","sources":["../../../../../src/authorization/safe/request/issuer/determine-issuer-from-bearer-token.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,oBAAoB,EAAE,MAAM,uDAAuD,CAAC;AAI7F;;;;;;;GAOG;AACH,QAAA,MAAM,8BAA8B,gBAAiB,MAAM,KAAG,oBAiB7D,CAAC;AAEF,OAAO,EAAE,8BAA8B,EAAE,CAAC"}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.determineIssuerFromBearerToken = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../../errors/authorization/authorization-errors");
|
|
5
|
+
const get_decoded_jwt_signed_token_payload_1 = require("../../../jwt/verify/get-decoded-jwt-signed-token-payload");
|
|
6
|
+
const verify_authorization_issuer_1 = require("../../validation/jwt/payload/verify-authorization-issuer");
|
|
7
|
+
/**
|
|
8
|
+
* This function determines the issuer from the bearer token (if it exists).
|
|
9
|
+
* doesn't validate the signature of the token, just that the shape is correct and
|
|
10
|
+
* can be used to determine the signature to use to validate the token.
|
|
11
|
+
*
|
|
12
|
+
* @param bearerToken the bearer token to determine the issuer from
|
|
13
|
+
* @returns
|
|
14
|
+
*/
|
|
15
|
+
const determineIssuerFromBearerToken = (bearerToken) => {
|
|
16
|
+
const decodedToken = (0, get_decoded_jwt_signed_token_payload_1.getDecodedJwtSignedTokenPayload)(bearerToken); // get the payload from the token
|
|
17
|
+
if (decodedToken === null || typeof decodedToken === 'string') {
|
|
18
|
+
throw new authorization_errors_1.SafeAuthorizationTokenNotObjectError();
|
|
19
|
+
}
|
|
20
|
+
// make sure the iss property exists
|
|
21
|
+
if (!decodedToken.iss) {
|
|
22
|
+
throw new authorization_errors_1.SafeAuthorizationTokenPropertyDataTypeNotValidError('iss', decodedToken.iss, 'string');
|
|
23
|
+
}
|
|
24
|
+
// make sure the type is an issuer
|
|
25
|
+
if (!(0, verify_authorization_issuer_1.verifyAuthorizationIssuer)(decodedToken.iss)) {
|
|
26
|
+
throw new authorization_errors_1.SafeAuthorizationIssuerNotValidError(decodedToken.iss);
|
|
27
|
+
}
|
|
28
|
+
return decodedToken.iss;
|
|
29
|
+
};
|
|
30
|
+
exports.determineIssuerFromBearerToken = determineIssuerFromBearerToken;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { AuthorizationAudience } from '../../../../../models/authorization/authorization-models';
|
|
2
|
+
/**
|
|
3
|
+
* This verifiies the audience of the token
|
|
4
|
+
*
|
|
5
|
+
* @param aud the audience to verify
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
declare const verifyAuthorizationAudience: (aud: unknown) => aud is AuthorizationAudience;
|
|
9
|
+
export { verifyAuthorizationAudience };
|
|
10
|
+
//# sourceMappingURL=verify-authorization-audience.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-authorization-audience.d.ts","sourceRoot":"","sources":["../../../../../../src/authorization/safe/validation/jwt/payload/verify-authorization-audience.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,qBAAqB,EAAE,MAAM,0DAA0D,CAAC;AAEjG;;;;;GAKG;AACH,QAAA,MAAM,2BAA2B,QAAS,OAAO,KAAG,GAAG,IAAI,qBAc1D,CAAA;AAED,OAAO,EAAE,2BAA2B,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyAuthorizationAudience = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../../../errors/authorization/authorization-errors");
|
|
5
|
+
const authorization_models_1 = require("../../../../../models/authorization/authorization-models");
|
|
6
|
+
/**
|
|
7
|
+
* This verifiies the audience of the token
|
|
8
|
+
*
|
|
9
|
+
* @param aud the audience to verify
|
|
10
|
+
* @returns
|
|
11
|
+
*/
|
|
12
|
+
const verifyAuthorizationAudience = (aud) => {
|
|
13
|
+
if (!aud) {
|
|
14
|
+
throw new authorization_errors_1.SafeAuthorizationMissingPropertyError('aud');
|
|
15
|
+
}
|
|
16
|
+
if (typeof aud !== 'string') {
|
|
17
|
+
throw new authorization_errors_1.SafeAuthorizationTokenPropertyDataTypeNotValidError('aud', aud, 'string');
|
|
18
|
+
}
|
|
19
|
+
if (!Object.values(authorization_models_1.AuthorizationAudience).includes(aud)) {
|
|
20
|
+
throw new authorization_errors_1.SafeAuthorizationPayloadNotValidError();
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
exports.verifyAuthorizationAudience = verifyAuthorizationAudience;
|
package/dist/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* this function validates the expiration time of the token hasn't passed
|
|
3
|
+
*
|
|
4
|
+
* @param exp the expiration time of the token
|
|
5
|
+
*/
|
|
6
|
+
declare const verifyAuthorizationExpirationTime: (exp: unknown) => exp is number;
|
|
7
|
+
export { verifyAuthorizationExpirationTime };
|
|
8
|
+
//# sourceMappingURL=verify-authorization-expiration-time.d.ts.map
|
package/dist/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-authorization-expiration-time.d.ts","sourceRoot":"","sources":["../../../../../../src/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.ts"],"names":[],"mappings":"AAMA;;;;GAIG;AACH,QAAA,MAAM,iCAAiC,QAAS,OAAO,KAAG,GAAG,IAAI,MAchE,CAAC;AAEF,OAAO,EAAE,iCAAiC,EAAE,CAAC"}
|
package/dist/authorization/safe/validation/jwt/payload/verify-authorization-expiration-time.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyAuthorizationExpirationTime = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../../../errors/authorization/authorization-errors");
|
|
5
|
+
/**
|
|
6
|
+
* this function validates the expiration time of the token hasn't passed
|
|
7
|
+
*
|
|
8
|
+
* @param exp the expiration time of the token
|
|
9
|
+
*/
|
|
10
|
+
const verifyAuthorizationExpirationTime = (exp) => {
|
|
11
|
+
if (!exp) {
|
|
12
|
+
throw new authorization_errors_1.SafeAuthorizationMissingPropertyError('exp');
|
|
13
|
+
}
|
|
14
|
+
if (typeof exp !== 'number') {
|
|
15
|
+
throw new authorization_errors_1.SafeAuthorizationTokenPropertyDataTypeNotValidError('exp', exp, 'number');
|
|
16
|
+
}
|
|
17
|
+
const currentTime = new Date().getTime() / 1000; // get the current time in unix format
|
|
18
|
+
if (exp < currentTime) {
|
|
19
|
+
throw new authorization_errors_1.SafeAuthorizationPayloadNotValidError();
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
exports.verifyAuthorizationExpirationTime = verifyAuthorizationExpirationTime;
|
package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.d.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function verifies that the issued at time is valid.
|
|
3
|
+
*
|
|
4
|
+
* @param iat the issued at time to verify
|
|
5
|
+
* @returns void (throws an error if the iat is not valid)
|
|
6
|
+
*/
|
|
7
|
+
declare const verifyAuthorizationIssuedAtTime: (iat: unknown) => iat is number;
|
|
8
|
+
export { verifyAuthorizationIssuedAtTime };
|
|
9
|
+
//# sourceMappingURL=verify-authorization-issued-at-time.d.ts.map
|
package/dist/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-authorization-issued-at-time.d.ts","sourceRoot":"","sources":["../../../../../../src/authorization/safe/validation/jwt/payload/verify-authorization-issued-at-time.ts"],"names":[],"mappings":"AAMA;;;;;GAKG;AACH,QAAA,MAAM,+BAA+B,QAAS,OAAO,KAAG,GAAG,IAAI,MAc9D,CAAC;AAEF,OAAO,EAAE,+BAA+B,EAAE,CAAC"}
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyAuthorizationIssuedAtTime = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../../../errors/authorization/authorization-errors");
|
|
5
|
+
/**
|
|
6
|
+
* This function verifies that the issued at time is valid.
|
|
7
|
+
*
|
|
8
|
+
* @param iat the issued at time to verify
|
|
9
|
+
* @returns void (throws an error if the iat is not valid)
|
|
10
|
+
*/
|
|
11
|
+
const verifyAuthorizationIssuedAtTime = (iat) => {
|
|
12
|
+
if (!iat) {
|
|
13
|
+
throw new authorization_errors_1.SafeAuthorizationMissingPropertyError('iat');
|
|
14
|
+
}
|
|
15
|
+
if (typeof iat !== 'number') {
|
|
16
|
+
throw new authorization_errors_1.SafeAuthorizationTokenPropertyDataTypeNotValidError('iat', iat, 'number');
|
|
17
|
+
}
|
|
18
|
+
const currentTime = new Date().getTime() / 1000; // get the current time in unix format
|
|
19
|
+
if (iat > currentTime) {
|
|
20
|
+
throw new authorization_errors_1.SafeAuthorizationPayloadNotValidError();
|
|
21
|
+
}
|
|
22
|
+
return true;
|
|
23
|
+
};
|
|
24
|
+
exports.verifyAuthorizationIssuedAtTime = verifyAuthorizationIssuedAtTime;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IAuthorizationIssuer } from '../../../../../models/authorization/authorization-models';
|
|
2
|
+
/**
|
|
3
|
+
* This function verifies that the incoming object is a valid authorization issuer.
|
|
4
|
+
*
|
|
5
|
+
* @param iss the object to verify
|
|
6
|
+
* @returns
|
|
7
|
+
*/
|
|
8
|
+
declare const verifyAuthorizationIssuer: (iss: unknown) => iss is IAuthorizationIssuer;
|
|
9
|
+
export { verifyAuthorizationIssuer };
|
|
10
|
+
//# sourceMappingURL=verify-authorization-issuer.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-authorization-issuer.d.ts","sourceRoot":"","sources":["../../../../../../src/authorization/safe/validation/jwt/payload/verify-authorization-issuer.ts"],"names":[],"mappings":"AAIA,OAAO,EAAE,oBAAoB,EAAE,MAAM,0DAA0D,CAAC;AAEhG;;;;;GAKG;AACH,QAAA,MAAM,yBAAyB,QAAS,OAAO,KAAG,GAAG,IAAI,oBAexD,CAAC;AAEF,OAAO,EAAE,yBAAyB,EAAE,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyAuthorizationIssuer = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../../../errors/authorization/authorization-errors");
|
|
5
|
+
/**
|
|
6
|
+
* This function verifies that the incoming object is a valid authorization issuer.
|
|
7
|
+
*
|
|
8
|
+
* @param iss the object to verify
|
|
9
|
+
* @returns
|
|
10
|
+
*/
|
|
11
|
+
const verifyAuthorizationIssuer = (iss) => {
|
|
12
|
+
if (!iss) {
|
|
13
|
+
throw new authorization_errors_1.SafeAuthorizationMissingPropertyError('iss');
|
|
14
|
+
}
|
|
15
|
+
if (typeof iss !== 'string') {
|
|
16
|
+
throw new authorization_errors_1.SafeAuthorizationTokenPropertyDataTypeNotValidError('iss', iss, 'string');
|
|
17
|
+
}
|
|
18
|
+
const regex = /^[a-zA-Z0-9]+-[0-9a-fA-F]{8}$/; // make sure the incoming object is in the format of the authorization issuer
|
|
19
|
+
const isValidShape = regex.test(iss); // check if the incoming object is in the correct format
|
|
20
|
+
if (!isValidShape) { // if the incoming object is not in the correct format
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return true;
|
|
24
|
+
};
|
|
25
|
+
exports.verifyAuthorizationIssuer = verifyAuthorizationIssuer;
|
package/dist/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.d.ts
ADDED
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This function verifies that the not before time is valid.
|
|
3
|
+
*
|
|
4
|
+
* @param nbf the not before time is the time before which the token is not valid
|
|
5
|
+
*/
|
|
6
|
+
declare const verifyAuthorizationNotBeforeTime: (nbf: unknown) => nbf is number;
|
|
7
|
+
export { verifyAuthorizationNotBeforeTime };
|
|
8
|
+
//# sourceMappingURL=verify-authorization-not-before-time.d.ts.map
|
package/dist/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.d.ts.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-authorization-not-before-time.d.ts","sourceRoot":"","sources":["../../../../../../src/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AACH,QAAA,MAAM,gCAAgC,QAAS,OAAO,KAAG,GAAG,IAAI,MAc/D,CAAC;AAEF,OAAO,EAAE,gCAAgC,EAAE,CAAC"}
|
package/dist/authorization/safe/validation/jwt/payload/verify-authorization-not-before-time.js
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyAuthorizationNotBeforeTime = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../../../errors/authorization/authorization-errors");
|
|
5
|
+
/**
|
|
6
|
+
* This function verifies that the not before time is valid.
|
|
7
|
+
*
|
|
8
|
+
* @param nbf the not before time is the time before which the token is not valid
|
|
9
|
+
*/
|
|
10
|
+
const verifyAuthorizationNotBeforeTime = (nbf) => {
|
|
11
|
+
if (!nbf) {
|
|
12
|
+
throw new authorization_errors_1.SafeAuthorizationMissingPropertyError('nbf');
|
|
13
|
+
}
|
|
14
|
+
if (typeof nbf !== 'number') {
|
|
15
|
+
throw new authorization_errors_1.SafeAuthorizationTokenPropertyDataTypeNotValidError('nbf', nbf, 'number');
|
|
16
|
+
}
|
|
17
|
+
const currentTime = new Date().getTime() / 1000; // get the current time in unix format
|
|
18
|
+
if (nbf > currentTime) {
|
|
19
|
+
throw new authorization_errors_1.SafeAuthorizationPayloadNotValidError();
|
|
20
|
+
}
|
|
21
|
+
return true;
|
|
22
|
+
};
|
|
23
|
+
exports.verifyAuthorizationNotBeforeTime = verifyAuthorizationNotBeforeTime;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { IAuthorizationSubject } from '../../../../../models/authorization/authorization-models';
|
|
2
|
+
/**
|
|
3
|
+
* This function validates that the input string is a valid authorization subject.
|
|
4
|
+
*
|
|
5
|
+
* @param sub The input string to validate.
|
|
6
|
+
* @returns True if the input is a valid authorization subject, false otherwise.
|
|
7
|
+
*/
|
|
8
|
+
declare const verifyAuthorizationSubject: (sub: unknown) => sub is IAuthorizationSubject;
|
|
9
|
+
export { verifyAuthorizationSubject };
|
|
10
|
+
//# sourceMappingURL=verify-authorization-subject.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-authorization-subject.d.ts","sourceRoot":"","sources":["../../../../../../src/authorization/safe/validation/jwt/payload/verify-authorization-subject.ts"],"names":[],"mappings":"AAIA,OAAO,EACH,qBAAqB,EAExB,MAAM,0DAA0D,CAAC;AAElE;;;;;GAKG;AACH,QAAA,MAAM,0BAA0B,QAAS,OAAO,KAAG,GAAG,IAAI,qBASzD,CAAC;AAEF,OAAO,EAAE,0BAA0B,EAAE,CAAC"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.verifyAuthorizationSubject = void 0;
|
|
4
|
+
const authorization_errors_1 = require("../../../../../errors/authorization/authorization-errors");
|
|
5
|
+
const authorization_models_1 = require("../../../../../models/authorization/authorization-models");
|
|
6
|
+
/**
|
|
7
|
+
* This function validates that the input string is a valid authorization subject.
|
|
8
|
+
*
|
|
9
|
+
* @param sub The input string to validate.
|
|
10
|
+
* @returns True if the input is a valid authorization subject, false otherwise.
|
|
11
|
+
*/
|
|
12
|
+
const verifyAuthorizationSubject = (sub) => {
|
|
13
|
+
if (!sub) {
|
|
14
|
+
throw new authorization_errors_1.SafeAuthorizationMissingPropertyError('sub');
|
|
15
|
+
}
|
|
16
|
+
if (typeof sub !== 'string') {
|
|
17
|
+
throw new authorization_errors_1.SafeAuthorizationTokenPropertyDataTypeNotValidError('sub', sub, 'string');
|
|
18
|
+
}
|
|
19
|
+
const regex = new RegExp(`^(${Object.values(authorization_models_1.AuthorizationSubjectStart).join('|')}):.+$`);
|
|
20
|
+
return regex.test(sub);
|
|
21
|
+
};
|
|
22
|
+
exports.verifyAuthorizationSubject = verifyAuthorizationSubject;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* This validates that the header encoding is the expected encoding for the token
|
|
3
|
+
*
|
|
4
|
+
* @param token the token to validate the header of.
|
|
5
|
+
* @returns
|
|
6
|
+
*/
|
|
7
|
+
declare const verifyTokenHeader: (token: string) => boolean;
|
|
8
|
+
export { verifyTokenHeader };
|
|
9
|
+
//# sourceMappingURL=verify-token-header.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"verify-token-header.d.ts","sourceRoot":"","sources":["../../../../../src/authorization/safe/validation/jwt/verify-token-header.ts"],"names":[],"mappings":"AAIA;;;;;GAKG;AACH,QAAA,MAAM,iBAAiB,UAAW,MAAM,KAAG,OAc1C,CAAC;AAEF,OAAO,EAAE,iBAAiB,EAAE,CAAC"}
|