@sphereon/ssi-sdk-ext.kms-musap-rn 0.26.1-feature.SPRIND.116.8 → 0.26.1-feature.SPRIND.124.esim.29
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,12 +1,19 @@
|
|
|
1
1
|
import { IKey, ManagedKeyInfo, MinimalImportableKey, TKeyType } from '@veramo/core';
|
|
2
|
-
import { SscdType } from '@sphereon/musap-react-native';
|
|
2
|
+
import { ExternalSscdSettings, SscdType } from '@sphereon/musap-react-native';
|
|
3
3
|
import { AbstractKeyManagementSystem } from '@veramo/key-manager';
|
|
4
4
|
import { KeyMetadata } from './index';
|
|
5
5
|
export declare const logger: import("@sphereon/ssi-types").ISimpleLogger<unknown>;
|
|
6
6
|
export declare class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
7
|
-
private
|
|
8
|
-
private sscdType;
|
|
9
|
-
|
|
7
|
+
private musapClient;
|
|
8
|
+
private readonly sscdType;
|
|
9
|
+
private readonly sscdId;
|
|
10
|
+
private readonly defaultKeyAttributes;
|
|
11
|
+
private readonly defaultSignAttributes;
|
|
12
|
+
constructor(sscdType?: SscdType, sscdId?: string, opts?: {
|
|
13
|
+
externalSscdSettings?: ExternalSscdSettings;
|
|
14
|
+
defaultKeyAttributes?: Record<string, string>;
|
|
15
|
+
defaultSignAttributes?: Record<string, string>;
|
|
16
|
+
});
|
|
10
17
|
listKeys(): Promise<ManagedKeyInfo[]>;
|
|
11
18
|
createKey(args: {
|
|
12
19
|
type: TKeyType;
|
|
@@ -32,5 +39,7 @@ export declare class MusapKeyManagementSystem extends AbstractKeyManagementSyste
|
|
|
32
39
|
myKeyRef: Pick<IKey, 'kid'>;
|
|
33
40
|
theirKey: Pick<IKey, 'publicKeyHex' | 'type'>;
|
|
34
41
|
}): Promise<string>;
|
|
42
|
+
private recordToKeyAttributes;
|
|
43
|
+
private recordToSignatureAttributes;
|
|
35
44
|
}
|
|
36
45
|
//# sourceMappingURL=MusapKeyManagerSystem.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MusapKeyManagerSystem.d.ts","sourceRoot":"","sources":["../src/MusapKeyManagerSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"MusapKeyManagerSystem.d.ts","sourceRoot":"","sources":["../src/MusapKeyManagerSystem.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,IAAI,EAAE,cAAc,EAAE,oBAAoB,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAA;AACnF,OAAO,EACL,oBAAoB,EAepB,QAAQ,EACT,MAAM,8BAA8B,CAAA;AACrC,OAAO,EAAE,2BAA2B,EAAE,MAAM,qBAAqB,CAAA;AAGjE,OAAO,EAAE,WAAW,EAAE,MAAM,SAAS,CAAA;AAUrC,eAAO,MAAM,MAAM,sDAA+C,CAAA;AAElE,qBAAa,wBAAyB,SAAQ,2BAA2B;IACvE,OAAO,CAAC,WAAW,CAAc;IACjC,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAU;IACnC,OAAO,CAAC,QAAQ,CAAC,MAAM,CAAQ;IAC/B,OAAO,CAAC,QAAQ,CAAC,oBAAoB,CAAoC;IACzE,OAAO,CAAC,QAAQ,CAAC,qBAAqB,CAAoC;gBAE9D,QAAQ,CAAC,EAAE,QAAQ,EAAE,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,EAAE;QACvD,oBAAoB,CAAC,EAAE,oBAAoB,CAAC;QAC5C,oBAAoB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;QAC9C,qBAAqB,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;KAC/C;IAmBK,QAAQ,IAAI,OAAO,CAAC,cAAc,EAAE,CAAC;IAKrC,SAAS,CAAC,IAAI,EAAE;QAAE,IAAI,EAAE,QAAQ,CAAC;QAAC,IAAI,CAAC,EAAE,WAAW,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAwCtF,OAAO,CAAC,yBAAyB,CAWhC;IAED,OAAO,CAAC,yBAAyB,CAWhC;IAEK,SAAS,CAAC,EAAE,GAAG,EAAE,EAAE;QAAE,GAAG,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,OAAO,CAAC;IAU3D,OAAO,CAAC,kBAAkB;IAapB,IAAI,CAAC,IAAI,EAAE;QACf,MAAM,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAC1B,SAAS,CAAC,EAAE,MAAM,CAAC;QACnB,IAAI,EAAE,UAAU,CAAC;QACjB,CAAC,CAAC,EAAE,MAAM,GAAG,GAAG,CAAA;KACjB,GAAG,OAAO,CAAC,MAAM,CAAC;IAoBb,SAAS,CAAC,IAAI,EAAE,IAAI,CAAC,oBAAoB,EAAE,KAAK,CAAC,GAAG;QAAE,aAAa,CAAC,EAAE,MAAM,CAAA;KAAE,GAAG,OAAO,CAAC,cAAc,CAAC;IAI9G,OAAO,CAAC,cAAc;IAoBtB,YAAY,CAAC,IAAI,EAAE;QAAE,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,CAAC;QAAC,QAAQ,EAAE,IAAI,CAAC,IAAI,EAAE,cAAc,GAAG,MAAM,CAAC,CAAA;KAAE,GAAG,OAAO,CAAC,MAAM,CAAC;IAInH,OAAO,CAAC,qBAAqB;IAU7B,OAAO,CAAC,2BAA2B;CASpC"}
|
|
@@ -29,7 +29,7 @@ const ssi_types_1 = require("@sphereon/ssi-types");
|
|
|
29
29
|
const ssi_sdk_ext_key_utils_1 = require("@sphereon/ssi-sdk-ext.key-utils");
|
|
30
30
|
exports.logger = ssi_types_1.Loggers.DEFAULT.get('sphereon:musap-rn-kms');
|
|
31
31
|
class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem {
|
|
32
|
-
constructor(sscdType) {
|
|
32
|
+
constructor(sscdType, sscdId, opts) {
|
|
33
33
|
super();
|
|
34
34
|
this.mapKeyTypeToAlgorithmType = (type) => {
|
|
35
35
|
switch (type) {
|
|
@@ -56,9 +56,15 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
56
56
|
}
|
|
57
57
|
};
|
|
58
58
|
try {
|
|
59
|
-
this.
|
|
59
|
+
this.musapClient = musap_react_native_1.MusapClient;
|
|
60
60
|
this.sscdType = sscdType ? sscdType : 'TEE';
|
|
61
|
-
this.
|
|
61
|
+
this.sscdId = sscdId !== null && sscdId !== void 0 ? sscdId : this.sscdType;
|
|
62
|
+
this.defaultKeyAttributes = opts === null || opts === void 0 ? void 0 : opts.defaultKeyAttributes;
|
|
63
|
+
this.defaultSignAttributes = opts === null || opts === void 0 ? void 0 : opts.defaultSignAttributes;
|
|
64
|
+
const enabledSscds = this.musapClient.listEnabledSscds();
|
|
65
|
+
if (!enabledSscds.some(value => value.sscdId == sscdId)) {
|
|
66
|
+
this.musapClient.enableSscd(this.sscdType, this.sscdId, opts === null || opts === void 0 ? void 0 : opts.externalSscdSettings);
|
|
67
|
+
}
|
|
62
68
|
}
|
|
63
69
|
catch (e) {
|
|
64
70
|
console.error('enableSscd', e);
|
|
@@ -67,7 +73,7 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
67
73
|
}
|
|
68
74
|
listKeys() {
|
|
69
75
|
return __awaiter(this, void 0, void 0, function* () {
|
|
70
|
-
const keysJson = (
|
|
76
|
+
const keysJson = (this.musapClient.listKeys());
|
|
71
77
|
return keysJson.map((key) => this.asMusapKeyInfo(key));
|
|
72
78
|
});
|
|
73
79
|
}
|
|
@@ -77,18 +83,28 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
77
83
|
if (meta === undefined || !('keyAlias' in meta)) {
|
|
78
84
|
return Promise.reject(Error('a unique keyAlias field is required for MUSAP'));
|
|
79
85
|
}
|
|
86
|
+
if (this.sscdType == 'EXTERNAL') {
|
|
87
|
+
const existingKeys = (this.musapClient.listKeys());
|
|
88
|
+
const extKey = existingKeys.find(musapKey => musapKey.sscdType === 'External Signature'); // FIXME returning does not match SscdType enum
|
|
89
|
+
if (extKey) {
|
|
90
|
+
const managedKeyInfo = this.asMusapKeyInfo(extKey);
|
|
91
|
+
managedKeyInfo.type = 'Secp256r1'; // FIXME MUSAP announces key as rsa2k, but it's actually EC
|
|
92
|
+
return managedKeyInfo;
|
|
93
|
+
}
|
|
94
|
+
return Promise.reject(Error(`No external key was bound yet for sscd ${this.sscdId}`));
|
|
95
|
+
}
|
|
80
96
|
const keyGenReq = {
|
|
81
97
|
keyAlgorithm: this.mapKeyTypeToAlgorithmType(type),
|
|
82
98
|
keyUsage: 'keyUsage' in meta ? meta.keyUsage : 'sign',
|
|
83
99
|
keyAlias: meta.keyAlias,
|
|
84
|
-
attributes: 'attributes' in meta ? meta.attributes :
|
|
100
|
+
attributes: this.recordToKeyAttributes(Object.assign(Object.assign({}, this.defaultKeyAttributes), ('attributes' in meta ? meta.attributes : {}))),
|
|
85
101
|
role: 'role' in meta ? meta.role : 'administrator',
|
|
86
102
|
};
|
|
87
103
|
try {
|
|
88
|
-
const generatedKeyUri = yield this.
|
|
104
|
+
const generatedKeyUri = yield this.musapClient.generateKey(this.sscdType, keyGenReq);
|
|
89
105
|
if (generatedKeyUri) {
|
|
90
106
|
exports.logger.debug('Generated key:', generatedKeyUri);
|
|
91
|
-
const key =
|
|
107
|
+
const key = this.musapClient.getKeyByUri(generatedKeyUri);
|
|
92
108
|
return this.asMusapKeyInfo(key);
|
|
93
109
|
}
|
|
94
110
|
else {
|
|
@@ -104,7 +120,7 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
104
120
|
deleteKey(_a) {
|
|
105
121
|
return __awaiter(this, arguments, void 0, function* ({ kid }) {
|
|
106
122
|
try {
|
|
107
|
-
this.
|
|
123
|
+
void this.musapClient.removeKey(kid);
|
|
108
124
|
return true;
|
|
109
125
|
}
|
|
110
126
|
catch (error) {
|
|
@@ -130,7 +146,7 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
130
146
|
throw new Error('key_not_found: No key ref provided');
|
|
131
147
|
}
|
|
132
148
|
const data = new text_encoding_1.TextDecoder().decode(args.data);
|
|
133
|
-
const key = this.
|
|
149
|
+
const key = this.musapClient.getKeyById(args.keyRef.kid);
|
|
134
150
|
const signatureReq = {
|
|
135
151
|
keyUri: key.keyUri,
|
|
136
152
|
data,
|
|
@@ -138,9 +154,9 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
138
154
|
displayText: args.displayText,
|
|
139
155
|
transId: args.transId,
|
|
140
156
|
format: (_a = args.format) !== null && _a !== void 0 ? _a : 'RAW',
|
|
141
|
-
attributes: args.attributes,
|
|
157
|
+
attributes: this.recordToSignatureAttributes(Object.assign(Object.assign({}, this.defaultSignAttributes), args.attributes)),
|
|
142
158
|
};
|
|
143
|
-
return this.
|
|
159
|
+
return this.musapClient.sign(signatureReq);
|
|
144
160
|
});
|
|
145
161
|
}
|
|
146
162
|
importKey(args) {
|
|
@@ -169,6 +185,24 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
169
185
|
sharedSecret(args) {
|
|
170
186
|
throw new Error('Not supported.');
|
|
171
187
|
}
|
|
188
|
+
recordToKeyAttributes(record) {
|
|
189
|
+
if (!record) {
|
|
190
|
+
return [];
|
|
191
|
+
}
|
|
192
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
193
|
+
name: key,
|
|
194
|
+
value,
|
|
195
|
+
}));
|
|
196
|
+
}
|
|
197
|
+
recordToSignatureAttributes(record) {
|
|
198
|
+
if (!record) {
|
|
199
|
+
return [];
|
|
200
|
+
}
|
|
201
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
202
|
+
name: key,
|
|
203
|
+
value,
|
|
204
|
+
}));
|
|
205
|
+
}
|
|
172
206
|
}
|
|
173
207
|
exports.MusapKeyManagementSystem = MusapKeyManagementSystem;
|
|
174
208
|
//# sourceMappingURL=MusapKeyManagerSystem.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"MusapKeyManagerSystem.js","sourceRoot":"","sources":["../src/MusapKeyManagerSystem.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,6EAA8D;AAE9D,
|
|
1
|
+
{"version":3,"file":"MusapKeyManagerSystem.js","sourceRoot":"","sources":["../src/MusapKeyManagerSystem.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;AAAA,6EAA8D;AAE9D,qEAiBqC;AACrC,qDAAiE;AACjE,iDAA2C;AAC3C,mDAA6C;AAE7C,2EAOwC;AAE3B,QAAA,MAAM,GAAG,mBAAO,CAAC,OAAO,CAAC,GAAG,CAAC,uBAAuB,CAAC,CAAA;AAElE,MAAa,wBAAyB,SAAQ,yCAA2B;IAOvE,YAAY,QAAmB,EAAE,MAAe,EAAE,IAIjD;QACC,KAAK,EAAE,CAAA;QA+DD,8BAAyB,GAAG,CAAC,IAAc,EAAoB,EAAE;YACvE,QAAQ,IAAI,EAAE,CAAC;gBACb,KAAK,WAAW;oBACd,OAAO,WAAW,CAAA;gBACpB,KAAK,WAAW;oBACd,OAAO,WAAW,CAAA;gBACpB,KAAK,KAAK;oBACR,OAAO,OAAO,CAAA;gBAChB;oBACE,MAAM,IAAI,KAAK,CAAC,YAAY,IAAI,4BAA4B,CAAC,CAAA;YACjE,CAAC;QACH,CAAC,CAAA;QAEO,8BAAyB,GAAG,CAAC,IAAkB,EAAY,EAAE;YACnE,QAAQ,IAAI,EAAE,CAAC;gBACb,KAAK,WAAW;oBACd,OAAO,WAAW,CAAA;gBACpB,KAAK,WAAW;oBACd,OAAO,WAAW,CAAA;gBACpB,KAAK,OAAO;oBACV,OAAO,KA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A;IACL,CAAC;IAEO,2BAA2B,CAAC,MAA+B;QACjE,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,OAAO,EAAE,CAAA;QACX,CAAC;QACD,OAAO,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACnD,IAAI,EAAE,GAAG;YACT,KAAK;SACN,CAAC,CAAC,CAAA;IACL,CAAC;CACF;AApMD,4DAoMC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sphereon/ssi-sdk-ext.kms-musap-rn",
|
|
3
3
|
"description": "Sphereon SSI-SDK react-native plugin for management of keys with musap.",
|
|
4
|
-
"version": "0.26.1-feature.SPRIND.
|
|
4
|
+
"version": "0.26.1-feature.SPRIND.124.esim.29+217de7e",
|
|
5
5
|
"source": "src/index.ts",
|
|
6
6
|
"main": "dist/index.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -10,9 +10,9 @@
|
|
|
10
10
|
"build:clean": "tsc --build --clean && tsc --build"
|
|
11
11
|
},
|
|
12
12
|
"dependencies": {
|
|
13
|
-
"@sphereon/musap-react-native": "0.
|
|
14
|
-
"@sphereon/ssi-sdk-ext.key-utils": "0.26.1-feature.SPRIND.
|
|
15
|
-
"@sphereon/ssi-sdk-ext.x509-utils": "0.26.1-feature.SPRIND.
|
|
13
|
+
"@sphereon/musap-react-native": "0.2.1-unstable.160",
|
|
14
|
+
"@sphereon/ssi-sdk-ext.key-utils": "0.26.1-feature.SPRIND.124.esim.29+217de7e",
|
|
15
|
+
"@sphereon/ssi-sdk-ext.x509-utils": "0.26.1-feature.SPRIND.124.esim.29+217de7e",
|
|
16
16
|
"@sphereon/ssi-types": "0.30.2-feature.SDK.41.oidf.support.286",
|
|
17
17
|
"@veramo/core": "4.2.0",
|
|
18
18
|
"@veramo/key-manager": "4.2.0",
|
|
@@ -41,5 +41,5 @@
|
|
|
41
41
|
"react-native",
|
|
42
42
|
"Veramo"
|
|
43
43
|
],
|
|
44
|
-
"gitHead": "
|
|
44
|
+
"gitHead": "217de7e2cb4eabe1d42e6780b1b0eca5e7ba8f69"
|
|
45
45
|
}
|
|
@@ -1,20 +1,23 @@
|
|
|
1
1
|
import { PEMToBinary } from '@sphereon/ssi-sdk-ext.x509-utils'
|
|
2
2
|
import { IKey, ManagedKeyInfo, MinimalImportableKey, TKeyType } from '@veramo/core'
|
|
3
3
|
import {
|
|
4
|
+
ExternalSscdSettings,
|
|
5
|
+
IMusapClient,
|
|
4
6
|
isSignatureAlgorithmType,
|
|
5
7
|
JWSAlgorithm,
|
|
6
8
|
KeyAlgorithm,
|
|
7
9
|
KeyAlgorithmType,
|
|
10
|
+
KeyAttribute,
|
|
8
11
|
KeyGenReq,
|
|
12
|
+
MusapClient,
|
|
9
13
|
MusapKey,
|
|
10
|
-
MusapModule,
|
|
11
|
-
MusapModuleType,
|
|
12
14
|
signatureAlgorithmFromKeyAlgorithm,
|
|
13
15
|
SignatureAlgorithmType,
|
|
16
|
+
SignatureAttribute,
|
|
14
17
|
SignatureFormat,
|
|
15
18
|
SignatureReq,
|
|
19
|
+
SscdType,
|
|
16
20
|
} from '@sphereon/musap-react-native'
|
|
17
|
-
import { KeyAttribute, SscdType } from '@sphereon/musap-react-native'
|
|
18
21
|
import { AbstractKeyManagementSystem } from '@veramo/key-manager'
|
|
19
22
|
import { TextDecoder } from 'text-encoding'
|
|
20
23
|
import { Loggers } from '@sphereon/ssi-types'
|
|
@@ -31,15 +34,29 @@ import {
|
|
|
31
34
|
export const logger = Loggers.DEFAULT.get('sphereon:musap-rn-kms')
|
|
32
35
|
|
|
33
36
|
export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
34
|
-
private
|
|
35
|
-
private sscdType: SscdType
|
|
36
|
-
|
|
37
|
-
|
|
37
|
+
private musapClient: IMusapClient
|
|
38
|
+
private readonly sscdType: SscdType
|
|
39
|
+
private readonly sscdId: string
|
|
40
|
+
private readonly defaultKeyAttributes: Record<string, string> | undefined
|
|
41
|
+
private readonly defaultSignAttributes: Record<string, string> | undefined
|
|
42
|
+
|
|
43
|
+
constructor(sscdType?: SscdType, sscdId?: string, opts?: {
|
|
44
|
+
externalSscdSettings?: ExternalSscdSettings,
|
|
45
|
+
defaultKeyAttributes?: Record<string, string>,
|
|
46
|
+
defaultSignAttributes?: Record<string, string>
|
|
47
|
+
}) {
|
|
38
48
|
super()
|
|
39
49
|
try {
|
|
40
|
-
this.
|
|
50
|
+
this.musapClient = MusapClient
|
|
41
51
|
this.sscdType = sscdType ? sscdType : 'TEE'
|
|
42
|
-
this.
|
|
52
|
+
this.sscdId = sscdId ?? this.sscdType
|
|
53
|
+
this.defaultKeyAttributes = opts?.defaultKeyAttributes
|
|
54
|
+
this.defaultSignAttributes = opts?.defaultSignAttributes
|
|
55
|
+
|
|
56
|
+
const enabledSscds = this.musapClient.listEnabledSscds()
|
|
57
|
+
if (!enabledSscds.some(value => value.sscdId == sscdId)) {
|
|
58
|
+
this.musapClient.enableSscd(this.sscdType, this.sscdId, opts?.externalSscdSettings)
|
|
59
|
+
}
|
|
43
60
|
} catch (e) {
|
|
44
61
|
console.error('enableSscd', e)
|
|
45
62
|
throw Error('enableSscd failed')
|
|
@@ -47,7 +64,7 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
47
64
|
}
|
|
48
65
|
|
|
49
66
|
async listKeys(): Promise<ManagedKeyInfo[]> {
|
|
50
|
-
const keysJson: MusapKey[] = (
|
|
67
|
+
const keysJson: MusapKey[] = (this.musapClient.listKeys()) as MusapKey[]
|
|
51
68
|
return keysJson.map((key) => this.asMusapKeyInfo(key))
|
|
52
69
|
}
|
|
53
70
|
|
|
@@ -56,20 +73,31 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
56
73
|
if (meta === undefined || !('keyAlias' in meta)) {
|
|
57
74
|
return Promise.reject(Error('a unique keyAlias field is required for MUSAP'))
|
|
58
75
|
}
|
|
76
|
+
|
|
77
|
+
if (this.sscdType == 'EXTERNAL') {
|
|
78
|
+
const existingKeys: MusapKey[] = (this.musapClient.listKeys()) as MusapKey[]
|
|
79
|
+
const extKey = existingKeys.find(musapKey => musapKey.sscdType as string === 'External Signature') // FIXME returning does not match SscdType enum
|
|
80
|
+
if (extKey) {
|
|
81
|
+
const managedKeyInfo = this.asMusapKeyInfo(extKey)
|
|
82
|
+
managedKeyInfo.type = 'Secp256r1' // FIXME MUSAP announces key as rsa2k, but it's actually EC
|
|
83
|
+
return managedKeyInfo
|
|
84
|
+
}
|
|
85
|
+
return Promise.reject(Error(`No external key was bound yet for sscd ${this.sscdId}`))
|
|
86
|
+
}
|
|
59
87
|
|
|
60
88
|
const keyGenReq = {
|
|
61
89
|
keyAlgorithm: this.mapKeyTypeToAlgorithmType(type),
|
|
62
90
|
keyUsage: 'keyUsage' in meta ? (meta.keyUsage as string) : 'sign',
|
|
63
91
|
keyAlias: meta.keyAlias as string,
|
|
64
|
-
attributes: 'attributes' in meta ?
|
|
92
|
+
attributes: this.recordToKeyAttributes({ ...this.defaultKeyAttributes, ...('attributes' in meta ? meta.attributes : {}) }),
|
|
65
93
|
role: 'role' in meta ? (meta.role as string) : 'administrator',
|
|
66
94
|
} satisfies KeyGenReq
|
|
67
95
|
|
|
68
96
|
try {
|
|
69
|
-
const generatedKeyUri = await this.
|
|
97
|
+
const generatedKeyUri = await this.musapClient.generateKey(this.sscdType, keyGenReq)
|
|
70
98
|
if (generatedKeyUri) {
|
|
71
99
|
logger.debug('Generated key:', generatedKeyUri)
|
|
72
|
-
const key =
|
|
100
|
+
const key = this.musapClient.getKeyByUri(generatedKeyUri)
|
|
73
101
|
return this.asMusapKeyInfo(key)
|
|
74
102
|
} else {
|
|
75
103
|
return Promise.reject(new Error('Failed to generate key. No key URI'))
|
|
@@ -108,7 +136,7 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
108
136
|
|
|
109
137
|
async deleteKey({ kid }: { kid: string }): Promise<boolean> {
|
|
110
138
|
try {
|
|
111
|
-
this.
|
|
139
|
+
void this.musapClient.removeKey(kid)
|
|
112
140
|
return true
|
|
113
141
|
} catch (error) {
|
|
114
142
|
console.warn('Failed to delete key:', error)
|
|
@@ -129,14 +157,19 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
129
157
|
return signatureAlgorithmFromKeyAlgorithm(providedAlgorithm as JWSAlgorithm)
|
|
130
158
|
}
|
|
131
159
|
|
|
132
|
-
async sign(args: {
|
|
160
|
+
async sign(args: {
|
|
161
|
+
keyRef: Pick<IKey, 'kid'>;
|
|
162
|
+
algorithm?: string;
|
|
163
|
+
data: Uint8Array;
|
|
164
|
+
[x: string]: any
|
|
165
|
+
}): Promise<string> {
|
|
133
166
|
if (!args.keyRef) {
|
|
134
167
|
throw new Error('key_not_found: No key ref provided')
|
|
135
168
|
}
|
|
136
169
|
|
|
137
170
|
const data = new TextDecoder().decode(args.data as Uint8Array)
|
|
138
171
|
|
|
139
|
-
const key: MusapKey = this.
|
|
172
|
+
const key: MusapKey = this.musapClient.getKeyById(args.keyRef.kid) as MusapKey
|
|
140
173
|
const signatureReq: SignatureReq = {
|
|
141
174
|
keyUri: key.keyUri,
|
|
142
175
|
data,
|
|
@@ -144,9 +177,9 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
144
177
|
displayText: args.displayText,
|
|
145
178
|
transId: args.transId,
|
|
146
179
|
format: (args.format as SignatureFormat) ?? 'RAW',
|
|
147
|
-
attributes: args.attributes,
|
|
180
|
+
attributes: this.recordToSignatureAttributes({ ...this.defaultSignAttributes, ...args.attributes }),
|
|
148
181
|
}
|
|
149
|
-
return this.
|
|
182
|
+
return this.musapClient.sign(signatureReq)
|
|
150
183
|
}
|
|
151
184
|
|
|
152
185
|
async importKey(args: Omit<MinimalImportableKey, 'kms'> & { privateKeyPEM?: string }): Promise<ManagedKeyInfo> {
|
|
@@ -176,4 +209,24 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
176
209
|
sharedSecret(args: { myKeyRef: Pick<IKey, 'kid'>; theirKey: Pick<IKey, 'publicKeyHex' | 'type'> }): Promise<string> {
|
|
177
210
|
throw new Error('Not supported.')
|
|
178
211
|
}
|
|
212
|
+
|
|
213
|
+
private recordToKeyAttributes(record?: Record<string, string>): KeyAttribute[] {
|
|
214
|
+
if (!record) {
|
|
215
|
+
return []
|
|
216
|
+
}
|
|
217
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
218
|
+
name: key,
|
|
219
|
+
value,
|
|
220
|
+
}))
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
private recordToSignatureAttributes(record?: Record<string, string>): SignatureAttribute[] {
|
|
224
|
+
if (!record) {
|
|
225
|
+
return []
|
|
226
|
+
}
|
|
227
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
228
|
+
name: key,
|
|
229
|
+
value,
|
|
230
|
+
}))
|
|
231
|
+
}
|
|
179
232
|
}
|