@sudoplatform/sudo-user 11.0.0 → 12.0.1
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/cjs/client/apiClient.d.ts +25 -0
- package/cjs/client/apiClient.js +149 -0
- package/cjs/client/apiClient.js.map +1 -0
- package/cjs/core/api-key-names.d.ts +8 -0
- package/cjs/core/api-key-names.js +12 -0
- package/cjs/core/api-key-names.js.map +1 -0
- package/cjs/core/auth-store.d.ts +51 -0
- package/cjs/core/auth-store.js +92 -0
- package/cjs/core/auth-store.js.map +1 -0
- package/cjs/core/crypto.d.ts +3 -0
- package/cjs/core/crypto.js +3 -0
- package/cjs/core/crypto.js.map +1 -0
- package/cjs/core/key-manager.d.ts +31 -0
- package/cjs/core/key-manager.js +113 -0
- package/cjs/core/key-manager.js.map +1 -0
- package/cjs/core/protected-store.d.ts +5 -0
- package/cjs/core/protected-store.js +3 -0
- package/cjs/core/protected-store.js.map +1 -0
- package/cjs/core/publisher.d.ts +6 -0
- package/cjs/core/publisher.js +3 -0
- package/cjs/core/publisher.js.map +1 -0
- package/cjs/core/sdk-config.d.ts +52 -0
- package/cjs/core/sdk-config.js +61 -0
- package/cjs/core/sdk-config.js.map +1 -0
- package/cjs/core/subscriber.d.ts +3 -0
- package/cjs/core/subscriber.js +3 -0
- package/cjs/core/subscriber.js.map +1 -0
- package/cjs/gen/graphql-types.d.ts +101 -0
- package/cjs/gen/graphql-types.js +105 -0
- package/cjs/gen/graphql-types.js.map +1 -0
- package/cjs/index.d.ts +4 -0
- package/cjs/index.js +13 -0
- package/cjs/index.js.map +1 -0
- package/cjs/runtimes/browser/browser-crypto.d.ts +2 -0
- package/cjs/runtimes/browser/browser-crypto.js +10 -0
- package/cjs/runtimes/browser/browser-crypto.js.map +1 -0
- package/cjs/runtimes/node/node-crypto.d.ts +2 -0
- package/cjs/runtimes/node/node-crypto.js +9 -0
- package/cjs/runtimes/node/node-crypto.js.map +1 -0
- package/cjs/sdk.d.ts +1 -0
- package/cjs/sdk.js +9 -0
- package/cjs/sdk.js.map +1 -0
- package/cjs/user/auth-provider.d.ts +97 -0
- package/cjs/user/auth-provider.js +116 -0
- package/cjs/user/auth-provider.js.map +1 -0
- package/cjs/user/auth.d.ts +64 -0
- package/cjs/user/auth.js +136 -0
- package/cjs/user/auth.js.map +1 -0
- package/cjs/user/error.d.ts +18 -0
- package/cjs/user/error.js +33 -0
- package/cjs/user/error.js.map +1 -0
- package/cjs/user/identity-provider.d.ts +73 -0
- package/cjs/user/identity-provider.js +245 -0
- package/cjs/user/identity-provider.js.map +1 -0
- package/cjs/user/user-client-interface.d.ts +168 -0
- package/cjs/user/user-client-interface.js +3 -0
- package/cjs/user/user-client-interface.js.map +1 -0
- package/cjs/user/user-client.d.ts +82 -0
- package/cjs/user/user-client.js +440 -0
- package/cjs/user/user-client.js.map +1 -0
- package/cjs/user/user-key-names.d.ts +6 -0
- package/cjs/user/user-key-names.js +10 -0
- package/cjs/user/user-key-names.js.map +1 -0
- package/cjs/utils/resolvable-promise.d.ts +9 -0
- package/cjs/utils/resolvable-promise.js +20 -0
- package/cjs/utils/resolvable-promise.js.map +1 -0
- package/docs/classes/AlreadyRegisteredError.html +4 -4
- package/docs/classes/IdentityServiceConfigNotFoundError.html +4 -4
- package/lib/client/apiClient.js +135 -180
- package/lib/client/apiClient.js.map +1 -0
- package/lib/core/api-key-names.js +8 -14
- package/lib/core/api-key-names.js.map +1 -0
- package/lib/core/auth-store.js +82 -138
- package/lib/core/auth-store.js.map +1 -0
- package/lib/core/crypto.js +2 -5
- package/lib/core/crypto.js.map +1 -0
- package/lib/core/key-manager.js +98 -148
- package/lib/core/key-manager.js.map +1 -0
- package/lib/core/protected-store.d.ts +5 -0
- package/lib/core/protected-store.js +2 -5
- package/lib/core/protected-store.js.map +1 -0
- package/lib/core/publisher.js +2 -5
- package/lib/core/publisher.js.map +1 -0
- package/lib/core/sdk-config.js +56 -56
- package/lib/core/sdk-config.js.map +1 -0
- package/lib/core/subscriber.js +2 -5
- package/lib/core/subscriber.js.map +1 -0
- package/lib/gen/graphql-types.js +96 -135
- package/lib/gen/graphql-types.js.map +1 -0
- package/lib/index.js +6 -67
- package/lib/index.js.map +1 -0
- package/lib/runtimes/browser/browser-crypto.d.ts +2 -0
- package/lib/runtimes/browser/browser-crypto.js +6 -14
- package/lib/runtimes/browser/browser-crypto.js.map +1 -0
- package/lib/runtimes/node/node-crypto.js +5 -11
- package/lib/runtimes/node/node-crypto.js.map +1 -0
- package/lib/sdk.js +6 -18
- package/lib/sdk.js.map +1 -0
- package/lib/user/auth-provider.js +81 -131
- package/lib/user/auth-provider.js.map +1 -0
- package/lib/user/auth.js +127 -179
- package/lib/user/auth.js.map +1 -0
- package/lib/user/error.js +15 -33
- package/lib/user/error.js.map +1 -0
- package/lib/user/identity-provider.js +232 -261
- package/lib/user/identity-provider.js.map +1 -0
- package/lib/user/user-client-interface.js +2 -5
- package/lib/user/user-client-interface.js.map +1 -0
- package/lib/user/user-client.js +423 -510
- package/lib/user/user-client.js.map +1 -0
- package/lib/user/user-key-names.js +6 -12
- package/lib/user/user-key-names.js.map +1 -0
- package/lib/utils/resolvable-promise.js +13 -19
- package/lib/utils/resolvable-promise.js.map +1 -0
- package/package.json +22 -21
package/lib/core/auth-store.js
CHANGED
|
@@ -1,144 +1,88 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
value: true
|
|
5
|
-
});
|
|
6
|
-
exports.AuthenticationStore = void 0;
|
|
7
|
-
|
|
8
|
-
var JWT = _interopRequireWildcard(require("jsonwebtoken"));
|
|
9
|
-
|
|
10
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
11
|
-
|
|
12
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
13
|
-
|
|
14
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
15
|
-
|
|
16
|
-
function _classPrivateFieldInitSpec(obj, privateMap, value) { _checkPrivateRedeclaration(obj, privateMap); privateMap.set(obj, value); }
|
|
17
|
-
|
|
18
|
-
function _checkPrivateRedeclaration(obj, privateCollection) { if (privateCollection.has(obj)) { throw new TypeError("Cannot initialize the same private elements twice on an object"); } }
|
|
19
|
-
|
|
20
|
-
function _classPrivateFieldSet(receiver, privateMap, value) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "set"); _classApplyDescriptorSet(receiver, descriptor, value); return value; }
|
|
21
|
-
|
|
22
|
-
function _classApplyDescriptorSet(receiver, descriptor, value) { if (descriptor.set) { descriptor.set.call(receiver, value); } else { if (!descriptor.writable) { throw new TypeError("attempted to set read only private field"); } descriptor.value = value; } }
|
|
23
|
-
|
|
24
|
-
function _classPrivateFieldGet(receiver, privateMap) { var descriptor = _classExtractFieldDescriptor(receiver, privateMap, "get"); return _classApplyDescriptorGet(receiver, descriptor); }
|
|
25
|
-
|
|
26
|
-
function _classExtractFieldDescriptor(receiver, privateMap, action) { if (!privateMap.has(receiver)) { throw new TypeError("attempted to " + action + " private field on non-instance"); } return privateMap.get(receiver); }
|
|
27
|
-
|
|
28
|
-
function _classApplyDescriptorGet(receiver, descriptor) { if (descriptor.get) { return descriptor.get.call(receiver); } return descriptor.value; }
|
|
29
|
-
|
|
30
|
-
var _secrets = /*#__PURE__*/new WeakMap();
|
|
31
|
-
|
|
1
|
+
var _AuthenticationStore_secrets;
|
|
2
|
+
import { __classPrivateFieldGet, __classPrivateFieldSet } from "tslib";
|
|
3
|
+
import * as JWT from 'jsonwebtoken';
|
|
32
4
|
/**
|
|
33
5
|
* Stores authentication details such as tokens and username
|
|
34
6
|
*/
|
|
35
|
-
class AuthenticationStore {
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
_defineProperty(this, "subscribers", []);
|
|
43
|
-
}
|
|
44
|
-
|
|
45
|
-
/** Adds a secret into private _secrets object */
|
|
46
|
-
async addSecret(keyId, secret) {
|
|
47
|
-
const key = keyId.substr(keyId.lastIndexOf('.') + 1);
|
|
48
|
-
_classPrivateFieldGet(this, _secrets)[key] = secret;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* Adds a string value into authentication store
|
|
52
|
-
*/
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
async setItem(keyId, value) {
|
|
56
|
-
const key = keyId.substr(keyId.lastIndexOf('.') + 1);
|
|
57
|
-
|
|
58
|
-
if (key === 'idToken') {
|
|
59
|
-
// Store the token expiry
|
|
60
|
-
const decoded = JWT.decode(value, {
|
|
61
|
-
complete: true
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
if (decoded) {
|
|
65
|
-
const tokenExpiry = decoded.payload['exp'];
|
|
66
|
-
await this.addSecret('tokenExpiry', {
|
|
67
|
-
type: 'string',
|
|
68
|
-
value: tokenExpiry
|
|
69
|
-
});
|
|
70
|
-
}
|
|
7
|
+
export class AuthenticationStore {
|
|
8
|
+
constructor() {
|
|
9
|
+
/** Do not expose these directly */
|
|
10
|
+
// eslint-disable-next-line tree-shaking/no-side-effects-in-initialization
|
|
11
|
+
_AuthenticationStore_secrets.set(this, {});
|
|
12
|
+
this.subscribers = [];
|
|
71
13
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
14
|
+
/** Adds a secret into private _secrets object */
|
|
15
|
+
async addSecret(keyId, secret) {
|
|
16
|
+
const key = keyId.substr(keyId.lastIndexOf('.') + 1);
|
|
17
|
+
__classPrivateFieldGet(this, _AuthenticationStore_secrets, "f")[key] = secret;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Adds a string value into authentication store
|
|
21
|
+
*/
|
|
22
|
+
async setItem(keyId, value) {
|
|
23
|
+
const key = keyId.substr(keyId.lastIndexOf('.') + 1);
|
|
24
|
+
if (key === 'idToken') {
|
|
25
|
+
// Store the token expiry
|
|
26
|
+
const decoded = JWT.decode(value, { complete: true });
|
|
27
|
+
if (decoded) {
|
|
28
|
+
const tokenExpiry = decoded.payload['exp'];
|
|
29
|
+
await this.addSecret('tokenExpiry', {
|
|
30
|
+
type: 'string',
|
|
31
|
+
value: tokenExpiry,
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
await this.addSecret(key, { type: 'string', value });
|
|
36
|
+
await this.notifySubscribers(key);
|
|
37
|
+
}
|
|
38
|
+
/**
|
|
39
|
+
* Returns a string value from authentication store
|
|
40
|
+
*/
|
|
41
|
+
getItem(keyId) {
|
|
42
|
+
const key = keyId.substr(keyId.lastIndexOf('.') + 1);
|
|
43
|
+
const secret = __classPrivateFieldGet(this, _AuthenticationStore_secrets, "f")[key];
|
|
44
|
+
return secret?.type === 'string' ? secret.value : undefined;
|
|
45
|
+
}
|
|
46
|
+
/**
|
|
47
|
+
* Removes a secret
|
|
48
|
+
*/
|
|
49
|
+
removeItem(keyId) {
|
|
50
|
+
const key = keyId.substr(keyId.lastIndexOf('.') + 1);
|
|
51
|
+
delete __classPrivateFieldGet(this, _AuthenticationStore_secrets, "f")[key];
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Clears all secrets
|
|
55
|
+
*/
|
|
56
|
+
reset() {
|
|
57
|
+
__classPrivateFieldSet(this, _AuthenticationStore_secrets, {}, "f");
|
|
58
|
+
}
|
|
59
|
+
/**
|
|
60
|
+
* Register a subscriber to be notified when items are added
|
|
61
|
+
*
|
|
62
|
+
* @param subscriber a subscriber to be notified when items are added
|
|
63
|
+
*/
|
|
64
|
+
async subscribe(subscriber) {
|
|
65
|
+
this.subscribers.push(subscriber);
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Remove a subscriber from the list of subscribers
|
|
69
|
+
*
|
|
70
|
+
* @param subscriber the subscriber to be removed
|
|
71
|
+
*/
|
|
72
|
+
async unsubscribe(subscriber) {
|
|
73
|
+
const index = this.subscribers.indexOf(subscriber);
|
|
74
|
+
this.subscribers.splice(index, 1);
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* Notify all subscribers that a change event was triggered for a specific item
|
|
78
|
+
*
|
|
79
|
+
* @param itemName the name of the item that changed
|
|
80
|
+
*/
|
|
81
|
+
async notifySubscribers(itemName) {
|
|
82
|
+
for (const subscriber of this.subscribers) {
|
|
83
|
+
subscriber.update(itemName);
|
|
84
|
+
}
|
|
139
85
|
}
|
|
140
|
-
}
|
|
141
|
-
|
|
142
86
|
}
|
|
143
|
-
|
|
144
|
-
|
|
87
|
+
_AuthenticationStore_secrets = new WeakMap();
|
|
88
|
+
//# sourceMappingURL=auth-store.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-store.js","sourceRoot":"","sources":["../../src/core/auth-store.ts"],"names":[],"mappings":";;AAEA,OAAO,KAAK,GAAG,MAAM,cAAc,CAAA;AAcnC;;GAEG;AACH,MAAM,OAAO,mBAAmB;IAAhC;QACE,mCAAmC;QACnC,0EAA0E;QAC1E,uCAAmC,EAAE,EAAA;QACrC,gBAAW,GAAiB,EAAE,CAAA;IAiFhC,CAAC;IA/EC,iDAAiD;IACzC,KAAK,CAAC,SAAS,CAAC,KAAa,EAAE,MAAc;QACnD,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QACpD,uBAAA,IAAI,oCAAS,CAAC,GAAG,CAAC,GAAG,MAAM,CAAA;IAC7B,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,OAAO,CAAC,KAAa,EAAE,KAAa;QAC/C,MAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC,CAAA;QACpD,IAAI,GAAG,KAAK,SAAS,EA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AAC,UAAU,CAAC,CAAA;IACnC,CAAC;IAED;;;;OAIG;IACI,KAAK,CAAC,WAAW,CAAC,UAAsB;QAC7C,MAAM,KAAK,GAAG,IAAI,CAAC,WAAW,CAAC,OAAO,CAAC,UAAU,CAAC,CAAA;QAClD,IAAI,CAAC,WAAW,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC,CAAC,CAAA;IACnC,CAAC;IAED;;;;OAIG;IACH,KAAK,CAAC,iBAAiB,CAAC,QAAgB;QACtC,KAAK,MAAM,UAAU,IAAI,IAAI,CAAC,WAAW,EAAE;YACzC,UAAU,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAA;SAC5B;IACH,CAAC;CACF"}
|
package/lib/core/crypto.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"crypto.js","sourceRoot":"","sources":["../../src/core/crypto.ts"],"names":[],"mappings":""}
|
package/lib/core/key-manager.js
CHANGED
|
@@ -1,158 +1,108 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
});
|
|
6
|
-
exports.KeyManager = void 0;
|
|
7
|
-
|
|
8
|
-
var _sudoCommon = require("@sudoplatform/sudo-common");
|
|
9
|
-
|
|
10
|
-
var _jsonwebtoken = _interopRequireDefault(require("jsonwebtoken"));
|
|
11
|
-
|
|
12
|
-
var uuid = _interopRequireWildcard(require("uuid"));
|
|
13
|
-
|
|
14
|
-
var _nodeCrypto = require("../runtimes/node/node-crypto");
|
|
15
|
-
|
|
16
|
-
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
17
|
-
|
|
18
|
-
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
19
|
-
|
|
20
|
-
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
21
|
-
|
|
22
|
-
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
23
|
-
|
|
1
|
+
import { DecodeError, KeyNotFoundError, } from '@sudoplatform/sudo-common';
|
|
2
|
+
import JWT from 'jsonwebtoken';
|
|
3
|
+
import * as uuid from 'uuid';
|
|
4
|
+
import { cryptoProvider } from '../runtimes/node/node-crypto';
|
|
24
5
|
/**
|
|
25
6
|
* Key Manager
|
|
26
7
|
*/
|
|
27
|
-
class KeyManager {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Adds a string value into key manager
|
|
33
|
-
*/
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
async addString(keyId, value) {
|
|
37
|
-
await this.sudoKeyManager.addPassword(new TextEncoder().encode(value).buffer, keyId);
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Returns a string value from key manager
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
async getString(keyId) {
|
|
45
|
-
const passwordBuffer = await this.sudoKeyManager.getPassword(keyId);
|
|
46
|
-
|
|
47
|
-
if (!passwordBuffer) {
|
|
48
|
-
throw new _sudoCommon.KeyNotFoundError(`No key found for keyId: ${keyId}`);
|
|
8
|
+
export class KeyManager {
|
|
9
|
+
constructor(sudoKeyManager) {
|
|
10
|
+
this.sudoKeyManager = sudoKeyManager;
|
|
49
11
|
}
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
} catch (err) {
|
|
56
|
-
const error = err;
|
|
57
|
-
throw new _sudoCommon.DecodeError(error.message);
|
|
12
|
+
/**
|
|
13
|
+
* Adds a string value into key manager
|
|
14
|
+
*/
|
|
15
|
+
async addString(keyId, value) {
|
|
16
|
+
await this.sudoKeyManager.addPassword(new TextEncoder().encode(value).buffer, keyId);
|
|
58
17
|
}
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
async removeItem(id) {
|
|
76
|
-
await this.sudoKeyManager.deletePassword(id);
|
|
77
|
-
}
|
|
78
|
-
/**
|
|
79
|
-
* Signs a JWT with a signing key that is in key manager
|
|
80
|
-
* @returns JWT data
|
|
81
|
-
*/
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
async signJWT(keyId, payload) {
|
|
85
|
-
const privateKeyBits = await this.sudoKeyManager.getPrivateKey(keyId);
|
|
86
|
-
|
|
87
|
-
if (!privateKeyBits) {
|
|
88
|
-
throw new _sudoCommon.KeyNotFoundError(`No key found for keyId: ${keyId}`);
|
|
18
|
+
/**
|
|
19
|
+
* Returns a string value from key manager
|
|
20
|
+
*/
|
|
21
|
+
async getString(keyId) {
|
|
22
|
+
const passwordBuffer = await this.sudoKeyManager.getPassword(keyId);
|
|
23
|
+
if (!passwordBuffer) {
|
|
24
|
+
throw new KeyNotFoundError(`No key found for keyId: ${keyId}`);
|
|
25
|
+
}
|
|
26
|
+
try {
|
|
27
|
+
return new TextDecoder('utf-8', { fatal: true }).decode(passwordBuffer);
|
|
28
|
+
}
|
|
29
|
+
catch (err) {
|
|
30
|
+
const error = err;
|
|
31
|
+
throw new DecodeError(error.message);
|
|
32
|
+
}
|
|
89
33
|
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
keyid: keyId
|
|
98
|
-
});
|
|
99
|
-
}
|
|
100
|
-
/**
|
|
101
|
-
* Exports public key in a format for use with SudoPlatform
|
|
102
|
-
*/
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
async exportPublicKey(keyId) {
|
|
106
|
-
const publicKey = await this.sudoKeyManager.getPublicKey(keyId);
|
|
107
|
-
|
|
108
|
-
if (!publicKey) {
|
|
109
|
-
throw new Error('Invalid key ID for exportPublicKey');
|
|
34
|
+
/**
|
|
35
|
+
* Generates and adds a new key pair into key manager
|
|
36
|
+
* @returns Key ID
|
|
37
|
+
*/
|
|
38
|
+
async generateKeyPair(keyId = uuid.v4()) {
|
|
39
|
+
await this.sudoKeyManager.generateKeyPair(keyId);
|
|
40
|
+
return keyId;
|
|
110
41
|
}
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
algorithm: KeyManager.Constants.publicKeyAlgorithm,
|
|
117
|
-
symmetricAlgorithm: KeyManager.Constants.symmetricAlgorithm,
|
|
118
|
-
publicKey: base64encoded,
|
|
119
|
-
keyFormat: publicKey.keyFormat
|
|
120
|
-
};
|
|
121
|
-
}
|
|
122
|
-
/**
|
|
123
|
-
* Clears all private keys from memory
|
|
124
|
-
*/
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
async reset() {
|
|
128
|
-
await this.sudoKeyManager.removeAllKeys();
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
async retrieveKeyPair(keyId) {
|
|
132
|
-
const publicKey = await this.sudoKeyManager.getPublicKey(keyId);
|
|
133
|
-
|
|
134
|
-
if (!publicKey) {
|
|
135
|
-
throw new _sudoCommon.KeyNotFoundError(`Public key not found for keyId: ${keyId}`);
|
|
42
|
+
/**
|
|
43
|
+
* Removes a secret
|
|
44
|
+
*/
|
|
45
|
+
async removeItem(id) {
|
|
46
|
+
await this.sudoKeyManager.deletePassword(id);
|
|
136
47
|
}
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
48
|
+
/**
|
|
49
|
+
* Signs a JWT with a signing key that is in key manager
|
|
50
|
+
* @returns JWT data
|
|
51
|
+
*/
|
|
52
|
+
async signJWT(keyId, payload) {
|
|
53
|
+
const privateKeyBits = await this.sudoKeyManager.getPrivateKey(keyId);
|
|
54
|
+
if (!privateKeyBits) {
|
|
55
|
+
throw new KeyNotFoundError(`No key found for keyId: ${keyId}`);
|
|
56
|
+
}
|
|
57
|
+
const base64encoded = cryptoProvider.arrayBufferToBase64(privateKeyBits);
|
|
58
|
+
//PEM encode private key
|
|
59
|
+
const signingKey = `-----BEGIN PRIVATE KEY-----\n${base64encoded}\n-----END PRIVATE KEY-----`;
|
|
60
|
+
return JWT.sign(payload, signingKey, {
|
|
61
|
+
algorithm: 'RS256',
|
|
62
|
+
keyid: keyId,
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Exports public key in a format for use with SudoPlatform
|
|
67
|
+
*/
|
|
68
|
+
async exportPublicKey(keyId) {
|
|
69
|
+
const publicKey = await this.sudoKeyManager.getPublicKey(keyId);
|
|
70
|
+
if (!publicKey) {
|
|
71
|
+
throw new Error('Invalid key ID for exportPublicKey');
|
|
72
|
+
}
|
|
73
|
+
const base64encoded = cryptoProvider.arrayBufferToBase64(publicKey.keyData);
|
|
74
|
+
return {
|
|
75
|
+
keyId,
|
|
76
|
+
algorithm: KeyManager.Constants.publicKeyAlgorithm,
|
|
77
|
+
symmetricAlgorithm: KeyManager.Constants.symmetricAlgorithm,
|
|
78
|
+
publicKey: base64encoded,
|
|
79
|
+
keyFormat: publicKey.keyFormat,
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Clears all private keys from memory
|
|
84
|
+
*/
|
|
85
|
+
async reset() {
|
|
86
|
+
await this.sudoKeyManager.removeAllKeys();
|
|
87
|
+
}
|
|
88
|
+
async retrieveKeyPair(keyId) {
|
|
89
|
+
const publicKey = await this.sudoKeyManager.getPublicKey(keyId);
|
|
90
|
+
if (!publicKey) {
|
|
91
|
+
throw new KeyNotFoundError(`Public key not found for keyId: ${keyId}`);
|
|
92
|
+
}
|
|
93
|
+
const privateKey = await this.sudoKeyManager.getPrivateKey(keyId);
|
|
94
|
+
if (!privateKey) {
|
|
95
|
+
throw new KeyNotFoundError(`Private key not found for keyId: ${keyId}`);
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
publicKey: cryptoProvider.arrayBufferToBase64(publicKey.keyData),
|
|
99
|
+
publicKeyFormat: publicKey.keyFormat,
|
|
100
|
+
privateKey: cryptoProvider.arrayBufferToBase64(privateKey),
|
|
101
|
+
};
|
|
142
102
|
}
|
|
143
|
-
|
|
144
|
-
return {
|
|
145
|
-
publicKey: _nodeCrypto.cryptoProvider.arrayBufferToBase64(publicKey.keyData),
|
|
146
|
-
publicKeyFormat: publicKey.keyFormat,
|
|
147
|
-
privateKey: _nodeCrypto.cryptoProvider.arrayBufferToBase64(privateKey)
|
|
148
|
-
};
|
|
149
|
-
}
|
|
150
|
-
|
|
151
103
|
}
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
symmetricAlgorithm: 'AES/256'
|
|
158
|
-
});
|
|
104
|
+
KeyManager.Constants = {
|
|
105
|
+
publicKeyAlgorithm: 'RSA',
|
|
106
|
+
symmetricAlgorithm: 'AES/256',
|
|
107
|
+
};
|
|
108
|
+
//# sourceMappingURL=key-manager.js.map
|
|
@@ -0,0 +1 @@
|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MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,EAAE,CAAA;IAC3C,CAAC;IAEM,KAAK,CAAC,eAAe,CAAC,KAAa;QACxC,MAAM,SAAS,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,YAAY,CAAC,KAAK,CAAC,CAAA;QAC/D,IAAI,CAAC,SAAS,EAAE;YACd,MAAM,IAAI,gBAAgB,CAAC,mCAAmC,KAAK,EAAE,CAAC,CAAA;SACvE;QACD,MAAM,UAAU,GAAG,MAAM,IAAI,CAAC,cAAc,CAAC,aAAa,CAAC,KAAK,CAAC,CAAA;QACjE,IAAI,CAAC,UAAU,EAAE;YACf,MAAM,IAAI,gBAAgB,CAAC,oCAAoC,KAAK,EAAE,CAAC,CAAA;SACxE;QAED,OAAO;YACL,SAAS,EAAE,cAAc,CAAC,mBAAmB,CAAC,SAAS,CAAC,OAAO,CAAC;YAChE,eAAe,EAAE,SAAS,CAAC,SAAS;YACpC,UAAU,EAAE,cAAc,CAAC,mBAAmB,CAAC,UAAyB,CAAC;SAC1E,CAAA;IACH,CAAC;;AAlHc,oBAAS,GAAG;IACzB,kBAAkB,EAAE,KAAK;IACzB,kBAAkB,EAAE,SAAS;CAC9B,CAAA"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"protected-store.js","sourceRoot":"","sources":["../../src/core/protected-store.ts"],"names":[],"mappings":""}
|
package/lib/core/publisher.js
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"publisher.js","sourceRoot":"","sources":["../../src/core/publisher.ts"],"names":[],"mappings":""}
|