@sphereon/ssi-sdk-ext.kms-local 0.27.1-next.6 → 0.28.1-feature.esm.cjs.11
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/index.cjs +268 -0
- package/dist/index.cjs.map +1 -0
- package/dist/{SphereonKeyManagementSystem.d.ts → index.d.cts} +22 -3
- package/dist/index.d.ts +39 -6
- package/dist/index.js +265 -22
- package/dist/index.js.map +1 -1
- package/dist/ssi-sdk-ext.kms-local.d.ts +1 -2
- package/dist/tsdoc-metadata.json +1 -1
- package/package.json +26 -13
- package/src/SphereonKeyManagementSystem.ts +4 -2
- package/src/__tests__/key-management-system.test.ts +3 -2
- package/src/__tests__/rsa.test.ts +5 -4
- package/dist/SphereonKeyManagementSystem.d.ts.map +0 -1
- package/dist/SphereonKeyManagementSystem.js +0 -290
- package/dist/SphereonKeyManagementSystem.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,268 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _createStarExport(obj) { Object.keys(obj) .filter((key) => key !== "default" && key !== "__esModule") .forEach((key) => { if (exports.hasOwnProperty(key)) { return; } Object.defineProperty(exports, key, {enumerable: true, configurable: true, get: () => obj[key]}); }); } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/SphereonKeyManagementSystem.ts
|
|
5
|
+
var _ssisdkextkeyutils = require('@sphereon/ssi-sdk-ext.key-utils');
|
|
6
|
+
var _kmslocal = require('@veramo/kms-local'); _createStarExport(_kmslocal);
|
|
7
|
+
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
8
|
+
var _elliptic = require('elliptic'); var _elliptic2 = _interopRequireDefault(_elliptic);
|
|
9
|
+
var _uint8arrays = require('uint8arrays'); var u8a = _interopRequireWildcard(_uint8arrays);
|
|
10
|
+
var _ssisdkextx509utils = require('@sphereon/ssi-sdk-ext.x509-utils');
|
|
11
|
+
var { fromString } = u8a;
|
|
12
|
+
var debug = _debug2.default.call(void 0, "sphereon:kms:local");
|
|
13
|
+
var SphereonKeyManagementSystem = class extends _kmslocal.KeyManagementSystem {
|
|
14
|
+
static {
|
|
15
|
+
__name(this, "SphereonKeyManagementSystem");
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
constructor(keyStore) {
|
|
19
|
+
super(keyStore);
|
|
20
|
+
this.privateKeyStore = keyStore;
|
|
21
|
+
}
|
|
22
|
+
async importKey(args) {
|
|
23
|
+
switch (args.type) {
|
|
24
|
+
case KeyType.Bls12381G2.toString():
|
|
25
|
+
if (!args.privateKeyHex || !args.publicKeyHex) {
|
|
26
|
+
throw new Error("invalid_argument: type, publicKeyHex and privateKeyHex are required to import a key");
|
|
27
|
+
}
|
|
28
|
+
const managedKey = this.asSphereonManagedKeyInfo({
|
|
29
|
+
...args,
|
|
30
|
+
alias: args.kid,
|
|
31
|
+
privateKeyHex: args.privateKeyHex,
|
|
32
|
+
publicKeyHex: args.publicKeyHex,
|
|
33
|
+
type: args.type
|
|
34
|
+
});
|
|
35
|
+
await this.privateKeyStore.import({
|
|
36
|
+
alias: managedKey.kid,
|
|
37
|
+
...args
|
|
38
|
+
});
|
|
39
|
+
debug("imported key", managedKey.type, managedKey.publicKeyHex);
|
|
40
|
+
return managedKey;
|
|
41
|
+
case "Secp256k1":
|
|
42
|
+
case "Secp256r1":
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
case "RSA": {
|
|
45
|
+
if (!args.privateKeyHex && !args.privateKeyPEM) {
|
|
46
|
+
throw new Error("invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key");
|
|
47
|
+
}
|
|
48
|
+
const managedKey2 = this.asSphereonManagedKeyInfo({
|
|
49
|
+
alias: args.kid,
|
|
50
|
+
...args
|
|
51
|
+
});
|
|
52
|
+
await this.privateKeyStore.import({
|
|
53
|
+
alias: managedKey2.kid,
|
|
54
|
+
...args
|
|
55
|
+
});
|
|
56
|
+
debug("imported key", managedKey2.type, managedKey2.publicKeyHex);
|
|
57
|
+
return managedKey2;
|
|
58
|
+
}
|
|
59
|
+
default:
|
|
60
|
+
return await super.importKey(args);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
async createKey({ type }) {
|
|
64
|
+
let key;
|
|
65
|
+
switch (type) {
|
|
66
|
+
case KeyType.Bls12381G2: {
|
|
67
|
+
throw Error("BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures");
|
|
68
|
+
}
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
case "RSA": {
|
|
71
|
+
const privateKeyHex = await _ssisdkextkeyutils.generatePrivateKeyHex.call(void 0, type);
|
|
72
|
+
key = await this.importKey({
|
|
73
|
+
type,
|
|
74
|
+
privateKeyHex
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
default:
|
|
79
|
+
key = await super.createKey({
|
|
80
|
+
type
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
debug("Created key", type, key.publicKeyHex);
|
|
84
|
+
return key;
|
|
85
|
+
}
|
|
86
|
+
async sign({ keyRef, algorithm, data }) {
|
|
87
|
+
let privateKey;
|
|
88
|
+
try {
|
|
89
|
+
privateKey = await this.privateKeyStore.get({
|
|
90
|
+
alias: keyRef.kid
|
|
91
|
+
});
|
|
92
|
+
} catch (e) {
|
|
93
|
+
throw new Error(`key_not_found: No key entry found for kid=${keyRef.kid}`);
|
|
94
|
+
}
|
|
95
|
+
if (privateKey.type === KeyType.Bls12381G2) {
|
|
96
|
+
throw Error("BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures");
|
|
97
|
+
} else if (
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
privateKey.type === "RSA" && (typeof algorithm === "undefined" || algorithm === "RS256" || algorithm === "RS512" || algorithm === "PS256" || algorithm === "PS512")
|
|
100
|
+
) {
|
|
101
|
+
return await this.signRSA(privateKey, data, _nullishCoalesce(algorithm, () => ( "PS256")));
|
|
102
|
+
} else {
|
|
103
|
+
return await super.sign({
|
|
104
|
+
keyRef,
|
|
105
|
+
algorithm,
|
|
106
|
+
data
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
throw Error(`not_supported: Cannot sign using key of type ${privateKey.type}`);
|
|
110
|
+
}
|
|
111
|
+
async verify({ publicKeyHex, type, algorithm, data, signature }) {
|
|
112
|
+
if (type === "RSA") {
|
|
113
|
+
return await this.verifyRSA(publicKeyHex, data, _nullishCoalesce(algorithm, () => ( "PS256")), signature);
|
|
114
|
+
}
|
|
115
|
+
throw Error(`KMS verify is not implemented yet for ${type}`);
|
|
116
|
+
}
|
|
117
|
+
asSphereonManagedKeyInfo(args) {
|
|
118
|
+
let key;
|
|
119
|
+
switch (args.type) {
|
|
120
|
+
case KeyType.Bls12381G2:
|
|
121
|
+
key = {
|
|
122
|
+
type: args.type,
|
|
123
|
+
kid: _nullishCoalesce(args.alias, () => ( args.publicKeyHex)),
|
|
124
|
+
publicKeyHex: args.publicKeyHex,
|
|
125
|
+
meta: {
|
|
126
|
+
algorithms: [
|
|
127
|
+
"BLS"
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
break;
|
|
132
|
+
case "Secp256k1": {
|
|
133
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), "base16");
|
|
134
|
+
const secp256k1 = new _elliptic2.default.ec("secp256k1");
|
|
135
|
+
const keyPair = secp256k1.keyFromPrivate(privateBytes, "hex");
|
|
136
|
+
const publicKeyHex = keyPair.getPublic(true, "hex");
|
|
137
|
+
key = {
|
|
138
|
+
type: args.type,
|
|
139
|
+
kid: _nullishCoalesce(args.alias, () => ( publicKeyHex)),
|
|
140
|
+
publicKeyHex,
|
|
141
|
+
meta: {
|
|
142
|
+
jwkThumbprint: _ssisdkextkeyutils.calculateJwkThumbprint.call(void 0, {
|
|
143
|
+
jwk: _ssisdkextkeyutils.toJwk.call(void 0, publicKeyHex, "Secp256k1")
|
|
144
|
+
}),
|
|
145
|
+
algorithms: [
|
|
146
|
+
"ES256K",
|
|
147
|
+
"ES256K-R",
|
|
148
|
+
"eth_signTransaction",
|
|
149
|
+
"eth_signTypedData",
|
|
150
|
+
"eth_signMessage",
|
|
151
|
+
"eth_rawSign"
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
case "Secp256r1": {
|
|
158
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), "base16");
|
|
159
|
+
const secp256r1 = new _elliptic2.default.ec("p256");
|
|
160
|
+
const keyPair = secp256r1.keyFromPrivate(privateBytes, "hex");
|
|
161
|
+
const publicKeyHex = keyPair.getPublic(true, "hex");
|
|
162
|
+
key = {
|
|
163
|
+
type: args.type,
|
|
164
|
+
kid: _nullishCoalesce(args.alias, () => ( publicKeyHex)),
|
|
165
|
+
publicKeyHex,
|
|
166
|
+
meta: {
|
|
167
|
+
jwkThumbprint: _ssisdkextkeyutils.calculateJwkThumbprint.call(void 0, {
|
|
168
|
+
jwk: _ssisdkextkeyutils.toJwk.call(void 0, publicKeyHex, "Secp256r1")
|
|
169
|
+
}),
|
|
170
|
+
algorithms: [
|
|
171
|
+
"ES256"
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
case "RSA": {
|
|
179
|
+
const x509 = _optionalChain([args, 'access', _ => _.meta, 'optionalAccess', _2 => _2.x509]);
|
|
180
|
+
const privateKeyPEM = _nullishCoalesce(_optionalChain([x509, 'optionalAccess', _3 => _3.privateKeyPEM]), () => ( (args.privateKeyHex.includes("---") ? args.privateKeyHex : _ssisdkextx509utils.hexToPEM.call(void 0, args.privateKeyHex, "private"))));
|
|
181
|
+
const publicKeyJwk = _ssisdkextx509utils.PEMToJwk.call(void 0, privateKeyPEM, "public");
|
|
182
|
+
const publicKeyPEM = _ssisdkextx509utils.jwkToPEM.call(void 0, publicKeyJwk, "public");
|
|
183
|
+
const publicKeyHex = _ssisdkextx509utils.PEMToHex.call(void 0, publicKeyPEM);
|
|
184
|
+
const meta = {};
|
|
185
|
+
if (x509) {
|
|
186
|
+
meta.x509 = {
|
|
187
|
+
cn: _nullishCoalesce(_nullishCoalesce(x509.cn, () => ( args.alias)), () => ( publicKeyHex))
|
|
188
|
+
};
|
|
189
|
+
let certChain = _nullishCoalesce(x509.certificateChainPEM, () => ( ""));
|
|
190
|
+
if (x509.certificatePEM) {
|
|
191
|
+
if (!certChain.includes(x509.certificatePEM)) {
|
|
192
|
+
certChain = `${x509.certificatePEM}
|
|
193
|
+
${certChain}`;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (certChain.length > 0) {
|
|
197
|
+
meta.x509.certificateChainPEM = certChain;
|
|
198
|
+
const x5c = _ssisdkextx509utils.pemCertChainTox5c.call(void 0, certChain);
|
|
199
|
+
if (!x509.certificateChainURL) {
|
|
200
|
+
publicKeyJwk.x5c = x5c;
|
|
201
|
+
}
|
|
202
|
+
meta.x509.x5c = x5c;
|
|
203
|
+
}
|
|
204
|
+
if (x509.certificateChainURL) {
|
|
205
|
+
publicKeyJwk.x5u = x509.certificateChainURL;
|
|
206
|
+
meta.x509.x5u = x509.certificateChainURL;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
key = {
|
|
210
|
+
type: args.type,
|
|
211
|
+
kid: _nullishCoalesce(_nullishCoalesce(args.alias, () => ( _optionalChain([meta, 'optionalAccess', _4 => _4.x509, 'optionalAccess', _5 => _5.cn]))), () => ( publicKeyHex)),
|
|
212
|
+
publicKeyHex,
|
|
213
|
+
meta: {
|
|
214
|
+
...meta,
|
|
215
|
+
// todo: could als be DSA etc
|
|
216
|
+
algorithms: [
|
|
217
|
+
"RS256",
|
|
218
|
+
"RS512",
|
|
219
|
+
"PS256",
|
|
220
|
+
"PS512"
|
|
221
|
+
],
|
|
222
|
+
publicKeyJwk,
|
|
223
|
+
publicKeyPEM
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
default:
|
|
229
|
+
throw Error("not_supported: Key type not supported: " + args.type);
|
|
230
|
+
}
|
|
231
|
+
return key;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @returns a base64url encoded signature for the `RS256` alg
|
|
235
|
+
*/
|
|
236
|
+
async signRSA(privateKey, data, signingAlgorithm) {
|
|
237
|
+
const { hashAlgorithm, scheme } = _ssisdkextx509utils.signAlgorithmToSchemeAndHashAlg.call(void 0, signingAlgorithm);
|
|
238
|
+
const signer = new (0, _ssisdkextx509utils.RSASigner)(_ssisdkextx509utils.PEMToJwk.call(void 0, _ssisdkextx509utils.hexToPEM.call(void 0, privateKey.privateKeyHex, "private"), "private"), {
|
|
239
|
+
hashAlgorithm,
|
|
240
|
+
scheme
|
|
241
|
+
});
|
|
242
|
+
const signature = await signer.sign(data);
|
|
243
|
+
return signature;
|
|
244
|
+
}
|
|
245
|
+
async verifyRSA(publicKeyHex, data, signingAlgorithm, signature) {
|
|
246
|
+
const { hashAlgorithm, scheme } = _ssisdkextx509utils.signAlgorithmToSchemeAndHashAlg.call(void 0, signingAlgorithm);
|
|
247
|
+
const signer = new (0, _ssisdkextx509utils.RSASigner)(_ssisdkextx509utils.PEMToJwk.call(void 0, _ssisdkextx509utils.hexToPEM.call(void 0, publicKeyHex, "public"), "public"), {
|
|
248
|
+
hashAlgorithm,
|
|
249
|
+
scheme
|
|
250
|
+
});
|
|
251
|
+
return await signer.verify(data, signature);
|
|
252
|
+
}
|
|
253
|
+
async listKeys() {
|
|
254
|
+
return (await this.privateKeyStore.list({})).map((privateKey) => this.asSphereonManagedKeyInfo(privateKey));
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/index.ts
|
|
259
|
+
|
|
260
|
+
var KeyType = /* @__PURE__ */ function(KeyType2) {
|
|
261
|
+
KeyType2["Bls12381G2"] = "Bls12381G2";
|
|
262
|
+
return KeyType2;
|
|
263
|
+
}({});
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
exports.KeyType = KeyType; exports.SphereonKeyManagementSystem = SphereonKeyManagementSystem;
|
|
268
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["/home/runner/work/SSI-SDK-crypto-extensions/SSI-SDK-crypto-extensions/packages/kms-local/dist/index.cjs","../src/SphereonKeyManagementSystem.ts","../src/index.ts"],"names":["fromString","u8a","debug","Debug","SphereonKeyManagementSystem","KeyManagementSystem","privateKeyStore","constructor","keyStore","importKey","args","type","KeyType","Bls12381G2","toString","privateKeyHex","publicKeyHex","Error","managedKey","asSphereonManagedKeyInfo","alias","kid","import","privateKeyPEM","createKey","key","generatePrivateKeyHex","sign","keyRef","algorithm","data","privateKey","get","e","signature","x509","includes","publicKeyPE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B;AACzC,YAAA;AACF,UAAA;AAC0B,UAAA;AACQA,YAAAA;AACFA,YAAAA;AACC,YAAA;AAGVC,cAAAA;AACrB,YAAA;AACgBA,YAAAA;AAClB,UAAA;AAC8B,UAAA;AAEJC,YAAAA;AACHA,YAAAA;AACvB,UAAA;AACF,QAAA;AAEM,QAAA;AACO7B,UAAAA;AAC0BK,UAAAA;AACrCA,UAAAA;AACM,UAAA;AACDyB,YAAAA;ADlC+D;ACoCtD,YAAA;AAAC,cAAA;AAAS,cAAA;AAAS,cAAA;AAAS,cAAA;AD9B0B,YAAA;AC+BlEC,YAAAA;AACAL,YAAAA;AACF,UAAA;AACF,QAAA;AACA,QAAA;AACF,MAAA;AAEA,MAAA;AACmE,QAAA;AACrE,IAAA;AACOZ,IAAAA;AACT,EAAA;AD9B4E;AACA;AACA;ACiCsC,EAAA;AAC9CkB,IAAAA;AACO,IAAA;AAA0BC,MAAAA;AAAeC,MAAAA;AAAO,IAAA;AACrFf,IAAAA;AAC7BI,IAAAA;AACT,EAAA;AAE6G,EAAA;AACzCS,IAAAA;AACM,IAAA;AAAaC,MAAAA;AAAeC,MAAAA;AAAO,IAAA;AAC1EX,IAAAA;AACnC,EAAA;AAEwD,EAAA;AACmCf,IAAAA;AAC3F,EAAA;AACF;AD3B8E;AACA;AE5PhE;AAcFP;AFiPkE,EAAA;AEjPlEA,EAAAA;AFmPkE;AACA;AACA;AACA;AACA","file":"/home/runner/work/SSI-SDK-crypto-extensions/SSI-SDK-crypto-extensions/packages/kms-local/dist/index.cjs","sourcesContent":[null,"import { calculateJwkThumbprint, generatePrivateKeyHex, toJwk, X509Opts } from '@sphereon/ssi-sdk-ext.key-utils'\n\nimport { IKey, ManagedKeyInfo, MinimalImportableKey, TKeyType } from '@veramo/core'\nimport { AbstractPrivateKeyStore, ManagedPrivateKey } from '@veramo/key-manager'\nimport { KeyManagementSystem } from '@veramo/kms-local'\nimport Debug from 'debug'\nimport elliptic from 'elliptic'\n// @ts-ignore\nimport * as u8a from 'uint8arrays'\nconst { fromString } = u8a\nimport { KeyType, ManagedKeyInfoArgs } from './index'\nimport {\n hexToPEM,\n jwkToPEM,\n pemCertChainTox5c,\n PEMToHex,\n PEMToJwk,\n RSASigner,\n signAlgorithmToSchemeAndHashAlg,\n} from '@sphereon/ssi-sdk-ext.x509-utils'\n\nconst debug = Debug('sphereon:kms:local')\n\nexport class SphereonKeyManagementSystem extends KeyManagementSystem {\n private readonly privateKeyStore: AbstractPrivateKeyStore\n\n constructor(keyStore: AbstractPrivateKeyStore) {\n super(keyStore)\n this.privateKeyStore = keyStore\n }\n\n async importKey(args: Omit<MinimalImportableKey, 'kms'> & { privateKeyPEM?: string }): Promise<ManagedKeyInfo> {\n switch (args.type) {\n case KeyType.Bls12381G2.toString():\n if (!args.privateKeyHex || !args.publicKeyHex) {\n throw new Error('invalid_argument: type, publicKeyHex and privateKeyHex are required to import a key')\n }\n const managedKey = this.asSphereonManagedKeyInfo({\n ...args,\n alias: args.kid,\n privateKeyHex: args.privateKeyHex,\n publicKeyHex: args.publicKeyHex,\n type: args.type,\n })\n await this.privateKeyStore.import({ alias: managedKey.kid, ...args })\n debug('imported key', managedKey.type, managedKey.publicKeyHex)\n return managedKey\n\n case 'Secp256k1':\n case 'Secp256r1':\n // @ts-ignore\n case 'RSA': {\n if (!args.privateKeyHex && !args.privateKeyPEM) {\n throw new Error('invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key')\n }\n const managedKey = this.asSphereonManagedKeyInfo({ alias: args.kid, ...args })\n await this.privateKeyStore.import({ alias: managedKey.kid, ...args })\n debug('imported key', managedKey.type, managedKey.publicKeyHex)\n return managedKey\n }\n default:\n return await super.importKey(args)\n }\n }\n\n async createKey({ type }: { type: TKeyType }): Promise<ManagedKeyInfo> {\n let key: ManagedKeyInfo\n\n switch (type) {\n case KeyType.Bls12381G2: {\n throw Error(\n 'BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures'\n )\n /*// @ts-ignore\n const bbs = await import('@digitalbazaar/bbs-signatures')\n const keyPairBls12381G2 = await bbs.generateKeyPair({\n ciphersuite: 'BLS12-381-SHA-256'\n })\n key = await this.importKey({\n type,\n privateKeyHex: Buffer.from(keyPairBls12381G2.secretKey).toString('hex'),\n publicKeyHex: Buffer.from(keyPairBls12381G2.publicKey).toString('hex'),\n })\n break*/\n }\n\n // @ts-ignore\n case 'RSA': {\n const privateKeyHex = await generatePrivateKeyHex(type)\n key = await this.importKey({\n type,\n privateKeyHex,\n })\n break\n }\n default:\n key = await super.createKey({ type })\n }\n\n debug('Created key', type, key.publicKeyHex)\n\n return key\n }\n\n async sign({ keyRef, algorithm, data }: { keyRef: Pick<IKey, 'kid'>; algorithm?: string; data: Uint8Array }): Promise<string> {\n let privateKey: ManagedPrivateKey\n try {\n privateKey = await this.privateKeyStore.get({ alias: keyRef.kid })\n } catch (e) {\n throw new Error(`key_not_found: No key entry found for kid=${keyRef.kid}`)\n }\n\n if (privateKey.type === KeyType.Bls12381G2) {\n throw Error(\n 'BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures'\n )\n /*// @ts-ignore\n const bbs = await import('@digitalbazaar/bbs-signatures')\n if (!data || Array.isArray(data)) {\n throw new Error('Data must be defined and cannot be an array')\n }\n const keyPair = {\n keyPair: {\n secretKey: Uint8Array.from(Buffer.from(privateKey.privateKeyHex, 'hex')),\n publicKey: Uint8Array.from(Buffer.from(keyRef.kid, 'hex')),\n },\n messages: [data],\n }\n const signature = await bbs.sign({secretKey: privateKey, publicKey, header, messages});\n return signature*/\n } else if (\n // @ts-ignore\n privateKey.type === 'RSA' &&\n (typeof algorithm === 'undefined' || algorithm === 'RS256' || algorithm === 'RS512' || algorithm === 'PS256' || algorithm === 'PS512')\n ) {\n return await this.signRSA(privateKey, data, algorithm ?? 'PS256')\n } else {\n return await super.sign({ keyRef, algorithm, data })\n }\n throw Error(`not_supported: Cannot sign using key of type ${privateKey.type}`)\n }\n\n async verify({\n publicKeyHex,\n type,\n algorithm,\n data,\n signature,\n }: {\n publicKeyHex: string\n type: TKeyType\n algorithm?: string\n data: Uint8Array\n signature: string\n }): Promise<boolean> {\n if (type === 'RSA') {\n return await this.verifyRSA(publicKeyHex, data, algorithm ?? 'PS256', signature)\n }\n throw Error(`KMS verify is not implemented yet for ${type}`)\n }\n\n private asSphereonManagedKeyInfo(args: ManagedKeyInfoArgs): ManagedKeyInfo {\n let key: Partial<ManagedKeyInfo>\n switch (args.type) {\n case KeyType.Bls12381G2:\n key = {\n type: args.type,\n kid: args.alias ?? args.publicKeyHex,\n publicKeyHex: args.publicKeyHex,\n meta: {\n algorithms: ['BLS'],\n },\n }\n break\n case 'Secp256k1': {\n const privateBytes = fromString(args.privateKeyHex.toLowerCase(), 'base16')\n const secp256k1 = new elliptic.ec('secp256k1')\n const keyPair = secp256k1.keyFromPrivate(privateBytes, 'hex')\n const publicKeyHex = keyPair.getPublic(true, 'hex')\n key = {\n type: args.type,\n kid: args.alias ?? publicKeyHex,\n publicKeyHex,\n meta: {\n jwkThumbprint: calculateJwkThumbprint({ jwk: toJwk(publicKeyHex, 'Secp256k1') }),\n algorithms: ['ES256K', 'ES256K-R', 'eth_signTransaction', 'eth_signTypedData', 'eth_signMessage', 'eth_rawSign'],\n },\n }\n break\n }\n case 'Secp256r1': {\n const privateBytes = fromString(args.privateKeyHex.toLowerCase(), 'base16')\n const secp256r1 = new elliptic.ec('p256')\n const keyPair = secp256r1.keyFromPrivate(privateBytes, 'hex')\n const publicKeyHex = keyPair.getPublic(true, 'hex')\n key = {\n type: args.type,\n kid: args.alias ?? publicKeyHex,\n publicKeyHex,\n meta: {\n jwkThumbprint: calculateJwkThumbprint({ jwk: toJwk(publicKeyHex, 'Secp256r1') }),\n algorithms: ['ES256'],\n },\n }\n break\n }\n // @ts-ignore\n case 'RSA': {\n const x509 = args.meta?.x509 as X509Opts\n const privateKeyPEM =\n x509?.privateKeyPEM ?? (args.privateKeyHex.includes('---') ? args.privateKeyHex : hexToPEM(args.privateKeyHex, 'private')) // In case we have x509 opts, the private key hex really was a PEM already (yuck)\n const publicKeyJwk = PEMToJwk(privateKeyPEM, 'public')\n const publicKeyPEM = jwkToPEM(publicKeyJwk, 'public')\n const publicKeyHex = PEMToHex(publicKeyPEM)\n\n const meta = {} as any\n if (x509) {\n meta.x509 = {\n cn: x509.cn ?? args.alias ?? publicKeyHex,\n }\n let certChain: string = x509.certificateChainPEM ?? ''\n if (x509.certificatePEM) {\n if (!certChain.includes(x509.certificatePEM)) {\n certChain = `${x509.certificatePEM}\\n${certChain}`\n }\n }\n if (certChain.length > 0) {\n meta.x509.certificateChainPEM = certChain\n const x5c = pemCertChainTox5c(certChain)\n if (!x509.certificateChainURL) {\n // Do not put the chain in the JWK when the chain is hosted. We do put it in the x509 metadata\n // @ts-ignore\n publicKeyJwk.x5c = x5c\n }\n meta.x509.x5c = x5c\n }\n if (x509.certificateChainURL) {\n // @ts-ignore\n publicKeyJwk.x5u = x509.certificateChainURL\n meta.x509.x5u = x509.certificateChainURL\n }\n }\n\n key = {\n type: args.type,\n kid: args.alias ?? meta?.x509?.cn ?? publicKeyHex,\n publicKeyHex,\n meta: {\n ...meta,\n // todo: could als be DSA etc\n algorithms: ['RS256', 'RS512', 'PS256', 'PS512'],\n publicKeyJwk,\n publicKeyPEM,\n },\n }\n break\n }\n\n default:\n throw Error('not_supported: Key type not supported: ' + args.type)\n }\n return key as ManagedKeyInfo\n }\n\n /**\n * @returns a base64url encoded signature for the `RS256` alg\n */\n private async signRSA(privateKey: ManagedPrivateKey, data: Uint8Array, signingAlgorithm: string): Promise<string> {\n const { hashAlgorithm, scheme } = signAlgorithmToSchemeAndHashAlg(signingAlgorithm)\n const signer = new RSASigner(PEMToJwk(hexToPEM(privateKey.privateKeyHex, 'private'), 'private'), { hashAlgorithm, scheme })\n const signature = await signer.sign(data)\n return signature as string\n }\n\n private async verifyRSA(publicKeyHex: string, data: Uint8Array, signingAlgorithm: string, signature: string) {\n const { hashAlgorithm, scheme } = signAlgorithmToSchemeAndHashAlg(signingAlgorithm)\n const signer = new RSASigner(PEMToJwk(hexToPEM(publicKeyHex, 'public'), 'public'), { hashAlgorithm, scheme })\n return await signer.verify(data, signature)\n }\n\n public async listKeys(): Promise<Array<ManagedKeyInfo>> {\n return (await this.privateKeyStore.list({})).map((privateKey: ManagedPrivateKey) => this.asSphereonManagedKeyInfo(privateKey))\n }\n}\n","import { X509Opts } from '@sphereon/ssi-sdk-ext.key-utils'\nimport { KeyMetadata, TKeyType } from '@veramo/core'\n\nexport { SphereonKeyManagementSystem } from './SphereonKeyManagementSystem'\n\nexport * from '@veramo/kms-local'\n\nexport interface ManagedKeyInfoArgs {\n alias?: string\n type: TKeyType\n privateKeyHex: string\n publicKeyHex?: string\n meta?: ManageKeyInfoMeta | undefined | null\n}\n\nexport interface ManageKeyInfoMeta extends KeyMetadata {\n x509?: X509Opts\n [x: string]: any\n}\nexport enum KeyType {\n Bls12381G2 = 'Bls12381G2',\n}\n"]}
|
|
@@ -1,7 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { X509Opts } from '@sphereon/ssi-sdk-ext.key-utils';
|
|
2
|
+
import { MinimalImportableKey, ManagedKeyInfo, TKeyType, IKey, KeyMetadata } from '@veramo/core';
|
|
2
3
|
import { AbstractPrivateKeyStore } from '@veramo/key-manager';
|
|
3
4
|
import { KeyManagementSystem } from '@veramo/kms-local';
|
|
4
|
-
export
|
|
5
|
+
export * from '@veramo/kms-local';
|
|
6
|
+
|
|
7
|
+
declare class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
5
8
|
private readonly privateKeyStore;
|
|
6
9
|
constructor(keyStore: AbstractPrivateKeyStore);
|
|
7
10
|
importKey(args: Omit<MinimalImportableKey, 'kms'> & {
|
|
@@ -30,4 +33,20 @@ export declare class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
|
30
33
|
private verifyRSA;
|
|
31
34
|
listKeys(): Promise<Array<ManagedKeyInfo>>;
|
|
32
35
|
}
|
|
33
|
-
|
|
36
|
+
|
|
37
|
+
interface ManagedKeyInfoArgs {
|
|
38
|
+
alias?: string;
|
|
39
|
+
type: TKeyType;
|
|
40
|
+
privateKeyHex: string;
|
|
41
|
+
publicKeyHex?: string;
|
|
42
|
+
meta?: ManageKeyInfoMeta | undefined | null;
|
|
43
|
+
}
|
|
44
|
+
interface ManageKeyInfoMeta extends KeyMetadata {
|
|
45
|
+
x509?: X509Opts;
|
|
46
|
+
[x: string]: any;
|
|
47
|
+
}
|
|
48
|
+
declare enum KeyType {
|
|
49
|
+
Bls12381G2 = "Bls12381G2"
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
export { KeyType, type ManageKeyInfoMeta, type ManagedKeyInfoArgs, SphereonKeyManagementSystem };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,19 +1,52 @@
|
|
|
1
1
|
import { X509Opts } from '@sphereon/ssi-sdk-ext.key-utils';
|
|
2
|
-
import {
|
|
3
|
-
|
|
2
|
+
import { MinimalImportableKey, ManagedKeyInfo, TKeyType, IKey, KeyMetadata } from '@veramo/core';
|
|
3
|
+
import { AbstractPrivateKeyStore } from '@veramo/key-manager';
|
|
4
|
+
import { KeyManagementSystem } from '@veramo/kms-local';
|
|
4
5
|
export * from '@veramo/kms-local';
|
|
5
|
-
|
|
6
|
+
|
|
7
|
+
declare class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
8
|
+
private readonly privateKeyStore;
|
|
9
|
+
constructor(keyStore: AbstractPrivateKeyStore);
|
|
10
|
+
importKey(args: Omit<MinimalImportableKey, 'kms'> & {
|
|
11
|
+
privateKeyPEM?: string;
|
|
12
|
+
}): Promise<ManagedKeyInfo>;
|
|
13
|
+
createKey({ type }: {
|
|
14
|
+
type: TKeyType;
|
|
15
|
+
}): Promise<ManagedKeyInfo>;
|
|
16
|
+
sign({ keyRef, algorithm, data }: {
|
|
17
|
+
keyRef: Pick<IKey, 'kid'>;
|
|
18
|
+
algorithm?: string;
|
|
19
|
+
data: Uint8Array;
|
|
20
|
+
}): Promise<string>;
|
|
21
|
+
verify({ publicKeyHex, type, algorithm, data, signature, }: {
|
|
22
|
+
publicKeyHex: string;
|
|
23
|
+
type: TKeyType;
|
|
24
|
+
algorithm?: string;
|
|
25
|
+
data: Uint8Array;
|
|
26
|
+
signature: string;
|
|
27
|
+
}): Promise<boolean>;
|
|
28
|
+
private asSphereonManagedKeyInfo;
|
|
29
|
+
/**
|
|
30
|
+
* @returns a base64url encoded signature for the `RS256` alg
|
|
31
|
+
*/
|
|
32
|
+
private signRSA;
|
|
33
|
+
private verifyRSA;
|
|
34
|
+
listKeys(): Promise<Array<ManagedKeyInfo>>;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
interface ManagedKeyInfoArgs {
|
|
6
38
|
alias?: string;
|
|
7
39
|
type: TKeyType;
|
|
8
40
|
privateKeyHex: string;
|
|
9
41
|
publicKeyHex?: string;
|
|
10
42
|
meta?: ManageKeyInfoMeta | undefined | null;
|
|
11
43
|
}
|
|
12
|
-
|
|
44
|
+
interface ManageKeyInfoMeta extends KeyMetadata {
|
|
13
45
|
x509?: X509Opts;
|
|
14
46
|
[x: string]: any;
|
|
15
47
|
}
|
|
16
|
-
|
|
48
|
+
declare enum KeyType {
|
|
17
49
|
Bls12381G2 = "Bls12381G2"
|
|
18
50
|
}
|
|
19
|
-
|
|
51
|
+
|
|
52
|
+
export { KeyType, type ManageKeyInfoMeta, type ManagedKeyInfoArgs, SphereonKeyManagementSystem };
|
package/dist/index.js
CHANGED
|
@@ -1,25 +1,268 @@
|
|
|
1
|
-
|
|
2
|
-
var
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/SphereonKeyManagementSystem.ts
|
|
5
|
+
import { calculateJwkThumbprint, generatePrivateKeyHex, toJwk } from "@sphereon/ssi-sdk-ext.key-utils";
|
|
6
|
+
import { KeyManagementSystem } from "@veramo/kms-local";
|
|
7
|
+
import Debug from "debug";
|
|
8
|
+
import elliptic from "elliptic";
|
|
9
|
+
import * as u8a from "uint8arrays";
|
|
10
|
+
import { hexToPEM, jwkToPEM, pemCertChainTox5c, PEMToHex, PEMToJwk, RSASigner, signAlgorithmToSchemeAndHashAlg } from "@sphereon/ssi-sdk-ext.x509-utils";
|
|
11
|
+
var { fromString } = u8a;
|
|
12
|
+
var debug = Debug("sphereon:kms:local");
|
|
13
|
+
var SphereonKeyManagementSystem = class extends KeyManagementSystem {
|
|
14
|
+
static {
|
|
15
|
+
__name(this, "SphereonKeyManagementSystem");
|
|
16
|
+
}
|
|
17
|
+
privateKeyStore;
|
|
18
|
+
constructor(keyStore) {
|
|
19
|
+
super(keyStore);
|
|
20
|
+
this.privateKeyStore = keyStore;
|
|
21
|
+
}
|
|
22
|
+
async importKey(args) {
|
|
23
|
+
switch (args.type) {
|
|
24
|
+
case KeyType.Bls12381G2.toString():
|
|
25
|
+
if (!args.privateKeyHex || !args.publicKeyHex) {
|
|
26
|
+
throw new Error("invalid_argument: type, publicKeyHex and privateKeyHex are required to import a key");
|
|
27
|
+
}
|
|
28
|
+
const managedKey = this.asSphereonManagedKeyInfo({
|
|
29
|
+
...args,
|
|
30
|
+
alias: args.kid,
|
|
31
|
+
privateKeyHex: args.privateKeyHex,
|
|
32
|
+
publicKeyHex: args.publicKeyHex,
|
|
33
|
+
type: args.type
|
|
34
|
+
});
|
|
35
|
+
await this.privateKeyStore.import({
|
|
36
|
+
alias: managedKey.kid,
|
|
37
|
+
...args
|
|
38
|
+
});
|
|
39
|
+
debug("imported key", managedKey.type, managedKey.publicKeyHex);
|
|
40
|
+
return managedKey;
|
|
41
|
+
case "Secp256k1":
|
|
42
|
+
case "Secp256r1":
|
|
43
|
+
// @ts-ignore
|
|
44
|
+
case "RSA": {
|
|
45
|
+
if (!args.privateKeyHex && !args.privateKeyPEM) {
|
|
46
|
+
throw new Error("invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key");
|
|
47
|
+
}
|
|
48
|
+
const managedKey2 = this.asSphereonManagedKeyInfo({
|
|
49
|
+
alias: args.kid,
|
|
50
|
+
...args
|
|
51
|
+
});
|
|
52
|
+
await this.privateKeyStore.import({
|
|
53
|
+
alias: managedKey2.kid,
|
|
54
|
+
...args
|
|
55
|
+
});
|
|
56
|
+
debug("imported key", managedKey2.type, managedKey2.publicKeyHex);
|
|
57
|
+
return managedKey2;
|
|
58
|
+
}
|
|
59
|
+
default:
|
|
60
|
+
return await super.importKey(args);
|
|
7
61
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
62
|
+
}
|
|
63
|
+
async createKey({ type }) {
|
|
64
|
+
let key;
|
|
65
|
+
switch (type) {
|
|
66
|
+
case KeyType.Bls12381G2: {
|
|
67
|
+
throw Error("BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures");
|
|
68
|
+
}
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
case "RSA": {
|
|
71
|
+
const privateKeyHex = await generatePrivateKeyHex(type);
|
|
72
|
+
key = await this.importKey({
|
|
73
|
+
type,
|
|
74
|
+
privateKeyHex
|
|
75
|
+
});
|
|
76
|
+
break;
|
|
77
|
+
}
|
|
78
|
+
default:
|
|
79
|
+
key = await super.createKey({
|
|
80
|
+
type
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
debug("Created key", type, key.publicKeyHex);
|
|
84
|
+
return key;
|
|
85
|
+
}
|
|
86
|
+
async sign({ keyRef, algorithm, data }) {
|
|
87
|
+
let privateKey;
|
|
88
|
+
try {
|
|
89
|
+
privateKey = await this.privateKeyStore.get({
|
|
90
|
+
alias: keyRef.kid
|
|
91
|
+
});
|
|
92
|
+
} catch (e) {
|
|
93
|
+
throw new Error(`key_not_found: No key entry found for kid=${keyRef.kid}`);
|
|
94
|
+
}
|
|
95
|
+
if (privateKey.type === KeyType.Bls12381G2) {
|
|
96
|
+
throw Error("BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures");
|
|
97
|
+
} else if (
|
|
98
|
+
// @ts-ignore
|
|
99
|
+
privateKey.type === "RSA" && (typeof algorithm === "undefined" || algorithm === "RS256" || algorithm === "RS512" || algorithm === "PS256" || algorithm === "PS512")
|
|
100
|
+
) {
|
|
101
|
+
return await this.signRSA(privateKey, data, algorithm ?? "PS256");
|
|
102
|
+
} else {
|
|
103
|
+
return await super.sign({
|
|
104
|
+
keyRef,
|
|
105
|
+
algorithm,
|
|
106
|
+
data
|
|
107
|
+
});
|
|
108
|
+
}
|
|
109
|
+
throw Error(`not_supported: Cannot sign using key of type ${privateKey.type}`);
|
|
110
|
+
}
|
|
111
|
+
async verify({ publicKeyHex, type, algorithm, data, signature }) {
|
|
112
|
+
if (type === "RSA") {
|
|
113
|
+
return await this.verifyRSA(publicKeyHex, data, algorithm ?? "PS256", signature);
|
|
114
|
+
}
|
|
115
|
+
throw Error(`KMS verify is not implemented yet for ${type}`);
|
|
116
|
+
}
|
|
117
|
+
asSphereonManagedKeyInfo(args) {
|
|
118
|
+
let key;
|
|
119
|
+
switch (args.type) {
|
|
120
|
+
case KeyType.Bls12381G2:
|
|
121
|
+
key = {
|
|
122
|
+
type: args.type,
|
|
123
|
+
kid: args.alias ?? args.publicKeyHex,
|
|
124
|
+
publicKeyHex: args.publicKeyHex,
|
|
125
|
+
meta: {
|
|
126
|
+
algorithms: [
|
|
127
|
+
"BLS"
|
|
128
|
+
]
|
|
129
|
+
}
|
|
130
|
+
};
|
|
131
|
+
break;
|
|
132
|
+
case "Secp256k1": {
|
|
133
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), "base16");
|
|
134
|
+
const secp256k1 = new elliptic.ec("secp256k1");
|
|
135
|
+
const keyPair = secp256k1.keyFromPrivate(privateBytes, "hex");
|
|
136
|
+
const publicKeyHex = keyPair.getPublic(true, "hex");
|
|
137
|
+
key = {
|
|
138
|
+
type: args.type,
|
|
139
|
+
kid: args.alias ?? publicKeyHex,
|
|
140
|
+
publicKeyHex,
|
|
141
|
+
meta: {
|
|
142
|
+
jwkThumbprint: calculateJwkThumbprint({
|
|
143
|
+
jwk: toJwk(publicKeyHex, "Secp256k1")
|
|
144
|
+
}),
|
|
145
|
+
algorithms: [
|
|
146
|
+
"ES256K",
|
|
147
|
+
"ES256K-R",
|
|
148
|
+
"eth_signTransaction",
|
|
149
|
+
"eth_signTypedData",
|
|
150
|
+
"eth_signMessage",
|
|
151
|
+
"eth_rawSign"
|
|
152
|
+
]
|
|
153
|
+
}
|
|
154
|
+
};
|
|
155
|
+
break;
|
|
156
|
+
}
|
|
157
|
+
case "Secp256r1": {
|
|
158
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), "base16");
|
|
159
|
+
const secp256r1 = new elliptic.ec("p256");
|
|
160
|
+
const keyPair = secp256r1.keyFromPrivate(privateBytes, "hex");
|
|
161
|
+
const publicKeyHex = keyPair.getPublic(true, "hex");
|
|
162
|
+
key = {
|
|
163
|
+
type: args.type,
|
|
164
|
+
kid: args.alias ?? publicKeyHex,
|
|
165
|
+
publicKeyHex,
|
|
166
|
+
meta: {
|
|
167
|
+
jwkThumbprint: calculateJwkThumbprint({
|
|
168
|
+
jwk: toJwk(publicKeyHex, "Secp256r1")
|
|
169
|
+
}),
|
|
170
|
+
algorithms: [
|
|
171
|
+
"ES256"
|
|
172
|
+
]
|
|
173
|
+
}
|
|
174
|
+
};
|
|
175
|
+
break;
|
|
176
|
+
}
|
|
177
|
+
// @ts-ignore
|
|
178
|
+
case "RSA": {
|
|
179
|
+
const x509 = args.meta?.x509;
|
|
180
|
+
const privateKeyPEM = x509?.privateKeyPEM ?? (args.privateKeyHex.includes("---") ? args.privateKeyHex : hexToPEM(args.privateKeyHex, "private"));
|
|
181
|
+
const publicKeyJwk = PEMToJwk(privateKeyPEM, "public");
|
|
182
|
+
const publicKeyPEM = jwkToPEM(publicKeyJwk, "public");
|
|
183
|
+
const publicKeyHex = PEMToHex(publicKeyPEM);
|
|
184
|
+
const meta = {};
|
|
185
|
+
if (x509) {
|
|
186
|
+
meta.x509 = {
|
|
187
|
+
cn: x509.cn ?? args.alias ?? publicKeyHex
|
|
188
|
+
};
|
|
189
|
+
let certChain = x509.certificateChainPEM ?? "";
|
|
190
|
+
if (x509.certificatePEM) {
|
|
191
|
+
if (!certChain.includes(x509.certificatePEM)) {
|
|
192
|
+
certChain = `${x509.certificatePEM}
|
|
193
|
+
${certChain}`;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
if (certChain.length > 0) {
|
|
197
|
+
meta.x509.certificateChainPEM = certChain;
|
|
198
|
+
const x5c = pemCertChainTox5c(certChain);
|
|
199
|
+
if (!x509.certificateChainURL) {
|
|
200
|
+
publicKeyJwk.x5c = x5c;
|
|
201
|
+
}
|
|
202
|
+
meta.x509.x5c = x5c;
|
|
203
|
+
}
|
|
204
|
+
if (x509.certificateChainURL) {
|
|
205
|
+
publicKeyJwk.x5u = x509.certificateChainURL;
|
|
206
|
+
meta.x509.x5u = x509.certificateChainURL;
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
key = {
|
|
210
|
+
type: args.type,
|
|
211
|
+
kid: args.alias ?? meta?.x509?.cn ?? publicKeyHex,
|
|
212
|
+
publicKeyHex,
|
|
213
|
+
meta: {
|
|
214
|
+
...meta,
|
|
215
|
+
// todo: could als be DSA etc
|
|
216
|
+
algorithms: [
|
|
217
|
+
"RS256",
|
|
218
|
+
"RS512",
|
|
219
|
+
"PS256",
|
|
220
|
+
"PS512"
|
|
221
|
+
],
|
|
222
|
+
publicKeyJwk,
|
|
223
|
+
publicKeyPEM
|
|
224
|
+
}
|
|
225
|
+
};
|
|
226
|
+
break;
|
|
227
|
+
}
|
|
228
|
+
default:
|
|
229
|
+
throw Error("not_supported: Key type not supported: " + args.type);
|
|
230
|
+
}
|
|
231
|
+
return key;
|
|
232
|
+
}
|
|
233
|
+
/**
|
|
234
|
+
* @returns a base64url encoded signature for the `RS256` alg
|
|
235
|
+
*/
|
|
236
|
+
async signRSA(privateKey, data, signingAlgorithm) {
|
|
237
|
+
const { hashAlgorithm, scheme } = signAlgorithmToSchemeAndHashAlg(signingAlgorithm);
|
|
238
|
+
const signer = new RSASigner(PEMToJwk(hexToPEM(privateKey.privateKeyHex, "private"), "private"), {
|
|
239
|
+
hashAlgorithm,
|
|
240
|
+
scheme
|
|
241
|
+
});
|
|
242
|
+
const signature = await signer.sign(data);
|
|
243
|
+
return signature;
|
|
244
|
+
}
|
|
245
|
+
async verifyRSA(publicKeyHex, data, signingAlgorithm, signature) {
|
|
246
|
+
const { hashAlgorithm, scheme } = signAlgorithmToSchemeAndHashAlg(signingAlgorithm);
|
|
247
|
+
const signer = new RSASigner(PEMToJwk(hexToPEM(publicKeyHex, "public"), "public"), {
|
|
248
|
+
hashAlgorithm,
|
|
249
|
+
scheme
|
|
250
|
+
});
|
|
251
|
+
return await signer.verify(data, signature);
|
|
252
|
+
}
|
|
253
|
+
async listKeys() {
|
|
254
|
+
return (await this.privateKeyStore.list({})).map((privateKey) => this.asSphereonManagedKeyInfo(privateKey));
|
|
255
|
+
}
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
// src/index.ts
|
|
259
|
+
export * from "@veramo/kms-local";
|
|
260
|
+
var KeyType = /* @__PURE__ */ function(KeyType2) {
|
|
261
|
+
KeyType2["Bls12381G2"] = "Bls12381G2";
|
|
262
|
+
return KeyType2;
|
|
263
|
+
}({});
|
|
264
|
+
export {
|
|
265
|
+
KeyType,
|
|
266
|
+
SphereonKeyManagementSystem
|
|
15
267
|
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
exports.KeyType = exports.SphereonKeyManagementSystem = void 0;
|
|
18
|
-
var SphereonKeyManagementSystem_1 = require("./SphereonKeyManagementSystem");
|
|
19
|
-
Object.defineProperty(exports, "SphereonKeyManagementSystem", { enumerable: true, get: function () { return SphereonKeyManagementSystem_1.SphereonKeyManagementSystem; } });
|
|
20
|
-
__exportStar(require("@veramo/kms-local"), exports);
|
|
21
|
-
var KeyType;
|
|
22
|
-
(function (KeyType) {
|
|
23
|
-
KeyType["Bls12381G2"] = "Bls12381G2";
|
|
24
|
-
})(KeyType || (exports.KeyType = KeyType = {}));
|
|
25
268
|
//# sourceMappingURL=index.js.map
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;AAGA,6EAA2E;AAAlE,0IAAA,2BAA2B,OAAA;AAEpC,oDAAiC;AAcjC,IAAY,OAEX;AAFD,WAAY,OAAO;IACjB,oCAAyB,CAAA;AAC3B,CAAC,EAFW,OAAO,uBAAP,OAAO,QAElB"}
|
|
1
|
+
{"version":3,"sources":["../src/SphereonKeyManagementSystem.ts","../src/index.ts"],"sourcesContent":["import { calculateJwkThumbprint, generatePrivateKeyHex, toJwk, X509Opts } from '@sphereon/ssi-sdk-ext.key-utils'\n\nimport { IKey, ManagedKeyInfo, MinimalImportableKey, TKeyType } from '@veramo/core'\nimport { AbstractPrivateKeyStore, ManagedPrivateKey } from '@veramo/key-manager'\nimport { KeyManagementSystem } from '@veramo/kms-local'\nimport Debug from 'debug'\nimport elliptic from 'elliptic'\n// @ts-ignore\nimport * as u8a from 'uint8arrays'\nconst { fromString } = u8a\nimport { KeyType, ManagedKeyInfoArgs } from './index'\nimport {\n hexToPEM,\n jwkToPEM,\n pemCertChainTox5c,\n PEMToHex,\n PEMToJwk,\n RSASigner,\n signAlgorithmToSchemeAndHashAlg,\n} from '@sphereon/ssi-sdk-ext.x509-utils'\n\nconst debug = Debug('sphereon:kms:local')\n\nexport class SphereonKeyManagementSystem extends KeyManagementSystem {\n private readonly privateKeyStore: AbstractPrivateKeyStore\n\n constructor(keyStore: AbstractPrivateKeyStore) {\n super(keyStore)\n this.privateKeyStore = keyStore\n }\n\n async importKey(args: Omit<MinimalImportableKey, 'kms'> & { privateKeyPEM?: string }): Promise<ManagedKeyInfo> {\n switch (args.type) {\n case KeyType.Bls12381G2.toString():\n if (!args.privateKeyHex || !args.publicKeyHex) {\n throw new Error('invalid_argument: type, publicKeyHex and privateKeyHex are required to import a key')\n }\n const managedKey = this.asSphereonManagedKeyInfo({\n ...args,\n alias: args.kid,\n privateKeyHex: args.privateKeyHex,\n publicKeyHex: args.publicKeyHex,\n type: args.type,\n })\n await this.privateKeyStore.import({ alias: managedKey.kid, ...args })\n debug('imported key', managedKey.type, managedKey.publicKeyHex)\n return managedKey\n\n case 'Secp256k1':\n case 'Secp256r1':\n // @ts-ignore\n case 'RSA': {\n if (!args.privateKeyHex && !args.privateKeyPEM) {\n throw new Error('invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key')\n }\n const managedKey = this.asSphereonManagedKeyInfo({ alias: args.kid, ...args })\n await this.privateKeyStore.import({ alias: managedKey.kid, ...args })\n debug('imported key', managedKey.type, managedKey.publicKeyHex)\n return managedKey\n }\n default:\n return await super.importKey(args)\n }\n }\n\n async createKey({ type }: { type: TKeyType }): Promise<ManagedKeyInfo> {\n let key: ManagedKeyInfo\n\n switch (type) {\n case KeyType.Bls12381G2: {\n throw Error(\n 'BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures'\n )\n /*// @ts-ignore\n const bbs = await import('@digitalbazaar/bbs-signatures')\n const keyPairBls12381G2 = await bbs.generateKeyPair({\n ciphersuite: 'BLS12-381-SHA-256'\n })\n key = await this.importKey({\n type,\n privateKeyHex: Buffer.from(keyPairBls12381G2.secretKey).toString('hex'),\n publicKeyHex: Buffer.from(keyPairBls12381G2.publicKey).toString('hex'),\n })\n break*/\n }\n\n // @ts-ignore\n case 'RSA': {\n const privateKeyHex = await generatePrivateKeyHex(type)\n key = await this.importKey({\n type,\n privateKeyHex,\n })\n break\n }\n default:\n key = await super.createKey({ type })\n }\n\n debug('Created key', type, key.publicKeyHex)\n\n return key\n }\n\n async sign({ keyRef, algorithm, data }: { keyRef: Pick<IKey, 'kid'>; algorithm?: string; data: Uint8Array }): Promise<string> {\n let privateKey: ManagedPrivateKey\n try {\n privateKey = await this.privateKeyStore.get({ alias: keyRef.kid })\n } catch (e) {\n throw new Error(`key_not_found: No key entry found for kid=${keyRef.kid}`)\n }\n\n if (privateKey.type === KeyType.Bls12381G2) {\n throw Error(\n 'BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures'\n )\n /*// @ts-ignore\n const bbs = await import('@digitalbazaar/bbs-signatures')\n if (!data || Array.isArray(data)) {\n throw new Error('Data must be defined and cannot be an array')\n }\n const keyPair = {\n keyPair: {\n secretKey: Uint8Array.from(Buffer.from(privateKey.privateKeyHex, 'hex')),\n publicKey: Uint8Array.from(Buffer.from(keyRef.kid, 'hex')),\n },\n messages: [data],\n }\n const signature = await bbs.sign({secretKey: privateKey, publicKey, header, messages});\n return signature*/\n } else if (\n // @ts-ignore\n privateKey.type === 'RSA' &&\n (typeof algorithm === 'undefined' || algorithm === 'RS256' || algorithm === 'RS512' || algorithm === 'PS256' || algorithm === 'PS512')\n ) {\n return await this.signRSA(privateKey, data, algorithm ?? 'PS256')\n } else {\n return await super.sign({ keyRef, algorithm, data })\n }\n throw Error(`not_supported: Cannot sign using key of type ${privateKey.type}`)\n }\n\n async verify({\n publicKeyHex,\n type,\n algorithm,\n data,\n signature,\n }: {\n publicKeyHex: string\n type: TKeyType\n algorithm?: string\n data: Uint8Array\n signature: string\n }): Promise<boolean> {\n if (type === 'RSA') {\n return await this.verifyRSA(publicKeyHex, data, algorithm ?? 'PS256', signature)\n }\n throw Error(`KMS verify is not implemented yet for ${type}`)\n }\n\n private asSphereonManagedKeyInfo(args: ManagedKeyInfoArgs): ManagedKeyInfo {\n let key: Partial<ManagedKeyInfo>\n switch (args.type) {\n case KeyType.Bls12381G2:\n key = {\n type: args.type,\n kid: args.alias ?? args.publicKeyHex,\n publicKeyHex: args.publicKeyHex,\n meta: {\n algorithms: ['BLS'],\n },\n }\n break\n case 'Secp256k1': {\n const privateBytes = fromString(args.privateKeyHex.toLowerCase(), 'base16')\n const secp256k1 = new elliptic.ec('secp256k1')\n const keyPair = secp256k1.keyFromPrivate(privateBytes, 'hex')\n const publicKeyHex = keyPair.getPublic(true, 'hex')\n key = {\n type: args.type,\n kid: args.alias ?? publicKeyHex,\n publicKeyHex,\n meta: {\n jwkThumbprint: calculateJwkThumbprint({ jwk: toJwk(publicKeyHex, 'Secp256k1') }),\n algorithms: ['ES256K', 'ES256K-R', 'eth_signTransaction', 'eth_signTypedData', 'eth_signMessage', 'eth_rawSign'],\n },\n }\n break\n }\n case 'Secp256r1': {\n const privateBytes = fromString(args.privateKeyHex.toLowerCase(), 'base16')\n const secp256r1 = new elliptic.ec('p256')\n const keyPair = secp256r1.keyFromPrivate(privateBytes, 'hex')\n const publicKeyHex = keyPair.getPublic(true, 'hex')\n key = {\n type: args.type,\n kid: args.alias ?? publicKeyHex,\n publicKeyHex,\n meta: {\n jwkThumbprint: calculateJwkThumbprint({ jwk: toJwk(publicKeyHex, 'Secp256r1') }),\n algorithms: ['ES256'],\n },\n }\n break\n }\n // @ts-ignore\n case 'RSA': {\n const x509 = args.meta?.x509 as X509Opts\n const privateKeyPEM =\n x509?.privateKeyPEM ?? (args.privateKeyHex.includes('---') ? args.privateKeyHex : hexToPEM(args.privateKeyHex, 'private')) // In case we have x509 opts, the private key hex really was a PEM already (yuck)\n const publicKeyJwk = PEMToJwk(privateKeyPEM, 'public')\n const publicKeyPEM = jwkToPEM(publicKeyJwk, 'public')\n const publicKeyHex = PEMToHex(publicKeyPEM)\n\n const meta = {} as any\n if (x509) {\n meta.x509 = {\n cn: x509.cn ?? args.alias ?? publicKeyHex,\n }\n let certChain: string = x509.certificateChainPEM ?? ''\n if (x509.certificatePEM) {\n if (!certChain.includes(x509.certificatePEM)) {\n certChain = `${x509.certificatePEM}\\n${certChain}`\n }\n }\n if (certChain.length > 0) {\n meta.x509.certificateChainPEM = certChain\n const x5c = pemCertChainTox5c(certChain)\n if (!x509.certificateChainURL) {\n // Do not put the chain in the JWK when the chain is hosted. We do put it in the x509 metadata\n // @ts-ignore\n publicKeyJwk.x5c = x5c\n }\n meta.x509.x5c = x5c\n }\n if (x509.certificateChainURL) {\n // @ts-ignore\n publicKeyJwk.x5u = x509.certificateChainURL\n meta.x509.x5u = x509.certificateChainURL\n }\n }\n\n key = {\n type: args.type,\n kid: args.alias ?? meta?.x509?.cn ?? publicKeyHex,\n publicKeyHex,\n meta: {\n ...meta,\n // todo: could als be DSA etc\n algorithms: ['RS256', 'RS512', 'PS256', 'PS512'],\n publicKeyJwk,\n publicKeyPEM,\n },\n }\n break\n }\n\n default:\n throw Error('not_supported: Key type not supported: ' + args.type)\n }\n return key as ManagedKeyInfo\n }\n\n /**\n * @returns a base64url encoded signature for the `RS256` alg\n */\n private async signRSA(privateKey: ManagedPrivateKey, data: Uint8Array, signingAlgorithm: string): Promise<string> {\n const { hashAlgorithm, scheme } = signAlgorithmToSchemeAndHashAlg(signingAlgorithm)\n const signer = new RSASigner(PEMToJwk(hexToPEM(privateKey.privateKeyHex, 'private'), 'private'), { hashAlgorithm, scheme })\n const signature = await signer.sign(data)\n return signature as string\n }\n\n private async verifyRSA(publicKeyHex: string, data: Uint8Array, signingAlgorithm: string, signature: string) {\n const { hashAlgorithm, scheme } = signAlgorithmToSchemeAndHashAlg(signingAlgorithm)\n const signer = new RSASigner(PEMToJwk(hexToPEM(publicKeyHex, 'public'), 'public'), { hashAlgorithm, scheme })\n return await signer.verify(data, signature)\n }\n\n public async listKeys(): Promise<Array<ManagedKeyInfo>> {\n return (await this.privateKeyStore.list({})).map((privateKey: ManagedPrivateKey) => this.asSphereonManagedKeyInfo(privateKey))\n }\n}\n","import { X509Opts } from '@sphereon/ssi-sdk-ext.key-utils'\nimport { KeyMetadata, TKeyType } from '@veramo/core'\n\nexport { SphereonKeyManagementSystem } from './SphereonKeyManagementSystem'\n\nexport * from '@veramo/kms-local'\n\nexport interface ManagedKeyInfoArgs {\n alias?: string\n type: TKeyType\n privateKeyHex: string\n publicKeyHex?: string\n meta?: ManageKeyInfoMeta | undefined | null\n}\n\nexport interface ManageKeyInfoMeta extends KeyMetadata {\n x509?: X509Opts\n [x: string]: any\n}\nexport enum KeyType {\n Bls12381G2 = 'Bls12381G2',\n}\n"],"mappings":";;;;AAAA,SAASA,wBAAwBC,uBAAuBC,aAAuB;AAI/E,SAASC,2BAA2B;AACpC,OAAOC,WAAW;AAClB,OAAOC,cAAc;AAErB,YAAYC,SAAS;AAGrB,SACEC,UACAC,UACAC,mBACAC,UACAC,UACAC,WACAC,uCACK;AAVP,IAAM,EAAEC,WAAU,IAAKC;AAYvB,IAAMC,QAAQC,MAAM,oBAAA;AAEb,IAAMC,8BAAN,cAA0CC,oBAAAA;EAvBjD,OAuBiDA;;;EAC9BC;EAEjBC,YAAYC,UAAmC;AAC7C,UAAMA,QAAAA;AACN,SAAKF,kBAAkBE;EACzB;EAEA,MAAMC,UAAUC,MAA+F;AAC7G,YAAQA,KAAKC,MAAI;MACf,KAAKC,QAAQC,WAAWC,SAAQ;AAC9B,YAAI,CAACJ,KAAKK,iBAAiB,CAACL,KAAKM,cAAc;AAC7C,gBAAM,IAAIC,MAAM,qFAAA;QAClB;AACA,cAAMC,aAAa,KAAKC,yBAAyB;UAC/C,GAAGT;UACHU,OAAOV,KAAKW;UACZN,eAAeL,KAAKK;UACpBC,cAAcN,KAAKM;UACnBL,MAAMD,KAAKC;QACb,CAAA;AACA,cAAM,KAAKL,gBAAgBgB,OAAO;UAAEF,OAAOF,WAAWG;UAAK,GAAGX;QAAK,CAAA;AACnER,cAAM,gBAAgBgB,WAAWP,M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D,KAAKC;UACXU,KAAKX,KAAKU,SAASkB,MAAMe,MAAMQ,MAAM7C;UACrCA;UACAsB,MAAM;YACJ,GAAGA;;YAEHC,YAAY;cAAC;cAAS;cAAS;cAAS;;YACxCiB;YACAE;UACF;QACF;AACA;MACF;MAEA;AACE,cAAMzC,MAAM,4CAA4CP,KAAKC,IAAI;IACrE;AACA,WAAOc;EACT;;;;EAKA,MAAcS,QAAQH,YAA+BD,MAAkBwC,kBAA2C;AAChH,UAAM,EAAEC,eAAeC,OAAM,IAAKC,gCAAgCH,gBAAAA;AAClE,UAAMI,SAAS,IAAIC,UAAUlB,SAASF,SAASxB,WAAWhB,eAAe,SAAA,GAAY,SAAA,GAAY;MAAEwD;MAAeC;IAAO,CAAA;AACzH,UAAMpC,YAAY,MAAMsC,OAAO/C,KAAKG,IAAAA;AACpC,WAAOM;EACT;EAEA,MAAcC,UAAUrB,cAAsBc,MAAkBwC,kBAA0BlC,WAAmB;AAC3G,UAAM,EAAEmC,eAAeC,OAAM,IAAKC,gCAAgCH,gBAAAA;AAClE,UAAMI,SAAS,IAAIC,UAAUlB,SAASF,SAASvC,cAAc,QAAA,GAAW,QAAA,GAAW;MAAEuD;MAAeC;IAAO,CAAA;AAC3G,WAAO,MAAME,OAAOvC,OAAOL,MAAMM,SAAAA;EACnC;EAEA,MAAawC,WAA2C;AACtD,YAAQ,MAAM,KAAKtE,gBAAgBuE,KAAK,CAAC,CAAA,GAAIC,IAAI,CAAC/C,eAAkC,KAAKZ,yBAAyBY,UAAAA,CAAAA;EACpH;AACF;;;ACtRA,cAAc;AAcP,IAAKgD,UAAAA,yBAAAA,UAAAA;;SAAAA;;","names":["calculateJwkThumbprint","generatePrivateKeyHex","toJwk","KeyManagementSystem","Debug","elliptic","u8a","hexToPEM","jwkToPEM","pemCertChainTox5c","PEMToHex","PEMToJwk","RSASigner","signAlgorithmToSchemeAndHashAlg","fromString","u8a","debug","Debug","SphereonKeyManagementSystem","KeyManagementSystem","privateKeyStore","constructor","keyStore","importKey","args","type","KeyType","Bls12381G2","toString","privateKeyHex","publicKeyHex","Error","managedKey","asSphereonManagedKeyInfo","alias","kid","import","privateKeyPEM","createKey","key","generatePrivateKeyHex","sign","keyRef","algorithm","data","privateKey","get","e","signRSA","verify","signature","verifyRSA","meta","algorithms","privateBytes","toLowerCase","secp256k1","elliptic","ec","keyPair","keyFromPrivate","getPublic","jwkThumbprint","calculateJwkThumbprint","jwk","toJwk","secp256r1","x509","includes","hexToPEM","publicKeyJwk","PEMToJwk","publicKeyPEM","jwkToPEM","PEMToHex","cn","certChain","certificateChainPEM","certificatePEM","length","x5c","pemCertChainTox5c","certificateChainURL","x5u","signingAlgorithm","hashAlgorithm","scheme","signAlgorithmToSchemeAndHashAlg","signer","RSASigner","listKeys","list","map","KeyType"]}
|
|
@@ -7,10 +7,9 @@ import { MinimalImportableKey } from '@veramo/core';
|
|
|
7
7
|
import { TKeyType } from '@veramo/core';
|
|
8
8
|
import { X509Opts } from '@sphereon/ssi-sdk-ext.key-utils';
|
|
9
9
|
|
|
10
|
-
declare enum
|
|
10
|
+
export declare enum KeyType {
|
|
11
11
|
Bls12381G2 = "Bls12381G2"
|
|
12
12
|
}
|
|
13
|
-
export { KeyType_2 as KeyType }
|
|
14
13
|
|
|
15
14
|
export declare interface ManagedKeyInfoArgs {
|
|
16
15
|
alias?: string;
|
package/dist/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,34 +1,47 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk-ext.kms-local",
|
|
3
3
|
"description": "Sphereon Local Key Management System with support for BLS/BBS+, RSA keys",
|
|
4
|
-
"version": "0.
|
|
5
|
-
"source": "src/index.ts",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"version": "0.28.1-feature.esm.cjs.11+5582cc4",
|
|
5
|
+
"source": "./src/index.ts",
|
|
6
|
+
"type": "module",
|
|
7
|
+
"main": "./dist/index.cjs",
|
|
8
|
+
"module": "./dist/index.js",
|
|
9
|
+
"types": "./dist/index.d.ts",
|
|
10
|
+
"exports": {
|
|
11
|
+
"import": {
|
|
12
|
+
"types": "./dist/index.d.ts",
|
|
13
|
+
"import": "./dist/index.js"
|
|
14
|
+
},
|
|
15
|
+
"require": {
|
|
16
|
+
"types": "./dist/index.d.cts",
|
|
17
|
+
"require": "./dist/index.cjs"
|
|
18
|
+
}
|
|
19
|
+
},
|
|
8
20
|
"scripts": {
|
|
9
|
-
"build": "
|
|
21
|
+
"build": "tsup --config ../../tsup.config.ts --tsconfig ../../tsconfig.tsup.json && sphereon dev generate-plugin-schema",
|
|
10
22
|
"generate-plugin-schema": "sphereon dev generate-plugin-schema"
|
|
11
23
|
},
|
|
12
24
|
"dependencies": {
|
|
13
|
-
"@sphereon/ssi-sdk-ext.did-utils": "0.
|
|
14
|
-
"@sphereon/ssi-sdk-ext.key-utils": "0.
|
|
15
|
-
"@sphereon/ssi-sdk-ext.x509-utils": "0.
|
|
25
|
+
"@sphereon/ssi-sdk-ext.did-utils": "^0.28.1-feature.esm.cjs.11+5582cc4",
|
|
26
|
+
"@sphereon/ssi-sdk-ext.key-utils": "^0.28.1-feature.esm.cjs.11+5582cc4",
|
|
27
|
+
"@sphereon/ssi-sdk-ext.x509-utils": "^0.28.1-feature.esm.cjs.11+5582cc4",
|
|
16
28
|
"@trust/keyto": "2.0.0-alpha1",
|
|
17
29
|
"@veramo/core": "4.2.0",
|
|
18
30
|
"@veramo/key-manager": "4.2.0",
|
|
19
31
|
"@veramo/kms-local": "4.2.0",
|
|
32
|
+
"debug": "^4.4.0",
|
|
20
33
|
"elliptic": "^6.5.4",
|
|
21
|
-
"uint8arrays": "
|
|
34
|
+
"uint8arrays": "5.1.0"
|
|
22
35
|
},
|
|
23
36
|
"devDependencies": {
|
|
24
37
|
"@sphereon/jsencrypt": "3.3.2-unstable.0",
|
|
25
|
-
"@sphereon/ssi-sdk.dev": "0.
|
|
38
|
+
"@sphereon/ssi-sdk.dev": " ^0.33",
|
|
26
39
|
"@types/elliptic": "6.4.14",
|
|
27
40
|
"@veramo/cli": "4.2.0"
|
|
28
41
|
},
|
|
29
42
|
"files": [
|
|
30
|
-
"dist
|
|
31
|
-
"src
|
|
43
|
+
"dist",
|
|
44
|
+
"src",
|
|
32
45
|
"plugin.schema.json",
|
|
33
46
|
"README.md",
|
|
34
47
|
"LICENSE"
|
|
@@ -44,5 +57,5 @@
|
|
|
44
57
|
"kms",
|
|
45
58
|
"Veramo"
|
|
46
59
|
],
|
|
47
|
-
"gitHead": "
|
|
60
|
+
"gitHead": "5582cc49ffc25ef9cef9d3b42ff7aad59ca3a480"
|
|
48
61
|
}
|
|
@@ -5,7 +5,9 @@ import { AbstractPrivateKeyStore, ManagedPrivateKey } from '@veramo/key-manager'
|
|
|
5
5
|
import { KeyManagementSystem } from '@veramo/kms-local'
|
|
6
6
|
import Debug from 'debug'
|
|
7
7
|
import elliptic from 'elliptic'
|
|
8
|
+
// @ts-ignore
|
|
8
9
|
import * as u8a from 'uint8arrays'
|
|
10
|
+
const { fromString } = u8a
|
|
9
11
|
import { KeyType, ManagedKeyInfoArgs } from './index'
|
|
10
12
|
import {
|
|
11
13
|
hexToPEM,
|
|
@@ -171,7 +173,7 @@ export class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
|
171
173
|
}
|
|
172
174
|
break
|
|
173
175
|
case 'Secp256k1': {
|
|
174
|
-
const privateBytes =
|
|
176
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), 'base16')
|
|
175
177
|
const secp256k1 = new elliptic.ec('secp256k1')
|
|
176
178
|
const keyPair = secp256k1.keyFromPrivate(privateBytes, 'hex')
|
|
177
179
|
const publicKeyHex = keyPair.getPublic(true, 'hex')
|
|
@@ -187,7 +189,7 @@ export class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
|
187
189
|
break
|
|
188
190
|
}
|
|
189
191
|
case 'Secp256r1': {
|
|
190
|
-
const privateBytes =
|
|
192
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), 'base16')
|
|
191
193
|
const secp256r1 = new elliptic.ec('p256')
|
|
192
194
|
const keyPair = secp256r1.keyFromPrivate(privateBytes, 'hex')
|
|
193
195
|
const publicKeyHex = keyPair.getPublic(true, 'hex')
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import { SphereonKeyManagementSystem } from '../SphereonKeyManagementSystem'
|
|
2
|
-
import { MemoryPrivateKeyStore } from '@veramo/key-manager'
|
|
3
1
|
import { ManagedKeyInfo } from '@veramo/core'
|
|
2
|
+
import { MemoryPrivateKeyStore } from '@veramo/key-manager'
|
|
3
|
+
import { describe, expect, it } from 'vitest'
|
|
4
|
+
import { SphereonKeyManagementSystem } from '../SphereonKeyManagementSystem'
|
|
4
5
|
|
|
5
6
|
describe('Key creation', () => {
|
|
6
7
|
it('should create a RSA key', async () => {
|
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import JSEncrypt from '@sphereon/jsencrypt'
|
|
2
|
-
import { PEM_CERT, PEM_CHAIN, PEM_FULL_CHAIN, PEM_PRIV_KEY } from './certs'
|
|
3
|
-
import { SphereonKeyManagementSystem } from '../SphereonKeyManagementSystem'
|
|
4
|
-
import { MemoryPrivateKeyStore } from '@veramo/key-manager'
|
|
5
|
-
import * as u8a from 'uint8arrays'
|
|
6
2
|
import { digestMethodParams, X509Opts } from '@sphereon/ssi-sdk-ext.key-utils'
|
|
7
3
|
import {
|
|
8
4
|
pemCertChainTox5c,
|
|
@@ -13,6 +9,11 @@ import {
|
|
|
13
9
|
toKeyObject,
|
|
14
10
|
x5cToPemCertChain,
|
|
15
11
|
} from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
12
|
+
import { MemoryPrivateKeyStore } from '@veramo/key-manager'
|
|
13
|
+
import * as u8a from 'uint8arrays'
|
|
14
|
+
import { describe, expect, it } from 'vitest'
|
|
15
|
+
import { SphereonKeyManagementSystem } from '../SphereonKeyManagementSystem'
|
|
16
|
+
import { PEM_CERT, PEM_CHAIN, PEM_FULL_CHAIN, PEM_PRIV_KEY } from './certs'
|
|
16
17
|
|
|
17
18
|
describe('X509 PEMs', () => {
|
|
18
19
|
it('should get public key from private key', () => {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SphereonKeyManagementSystem.d.ts","sourceRoot":"","sources":["../src/SphereonKeyManagementSystem.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACnF,OAAO,EAAE,uBAAuB,EAAqB,MAAM,qBAAqB,CAAA;AAChF,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AAiBvD,qBAAa,2BAA4B,SAAQ,mBAAmB;IAClE,OAAO,CAAC,QAAQ,CAAC,eAAe,CAAyB;gBAE7C,QAAQ,EAAE,uBAAuB;IAKvC,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC,GAAG;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAkCxG,SAAS,CAAC,EAAE,IAAI,EAAE,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAuChE,IAAI,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,EAAE;QAAE,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAAC,SAAS,CAAC,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,UAAU,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAsCvH,MAAM,CAAC,EACX,YAAY,EACZ,IAAI,EACJ,SAAS,EACT,IAAI,EACJ,SAAS,GACV,EAAE;QACD,YAAY,EAAE,MAAM,CAAA;QACpB,IAAI,EAAE,QAAQ,CAAA;QACd,SAAS,CAAC,EAAE,MAAM,CAAA;QAClB,IAAI,EAAE,UAAU,CAAA;QAChB,SAAS,EAAE,MAAM,CAAA;KAClB,GAAG,OAAO,CAAC,OAAO,CAAC;IAOpB,OAAO,CAAC,wBAAwB;IAuGhC;;OAEG;YACW,OAAO;YAOP,SAAS;IAMV,QAAQ,IAAI,OAAO,CAAC,KAAK,CAAC,cAAc,CAAC,CAAC;CAGxD"}
|
|
@@ -1,290 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.SphereonKeyManagementSystem = void 0;
|
|
39
|
-
const ssi_sdk_ext_key_utils_1 = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
40
|
-
const kms_local_1 = require("@veramo/kms-local");
|
|
41
|
-
const debug_1 = __importDefault(require("debug"));
|
|
42
|
-
const elliptic_1 = __importDefault(require("elliptic"));
|
|
43
|
-
const u8a = __importStar(require("uint8arrays"));
|
|
44
|
-
const index_1 = require("./index");
|
|
45
|
-
const ssi_sdk_ext_x509_utils_1 = require("@sphereon/ssi-sdk-ext.x509-utils");
|
|
46
|
-
const debug = (0, debug_1.default)('sphereon:kms:local');
|
|
47
|
-
class SphereonKeyManagementSystem extends kms_local_1.KeyManagementSystem {
|
|
48
|
-
constructor(keyStore) {
|
|
49
|
-
super(keyStore);
|
|
50
|
-
this.privateKeyStore = keyStore;
|
|
51
|
-
}
|
|
52
|
-
importKey(args) {
|
|
53
|
-
const _super = Object.create(null, {
|
|
54
|
-
importKey: { get: () => super.importKey }
|
|
55
|
-
});
|
|
56
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
57
|
-
switch (args.type) {
|
|
58
|
-
case index_1.KeyType.Bls12381G2.toString():
|
|
59
|
-
if (!args.privateKeyHex || !args.publicKeyHex) {
|
|
60
|
-
throw new Error('invalid_argument: type, publicKeyHex and privateKeyHex are required to import a key');
|
|
61
|
-
}
|
|
62
|
-
const managedKey = this.asSphereonManagedKeyInfo(Object.assign(Object.assign({}, args), { alias: args.kid, privateKeyHex: args.privateKeyHex, publicKeyHex: args.publicKeyHex, type: args.type }));
|
|
63
|
-
yield this.privateKeyStore.import(Object.assign({ alias: managedKey.kid }, args));
|
|
64
|
-
debug('imported key', managedKey.type, managedKey.publicKeyHex);
|
|
65
|
-
return managedKey;
|
|
66
|
-
case 'Secp256k1':
|
|
67
|
-
case 'Secp256r1':
|
|
68
|
-
// @ts-ignore
|
|
69
|
-
case 'RSA': {
|
|
70
|
-
if (!args.privateKeyHex && !args.privateKeyPEM) {
|
|
71
|
-
throw new Error('invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key');
|
|
72
|
-
}
|
|
73
|
-
const managedKey = this.asSphereonManagedKeyInfo(Object.assign({ alias: args.kid }, args));
|
|
74
|
-
yield this.privateKeyStore.import(Object.assign({ alias: managedKey.kid }, args));
|
|
75
|
-
debug('imported key', managedKey.type, managedKey.publicKeyHex);
|
|
76
|
-
return managedKey;
|
|
77
|
-
}
|
|
78
|
-
default:
|
|
79
|
-
return yield _super.importKey.call(this, args);
|
|
80
|
-
}
|
|
81
|
-
});
|
|
82
|
-
}
|
|
83
|
-
createKey(_a) {
|
|
84
|
-
const _super = Object.create(null, {
|
|
85
|
-
createKey: { get: () => super.createKey }
|
|
86
|
-
});
|
|
87
|
-
return __awaiter(this, arguments, void 0, function* ({ type }) {
|
|
88
|
-
let key;
|
|
89
|
-
switch (type) {
|
|
90
|
-
case index_1.KeyType.Bls12381G2: {
|
|
91
|
-
throw Error('BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures');
|
|
92
|
-
/*// @ts-ignore
|
|
93
|
-
const bbs = await import('@digitalbazaar/bbs-signatures')
|
|
94
|
-
const keyPairBls12381G2 = await bbs.generateKeyPair({
|
|
95
|
-
ciphersuite: 'BLS12-381-SHA-256'
|
|
96
|
-
})
|
|
97
|
-
key = await this.importKey({
|
|
98
|
-
type,
|
|
99
|
-
privateKeyHex: Buffer.from(keyPairBls12381G2.secretKey).toString('hex'),
|
|
100
|
-
publicKeyHex: Buffer.from(keyPairBls12381G2.publicKey).toString('hex'),
|
|
101
|
-
})
|
|
102
|
-
break*/
|
|
103
|
-
}
|
|
104
|
-
// @ts-ignore
|
|
105
|
-
case 'RSA': {
|
|
106
|
-
const privateKeyHex = yield (0, ssi_sdk_ext_key_utils_1.generatePrivateKeyHex)(type);
|
|
107
|
-
key = yield this.importKey({
|
|
108
|
-
type,
|
|
109
|
-
privateKeyHex,
|
|
110
|
-
});
|
|
111
|
-
break;
|
|
112
|
-
}
|
|
113
|
-
default:
|
|
114
|
-
key = yield _super.createKey.call(this, { type });
|
|
115
|
-
}
|
|
116
|
-
debug('Created key', type, key.publicKeyHex);
|
|
117
|
-
return key;
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
sign(_a) {
|
|
121
|
-
const _super = Object.create(null, {
|
|
122
|
-
sign: { get: () => super.sign }
|
|
123
|
-
});
|
|
124
|
-
return __awaiter(this, arguments, void 0, function* ({ keyRef, algorithm, data }) {
|
|
125
|
-
let privateKey;
|
|
126
|
-
try {
|
|
127
|
-
privateKey = yield this.privateKeyStore.get({ alias: keyRef.kid });
|
|
128
|
-
}
|
|
129
|
-
catch (e) {
|
|
130
|
-
throw new Error(`key_not_found: No key entry found for kid=${keyRef.kid}`);
|
|
131
|
-
}
|
|
132
|
-
if (privateKey.type === index_1.KeyType.Bls12381G2) {
|
|
133
|
-
throw Error('BLS support not available because upstream is not really providing Windows and React-Native support; giving too much headache. We soon will move to @digitalbazaar/bbs-signatures');
|
|
134
|
-
/*// @ts-ignore
|
|
135
|
-
const bbs = await import('@digitalbazaar/bbs-signatures')
|
|
136
|
-
if (!data || Array.isArray(data)) {
|
|
137
|
-
throw new Error('Data must be defined and cannot be an array')
|
|
138
|
-
}
|
|
139
|
-
const keyPair = {
|
|
140
|
-
keyPair: {
|
|
141
|
-
secretKey: Uint8Array.from(Buffer.from(privateKey.privateKeyHex, 'hex')),
|
|
142
|
-
publicKey: Uint8Array.from(Buffer.from(keyRef.kid, 'hex')),
|
|
143
|
-
},
|
|
144
|
-
messages: [data],
|
|
145
|
-
}
|
|
146
|
-
const signature = await bbs.sign({secretKey: privateKey, publicKey, header, messages});
|
|
147
|
-
return signature*/
|
|
148
|
-
}
|
|
149
|
-
else if (
|
|
150
|
-
// @ts-ignore
|
|
151
|
-
privateKey.type === 'RSA' &&
|
|
152
|
-
(typeof algorithm === 'undefined' || algorithm === 'RS256' || algorithm === 'RS512' || algorithm === 'PS256' || algorithm === 'PS512')) {
|
|
153
|
-
return yield this.signRSA(privateKey, data, algorithm !== null && algorithm !== void 0 ? algorithm : 'PS256');
|
|
154
|
-
}
|
|
155
|
-
else {
|
|
156
|
-
return yield _super.sign.call(this, { keyRef, algorithm, data });
|
|
157
|
-
}
|
|
158
|
-
throw Error(`not_supported: Cannot sign using key of type ${privateKey.type}`);
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
verify(_a) {
|
|
162
|
-
return __awaiter(this, arguments, void 0, function* ({ publicKeyHex, type, algorithm, data, signature, }) {
|
|
163
|
-
if (type === 'RSA') {
|
|
164
|
-
return yield this.verifyRSA(publicKeyHex, data, algorithm !== null && algorithm !== void 0 ? algorithm : 'PS256', signature);
|
|
165
|
-
}
|
|
166
|
-
throw Error(`KMS verify is not implemented yet for ${type}`);
|
|
167
|
-
});
|
|
168
|
-
}
|
|
169
|
-
asSphereonManagedKeyInfo(args) {
|
|
170
|
-
var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k, _l;
|
|
171
|
-
let key;
|
|
172
|
-
switch (args.type) {
|
|
173
|
-
case index_1.KeyType.Bls12381G2:
|
|
174
|
-
key = {
|
|
175
|
-
type: args.type,
|
|
176
|
-
kid: (_a = args.alias) !== null && _a !== void 0 ? _a : args.publicKeyHex,
|
|
177
|
-
publicKeyHex: args.publicKeyHex,
|
|
178
|
-
meta: {
|
|
179
|
-
algorithms: ['BLS'],
|
|
180
|
-
},
|
|
181
|
-
};
|
|
182
|
-
break;
|
|
183
|
-
case 'Secp256k1': {
|
|
184
|
-
const privateBytes = u8a.fromString(args.privateKeyHex.toLowerCase(), 'base16');
|
|
185
|
-
const secp256k1 = new elliptic_1.default.ec('secp256k1');
|
|
186
|
-
const keyPair = secp256k1.keyFromPrivate(privateBytes, 'hex');
|
|
187
|
-
const publicKeyHex = keyPair.getPublic(true, 'hex');
|
|
188
|
-
key = {
|
|
189
|
-
type: args.type,
|
|
190
|
-
kid: (_b = args.alias) !== null && _b !== void 0 ? _b : publicKeyHex,
|
|
191
|
-
publicKeyHex,
|
|
192
|
-
meta: {
|
|
193
|
-
jwkThumbprint: (0, ssi_sdk_ext_key_utils_1.calculateJwkThumbprint)({ jwk: (0, ssi_sdk_ext_key_utils_1.toJwk)(publicKeyHex, 'Secp256k1') }),
|
|
194
|
-
algorithms: ['ES256K', 'ES256K-R', 'eth_signTransaction', 'eth_signTypedData', 'eth_signMessage', 'eth_rawSign'],
|
|
195
|
-
},
|
|
196
|
-
};
|
|
197
|
-
break;
|
|
198
|
-
}
|
|
199
|
-
case 'Secp256r1': {
|
|
200
|
-
const privateBytes = u8a.fromString(args.privateKeyHex.toLowerCase(), 'base16');
|
|
201
|
-
const secp256r1 = new elliptic_1.default.ec('p256');
|
|
202
|
-
const keyPair = secp256r1.keyFromPrivate(privateBytes, 'hex');
|
|
203
|
-
const publicKeyHex = keyPair.getPublic(true, 'hex');
|
|
204
|
-
key = {
|
|
205
|
-
type: args.type,
|
|
206
|
-
kid: (_c = args.alias) !== null && _c !== void 0 ? _c : publicKeyHex,
|
|
207
|
-
publicKeyHex,
|
|
208
|
-
meta: {
|
|
209
|
-
jwkThumbprint: (0, ssi_sdk_ext_key_utils_1.calculateJwkThumbprint)({ jwk: (0, ssi_sdk_ext_key_utils_1.toJwk)(publicKeyHex, 'Secp256r1') }),
|
|
210
|
-
algorithms: ['ES256'],
|
|
211
|
-
},
|
|
212
|
-
};
|
|
213
|
-
break;
|
|
214
|
-
}
|
|
215
|
-
// @ts-ignore
|
|
216
|
-
case 'RSA': {
|
|
217
|
-
const x509 = (_d = args.meta) === null || _d === void 0 ? void 0 : _d.x509;
|
|
218
|
-
const privateKeyPEM = (_e = x509 === null || x509 === void 0 ? void 0 : x509.privateKeyPEM) !== null && _e !== void 0 ? _e : (args.privateKeyHex.includes('---') ? args.privateKeyHex : (0, ssi_sdk_ext_x509_utils_1.hexToPEM)(args.privateKeyHex, 'private')); // In case we have x509 opts, the private key hex really was a PEM already (yuck)
|
|
219
|
-
const publicKeyJwk = (0, ssi_sdk_ext_x509_utils_1.PEMToJwk)(privateKeyPEM, 'public');
|
|
220
|
-
const publicKeyPEM = (0, ssi_sdk_ext_x509_utils_1.jwkToPEM)(publicKeyJwk, 'public');
|
|
221
|
-
const publicKeyHex = (0, ssi_sdk_ext_x509_utils_1.PEMToHex)(publicKeyPEM);
|
|
222
|
-
const meta = {};
|
|
223
|
-
if (x509) {
|
|
224
|
-
meta.x509 = {
|
|
225
|
-
cn: (_g = (_f = x509.cn) !== null && _f !== void 0 ? _f : args.alias) !== null && _g !== void 0 ? _g : publicKeyHex,
|
|
226
|
-
};
|
|
227
|
-
let certChain = (_h = x509.certificateChainPEM) !== null && _h !== void 0 ? _h : '';
|
|
228
|
-
if (x509.certificatePEM) {
|
|
229
|
-
if (!certChain.includes(x509.certificatePEM)) {
|
|
230
|
-
certChain = `${x509.certificatePEM}\n${certChain}`;
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
if (certChain.length > 0) {
|
|
234
|
-
meta.x509.certificateChainPEM = certChain;
|
|
235
|
-
const x5c = (0, ssi_sdk_ext_x509_utils_1.pemCertChainTox5c)(certChain);
|
|
236
|
-
if (!x509.certificateChainURL) {
|
|
237
|
-
// Do not put the chain in the JWK when the chain is hosted. We do put it in the x509 metadata
|
|
238
|
-
// @ts-ignore
|
|
239
|
-
publicKeyJwk.x5c = x5c;
|
|
240
|
-
}
|
|
241
|
-
meta.x509.x5c = x5c;
|
|
242
|
-
}
|
|
243
|
-
if (x509.certificateChainURL) {
|
|
244
|
-
// @ts-ignore
|
|
245
|
-
publicKeyJwk.x5u = x509.certificateChainURL;
|
|
246
|
-
meta.x509.x5u = x509.certificateChainURL;
|
|
247
|
-
}
|
|
248
|
-
}
|
|
249
|
-
key = {
|
|
250
|
-
type: args.type,
|
|
251
|
-
kid: (_l = (_j = args.alias) !== null && _j !== void 0 ? _j : (_k = meta === null || meta === void 0 ? void 0 : meta.x509) === null || _k === void 0 ? void 0 : _k.cn) !== null && _l !== void 0 ? _l : publicKeyHex,
|
|
252
|
-
publicKeyHex,
|
|
253
|
-
meta: Object.assign(Object.assign({}, meta), {
|
|
254
|
-
// todo: could als be DSA etc
|
|
255
|
-
algorithms: ['RS256', 'RS512', 'PS256', 'PS512'], publicKeyJwk,
|
|
256
|
-
publicKeyPEM }),
|
|
257
|
-
};
|
|
258
|
-
break;
|
|
259
|
-
}
|
|
260
|
-
default:
|
|
261
|
-
throw Error('not_supported: Key type not supported: ' + args.type);
|
|
262
|
-
}
|
|
263
|
-
return key;
|
|
264
|
-
}
|
|
265
|
-
/**
|
|
266
|
-
* @returns a base64url encoded signature for the `RS256` alg
|
|
267
|
-
*/
|
|
268
|
-
signRSA(privateKey, data, signingAlgorithm) {
|
|
269
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
270
|
-
const { hashAlgorithm, scheme } = (0, ssi_sdk_ext_x509_utils_1.signAlgorithmToSchemeAndHashAlg)(signingAlgorithm);
|
|
271
|
-
const signer = new ssi_sdk_ext_x509_utils_1.RSASigner((0, ssi_sdk_ext_x509_utils_1.PEMToJwk)((0, ssi_sdk_ext_x509_utils_1.hexToPEM)(privateKey.privateKeyHex, 'private'), 'private'), { hashAlgorithm, scheme });
|
|
272
|
-
const signature = yield signer.sign(data);
|
|
273
|
-
return signature;
|
|
274
|
-
});
|
|
275
|
-
}
|
|
276
|
-
verifyRSA(publicKeyHex, data, signingAlgorithm, signature) {
|
|
277
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
278
|
-
const { hashAlgorithm, scheme } = (0, ssi_sdk_ext_x509_utils_1.signAlgorithmToSchemeAndHashAlg)(signingAlgorithm);
|
|
279
|
-
const signer = new ssi_sdk_ext_x509_utils_1.RSASigner((0, ssi_sdk_ext_x509_utils_1.PEMToJwk)((0, ssi_sdk_ext_x509_utils_1.hexToPEM)(publicKeyHex, 'public'), 'public'), { hashAlgorithm, scheme });
|
|
280
|
-
return yield signer.verify(data, signature);
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
listKeys() {
|
|
284
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
285
|
-
return (yield this.privateKeyStore.list({})).map((privateKey) => this.asSphereonManagedKeyInfo(privateKey));
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
exports.SphereonKeyManagementSystem = SphereonKeyManagementSystem;
|
|
290
|
-
//# sourceMappingURL=SphereonKeyManagementSystem.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"SphereonKeyManagementSystem.js","sourceRoot":"","sources":["../src/SphereonKeyManagementSystem.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,2EAAgH;AAIhH,iDAAuD;AACvD,kDAAyB;AACzB,wDAA+B;AAC/B,iDAAkC;AAClC,mCAAqD;AACrD,6EAQyC;AAEzC,MAAM,KAAK,GAAG,IAAA,eAAK,EAAC,oBAAoB,CAAC,CAAA;AAEzC,MAAa,2BAA4B,SAAQ,+BAAmB;IAGlE,YAAY,QAAiC;QAC3C,KAAK,CAAC,QAAQ,CAAC,CAAA;QACf,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAA;IACjC,CAAC;IAEK,SAAS,CAAC,IAAoE;;;;;YAClF,QAAQ,IAAI,CAAC,IAAI,EAAE,CA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