@sphereon/ssi-sdk-ext.key-utils 0.28.0 → 0.28.1-feature.esm.cjs.11
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +1219 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +209 -0
- package/dist/index.d.ts +206 -9
- package/dist/index.js +1217 -26
- package/dist/index.js.map +1 -1
- package/package.json +25 -13
- package/src/conversion.ts +2 -0
- package/src/digest-methods.ts +12 -11
- package/src/functions.ts +35 -27
- package/src/jwk-jcs.ts +3 -1
- package/dist/conversion.d.ts +0 -12
- package/dist/conversion.d.ts.map +0 -1
- package/dist/conversion.js +0 -206
- package/dist/conversion.js.map +0 -1
- package/dist/digest-methods.d.ts +0 -11
- package/dist/digest-methods.d.ts.map +0 -1
- package/dist/digest-methods.js +0 -106
- package/dist/digest-methods.js.map +0 -1
- package/dist/functions.d.ts +0 -100
- package/dist/functions.d.ts.map +0 -1
- package/dist/functions.js +0 -756
- package/dist/functions.js.map +0 -1
- package/dist/index.d.ts.map +0 -1
- package/dist/jwk-jcs.d.ts +0 -41
- package/dist/jwk-jcs.d.ts.map +0 -1
- package/dist/jwk-jcs.js +0 -182
- package/dist/jwk-jcs.js.map +0 -1
- package/dist/types/index.d.ts +0 -2
- package/dist/types/index.d.ts.map +0 -1
- package/dist/types/index.js +0 -18
- package/dist/types/index.js.map +0 -1
- package/dist/types/key-util-types.d.ts +0 -46
- package/dist/types/key-util-types.d.ts.map +0 -1
- package/dist/types/key-util-types.js +0 -19
- package/dist/types/key-util-types.js.map +0 -1
package/dist/index.cjs
ADDED
|
@@ -0,0 +1,1219 @@
|
|
|
1
|
+
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } } function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }var __defProp = Object.defineProperty;
|
|
2
|
+
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
+
|
|
4
|
+
// src/functions.ts
|
|
5
|
+
var _random = require('@ethersproject/random');
|
|
6
|
+
var _bls12381 = require('@noble/curves/bls12-381');
|
|
7
|
+
var _ed25519 = require('@noble/curves/ed25519');
|
|
8
|
+
var _p256 = require('@noble/curves/p256');
|
|
9
|
+
var _p384 = require('@noble/curves/p384');
|
|
10
|
+
var _p521 = require('@noble/curves/p521');
|
|
11
|
+
var _secp256k1 = require('@noble/curves/secp256k1');
|
|
12
|
+
var _sha256 = require('@noble/hashes/sha256');
|
|
13
|
+
var _sha512 = require('@noble/hashes/sha512');
|
|
14
|
+
var _ssisdkextx509utils = require('@sphereon/ssi-sdk-ext.x509-utils');
|
|
15
|
+
var _ssitypes = require('@sphereon/ssi-types');
|
|
16
|
+
var _ed255193 = require('@stablelib/ed25519');
|
|
17
|
+
var _debug = require('debug'); var _debug2 = _interopRequireDefault(_debug);
|
|
18
|
+
var _elliptic = require('elliptic'); var _elliptic2 = _interopRequireDefault(_elliptic);
|
|
19
|
+
var _rsajs = require('micro-rsa-dsa-dh/rsa.js'); var rsa = _interopRequireWildcard(_rsajs);
|
|
20
|
+
var _uint8arrays = require('uint8arrays'); var u8a2 = _interopRequireWildcard(_uint8arrays); var u8a = _interopRequireWildcard(_uint8arrays);
|
|
21
|
+
|
|
22
|
+
// src/digest-methods.ts
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
var { fromString, toString, SupportedEncodings } = u8a;
|
|
27
|
+
var digestMethodParams = /* @__PURE__ */ __name((hashAlgorithm) => {
|
|
28
|
+
if (hashAlgorithm === "SHA-256") {
|
|
29
|
+
return {
|
|
30
|
+
hashAlgorithm: "SHA-256",
|
|
31
|
+
digestMethod: sha256DigestMethod,
|
|
32
|
+
hash: _sha256.sha256
|
|
33
|
+
};
|
|
34
|
+
} else if (hashAlgorithm === "SHA-384") {
|
|
35
|
+
return {
|
|
36
|
+
hashAlgorithm: "SHA-384",
|
|
37
|
+
digestMethod: sha384DigestMethod,
|
|
38
|
+
hash: _sha512.sha384
|
|
39
|
+
};
|
|
40
|
+
} else {
|
|
41
|
+
return {
|
|
42
|
+
hashAlgorithm: "SHA-512",
|
|
43
|
+
digestMethod: sha512DigestMethod,
|
|
44
|
+
hash: _sha512.sha512
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}, "digestMethodParams");
|
|
48
|
+
var shaHasher = /* @__PURE__ */ __name((input, alg) => {
|
|
49
|
+
const hashAlgorithm = alg.includes("384") ? "SHA-384" : alg.includes("512") ? "SHA-512" : "SHA-256";
|
|
50
|
+
return digestMethodParams(hashAlgorithm).hash(typeof input === "string" ? fromString(input, "utf-8") : new Uint8Array(input));
|
|
51
|
+
}, "shaHasher");
|
|
52
|
+
var sha256DigestMethod = /* @__PURE__ */ __name((input, encoding = "base16") => {
|
|
53
|
+
return toString(_sha256.sha256.call(void 0, fromString(input, "utf-8")), encoding);
|
|
54
|
+
}, "sha256DigestMethod");
|
|
55
|
+
var sha384DigestMethod = /* @__PURE__ */ __name((input, encoding = "base16") => {
|
|
56
|
+
return toString(_sha512.sha384.call(void 0, fromString(input, "utf-8")), encoding);
|
|
57
|
+
}, "sha384DigestMethod");
|
|
58
|
+
var sha512DigestMethod = /* @__PURE__ */ __name((input, encoding = "base16") => {
|
|
59
|
+
return toString(_sha512.sha512.call(void 0, fromString(input, "utf-8")), encoding);
|
|
60
|
+
}, "sha512DigestMethod");
|
|
61
|
+
|
|
62
|
+
// src/jwk-jcs.ts
|
|
63
|
+
var _webencoding = require('web-encoding');
|
|
64
|
+
var textEncoder = new (0, _webencoding.TextEncoder)();
|
|
65
|
+
var textDecoder = new (0, _webencoding.TextDecoder)();
|
|
66
|
+
function check(value, description, optional = false) {
|
|
67
|
+
if (optional && !value) {
|
|
68
|
+
return;
|
|
69
|
+
}
|
|
70
|
+
if (typeof value !== "string" || !value) {
|
|
71
|
+
throw new Error(`${description} missing or invalid`);
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
__name(check, "check");
|
|
75
|
+
function assertObject(value) {
|
|
76
|
+
if (!value || typeof value !== "object") {
|
|
77
|
+
throw new Error("Value must be an object");
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
__name(assertObject, "assertObject");
|
|
81
|
+
function validateJwk(jwk, opts) {
|
|
82
|
+
assertObject(jwk);
|
|
83
|
+
const { crvOptional = false } = _nullishCoalesce(opts, () => ( {}));
|
|
84
|
+
check(jwk.kty, '"kty" (Key Type) Parameter', false);
|
|
85
|
+
switch (jwk.kty) {
|
|
86
|
+
/**
|
|
87
|
+
* @see https://www.rfc-editor.org/rfc/rfc7518#section-6.2.1
|
|
88
|
+
*/
|
|
89
|
+
case "EC":
|
|
90
|
+
check(jwk.crv, '"crv" (Curve) Parameter', crvOptional);
|
|
91
|
+
check(jwk.x, '"x" (X Coordinate) Parameter');
|
|
92
|
+
check(jwk.y, '"y" (Y Coordinate) Parameter');
|
|
93
|
+
break;
|
|
94
|
+
/**
|
|
95
|
+
* @see https://www.rfc-editor.org/rfc/rfc8037#section-2
|
|
96
|
+
*/
|
|
97
|
+
case "OKP":
|
|
98
|
+
check(jwk.crv, '"crv" (Subtype of Key Pair) Parameter', crvOptional);
|
|
99
|
+
check(jwk.x, '"x" (Public Key) Parameter');
|
|
100
|
+
break;
|
|
101
|
+
/**
|
|
102
|
+
* @see https://www.rfc-editor.org/rfc/rfc7518#section-6.3.1
|
|
103
|
+
*/
|
|
104
|
+
case "RSA":
|
|
105
|
+
check(jwk.e, '"e" (Exponent) Parameter');
|
|
106
|
+
check(jwk.n, '"n" (Modulus) Parameter');
|
|
107
|
+
break;
|
|
108
|
+
default:
|
|
109
|
+
throw new Error('"kty" (Key Type) Parameter missing or unsupported');
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
__name(validateJwk, "validateJwk");
|
|
113
|
+
function minimalJwk(jwk) {
|
|
114
|
+
switch (jwk.kty) {
|
|
115
|
+
case "EC":
|
|
116
|
+
return {
|
|
117
|
+
...jwk.crv && {
|
|
118
|
+
crv: jwk.crv
|
|
119
|
+
},
|
|
120
|
+
kty: jwk.kty,
|
|
121
|
+
x: jwk.x,
|
|
122
|
+
y: jwk.y
|
|
123
|
+
};
|
|
124
|
+
case "OKP":
|
|
125
|
+
return {
|
|
126
|
+
...jwk.crv && {
|
|
127
|
+
crv: jwk.crv
|
|
128
|
+
},
|
|
129
|
+
kty: jwk.kty,
|
|
130
|
+
x: jwk.x
|
|
131
|
+
};
|
|
132
|
+
case "RSA":
|
|
133
|
+
return {
|
|
134
|
+
e: jwk.e,
|
|
135
|
+
kty: jwk.kty,
|
|
136
|
+
n: jwk.n
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
throw Error(`Unsupported key type (kty) provided: ${jwk.kty}`);
|
|
140
|
+
}
|
|
141
|
+
__name(minimalJwk, "minimalJwk");
|
|
142
|
+
function jwkJcsEncode(jwk) {
|
|
143
|
+
validateJwk(jwk);
|
|
144
|
+
const strippedJwk = minimalJwk(jwk);
|
|
145
|
+
return textEncoder.encode(jcsCanonicalize(strippedJwk));
|
|
146
|
+
}
|
|
147
|
+
__name(jwkJcsEncode, "jwkJcsEncode");
|
|
148
|
+
function jwkJcsDecode(bytes) {
|
|
149
|
+
const jwk = JSON.parse(textDecoder.decode(bytes));
|
|
150
|
+
validateJwk(jwk);
|
|
151
|
+
if (JSON.stringify(jwk) !== jcsCanonicalize(minimalJwk(jwk))) {
|
|
152
|
+
throw new Error("The JWK embedded in the DID is not correctly formatted");
|
|
153
|
+
}
|
|
154
|
+
return jwk;
|
|
155
|
+
}
|
|
156
|
+
__name(jwkJcsDecode, "jwkJcsDecode");
|
|
157
|
+
function jcsCanonicalize(object) {
|
|
158
|
+
let buffer = "";
|
|
159
|
+
serialize(object);
|
|
160
|
+
return buffer;
|
|
161
|
+
function serialize(object2) {
|
|
162
|
+
if (object2 === null || typeof object2 !== "object" || object2.toJSON != null) {
|
|
163
|
+
buffer += JSON.stringify(object2);
|
|
164
|
+
} else if (Array.isArray(object2)) {
|
|
165
|
+
buffer += "[";
|
|
166
|
+
let next = false;
|
|
167
|
+
object2.forEach((element) => {
|
|
168
|
+
if (next) {
|
|
169
|
+
buffer += ",";
|
|
170
|
+
}
|
|
171
|
+
next = true;
|
|
172
|
+
serialize(element);
|
|
173
|
+
});
|
|
174
|
+
buffer += "]";
|
|
175
|
+
} else {
|
|
176
|
+
buffer += "{";
|
|
177
|
+
let next = false;
|
|
178
|
+
Object.keys(object2).sort().forEach((property) => {
|
|
179
|
+
if (next) {
|
|
180
|
+
buffer += ",";
|
|
181
|
+
}
|
|
182
|
+
next = true;
|
|
183
|
+
buffer += JSON.stringify(property);
|
|
184
|
+
buffer += ":";
|
|
185
|
+
serialize(object2[property]);
|
|
186
|
+
});
|
|
187
|
+
buffer += "}";
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
__name(serialize, "serialize");
|
|
191
|
+
}
|
|
192
|
+
__name(jcsCanonicalize, "jcsCanonicalize");
|
|
193
|
+
|
|
194
|
+
// src/types/key-util-types.ts
|
|
195
|
+
var JWK_JCS_PUB_NAME = "jwk_jcs-pub";
|
|
196
|
+
var JWK_JCS_PUB_PREFIX = 60241;
|
|
197
|
+
var Key = /* @__PURE__ */ function(Key2) {
|
|
198
|
+
Key2["Ed25519"] = "Ed25519";
|
|
199
|
+
Key2["Secp256k1"] = "Secp256k1";
|
|
200
|
+
Key2["Secp256r1"] = "Secp256r1";
|
|
201
|
+
return Key2;
|
|
202
|
+
}({});
|
|
203
|
+
var JwkKeyUse = /* @__PURE__ */ function(JwkKeyUse2) {
|
|
204
|
+
JwkKeyUse2["Encryption"] = "enc";
|
|
205
|
+
JwkKeyUse2["Signature"] = "sig";
|
|
206
|
+
return JwkKeyUse2;
|
|
207
|
+
}({});
|
|
208
|
+
var SIG_KEY_ALGS = [
|
|
209
|
+
"ES256",
|
|
210
|
+
"ES384",
|
|
211
|
+
"ES512",
|
|
212
|
+
"EdDSA",
|
|
213
|
+
"ES256K",
|
|
214
|
+
"Ed25519",
|
|
215
|
+
"Secp256k1",
|
|
216
|
+
"Secp256r1",
|
|
217
|
+
"Bls12381G1",
|
|
218
|
+
"Bls12381G2"
|
|
219
|
+
];
|
|
220
|
+
var ENC_KEY_ALGS = [
|
|
221
|
+
"X25519",
|
|
222
|
+
"ECDH_ES_A256KW",
|
|
223
|
+
"RSA_OAEP_256"
|
|
224
|
+
];
|
|
225
|
+
|
|
226
|
+
// src/functions.ts
|
|
227
|
+
var { fromString: fromString2, toString: toString2 } = u8a2;
|
|
228
|
+
var logger = _ssitypes.Loggers.DEFAULT.get("sphereon:key-utils");
|
|
229
|
+
var getKms = /* @__PURE__ */ __name(async (context, kms) => {
|
|
230
|
+
if (kms) {
|
|
231
|
+
return kms;
|
|
232
|
+
}
|
|
233
|
+
if (!context.agent.availableMethods().includes("keyManagerGetDefaultKeyManagementSystem")) {
|
|
234
|
+
throw Error("Cannot determine default KMS if not provided and a non Sphereon Key Manager is being used");
|
|
235
|
+
}
|
|
236
|
+
return context.agent.keyManagerGetDefaultKeyManagementSystem();
|
|
237
|
+
}, "getKms");
|
|
238
|
+
var generatePrivateKeyHex = /* @__PURE__ */ __name(async (type) => {
|
|
239
|
+
switch (type) {
|
|
240
|
+
case "Ed25519": {
|
|
241
|
+
const keyPairEd25519 = _ed255193.generateKeyPair.call(void 0, );
|
|
242
|
+
return toString2(keyPairEd25519.secretKey, "base16");
|
|
243
|
+
}
|
|
244
|
+
// The Secp256 types use the same method to generate the key
|
|
245
|
+
case "Secp256r1":
|
|
246
|
+
case "Secp256k1": {
|
|
247
|
+
const privateBytes = _random.randomBytes.call(void 0, 32);
|
|
248
|
+
return toString2(privateBytes, "base16");
|
|
249
|
+
}
|
|
250
|
+
case "RSA": {
|
|
251
|
+
const pem = await _ssisdkextx509utils.generateRSAKeyAsPEM.call(void 0, "RSA-PSS", "SHA-256", 2048);
|
|
252
|
+
return _ssisdkextx509utils.privateKeyHexFromPEM.call(void 0, pem);
|
|
253
|
+
}
|
|
254
|
+
default:
|
|
255
|
+
throw Error(`not_supported: Key type ${type} not yet supported for this did:jwk implementation`);
|
|
256
|
+
}
|
|
257
|
+
}, "generatePrivateKeyHex");
|
|
258
|
+
var keyMetaAlgorithmsFromKeyType = /* @__PURE__ */ __name((type) => {
|
|
259
|
+
switch (type) {
|
|
260
|
+
case "Ed25519":
|
|
261
|
+
return [
|
|
262
|
+
"Ed25519",
|
|
263
|
+
"EdDSA"
|
|
264
|
+
];
|
|
265
|
+
case "ES256K":
|
|
266
|
+
case "Secp256k1":
|
|
267
|
+
return [
|
|
268
|
+
"ES256K",
|
|
269
|
+
"ES256K-R",
|
|
270
|
+
"eth_signTransaction",
|
|
271
|
+
"eth_signTypedData",
|
|
272
|
+
"eth_signMessage",
|
|
273
|
+
"eth_rawSign"
|
|
274
|
+
];
|
|
275
|
+
case "Secp256r1":
|
|
276
|
+
return [
|
|
277
|
+
"ES256"
|
|
278
|
+
];
|
|
279
|
+
case "X25519":
|
|
280
|
+
return [
|
|
281
|
+
"ECDH",
|
|
282
|
+
"ECDH-ES",
|
|
283
|
+
"ECDH-1PU"
|
|
284
|
+
];
|
|
285
|
+
case "RSA":
|
|
286
|
+
return [
|
|
287
|
+
"RS256",
|
|
288
|
+
"RS512",
|
|
289
|
+
"PS256",
|
|
290
|
+
"PS512"
|
|
291
|
+
];
|
|
292
|
+
}
|
|
293
|
+
return [
|
|
294
|
+
type
|
|
295
|
+
];
|
|
296
|
+
}, "keyMetaAlgorithmsFromKeyType");
|
|
297
|
+
async function importProvidedOrGeneratedKey(args, context) {
|
|
298
|
+
const type = _nullishCoalesce(_nullishCoalesce(_nullishCoalesce(_optionalChain([args, 'access', _ => _.options, 'optionalAccess', _2 => _2.type]), () => ( _optionalChain([args, 'access', _3 => _3.options, 'optionalAccess', _4 => _4.key, 'optionalAccess', _5 => _5.type]))), () => ( _optionalChain([args, 'access', _6 => _6.options, 'optionalAccess', _7 => _7.keyType]))), () => ( "Secp256r1"));
|
|
299
|
+
const key = _optionalChain([args, 'optionalAccess', _8 => _8.options, 'optionalAccess', _9 => _9.key]);
|
|
300
|
+
if (_optionalChain([args, 'access', _10 => _10.options, 'optionalAccess', _11 => _11.x509]) && key) {
|
|
301
|
+
key.meta = {
|
|
302
|
+
...key.meta,
|
|
303
|
+
x509: {
|
|
304
|
+
...args.options.x509,
|
|
305
|
+
..._optionalChain([key, 'access', _12 => _12.meta, 'optionalAccess', _13 => _13.x509])
|
|
306
|
+
}
|
|
307
|
+
};
|
|
308
|
+
}
|
|
309
|
+
if (args.options && _optionalChain([args, 'access', _14 => _14.options, 'optionalAccess', _15 => _15.use]) === JwkKeyUse.Encryption && !ENC_KEY_ALGS.includes(type)) {
|
|
310
|
+
throw new Error(`${type} keys are not valid for encryption`);
|
|
311
|
+
}
|
|
312
|
+
let privateKeyHex = void 0;
|
|
313
|
+
if (key) {
|
|
314
|
+
privateKeyHex = _nullishCoalesce(key.privateKeyHex, () => ( _optionalChain([key, 'access', _16 => _16.meta, 'optionalAccess', _17 => _17.x509, 'optionalAccess', _18 => _18.privateKeyHex])));
|
|
315
|
+
if ((!privateKeyHex || privateKeyHex.trim() === "") && _optionalChain([key, 'optionalAccess', _19 => _19.meta, 'optionalAccess', _20 => _20.x509, 'optionalAccess', _21 => _21.privateKeyPEM])) {
|
|
316
|
+
privateKeyHex = _ssisdkextx509utils.privateKeyHexFromPEM.call(void 0, key.meta.x509.privateKeyPEM);
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
if (privateKeyHex) {
|
|
320
|
+
return context.agent.keyManagerImport({
|
|
321
|
+
...key,
|
|
322
|
+
kms: args.kms,
|
|
323
|
+
type,
|
|
324
|
+
privateKeyHex
|
|
325
|
+
});
|
|
326
|
+
}
|
|
327
|
+
return context.agent.keyManagerCreate({
|
|
328
|
+
type,
|
|
329
|
+
kms: args.kms,
|
|
330
|
+
meta: {
|
|
331
|
+
..._optionalChain([key, 'optionalAccess', _22 => _22.meta]),
|
|
332
|
+
algorithms: keyMetaAlgorithmsFromKeyType(type),
|
|
333
|
+
keyAlias: args.alias
|
|
334
|
+
}
|
|
335
|
+
});
|
|
336
|
+
}
|
|
337
|
+
__name(importProvidedOrGeneratedKey, "importProvidedOrGeneratedKey");
|
|
338
|
+
var calculateJwkThumbprintForKey = /* @__PURE__ */ __name((args) => {
|
|
339
|
+
const { key } = args;
|
|
340
|
+
const jwk = key.publicKeyHex ? toJwk(key.publicKeyHex, key.type, {
|
|
341
|
+
key,
|
|
342
|
+
isPrivateKey: false
|
|
343
|
+
}) : "privateKeyHex" in key && key.privateKeyHex ? toJwk(key.privateKeyHex, key.type, {
|
|
344
|
+
isPrivateKey: true
|
|
345
|
+
}) : void 0;
|
|
346
|
+
if (!jwk) {
|
|
347
|
+
throw Error(`Could not determine jwk from key ${key.kid}`);
|
|
348
|
+
}
|
|
349
|
+
return calculateJwkThumbprint({
|
|
350
|
+
jwk,
|
|
351
|
+
digestAlgorithm: args.digestAlgorithm
|
|
352
|
+
});
|
|
353
|
+
}, "calculateJwkThumbprintForKey");
|
|
354
|
+
var assertJwkClaimPresent = /* @__PURE__ */ __name((value, description) => {
|
|
355
|
+
if (typeof value !== "string" || !value) {
|
|
356
|
+
throw new Error(`${description} missing or invalid`);
|
|
357
|
+
}
|
|
358
|
+
}, "assertJwkClaimPresent");
|
|
359
|
+
var toBase64url = /* @__PURE__ */ __name((input) => toString2(fromString2(input), "base64url"), "toBase64url");
|
|
360
|
+
var calculateJwkThumbprint = /* @__PURE__ */ __name((args) => {
|
|
361
|
+
const { digestAlgorithm = "sha256" } = args;
|
|
362
|
+
const jwk = sanitizedJwk(args.jwk);
|
|
363
|
+
let components;
|
|
364
|
+
switch (jwk.kty) {
|
|
365
|
+
case "EC":
|
|
366
|
+
assertJwkClaimPresent(jwk.crv, '"crv" (Curve) Parameter');
|
|
367
|
+
assertJwkClaimPresent(jwk.x, '"x" (X Coordinate) Parameter');
|
|
368
|
+
assertJwkClaimPresent(jwk.y, '"y" (Y Coordinate) Parameter');
|
|
369
|
+
components = {
|
|
370
|
+
crv: jwk.crv,
|
|
371
|
+
kty: jwk.kty,
|
|
372
|
+
x: jwk.x,
|
|
373
|
+
y: jwk.y
|
|
374
|
+
};
|
|
375
|
+
break;
|
|
376
|
+
case "OKP":
|
|
377
|
+
assertJwkClaimPresent(jwk.crv, '"crv" (Subtype of Key Pair) Parameter');
|
|
378
|
+
assertJwkClaimPresent(jwk.x, '"x" (Public Key) Parameter');
|
|
379
|
+
components = {
|
|
380
|
+
crv: jwk.crv,
|
|
381
|
+
kty: jwk.kty,
|
|
382
|
+
x: jwk.x
|
|
383
|
+
};
|
|
384
|
+
break;
|
|
385
|
+
case "RSA":
|
|
386
|
+
assertJwkClaimPresent(jwk.e, '"e" (Exponent) Parameter');
|
|
387
|
+
assertJwkClaimPresent(jwk.n, '"n" (Modulus) Parameter');
|
|
388
|
+
components = {
|
|
389
|
+
e: jwk.e,
|
|
390
|
+
kty: jwk.kty,
|
|
391
|
+
n: jwk.n
|
|
392
|
+
};
|
|
393
|
+
break;
|
|
394
|
+
case "oct":
|
|
395
|
+
assertJwkClaimPresent(jwk.k, '"k" (Key Value) Parameter');
|
|
396
|
+
components = {
|
|
397
|
+
k: jwk.k,
|
|
398
|
+
kty: jwk.kty
|
|
399
|
+
};
|
|
400
|
+
break;
|
|
401
|
+
default:
|
|
402
|
+
throw new Error('"kty" (Key Type) Parameter missing or unsupported');
|
|
403
|
+
}
|
|
404
|
+
const data = JSON.stringify(components);
|
|
405
|
+
return digestAlgorithm === "sha512" ? digestMethodParams("SHA-512").digestMethod(data, "base64url") : digestMethodParams("SHA-256").digestMethod(data, "base64url");
|
|
406
|
+
}, "calculateJwkThumbprint");
|
|
407
|
+
var toJwkFromKey = /* @__PURE__ */ __name((key, opts) => {
|
|
408
|
+
const isPrivateKey = "privateKeyHex" in key;
|
|
409
|
+
return toJwk(key.publicKeyHex, key.type, {
|
|
410
|
+
...opts,
|
|
411
|
+
key,
|
|
412
|
+
isPrivateKey
|
|
413
|
+
});
|
|
414
|
+
}, "toJwkFromKey");
|
|
415
|
+
var toJwk = /* @__PURE__ */ __name((publicKeyHex, type, opts) => {
|
|
416
|
+
const { key, noKidThumbprint = false } = _nullishCoalesce(opts, () => ( {}));
|
|
417
|
+
if (key && key.publicKeyHex !== publicKeyHex && _optionalChain([opts, 'optionalAccess', _23 => _23.isPrivateKey]) !== true) {
|
|
418
|
+
throw Error(`Provided key with id ${key.kid}, has a different public key hex ${key.publicKeyHex} than supplied public key ${publicKeyHex}`);
|
|
419
|
+
}
|
|
420
|
+
let jwk;
|
|
421
|
+
switch (type) {
|
|
422
|
+
case "Ed25519":
|
|
423
|
+
jwk = toEd25519OrX25519Jwk(publicKeyHex, {
|
|
424
|
+
...opts,
|
|
425
|
+
crv: _ssitypes.JoseCurve.Ed25519
|
|
426
|
+
});
|
|
427
|
+
break;
|
|
428
|
+
case "X25519":
|
|
429
|
+
jwk = toEd25519OrX25519Jwk(publicKeyHex, {
|
|
430
|
+
...opts,
|
|
431
|
+
crv: _ssitypes.JoseCurve.X25519
|
|
432
|
+
});
|
|
433
|
+
break;
|
|
434
|
+
case "Secp256k1":
|
|
435
|
+
jwk = toSecp256k1Jwk(publicKeyHex, opts);
|
|
436
|
+
break;
|
|
437
|
+
case "Secp256r1":
|
|
438
|
+
jwk = toSecp256r1Jwk(publicKeyHex, opts);
|
|
439
|
+
break;
|
|
440
|
+
case "RSA":
|
|
441
|
+
jwk = toRSAJwk(publicKeyHex, opts);
|
|
442
|
+
break;
|
|
443
|
+
default:
|
|
444
|
+
throw new Error(`not_supported: Key type ${type} not yet supported for this did:jwk implementation`);
|
|
445
|
+
}
|
|
446
|
+
if (!jwk.kid && !noKidThumbprint) {
|
|
447
|
+
jwk["kid"] = calculateJwkThumbprint({
|
|
448
|
+
jwk
|
|
449
|
+
});
|
|
450
|
+
}
|
|
451
|
+
return sanitizedJwk(jwk);
|
|
452
|
+
}, "toJwk");
|
|
453
|
+
var jwkToRawHexKey = /* @__PURE__ */ __name(async (jwk) => {
|
|
454
|
+
jwk = sanitizedJwk(jwk);
|
|
455
|
+
if (jwk.kty === "RSA") {
|
|
456
|
+
return rsaJwkToRawHexKey(jwk);
|
|
457
|
+
} else if (jwk.kty === "EC") {
|
|
458
|
+
return ecJwkToRawHexKey(jwk);
|
|
459
|
+
} else if (jwk.kty === "OKP") {
|
|
460
|
+
return okpJwkToRawHexKey(jwk);
|
|
461
|
+
} else if (jwk.kty === "oct") {
|
|
462
|
+
return octJwkToRawHexKey(jwk);
|
|
463
|
+
} else {
|
|
464
|
+
throw new Error(`Unsupported key type: ${jwk.kty}`);
|
|
465
|
+
}
|
|
466
|
+
}, "jwkToRawHexKey");
|
|
467
|
+
function rsaJwkToRawHexKey(jwk) {
|
|
468
|
+
jwk = sanitizedJwk(jwk);
|
|
469
|
+
if (!jwk.n || !jwk.e) {
|
|
470
|
+
throw new Error("RSA JWK must contain 'n' and 'e' properties.");
|
|
471
|
+
}
|
|
472
|
+
const modulus = fromString2(jwk.n.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), "base64url");
|
|
473
|
+
const exponent = fromString2(jwk.e.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), "base64url");
|
|
474
|
+
return toString2(modulus, "hex") + toString2(exponent, "hex");
|
|
475
|
+
}
|
|
476
|
+
__name(rsaJwkToRawHexKey, "rsaJwkToRawHexKey");
|
|
477
|
+
function ecJwkToRawHexKey(jwk) {
|
|
478
|
+
jwk = sanitizedJwk(jwk);
|
|
479
|
+
if (!jwk.x || !jwk.y) {
|
|
480
|
+
throw new Error("EC JWK must contain 'x' and 'y' properties.");
|
|
481
|
+
}
|
|
482
|
+
const x = fromString2(jwk.x.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), "base64url");
|
|
483
|
+
const y = fromString2(jwk.y.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), "base64url");
|
|
484
|
+
return "04" + toString2(x, "hex") + toString2(y, "hex");
|
|
485
|
+
}
|
|
486
|
+
__name(ecJwkToRawHexKey, "ecJwkToRawHexKey");
|
|
487
|
+
function okpJwkToRawHexKey(jwk) {
|
|
488
|
+
jwk = sanitizedJwk(jwk);
|
|
489
|
+
if (!jwk.x) {
|
|
490
|
+
throw new Error("OKP JWK must contain 'x' property.");
|
|
491
|
+
}
|
|
492
|
+
const x = fromString2(jwk.x.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), "base64url");
|
|
493
|
+
return toString2(x, "hex");
|
|
494
|
+
}
|
|
495
|
+
__name(okpJwkToRawHexKey, "okpJwkToRawHexKey");
|
|
496
|
+
function octJwkToRawHexKey(jwk) {
|
|
497
|
+
jwk = sanitizedJwk(jwk);
|
|
498
|
+
if (!jwk.k) {
|
|
499
|
+
throw new Error("Octet JWK must contain 'k' property.");
|
|
500
|
+
}
|
|
501
|
+
const key = fromString2(jwk.k.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""), "base64url");
|
|
502
|
+
return toString2(key, "hex");
|
|
503
|
+
}
|
|
504
|
+
__name(octJwkToRawHexKey, "octJwkToRawHexKey");
|
|
505
|
+
var jwkDetermineUse = /* @__PURE__ */ __name((type, suppliedUse) => {
|
|
506
|
+
return suppliedUse ? suppliedUse : SIG_KEY_ALGS.includes(type) ? JwkKeyUse.Signature : ENC_KEY_ALGS.includes(type) ? JwkKeyUse.Encryption : void 0;
|
|
507
|
+
}, "jwkDetermineUse");
|
|
508
|
+
var assertProperKeyLength = /* @__PURE__ */ __name((keyHex, expectedKeyLength) => {
|
|
509
|
+
if (Array.isArray(expectedKeyLength)) {
|
|
510
|
+
if (!expectedKeyLength.includes(keyHex.length)) {
|
|
511
|
+
throw Error(`Invalid key length. Needs to be a hex string with length from ${JSON.stringify(expectedKeyLength)} instead of ${keyHex.length}. Input: ${keyHex}`);
|
|
512
|
+
}
|
|
513
|
+
} else if (keyHex.length !== expectedKeyLength) {
|
|
514
|
+
throw Error(`Invalid key length. Needs to be a hex string with length ${expectedKeyLength} instead of ${keyHex.length}. Input: ${keyHex}`);
|
|
515
|
+
}
|
|
516
|
+
}, "assertProperKeyLength");
|
|
517
|
+
var toSecp256k1Jwk = /* @__PURE__ */ __name((keyHex, opts) => {
|
|
518
|
+
const { use } = _nullishCoalesce(opts, () => ( {}));
|
|
519
|
+
logger.debug(`toSecp256k1Jwk keyHex: ${keyHex}, length: ${keyHex.length}`);
|
|
520
|
+
if (_optionalChain([opts, 'optionalAccess', _24 => _24.isPrivateKey])) {
|
|
521
|
+
assertProperKeyLength(keyHex, [
|
|
522
|
+
64
|
|
523
|
+
]);
|
|
524
|
+
} else {
|
|
525
|
+
assertProperKeyLength(keyHex, [
|
|
526
|
+
66,
|
|
527
|
+
130
|
|
528
|
+
]);
|
|
529
|
+
}
|
|
530
|
+
const secp256k12 = new _elliptic2.default.ec("secp256k1");
|
|
531
|
+
const keyBytes = fromString2(keyHex, "base16");
|
|
532
|
+
const keyPair = _optionalChain([opts, 'optionalAccess', _25 => _25.isPrivateKey]) ? secp256k12.keyFromPrivate(keyBytes) : secp256k12.keyFromPublic(keyBytes);
|
|
533
|
+
const pubPoint = keyPair.getPublic();
|
|
534
|
+
return sanitizedJwk({
|
|
535
|
+
alg: _ssitypes.JoseSignatureAlgorithm.ES256K,
|
|
536
|
+
...use !== void 0 && {
|
|
537
|
+
use
|
|
538
|
+
},
|
|
539
|
+
kty: _ssitypes.JwkKeyType.EC,
|
|
540
|
+
crv: _ssitypes.JoseCurve.secp256k1,
|
|
541
|
+
x: _ssisdkextx509utils.hexToBase64.call(void 0, pubPoint.getX().toString("hex"), "base64url"),
|
|
542
|
+
y: _ssisdkextx509utils.hexToBase64.call(void 0, pubPoint.getY().toString("hex"), "base64url"),
|
|
543
|
+
..._optionalChain([opts, 'optionalAccess', _26 => _26.isPrivateKey]) && {
|
|
544
|
+
d: _ssisdkextx509utils.hexToBase64.call(void 0, keyPair.getPrivate("hex"), "base64url")
|
|
545
|
+
}
|
|
546
|
+
});
|
|
547
|
+
}, "toSecp256k1Jwk");
|
|
548
|
+
var toSecp256r1Jwk = /* @__PURE__ */ __name((keyHex, opts) => {
|
|
549
|
+
const { use } = _nullishCoalesce(opts, () => ( {}));
|
|
550
|
+
logger.debug(`toSecp256r1Jwk keyHex: ${keyHex}, length: ${keyHex.length}`);
|
|
551
|
+
if (_optionalChain([opts, 'optionalAccess', _27 => _27.isPrivateKey])) {
|
|
552
|
+
assertProperKeyLength(keyHex, [
|
|
553
|
+
64
|
|
554
|
+
]);
|
|
555
|
+
} else {
|
|
556
|
+
assertProperKeyLength(keyHex, [
|
|
557
|
+
66,
|
|
558
|
+
130
|
|
559
|
+
]);
|
|
560
|
+
}
|
|
561
|
+
const secp256r1 = new _elliptic2.default.ec("p256");
|
|
562
|
+
const keyBytes = fromString2(keyHex, "base16");
|
|
563
|
+
logger.debug(`keyBytes length: ${keyBytes}`);
|
|
564
|
+
const keyPair = _optionalChain([opts, 'optionalAccess', _28 => _28.isPrivateKey]) ? secp256r1.keyFromPrivate(keyBytes) : secp256r1.keyFromPublic(keyBytes);
|
|
565
|
+
const pubPoint = keyPair.getPublic();
|
|
566
|
+
return sanitizedJwk({
|
|
567
|
+
alg: _ssitypes.JoseSignatureAlgorithm.ES256,
|
|
568
|
+
...use !== void 0 && {
|
|
569
|
+
use
|
|
570
|
+
},
|
|
571
|
+
kty: _ssitypes.JwkKeyType.EC,
|
|
572
|
+
crv: _ssitypes.JoseCurve.P_256,
|
|
573
|
+
x: _ssisdkextx509utils.hexToBase64.call(void 0, pubPoint.getX().toString("hex"), "base64url"),
|
|
574
|
+
y: _ssisdkextx509utils.hexToBase64.call(void 0, pubPoint.getY().toString("hex"), "base64url"),
|
|
575
|
+
..._optionalChain([opts, 'optionalAccess', _29 => _29.isPrivateKey]) && {
|
|
576
|
+
d: _ssisdkextx509utils.hexToBase64.call(void 0, keyPair.getPrivate("hex"), "base64url")
|
|
577
|
+
}
|
|
578
|
+
});
|
|
579
|
+
}, "toSecp256r1Jwk");
|
|
580
|
+
var toEd25519OrX25519Jwk = /* @__PURE__ */ __name((publicKeyHex, opts) => {
|
|
581
|
+
assertProperKeyLength(publicKeyHex, 64);
|
|
582
|
+
const { use } = _nullishCoalesce(opts, () => ( {}));
|
|
583
|
+
return sanitizedJwk({
|
|
584
|
+
alg: _ssitypes.JoseSignatureAlgorithm.EdDSA,
|
|
585
|
+
...use !== void 0 && {
|
|
586
|
+
use
|
|
587
|
+
},
|
|
588
|
+
kty: _ssitypes.JwkKeyType.OKP,
|
|
589
|
+
crv: _nullishCoalesce(_optionalChain([opts, 'optionalAccess', _30 => _30.crv]), () => ( _ssitypes.JoseCurve.Ed25519)),
|
|
590
|
+
x: _ssisdkextx509utils.hexToBase64.call(void 0, publicKeyHex, "base64url")
|
|
591
|
+
});
|
|
592
|
+
}, "toEd25519OrX25519Jwk");
|
|
593
|
+
var toRSAJwk = /* @__PURE__ */ __name((publicKeyHex, opts) => {
|
|
594
|
+
const meta = _optionalChain([opts, 'optionalAccess', _31 => _31.key, 'optionalAccess', _32 => _32.meta]);
|
|
595
|
+
if (_optionalChain([meta, 'optionalAccess', _33 => _33.publicKeyJwk]) || _optionalChain([meta, 'optionalAccess', _34 => _34.publicKeyPEM])) {
|
|
596
|
+
if (_optionalChain([meta, 'optionalAccess', _35 => _35.publicKeyJwk])) {
|
|
597
|
+
return meta.publicKeyJwk;
|
|
598
|
+
}
|
|
599
|
+
const publicKeyPEM = _nullishCoalesce(_optionalChain([meta, 'optionalAccess', _36 => _36.publicKeyPEM]), () => ( _ssisdkextx509utils.hexToPEM.call(void 0, publicKeyHex, "public")));
|
|
600
|
+
return _ssisdkextx509utils.PEMToJwk.call(void 0, publicKeyPEM, "public");
|
|
601
|
+
}
|
|
602
|
+
const exponent = publicKeyHex.slice(-5);
|
|
603
|
+
const modulus = publicKeyHex.slice(0, -5);
|
|
604
|
+
return sanitizedJwk({
|
|
605
|
+
kty: "RSA",
|
|
606
|
+
n: _ssisdkextx509utils.hexToBase64.call(void 0, modulus, "base64url"),
|
|
607
|
+
e: _ssisdkextx509utils.hexToBase64.call(void 0, exponent, "base64url")
|
|
608
|
+
});
|
|
609
|
+
}, "toRSAJwk");
|
|
610
|
+
var padLeft = /* @__PURE__ */ __name((args) => {
|
|
611
|
+
const { data } = args;
|
|
612
|
+
const size = _nullishCoalesce(args.size, () => ( 32));
|
|
613
|
+
const padString = _nullishCoalesce(args.padString, () => ( "0"));
|
|
614
|
+
if (data.length >= size) {
|
|
615
|
+
return data;
|
|
616
|
+
}
|
|
617
|
+
if (padString && padString.length === 0) {
|
|
618
|
+
throw Error(`Pad string needs to have at least a length of 1`);
|
|
619
|
+
}
|
|
620
|
+
const length = padString.length;
|
|
621
|
+
return padString.repeat((size - data.length) / length) + data;
|
|
622
|
+
}, "padLeft");
|
|
623
|
+
var OID = {
|
|
624
|
+
[0]: new Uint8Array([
|
|
625
|
+
6,
|
|
626
|
+
7,
|
|
627
|
+
42,
|
|
628
|
+
134,
|
|
629
|
+
72,
|
|
630
|
+
206,
|
|
631
|
+
61,
|
|
632
|
+
2,
|
|
633
|
+
1
|
|
634
|
+
]),
|
|
635
|
+
[1]: new Uint8Array([
|
|
636
|
+
6,
|
|
637
|
+
8,
|
|
638
|
+
42,
|
|
639
|
+
134,
|
|
640
|
+
72,
|
|
641
|
+
206,
|
|
642
|
+
61,
|
|
643
|
+
3,
|
|
644
|
+
1,
|
|
645
|
+
7
|
|
646
|
+
]),
|
|
647
|
+
[2]: new Uint8Array([
|
|
648
|
+
6,
|
|
649
|
+
3,
|
|
650
|
+
43,
|
|
651
|
+
101,
|
|
652
|
+
112
|
|
653
|
+
])
|
|
654
|
+
};
|
|
655
|
+
var compareUint8Arrays = /* @__PURE__ */ __name((a, b) => {
|
|
656
|
+
if (a.length !== b.length) {
|
|
657
|
+
return false;
|
|
658
|
+
}
|
|
659
|
+
for (let i = 0; i < a.length; i++) {
|
|
660
|
+
if (a[i] !== b[i]) {
|
|
661
|
+
return false;
|
|
662
|
+
}
|
|
663
|
+
}
|
|
664
|
+
return true;
|
|
665
|
+
}, "compareUint8Arrays");
|
|
666
|
+
var findSubarray = /* @__PURE__ */ __name((haystack, needle) => {
|
|
667
|
+
for (let i = 0; i <= haystack.length - needle.length; i++) {
|
|
668
|
+
if (compareUint8Arrays(haystack.subarray(i, i + needle.length), needle)) {
|
|
669
|
+
return i;
|
|
670
|
+
}
|
|
671
|
+
}
|
|
672
|
+
return -1;
|
|
673
|
+
}, "findSubarray");
|
|
674
|
+
var getTargetOID = /* @__PURE__ */ __name((keyType) => {
|
|
675
|
+
switch (keyType) {
|
|
676
|
+
case "Secp256k1":
|
|
677
|
+
return OID[0];
|
|
678
|
+
case "Secp256r1":
|
|
679
|
+
return OID[1];
|
|
680
|
+
case "Ed25519":
|
|
681
|
+
return OID[2];
|
|
682
|
+
default:
|
|
683
|
+
throw new Error(`Unsupported key type: ${keyType}`);
|
|
684
|
+
}
|
|
685
|
+
}, "getTargetOID");
|
|
686
|
+
var isAsn1Der = /* @__PURE__ */ __name((key) => key[0] === 48, "isAsn1Der");
|
|
687
|
+
var asn1DerToRawPublicKey = /* @__PURE__ */ __name((derKey, keyType) => {
|
|
688
|
+
if (!isAsn1Der(derKey)) {
|
|
689
|
+
throw new Error("Invalid DER encoding: Expected to start with sequence tag");
|
|
690
|
+
}
|
|
691
|
+
let index = 2;
|
|
692
|
+
if (derKey[1] & 128) {
|
|
693
|
+
const lengthBytesCount = derKey[1] & 127;
|
|
694
|
+
index += lengthBytesCount;
|
|
695
|
+
}
|
|
696
|
+
const targetOid = getTargetOID(keyType);
|
|
697
|
+
const oidIndex = findSubarray(derKey, targetOid);
|
|
698
|
+
if (oidIndex === -1) {
|
|
699
|
+
throw new Error(`OID for ${keyType} not found in DER encoding`);
|
|
700
|
+
}
|
|
701
|
+
index = oidIndex + targetOid.length;
|
|
702
|
+
while (index < derKey.length && derKey[index] !== 3) {
|
|
703
|
+
index++;
|
|
704
|
+
}
|
|
705
|
+
if (index >= derKey.length) {
|
|
706
|
+
throw new Error("Invalid DER encoding: Bit string not found");
|
|
707
|
+
}
|
|
708
|
+
index += 2;
|
|
709
|
+
index++;
|
|
710
|
+
return derKey.slice(index);
|
|
711
|
+
}, "asn1DerToRawPublicKey");
|
|
712
|
+
var isRawCompressedPublicKey = /* @__PURE__ */ __name((key) => key.length === 33 && (key[0] === 2 || key[0] === 3), "isRawCompressedPublicKey");
|
|
713
|
+
var toRawCompressedHexPublicKey = /* @__PURE__ */ __name((rawPublicKey, keyType) => {
|
|
714
|
+
if (isRawCompressedPublicKey(rawPublicKey)) {
|
|
715
|
+
return hexStringFromUint8Array(rawPublicKey);
|
|
716
|
+
}
|
|
717
|
+
if (keyType === "Secp256k1" || keyType === "Secp256r1") {
|
|
718
|
+
if (rawPublicKey[0] === 4 && rawPublicKey.length === 65) {
|
|
719
|
+
const xCoordinate = rawPublicKey.slice(1, 33);
|
|
720
|
+
const yCoordinate = rawPublicKey.slice(33);
|
|
721
|
+
const prefix = new Uint8Array([
|
|
722
|
+
yCoordinate[31] % 2 === 0 ? 2 : 3
|
|
723
|
+
]);
|
|
724
|
+
const resultKey = hexStringFromUint8Array(new Uint8Array([
|
|
725
|
+
...prefix,
|
|
726
|
+
...xCoordinate
|
|
727
|
+
]));
|
|
728
|
+
logger.debug(`converted public key ${hexStringFromUint8Array(rawPublicKey)} to ${resultKey}`);
|
|
729
|
+
return resultKey;
|
|
730
|
+
}
|
|
731
|
+
return toString2(rawPublicKey, "base16");
|
|
732
|
+
} else if (keyType === "Ed25519") {
|
|
733
|
+
return toString2(rawPublicKey, "base16");
|
|
734
|
+
}
|
|
735
|
+
throw new Error(`Unsupported key type: ${keyType}`);
|
|
736
|
+
}, "toRawCompressedHexPublicKey");
|
|
737
|
+
var hexStringFromUint8Array = /* @__PURE__ */ __name((value) => toString2(value, "base16"), "hexStringFromUint8Array");
|
|
738
|
+
var signatureAlgorithmFromKey = /* @__PURE__ */ __name(async (args) => {
|
|
739
|
+
const { key } = args;
|
|
740
|
+
return signatureAlgorithmFromKeyType({
|
|
741
|
+
type: key.type
|
|
742
|
+
});
|
|
743
|
+
}, "signatureAlgorithmFromKey");
|
|
744
|
+
var signatureAlgorithmFromKeyType = /* @__PURE__ */ __name((args) => {
|
|
745
|
+
const { type } = args;
|
|
746
|
+
switch (type) {
|
|
747
|
+
case "Ed25519":
|
|
748
|
+
case "X25519":
|
|
749
|
+
return _ssitypes.JoseSignatureAlgorithm.EdDSA;
|
|
750
|
+
case "Secp256r1":
|
|
751
|
+
return _ssitypes.JoseSignatureAlgorithm.ES256;
|
|
752
|
+
case "Secp384r1":
|
|
753
|
+
return _ssitypes.JoseSignatureAlgorithm.ES384;
|
|
754
|
+
case "Secp521r1":
|
|
755
|
+
return _ssitypes.JoseSignatureAlgorithm.ES512;
|
|
756
|
+
case "Secp256k1":
|
|
757
|
+
return _ssitypes.JoseSignatureAlgorithm.ES256K;
|
|
758
|
+
default:
|
|
759
|
+
throw new Error(`Key type '${type}' not supported`);
|
|
760
|
+
}
|
|
761
|
+
}, "signatureAlgorithmFromKeyType");
|
|
762
|
+
var keyTypeFromCryptographicSuite = /* @__PURE__ */ __name((args) => {
|
|
763
|
+
const { crv, kty, alg } = args;
|
|
764
|
+
switch (alg) {
|
|
765
|
+
case "RSASSA-PSS":
|
|
766
|
+
case "RS256":
|
|
767
|
+
case "RS384":
|
|
768
|
+
case "RS512":
|
|
769
|
+
case "PS256":
|
|
770
|
+
case "PS384":
|
|
771
|
+
case "PS512":
|
|
772
|
+
return "RSA";
|
|
773
|
+
}
|
|
774
|
+
switch (crv) {
|
|
775
|
+
case "EdDSA":
|
|
776
|
+
case "Ed25519":
|
|
777
|
+
case "Ed25519Signature2018":
|
|
778
|
+
case "Ed25519Signature2020":
|
|
779
|
+
case "JcsEd25519Signature2020":
|
|
780
|
+
return "Ed25519";
|
|
781
|
+
case "JsonWebSignature2020":
|
|
782
|
+
case "ES256":
|
|
783
|
+
case "ECDSA":
|
|
784
|
+
case "P-256":
|
|
785
|
+
return "Secp256r1";
|
|
786
|
+
case "ES384":
|
|
787
|
+
case "P-384":
|
|
788
|
+
return "Secp384r1";
|
|
789
|
+
case "ES512":
|
|
790
|
+
case "P-521":
|
|
791
|
+
return "Secp521r1";
|
|
792
|
+
case "EcdsaSecp256k1Signature2019":
|
|
793
|
+
case "secp256k1":
|
|
794
|
+
case "ES256K":
|
|
795
|
+
return "Secp256k1";
|
|
796
|
+
}
|
|
797
|
+
if (kty) {
|
|
798
|
+
return kty;
|
|
799
|
+
}
|
|
800
|
+
throw new Error(`Cryptographic suite '${crv}' not supported`);
|
|
801
|
+
}, "keyTypeFromCryptographicSuite");
|
|
802
|
+
function removeNulls(obj) {
|
|
803
|
+
Object.keys(obj).forEach((key) => {
|
|
804
|
+
if (obj[key] && typeof obj[key] === "object") removeNulls(obj[key]);
|
|
805
|
+
else if (obj[key] == null) delete obj[key];
|
|
806
|
+
});
|
|
807
|
+
return obj;
|
|
808
|
+
}
|
|
809
|
+
__name(removeNulls, "removeNulls");
|
|
810
|
+
var globalCrypto = /* @__PURE__ */ __name((setGlobal, suppliedCrypto) => {
|
|
811
|
+
let webcrypto;
|
|
812
|
+
if (typeof suppliedCrypto !== "undefined") {
|
|
813
|
+
webcrypto = suppliedCrypto;
|
|
814
|
+
} else if (typeof crypto !== "undefined") {
|
|
815
|
+
webcrypto = crypto;
|
|
816
|
+
} else if (typeof global.crypto !== "undefined") {
|
|
817
|
+
webcrypto = global.crypto;
|
|
818
|
+
} else {
|
|
819
|
+
if (typeof _optionalChain([global, 'access', _37 => _37.window, 'optionalAccess', _38 => _38.crypto, 'optionalAccess', _39 => _39.subtle]) !== "undefined") {
|
|
820
|
+
webcrypto = global.window.crypto;
|
|
821
|
+
} else {
|
|
822
|
+
webcrypto = Promise.resolve().then(() => _interopRequireWildcard(require("crypto")));
|
|
823
|
+
}
|
|
824
|
+
}
|
|
825
|
+
if (setGlobal) {
|
|
826
|
+
global.crypto = webcrypto;
|
|
827
|
+
}
|
|
828
|
+
return webcrypto;
|
|
829
|
+
}, "globalCrypto");
|
|
830
|
+
var sanitizedJwk = /* @__PURE__ */ __name((input) => {
|
|
831
|
+
const inputJwk = typeof input["toJsonDTO"] === "function" ? input["toJsonDTO"]() : {
|
|
832
|
+
...input
|
|
833
|
+
};
|
|
834
|
+
const jwk = {
|
|
835
|
+
...inputJwk,
|
|
836
|
+
...inputJwk.x && {
|
|
837
|
+
x: base64ToBase64Url(inputJwk.x)
|
|
838
|
+
},
|
|
839
|
+
...inputJwk.y && {
|
|
840
|
+
y: base64ToBase64Url(inputJwk.y)
|
|
841
|
+
},
|
|
842
|
+
...inputJwk.d && {
|
|
843
|
+
d: base64ToBase64Url(inputJwk.d)
|
|
844
|
+
},
|
|
845
|
+
...inputJwk.n && {
|
|
846
|
+
n: base64ToBase64Url(inputJwk.n)
|
|
847
|
+
},
|
|
848
|
+
...inputJwk.e && {
|
|
849
|
+
e: base64ToBase64Url(inputJwk.e)
|
|
850
|
+
},
|
|
851
|
+
...inputJwk.k && {
|
|
852
|
+
k: base64ToBase64Url(inputJwk.k)
|
|
853
|
+
}
|
|
854
|
+
};
|
|
855
|
+
return removeNulls(jwk);
|
|
856
|
+
}, "sanitizedJwk");
|
|
857
|
+
var base64ToBase64Url = /* @__PURE__ */ __name((input) => {
|
|
858
|
+
return input.replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
|
|
859
|
+
}, "base64ToBase64Url");
|
|
860
|
+
async function verifyRawSignature({ data, signature, key: inputKey, opts }) {
|
|
861
|
+
function jwkPropertyToBigInt(jwkProp) {
|
|
862
|
+
const byteArray = fromString2(jwkProp, "base64url");
|
|
863
|
+
const hex = toString2(byteArray, "hex");
|
|
864
|
+
return BigInt(`0x${hex}`);
|
|
865
|
+
}
|
|
866
|
+
__name(jwkPropertyToBigInt, "jwkPropertyToBigInt");
|
|
867
|
+
try {
|
|
868
|
+
_debug2.default.call(void 0, `verifyRawSignature for: ${inputKey}`);
|
|
869
|
+
const jwk = sanitizedJwk(inputKey);
|
|
870
|
+
validateJwk(jwk, {
|
|
871
|
+
crvOptional: true
|
|
872
|
+
});
|
|
873
|
+
const keyType = keyTypeFromCryptographicSuite({
|
|
874
|
+
crv: jwk.crv,
|
|
875
|
+
kty: jwk.kty,
|
|
876
|
+
alg: jwk.alg
|
|
877
|
+
});
|
|
878
|
+
const publicKeyHex = await jwkToRawHexKey(jwk);
|
|
879
|
+
switch (keyType) {
|
|
880
|
+
case "Secp256k1":
|
|
881
|
+
return _secp256k1.secp256k1.verify(signature, data, publicKeyHex, {
|
|
882
|
+
format: "compact",
|
|
883
|
+
prehash: true
|
|
884
|
+
});
|
|
885
|
+
case "Secp256r1":
|
|
886
|
+
return _p256.p256.verify(signature, data, publicKeyHex, {
|
|
887
|
+
format: "compact",
|
|
888
|
+
prehash: true
|
|
889
|
+
});
|
|
890
|
+
case "Secp384r1":
|
|
891
|
+
return _p384.p384.verify(signature, data, publicKeyHex, {
|
|
892
|
+
format: "compact",
|
|
893
|
+
prehash: true
|
|
894
|
+
});
|
|
895
|
+
case "Secp521r1":
|
|
896
|
+
return _p521.p521.verify(signature, data, publicKeyHex, {
|
|
897
|
+
format: "compact",
|
|
898
|
+
prehash: true
|
|
899
|
+
});
|
|
900
|
+
case "Ed25519":
|
|
901
|
+
return _ed25519.ed25519.verify(signature, data, fromString2(publicKeyHex, "hex"));
|
|
902
|
+
case "Bls12381G1":
|
|
903
|
+
case "Bls12381G2":
|
|
904
|
+
return _bls12381.bls12_381.verify(signature, data, fromString2(publicKeyHex, "hex"));
|
|
905
|
+
case "RSA": {
|
|
906
|
+
const signatureAlgorithm = _nullishCoalesce(_nullishCoalesce(_optionalChain([opts, 'optionalAccess', _40 => _40.signatureAlg]), () => ( jwk.alg)), () => ( _ssitypes.JoseSignatureAlgorithm.PS256));
|
|
907
|
+
const hashAlg = signatureAlgorithm === (_ssitypes.JoseSignatureAlgorithm.RS512 || _ssitypes.JoseSignatureAlgorithm.PS512) ? _sha512.sha512 : signatureAlgorithm === (_ssitypes.JoseSignatureAlgorithm.RS384 || _ssitypes.JoseSignatureAlgorithm.PS384) ? _sha512.sha384 : _sha256.sha256;
|
|
908
|
+
switch (signatureAlgorithm) {
|
|
909
|
+
case _ssitypes.JoseSignatureAlgorithm.RS256:
|
|
910
|
+
return rsa.PKCS1_SHA256.verify({
|
|
911
|
+
n: jwkPropertyToBigInt(jwk.n),
|
|
912
|
+
e: jwkPropertyToBigInt(jwk.e)
|
|
913
|
+
}, data, signature);
|
|
914
|
+
case _ssitypes.JoseSignatureAlgorithm.RS384:
|
|
915
|
+
return rsa.PKCS1_SHA384.verify({
|
|
916
|
+
n: jwkPropertyToBigInt(jwk.n),
|
|
917
|
+
e: jwkPropertyToBigInt(jwk.e)
|
|
918
|
+
}, data, signature);
|
|
919
|
+
case _ssitypes.JoseSignatureAlgorithm.RS512:
|
|
920
|
+
return rsa.PKCS1_SHA512.verify({
|
|
921
|
+
n: jwkPropertyToBigInt(jwk.n),
|
|
922
|
+
e: jwkPropertyToBigInt(jwk.e)
|
|
923
|
+
}, data, signature);
|
|
924
|
+
case _ssitypes.JoseSignatureAlgorithm.PS256:
|
|
925
|
+
case _ssitypes.JoseSignatureAlgorithm.PS384:
|
|
926
|
+
case _ssitypes.JoseSignatureAlgorithm.PS512:
|
|
927
|
+
return rsa.PSS(hashAlg, rsa.mgf1(hashAlg)).verify({
|
|
928
|
+
n: jwkPropertyToBigInt(jwk.n),
|
|
929
|
+
e: jwkPropertyToBigInt(jwk.e)
|
|
930
|
+
}, data, signature);
|
|
931
|
+
}
|
|
932
|
+
}
|
|
933
|
+
}
|
|
934
|
+
throw Error(`Unsupported key type for signature validation: ${keyType}`);
|
|
935
|
+
} catch (error) {
|
|
936
|
+
logger.error(`Error: ${error}`);
|
|
937
|
+
throw error;
|
|
938
|
+
}
|
|
939
|
+
}
|
|
940
|
+
__name(verifyRawSignature, "verifyRawSignature");
|
|
941
|
+
|
|
942
|
+
// src/conversion.ts
|
|
943
|
+
|
|
944
|
+
function coseKeyToJwk(coseKey) {
|
|
945
|
+
const { x5chain, key_ops, crv, alg, baseIV, kty, ...rest } = coseKey;
|
|
946
|
+
return removeNulls({
|
|
947
|
+
...rest,
|
|
948
|
+
kty: coseToJoseKty(kty),
|
|
949
|
+
...crv && {
|
|
950
|
+
crv: coseToJoseCurve(crv)
|
|
951
|
+
},
|
|
952
|
+
...key_ops && {
|
|
953
|
+
key_ops: key_ops.map(coseToJoseKeyOperation)
|
|
954
|
+
},
|
|
955
|
+
...alg && {
|
|
956
|
+
alg: coseToJoseSignatureAlg(alg)
|
|
957
|
+
},
|
|
958
|
+
...baseIV && {
|
|
959
|
+
iv: baseIV
|
|
960
|
+
},
|
|
961
|
+
...x5chain && {
|
|
962
|
+
x5c: x5chain
|
|
963
|
+
}
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
__name(coseKeyToJwk, "coseKeyToJwk");
|
|
967
|
+
function jwkToCoseKey(jwk) {
|
|
968
|
+
const { x5c, key_ops, crv, alg, iv, kty, ...rest } = jwk;
|
|
969
|
+
return removeNulls({
|
|
970
|
+
...rest,
|
|
971
|
+
kty: joseToCoseKty(kty),
|
|
972
|
+
...crv && {
|
|
973
|
+
crv: joseToCoseCurve(crv)
|
|
974
|
+
},
|
|
975
|
+
...key_ops && {
|
|
976
|
+
key_ops: key_ops.map(joseToCoseKeyOperation)
|
|
977
|
+
},
|
|
978
|
+
...alg && {
|
|
979
|
+
alg: joseToCoseSignatureAlg(alg)
|
|
980
|
+
},
|
|
981
|
+
...iv && {
|
|
982
|
+
baseIV: iv
|
|
983
|
+
},
|
|
984
|
+
...x5c && {
|
|
985
|
+
x5chain: x5c
|
|
986
|
+
}
|
|
987
|
+
});
|
|
988
|
+
}
|
|
989
|
+
__name(jwkToCoseKey, "jwkToCoseKey");
|
|
990
|
+
function coseToJoseKty(kty) {
|
|
991
|
+
switch (kty) {
|
|
992
|
+
case _ssitypes.ICoseKeyType.EC2:
|
|
993
|
+
return _ssitypes.JwkKeyType.EC;
|
|
994
|
+
case _ssitypes.ICoseKeyType.RSA:
|
|
995
|
+
return _ssitypes.JwkKeyType.RSA;
|
|
996
|
+
case _ssitypes.ICoseKeyType.Symmetric:
|
|
997
|
+
return _ssitypes.JwkKeyType.oct;
|
|
998
|
+
case _ssitypes.ICoseKeyType.OKP:
|
|
999
|
+
return _ssitypes.JwkKeyType.OKP;
|
|
1000
|
+
default:
|
|
1001
|
+
throw Error(`Key type ${kty} not supported in JWA`);
|
|
1002
|
+
}
|
|
1003
|
+
}
|
|
1004
|
+
__name(coseToJoseKty, "coseToJoseKty");
|
|
1005
|
+
function joseToCoseKty(kty) {
|
|
1006
|
+
switch (kty) {
|
|
1007
|
+
case "EC":
|
|
1008
|
+
return _ssitypes.ICoseKeyType.EC2;
|
|
1009
|
+
case "RSA":
|
|
1010
|
+
return _ssitypes.ICoseKeyType.RSA;
|
|
1011
|
+
case "oct":
|
|
1012
|
+
return _ssitypes.ICoseKeyType.Symmetric;
|
|
1013
|
+
case "OKP":
|
|
1014
|
+
return _ssitypes.ICoseKeyType.OKP;
|
|
1015
|
+
default:
|
|
1016
|
+
throw Error(`Key type ${kty} not supported in Cose`);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
__name(joseToCoseKty, "joseToCoseKty");
|
|
1020
|
+
function coseToJoseSignatureAlg(coseAlg) {
|
|
1021
|
+
switch (coseAlg) {
|
|
1022
|
+
case _ssitypes.ICoseSignatureAlgorithm.ES256K:
|
|
1023
|
+
return _ssitypes.JoseSignatureAlgorithm.ES256K;
|
|
1024
|
+
case _ssitypes.ICoseSignatureAlgorithm.ES256:
|
|
1025
|
+
return _ssitypes.JoseSignatureAlgorithm.ES256;
|
|
1026
|
+
case _ssitypes.ICoseSignatureAlgorithm.ES384:
|
|
1027
|
+
return _ssitypes.JoseSignatureAlgorithm.ES384;
|
|
1028
|
+
case _ssitypes.ICoseSignatureAlgorithm.ES512:
|
|
1029
|
+
return _ssitypes.JoseSignatureAlgorithm.ES512;
|
|
1030
|
+
case _ssitypes.ICoseSignatureAlgorithm.PS256:
|
|
1031
|
+
return _ssitypes.JoseSignatureAlgorithm.PS256;
|
|
1032
|
+
case _ssitypes.ICoseSignatureAlgorithm.PS384:
|
|
1033
|
+
return _ssitypes.JoseSignatureAlgorithm.PS384;
|
|
1034
|
+
case _ssitypes.ICoseSignatureAlgorithm.PS512:
|
|
1035
|
+
return _ssitypes.JoseSignatureAlgorithm.PS512;
|
|
1036
|
+
case _ssitypes.ICoseSignatureAlgorithm.HS256:
|
|
1037
|
+
return _ssitypes.JoseSignatureAlgorithm.HS256;
|
|
1038
|
+
case _ssitypes.ICoseSignatureAlgorithm.HS384:
|
|
1039
|
+
return _ssitypes.JoseSignatureAlgorithm.HS384;
|
|
1040
|
+
case _ssitypes.ICoseSignatureAlgorithm.HS512:
|
|
1041
|
+
return _ssitypes.JoseSignatureAlgorithm.HS512;
|
|
1042
|
+
case _ssitypes.ICoseSignatureAlgorithm.EdDSA:
|
|
1043
|
+
return _ssitypes.JoseSignatureAlgorithm.EdDSA;
|
|
1044
|
+
default:
|
|
1045
|
+
throw Error(`Signature algorithm ${coseAlg} not supported in Jose`);
|
|
1046
|
+
}
|
|
1047
|
+
}
|
|
1048
|
+
__name(coseToJoseSignatureAlg, "coseToJoseSignatureAlg");
|
|
1049
|
+
function joseToCoseSignatureAlg(joseAlg) {
|
|
1050
|
+
switch (joseAlg) {
|
|
1051
|
+
case (_ssitypes.JoseSignatureAlgorithm.ES256K, "ES256K"):
|
|
1052
|
+
return _ssitypes.ICoseSignatureAlgorithm.ES256K;
|
|
1053
|
+
case (_ssitypes.JoseSignatureAlgorithm.ES256, "ES256"):
|
|
1054
|
+
return _ssitypes.ICoseSignatureAlgorithm.ES256;
|
|
1055
|
+
case (_ssitypes.JoseSignatureAlgorithm.ES384, "ES384"):
|
|
1056
|
+
return _ssitypes.ICoseSignatureAlgorithm.ES384;
|
|
1057
|
+
case (_ssitypes.JoseSignatureAlgorithm.ES512, "ES512"):
|
|
1058
|
+
return _ssitypes.ICoseSignatureAlgorithm.ES512;
|
|
1059
|
+
case (_ssitypes.JoseSignatureAlgorithm.PS256, "PS256"):
|
|
1060
|
+
return _ssitypes.ICoseSignatureAlgorithm.PS256;
|
|
1061
|
+
case (_ssitypes.JoseSignatureAlgorithm.PS384, "PS384"):
|
|
1062
|
+
return _ssitypes.ICoseSignatureAlgorithm.PS384;
|
|
1063
|
+
case (_ssitypes.JoseSignatureAlgorithm.PS512, "PS512"):
|
|
1064
|
+
return _ssitypes.ICoseSignatureAlgorithm.PS512;
|
|
1065
|
+
case (_ssitypes.JoseSignatureAlgorithm.HS256, "HS256"):
|
|
1066
|
+
return _ssitypes.ICoseSignatureAlgorithm.HS256;
|
|
1067
|
+
case (_ssitypes.JoseSignatureAlgorithm.HS384, "HS384"):
|
|
1068
|
+
return _ssitypes.ICoseSignatureAlgorithm.HS384;
|
|
1069
|
+
case (_ssitypes.JoseSignatureAlgorithm.HS512, "HS512"):
|
|
1070
|
+
return _ssitypes.ICoseSignatureAlgorithm.HS512;
|
|
1071
|
+
case (_ssitypes.JoseSignatureAlgorithm.EdDSA, "EdDSA"):
|
|
1072
|
+
return _ssitypes.ICoseSignatureAlgorithm.EdDSA;
|
|
1073
|
+
default:
|
|
1074
|
+
throw Error(`Signature algorithm ${joseAlg} not supported in Cose`);
|
|
1075
|
+
}
|
|
1076
|
+
}
|
|
1077
|
+
__name(joseToCoseSignatureAlg, "joseToCoseSignatureAlg");
|
|
1078
|
+
function joseToCoseKeyOperation(keyOp) {
|
|
1079
|
+
switch (keyOp) {
|
|
1080
|
+
case (_ssitypes.JoseKeyOperation.SIGN, "sign"):
|
|
1081
|
+
return _ssitypes.ICoseKeyOperation.SIGN;
|
|
1082
|
+
case (_ssitypes.JoseKeyOperation.VERIFY, "verify"):
|
|
1083
|
+
return _ssitypes.ICoseKeyOperation.VERIFY;
|
|
1084
|
+
case (_ssitypes.JoseKeyOperation.ENCRYPT, "encrypt"):
|
|
1085
|
+
return _ssitypes.ICoseKeyOperation.ENCRYPT;
|
|
1086
|
+
case (_ssitypes.JoseKeyOperation.DECRYPT, "decrypt"):
|
|
1087
|
+
return _ssitypes.ICoseKeyOperation.DECRYPT;
|
|
1088
|
+
case (_ssitypes.JoseKeyOperation.WRAP_KEY, "wrapKey"):
|
|
1089
|
+
return _ssitypes.ICoseKeyOperation.WRAP_KEY;
|
|
1090
|
+
case (_ssitypes.JoseKeyOperation.UNWRAP_KEY, "unwrapKey"):
|
|
1091
|
+
return _ssitypes.ICoseKeyOperation.UNWRAP_KEY;
|
|
1092
|
+
case (_ssitypes.JoseKeyOperation.DERIVE_KEY, "deriveKey"):
|
|
1093
|
+
return _ssitypes.ICoseKeyOperation.DERIVE_KEY;
|
|
1094
|
+
case (_ssitypes.JoseKeyOperation.DERIVE_BITS, "deriveBits"):
|
|
1095
|
+
return _ssitypes.ICoseKeyOperation.DERIVE_BITS;
|
|
1096
|
+
default:
|
|
1097
|
+
throw Error(`Key operation ${keyOp} not supported in Cose`);
|
|
1098
|
+
}
|
|
1099
|
+
}
|
|
1100
|
+
__name(joseToCoseKeyOperation, "joseToCoseKeyOperation");
|
|
1101
|
+
function coseToJoseKeyOperation(keyOp) {
|
|
1102
|
+
switch (keyOp) {
|
|
1103
|
+
case _ssitypes.ICoseKeyOperation.SIGN:
|
|
1104
|
+
return _ssitypes.JoseKeyOperation.SIGN;
|
|
1105
|
+
case _ssitypes.ICoseKeyOperation.VERIFY:
|
|
1106
|
+
return _ssitypes.JoseKeyOperation.VERIFY;
|
|
1107
|
+
case _ssitypes.ICoseKeyOperation.ENCRYPT:
|
|
1108
|
+
return _ssitypes.JoseKeyOperation.ENCRYPT;
|
|
1109
|
+
case _ssitypes.ICoseKeyOperation.DECRYPT:
|
|
1110
|
+
return _ssitypes.JoseKeyOperation.DECRYPT;
|
|
1111
|
+
case _ssitypes.ICoseKeyOperation.WRAP_KEY:
|
|
1112
|
+
return _ssitypes.JoseKeyOperation.WRAP_KEY;
|
|
1113
|
+
case _ssitypes.ICoseKeyOperation.UNWRAP_KEY:
|
|
1114
|
+
return _ssitypes.JoseKeyOperation.UNWRAP_KEY;
|
|
1115
|
+
case _ssitypes.ICoseKeyOperation.DERIVE_KEY:
|
|
1116
|
+
return _ssitypes.JoseKeyOperation.DERIVE_KEY;
|
|
1117
|
+
case _ssitypes.ICoseKeyOperation.DERIVE_BITS:
|
|
1118
|
+
return _ssitypes.JoseKeyOperation.DERIVE_BITS;
|
|
1119
|
+
default:
|
|
1120
|
+
throw Error(`Key operation ${keyOp} not supported in Jose`);
|
|
1121
|
+
}
|
|
1122
|
+
}
|
|
1123
|
+
__name(coseToJoseKeyOperation, "coseToJoseKeyOperation");
|
|
1124
|
+
function joseToCoseCurve(curve) {
|
|
1125
|
+
switch (curve) {
|
|
1126
|
+
case (_ssitypes.JoseCurve.P_256, "P-256"):
|
|
1127
|
+
return _ssitypes.ICoseCurve.P_256;
|
|
1128
|
+
case (_ssitypes.JoseCurve.P_384, "P-384"):
|
|
1129
|
+
return _ssitypes.ICoseCurve.P_384;
|
|
1130
|
+
case (_ssitypes.JoseCurve.P_521, "P-521"):
|
|
1131
|
+
return _ssitypes.ICoseCurve.P_521;
|
|
1132
|
+
case (_ssitypes.JoseCurve.X25519, "X25519"):
|
|
1133
|
+
return _ssitypes.ICoseCurve.X25519;
|
|
1134
|
+
case (_ssitypes.JoseCurve.X448, "X448"):
|
|
1135
|
+
return _ssitypes.ICoseCurve.X448;
|
|
1136
|
+
case (_ssitypes.JoseCurve.Ed25519, "Ed25519"):
|
|
1137
|
+
return _ssitypes.ICoseCurve.Ed25519;
|
|
1138
|
+
case (_ssitypes.JoseCurve.Ed448, "Ed448"):
|
|
1139
|
+
return _ssitypes.ICoseCurve.Ed448;
|
|
1140
|
+
case (_ssitypes.JoseCurve.secp256k1, "secp256k1"):
|
|
1141
|
+
return _ssitypes.ICoseCurve.secp256k1;
|
|
1142
|
+
default:
|
|
1143
|
+
throw Error(`Curve ${curve} not supported in Cose`);
|
|
1144
|
+
}
|
|
1145
|
+
}
|
|
1146
|
+
__name(joseToCoseCurve, "joseToCoseCurve");
|
|
1147
|
+
function coseToJoseCurve(curve) {
|
|
1148
|
+
switch (curve) {
|
|
1149
|
+
case _ssitypes.ICoseCurve.P_256:
|
|
1150
|
+
return _ssitypes.JoseCurve.P_256;
|
|
1151
|
+
case _ssitypes.ICoseCurve.P_384:
|
|
1152
|
+
return _ssitypes.JoseCurve.P_384;
|
|
1153
|
+
case _ssitypes.ICoseCurve.P_521:
|
|
1154
|
+
return _ssitypes.JoseCurve.P_521;
|
|
1155
|
+
case _ssitypes.ICoseCurve.X25519:
|
|
1156
|
+
return _ssitypes.JoseCurve.X25519;
|
|
1157
|
+
case _ssitypes.ICoseCurve.X448:
|
|
1158
|
+
return _ssitypes.JoseCurve.X448;
|
|
1159
|
+
case _ssitypes.ICoseCurve.Ed25519:
|
|
1160
|
+
return _ssitypes.JoseCurve.Ed25519;
|
|
1161
|
+
case _ssitypes.ICoseCurve.Ed448:
|
|
1162
|
+
return _ssitypes.JoseCurve.Ed448;
|
|
1163
|
+
case _ssitypes.ICoseCurve.secp256k1:
|
|
1164
|
+
return _ssitypes.JoseCurve.secp256k1;
|
|
1165
|
+
default:
|
|
1166
|
+
throw Error(`Curve ${curve} not supported in Jose`);
|
|
1167
|
+
}
|
|
1168
|
+
}
|
|
1169
|
+
__name(coseToJoseCurve, "coseToJoseCurve");
|
|
1170
|
+
|
|
1171
|
+
|
|
1172
|
+
|
|
1173
|
+
|
|
1174
|
+
|
|
1175
|
+
|
|
1176
|
+
|
|
1177
|
+
|
|
1178
|
+
|
|
1179
|
+
|
|
1180
|
+
|
|
1181
|
+
|
|
1182
|
+
|
|
1183
|
+
|
|
1184
|
+
|
|
1185
|
+
|
|
1186
|
+
|
|
1187
|
+
|
|
1188
|
+
|
|
1189
|
+
|
|
1190
|
+
|
|
1191
|
+
|
|
1192
|
+
|
|
1193
|
+
|
|
1194
|
+
|
|
1195
|
+
|
|
1196
|
+
|
|
1197
|
+
|
|
1198
|
+
|
|
1199
|
+
|
|
1200
|
+
|
|
1201
|
+
|
|
1202
|
+
|
|
1203
|
+
|
|
1204
|
+
|
|
1205
|
+
|
|
1206
|
+
|
|
1207
|
+
|
|
1208
|
+
|
|
1209
|
+
|
|
1210
|
+
|
|
1211
|
+
|
|
1212
|
+
|
|
1213
|
+
|
|
1214
|
+
|
|
1215
|
+
|
|
1216
|
+
|
|
1217
|
+
|
|
1218
|
+
exports.ENC_KEY_ALGS = ENC_KEY_ALGS; exports.JWK_JCS_PUB_NAME = JWK_JCS_PUB_NAME; exports.JWK_JCS_PUB_PREFIX = JWK_JCS_PUB_PREFIX; exports.JwkKeyUse = JwkKeyUse; exports.Key = Key; exports.SIG_KEY_ALGS = SIG_KEY_ALGS; exports.asn1DerToRawPublicKey = asn1DerToRawPublicKey; exports.calculateJwkThumbprint = calculateJwkThumbprint; exports.calculateJwkThumbprintForKey = calculateJwkThumbprintForKey; exports.coseKeyToJwk = coseKeyToJwk; exports.coseToJoseCurve = coseToJoseCurve; exports.coseToJoseKeyOperation = coseToJoseKeyOperation; exports.coseToJoseKty = coseToJoseKty; exports.coseToJoseSignatureAlg = coseToJoseSignatureAlg; exports.digestMethodParams = digestMethodParams; exports.generatePrivateKeyHex = generatePrivateKeyHex; exports.getKms = getKms; exports.globalCrypto = globalCrypto; exports.hexStringFromUint8Array = hexStringFromUint8Array; exports.importProvidedOrGeneratedKey = importProvidedOrGeneratedKey; exports.isAsn1Der = isAsn1Der; exports.isRawCompressedPublicKey = isRawCompressedPublicKey; exports.jcsCanonicalize = jcsCanonicalize; exports.joseToCoseCurve = joseToCoseCurve; exports.joseToCoseKeyOperation = joseToCoseKeyOperation; exports.joseToCoseKty = joseToCoseKty; exports.joseToCoseSignatureAlg = joseToCoseSignatureAlg; exports.jwkDetermineUse = jwkDetermineUse; exports.jwkJcsDecode = jwkJcsDecode; exports.jwkJcsEncode = jwkJcsEncode; exports.jwkToCoseKey = jwkToCoseKey; exports.jwkToRawHexKey = jwkToRawHexKey; exports.keyTypeFromCryptographicSuite = keyTypeFromCryptographicSuite; exports.logger = logger; exports.minimalJwk = minimalJwk; exports.padLeft = padLeft; exports.removeNulls = removeNulls; exports.sanitizedJwk = sanitizedJwk; exports.shaHasher = shaHasher; exports.signatureAlgorithmFromKey = signatureAlgorithmFromKey; exports.signatureAlgorithmFromKeyType = signatureAlgorithmFromKeyType; exports.toBase64url = toBase64url; exports.toJwk = toJwk; exports.toJwkFromKey = toJwkFromKey; exports.toRawCompressedHexPublicKey = toRawCompressedHexPublicKey; exports.validateJwk = validateJwk; exports.verifyRawSignature = verifyRawSignature;
|
|
1219
|
+
//# sourceMappingURL=index.cjs.map
|