samlify 2.11.0 → 2.13.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 (83) hide show
  1. package/README.md +1 -1
  2. package/build/src/api.js +52 -3
  3. package/build/src/api.js.map +1 -1
  4. package/build/src/binding-post.js +236 -182
  5. package/build/src/binding-post.js.map +1 -1
  6. package/build/src/binding-redirect.js +303 -215
  7. package/build/src/binding-redirect.js.map +1 -1
  8. package/build/src/binding-simplesign.js +285 -137
  9. package/build/src/binding-simplesign.js.map +1 -1
  10. package/build/src/entity-idp.js +130 -47
  11. package/build/src/entity-idp.js.map +1 -1
  12. package/build/src/entity-sp.js +81 -39
  13. package/build/src/entity-sp.js.map +1 -1
  14. package/build/src/entity.js +100 -62
  15. package/build/src/entity.js.map +1 -1
  16. package/build/src/extractor.js +119 -155
  17. package/build/src/extractor.js.map +1 -1
  18. package/build/src/flow.js +100 -96
  19. package/build/src/flow.js.map +1 -1
  20. package/build/src/libsaml.js +318 -261
  21. package/build/src/libsaml.js.map +1 -1
  22. package/build/src/metadata-idp.js +60 -30
  23. package/build/src/metadata-idp.js.map +1 -1
  24. package/build/src/metadata-sp.js +51 -41
  25. package/build/src/metadata-sp.js.map +1 -1
  26. package/build/src/metadata.js +47 -43
  27. package/build/src/metadata.js.map +1 -1
  28. package/build/src/options.js +73 -0
  29. package/build/src/options.js.map +1 -0
  30. package/build/src/urn.js +28 -1
  31. package/build/src/urn.js.map +1 -1
  32. package/build/src/utility.js +165 -83
  33. package/build/src/utility.js.map +1 -1
  34. package/build/src/validator.js +27 -10
  35. package/build/src/validator.js.map +1 -1
  36. package/package.json +17 -7
  37. package/types/src/api.d.ts +33 -3
  38. package/types/src/binding-post.d.ts +67 -34
  39. package/types/src/binding-redirect.d.ts +58 -31
  40. package/types/src/binding-simplesign.d.ts +77 -21
  41. package/types/src/entity-idp.d.ts +40 -31
  42. package/types/src/entity-sp.d.ts +37 -27
  43. package/types/src/entity.d.ts +71 -77
  44. package/types/src/extractor.d.ts +31 -22
  45. package/types/src/flow.d.ts +24 -2
  46. package/types/src/libsaml.d.ts +172 -118
  47. package/types/src/metadata-idp.d.ts +27 -11
  48. package/types/src/metadata-sp.d.ts +29 -19
  49. package/types/src/metadata.d.ts +59 -34
  50. package/types/src/options.d.ts +37 -0
  51. package/types/src/types.d.ts +250 -24
  52. package/types/src/urn.d.ts +7 -0
  53. package/types/src/utility.d.ts +144 -89
  54. package/types/src/validator.d.ts +21 -0
  55. package/.circleci/config.yml +0 -98
  56. package/.editorconfig +0 -19
  57. package/.github/FUNDING.yml +0 -1
  58. package/.github/workflows/deploy-docs.yml +0 -56
  59. package/.pre-commit.sh +0 -15
  60. package/.snyk +0 -4
  61. package/Makefile +0 -25
  62. package/index.ts +0 -28
  63. package/src/api.ts +0 -36
  64. package/src/binding-post.ts +0 -336
  65. package/src/binding-redirect.ts +0 -335
  66. package/src/binding-simplesign.ts +0 -231
  67. package/src/entity-idp.ts +0 -145
  68. package/src/entity-sp.ts +0 -114
  69. package/src/entity.ts +0 -243
  70. package/src/extractor.ts +0 -399
  71. package/src/flow.ts +0 -469
  72. package/src/libsaml.ts +0 -777
  73. package/src/metadata-idp.ts +0 -146
  74. package/src/metadata-sp.ts +0 -203
  75. package/src/metadata.ts +0 -166
  76. package/src/types.ts +0 -127
  77. package/src/urn.ts +0 -210
  78. package/src/utility.ts +0 -231
  79. package/src/validator.ts +0 -44
  80. package/tsconfig.json +0 -41
  81. package/tslint.json +0 -35
  82. package/types.d.ts +0 -2
  83. package/vitest.config.ts +0 -12
