@sphereon/ssi-sdk-ext.kms-local 0.28.0 → 0.28.1-feature.esm.cjs.8
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 +299 -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 +264 -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 -3
- 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,299 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
3
|
+
var __defProp = Object.defineProperty;
|
|
4
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
5
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
7
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
8
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
9
|
+
var __export = (target, all) => {
|
|
10
|
+
for (var name in all)
|
|
11
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
12
|
+
};
|
|
13
|
+
var __copyProps = (to, from, except, desc) => {
|
|
14
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
15
|
+
for (let key of __getOwnPropNames(from))
|
|
16
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
17
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
18
|
+
}
|
|
19
|
+
return to;
|
|
20
|
+
};
|
|
21
|
+
var __reExport = (target, mod, secondTarget) => (__copyProps(target, mod, "default"), secondTarget && __copyProps(secondTarget, mod, "default"));
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
23
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
24
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
25
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
26
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
27
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
28
|
+
mod
|
|
29
|
+
));
|
|
30
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
31
|
+
|
|
32
|
+
// src/index.ts
|
|
33
|
+
var index_exports = {};
|
|
34
|
+
__export(index_exports, {
|
|
35
|
+
KeyType: () => KeyType,
|
|
36
|
+
SphereonKeyManagementSystem: () => SphereonKeyManagementSystem
|
|
37
|
+
});
|
|
38
|
+
module.exports = __toCommonJS(index_exports);
|
|
39
|
+
|
|
40
|
+
// src/SphereonKeyManagementSystem.ts
|
|
41
|
+
var import_ssi_sdk_ext = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
42
|
+
var import_kms_local = require("@veramo/kms-local");
|
|
43
|
+
var import_debug = __toESM(require("debug"), 1);
|
|
44
|
+
var import_elliptic = __toESM(require("elliptic"), 1);
|
|
45
|
+
var import_from_string = require("uint8arrays/from-string");
|
|
46
|
+
var import_ssi_sdk_ext2 = require("@sphereon/ssi-sdk-ext.x509-utils");
|
|
47
|
+
var debug = (0, import_debug.default)("sphereon:kms:local");
|
|
48
|
+
var SphereonKeyManagementSystem = class extends import_kms_local.KeyManagementSystem {
|
|
49
|
+
static {
|
|
50
|
+
__name(this, "SphereonKeyManagementSystem");
|
|
51
|
+
}
|
|
52
|
+
privateKeyStore;
|
|
53
|
+
constructor(keyStore) {
|
|
54
|
+
super(keyStore);
|
|
55
|
+
this.privateKeyStore = keyStore;
|
|
56
|
+
}
|
|
57
|
+
async importKey(args) {
|
|
58
|
+
switch (args.type) {
|
|
59
|
+
case KeyType.Bls12381G2.toString():
|
|
60
|
+
if (!args.privateKeyHex || !args.publicKeyHex) {
|
|
61
|
+
throw new Error("invalid_argument: type, publicKeyHex and privateKeyHex are required to import a key");
|
|
62
|
+
}
|
|
63
|
+
const managedKey = this.asSphereonManagedKeyInfo({
|
|
64
|
+
...args,
|
|
65
|
+
alias: args.kid,
|
|
66
|
+
privateKeyHex: args.privateKeyHex,
|
|
67
|
+
publicKeyHex: args.publicKeyHex,
|
|
68
|
+
type: args.type
|
|
69
|
+
});
|
|
70
|
+
await this.privateKeyStore.import({
|
|
71
|
+
alias: managedKey.kid,
|
|
72
|
+
...args
|
|
73
|
+
});
|
|
74
|
+
debug("imported key", managedKey.type, managedKey.publicKeyHex);
|
|
75
|
+
return managedKey;
|
|
76
|
+
case "Secp256k1":
|
|
77
|
+
case "Secp256r1":
|
|
78
|
+
// @ts-ignore
|
|
79
|
+
case "RSA": {
|
|
80
|
+
if (!args.privateKeyHex && !args.privateKeyPEM) {
|
|
81
|
+
throw new Error("invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key");
|
|
82
|
+
}
|
|
83
|
+
const managedKey2 = this.asSphereonManagedKeyInfo({
|
|
84
|
+
alias: args.kid,
|
|
85
|
+
...args
|
|
86
|
+
});
|
|
87
|
+
await this.privateKeyStore.import({
|
|
88
|
+
alias: managedKey2.kid,
|
|
89
|
+
...args
|
|
90
|
+
});
|
|
91
|
+
debug("imported key", managedKey2.type, managedKey2.publicKeyHex);
|
|
92
|
+
return managedKey2;
|
|
93
|
+
}
|
|
94
|
+
default:
|
|
95
|
+
return await super.importKey(args);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
async createKey({ type }) {
|
|
99
|
+
let key;
|
|
100
|
+
switch (type) {
|
|
101
|
+
case KeyType.Bls12381G2: {
|
|
102
|
+
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");
|
|
103
|
+
}
|
|
104
|
+
// @ts-ignore
|
|
105
|
+
case "RSA": {
|
|
106
|
+
const privateKeyHex = await (0, import_ssi_sdk_ext.generatePrivateKeyHex)(type);
|
|
107
|
+
key = await this.importKey({
|
|
108
|
+
type,
|
|
109
|
+
privateKeyHex
|
|
110
|
+
});
|
|
111
|
+
break;
|
|
112
|
+
}
|
|
113
|
+
default:
|
|
114
|
+
key = await super.createKey({
|
|
115
|
+
type
|
|
116
|
+
});
|
|
117
|
+
}
|
|
118
|
+
debug("Created key", type, key.publicKeyHex);
|
|
119
|
+
return key;
|
|
120
|
+
}
|
|
121
|
+
async sign({ keyRef, algorithm, data }) {
|
|
122
|
+
let privateKey;
|
|
123
|
+
try {
|
|
124
|
+
privateKey = await this.privateKeyStore.get({
|
|
125
|
+
alias: keyRef.kid
|
|
126
|
+
});
|
|
127
|
+
} catch (e) {
|
|
128
|
+
throw new Error(`key_not_found: No key entry found for kid=${keyRef.kid}`);
|
|
129
|
+
}
|
|
130
|
+
if (privateKey.type === KeyType.Bls12381G2) {
|
|
131
|
+
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");
|
|
132
|
+
} else if (
|
|
133
|
+
// @ts-ignore
|
|
134
|
+
privateKey.type === "RSA" && (typeof algorithm === "undefined" || algorithm === "RS256" || algorithm === "RS512" || algorithm === "PS256" || algorithm === "PS512")
|
|
135
|
+
) {
|
|
136
|
+
return await this.signRSA(privateKey, data, algorithm ?? "PS256");
|
|
137
|
+
} else {
|
|
138
|
+
return await super.sign({
|
|
139
|
+
keyRef,
|
|
140
|
+
algorithm,
|
|
141
|
+
data
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
throw Error(`not_supported: Cannot sign using key of type ${privateKey.type}`);
|
|
145
|
+
}
|
|
146
|
+
async verify({ publicKeyHex, type, algorithm, data, signature }) {
|
|
147
|
+
if (type === "RSA") {
|
|
148
|
+
return await this.verifyRSA(publicKeyHex, data, algorithm ?? "PS256", signature);
|
|
149
|
+
}
|
|
150
|
+
throw Error(`KMS verify is not implemented yet for ${type}`);
|
|
151
|
+
}
|
|
152
|
+
asSphereonManagedKeyInfo(args) {
|
|
153
|
+
let key;
|
|
154
|
+
switch (args.type) {
|
|
155
|
+
case KeyType.Bls12381G2:
|
|
156
|
+
key = {
|
|
157
|
+
type: args.type,
|
|
158
|
+
kid: args.alias ?? args.publicKeyHex,
|
|
159
|
+
publicKeyHex: args.publicKeyHex,
|
|
160
|
+
meta: {
|
|
161
|
+
algorithms: [
|
|
162
|
+
"BLS"
|
|
163
|
+
]
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
break;
|
|
167
|
+
case "Secp256k1": {
|
|
168
|
+
const privateBytes = (0, import_from_string.fromString)(args.privateKeyHex.toLowerCase(), "base16");
|
|
169
|
+
const secp256k1 = new import_elliptic.default.ec("secp256k1");
|
|
170
|
+
const keyPair = secp256k1.keyFromPrivate(privateBytes, "hex");
|
|
171
|
+
const publicKeyHex = keyPair.getPublic(true, "hex");
|
|
172
|
+
key = {
|
|
173
|
+
type: args.type,
|
|
174
|
+
kid: args.alias ?? publicKeyHex,
|
|
175
|
+
publicKeyHex,
|
|
176
|
+
meta: {
|
|
177
|
+
jwkThumbprint: (0, import_ssi_sdk_ext.calculateJwkThumbprint)({
|
|
178
|
+
jwk: (0, import_ssi_sdk_ext.toJwk)(publicKeyHex, "Secp256k1")
|
|
179
|
+
}),
|
|
180
|
+
algorithms: [
|
|
181
|
+
"ES256K",
|
|
182
|
+
"ES256K-R",
|
|
183
|
+
"eth_signTransaction",
|
|
184
|
+
"eth_signTypedData",
|
|
185
|
+
"eth_signMessage",
|
|
186
|
+
"eth_rawSign"
|
|
187
|
+
]
|
|
188
|
+
}
|
|
189
|
+
};
|
|
190
|
+
break;
|
|
191
|
+
}
|
|
192
|
+
case "Secp256r1": {
|
|
193
|
+
const privateBytes = (0, import_from_string.fromString)(args.privateKeyHex.toLowerCase(), "base16");
|
|
194
|
+
const secp256r1 = new import_elliptic.default.ec("p256");
|
|
195
|
+
const keyPair = secp256r1.keyFromPrivate(privateBytes, "hex");
|
|
196
|
+
const publicKeyHex = keyPair.getPublic(true, "hex");
|
|
197
|
+
key = {
|
|
198
|
+
type: args.type,
|
|
199
|
+
kid: args.alias ?? publicKeyHex,
|
|
200
|
+
publicKeyHex,
|
|
201
|
+
meta: {
|
|
202
|
+
jwkThumbprint: (0, import_ssi_sdk_ext.calculateJwkThumbprint)({
|
|
203
|
+
jwk: (0, import_ssi_sdk_ext.toJwk)(publicKeyHex, "Secp256r1")
|
|
204
|
+
}),
|
|
205
|
+
algorithms: [
|
|
206
|
+
"ES256"
|
|
207
|
+
]
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
break;
|
|
211
|
+
}
|
|
212
|
+
// @ts-ignore
|
|
213
|
+
case "RSA": {
|
|
214
|
+
const x509 = args.meta?.x509;
|
|
215
|
+
const privateKeyPEM = x509?.privateKeyPEM ?? (args.privateKeyHex.includes("---") ? args.privateKeyHex : (0, import_ssi_sdk_ext2.hexToPEM)(args.privateKeyHex, "private"));
|
|
216
|
+
const publicKeyJwk = (0, import_ssi_sdk_ext2.PEMToJwk)(privateKeyPEM, "public");
|
|
217
|
+
const publicKeyPEM = (0, import_ssi_sdk_ext2.jwkToPEM)(publicKeyJwk, "public");
|
|
218
|
+
const publicKeyHex = (0, import_ssi_sdk_ext2.PEMToHex)(publicKeyPEM);
|
|
219
|
+
const meta = {};
|
|
220
|
+
if (x509) {
|
|
221
|
+
meta.x509 = {
|
|
222
|
+
cn: x509.cn ?? args.alias ?? publicKeyHex
|
|
223
|
+
};
|
|
224
|
+
let certChain = x509.certificateChainPEM ?? "";
|
|
225
|
+
if (x509.certificatePEM) {
|
|
226
|
+
if (!certChain.includes(x509.certificatePEM)) {
|
|
227
|
+
certChain = `${x509.certificatePEM}
|
|
228
|
+
${certChain}`;
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
if (certChain.length > 0) {
|
|
232
|
+
meta.x509.certificateChainPEM = certChain;
|
|
233
|
+
const x5c = (0, import_ssi_sdk_ext2.pemCertChainTox5c)(certChain);
|
|
234
|
+
if (!x509.certificateChainURL) {
|
|
235
|
+
publicKeyJwk.x5c = x5c;
|
|
236
|
+
}
|
|
237
|
+
meta.x509.x5c = x5c;
|
|
238
|
+
}
|
|
239
|
+
if (x509.certificateChainURL) {
|
|
240
|
+
publicKeyJwk.x5u = x509.certificateChainURL;
|
|
241
|
+
meta.x509.x5u = x509.certificateChainURL;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
key = {
|
|
245
|
+
type: args.type,
|
|
246
|
+
kid: args.alias ?? meta?.x509?.cn ?? publicKeyHex,
|
|
247
|
+
publicKeyHex,
|
|
248
|
+
meta: {
|
|
249
|
+
...meta,
|
|
250
|
+
// todo: could als be DSA etc
|
|
251
|
+
algorithms: [
|
|
252
|
+
"RS256",
|
|
253
|
+
"RS512",
|
|
254
|
+
"PS256",
|
|
255
|
+
"PS512"
|
|
256
|
+
],
|
|
257
|
+
publicKeyJwk,
|
|
258
|
+
publicKeyPEM
|
|
259
|
+
}
|
|
260
|
+
};
|
|
261
|
+
break;
|
|
262
|
+
}
|
|
263
|
+
default:
|
|
264
|
+
throw Error("not_supported: Key type not supported: " + args.type);
|
|
265
|
+
}
|
|
266
|
+
return key;
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* @returns a base64url encoded signature for the `RS256` alg
|
|
270
|
+
*/
|
|
271
|
+
async signRSA(privateKey, data, signingAlgorithm) {
|
|
272
|
+
const { hashAlgorithm, scheme } = (0, import_ssi_sdk_ext2.signAlgorithmToSchemeAndHashAlg)(signingAlgorithm);
|
|
273
|
+
const signer = new import_ssi_sdk_ext2.RSASigner((0, import_ssi_sdk_ext2.PEMToJwk)((0, import_ssi_sdk_ext2.hexToPEM)(privateKey.privateKeyHex, "private"), "private"), {
|
|
274
|
+
hashAlgorithm,
|
|
275
|
+
scheme
|
|
276
|
+
});
|
|
277
|
+
const signature = await signer.sign(data);
|
|
278
|
+
return signature;
|
|
279
|
+
}
|
|
280
|
+
async verifyRSA(publicKeyHex, data, signingAlgorithm, signature) {
|
|
281
|
+
const { hashAlgorithm, scheme } = (0, import_ssi_sdk_ext2.signAlgorithmToSchemeAndHashAlg)(signingAlgorithm);
|
|
282
|
+
const signer = new import_ssi_sdk_ext2.RSASigner((0, import_ssi_sdk_ext2.PEMToJwk)((0, import_ssi_sdk_ext2.hexToPEM)(publicKeyHex, "public"), "public"), {
|
|
283
|
+
hashAlgorithm,
|
|
284
|
+
scheme
|
|
285
|
+
});
|
|
286
|
+
return await signer.verify(data, signature);
|
|
287
|
+
}
|
|
288
|
+
async listKeys() {
|
|
289
|
+
return (await this.privateKeyStore.list({})).map((privateKey) => this.asSphereonManagedKeyInfo(privateKey));
|
|
290
|
+
}
|
|
291
|
+
};
|
|
292
|
+
|
|
293
|
+
// src/index.ts
|
|
294
|
+
__reExport(index_exports, require("@veramo/kms-local"), module.exports);
|
|
295
|
+
var KeyType = /* @__PURE__ */ function(KeyType2) {
|
|
296
|
+
KeyType2["Bls12381G2"] = "Bls12381G2";
|
|
297
|
+
return KeyType2;
|
|
298
|
+
}({});
|
|
299
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/index.ts","../src/SphereonKeyManagementSystem.ts"],"sourcesContent":["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","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 { fromString } from 'uint8arrays/from-string'\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"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAGA;;;;;;;;ACHA,yBAA+E;AAI/E,uBAAoC;AACpC,mBAAkB;AAClB,sBAAqB;AAErB,yBAA2B;AAE3B,IAAAA,sBAQO;AAEP,IAAMC,YAAQC,aAAAA,SAAM,oBAAA;AAEb,IAAMC,8BAAN,cAA0CC,qCAAAA;EAtBjD,OAsBiDA;;;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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AAA,GAAIC,IAAI,CAAChD,eAAkC,KAAKZ,yBAAyBY,UAAAA,CAAAA;EACpH;AACF;;;ADrRA,0BAAc,8BAFd;AAgBO,IAAKiD,UAAAA,yBAAAA,UAAAA;;SAAAA;;","names":["import_ssi_sdk_ext","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","fromString","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"]}
|
|
@@ -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,267 @@
|
|
|
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 { fromString } from "uint8arrays/from-string";
|
|
10
|
+
import { hexToPEM, jwkToPEM, pemCertChainTox5c, PEMToHex, PEMToJwk, RSASigner, signAlgorithmToSchemeAndHashAlg } from "@sphereon/ssi-sdk-ext.x509-utils";
|
|
11
|
+
var debug = Debug("sphereon:kms:local");
|
|
12
|
+
var SphereonKeyManagementSystem = class extends KeyManagementSystem {
|
|
13
|
+
static {
|
|
14
|
+
__name(this, "SphereonKeyManagementSystem");
|
|
15
|
+
}
|
|
16
|
+
privateKeyStore;
|
|
17
|
+
constructor(keyStore) {
|
|
18
|
+
super(keyStore);
|
|
19
|
+
this.privateKeyStore = keyStore;
|
|
20
|
+
}
|
|
21
|
+
async importKey(args) {
|
|
22
|
+
switch (args.type) {
|
|
23
|
+
case KeyType.Bls12381G2.toString():
|
|
24
|
+
if (!args.privateKeyHex || !args.publicKeyHex) {
|
|
25
|
+
throw new Error("invalid_argument: type, publicKeyHex and privateKeyHex are required to import a key");
|
|
26
|
+
}
|
|
27
|
+
const managedKey = this.asSphereonManagedKeyInfo({
|
|
28
|
+
...args,
|
|
29
|
+
alias: args.kid,
|
|
30
|
+
privateKeyHex: args.privateKeyHex,
|
|
31
|
+
publicKeyHex: args.publicKeyHex,
|
|
32
|
+
type: args.type
|
|
33
|
+
});
|
|
34
|
+
await this.privateKeyStore.import({
|
|
35
|
+
alias: managedKey.kid,
|
|
36
|
+
...args
|
|
37
|
+
});
|
|
38
|
+
debug("imported key", managedKey.type, managedKey.publicKeyHex);
|
|
39
|
+
return managedKey;
|
|
40
|
+
case "Secp256k1":
|
|
41
|
+
case "Secp256r1":
|
|
42
|
+
// @ts-ignore
|
|
43
|
+
case "RSA": {
|
|
44
|
+
if (!args.privateKeyHex && !args.privateKeyPEM) {
|
|
45
|
+
throw new Error("invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key");
|
|
46
|
+
}
|
|
47
|
+
const managedKey2 = this.asSphereonManagedKeyInfo({
|
|
48
|
+
alias: args.kid,
|
|
49
|
+
...args
|
|
50
|
+
});
|
|
51
|
+
await this.privateKeyStore.import({
|
|
52
|
+
alias: managedKey2.kid,
|
|
53
|
+
...args
|
|
54
|
+
});
|
|
55
|
+
debug("imported key", managedKey2.type, managedKey2.publicKeyHex);
|
|
56
|
+
return managedKey2;
|
|
57
|
+
}
|
|
58
|
+
default:
|
|
59
|
+
return await super.importKey(args);
|
|
7
60
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
61
|
+
}
|
|
62
|
+
async createKey({ type }) {
|
|
63
|
+
let key;
|
|
64
|
+
switch (type) {
|
|
65
|
+
case KeyType.Bls12381G2: {
|
|
66
|
+
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");
|
|
67
|
+
}
|
|
68
|
+
// @ts-ignore
|
|
69
|
+
case "RSA": {
|
|
70
|
+
const privateKeyHex = await generatePrivateKeyHex(type);
|
|
71
|
+
key = await this.importKey({
|
|
72
|
+
type,
|
|
73
|
+
privateKeyHex
|
|
74
|
+
});
|
|
75
|
+
break;
|
|
76
|
+
}
|
|
77
|
+
default:
|
|
78
|
+
key = await super.createKey({
|
|
79
|
+
type
|
|
80
|
+
});
|
|
81
|
+
}
|
|
82
|
+
debug("Created key", type, key.publicKeyHex);
|
|
83
|
+
return key;
|
|
84
|
+
}
|
|
85
|
+
async sign({ keyRef, algorithm, data }) {
|
|
86
|
+
let privateKey;
|
|
87
|
+
try {
|
|
88
|
+
privateKey = await this.privateKeyStore.get({
|
|
89
|
+
alias: keyRef.kid
|
|
90
|
+
});
|
|
91
|
+
} catch (e) {
|
|
92
|
+
throw new Error(`key_not_found: No key entry found for kid=${keyRef.kid}`);
|
|
93
|
+
}
|
|
94
|
+
if (privateKey.type === KeyType.Bls12381G2) {
|
|
95
|
+
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");
|
|
96
|
+
} else if (
|
|
97
|
+
// @ts-ignore
|
|
98
|
+
privateKey.type === "RSA" && (typeof algorithm === "undefined" || algorithm === "RS256" || algorithm === "RS512" || algorithm === "PS256" || algorithm === "PS512")
|
|
99
|
+
) {
|
|
100
|
+
return await this.signRSA(privateKey, data, algorithm ?? "PS256");
|
|
101
|
+
} else {
|
|
102
|
+
return await super.sign({
|
|
103
|
+
keyRef,
|
|
104
|
+
algorithm,
|
|
105
|
+
data
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
throw Error(`not_supported: Cannot sign using key of type ${privateKey.type}`);
|
|
109
|
+
}
|
|
110
|
+
async verify({ publicKeyHex, type, algorithm, data, signature }) {
|
|
111
|
+
if (type === "RSA") {
|
|
112
|
+
return await this.verifyRSA(publicKeyHex, data, algorithm ?? "PS256", signature);
|
|
113
|
+
}
|
|
114
|
+
throw Error(`KMS verify is not implemented yet for ${type}`);
|
|
115
|
+
}
|
|
116
|
+
asSphereonManagedKeyInfo(args) {
|
|
117
|
+
let key;
|
|
118
|
+
switch (args.type) {
|
|
119
|
+
case KeyType.Bls12381G2:
|
|
120
|
+
key = {
|
|
121
|
+
type: args.type,
|
|
122
|
+
kid: args.alias ?? args.publicKeyHex,
|
|
123
|
+
publicKeyHex: args.publicKeyHex,
|
|
124
|
+
meta: {
|
|
125
|
+
algorithms: [
|
|
126
|
+
"BLS"
|
|
127
|
+
]
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
break;
|
|
131
|
+
case "Secp256k1": {
|
|
132
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), "base16");
|
|
133
|
+
const secp256k1 = new elliptic.ec("secp256k1");
|
|
134
|
+
const keyPair = secp256k1.keyFromPrivate(privateBytes, "hex");
|
|
135
|
+
const publicKeyHex = keyPair.getPublic(true, "hex");
|
|
136
|
+
key = {
|
|
137
|
+
type: args.type,
|
|
138
|
+
kid: args.alias ?? publicKeyHex,
|
|
139
|
+
publicKeyHex,
|
|
140
|
+
meta: {
|
|
141
|
+
jwkThumbprint: calculateJwkThumbprint({
|
|
142
|
+
jwk: toJwk(publicKeyHex, "Secp256k1")
|
|
143
|
+
}),
|
|
144
|
+
algorithms: [
|
|
145
|
+
"ES256K",
|
|
146
|
+
"ES256K-R",
|
|
147
|
+
"eth_signTransaction",
|
|
148
|
+
"eth_signTypedData",
|
|
149
|
+
"eth_signMessage",
|
|
150
|
+
"eth_rawSign"
|
|
151
|
+
]
|
|
152
|
+
}
|
|
153
|
+
};
|
|
154
|
+
break;
|
|
155
|
+
}
|
|
156
|
+
case "Secp256r1": {
|
|
157
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), "base16");
|
|
158
|
+
const secp256r1 = new elliptic.ec("p256");
|
|
159
|
+
const keyPair = secp256r1.keyFromPrivate(privateBytes, "hex");
|
|
160
|
+
const publicKeyHex = keyPair.getPublic(true, "hex");
|
|
161
|
+
key = {
|
|
162
|
+
type: args.type,
|
|
163
|
+
kid: args.alias ?? publicKeyHex,
|
|
164
|
+
publicKeyHex,
|
|
165
|
+
meta: {
|
|
166
|
+
jwkThumbprint: calculateJwkThumbprint({
|
|
167
|
+
jwk: toJwk(publicKeyHex, "Secp256r1")
|
|
168
|
+
}),
|
|
169
|
+
algorithms: [
|
|
170
|
+
"ES256"
|
|
171
|
+
]
|
|
172
|
+
}
|
|
173
|
+
};
|
|
174
|
+
break;
|
|
175
|
+
}
|
|
176
|
+
// @ts-ignore
|
|
177
|
+
case "RSA": {
|
|
178
|
+
const x509 = args.meta?.x509;
|
|
179
|
+
const privateKeyPEM = x509?.privateKeyPEM ?? (args.privateKeyHex.includes("---") ? args.privateKeyHex : hexToPEM(args.privateKeyHex, "private"));
|
|
180
|
+
const publicKeyJwk = PEMToJwk(privateKeyPEM, "public");
|
|
181
|
+
const publicKeyPEM = jwkToPEM(publicKeyJwk, "public");
|
|
182
|
+
const publicKeyHex = PEMToHex(publicKeyPEM);
|
|
183
|
+
const meta = {};
|
|
184
|
+
if (x509) {
|
|
185
|
+
meta.x509 = {
|
|
186
|
+
cn: x509.cn ?? args.alias ?? publicKeyHex
|
|
187
|
+
};
|
|
188
|
+
let certChain = x509.certificateChainPEM ?? "";
|
|
189
|
+
if (x509.certificatePEM) {
|
|
190
|
+
if (!certChain.includes(x509.certificatePEM)) {
|
|
191
|
+
certChain = `${x509.certificatePEM}
|
|
192
|
+
${certChain}`;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (certChain.length > 0) {
|
|
196
|
+
meta.x509.certificateChainPEM = certChain;
|
|
197
|
+
const x5c = pemCertChainTox5c(certChain);
|
|
198
|
+
if (!x509.certificateChainURL) {
|
|
199
|
+
publicKeyJwk.x5c = x5c;
|
|
200
|
+
}
|
|
201
|
+
meta.x509.x5c = x5c;
|
|
202
|
+
}
|
|
203
|
+
if (x509.certificateChainURL) {
|
|
204
|
+
publicKeyJwk.x5u = x509.certificateChainURL;
|
|
205
|
+
meta.x509.x5u = x509.certificateChainURL;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
key = {
|
|
209
|
+
type: args.type,
|
|
210
|
+
kid: args.alias ?? meta?.x509?.cn ?? publicKeyHex,
|
|
211
|
+
publicKeyHex,
|
|
212
|
+
meta: {
|
|
213
|
+
...meta,
|
|
214
|
+
// todo: could als be DSA etc
|
|
215
|
+
algorithms: [
|
|
216
|
+
"RS256",
|
|
217
|
+
"RS512",
|
|
218
|
+
"PS256",
|
|
219
|
+
"PS512"
|
|
220
|
+
],
|
|
221
|
+
publicKeyJwk,
|
|
222
|
+
publicKeyPEM
|
|
223
|
+
}
|
|
224
|
+
};
|
|
225
|
+
break;
|
|
226
|
+
}
|
|
227
|
+
default:
|
|
228
|
+
throw Error("not_supported: Key type not supported: " + args.type);
|
|
229
|
+
}
|
|
230
|
+
return key;
|
|
231
|
+
}
|
|
232
|
+
/**
|
|
233
|
+
* @returns a base64url encoded signature for the `RS256` alg
|
|
234
|
+
*/
|
|
235
|
+
async signRSA(privateKey, data, signingAlgorithm) {
|
|
236
|
+
const { hashAlgorithm, scheme } = signAlgorithmToSchemeAndHashAlg(signingAlgorithm);
|
|
237
|
+
const signer = new RSASigner(PEMToJwk(hexToPEM(privateKey.privateKeyHex, "private"), "private"), {
|
|
238
|
+
hashAlgorithm,
|
|
239
|
+
scheme
|
|
240
|
+
});
|
|
241
|
+
const signature = await signer.sign(data);
|
|
242
|
+
return signature;
|
|
243
|
+
}
|
|
244
|
+
async verifyRSA(publicKeyHex, data, signingAlgorithm, signature) {
|
|
245
|
+
const { hashAlgorithm, scheme } = signAlgorithmToSchemeAndHashAlg(signingAlgorithm);
|
|
246
|
+
const signer = new RSASigner(PEMToJwk(hexToPEM(publicKeyHex, "public"), "public"), {
|
|
247
|
+
hashAlgorithm,
|
|
248
|
+
scheme
|
|
249
|
+
});
|
|
250
|
+
return await signer.verify(data, signature);
|
|
251
|
+
}
|
|
252
|
+
async listKeys() {
|
|
253
|
+
return (await this.privateKeyStore.list({})).map((privateKey) => this.asSphereonManagedKeyInfo(privateKey));
|
|
254
|
+
}
|
|
255
|
+
};
|
|
256
|
+
|
|
257
|
+
// src/index.ts
|
|
258
|
+
export * from "@veramo/kms-local";
|
|
259
|
+
var KeyType = /* @__PURE__ */ function(KeyType2) {
|
|
260
|
+
KeyType2["Bls12381G2"] = "Bls12381G2";
|
|
261
|
+
return KeyType2;
|
|
262
|
+
}({});
|
|
263
|
+
export {
|
|
264
|
+
KeyType,
|
|
265
|
+
SphereonKeyManagementSystem
|
|
15
266
|
};
|
|
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
267
|
//# 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 { fromString } from 'uint8arrays/from-string'\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,SAASC,kBAAkB;AAE3B,SACEC,UACAC,UACAC,mBACAC,UACAC,UACAC,WACAC,uCACK;AAEP,IAAMC,QAAQC,MAAM,oBAAA;AAEb,IAAMC,8BAAN,cAA0CC,oBAAAA;EAtBjD,OAsBiDA;;;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,WAAW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M;UACJd,MAAMD,KAAKC;UACXU,KAAKX,KAAKU,SAASkB,MAAMgB,MAAMQ,MAAM9C;UACrCA;UACAsB,MAAM;YACJ,GAAGA;;YAEHC,YAAY;cAAC;cAAS;cAAS;cAAS;;YACxCkB;YACAE;UACF;QACF;AACA;MACF;MAEA;AACE,cAAM1C,MAAM,4CAA4CP,KAAKC,IAAI;IACrE;AACA,WAAOc;EACT;;;;EAKA,MAAcS,QAAQH,YAA+BD,MAAkByC,kBAA2C;AAChH,UAAM,EAAEC,eAAeC,OAAM,IAAKC,gCAAgCH,gBAAAA;AAClE,UAAMI,SAAS,IAAIC,UAAUlB,SAASF,SAASzB,WAAWhB,eAAe,SAAA,GAAY,SAAA,GAAY;MAAEyD;MAAeC;IAAO,CAAA;AACzH,UAAMrC,YAAY,MAAMuC,OAAOhD,KAAKG,IAAAA;AACpC,WAAOM;EACT;EAEA,MAAcC,UAAUrB,cAAsBc,MAAkByC,kBAA0BnC,WAAmB;AAC3G,UAAM,EAAEoC,eAAeC,OAAM,IAAKC,gCAAgCH,gBAAAA;AAClE,UAAMI,SAAS,IAAIC,UAAUlB,SAASF,SAASxC,cAAc,QAAA,GAAW,QAAA,GAAW;MAAEwD;MAAeC;IAAO,CAAA;AAC3G,WAAO,MAAME,OAAOxC,OAAOL,MAAMM,SAAAA;EACnC;EAEA,MAAayC,WAA2C;AACtD,YAAQ,MAAM,KAAKvE,gBAAgBwE,KAAK,CAAC,CAAA,GAAIC,IAAI,CAAChD,eAAkC,KAAKZ,yBAAyBY,UAAAA,CAAAA;EACpH;AACF;;;ACrRA,cAAc;AAcP,IAAKiD,UAAAA,yBAAAA,UAAAA;;SAAAA;;","names":["calculateJwkThumbprint","generatePrivateKeyHex","toJwk","KeyManagementSystem","Debug","elliptic","fromString","hexToPEM","jwkToPEM","pemCertChainTox5c","PEMToHex","PEMToJwk","RSASigner","signAlgorithmToSchemeAndHashAlg","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","fromString","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.28.
|
|
5
|
-
"source": "src/index.ts",
|
|
6
|
-
"
|
|
7
|
-
"
|
|
4
|
+
"version": "0.28.1-feature.esm.cjs.8+4c162d1",
|
|
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.28.
|
|
14
|
-
"@sphereon/ssi-sdk-ext.key-utils": "0.28.
|
|
15
|
-
"@sphereon/ssi-sdk-ext.x509-utils": "0.28.
|
|
25
|
+
"@sphereon/ssi-sdk-ext.did-utils": "^0.28.1-feature.esm.cjs.8+4c162d1",
|
|
26
|
+
"@sphereon/ssi-sdk-ext.key-utils": "^0.28.1-feature.esm.cjs.8+4c162d1",
|
|
27
|
+
"@sphereon/ssi-sdk-ext.x509-utils": "^0.28.1-feature.esm.cjs.8+4c162d1",
|
|
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": "4c162d14577f462070adeea3e7ec5a443c324ee7"
|
|
48
61
|
}
|
|
@@ -5,7 +5,8 @@ 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
|
-
|
|
8
|
+
// @ts-ignore
|
|
9
|
+
import { fromString } from 'uint8arrays/from-string'
|
|
9
10
|
import { KeyType, ManagedKeyInfoArgs } from './index'
|
|
10
11
|
import {
|
|
11
12
|
hexToPEM,
|
|
@@ -171,7 +172,7 @@ export class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
|
171
172
|
}
|
|
172
173
|
break
|
|
173
174
|
case 'Secp256k1': {
|
|
174
|
-
const privateBytes =
|
|
175
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), 'base16')
|
|
175
176
|
const secp256k1 = new elliptic.ec('secp256k1')
|
|
176
177
|
const keyPair = secp256k1.keyFromPrivate(privateBytes, 'hex')
|
|
177
178
|
const publicKeyHex = keyPair.getPublic(true, 'hex')
|
|
@@ -187,7 +188,7 @@ export class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
|
187
188
|
break
|
|
188
189
|
}
|
|
189
190
|
case 'Secp256r1': {
|
|
190
|
-
const privateBytes =
|
|
191
|
+
const privateBytes = fromString(args.privateKeyHex.toLowerCase(), 'base16')
|
|
191
192
|
const secp256r1 = new elliptic.ec('p256')
|
|
192
193
|
const keyPair = secp256r1.keyFromPrivate(privateBytes, 'hex')
|
|
193
194
|
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,C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