@authup/server-kit 1.0.0-beta.4 → 1.0.0-beta.40
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/LICENSE +1 -1
- package/README.md +1 -1
- package/dist/crypto/hash/hash.d.ts +1 -1
- package/dist/crypto/hash/hash.d.ts.map +1 -1
- package/dist/crypto/index.d.ts +1 -1
- package/dist/crypto/index.d.ts.map +1 -1
- package/dist/crypto/json-web-token/extract.d.ts +16 -0
- package/dist/crypto/json-web-token/extract.d.ts.map +1 -0
- package/dist/crypto/json-web-token/index.d.ts +1 -1
- package/dist/crypto/json-web-token/index.d.ts.map +1 -1
- package/dist/crypto/json-web-token/sign/index.d.ts +3 -0
- package/dist/crypto/json-web-token/sign/index.d.ts.map +1 -0
- package/dist/crypto/json-web-token/sign/module.d.ts +4 -0
- package/dist/crypto/json-web-token/sign/module.d.ts.map +1 -0
- package/dist/crypto/json-web-token/sign/types.d.ts +28 -0
- package/dist/crypto/json-web-token/sign/types.d.ts.map +1 -0
- package/dist/crypto/json-web-token/type.d.ts +4 -33
- package/dist/crypto/json-web-token/type.d.ts.map +1 -1
- package/dist/crypto/json-web-token/utils.d.ts +5 -2
- package/dist/crypto/json-web-token/utils.d.ts.map +1 -1
- package/dist/crypto/json-web-token/verify/index.d.ts +3 -0
- package/dist/crypto/json-web-token/verify/index.d.ts.map +1 -0
- package/dist/crypto/json-web-token/verify/module.d.ts +12 -0
- package/dist/crypto/json-web-token/verify/module.d.ts.map +1 -0
- package/dist/crypto/json-web-token/verify/types.d.ts +25 -0
- package/dist/crypto/json-web-token/verify/types.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/check.d.ts +3 -0
- package/dist/crypto/key/asymmetric/check.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/constants.d.ts +8 -0
- package/dist/crypto/key/asymmetric/constants.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/create.d.ts +3 -0
- package/dist/crypto/key/asymmetric/create.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/helpers/index.d.ts +2 -0
- package/dist/crypto/key/asymmetric/helpers/index.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/helpers/wrap.d.ts +5 -0
- package/dist/crypto/key/asymmetric/helpers/wrap.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/index.d.ts +9 -0
- package/dist/crypto/key/asymmetric/index.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/key-usages.d.ts +5 -0
- package/dist/crypto/key/asymmetric/key-usages.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/module.d.ts +20 -0
- package/dist/crypto/key/asymmetric/module.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/normalize.d.ts +4 -0
- package/dist/crypto/key/asymmetric/normalize.d.ts.map +1 -0
- package/dist/crypto/key/asymmetric/types.d.ts +35 -0
- package/dist/crypto/key/asymmetric/types.d.ts.map +1 -0
- package/dist/crypto/key/base.d.ts +9 -0
- package/dist/crypto/key/base.d.ts.map +1 -0
- package/dist/crypto/key/index.d.ts +4 -0
- package/dist/crypto/key/index.d.ts.map +1 -0
- package/dist/crypto/key/symmetric/check.d.ts +3 -0
- package/dist/crypto/key/symmetric/check.d.ts.map +1 -0
- package/dist/crypto/key/symmetric/constants.d.ts +7 -0
- package/dist/crypto/key/symmetric/constants.d.ts.map +1 -0
- package/dist/crypto/key/symmetric/create.d.ts +3 -0
- package/dist/crypto/key/symmetric/create.d.ts.map +1 -0
- package/dist/crypto/key/symmetric/index.d.ts +7 -0
- package/dist/crypto/key/symmetric/index.d.ts.map +1 -0
- package/dist/crypto/key/symmetric/key-usages.d.ts +2 -0
- package/dist/crypto/key/symmetric/key-usages.d.ts.map +1 -0
- package/dist/crypto/key/symmetric/module.d.ts +13 -0
- package/dist/crypto/key/symmetric/module.d.ts.map +1 -0
- package/dist/crypto/key/symmetric/normalize.d.ts +4 -0
- package/dist/crypto/key/symmetric/normalize.d.ts.map +1 -0
- package/dist/crypto/key/symmetric/types.d.ts +32 -0
- package/dist/crypto/key/symmetric/types.d.ts.map +1 -0
- package/dist/domain-event/index.d.ts +1 -1
- package/dist/domain-event/index.d.ts.map +1 -1
- package/dist/domain-event/module.d.ts +9 -0
- package/dist/domain-event/module.d.ts.map +1 -0
- package/dist/domain-event/redis/index.d.ts +1 -1
- package/dist/domain-event/redis/index.d.ts.map +1 -1
- package/dist/domain-event/redis/module.d.ts +9 -0
- package/dist/domain-event/redis/module.d.ts.map +1 -0
- package/dist/domain-event/socket/index.d.ts +1 -2
- package/dist/domain-event/socket/index.d.ts.map +1 -1
- package/dist/domain-event/socket/module.d.ts +9 -0
- package/dist/domain-event/socket/module.d.ts.map +1 -0
- package/dist/domain-event/type.d.ts +8 -0
- package/dist/domain-event/type.d.ts.map +1 -1
- package/dist/domain-event/utils.d.ts +2 -1
- package/dist/domain-event/utils.d.ts.map +1 -1
- package/dist/index.d.mts +379 -0
- package/dist/index.d.mts.map +1 -0
- package/dist/index.d.ts +1 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.mjs +705 -579
- package/dist/index.mjs.map +1 -1
- package/dist/services/cache/adapters/index.d.ts +3 -0
- package/dist/services/cache/adapters/index.d.ts.map +1 -0
- package/dist/services/cache/adapters/memory.d.ts +15 -0
- package/dist/services/cache/adapters/memory.d.ts.map +1 -0
- package/dist/services/cache/adapters/redis.d.ts +17 -0
- package/dist/services/cache/adapters/redis.d.ts.map +1 -0
- package/dist/services/cache/helper.d.ts +3 -0
- package/dist/services/cache/helper.d.ts.map +1 -0
- package/dist/services/cache/index.d.ts +4 -0
- package/dist/services/cache/index.d.ts.map +1 -0
- package/dist/services/cache/types.d.ts +25 -0
- package/dist/services/cache/types.d.ts.map +1 -0
- package/dist/services/index.d.ts +5 -0
- package/dist/services/index.d.ts.map +1 -0
- package/dist/services/logger/index.d.ts +4 -0
- package/dist/services/logger/index.d.ts.map +1 -0
- package/dist/services/logger/module.d.ts +4 -0
- package/dist/services/logger/module.d.ts.map +1 -0
- package/dist/services/logger/singleton.d.ts +7 -0
- package/dist/services/logger/singleton.d.ts.map +1 -0
- package/dist/services/logger/types.d.ts +7 -0
- package/dist/services/logger/types.d.ts.map +1 -0
- package/dist/services/redis/check.d.ts +3 -0
- package/dist/services/redis/check.d.ts.map +1 -0
- package/dist/services/redis/factory.d.ts +4 -0
- package/dist/services/redis/factory.d.ts.map +1 -0
- package/dist/services/redis/index.d.ts +4 -0
- package/dist/services/redis/index.d.ts.map +1 -0
- package/dist/services/redis/module.d.ts +5 -0
- package/dist/services/redis/module.d.ts.map +1 -0
- package/dist/services/vault/index.d.ts +3 -0
- package/dist/services/vault/index.d.ts.map +1 -0
- package/dist/services/vault/module.d.ts +3 -0
- package/dist/services/vault/module.d.ts.map +1 -0
- package/dist/services/vault/singleton.d.ts +6 -0
- package/dist/services/vault/singleton.d.ts.map +1 -0
- package/package.json +45 -34
- package/dist/crypto/json-web-token/decode.d.ts +0 -15
- package/dist/crypto/json-web-token/decode.d.ts.map +0 -1
- package/dist/crypto/json-web-token/sign.d.ts +0 -4
- package/dist/crypto/json-web-token/sign.d.ts.map +0 -1
- package/dist/crypto/json-web-token/verify.d.ts +0 -15
- package/dist/crypto/json-web-token/verify.d.ts.map +0 -1
- package/dist/crypto/key-pair/constants.d.ts +0 -5
- package/dist/crypto/key-pair/constants.d.ts.map +0 -1
- package/dist/crypto/key-pair/create.d.ts +0 -3
- package/dist/crypto/key-pair/create.d.ts.map +0 -1
- package/dist/crypto/key-pair/delete.d.ts +0 -3
- package/dist/crypto/key-pair/delete.d.ts.map +0 -1
- package/dist/crypto/key-pair/index.d.ts +0 -9
- package/dist/crypto/key-pair/index.d.ts.map +0 -1
- package/dist/crypto/key-pair/load.d.ts +0 -3
- package/dist/crypto/key-pair/load.d.ts.map +0 -1
- package/dist/crypto/key-pair/module.d.ts +0 -3
- package/dist/crypto/key-pair/module.d.ts.map +0 -1
- package/dist/crypto/key-pair/save.d.ts +0 -3
- package/dist/crypto/key-pair/save.d.ts.map +0 -1
- package/dist/crypto/key-pair/type.d.ts +0 -65
- package/dist/crypto/key-pair/type.d.ts.map +0 -1
- package/dist/crypto/key-pair/utils/check.d.ts +0 -4
- package/dist/crypto/key-pair/utils/check.d.ts.map +0 -1
- package/dist/crypto/key-pair/utils/file-name.d.ts +0 -4
- package/dist/crypto/key-pair/utils/file-name.d.ts.map +0 -1
- package/dist/crypto/key-pair/utils/index.d.ts +0 -5
- package/dist/crypto/key-pair/utils/index.d.ts.map +0 -1
- package/dist/crypto/key-pair/utils/options.d.ts +0 -3
- package/dist/crypto/key-pair/utils/options.d.ts.map +0 -1
- package/dist/crypto/key-pair/utils/private-key.d.ts +0 -4
- package/dist/crypto/key-pair/utils/private-key.d.ts.map +0 -1
- package/dist/domain-event/publish.d.ts +0 -4
- package/dist/domain-event/publish.d.ts.map +0 -1
- package/dist/domain-event/redis/publish.d.ts +0 -4
- package/dist/domain-event/redis/publish.d.ts.map +0 -1
- package/dist/domain-event/socket/publish.d.ts +0 -4
- package/dist/domain-event/socket/publish.d.ts.map +0 -1
- package/dist/domain-event/socket/singleton.d.ts +0 -4
- package/dist/domain-event/socket/singleton.d.ts.map +0 -1
- package/dist/domain-event/socket/type.d.ts +0 -5
- package/dist/domain-event/socket/type.d.ts.map +0 -1
- package/dist/index.cjs +0 -642
- package/dist/index.cjs.map +0 -1
- package/dist/logger/index.d.ts +0 -4
- package/dist/logger/index.d.ts.map +0 -1
- package/dist/logger/module.d.ts +0 -4
- package/dist/logger/module.d.ts.map +0 -1
- package/dist/logger/presets/index.d.ts +0 -2
- package/dist/logger/presets/index.d.ts.map +0 -1
- package/dist/logger/presets/void.d.ts +0 -16
- package/dist/logger/presets/void.d.ts.map +0 -1
- package/dist/logger/type.d.ts +0 -14
- package/dist/logger/type.d.ts.map +0 -1
- package/dist/smtp/config/index.d.ts +0 -2
- package/dist/smtp/config/index.d.ts.map +0 -1
- package/dist/smtp/config/singleton.d.ts +0 -5
- package/dist/smtp/config/singleton.d.ts.map +0 -1
- package/dist/smtp/index.d.ts +0 -5
- package/dist/smtp/index.d.ts.map +0 -1
- package/dist/smtp/module.d.ts +0 -4
- package/dist/smtp/module.d.ts.map +0 -1
- package/dist/smtp/singleton.d.ts +0 -3
- package/dist/smtp/singleton.d.ts.map +0 -1
- package/dist/smtp/type.d.ts +0 -14
- package/dist/smtp/type.d.ts.map +0 -1
package/dist/index.cjs
DELETED
|
@@ -1,642 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var bcrypt = require('bcrypt');
|
|
4
|
-
var node_crypto = require('node:crypto');
|
|
5
|
-
var core = require('@authup/core');
|
|
6
|
-
var path = require('node:path');
|
|
7
|
-
var fs = require('node:fs');
|
|
8
|
-
var jsonwebtoken = require('jsonwebtoken');
|
|
9
|
-
var smob = require('smob');
|
|
10
|
-
var redisExtension = require('redis-extension');
|
|
11
|
-
var redisEmitter = require('@socket.io/redis-emitter');
|
|
12
|
-
var nodemailer = require('nodemailer');
|
|
13
|
-
|
|
14
|
-
async function compare(value, hashedValue) {
|
|
15
|
-
return bcrypt.compare(value, hashedValue);
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
async function hash(str, saltOrRounds = 10) {
|
|
19
|
-
return bcrypt.hash(str, saltOrRounds);
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/*
|
|
23
|
-
* Copyright (c) 2022.
|
|
24
|
-
* Author Peter Placzek (tada5hi)
|
|
25
|
-
* For the full copyright and license information,
|
|
26
|
-
* view the LICENSE file that was distributed with this source code.
|
|
27
|
-
*/ exports.KeyPairKind = void 0;
|
|
28
|
-
(function(KeyPairKind) {
|
|
29
|
-
KeyPairKind["PRIVATE"] = "private";
|
|
30
|
-
KeyPairKind["PUBLIC"] = "public";
|
|
31
|
-
})(exports.KeyPairKind || (exports.KeyPairKind = {}));
|
|
32
|
-
|
|
33
|
-
function isKeyPair(data) {
|
|
34
|
-
return core.isObject(data) && typeof data.privateKey !== 'undefined' && typeof data.publicKey !== 'undefined';
|
|
35
|
-
}
|
|
36
|
-
function isKeyPairWithPublicKey(data) {
|
|
37
|
-
return core.isObject(data) && typeof data.publicKey !== 'undefined';
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
function extendKeyPairOptions(options) {
|
|
41
|
-
var _options;
|
|
42
|
-
options = options ?? {};
|
|
43
|
-
options.directory = options.directory || process.cwd();
|
|
44
|
-
options.directory = path.isAbsolute(options.directory) ? options.directory : path.resolve(process.cwd(), options.directory);
|
|
45
|
-
(_options = options).type ?? (_options.type = 'rsa');
|
|
46
|
-
if (options.type === 'rsa' || options.type === 'rsa-pss' || options.type === 'dsa') {
|
|
47
|
-
options.modulusLength = 2048;
|
|
48
|
-
}
|
|
49
|
-
if (!options.privateKeyEncoding) {
|
|
50
|
-
options.privateKeyEncoding = {
|
|
51
|
-
type: 'pkcs8',
|
|
52
|
-
format: 'pem'
|
|
53
|
-
};
|
|
54
|
-
}
|
|
55
|
-
if (!options.publicKeyEncoding) {
|
|
56
|
-
options.publicKeyEncoding = {
|
|
57
|
-
type: 'spki',
|
|
58
|
-
format: 'pem'
|
|
59
|
-
};
|
|
60
|
-
}
|
|
61
|
-
if (options.privateKeyEncoding.passphrase && !options.privateKeyEncoding.cipher) {
|
|
62
|
-
options.privateKeyEncoding.cipher = 'aes-256-cbc';
|
|
63
|
-
}
|
|
64
|
-
return options;
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
function buildKeyFileName(type, context) {
|
|
68
|
-
const options = extendKeyPairOptions(context);
|
|
69
|
-
const parts = [];
|
|
70
|
-
switch(type){
|
|
71
|
-
case exports.KeyPairKind.PRIVATE:
|
|
72
|
-
{
|
|
73
|
-
if (options.privateName) {
|
|
74
|
-
parts.push(options.privateName);
|
|
75
|
-
} else {
|
|
76
|
-
parts.push(type);
|
|
77
|
-
}
|
|
78
|
-
if (options.privateExtension) {
|
|
79
|
-
if (options.privateExtension.startsWith('.')) {
|
|
80
|
-
options.privateExtension = options.privateExtension.slice(1);
|
|
81
|
-
}
|
|
82
|
-
parts.push(options.privateExtension);
|
|
83
|
-
} else {
|
|
84
|
-
parts.push('pem');
|
|
85
|
-
}
|
|
86
|
-
break;
|
|
87
|
-
}
|
|
88
|
-
case exports.KeyPairKind.PUBLIC:
|
|
89
|
-
{
|
|
90
|
-
if (options.publicName) {
|
|
91
|
-
parts.push(options.publicName);
|
|
92
|
-
} else {
|
|
93
|
-
parts.push(type);
|
|
94
|
-
}
|
|
95
|
-
if (options.publicExtension) {
|
|
96
|
-
if (options.publicExtension.startsWith('.')) {
|
|
97
|
-
options.publicExtension = options.publicExtension.slice(1);
|
|
98
|
-
}
|
|
99
|
-
parts.push(options.publicExtension);
|
|
100
|
-
} else {
|
|
101
|
-
parts.push('pem');
|
|
102
|
-
}
|
|
103
|
-
break;
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
return parts.join('.');
|
|
107
|
-
}
|
|
108
|
-
|
|
109
|
-
function decryptRSAPrivateKey(context, key) {
|
|
110
|
-
const privateKey = node_crypto.createPrivateKey({
|
|
111
|
-
type: context.privateKeyEncoding.type,
|
|
112
|
-
format: context.privateKeyEncoding.format,
|
|
113
|
-
key,
|
|
114
|
-
passphrase: context.privateKeyEncoding.passphrase || context.passphrase
|
|
115
|
-
});
|
|
116
|
-
let content = privateKey.export({
|
|
117
|
-
type: context.privateKeyEncoding.type,
|
|
118
|
-
format: context.privateKeyEncoding.format
|
|
119
|
-
});
|
|
120
|
-
if (typeof content !== 'string') {
|
|
121
|
-
content = Buffer.from(content).toString('utf-8');
|
|
122
|
-
}
|
|
123
|
-
return content;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
async function saveKeyPair(keyPair, context) {
|
|
127
|
-
context = extendKeyPairOptions(context);
|
|
128
|
-
await fs.promises.mkdir(context.directory, {
|
|
129
|
-
recursive: true
|
|
130
|
-
});
|
|
131
|
-
await Promise.all([
|
|
132
|
-
{
|
|
133
|
-
path: path.resolve(context.directory, buildKeyFileName(exports.KeyPairKind.PRIVATE, context)),
|
|
134
|
-
content: keyPair.privateKey
|
|
135
|
-
},
|
|
136
|
-
{
|
|
137
|
-
path: path.resolve(context.directory, buildKeyFileName(exports.KeyPairKind.PUBLIC, context)),
|
|
138
|
-
content: keyPair.publicKey
|
|
139
|
-
}
|
|
140
|
-
].map((file)=>fs.promises.writeFile(file.path, file.content)));
|
|
141
|
-
return keyPair;
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
async function createKeyPair(context) {
|
|
145
|
-
const options = extendKeyPairOptions(context);
|
|
146
|
-
const keyPair = await new Promise((resolve, reject)=>{
|
|
147
|
-
const callback = (err, publicKey, privateKey)=>{
|
|
148
|
-
if (err) reject(err);
|
|
149
|
-
resolve({
|
|
150
|
-
privateKey,
|
|
151
|
-
publicKey
|
|
152
|
-
});
|
|
153
|
-
};
|
|
154
|
-
switch(options.type){
|
|
155
|
-
case 'dsa':
|
|
156
|
-
node_crypto.generateKeyPair(options.type, options, callback);
|
|
157
|
-
break;
|
|
158
|
-
case 'ec':
|
|
159
|
-
node_crypto.generateKeyPair(options.type, options, callback);
|
|
160
|
-
break;
|
|
161
|
-
case 'rsa':
|
|
162
|
-
node_crypto.generateKeyPair(options.type, options, callback);
|
|
163
|
-
break;
|
|
164
|
-
case 'rsa-pss':
|
|
165
|
-
node_crypto.generateKeyPair(options.type, options, callback);
|
|
166
|
-
break;
|
|
167
|
-
}
|
|
168
|
-
});
|
|
169
|
-
if (options.save) {
|
|
170
|
-
await saveKeyPair(keyPair, options);
|
|
171
|
-
}
|
|
172
|
-
if (options.passphrase || options.privateKeyEncoding.passphrase) {
|
|
173
|
-
keyPair.privateKey = decryptRSAPrivateKey(options, keyPair.privateKey);
|
|
174
|
-
}
|
|
175
|
-
return keyPair;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
async function deleteKeyPair(context) {
|
|
179
|
-
const options = extendKeyPairOptions(context);
|
|
180
|
-
const privateKeyPath = path.resolve(options.directory, buildKeyFileName(exports.KeyPairKind.PRIVATE, options));
|
|
181
|
-
const publicKeyPath = path.resolve(options.directory, buildKeyFileName(exports.KeyPairKind.PUBLIC, options));
|
|
182
|
-
try {
|
|
183
|
-
await Promise.all([
|
|
184
|
-
privateKeyPath,
|
|
185
|
-
publicKeyPath
|
|
186
|
-
].map((filePath)=>fs.promises.stat(filePath)));
|
|
187
|
-
} catch (e) {
|
|
188
|
-
return;
|
|
189
|
-
}
|
|
190
|
-
await Promise.all([
|
|
191
|
-
privateKeyPath,
|
|
192
|
-
publicKeyPath
|
|
193
|
-
].map((filePath)=>fs.promises.rm(filePath)));
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
async function loadKeyPair(context) {
|
|
197
|
-
const options = extendKeyPairOptions(context);
|
|
198
|
-
const privateKeyPath = path.resolve(options.directory, buildKeyFileName(exports.KeyPairKind.PRIVATE, options));
|
|
199
|
-
try {
|
|
200
|
-
await fs.promises.stat(privateKeyPath);
|
|
201
|
-
} catch (e) {
|
|
202
|
-
return undefined;
|
|
203
|
-
}
|
|
204
|
-
const privateKeyBuffer = await fs.promises.readFile(privateKeyPath);
|
|
205
|
-
let privateKey = privateKeyBuffer.toString();
|
|
206
|
-
if (options.passphrase || options.privateKeyEncoding.passphrase) {
|
|
207
|
-
privateKey = decryptRSAPrivateKey(options, privateKey);
|
|
208
|
-
}
|
|
209
|
-
const publicKeyPath = path.resolve(options.directory, buildKeyFileName(exports.KeyPairKind.PUBLIC, options));
|
|
210
|
-
let publicKey;
|
|
211
|
-
try {
|
|
212
|
-
await fs.promises.stat(publicKeyPath);
|
|
213
|
-
const publicKeyBuffer = await fs.promises.readFile(publicKeyPath);
|
|
214
|
-
publicKey = publicKeyBuffer.toString();
|
|
215
|
-
} catch (e) {
|
|
216
|
-
const publicKeyObject = node_crypto.createPublicKey({
|
|
217
|
-
key: privateKey,
|
|
218
|
-
format: options.privateKeyEncoding.format,
|
|
219
|
-
type: options.publicKeyEncoding.type
|
|
220
|
-
});
|
|
221
|
-
const stringOrBuffer = publicKeyObject.export({
|
|
222
|
-
format: options.publicKeyEncoding.format,
|
|
223
|
-
type: options.publicKeyEncoding.type
|
|
224
|
-
});
|
|
225
|
-
if (typeof stringOrBuffer !== 'string') {
|
|
226
|
-
publicKey = stringOrBuffer.toString();
|
|
227
|
-
} else {
|
|
228
|
-
publicKey = stringOrBuffer;
|
|
229
|
-
}
|
|
230
|
-
if (options.save) {
|
|
231
|
-
await saveKeyPair({
|
|
232
|
-
privateKey,
|
|
233
|
-
publicKey
|
|
234
|
-
}, options);
|
|
235
|
-
}
|
|
236
|
-
}
|
|
237
|
-
return {
|
|
238
|
-
privateKey,
|
|
239
|
-
publicKey
|
|
240
|
-
};
|
|
241
|
-
}
|
|
242
|
-
|
|
243
|
-
const keyPairCache = {};
|
|
244
|
-
async function useKeyPair(value) {
|
|
245
|
-
let options;
|
|
246
|
-
if (typeof value === 'string') {
|
|
247
|
-
options = extendKeyPairOptions({
|
|
248
|
-
privateName: value
|
|
249
|
-
});
|
|
250
|
-
} else {
|
|
251
|
-
options = extendKeyPairOptions(value || {});
|
|
252
|
-
}
|
|
253
|
-
if (Object.prototype.hasOwnProperty.call(keyPairCache, options.privateName)) {
|
|
254
|
-
return keyPairCache[options.privateName];
|
|
255
|
-
}
|
|
256
|
-
let keyPair = await loadKeyPair(options);
|
|
257
|
-
if (typeof keyPair === 'undefined') {
|
|
258
|
-
keyPair = await createKeyPair(options);
|
|
259
|
-
}
|
|
260
|
-
keyPairCache[options.privateName] = keyPair;
|
|
261
|
-
return keyPair;
|
|
262
|
-
}
|
|
263
|
-
|
|
264
|
-
function createErrorForJWTError(e) {
|
|
265
|
-
if (smob.isObject(e) && typeof e.name === 'string') {
|
|
266
|
-
switch(e.name){
|
|
267
|
-
case 'TokenExpiredError':
|
|
268
|
-
{
|
|
269
|
-
return core.TokenError.expired();
|
|
270
|
-
}
|
|
271
|
-
case 'NotBeforeError':
|
|
272
|
-
{
|
|
273
|
-
if (typeof e.date === 'string' || e.date instanceof Date) {
|
|
274
|
-
return core.TokenError.notActiveBefore(e.date);
|
|
275
|
-
}
|
|
276
|
-
break;
|
|
277
|
-
}
|
|
278
|
-
case 'JsonWebTokenError':
|
|
279
|
-
{
|
|
280
|
-
if (typeof e.message === 'string') {
|
|
281
|
-
return core.TokenError.payloadInvalid(e.message);
|
|
282
|
-
}
|
|
283
|
-
break;
|
|
284
|
-
}
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
return new core.TokenError({
|
|
288
|
-
cause: e,
|
|
289
|
-
logMessage: true,
|
|
290
|
-
message: 'The JWT error could not be determined.'
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
|
|
294
|
-
function decodeToken(token, options) {
|
|
295
|
-
options ?? (options = {});
|
|
296
|
-
let output;
|
|
297
|
-
try {
|
|
298
|
-
output = jsonwebtoken.decode(token, {
|
|
299
|
-
...options
|
|
300
|
-
});
|
|
301
|
-
} catch (e) {
|
|
302
|
-
throw createErrorForJWTError(e);
|
|
303
|
-
}
|
|
304
|
-
if (output === null) {
|
|
305
|
-
throw core.TokenError.payloadInvalid('The token could not be decoded.');
|
|
306
|
-
}
|
|
307
|
-
return output;
|
|
308
|
-
}
|
|
309
|
-
|
|
310
|
-
async function signToken(payload, context) {
|
|
311
|
-
context.expiresIn = context.expiresIn || 3600;
|
|
312
|
-
switch(context.type){
|
|
313
|
-
case core.KeyType.RSA:
|
|
314
|
-
case core.KeyType.EC:
|
|
315
|
-
{
|
|
316
|
-
const { type, keyPair, ...options } = context;
|
|
317
|
-
const { privateKey } = isKeyPair(keyPair) ? keyPair : await useKeyPair(keyPair);
|
|
318
|
-
if (type === core.KeyType.RSA) {
|
|
319
|
-
options.algorithm = options.algorithm || 'RS256';
|
|
320
|
-
} else {
|
|
321
|
-
options.algorithm = options.algorithm || 'ES256';
|
|
322
|
-
}
|
|
323
|
-
return jsonwebtoken.sign(payload, privateKey, options);
|
|
324
|
-
}
|
|
325
|
-
case core.KeyType.OCT:
|
|
326
|
-
{
|
|
327
|
-
const { type, secret, ...options } = context;
|
|
328
|
-
options.algorithm = options.algorithm || 'HS256';
|
|
329
|
-
return jsonwebtoken.sign(payload, secret, options);
|
|
330
|
-
}
|
|
331
|
-
}
|
|
332
|
-
throw new core.TokenError();
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
async function verifyToken(token, context) {
|
|
336
|
-
let promise;
|
|
337
|
-
let output;
|
|
338
|
-
try {
|
|
339
|
-
switch(context.type){
|
|
340
|
-
case core.KeyType.RSA:
|
|
341
|
-
case core.KeyType.EC:
|
|
342
|
-
{
|
|
343
|
-
const { type, keyPair, ...options } = context;
|
|
344
|
-
const { publicKey } = isKeyPairWithPublicKey(keyPair) ? keyPair : await useKeyPair(keyPair);
|
|
345
|
-
if (type === core.KeyType.RSA) {
|
|
346
|
-
options.algorithms = options.algorithms || [
|
|
347
|
-
'RS256',
|
|
348
|
-
'RS384',
|
|
349
|
-
'RS512',
|
|
350
|
-
'PS256',
|
|
351
|
-
'PS384',
|
|
352
|
-
'PS512'
|
|
353
|
-
];
|
|
354
|
-
} else {
|
|
355
|
-
options.algorithms = options.algorithms || [
|
|
356
|
-
'ES256',
|
|
357
|
-
'ES384',
|
|
358
|
-
'ES512'
|
|
359
|
-
];
|
|
360
|
-
}
|
|
361
|
-
promise = new Promise((resolve, reject)=>{
|
|
362
|
-
jsonwebtoken.verify(token, publicKey, options, (err, decoded)=>{
|
|
363
|
-
if (err) {
|
|
364
|
-
reject(err);
|
|
365
|
-
return;
|
|
366
|
-
}
|
|
367
|
-
resolve(decoded);
|
|
368
|
-
});
|
|
369
|
-
});
|
|
370
|
-
break;
|
|
371
|
-
}
|
|
372
|
-
case core.KeyType.OCT:
|
|
373
|
-
{
|
|
374
|
-
const { type, secret, ...options } = context;
|
|
375
|
-
options.algorithms = options.algorithms || [
|
|
376
|
-
'HS256',
|
|
377
|
-
'HS384',
|
|
378
|
-
'HS512'
|
|
379
|
-
];
|
|
380
|
-
promise = new Promise((resolve, reject)=>{
|
|
381
|
-
jsonwebtoken.verify(token, secret, options, (err, decoded)=>{
|
|
382
|
-
if (err) {
|
|
383
|
-
reject(err);
|
|
384
|
-
return;
|
|
385
|
-
}
|
|
386
|
-
resolve(decoded);
|
|
387
|
-
});
|
|
388
|
-
});
|
|
389
|
-
}
|
|
390
|
-
}
|
|
391
|
-
output = await promise;
|
|
392
|
-
} catch (e) {
|
|
393
|
-
throw createErrorForJWTError(e);
|
|
394
|
-
}
|
|
395
|
-
if (typeof output === 'undefined') {
|
|
396
|
-
throw new core.TokenError({
|
|
397
|
-
message: 'Invalid type.'
|
|
398
|
-
});
|
|
399
|
-
}
|
|
400
|
-
return output;
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
function transformDomainEventData(input) {
|
|
404
|
-
if (core.isObject(input)) {
|
|
405
|
-
const keys = Object.keys(input);
|
|
406
|
-
for(let i = 0; i < keys.length; i++){
|
|
407
|
-
const value = input[keys[i]];
|
|
408
|
-
if (value instanceof Date) {
|
|
409
|
-
input[keys[i]] = value.toISOString();
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
}
|
|
413
|
-
return input;
|
|
414
|
-
}
|
|
415
|
-
function buildDomainEventChannelName(input, id) {
|
|
416
|
-
if (typeof input === 'string') {
|
|
417
|
-
return input;
|
|
418
|
-
}
|
|
419
|
-
return input(id);
|
|
420
|
-
}
|
|
421
|
-
|
|
422
|
-
async function publishDomainRedisEvent(context, destinations) {
|
|
423
|
-
if (!redisExtension.hasClient() && !redisExtension.hasConfig()) {
|
|
424
|
-
return Promise.resolve();
|
|
425
|
-
}
|
|
426
|
-
context = transformDomainEventData(context);
|
|
427
|
-
const json = JSON.stringify(context);
|
|
428
|
-
const client = redisExtension.useClient();
|
|
429
|
-
const pipeline = client.pipeline();
|
|
430
|
-
for(let i = 0; i < destinations.length; i++){
|
|
431
|
-
const { namespace } = destinations[i];
|
|
432
|
-
const keyPrefix = namespace ? `${namespace}:` : '';
|
|
433
|
-
let key = keyPrefix + buildDomainEventChannelName(destinations[i].channel);
|
|
434
|
-
pipeline.publish(key, json);
|
|
435
|
-
if (context.event !== core.DomainEventName.CREATED && typeof destinations[i].channel === 'function') {
|
|
436
|
-
key = keyPrefix + buildDomainEventChannelName(destinations[i].channel, context.data.id);
|
|
437
|
-
pipeline.publish(key, json);
|
|
438
|
-
}
|
|
439
|
-
}
|
|
440
|
-
return pipeline.exec();
|
|
441
|
-
}
|
|
442
|
-
|
|
443
|
-
let instance$3;
|
|
444
|
-
function useSocketEmitter() {
|
|
445
|
-
if (typeof instance$3 !== 'undefined') {
|
|
446
|
-
return instance$3;
|
|
447
|
-
}
|
|
448
|
-
instance$3 = new redisEmitter.Emitter(redisExtension.useClient());
|
|
449
|
-
return instance$3;
|
|
450
|
-
}
|
|
451
|
-
|
|
452
|
-
function publishDomainSocketEvent(context, destinations) {
|
|
453
|
-
if (!redisExtension.hasClient() && !redisExtension.hasConfig()) {
|
|
454
|
-
return;
|
|
455
|
-
}
|
|
456
|
-
context = transformDomainEventData(context);
|
|
457
|
-
for(let i = 0; i < destinations.length; i++){
|
|
458
|
-
let emitter = useSocketEmitter();
|
|
459
|
-
if (destinations[i].namespace) {
|
|
460
|
-
emitter = emitter.of(destinations[i].namespace);
|
|
461
|
-
}
|
|
462
|
-
let roomName = buildDomainEventChannelName(destinations[i].channel);
|
|
463
|
-
const fullEventName = core.buildDomainEventFullName(context.type, context.event);
|
|
464
|
-
emitter.in(roomName)// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
465
|
-
// @ts-ignore
|
|
466
|
-
.emit(fullEventName, {
|
|
467
|
-
...context,
|
|
468
|
-
meta: {
|
|
469
|
-
roomName
|
|
470
|
-
}
|
|
471
|
-
});
|
|
472
|
-
if (context.event !== core.DomainEventName.CREATED && typeof destinations[i].channel === 'function') {
|
|
473
|
-
roomName = buildDomainEventChannelName(destinations[i].channel, context.data.id);
|
|
474
|
-
emitter.in(roomName)// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
475
|
-
// @ts-ignore
|
|
476
|
-
.emit(fullEventName, {
|
|
477
|
-
...context,
|
|
478
|
-
meta: {
|
|
479
|
-
roomName,
|
|
480
|
-
roomId: context.data.id
|
|
481
|
-
}
|
|
482
|
-
});
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
|
|
487
|
-
async function publishDomainEvent(context, destinations) {
|
|
488
|
-
await publishDomainRedisEvent(context, destinations);
|
|
489
|
-
publishDomainSocketEvent(context, destinations);
|
|
490
|
-
}
|
|
491
|
-
|
|
492
|
-
/*
|
|
493
|
-
* Copyright (c) 2022.
|
|
494
|
-
* Author Peter Placzek (tada5hi)
|
|
495
|
-
* For the full copyright and license information,
|
|
496
|
-
* view the LICENSE file that was distributed with this source code.
|
|
497
|
-
*/ class VoidLogger {
|
|
498
|
-
error() {
|
|
499
|
-
return this;
|
|
500
|
-
}
|
|
501
|
-
warn() {
|
|
502
|
-
return this;
|
|
503
|
-
}
|
|
504
|
-
info() {
|
|
505
|
-
return this;
|
|
506
|
-
}
|
|
507
|
-
http() {
|
|
508
|
-
return this;
|
|
509
|
-
}
|
|
510
|
-
verbose() {
|
|
511
|
-
return this;
|
|
512
|
-
}
|
|
513
|
-
debug() {
|
|
514
|
-
return this;
|
|
515
|
-
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
let instance$2;
|
|
519
|
-
function useLogger() {
|
|
520
|
-
if (typeof instance$2 !== 'undefined') {
|
|
521
|
-
return instance$2;
|
|
522
|
-
}
|
|
523
|
-
instance$2 = new VoidLogger();
|
|
524
|
-
return instance$2;
|
|
525
|
-
}
|
|
526
|
-
function setLogger(logger) {
|
|
527
|
-
instance$2 = logger;
|
|
528
|
-
}
|
|
529
|
-
|
|
530
|
-
/*
|
|
531
|
-
* Copyright (c) 2022.
|
|
532
|
-
* Author Peter Placzek (tada5hi)
|
|
533
|
-
* For the full copyright and license information,
|
|
534
|
-
* view the LICENSE file that was distributed with this source code.
|
|
535
|
-
*/ let instance$1;
|
|
536
|
-
function hasSmtpConfig() {
|
|
537
|
-
return !!instance$1;
|
|
538
|
-
}
|
|
539
|
-
function setSmtpConfig(value) {
|
|
540
|
-
instance$1 = value;
|
|
541
|
-
}
|
|
542
|
-
function useSmtpConfig() {
|
|
543
|
-
if (typeof instance$1 !== 'undefined') {
|
|
544
|
-
return instance$1;
|
|
545
|
-
}
|
|
546
|
-
instance$1 = {};
|
|
547
|
-
return instance$1;
|
|
548
|
-
}
|
|
549
|
-
|
|
550
|
-
function createSmtpClient(options) {
|
|
551
|
-
let transport;
|
|
552
|
-
options = options || {};
|
|
553
|
-
if (typeof options === 'string') {
|
|
554
|
-
transport = nodemailer.createTransport(options);
|
|
555
|
-
} else if (options.connectionString) {
|
|
556
|
-
transport = nodemailer.createTransport(options.connectionString);
|
|
557
|
-
} else {
|
|
558
|
-
let auth;
|
|
559
|
-
if (options.user && options.password) {
|
|
560
|
-
auth = {
|
|
561
|
-
type: 'login',
|
|
562
|
-
user: options.user,
|
|
563
|
-
pass: options.password
|
|
564
|
-
};
|
|
565
|
-
}
|
|
566
|
-
transport = nodemailer.createTransport({
|
|
567
|
-
host: options.host,
|
|
568
|
-
port: options.port,
|
|
569
|
-
auth,
|
|
570
|
-
secure: options.ssl,
|
|
571
|
-
opportunisticTLS: options.starttls,
|
|
572
|
-
tls: {
|
|
573
|
-
rejectUnauthorized: false
|
|
574
|
-
}
|
|
575
|
-
});
|
|
576
|
-
}
|
|
577
|
-
transport.on('error', (e)=>{
|
|
578
|
-
useLogger().error(e.message);
|
|
579
|
-
});
|
|
580
|
-
return transport;
|
|
581
|
-
}
|
|
582
|
-
|
|
583
|
-
let instance;
|
|
584
|
-
async function useSMTPClient() {
|
|
585
|
-
if (typeof instance !== 'undefined') {
|
|
586
|
-
return instance;
|
|
587
|
-
}
|
|
588
|
-
let options;
|
|
589
|
-
if (process.env.NODE_ENV === 'test') {
|
|
590
|
-
const testAccount = await nodemailer.createTestAccount();
|
|
591
|
-
options = {
|
|
592
|
-
host: 'smtp.ethereal.email',
|
|
593
|
-
port: 587,
|
|
594
|
-
ssl: false,
|
|
595
|
-
user: testAccount.user,
|
|
596
|
-
password: testAccount.pass
|
|
597
|
-
};
|
|
598
|
-
} else {
|
|
599
|
-
options = useSmtpConfig();
|
|
600
|
-
}
|
|
601
|
-
instance = createSmtpClient(options);
|
|
602
|
-
return instance;
|
|
603
|
-
}
|
|
604
|
-
|
|
605
|
-
/*
|
|
606
|
-
* Copyright (c) 2022.
|
|
607
|
-
* Author Peter Placzek (tada5hi)
|
|
608
|
-
* For the full copyright and license information,
|
|
609
|
-
* view the LICENSE file that was distributed with this source code.
|
|
610
|
-
*/ function hasOwnProperty(obj, prop) {
|
|
611
|
-
return Object.prototype.hasOwnProperty.call(obj, prop);
|
|
612
|
-
}
|
|
613
|
-
|
|
614
|
-
exports.VoidLogger = VoidLogger;
|
|
615
|
-
exports.buildKeyFileName = buildKeyFileName;
|
|
616
|
-
exports.compare = compare;
|
|
617
|
-
exports.createKeyPair = createKeyPair;
|
|
618
|
-
exports.createSmtpClient = createSmtpClient;
|
|
619
|
-
exports.decodeToken = decodeToken;
|
|
620
|
-
exports.decryptRSAPrivateKey = decryptRSAPrivateKey;
|
|
621
|
-
exports.deleteKeyPair = deleteKeyPair;
|
|
622
|
-
exports.extendKeyPairOptions = extendKeyPairOptions;
|
|
623
|
-
exports.hasOwnProperty = hasOwnProperty;
|
|
624
|
-
exports.hasSmtpConfig = hasSmtpConfig;
|
|
625
|
-
exports.hash = hash;
|
|
626
|
-
exports.isKeyPair = isKeyPair;
|
|
627
|
-
exports.isKeyPairWithPublicKey = isKeyPairWithPublicKey;
|
|
628
|
-
exports.loadKeyPair = loadKeyPair;
|
|
629
|
-
exports.publishDomainEvent = publishDomainEvent;
|
|
630
|
-
exports.publishDomainRedisEvent = publishDomainRedisEvent;
|
|
631
|
-
exports.publishDomainSocketEvent = publishDomainSocketEvent;
|
|
632
|
-
exports.saveKeyPair = saveKeyPair;
|
|
633
|
-
exports.setLogger = setLogger;
|
|
634
|
-
exports.setSmtpConfig = setSmtpConfig;
|
|
635
|
-
exports.signToken = signToken;
|
|
636
|
-
exports.useKeyPair = useKeyPair;
|
|
637
|
-
exports.useLogger = useLogger;
|
|
638
|
-
exports.useSMTPClient = useSMTPClient;
|
|
639
|
-
exports.useSmtpConfig = useSmtpConfig;
|
|
640
|
-
exports.useSocketEmitter = useSocketEmitter;
|
|
641
|
-
exports.verifyToken = verifyToken;
|
|
642
|
-
//# sourceMappingURL=index.cjs.map
|