@sphereon/ssi-sdk-ext.kms-local 0.13.0 → 0.13.1-unstable.2
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.
|
@@ -1,158 +1,111 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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 bbs_signatures_1 = require("@mattrglobal/bbs-signatures");
|
|
40
|
-
const ssi_sdk_ext_key_utils_1 = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
41
|
-
const kms_local_1 = require("@veramo/kms-local");
|
|
42
|
-
const debug_1 = __importDefault(require("debug"));
|
|
43
|
-
const elliptic_1 = __importDefault(require("elliptic"));
|
|
44
|
-
const u8a = __importStar(require("uint8arrays"));
|
|
45
|
-
const index_1 = require("./index");
|
|
46
|
-
const debug = (0, debug_1.default)('sphereon:kms:bls:local');
|
|
47
|
-
class SphereonKeyManagementSystem extends kms_local_1.KeyManagementSystem {
|
|
1
|
+
import { blsSign, generateBls12381G2KeyPair } from '@mattrglobal/bbs-signatures';
|
|
2
|
+
import { generatePrivateKeyHex, hexToPEM, jwkToPEM, pemCertChainTox5c, PEMToHex, PEMToJwk, RSASigner, signAlgorithmToSchemeAndHashAlg, } from '@sphereon/ssi-sdk-ext.key-utils';
|
|
3
|
+
import { KeyManagementSystem } from '@veramo/kms-local';
|
|
4
|
+
import Debug from 'debug';
|
|
5
|
+
import elliptic from 'elliptic';
|
|
6
|
+
import * as u8a from 'uint8arrays';
|
|
7
|
+
import { KeyType } from './index';
|
|
8
|
+
const debug = Debug('sphereon:kms:bls:local');
|
|
9
|
+
export class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
10
|
+
privateKeyStore;
|
|
48
11
|
constructor(keyStore) {
|
|
49
12
|
super(keyStore);
|
|
50
13
|
this.privateKeyStore = keyStore;
|
|
51
14
|
}
|
|
52
|
-
importKey(args) {
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
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 'Secp256r1':
|
|
67
|
-
// @ts-ignore
|
|
68
|
-
case 'RSA': {
|
|
69
|
-
if (!args.privateKeyHex && !args.privateKeyPEM) {
|
|
70
|
-
throw new Error('invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key');
|
|
71
|
-
}
|
|
72
|
-
const managedKey = this.asSphereonManagedKeyInfo(Object.assign({ alias: args.kid }, args));
|
|
73
|
-
yield this.privateKeyStore.import(Object.assign({ alias: managedKey.kid }, args));
|
|
74
|
-
debug('imported key', managedKey.type, managedKey.publicKeyHex);
|
|
75
|
-
return managedKey;
|
|
76
|
-
}
|
|
77
|
-
default:
|
|
78
|
-
return yield _super.importKey.call(this, args);
|
|
79
|
-
}
|
|
80
|
-
});
|
|
81
|
-
}
|
|
82
|
-
createKey({ type }) {
|
|
83
|
-
const _super = Object.create(null, {
|
|
84
|
-
createKey: { get: () => super.createKey }
|
|
85
|
-
});
|
|
86
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
87
|
-
let key;
|
|
88
|
-
switch (type) {
|
|
89
|
-
case index_1.KeyType.Bls12381G2: {
|
|
90
|
-
const keyPairBls12381G2 = yield (0, bbs_signatures_1.generateBls12381G2KeyPair)();
|
|
91
|
-
key = yield this.importKey({
|
|
92
|
-
type,
|
|
93
|
-
privateKeyHex: Buffer.from(keyPairBls12381G2.secretKey).toString('hex'),
|
|
94
|
-
publicKeyHex: Buffer.from(keyPairBls12381G2.publicKey).toString('hex'),
|
|
95
|
-
});
|
|
96
|
-
break;
|
|
15
|
+
async importKey(args) {
|
|
16
|
+
switch (args.type) {
|
|
17
|
+
case KeyType.Bls12381G2.toString():
|
|
18
|
+
if (!args.privateKeyHex || !args.publicKeyHex) {
|
|
19
|
+
throw new Error('invalid_argument: type, publicKeyHex and privateKeyHex are required to import a key');
|
|
97
20
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
21
|
+
const managedKey = this.asSphereonManagedKeyInfo({
|
|
22
|
+
...args,
|
|
23
|
+
alias: args.kid,
|
|
24
|
+
privateKeyHex: args.privateKeyHex,
|
|
25
|
+
publicKeyHex: args.publicKeyHex,
|
|
26
|
+
type: args.type,
|
|
27
|
+
});
|
|
28
|
+
await this.privateKeyStore.importKey({ alias: managedKey.kid, ...args });
|
|
29
|
+
debug('imported key', managedKey.type, managedKey.publicKeyHex);
|
|
30
|
+
return managedKey;
|
|
31
|
+
case 'Secp256r1':
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
case 'RSA': {
|
|
34
|
+
if (!args.privateKeyHex && !args.privateKeyPEM) {
|
|
35
|
+
throw new Error('invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key');
|
|
106
36
|
}
|
|
107
|
-
|
|
108
|
-
|
|
37
|
+
const managedKey = this.asSphereonManagedKeyInfo({ alias: args.kid, ...args });
|
|
38
|
+
await this.privateKeyStore.importKey({ alias: managedKey.kid, ...args });
|
|
39
|
+
debug('imported key', managedKey.type, managedKey.publicKeyHex);
|
|
40
|
+
return managedKey;
|
|
109
41
|
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
}
|
|
42
|
+
default:
|
|
43
|
+
return await super.importKey(args);
|
|
44
|
+
}
|
|
113
45
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
if (privateKey.type === index_1.KeyType.Bls12381G2) {
|
|
127
|
-
if (!data || Array.isArray(data)) {
|
|
128
|
-
throw new Error('Data must be defined and cannot be an array');
|
|
129
|
-
}
|
|
130
|
-
const keyPair = {
|
|
131
|
-
keyPair: {
|
|
132
|
-
secretKey: Uint8Array.from(Buffer.from(privateKey.privateKeyHex, 'hex')),
|
|
133
|
-
publicKey: Uint8Array.from(Buffer.from(keyRef.kid, 'hex')),
|
|
134
|
-
},
|
|
135
|
-
messages: [data],
|
|
136
|
-
};
|
|
137
|
-
return Buffer.from(yield (0, bbs_signatures_1.blsSign)(keyPair)).toString('hex');
|
|
46
|
+
async createKey({ type }) {
|
|
47
|
+
let key;
|
|
48
|
+
switch (type) {
|
|
49
|
+
case KeyType.Bls12381G2: {
|
|
50
|
+
const keyPairBls12381G2 = await generateBls12381G2KeyPair();
|
|
51
|
+
key = await this.importKey({
|
|
52
|
+
type,
|
|
53
|
+
privateKeyHex: Buffer.from(keyPairBls12381G2.secretKey).toString('hex'),
|
|
54
|
+
publicKeyHex: Buffer.from(keyPairBls12381G2.publicKey).toString('hex'),
|
|
55
|
+
});
|
|
56
|
+
break;
|
|
138
57
|
}
|
|
139
|
-
else if (
|
|
140
58
|
// @ts-ignore
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
59
|
+
case 'RSA': {
|
|
60
|
+
const privateKeyHex = await generatePrivateKeyHex(type);
|
|
61
|
+
key = await this.importKey({
|
|
62
|
+
type,
|
|
63
|
+
privateKeyHex,
|
|
64
|
+
});
|
|
65
|
+
break;
|
|
144
66
|
}
|
|
145
|
-
|
|
146
|
-
|
|
67
|
+
default:
|
|
68
|
+
key = await super.createKey({ type });
|
|
69
|
+
}
|
|
70
|
+
debug('Created key', type, key.publicKeyHex);
|
|
71
|
+
return key;
|
|
72
|
+
}
|
|
73
|
+
async sign({ keyRef, algorithm, data }) {
|
|
74
|
+
let privateKey;
|
|
75
|
+
try {
|
|
76
|
+
privateKey = await this.privateKeyStore.getKey({ alias: keyRef.kid });
|
|
77
|
+
}
|
|
78
|
+
catch (e) {
|
|
79
|
+
throw new Error(`key_not_found: No key entry found for kid=${keyRef.kid}`);
|
|
80
|
+
}
|
|
81
|
+
if (privateKey.type === KeyType.Bls12381G2) {
|
|
82
|
+
if (!data || Array.isArray(data)) {
|
|
83
|
+
throw new Error('Data must be defined and cannot be an array');
|
|
147
84
|
}
|
|
148
|
-
|
|
149
|
-
|
|
85
|
+
const keyPair = {
|
|
86
|
+
keyPair: {
|
|
87
|
+
secretKey: Uint8Array.from(Buffer.from(privateKey.privateKeyHex, 'hex')),
|
|
88
|
+
publicKey: Uint8Array.from(Buffer.from(keyRef.kid, 'hex')),
|
|
89
|
+
},
|
|
90
|
+
messages: [data],
|
|
91
|
+
};
|
|
92
|
+
return Buffer.from(await blsSign(keyPair)).toString('hex');
|
|
93
|
+
}
|
|
94
|
+
else if (
|
|
95
|
+
// @ts-ignore
|
|
96
|
+
privateKey.type === 'RSA' &&
|
|
97
|
+
(typeof algorithm === 'undefined' || algorithm === 'RS256' || algorithm === 'RS512' || algorithm === 'PS256' || algorithm === 'PS512')) {
|
|
98
|
+
return await this.signRSA(privateKey.privateKeyHex, data, algorithm ?? 'PS256');
|
|
99
|
+
}
|
|
100
|
+
else {
|
|
101
|
+
return await super.sign({ keyRef, algorithm, data });
|
|
102
|
+
}
|
|
103
|
+
throw Error(`not_supported: Cannot sign using key of type ${privateKey.type}`);
|
|
150
104
|
}
|
|
151
105
|
asSphereonManagedKeyInfo(args) {
|
|
152
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
153
106
|
let key;
|
|
154
107
|
switch (args.type) {
|
|
155
|
-
case
|
|
108
|
+
case KeyType.Bls12381G2:
|
|
156
109
|
key = {
|
|
157
110
|
type: args.type,
|
|
158
111
|
kid: args.alias || args.publicKeyHex,
|
|
@@ -164,7 +117,7 @@ class SphereonKeyManagementSystem extends kms_local_1.KeyManagementSystem {
|
|
|
164
117
|
break;
|
|
165
118
|
case 'Secp256r1': {
|
|
166
119
|
const privateBytes = u8a.fromString(args.privateKeyHex.toLowerCase(), 'base16');
|
|
167
|
-
const secp256r1 = new
|
|
120
|
+
const secp256r1 = new elliptic.ec('p256');
|
|
168
121
|
const keyPair = secp256r1.keyFromPrivate(privateBytes);
|
|
169
122
|
const publicKeyHex = keyPair.getPublic(true, 'hex');
|
|
170
123
|
key = {
|
|
@@ -179,17 +132,17 @@ class SphereonKeyManagementSystem extends kms_local_1.KeyManagementSystem {
|
|
|
179
132
|
}
|
|
180
133
|
// @ts-ignore
|
|
181
134
|
case 'RSA': {
|
|
182
|
-
const x509 =
|
|
183
|
-
const privateKeyPEM =
|
|
184
|
-
const publicKeyJwk =
|
|
185
|
-
const publicKeyPEM =
|
|
186
|
-
const publicKeyHex =
|
|
135
|
+
const x509 = args.meta?.x509;
|
|
136
|
+
const privateKeyPEM = 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)
|
|
137
|
+
const publicKeyJwk = PEMToJwk(privateKeyPEM, 'public');
|
|
138
|
+
const publicKeyPEM = jwkToPEM(publicKeyJwk, 'public');
|
|
139
|
+
const publicKeyHex = PEMToHex(publicKeyPEM);
|
|
187
140
|
const meta = {};
|
|
188
141
|
if (x509) {
|
|
189
142
|
meta.x509 = {
|
|
190
|
-
cn:
|
|
143
|
+
cn: x509.cn ?? args.alias ?? publicKeyHex,
|
|
191
144
|
};
|
|
192
|
-
let certChain =
|
|
145
|
+
let certChain = x509.certificateChainPEM ?? '';
|
|
193
146
|
if (x509.certificatePEM) {
|
|
194
147
|
if (!certChain.includes(x509.certificatePEM)) {
|
|
195
148
|
certChain = `${x509.certificatePEM}\n${certChain}`;
|
|
@@ -197,7 +150,7 @@ class SphereonKeyManagementSystem extends kms_local_1.KeyManagementSystem {
|
|
|
197
150
|
}
|
|
198
151
|
if (certChain.length > 0) {
|
|
199
152
|
meta.x509.certificateChainPEM = certChain;
|
|
200
|
-
const x5c =
|
|
153
|
+
const x5c = pemCertChainTox5c(certChain);
|
|
201
154
|
if (!x509.certificateChainURL) {
|
|
202
155
|
// Do not put the chain in the JWK when the chain is hosted. We do put it in the x509 metadata
|
|
203
156
|
// @ts-ignore
|
|
@@ -213,12 +166,15 @@ class SphereonKeyManagementSystem extends kms_local_1.KeyManagementSystem {
|
|
|
213
166
|
}
|
|
214
167
|
key = {
|
|
215
168
|
type: args.type,
|
|
216
|
-
kid:
|
|
169
|
+
kid: args.alias ?? meta?.x509?.cn ?? publicKeyHex,
|
|
217
170
|
publicKeyHex,
|
|
218
|
-
meta:
|
|
171
|
+
meta: {
|
|
172
|
+
...meta,
|
|
219
173
|
// todo: could als be DSA etc
|
|
220
|
-
algorithms: ['RS256', 'RS512', 'PS256', 'PS512'],
|
|
221
|
-
|
|
174
|
+
algorithms: ['RS256', 'RS512', 'PS256', 'PS512'],
|
|
175
|
+
publicKeyJwk,
|
|
176
|
+
publicKeyPEM,
|
|
177
|
+
},
|
|
222
178
|
};
|
|
223
179
|
break;
|
|
224
180
|
}
|
|
@@ -230,14 +186,11 @@ class SphereonKeyManagementSystem extends kms_local_1.KeyManagementSystem {
|
|
|
230
186
|
/**
|
|
231
187
|
* @returns a base64url encoded signature for the `RS256` alg
|
|
232
188
|
*/
|
|
233
|
-
signRSA(privateKeyHex, data, signingAlgorithm) {
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return signature;
|
|
239
|
-
});
|
|
189
|
+
async signRSA(privateKeyHex, data, signingAlgorithm) {
|
|
190
|
+
const { hashAlgorithm, scheme } = signAlgorithmToSchemeAndHashAlg(signingAlgorithm);
|
|
191
|
+
const signer = new RSASigner(PEMToJwk(hexToPEM(privateKeyHex, 'private'), 'private'), { hashAlgorithm, scheme });
|
|
192
|
+
const signature = await signer.sign(data);
|
|
193
|
+
return signature;
|
|
240
194
|
}
|
|
241
195
|
}
|
|
242
|
-
exports.SphereonKeyManagementSystem = SphereonKeyManagementSystem;
|
|
243
196
|
//# sourceMappingURL=SphereonKeyManagementSystem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"SphereonKeyManagementSystem.js","sourceRoot":"","sources":["../src/SphereonKeyManagementSystem.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"SphereonKeyManagementSystem.js","sourceRoot":"","sources":["../src/SphereonKeyManagementSystem.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAChF,OAAO,EACL,qBAAqB,EACrB,QAAQ,EACR,QAAQ,EACR,iBAAiB,EACjB,QAAQ,EACR,QAAQ,EACR,SAAS,EACT,+BAA+B,GAEhC,MAAM,iCAAiC,CAAA;AAIxC,OAAO,EAAE,mBAAmB,EAAE,MAAM,mBAAmB,CAAA;AACvD,OAAO,KAAK,MAAM,OAAO,CAAA;AACzB,OAAO,QAAQ,MAAM,UAAU,CAAA;AAC/B,OAAO,KAAK,GAAG,MAAM,aAAa,CAAA;AAClC,OAAO,EAAE,OAAO,EAAsB,MAAM,SAAS,CAAA;AAErD,MAAM,KAAK,GAAG,KAAK,CAAC,wBAAwB,CAAC,CAAA;AAE7C,MAAM,OAAO,2BAA4B,SAAQ,mBAAmB;IACjD,eAAe,CAAyB;IAEzD,YAAY,QAAiC;QAC3C,KAAK,CAAC,QAAQ,CAAC,CAAA;QACf,IAAI,CAAC,eAAe,GAAG,QAAQ,CAAA;IACjC,CAAC;IAED,KAAK,CAAC,SAAS,CAAC,IAAoE;QAClF,QAAQ,IAAI,CAAC,IAAI,EAAE;YACjB,KAAK,OAAO,CAAC,UAAU,CAAC,QAAQ,EAAE;gBAChC,IAAI,CAAC,IAAI,CAAC,aAAa,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE;oBAC7C,MAAM,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AAI;wBACP,6BAA6B;wBAC7B,UAAU,EAAE,CAAC,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,OAAO,CAAC;wBAChD,YAAY;wBACZ,YAAY;qBACb;iBACF,CAAA;gBACD,MAAK;aACN;YAED;gBACE,MAAM,KAAK,CAAC,yCAAyC,GAAG,IAAI,CAAC,IAAI,CAAC,CAAA;SACrE;QACD,OAAO,GAAqB,CAAA;IAC9B,CAAC;IAED;;OAEG;IACK,KAAK,CAAC,OAAO,CAAC,aAAqB,EAAE,IAAgB,EAAE,gBAAwB;QACrF,MAAM,EAAE,aAAa,EAAE,MAAM,EAAE,GAAG,+BAA+B,CAAC,gBAAgB,CAAC,CAAA;QACnF,MAAM,MAAM,GAAG,IAAI,SAAS,CAAC,QAAQ,CAAC,QAAQ,CAAC,aAAa,EAAE,SAAS,CAAC,EAAE,SAAS,CAAC,EAAE,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,CAAA;QAChH,MAAM,SAAS,GAAG,MAAM,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAA;QACzC,OAAO,SAAmB,CAAA;IAC5B,CAAC;CACF"}
|
package/dist/index.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.KeyType = exports.SphereonKeyManagementSystem = void 0;
|
|
4
|
-
var SphereonKeyManagementSystem_1 = require("./SphereonKeyManagementSystem");
|
|
5
|
-
Object.defineProperty(exports, "SphereonKeyManagementSystem", { enumerable: true, get: function () { return SphereonKeyManagementSystem_1.SphereonKeyManagementSystem; } });
|
|
6
|
-
var KeyType;
|
|
1
|
+
export { SphereonKeyManagementSystem } from './SphereonKeyManagementSystem';
|
|
2
|
+
export var KeyType;
|
|
7
3
|
(function (KeyType) {
|
|
8
4
|
KeyType["Bls12381G2"] = "Bls12381G2";
|
|
9
|
-
})(KeyType
|
|
5
|
+
})(KeyType || (KeyType = {}));
|
|
10
6
|
//# 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":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,2BAA2B,EAAE,MAAM,+BAA+B,CAAA;AAc3E,MAAM,CAAN,IAAY,OAEX;AAFD,WAAY,OAAO;IACjB,oCAAyB,CAAA;AAC3B,CAAC,EAFW,OAAO,KAAP,OAAO,QAElB"}
|
package/dist/tsdoc-metadata.json
CHANGED
package/package.json
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
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.13.
|
|
4
|
+
"version": "0.13.1-unstable.2+6b086a6",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
8
|
+
"type": "module",
|
|
8
9
|
"scripts": {
|
|
9
10
|
"build": "tsc --build",
|
|
10
11
|
"generate-plugin-schema": "pnpm veramo dev extract-api"
|
|
@@ -12,19 +13,19 @@
|
|
|
12
13
|
"dependencies": {
|
|
13
14
|
"@mattrglobal/bbs-signatures": "^1.1.0",
|
|
14
15
|
"@sphereon/isomorphic-webcrypto": "^2.4.0-unstable.4",
|
|
15
|
-
"@sphereon/ssi-sdk-ext.did-utils": "0.13.
|
|
16
|
-
"@sphereon/ssi-sdk-ext.key-utils": "0.13.
|
|
16
|
+
"@sphereon/ssi-sdk-ext.did-utils": "0.13.1-unstable.2+6b086a6",
|
|
17
|
+
"@sphereon/ssi-sdk-ext.key-utils": "0.13.1-unstable.2+6b086a6",
|
|
17
18
|
"@trust/keyto": "^2.0.0-alpha1",
|
|
18
|
-
"@veramo/core": "
|
|
19
|
-
"@veramo/key-manager": "4.
|
|
20
|
-
"@veramo/kms-local": "4.
|
|
19
|
+
"@veramo/core": "^5.3.0",
|
|
20
|
+
"@veramo/key-manager": "5.4.0",
|
|
21
|
+
"@veramo/kms-local": "5.4.0",
|
|
21
22
|
"elliptic": "^6.5.4",
|
|
22
23
|
"uint8arrays": "3.1.1"
|
|
23
24
|
},
|
|
24
25
|
"devDependencies": {
|
|
25
26
|
"@sphereon/jsencrypt": "^3.3.2-unstable.0",
|
|
26
27
|
"@types/elliptic": "6.4.14",
|
|
27
|
-
"@veramo/cli": "
|
|
28
|
+
"@veramo/cli": "^5.3.0"
|
|
28
29
|
},
|
|
29
30
|
"resolutions": {
|
|
30
31
|
"**/@digitalcredentials/ed25519-verification-key-2020": "3.2.2"
|
|
@@ -47,5 +48,5 @@
|
|
|
47
48
|
"kms",
|
|
48
49
|
"Veramo"
|
|
49
50
|
],
|
|
50
|
-
"gitHead": "
|
|
51
|
+
"gitHead": "6b086a63124311dda85df1f44929df99bdc48616"
|
|
51
52
|
}
|
|
@@ -42,7 +42,7 @@ export class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
|
42
42
|
publicKeyHex: args.publicKeyHex,
|
|
43
43
|
type: args.type,
|
|
44
44
|
})
|
|
45
|
-
await this.privateKeyStore.
|
|
45
|
+
await this.privateKeyStore.importKey({ alias: managedKey.kid, ...args })
|
|
46
46
|
debug('imported key', managedKey.type, managedKey.publicKeyHex)
|
|
47
47
|
return managedKey
|
|
48
48
|
|
|
@@ -53,7 +53,7 @@ export class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
|
53
53
|
throw new Error('invalid_argument: type and privateKeyHex (or privateKeyPEM for RSA) are required to import a key')
|
|
54
54
|
}
|
|
55
55
|
const managedKey = this.asSphereonManagedKeyInfo({ alias: args.kid, ...args })
|
|
56
|
-
await this.privateKeyStore.
|
|
56
|
+
await this.privateKeyStore.importKey({ alias: managedKey.kid, ...args })
|
|
57
57
|
debug('imported key', managedKey.type, managedKey.publicKeyHex)
|
|
58
58
|
return managedKey
|
|
59
59
|
}
|
|
@@ -97,7 +97,7 @@ export class SphereonKeyManagementSystem extends KeyManagementSystem {
|
|
|
97
97
|
async sign({ keyRef, algorithm, data }: { keyRef: Pick<IKey, 'kid'>; algorithm?: string; data: Uint8Array }): Promise<string> {
|
|
98
98
|
let privateKey: ManagedPrivateKey
|
|
99
99
|
try {
|
|
100
|
-
privateKey = await this.privateKeyStore.
|
|
100
|
+
privateKey = await this.privateKeyStore.getKey({ alias: keyRef.kid })
|
|
101
101
|
} catch (e) {
|
|
102
102
|
throw new Error(`key_not_found: No key entry found for kid=${keyRef.kid}`)
|
|
103
103
|
}
|