@sphereon/ssi-sdk-ext.kms-musap-rn 0.26.1-feature.SPRIND.116.7 → 0.26.1-feature.SPRIND.124.esim.28
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;IA6BtF,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
|
}
|
|
@@ -81,14 +87,14 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
81
87
|
keyAlgorithm: this.mapKeyTypeToAlgorithmType(type),
|
|
82
88
|
keyUsage: 'keyUsage' in meta ? meta.keyUsage : 'sign',
|
|
83
89
|
keyAlias: meta.keyAlias,
|
|
84
|
-
attributes: 'attributes' in meta ? meta.attributes :
|
|
90
|
+
attributes: this.recordToKeyAttributes(Object.assign(Object.assign({}, this.defaultKeyAttributes), ('attributes' in meta ? meta.attributes : {}))),
|
|
85
91
|
role: 'role' in meta ? meta.role : 'administrator',
|
|
86
92
|
};
|
|
87
93
|
try {
|
|
88
|
-
const generatedKeyUri = yield this.
|
|
94
|
+
const generatedKeyUri = yield this.musapClient.generateKey(this.sscdType, keyGenReq);
|
|
89
95
|
if (generatedKeyUri) {
|
|
90
96
|
exports.logger.debug('Generated key:', generatedKeyUri);
|
|
91
|
-
const key =
|
|
97
|
+
const key = this.musapClient.getKeyByUri(generatedKeyUri);
|
|
92
98
|
return this.asMusapKeyInfo(key);
|
|
93
99
|
}
|
|
94
100
|
else {
|
|
@@ -104,7 +110,7 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
104
110
|
deleteKey(_a) {
|
|
105
111
|
return __awaiter(this, arguments, void 0, function* ({ kid }) {
|
|
106
112
|
try {
|
|
107
|
-
this.
|
|
113
|
+
void this.musapClient.removeKey(kid);
|
|
108
114
|
return true;
|
|
109
115
|
}
|
|
110
116
|
catch (error) {
|
|
@@ -130,7 +136,7 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
130
136
|
throw new Error('key_not_found: No key ref provided');
|
|
131
137
|
}
|
|
132
138
|
const data = new text_encoding_1.TextDecoder().decode(args.data);
|
|
133
|
-
const key = this.
|
|
139
|
+
const key = this.musapClient.getKeyById(args.keyRef.kid);
|
|
134
140
|
const signatureReq = {
|
|
135
141
|
keyUri: key.keyUri,
|
|
136
142
|
data,
|
|
@@ -138,9 +144,9 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
138
144
|
displayText: args.displayText,
|
|
139
145
|
transId: args.transId,
|
|
140
146
|
format: (_a = args.format) !== null && _a !== void 0 ? _a : 'RAW',
|
|
141
|
-
attributes: args.attributes,
|
|
147
|
+
attributes: this.recordToSignatureAttributes(Object.assign(Object.assign({}, this.defaultSignAttributes), args.attributes)),
|
|
142
148
|
};
|
|
143
|
-
return this.
|
|
149
|
+
return this.musapClient.sign(signatureReq);
|
|
144
150
|
});
|
|
145
151
|
}
|
|
146
152
|
importKey(args) {
|
|
@@ -169,6 +175,24 @@ class MusapKeyManagementSystem extends key_manager_1.AbstractKeyManagementSystem
|
|
|
169
175
|
sharedSecret(args) {
|
|
170
176
|
throw new Error('Not supported.');
|
|
171
177
|
}
|
|
178
|
+
recordToKeyAttributes(record) {
|
|
179
|
+
if (!record) {
|
|
180
|
+
return [];
|
|
181
|
+
}
|
|
182
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
183
|
+
name: key,
|
|
184
|
+
value,
|
|
185
|
+
}));
|
|
186
|
+
}
|
|
187
|
+
recordToSignatureAttributes(record) {
|
|
188
|
+
if (!record) {
|
|
189
|
+
return [];
|
|
190
|
+
}
|
|
191
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
192
|
+
name: key,
|
|
193
|
+
value,
|
|
194
|
+
}));
|
|
195
|
+
}
|
|
172
196
|
}
|
|
173
197
|
exports.MusapKeyManagementSystem = MusapKeyManagementSystem;
|
|
174
198
|
//# 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;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AAG,CAAC,CAAC,CAAC,GAAG,EAAE,KAAK,CAAC,EAAE,EAAE,CAAC,CAAC;YACnD,IAAI,EAAE,GAAG;YACT,KAAK;SACN,CAAC,CAAC,CAAA;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;AAzLD,4DAyLC"}
|
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.28+14a58a4",
|
|
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.28+14a58a4",
|
|
15
|
+
"@sphereon/ssi-sdk-ext.x509-utils": "0.26.1-feature.SPRIND.124.esim.28+14a58a4",
|
|
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": "14a58a4cde69c964f85ac741a1bd4410dc0ecc84"
|
|
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
|
|
|
@@ -61,15 +78,15 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
61
78
|
keyAlgorithm: this.mapKeyTypeToAlgorithmType(type),
|
|
62
79
|
keyUsage: 'keyUsage' in meta ? (meta.keyUsage as string) : 'sign',
|
|
63
80
|
keyAlias: meta.keyAlias as string,
|
|
64
|
-
attributes: 'attributes' in meta ?
|
|
81
|
+
attributes: this.recordToKeyAttributes({ ...this.defaultKeyAttributes, ...('attributes' in meta ? meta.attributes : {}) }),
|
|
65
82
|
role: 'role' in meta ? (meta.role as string) : 'administrator',
|
|
66
83
|
} satisfies KeyGenReq
|
|
67
84
|
|
|
68
85
|
try {
|
|
69
|
-
const generatedKeyUri = await this.
|
|
86
|
+
const generatedKeyUri = await this.musapClient.generateKey(this.sscdType, keyGenReq)
|
|
70
87
|
if (generatedKeyUri) {
|
|
71
88
|
logger.debug('Generated key:', generatedKeyUri)
|
|
72
|
-
const key =
|
|
89
|
+
const key = this.musapClient.getKeyByUri(generatedKeyUri)
|
|
73
90
|
return this.asMusapKeyInfo(key)
|
|
74
91
|
} else {
|
|
75
92
|
return Promise.reject(new Error('Failed to generate key. No key URI'))
|
|
@@ -108,7 +125,7 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
108
125
|
|
|
109
126
|
async deleteKey({ kid }: { kid: string }): Promise<boolean> {
|
|
110
127
|
try {
|
|
111
|
-
this.
|
|
128
|
+
void this.musapClient.removeKey(kid)
|
|
112
129
|
return true
|
|
113
130
|
} catch (error) {
|
|
114
131
|
console.warn('Failed to delete key:', error)
|
|
@@ -129,14 +146,19 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
129
146
|
return signatureAlgorithmFromKeyAlgorithm(providedAlgorithm as JWSAlgorithm)
|
|
130
147
|
}
|
|
131
148
|
|
|
132
|
-
async sign(args: {
|
|
149
|
+
async sign(args: {
|
|
150
|
+
keyRef: Pick<IKey, 'kid'>;
|
|
151
|
+
algorithm?: string;
|
|
152
|
+
data: Uint8Array;
|
|
153
|
+
[x: string]: any
|
|
154
|
+
}): Promise<string> {
|
|
133
155
|
if (!args.keyRef) {
|
|
134
156
|
throw new Error('key_not_found: No key ref provided')
|
|
135
157
|
}
|
|
136
158
|
|
|
137
159
|
const data = new TextDecoder().decode(args.data as Uint8Array)
|
|
138
160
|
|
|
139
|
-
const key: MusapKey = this.
|
|
161
|
+
const key: MusapKey = this.musapClient.getKeyById(args.keyRef.kid) as MusapKey
|
|
140
162
|
const signatureReq: SignatureReq = {
|
|
141
163
|
keyUri: key.keyUri,
|
|
142
164
|
data,
|
|
@@ -144,9 +166,9 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
144
166
|
displayText: args.displayText,
|
|
145
167
|
transId: args.transId,
|
|
146
168
|
format: (args.format as SignatureFormat) ?? 'RAW',
|
|
147
|
-
attributes: args.attributes,
|
|
169
|
+
attributes: this.recordToSignatureAttributes({ ...this.defaultSignAttributes, ...args.attributes }),
|
|
148
170
|
}
|
|
149
|
-
return this.
|
|
171
|
+
return this.musapClient.sign(signatureReq)
|
|
150
172
|
}
|
|
151
173
|
|
|
152
174
|
async importKey(args: Omit<MinimalImportableKey, 'kms'> & { privateKeyPEM?: string }): Promise<ManagedKeyInfo> {
|
|
@@ -176,4 +198,24 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
|
|
|
176
198
|
sharedSecret(args: { myKeyRef: Pick<IKey, 'kid'>; theirKey: Pick<IKey, 'publicKeyHex' | 'type'> }): Promise<string> {
|
|
177
199
|
throw new Error('Not supported.')
|
|
178
200
|
}
|
|
201
|
+
|
|
202
|
+
private recordToKeyAttributes(record?: Record<string, string>): KeyAttribute[] {
|
|
203
|
+
if (!record) {
|
|
204
|
+
return []
|
|
205
|
+
}
|
|
206
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
207
|
+
name: key,
|
|
208
|
+
value,
|
|
209
|
+
}))
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
private recordToSignatureAttributes(record?: Record<string, string>): SignatureAttribute[] {
|
|
213
|
+
if (!record) {
|
|
214
|
+
return []
|
|
215
|
+
}
|
|
216
|
+
return Object.entries(record).map(([key, value]) => ({
|
|
217
|
+
name: key,
|
|
218
|
+
value,
|
|
219
|
+
}))
|
|
220
|
+
}
|
|
179
221
|
}
|