package/src/urn.ts DELETED
@@ -1,210 +0,0 @@
1
- /**
2
- * @file urn.ts
3
- * @author tngan
4
- * @desc Includes all keywords need in samlify
5
- */
6
-
7
- export enum BindingNamespace {
8
- Redirect = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
9
- Post = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
10
- SimpleSign = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign',
11
- Artifact = 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact'
12
- }
13
-
14
- export enum MessageSignatureOrder {
15
- STE = 'sign-then-encrypt',
16
- ETS = 'encrypt-then-sign'
17
- }
18
-
19
- export enum StatusCode {
20
- // top-tier
21
- Success = 'urn:oasis:names:tc:SAML:2.0:status:Success',
22
- Requester = 'urn:oasis:names:tc:SAML:2.0:status:Requester',
23
- Responder = 'urn:oasis:names:tc:SAML:2.0:status:Responder',
24
- VersionMismatch = 'urn:oasis:names:tc:SAML:2.0:status:VersionMismatch',
25
- // second-tier to provide more information
26
- AuthFailed = 'urn:oasis:names:tc:SAML:2.0:status:AuthnFailed',
27
- InvalidAttrNameOrValue = 'urn:oasis:names:tc:SAML:2.0:status:InvalidAttrNameOrValue',
28
- InvalidNameIDPolicy = 'urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy',
29
- NoAuthnContext = 'urn:oasis:names:tc:SAML:2.0:status:NoAuthnContext',
30
- NoAvailableIDP = 'urn:oasis:names:tc:SAML:2.0:status:NoAvailableIDP',
31
- NoPassive = 'urn:oasis:names:tc:SAML:2.0:status:NoPassive',
32
- NoSupportedIDP = 'urn:oasis:names:tc:SAML:2.0:status:NoSupportedIDP',
33
- PartialLogout = 'urn:oasis:names:tc:SAML:2.0:status:PartialLogout',
34
- ProxyCountExceeded = 'urn:oasis:names:tc:SAML:2.0:status:ProxyCountExceeded',
35
- RequestDenied = 'urn:oasis:names:tc:SAML:2.0:status:RequestDenied',
36
- RequestUnsupported = 'urn:oasis:names:tc:SAML:2.0:status:RequestUnsupported',
37
- RequestVersionDeprecated = 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionDeprecated',
38
- RequestVersionTooHigh = 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionTooHigh',
39
- RequestVersionTooLow = 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionTooLow',
40
- ResourceNotRecognized = 'urn:oasis:names:tc:SAML:2.0:status:ResourceNotRecognized',
41
- TooManyResponses = 'urn:oasis:names:tc:SAML:2.0:status:TooManyResponses',
42
- UnknownAttrProfile = 'urn:oasis:names:tc:SAML:2.0:status:UnknownAttrProfile',
43
- UnknownPrincipal = 'urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal',
44
- UnsupportedBinding = 'urn:oasis:names:tc:SAML:2.0:status:UnsupportedBinding',
45
- }
46
-
47
- const namespace = {
48
- binding: {
49
- redirect: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Redirect',
50
- post: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST',
51
- simpleSign: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST-SimpleSign',
52
- artifact: 'urn:oasis:names:tc:SAML:2.0:bindings:HTTP-Artifact',
53
- },
54
- names: {
55
- protocol: 'urn:oasis:names:tc:SAML:2.0:protocol',
56
- assertion: 'urn:oasis:names:tc:SAML:2.0:assertion',
57
- metadata: 'urn:oasis:names:tc:SAML:2.0:metadata',
58
- userLogout: 'urn:oasis:names:tc:SAML:2.0:logout:user',
59
- adminLogout: 'urn:oasis:names:tc:SAML:2.0:logout:admin',
60
- },
61
- authnContextClassRef: {
62
- password: 'urn:oasis:names:tc:SAML:2.0:ac:classes:Password',
63
- passwordProtectedTransport: 'urn:oasis:names:tc:SAML:2.0:ac:classes:PasswordProtectedTransport',
64
- },
65
- format: {
66
- emailAddress: 'urn:oasis:names:tc:SAML:1.1:nameid-format:emailAddress',
67
- persistent: 'urn:oasis:names:tc:SAML:2.0:nameid-format:persistent',
68
- transient: 'urn:oasis:names:tc:SAML:2.0:nameid-format:transient',
69
- entity: 'urn:oasis:names:tc:SAML:2.0:nameid-format:entity',
70
- unspecified: 'urn:oasis:names:tc:SAML:1.1:nameid-format:unspecified',
71
- kerberos: 'urn:oasis:names:tc:SAML:2.0:nameid-format:kerberos',
72
- windowsDomainQualifiedName: 'urn:oasis:names:tc:SAML:1.1:nameid-format:WindowsDomainQualifiedName',
73
- x509SubjectName: 'urn:oasis:names:tc:SAML:1.1:nameid-format:X509SubjectName',
74
- },
75
- statusCode: {
76
- // permissible top-level status codes
77
- success: 'urn:oasis:names:tc:SAML:2.0:status:Success',
78
- requester: 'urn:oasis:names:tc:SAML:2.0:status:Requester',
79
- responder: 'urn:oasis:names:tc:SAML:2.0:status:Responder',
80
- versionMismatch: 'urn:oasis:names:tc:SAML:2.0:status:VersionMismatch',
81
- // second-level status codes
82
- authFailed: 'urn:oasis:names:tc:SAML:2.0:status:AuthnFailed',
83
- invalidAttrNameOrValue: 'urn:oasis:names:tc:SAML:2.0:status:InvalidAttrNameOrValue',
84
- invalidNameIDPolicy: 'urn:oasis:names:tc:SAML:2.0:status:InvalidNameIDPolicy',
85
- noAuthnContext: 'urn:oasis:names:tc:SAML:2.0:status:NoAuthnContext',
86
- noAvailableIDP: 'urn:oasis:names:tc:SAML:2.0:status:NoAvailableIDP',
87
- noPassive: 'urn:oasis:names:tc:SAML:2.0:status:NoPassive',
88
- noSupportedIDP: 'urn:oasis:names:tc:SAML:2.0:status:NoSupportedIDP',
89
- partialLogout: 'urn:oasis:names:tc:SAML:2.0:status:PartialLogout',
90
- proxyCountExceeded: 'urn:oasis:names:tc:SAML:2.0:status:ProxyCountExceeded',
91
- requestDenied: 'urn:oasis:names:tc:SAML:2.0:status:RequestDenied',
92
- requestUnsupported: 'urn:oasis:names:tc:SAML:2.0:status:RequestUnsupported',
93
- requestVersionDeprecated: 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionDeprecated',
94
- requestVersionTooHigh: 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionTooHigh',
95
- requestVersionTooLow: 'urn:oasis:names:tc:SAML:2.0:status:RequestVersionTooLow',
96
- resourceNotRecognized: 'urn:oasis:names:tc:SAML:2.0:status:ResourceNotRecognized',
97
- tooManyResponses: 'urn:oasis:names:tc:SAML:2.0:status:TooManyResponses',
98
- unknownAttrProfile: 'urn:oasis:names:tc:SAML:2.0:status:UnknownAttrProfile',
99
- unknownPrincipal: 'urn:oasis:names:tc:SAML:2.0:status:UnknownPrincipal',
100
- unsupportedBinding: 'urn:oasis:names:tc:SAML:2.0:status:UnsupportedBinding',
101
- },
102
- };
103
-
104
- const tags = {
105
- request: {
106
- AllowCreate: '{AllowCreate}',
107
- AssertionConsumerServiceURL: '{AssertionConsumerServiceURL}',
108
- AuthnContextClassRef: '{AuthnContextClassRef}',
109
- AssertionID: '{AssertionID}',
110
- Audience: '{Audience}',
111
- AuthnStatement: '{AuthnStatement}',
112
- AttributeStatement: '{AttributeStatement}',
113
- ConditionsNotBefore: '{ConditionsNotBefore}',
114
- ConditionsNotOnOrAfter: '{ConditionsNotOnOrAfter}',
115
- Destination: '{Destination}',
116
- EntityID: '{EntityID}',
117
- ID: '{ID}',
118
- Issuer: '{Issuer}',
119
- IssueInstant: '{IssueInstant}',
120
- InResponseTo: '{InResponseTo}',
121
- NameID: '{NameID}',
122
- NameIDFormat: '{NameIDFormat}',
123
- ProtocolBinding: '{ProtocolBinding}',
124
- SessionIndex: '{SessionIndex}',
125
- SubjectRecipient: '{SubjectRecipient}',
126
- SubjectConfirmationDataNotOnOrAfter: '{SubjectConfirmationDataNotOnOrAfter}',
127
- StatusCode: '{StatusCode}',
128
- },
129
- xmlTag: {
130
- loginRequest: 'AuthnRequest',
131
- logoutRequest: 'LogoutRequest',
132
- loginResponse: 'Response',
133
- logoutResponse: 'LogoutResponse',
134
- },
135
- };
136
-
137
- const messageConfigurations = {
138
- signingOrder: {
139
- SIGN_THEN_ENCRYPT: 'sign-then-encrypt',
140
- ENCRYPT_THEN_SIGN: 'encrypt-then-sign',
141
- },
142
- };
143
-
144
- const algorithms = {
145
- signature: {
146
- RSA_SHA1: 'http://www.w3.org/2000/09/xmldsig#rsa-sha1',
147
- RSA_SHA256: 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256',
148
- RSA_SHA512: 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512',
149
- },
150
- encryption: {
151
- data: {
152
- AES_128: 'http://www.w3.org/2001/04/xmlenc#aes128-cbc',
153
- AES_256: 'http://www.w3.org/2001/04/xmlenc#aes256-cbc',
154
- TRI_DEC: 'http://www.w3.org/2001/04/xmlenc#tripledes-cbc',
155
- AES_128_GCM: 'http://www.w3.org/2009/xmlenc11#aes128-gcm'
156
- },
157
- key: {
158
- RSA_OAEP_MGF1P: 'http://www.w3.org/2001/04/xmlenc#rsa-oaep-mgf1p',
159
- RSA_1_5: 'http://www.w3.org/2001/04/xmlenc#rsa-1_5',
160
- },
161
- },
162
- digest: {
163
- 'http://www.w3.org/2000/09/xmldsig#rsa-sha1': 'http://www.w3.org/2000/09/xmldsig#sha1',
164
- 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha256': 'http://www.w3.org/2001/04/xmlenc#sha256',
165
- 'http://www.w3.org/2001/04/xmldsig-more#rsa-sha512': 'http://www.w3.org/2001/04/xmlenc#sha512', // support hashing algorithm sha512 in xml-crypto after 0.8.0
166
- },
167
- };
168
-
169
- export enum ParserType {
170
- SAMLRequest = 'SAMLRequest',
171
- SAMLResponse = 'SAMLResponse',
172
- LogoutRequest = 'LogoutRequest',
173
- LogoutResponse = 'LogoutResponse'
174
- }
175
-
176
- const wording = {
177
- urlParams: {
178
- samlRequest: 'SAMLRequest',
179
- samlResponse: 'SAMLResponse',
180
- logoutRequest: 'LogoutRequest',
181
- logoutResponse: 'LogoutResponse',
182
- sigAlg: 'SigAlg',
183
- signature: 'Signature',
184
- relayState: 'RelayState',
185
- },
186
- binding: {
187
- redirect: 'redirect',
188
- post: 'post',
189
- simpleSign: 'simpleSign',
190
- artifact: 'artifact',
191
- },
192
- certUse: {
193
- signing: 'signing',
194
- encrypt: 'encryption',
195
- },
196
- metadata: {
197
- sp: 'metadata-sp',
198
- idp: 'metadata-idp',
199
- },
200
- };
201
-
202
- // https://wiki.shibboleth.net/confluence/display/CONCEPT/MetadataForSP
203
- // some idps restrict the order of elements in entity descriptors
204
- const elementsOrder = {
205
- default: ['KeyDescriptor', 'NameIDFormat', 'SingleLogoutService', 'AssertionConsumerService'],
206
- onelogin: ['KeyDescriptor', 'NameIDFormat', 'SingleLogoutService', 'AssertionConsumerService'],
207
- shibboleth: ['KeyDescriptor', 'SingleLogoutService', 'NameIDFormat', 'AssertionConsumerService', 'AttributeConsumingService'],
208
- };
209
-
210
- export { namespace, tags, algorithms, wording, elementsOrder, messageConfigurations };
package/src/utility.ts DELETED
@@ -1,231 +0,0 @@
1
- /**
2
- * @file utility.ts
3
- * @author tngan
4
- * @desc Library for some common functions (e.g. de/inflation, en/decoding)
5
- */
6
- import { X509Certificate, createPrivateKey } from 'crypto';
7
- import { deflateRawSync, inflateRawSync } from 'zlib';
8
-
9
- const BASE64_STR = 'base64';
10
-
11
- /**
12
- * @desc Mimic lodash.zipObject
13
- * @param arr1 {string[]}
14
- * @param arr2 {[]}
15
- */
16
- export function zipObject(arr1: string[], arr2: any[], skipDuplicated = true) {
17
- return arr1.reduce((res, l, i) => {
18
-
19
- if (skipDuplicated) {
20
- res[l] = arr2[i];
21
- return res;
22
- }
23
- // if key exists, aggregate with array in order to get rid of duplicate key
24
- if (res[l] !== undefined) {
25
- res[l] = Array.isArray(res[l])
26
- ? res[l].concat(arr2[i])
27
- : [res[l]].concat(arr2[i]);
28
- return res;
29
- }
30
-
31
- res[l] = arr2[i];
32
- return res;
33
-
34
- }, {});
35
- }
36
- /**
37
- * @desc Alternative to lodash.flattenDeep
38
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_flattendeep
39
- * @param input {[]}
40
- */
41
- export function flattenDeep(input: any[]) {
42
- return Array.isArray(input)
43
- ? input.reduce( (a, b) => a.concat(flattenDeep(b)) , [])
44
- : [input];
45
- }
46
- /**
47
- * @desc Alternative to lodash.last
48
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_last
49
- * @param input {[]}
50
- */
51
- export function last(input: any[]) {
52
- return input.slice(-1)[0];
53
- }
54
- /**
55
- * @desc Alternative to lodash.uniq
56
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_uniq
57
- * @param input {string[]}
58
- */
59
- export function uniq(input: string[]) {
60
- const set = new Set(input);
61
- return [... set];
62
- }
63
- /**
64
- * @desc Alternative to lodash.get
65
- * @reference https://github.com/you-dont-need/You-Dont-Need-Lodash-Underscore#_get
66
- * @param obj
67
- * @param path
68
- * @param defaultValue
69
- */
70
- export function get(obj, path, defaultValue) {
71
- return path.split('.')
72
- .reduce((a, c) => (a && a[c] ? a[c] : (defaultValue || null)), obj);
73
- }
74
- /**
75
- * @desc Check if the input is string
76
- * @param {any} input
77
- */
78
- export function isString(input: any) {
79
- return typeof input === 'string';
80
- }
81
- /**
82
- * @desc Encode string with base64 format
83
- * @param {string} message plain-text message
84
- * @return {string} base64 encoded string
85
- */
86
- function base64Encode(message: string | number[]) {
87
- return Buffer.from(message as string).toString(BASE64_STR);
88
- }
89
- /**
90
- * @desc Decode string from base64 format
91
- * @param {string} base64Message encoded string
92
- * @param {boolean} isBytes determine the return value type (True: bytes False: string)
93
- * @return {bytes/string} decoded bytes/string depends on isBytes, default is {string}
94
- */
95
- export function base64Decode(base64Message: string, isBytes?: boolean): string | Buffer {
96
- const bytes = Buffer.from(base64Message, BASE64_STR);
97
- return Boolean(isBytes) ? bytes : bytes.toString();
98
- }
99
- /**
100
- * @desc Compress the string
101
- * @param {string} message
102
- * @return {string} compressed string
103
- */
104
- function deflateString(message: string): number[] {
105
- const input = Buffer.from(message, 'utf8');
106
- return Array.from(deflateRawSync(input));
107
- }
108
- /**
109
- * @desc Decompress the compressed string
110
- * @param {string} compressedString
111
- * @return {string} decompressed string
112
- */
113
- export function inflateString(compressedString: string): string {
114
- const inputBuffer = Buffer.from(compressedString, BASE64_STR);
115
- return inflateRawSync(inputBuffer).toString('utf8');
116
- }
117
- /**
118
- * @desc Abstract the normalizeCerString and normalizePemString
119
- * @param {buffer} File stream or string
120
- * @param {string} String for header and tail
121
- * @return {string} A formatted certificate string
122
- */
123
- function _normalizeCerString(bin: string | Buffer, format: string) {
124
- return bin.toString().replace(/\n/g, '').replace(/\r/g, '').replace(`-----BEGIN ${format}-----`, '').replace(`-----END ${format}-----`, '').replace(/ /g, '').replace(/\t/g, '');
125
- }
126
- /**
127
- * @desc Parse the .cer to string format without line break, header and footer
128
- * @param {string} certString declares the certificate contents
129
- * @return {string} certificiate in string format
130
- */
131
- function normalizeCerString(certString: string | Buffer) {
132
- return _normalizeCerString(certString, 'CERTIFICATE');
133
- }
134
- /**
135
- * @desc Normalize the string in .pem format without line break, header and footer
136
- * @param {string} pemString
137
- * @return {string} private key in string format
138
- */
139
- function normalizePemString(pemString: string | Buffer) {
140
- return _normalizeCerString(pemString.toString(), 'RSA PRIVATE KEY');
141
- }
142
- /**
143
- * @desc Return the complete URL
144
- * @param {object} req HTTP request
145
- * @return {string} URL
146
- */
147
- function getFullURL(req) {
148
- return `${req.protocol}://${req.get('host')}${req.originalUrl}`;
149
- }
150
- /**
151
- * @desc Parse input string, return default value if it is undefined
152
- * @param {string/boolean}
153
- * @return {boolean}
154
- */
155
- function parseString(str, defaultValue = '') {
156
- return str || defaultValue;
157
- }
158
- /**
159
- * @desc Override the object by another object (rtl)
160
- * @param {object} default object
161
- * @param {object} object applied to the default object
162
- * @return {object} result object
163
- */
164
- function applyDefault(obj1, obj2) {
165
- return Object.assign({}, obj1, obj2);
166
- }
167
- /**
168
- * @desc Get public key in pem format from the certificate included in the metadata
169
- * @param {string} x509 certificate
170
- * @return {string} public key fetched from the certificate
171
- */
172
- function getPublicKeyPemFromCertificate(x509Certificate: string) {
173
- const der = Buffer.from(x509Certificate, 'base64');
174
- const cert = new X509Certificate(der);
175
- return cert.publicKey.export({ type: 'spki', format: 'pem' });
176
- }
177
- /**
178
- * @desc Read private key from pem-formatted string
179
- * @param {string | Buffer} keyString pem-formatted string
180
- * @param {string} protected passphrase of the key
181
- * @return {string} string in pem format
182
- * If passphrase is used to protect the .pem content (recommend)
183
- */
184
- export function readPrivateKey(keyString: string | Buffer, passphrase: string | undefined, isOutputString?: boolean) {
185
- if (isString(passphrase)) {
186
- const key = createPrivateKey({ key: keyString, format: 'pem', passphrase });
187
- const pem = key.export({ type: 'pkcs1', format: 'pem' });
188
- return convertToString(pem, isOutputString);
189
- }
190
- return keyString;
191
- }
192
- /**
193
- * @desc Inline syntax sugar
194
- */
195
- function convertToString(input, isOutputString) {
196
- return Boolean(isOutputString) ? String(input) : input;
197
- }
198
- /**
199
- * @desc Check if the input is an array with non-zero size
200
- */
201
- export function isNonEmptyArray(a) {
202
- return Array.isArray(a) && a.length > 0;
203
- }
204
-
205
- export function castArrayOpt<T>(a?: T | T[]): T[] {
206
- if (a === undefined) return []
207
- return Array.isArray(a) ? a : [a]
208
- }
209
-
210
- export function notEmpty<TValue>(value: TValue | null | undefined): value is TValue {
211
- return value !== null && value !== undefined;
212
- }
213
-
214
- const utility = {
215
- isString,
216
- base64Encode,
217
- base64Decode,
218
- deflateString,
219
- inflateString,
220
- normalizeCerString,
221
- normalizePemString,
222
- getFullURL,
223
- parseString,
224
- applyDefault,
225
- getPublicKeyPemFromCertificate,
226
- readPrivateKey,
227
- convertToString,
228
- isNonEmptyArray,
229
- };
230
-
231
- export default utility;
package/src/validator.ts DELETED
@@ -1,44 +0,0 @@
1
- // unit is ms
2
- type DriftTolerance = [number, number];
3
-
4
- function verifyTime(
5
- utcNotBefore: string | undefined,
6
- utcNotOnOrAfter: string | undefined,
7
- drift: DriftTolerance = [0, 0]
8
- ): boolean {
9
-
10
- const now = new Date();
11
-
12
- if (!utcNotBefore && !utcNotOnOrAfter) {
13
- // show warning because user intends to have time check but the document doesn't include corresponding information
14
- console.warn('You intend to have time validation however the document doesn\'t include the valid range.');
15
- return true;
16
- }
17
-
18
- let notBeforeLocal: Date | null = null;
19
- let notOnOrAfterLocal: Date | null = null;
20
-
21
- const [notBeforeDrift, notOnOrAfterDrift] = drift;
22
-
23
- if (utcNotBefore && !utcNotOnOrAfter) {
24
- notBeforeLocal = new Date(utcNotBefore);
25
- return +notBeforeLocal + notBeforeDrift <= +now;
26
- }
27
- if (!utcNotBefore && utcNotOnOrAfter) {
28
- notOnOrAfterLocal = new Date(utcNotOnOrAfter);
29
- return +now < +notOnOrAfterLocal + notOnOrAfterDrift;
30
- }
31
-
32
- notBeforeLocal = new Date(utcNotBefore!);
33
- notOnOrAfterLocal = new Date(utcNotOnOrAfter!);
34
-
35
- return (
36
- +notBeforeLocal + notBeforeDrift <= +now &&
37
- +now < +notOnOrAfterLocal + notOnOrAfterDrift
38
- );
39
-
40
- }
41
-
42
- export {
43
- verifyTime
44
- };
package/tsconfig.json DELETED
@@ -1,41 +0,0 @@
1
- {
2
- "compilerOptions": {
3
- "target": "es5",
4
- "module": "commonjs",
5
- "moduleResolution": "node",
6
- "declaration": true,
7
- "declarationDir": "types",
8
- "emitDecoratorMetadata": true,
9
- "experimentalDecorators": true,
10
- "downlevelIteration": true,
11
- "sourceMap": true,
12
- "outDir": "./build",
13
- "baseUrl": "./",
14
- "removeComments": false,
15
- "strictNullChecks": true,
16
- "esModuleInterop": true,
17
- "skipLibCheck": true,
18
- "paths": {},
19
- "lib": [
20
- "dom",
21
- "es2015.core",
22
- "es2015.promise",
23
- "es2015.iterable",
24
- "es5"
25
- ]
26
- },
27
- "atom": { "rewriteTsconfig": false },
28
- "include": [
29
- "src/**/*.ts",
30
- "index.ts"
31
- ],
32
- "exclude": [
33
- "node_modules",
34
- "types/**/*.ts",
35
- "test/**/*.ts",
36
- "build",
37
- "docs"
38
- ],
39
- "compileOnSave": false,
40
- "buildOnSave": false
41
- }
package/tslint.json DELETED
@@ -1,35 +0,0 @@
1
- {
2
- "extends": "tslint:recommended",
3
- "rulesDirectory": [],
4
- "linterOptions": {
5
- "exclude": [
6
- "node_modules/**"
7
- ]
8
- },
9
- "rules": {
10
- "arrow-parens": [true, "ban-single-arg-parens"],
11
- "comment-format": false,
12
- "interface-name": [true, "never-prefix"],
13
- "jsdoc-format": false,
14
- "max-line-length": false,
15
- "member-access": false,
16
- "no-console": [false],
17
- "no-consecutive-blank-lines": [true, 3],
18
- "no-empty-interface": false,
19
- "no-string-literal": false,
20
- "object-literal-sort-keys": false,
21
- "object-literal-key-quotes": false,
22
- "object-literal-shorthand": false,
23
- "trailing-comma": false,
24
- "eofline": false,
25
- "no-empty": false,
26
- "align": false,
27
- "no-trailing-whitespace": false,
28
- "ordered-imports": false,
29
- "quotemark": [true, "single", "avoid-escape", "avoid-template"],
30
- "variable-name": [true, "ban-keywords", "check-format", "allow-leading-underscore", "allow-pascal-case"],
31
- "interface-over-type-literal": false,
32
- "no-var-requires": false
33
- },
34
- "jsRules": {}
35
- }
package/types.d.ts DELETED
@@ -1,2 +0,0 @@
1
- export * from './index'
2
- export * from './src/types'
package/vitest.config.ts DELETED
@@ -1,12 +0,0 @@
1
- import { defineConfig } from 'vitest/config'
2
-
3
- export default defineConfig({
4
- test: {
5
- include: ['test/**/*.ts'],
6
- exclude: ['node_modules', 'build'],
7
- globals: true,
8
- environment: 'node',
9
- },
10
- })
11
-
12
-