@sphereon/ssi-sdk-ext.key-utils 0.26.1-next.3 → 0.26.1-next.30
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/conversion.d.ts.map +1 -1
- package/dist/conversion.js +3 -2
- package/dist/conversion.js.map +1 -1
- package/dist/digest-methods.d.ts +3 -1
- package/dist/digest-methods.d.ts.map +1 -1
- package/dist/digest-methods.js +18 -7
- package/dist/digest-methods.js.map +1 -1
- package/dist/functions.d.ts +17 -4
- package/dist/functions.d.ts.map +1 -1
- package/dist/functions.js +243 -30
- package/dist/functions.js.map +1 -1
- package/dist/jwk-jcs.d.ts +14 -22
- package/dist/jwk-jcs.d.ts.map +1 -1
- package/dist/jwk-jcs.js +18 -14
- package/dist/jwk-jcs.js.map +1 -1
- package/dist/types/key-util-types.d.ts +5 -3
- package/dist/types/key-util-types.d.ts.map +1 -1
- package/package.json +6 -5
- package/src/conversion.ts +5 -4
- package/src/digest-methods.ts +15 -3
- package/src/functions.ts +270 -43
- package/src/jwk-jcs.ts +21 -13
- package/src/types/key-util-types.ts +5 -3
package/dist/conversion.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../src/conversion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EACvB,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,GAAG,EACH,UAAU,EACV,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;
|
|
1
|
+
{"version":3,"file":"conversion.d.ts","sourceRoot":"","sources":["../src/conversion.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,UAAU,EACV,YAAY,EACZ,iBAAiB,EACjB,YAAY,EACZ,uBAAuB,EACvB,SAAS,EACT,eAAe,EACf,gBAAgB,EAChB,sBAAsB,EACtB,sBAAsB,EACtB,4BAA4B,EAC5B,GAAG,EACH,UAAU,EACV,gBAAgB,EACjB,MAAM,qBAAqB,CAAA;AAG5B,wBAAgB,YAAY,CAAC,OAAO,EAAE,YAAY,GAAG,GAAG,CAWvD;AAED,wBAAgB,YAAY,CAAC,GAAG,EAAE,GAAG,GAAG,YAAY,CAWnD;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,YAAY,GAAG,UAAU,CAa3D;AAED,wBAAgB,aAAa,CAAC,GAAG,EAAE,UAAU,GAAG,gBAAgB,GAAG,YAAY,CAa9E;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,uBAAuB,GAAG,sBAAsB,CA2B/F;AAED,wBAAgB,sBAAsB,CAAC,OAAO,EAAE,sBAAsB,GAAG,4BAA4B,GAAG,uBAAuB,CA2B9H;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,gBAAgB,GAAG,sBAAsB,GAAG,iBAAiB,CAqB1G;AAED,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,iBAAiB,GAAG,gBAAgB,CAqBjF;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,SAAS,GAAG,eAAe,GAAG,UAAU,CAqB9E;AAED,wBAAgB,eAAe,CAAC,KAAK,EAAE,UAAU,GAAG,SAAS,CAqB5D"}
|
package/dist/conversion.js
CHANGED
|
@@ -22,13 +22,14 @@ exports.coseToJoseKeyOperation = coseToJoseKeyOperation;
|
|
|
22
22
|
exports.joseToCoseCurve = joseToCoseCurve;
|
|
23
23
|
exports.coseToJoseCurve = coseToJoseCurve;
|
|
24
24
|
const ssi_types_1 = require("@sphereon/ssi-types");
|
|
25
|
+
const functions_1 = require("./functions");
|
|
25
26
|
function coseKeyToJwk(coseKey) {
|
|
26
27
|
const { x5chain, key_ops, crv, alg, baseIV, kty } = coseKey, rest = __rest(coseKey, ["x5chain", "key_ops", "crv", "alg", "baseIV", "kty"]);
|
|
27
|
-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, rest), { kty: coseToJoseKty(kty) }), (crv && { crv: coseToJoseCurve(crv) })), (key_ops && { key_ops: key_ops.map(coseToJoseKeyOperation) })), (alg && { alg: coseToJoseSignatureAlg(alg) })), (baseIV && { iv: baseIV })), (x5chain && { x5c: x5chain }));
|
|
28
|
+
return (0, functions_1.removeNulls)(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, rest), { kty: coseToJoseKty(kty) }), (crv && { crv: coseToJoseCurve(crv) })), (key_ops && { key_ops: key_ops.map(coseToJoseKeyOperation) })), (alg && { alg: coseToJoseSignatureAlg(alg) })), (baseIV && { iv: baseIV })), (x5chain && { x5c: x5chain })));
|
|
28
29
|
}
|
|
29
30
|
function jwkToCoseKey(jwk) {
|
|
30
31
|
const { x5c, key_ops, crv, alg, iv, kty } = jwk, rest = __rest(jwk, ["x5c", "key_ops", "crv", "alg", "iv", "kty"]);
|
|
31
|
-
return Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, rest), { kty: joseToCoseKty(kty) }), (crv && { crv: joseToCoseCurve(crv) })), (key_ops && { key_ops: key_ops.map(joseToCoseKeyOperation) })), (alg && { alg: joseToCoseSignatureAlg(alg) })), (iv && { baseIV: iv })), (x5c && { x5chain: x5c }));
|
|
32
|
+
return (0, functions_1.removeNulls)(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign(Object.assign({}, rest), { kty: joseToCoseKty(kty) }), (crv && { crv: joseToCoseCurve(crv) })), (key_ops && { key_ops: key_ops.map(joseToCoseKeyOperation) })), (alg && { alg: joseToCoseSignatureAlg(alg) })), (iv && { baseIV: iv })), (x5c && { x5chain: x5c })));
|
|
32
33
|
}
|
|
33
34
|
function coseToJoseKty(kty) {
|
|
34
35
|
switch (kty) {
|
package/dist/conversion.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"conversion.js","sourceRoot":"","sources":["../src/conversion.ts"],"names":[],"mappings":";;;;;;;;;;;;;
|
|
1
|
+
{"version":3,"file":"conversion.js","sourceRoot":"","sources":["../src/conversion.ts"],"names":[],"mappings":";;;;;;;;;;;;;AAkBA,oCAWC;AAED,oCAWC;AAED,sCAaC;AAED,sCAaC;AAED,wDA2BC;AAED,wDA2BC;AAED,wDAqBC;AAED,wDAqBC;AAED,0CAqBC;AAED,0CAqBC;AA9ND,mDAe4B;AAC5B,2CAAyC;AAEzC,SAAgB,YAAY,CAAC,OAAqB;IAChD,MAAM,EAAE,OAAO,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,MAAM,EAAE,GAAG,KAAc,OAAO,EAAhB,IAAI,UAAK,OAAO,EAA9D,qDAAoD,CAAU,CAAA;IACpE,OAAO,IAAA,uBAAW,wGACb,IAAI,KACP,GAAG,EAAE,aAAa,CAAC,GAAG,CAAC,KACpB,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,eAAe,CAAC,GAAG,CAAC,EAAE,CAAC,GACtC,CAAC,OAAO,IAAI,EAAE,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,sBAAsB,CAAC,EAAE,CAAC,GAC7D,CAAC,GAAG,IAAI,EAAE,GAAG,EAAE,sBAAsB,CAAC,GAAG,CAAC,EAAE,CAAC,GAC7C,CAAC,MAAM,IAAI,EAAE,EAAE,EAAE,MAAM,EAAE,CAAC,GAC1B,CAAC,OAAO,IAAI,EAAE,GAAG,EAAE,OAAO,EAAE,CAAC,EAClB,CAAA;AAClB,CAAC;AAED,SAAgB,YAAY,CAAC,GAAQ;IACnC,MAAM,EAAE,GAAG,EAAE,OAAO,EAAE,GAAG,EAAE,GAAG,EAAE,EAAE,EAAE,GAAG,KAAc,GAAG,EAAZ,IAAI,UAAK,GAAG,EAAlD,6CAA4C,CAAM,CAAA;IACxD,OAAO,IAAA,uBAAW,EAAC,sGACd,IAAI,KACP,GAAG,EAAE,aAAa,CAAC,GAAG,CAAC,KACpB,CAAC,GAA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AAC,MAAM;YACpB,OAAO,qBAAS,CAAC,MAAM,CAAA;QACzB,KAAK,sBAAU,CAAC,IAAI;YAClB,OAAO,qBAAS,CAAC,IAAI,CAAA;QACvB,KAAK,sBAAU,CAAC,OAAO;YACrB,OAAO,qBAAS,CAAC,OAAO,CAAA;QAC1B,KAAK,sBAAU,CAAC,KAAK;YACnB,OAAO,qBAAS,CAAC,KAAK,CAAA;QACxB,KAAK,sBAAU,CAAC,SAAS;YACvB,OAAO,qBAAS,CAAC,SAAS,CAAA;QAC5B;YACE,MAAM,KAAK,CAAC,SAAS,KAAK,wBAAwB,CAAC,CAAA;IACvD,CAAC;AACH,CAAC"}
|
package/dist/digest-methods.d.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
import { Hasher } from '@sphereon/ssi-types';
|
|
1
2
|
import { SupportedEncodings } from 'uint8arrays/to-string';
|
|
2
|
-
export type HashAlgorithm = 'SHA-256' | 'SHA-512';
|
|
3
|
+
export type HashAlgorithm = 'SHA-256' | 'SHA-384' | 'SHA-512';
|
|
3
4
|
export type TDigestMethod = (input: string, encoding?: SupportedEncodings) => string;
|
|
4
5
|
export declare const digestMethodParams: (hashAlgorithm: HashAlgorithm) => {
|
|
5
6
|
hashAlgorithm: HashAlgorithm;
|
|
6
7
|
digestMethod: TDigestMethod;
|
|
7
8
|
hash: (data: Uint8Array) => Uint8Array;
|
|
8
9
|
};
|
|
10
|
+
export declare const shaHasher: Hasher;
|
|
9
11
|
//# sourceMappingURL=digest-methods.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest-methods.d.ts","sourceRoot":"","sources":["../src/digest-methods.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"digest-methods.d.ts","sourceRoot":"","sources":["../src/digest-methods.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,MAAM,EAAE,MAAM,qBAAqB,CAAA;AAE5C,OAAO,EAAE,kBAAkB,EAAE,MAAM,uBAAuB,CAAA;AAE1D,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG,SAAS,GAAG,SAAS,CAAA;AAC7D,MAAM,MAAM,aAAa,GAAG,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,kBAAkB,KAAK,MAAM,CAAA;AAEpF,eAAO,MAAM,kBAAkB,kBACd,aAAa,KAC3B;IAAE,aAAa,EAAE,aAAa,CAAC;IAAC,YAAY,EAAE,aAAa,CAAC;IAAC,IAAI,EAAE,CAAC,IAAI,EAAE,UAAU,KAAK,UAAU,CAAA;CAQrG,CAAA;AAED,eAAO,MAAM,SAAS,EAAE,MAGvB,CAAA"}
|
package/dist/digest-methods.js
CHANGED
|
@@ -23,24 +23,35 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.digestMethodParams = void 0;
|
|
27
|
-
const sha256_1 = require("@
|
|
28
|
-
const sha512_1 = require("@
|
|
26
|
+
exports.shaHasher = exports.digestMethodParams = void 0;
|
|
27
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
28
|
+
const sha512_1 = require("@noble/hashes/sha512");
|
|
29
29
|
const u8a = __importStar(require("uint8arrays"));
|
|
30
30
|
const digestMethodParams = (hashAlgorithm) => {
|
|
31
31
|
if (hashAlgorithm === 'SHA-256') {
|
|
32
|
-
return { hashAlgorithm: 'SHA-256', digestMethod: sha256DigestMethod, hash: sha256_1.
|
|
32
|
+
return { hashAlgorithm: 'SHA-256', digestMethod: sha256DigestMethod, hash: sha256_1.sha256 };
|
|
33
|
+
}
|
|
34
|
+
else if (hashAlgorithm === 'SHA-384') {
|
|
35
|
+
return { hashAlgorithm: 'SHA-384', digestMethod: sha384DigestMethod, hash: sha512_1.sha384 };
|
|
33
36
|
}
|
|
34
37
|
else {
|
|
35
|
-
return { hashAlgorithm: 'SHA-512', digestMethod: sha512DigestMethod, hash: sha512_1.
|
|
38
|
+
return { hashAlgorithm: 'SHA-512', digestMethod: sha512DigestMethod, hash: sha512_1.sha512 };
|
|
36
39
|
}
|
|
37
40
|
};
|
|
38
41
|
exports.digestMethodParams = digestMethodParams;
|
|
42
|
+
const shaHasher = (input, alg) => {
|
|
43
|
+
const hashAlgorithm = alg.includes('384') ? 'SHA-384' : alg.includes('512') ? 'SHA-512' : 'SHA-256';
|
|
44
|
+
return (0, exports.digestMethodParams)(hashAlgorithm).hash(u8a.fromString(input, 'utf-8'));
|
|
45
|
+
};
|
|
46
|
+
exports.shaHasher = shaHasher;
|
|
39
47
|
const sha256DigestMethod = (input, encoding = 'base16') => {
|
|
40
|
-
return u8a.toString((0, sha256_1.
|
|
48
|
+
return u8a.toString((0, sha256_1.sha256)(u8a.fromString(input, 'utf-8')), encoding);
|
|
49
|
+
};
|
|
50
|
+
const sha384DigestMethod = (input, encoding = 'base16') => {
|
|
51
|
+
return u8a.toString((0, sha512_1.sha384)(u8a.fromString(input, 'utf-8')), encoding);
|
|
41
52
|
};
|
|
42
53
|
const sha512DigestMethod = (input, encoding = 'base16') => {
|
|
43
|
-
return u8a.toString((0, sha512_1.
|
|
54
|
+
return u8a.toString((0, sha512_1.sha512)(u8a.fromString(input, 'utf-8')), encoding);
|
|
44
55
|
};
|
|
45
56
|
/*
|
|
46
57
|
// PKCS#1 (PSS) mask generation function
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"digest-methods.js","sourceRoot":"","sources":["../src/digest-methods.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,
|
|
1
|
+
{"version":3,"file":"digest-methods.js","sourceRoot":"","sources":["../src/digest-methods.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAA6C;AAC7C,iDAAqD;AAErD,iDAAkC;AAM3B,MAAM,kBAAkB,GAAG,CAChC,aAA4B,EAC2E,EAAE;IACzG,IAAI,aAAa,KAAK,SAAS,EAAE,CAA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KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;AACvE,CAAC,CAAA;AAED,MAAM,kBAAkB,GAAG,CAAC,KAAa,EAAE,WAA+B,QAAQ,EAAU,EAAE;IAC5F,OAAO,GAAG,CAAC,QAAQ,CAAC,IAAA,eAAM,EAAC,GAAG,CAAC,UAAU,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC,EAAE,QAAQ,CAAC,CAAA;AACvE,CAAC,CAAA;AAED;;;;;;;;;;;;;;;;;GAiBG;AAEH;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EA+BE"}
|
package/dist/functions.d.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { JoseSignatureAlgorithm, JWK } from '@sphereon/ssi-types';
|
|
2
2
|
import { IAgentContext, IKey, IKeyManager, ManagedKeyInfo, MinimalImportableKey } from '@veramo/core';
|
|
3
|
-
import { JsonWebKey } from 'did-resolver';
|
|
4
3
|
import { IImportProvidedOrGeneratedKeyArgs, JwkKeyUse, KeyTypeFromCryptographicSuiteArgs, SignatureAlgorithmFromKeyArgs, SignatureAlgorithmFromKeyTypeArgs, TKeyType } from './types';
|
|
5
4
|
export declare const logger: import("@sphereon/ssi-types").ISimpleLogger<unknown>;
|
|
6
5
|
/**
|
|
@@ -56,6 +55,13 @@ export declare const toJwk: (publicKeyHex: string, type: TKeyType, opts?: {
|
|
|
56
55
|
isPrivateKey?: boolean;
|
|
57
56
|
noKidThumbprint?: boolean;
|
|
58
57
|
}) => JWK;
|
|
58
|
+
/**
|
|
59
|
+
* Convert a JWK to a raw hex key.
|
|
60
|
+
* Currently supports `RSA` and `EC` keys. Extendable for other key types.
|
|
61
|
+
* @param jwk - The JSON Web Key object.
|
|
62
|
+
* @returns A string representing the key in raw hexadecimal format.
|
|
63
|
+
*/
|
|
64
|
+
export declare const jwkToRawHexKey: (jwk: JWK) => Promise<string>;
|
|
59
65
|
/**
|
|
60
66
|
* Determines the use param based upon the key/signature type or supplied use value.
|
|
61
67
|
*
|
|
@@ -76,10 +82,17 @@ export declare const hexStringFromUint8Array: (value: Uint8Array) => string;
|
|
|
76
82
|
export declare const signatureAlgorithmFromKey: (args: SignatureAlgorithmFromKeyArgs) => Promise<JoseSignatureAlgorithm>;
|
|
77
83
|
export declare const signatureAlgorithmFromKeyType: (args: SignatureAlgorithmFromKeyTypeArgs) => JoseSignatureAlgorithm;
|
|
78
84
|
export declare const keyTypeFromCryptographicSuite: (args: KeyTypeFromCryptographicSuiteArgs) => TKeyType;
|
|
79
|
-
export declare function
|
|
85
|
+
export declare function removeNulls<T>(obj: T | any): any;
|
|
86
|
+
export declare const globalCrypto: (setGlobal: boolean, suppliedCrypto?: Crypto) => Crypto;
|
|
87
|
+
/**
|
|
88
|
+
*
|
|
89
|
+
*/
|
|
90
|
+
export declare function verifyRawSignature({ data, signature, key: inputKey, opts, }: {
|
|
80
91
|
data: Uint8Array;
|
|
81
92
|
signature: Uint8Array;
|
|
82
|
-
key:
|
|
83
|
-
|
|
93
|
+
key: JWK;
|
|
94
|
+
opts?: {
|
|
95
|
+
signatureAlg?: JoseSignatureAlgorithm;
|
|
96
|
+
};
|
|
84
97
|
}): Promise<boolean>;
|
|
85
98
|
//# sourceMappingURL=functions.d.ts.map
|
package/dist/functions.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"functions.d.ts","sourceRoot":"","sources":["../src/functions.ts"],"names":[],"mappings":"AAWA,OAAO,EAAa,sBAAsB,EAAE,GAAG,EAAuB,MAAM,qBAAqB,CAAA;AAEjG,OAAO,EAAE,aAAa,EAAE,IAAI,EAAE,WAAW,EAAE,cAAc,EAAE,oBAAoB,EAAE,MAAM,cAAc,CAAA;AAQrG,OAAO,EAEL,iCAAiC,EACjC,SAAS,EACT,iCAAiC,EAEjC,6BAA6B,EAC7B,iCAAi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AE,GAAG,CAAA;IACR,IAAI,CAAC,EAAE;QACL,YAAY,CAAC,EAAE,sBAAsB,CAAA;KACtC,CAAA;CACF,oBAsFA"}
|
package/dist/functions.js
CHANGED
|
@@ -35,16 +35,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
35
35
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
36
|
};
|
|
37
37
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.keyTypeFromCryptographicSuite = exports.signatureAlgorithmFromKeyType = exports.signatureAlgorithmFromKey = exports.hexStringFromUint8Array = exports.toRawCompressedHexPublicKey = exports.isRawCompressedPublicKey = exports.asn1DerToRawPublicKey = exports.isAsn1Der = exports.padLeft = exports.jwkDetermineUse = exports.toJwk = exports.toJwkFromKey = exports.calculateJwkThumbprint = exports.toBase64url = exports.calculateJwkThumbprintForKey = exports.generatePrivateKeyHex = exports.getKms = exports.logger = void 0;
|
|
38
|
+
exports.globalCrypto = exports.keyTypeFromCryptographicSuite = exports.signatureAlgorithmFromKeyType = exports.signatureAlgorithmFromKey = exports.hexStringFromUint8Array = exports.toRawCompressedHexPublicKey = exports.isRawCompressedPublicKey = exports.asn1DerToRawPublicKey = exports.isAsn1Der = exports.padLeft = exports.jwkDetermineUse = exports.jwkToRawHexKey = exports.toJwk = exports.toJwkFromKey = exports.calculateJwkThumbprint = exports.toBase64url = exports.calculateJwkThumbprintForKey = exports.generatePrivateKeyHex = exports.getKms = exports.logger = void 0;
|
|
39
39
|
exports.importProvidedOrGeneratedKey = importProvidedOrGeneratedKey;
|
|
40
|
-
exports.
|
|
40
|
+
exports.removeNulls = removeNulls;
|
|
41
|
+
exports.verifyRawSignature = verifyRawSignature;
|
|
41
42
|
const random_1 = require("@ethersproject/random");
|
|
43
|
+
// Do not change these require statements to imports before we change to ESM. Breaks external CJS packages depending on this module
|
|
44
|
+
const bls12_381_1 = require("@noble/curves/bls12-381");
|
|
45
|
+
const ed25519_1 = require("@noble/curves/ed25519");
|
|
46
|
+
const p256_1 = require("@noble/curves/p256");
|
|
47
|
+
const p384_1 = require("@noble/curves/p384");
|
|
48
|
+
const p521_1 = require("@noble/curves/p521");
|
|
49
|
+
const secp256k1_1 = require("@noble/curves/secp256k1");
|
|
50
|
+
const sha256_1 = require("@noble/hashes/sha256");
|
|
51
|
+
const sha512_1 = require("@noble/hashes/sha512");
|
|
42
52
|
const ssi_sdk_ext_x509_utils_1 = require("@sphereon/ssi-sdk-ext.x509-utils");
|
|
43
53
|
const ssi_types_1 = require("@sphereon/ssi-types");
|
|
44
|
-
const
|
|
54
|
+
const ed25519_2 = require("@stablelib/ed25519");
|
|
45
55
|
const elliptic_1 = __importDefault(require("elliptic"));
|
|
56
|
+
const rsa = __importStar(require("micro-rsa-dsa-dh/rsa.js"));
|
|
46
57
|
const u8a = __importStar(require("uint8arrays"));
|
|
47
58
|
const digest_methods_1 = require("./digest-methods");
|
|
59
|
+
const jwk_jcs_1 = require("./jwk-jcs");
|
|
48
60
|
const types_1 = require("./types");
|
|
49
61
|
exports.logger = ssi_types_1.Loggers.DEFAULT.get('sphereon:key-utils');
|
|
50
62
|
/**
|
|
@@ -71,7 +83,7 @@ exports.getKms = getKms;
|
|
|
71
83
|
const generatePrivateKeyHex = (type) => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
84
|
switch (type) {
|
|
73
85
|
case 'Ed25519': {
|
|
74
|
-
const keyPairEd25519 = (0,
|
|
86
|
+
const keyPairEd25519 = (0, ed25519_2.generateKeyPair)();
|
|
75
87
|
return u8a.toString(keyPairEd25519.secretKey, 'base16');
|
|
76
88
|
}
|
|
77
89
|
// The Secp256 types use the same method to generate the key
|
|
@@ -243,6 +255,81 @@ const toJwk = (publicKeyHex, type, opts) => {
|
|
|
243
255
|
return jwk;
|
|
244
256
|
};
|
|
245
257
|
exports.toJwk = toJwk;
|
|
258
|
+
/**
|
|
259
|
+
* Convert a JWK to a raw hex key.
|
|
260
|
+
* Currently supports `RSA` and `EC` keys. Extendable for other key types.
|
|
261
|
+
* @param jwk - The JSON Web Key object.
|
|
262
|
+
* @returns A string representing the key in raw hexadecimal format.
|
|
263
|
+
*/
|
|
264
|
+
const jwkToRawHexKey = (jwk) => __awaiter(void 0, void 0, void 0, function* () {
|
|
265
|
+
// TODO: Probably makes sense to have an option to do the same for private keys
|
|
266
|
+
if (jwk.kty === 'RSA') {
|
|
267
|
+
return rsaJwkToRawHexKey(jwk);
|
|
268
|
+
}
|
|
269
|
+
else if (jwk.kty === 'EC') {
|
|
270
|
+
return '04' + ecJwkToRawHexKey(jwk);
|
|
271
|
+
}
|
|
272
|
+
else if (jwk.kty === 'OKP') {
|
|
273
|
+
return okpJwkToRawHexKey(jwk);
|
|
274
|
+
}
|
|
275
|
+
else if (jwk.kty === 'oct') {
|
|
276
|
+
return octJwkToRawHexKey(jwk);
|
|
277
|
+
}
|
|
278
|
+
else {
|
|
279
|
+
throw new Error(`Unsupported key type: ${jwk.kty}`);
|
|
280
|
+
}
|
|
281
|
+
});
|
|
282
|
+
exports.jwkToRawHexKey = jwkToRawHexKey;
|
|
283
|
+
/**
|
|
284
|
+
* Convert an RSA JWK to a raw hex key.
|
|
285
|
+
* @param jwk - The RSA JWK object.
|
|
286
|
+
* @returns A string representing the RSA key in raw hexadecimal format.
|
|
287
|
+
*/
|
|
288
|
+
function rsaJwkToRawHexKey(jwk) {
|
|
289
|
+
if (!jwk.n || !jwk.e) {
|
|
290
|
+
throw new Error("RSA JWK must contain 'n' and 'e' properties.");
|
|
291
|
+
}
|
|
292
|
+
const modulus = u8a.fromString(jwk.n, 'base64url'); // 'n' is the modulus
|
|
293
|
+
const exponent = u8a.fromString(jwk.e, 'base64url'); // 'e' is the exponent
|
|
294
|
+
return u8a.toString(modulus, 'hex') + u8a.toString(exponent, 'hex');
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Convert an EC JWK to a raw hex key.
|
|
298
|
+
* @param jwk - The EC JWK object.
|
|
299
|
+
* @returns A string representing the EC key in raw hexadecimal format.
|
|
300
|
+
*/
|
|
301
|
+
function ecJwkToRawHexKey(jwk) {
|
|
302
|
+
if (!jwk.x || !jwk.y) {
|
|
303
|
+
throw new Error("EC JWK must contain 'x' and 'y' properties.");
|
|
304
|
+
}
|
|
305
|
+
const x = u8a.fromString(jwk.x, 'base64url');
|
|
306
|
+
const y = u8a.fromString(jwk.y, 'base64url');
|
|
307
|
+
return u8a.toString(x, 'hex') + u8a.toString(y, 'hex');
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* Convert an EC JWK to a raw hex key.
|
|
311
|
+
* @param jwk - The EC JWK object.
|
|
312
|
+
* @returns A string representing the EC key in raw hexadecimal format.
|
|
313
|
+
*/
|
|
314
|
+
function okpJwkToRawHexKey(jwk) {
|
|
315
|
+
if (!jwk.x) {
|
|
316
|
+
throw new Error("OKP JWK must contain 'x' property.");
|
|
317
|
+
}
|
|
318
|
+
const x = u8a.fromString(jwk.x, 'base64url');
|
|
319
|
+
return u8a.toString(x, 'hex');
|
|
320
|
+
}
|
|
321
|
+
/**
|
|
322
|
+
* Convert an octet JWK to a raw hex key.
|
|
323
|
+
* @param jwk - The octet JWK object.
|
|
324
|
+
* @returns A string representing the octet key in raw hexadecimal format.
|
|
325
|
+
*/
|
|
326
|
+
function octJwkToRawHexKey(jwk) {
|
|
327
|
+
if (!jwk.k) {
|
|
328
|
+
throw new Error("Octet JWK must contain 'k' property.");
|
|
329
|
+
}
|
|
330
|
+
const key = u8a.fromString(jwk.k, 'base64url');
|
|
331
|
+
return u8a.toString(key, 'hex');
|
|
332
|
+
}
|
|
246
333
|
/**
|
|
247
334
|
* Determines the use param based upon the key/signature type or supplied use value.
|
|
248
335
|
*
|
|
@@ -331,15 +418,28 @@ const toEd25519OrX25519Jwk = (publicKeyHex, opts) => {
|
|
|
331
418
|
return Object.assign(Object.assign({ alg: ssi_types_1.JoseSignatureAlgorithm.EdDSA }, (use !== undefined && { use })), { kty: ssi_types_1.JwkKeyType.OKP, crv: (_a = opts === null || opts === void 0 ? void 0 : opts.crv) !== null && _a !== void 0 ? _a : ssi_types_1.JoseCurve.Ed25519, x: (0, ssi_sdk_ext_x509_utils_1.hexToBase64)(publicKeyHex, 'base64url') });
|
|
332
419
|
};
|
|
333
420
|
const toRSAJwk = (publicKeyHex, opts) => {
|
|
334
|
-
var _a, _b
|
|
335
|
-
const
|
|
421
|
+
var _a, _b;
|
|
422
|
+
const meta = (_a = opts === null || opts === void 0 ? void 0 : opts.key) === null || _a === void 0 ? void 0 : _a.meta;
|
|
423
|
+
if ((meta === null || meta === void 0 ? void 0 : meta.publicKeyJwk) || (meta === null || meta === void 0 ? void 0 : meta.publicKeyPEM)) {
|
|
424
|
+
if (meta === null || meta === void 0 ? void 0 : meta.publicKeyJwk) {
|
|
425
|
+
return meta.publicKeyJwk;
|
|
426
|
+
}
|
|
427
|
+
const publicKeyPEM = (_b = meta === null || meta === void 0 ? void 0 : meta.publicKeyPEM) !== null && _b !== void 0 ? _b : (0, ssi_sdk_ext_x509_utils_1.hexToPEM)(publicKeyHex, 'public');
|
|
428
|
+
return (0, ssi_sdk_ext_x509_utils_1.PEMToJwk)(publicKeyPEM, 'public');
|
|
429
|
+
}
|
|
430
|
+
// exponent (e) is 5 chars long, rest is modulus (n)
|
|
336
431
|
// const publicKey = publicKeyHex
|
|
337
432
|
// assertProperKeyLength(publicKey, [2048, 3072, 4096])
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
const
|
|
342
|
-
return
|
|
433
|
+
const exponent = publicKeyHex.slice(-5);
|
|
434
|
+
const modulus = publicKeyHex.slice(0, -5);
|
|
435
|
+
// const modulusBitLength = (modulus.length / 2) * 8
|
|
436
|
+
// const alg = modulusBitLength === 2048 ? JoseSignatureAlgorithm.RS256 : modulusBitLength === 3072 ? JoseSignatureAlgorithm.RS384 : modulusBitLength === 4096 ? JoseSignatureAlgorithm.RS512 : undefined
|
|
437
|
+
return {
|
|
438
|
+
kty: 'RSA',
|
|
439
|
+
n: (0, ssi_sdk_ext_x509_utils_1.hexToBase64)(modulus, 'base64url'),
|
|
440
|
+
e: (0, ssi_sdk_ext_x509_utils_1.hexToBase64)(exponent, 'base64url'),
|
|
441
|
+
// ...(alg && { alg }),
|
|
442
|
+
};
|
|
343
443
|
};
|
|
344
444
|
const padLeft = (args) => {
|
|
345
445
|
var _a, _b;
|
|
@@ -432,7 +532,7 @@ const isRawCompressedPublicKey = (key) => key.length === 33 && (key[0] === 0x02
|
|
|
432
532
|
exports.isRawCompressedPublicKey = isRawCompressedPublicKey;
|
|
433
533
|
const toRawCompressedHexPublicKey = (rawPublicKey, keyType) => {
|
|
434
534
|
if ((0, exports.isRawCompressedPublicKey)(rawPublicKey)) {
|
|
435
|
-
|
|
535
|
+
return (0, exports.hexStringFromUint8Array)(rawPublicKey);
|
|
436
536
|
}
|
|
437
537
|
if (keyType === 'Secp256k1' || keyType === 'Secp256r1') {
|
|
438
538
|
if (rawPublicKey[0] === 0x04 && rawPublicKey.length === 65) {
|
|
@@ -467,6 +567,10 @@ const signatureAlgorithmFromKeyType = (args) => {
|
|
|
467
567
|
return ssi_types_1.JoseSignatureAlgorithm.EdDSA;
|
|
468
568
|
case 'Secp256r1':
|
|
469
569
|
return ssi_types_1.JoseSignatureAlgorithm.ES256;
|
|
570
|
+
case 'Secp384r1':
|
|
571
|
+
return ssi_types_1.JoseSignatureAlgorithm.ES384;
|
|
572
|
+
case 'Secp521r1':
|
|
573
|
+
return ssi_types_1.JoseSignatureAlgorithm.ES512;
|
|
470
574
|
case 'Secp256k1':
|
|
471
575
|
return ssi_types_1.JoseSignatureAlgorithm.ES256K;
|
|
472
576
|
default:
|
|
@@ -476,9 +580,20 @@ const signatureAlgorithmFromKeyType = (args) => {
|
|
|
476
580
|
exports.signatureAlgorithmFromKeyType = signatureAlgorithmFromKeyType;
|
|
477
581
|
// TODO improve this conversion for jwt and jsonld, not a fan of current structure
|
|
478
582
|
const keyTypeFromCryptographicSuite = (args) => {
|
|
479
|
-
const {
|
|
480
|
-
switch (
|
|
583
|
+
const { crv, kty, alg } = args;
|
|
584
|
+
switch (alg) {
|
|
585
|
+
case 'RSASSA-PSS':
|
|
586
|
+
case 'RS256':
|
|
587
|
+
case 'RS384':
|
|
588
|
+
case 'RS512':
|
|
589
|
+
case 'PS256':
|
|
590
|
+
case 'PS384':
|
|
591
|
+
case 'PS512':
|
|
592
|
+
return 'RSA';
|
|
593
|
+
}
|
|
594
|
+
switch (crv) {
|
|
481
595
|
case 'EdDSA':
|
|
596
|
+
case 'Ed25519':
|
|
482
597
|
case 'Ed25519Signature2018':
|
|
483
598
|
case 'Ed25519Signature2020':
|
|
484
599
|
case 'JcsEd25519Signature2020':
|
|
@@ -486,31 +601,129 @@ const keyTypeFromCryptographicSuite = (args) => {
|
|
|
486
601
|
case 'JsonWebSignature2020':
|
|
487
602
|
case 'ES256':
|
|
488
603
|
case 'ECDSA':
|
|
604
|
+
case 'P-256':
|
|
489
605
|
return 'Secp256r1';
|
|
606
|
+
case 'ES384':
|
|
607
|
+
case 'P-384':
|
|
608
|
+
return 'Secp384r1';
|
|
609
|
+
case 'ES512':
|
|
610
|
+
case 'P-521':
|
|
611
|
+
return 'Secp521r1';
|
|
490
612
|
case 'EcdsaSecp256k1Signature2019':
|
|
613
|
+
case 'secp256k1':
|
|
491
614
|
case 'ES256K':
|
|
492
615
|
return 'Secp256k1';
|
|
493
|
-
default:
|
|
494
|
-
throw new Error(`Cryptographic suite '${suite}' not supported`);
|
|
495
616
|
}
|
|
617
|
+
if (kty) {
|
|
618
|
+
return kty;
|
|
619
|
+
}
|
|
620
|
+
throw new Error(`Cryptographic suite '${crv}' not supported`);
|
|
496
621
|
};
|
|
497
622
|
exports.keyTypeFromCryptographicSuite = keyTypeFromCryptographicSuite;
|
|
498
|
-
function
|
|
499
|
-
|
|
623
|
+
function removeNulls(obj) {
|
|
624
|
+
Object.keys(obj).forEach((key) => {
|
|
625
|
+
if (obj[key] && typeof obj[key] === 'object')
|
|
626
|
+
removeNulls(obj[key]);
|
|
627
|
+
else if (obj[key] == null)
|
|
628
|
+
delete obj[key];
|
|
629
|
+
});
|
|
630
|
+
return obj;
|
|
631
|
+
}
|
|
632
|
+
const globalCrypto = (setGlobal, suppliedCrypto) => {
|
|
633
|
+
var _a, _b;
|
|
634
|
+
let webcrypto;
|
|
635
|
+
if (typeof suppliedCrypto !== 'undefined') {
|
|
636
|
+
webcrypto = suppliedCrypto;
|
|
637
|
+
}
|
|
638
|
+
else if (typeof crypto !== 'undefined') {
|
|
639
|
+
webcrypto = crypto;
|
|
640
|
+
}
|
|
641
|
+
else if (typeof global.crypto !== 'undefined') {
|
|
642
|
+
webcrypto = global.crypto;
|
|
643
|
+
}
|
|
644
|
+
else if (typeof ((_b = (_a = global.window) === null || _a === void 0 ? void 0 : _a.crypto) === null || _b === void 0 ? void 0 : _b.subtle) !== 'undefined') {
|
|
645
|
+
webcrypto = global.window.crypto;
|
|
646
|
+
}
|
|
647
|
+
else {
|
|
648
|
+
webcrypto = require('crypto');
|
|
649
|
+
}
|
|
650
|
+
if (setGlobal) {
|
|
651
|
+
global.crypto = webcrypto;
|
|
652
|
+
}
|
|
653
|
+
return webcrypto;
|
|
654
|
+
};
|
|
655
|
+
exports.globalCrypto = globalCrypto;
|
|
656
|
+
/**
|
|
657
|
+
*
|
|
658
|
+
*/
|
|
659
|
+
function verifyRawSignature(_a) {
|
|
660
|
+
return __awaiter(this, arguments, void 0, function* ({ data, signature, key: inputKey, opts, }) {
|
|
500
661
|
var _b;
|
|
501
|
-
|
|
502
|
-
|
|
503
|
-
|
|
662
|
+
/**
|
|
663
|
+
* Converts a Base64URL-encoded JWK property to a BigInt.
|
|
664
|
+
* @param jwkProp - The Base64URL-encoded string.
|
|
665
|
+
* @returns The BigInt representation of the decoded value.
|
|
666
|
+
*/
|
|
667
|
+
function jwkPropertyToBigInt(jwkProp) {
|
|
668
|
+
// Decode Base64URL to Uint8Array
|
|
669
|
+
const byteArray = u8a.fromString(jwkProp, 'base64url');
|
|
670
|
+
// Convert Uint8Array to hexadecimal string and then to BigInt
|
|
671
|
+
const hex = u8a.toString(byteArray, 'hex');
|
|
672
|
+
return BigInt(`0x${hex}`);
|
|
673
|
+
}
|
|
674
|
+
const key = removeNulls(inputKey);
|
|
675
|
+
(0, jwk_jcs_1.validateJwk)(key, { crvOptional: true });
|
|
676
|
+
const keyType = (0, exports.keyTypeFromCryptographicSuite)({ crv: key.crv, kty: key.kty, alg: key.alg });
|
|
677
|
+
const publicKeyHex = yield (0, exports.jwkToRawHexKey)(key);
|
|
678
|
+
// TODO: We really should look at the signature alg first if provided! From key type should be the last resort
|
|
679
|
+
switch (keyType) {
|
|
680
|
+
case 'Secp256k1':
|
|
681
|
+
return secp256k1_1.secp256k1.verify(signature, data, publicKeyHex, { format: 'compact', prehash: true });
|
|
682
|
+
case 'Secp256r1':
|
|
683
|
+
return p256_1.p256.verify(signature, data, publicKeyHex, { format: 'compact', prehash: true });
|
|
684
|
+
case 'Secp384r1':
|
|
685
|
+
return p384_1.p384.verify(signature, data, publicKeyHex, { format: 'compact', prehash: true });
|
|
686
|
+
case 'Secp521r1':
|
|
687
|
+
return p521_1.p521.verify(signature, data, publicKeyHex, { format: 'compact', prehash: true });
|
|
688
|
+
case 'Ed25519':
|
|
689
|
+
return ed25519_1.ed25519.verify(signature, data, u8a.fromString(publicKeyHex, 'hex'));
|
|
690
|
+
case 'Bls12381G1':
|
|
691
|
+
case 'Bls12381G2':
|
|
692
|
+
return bls12_381_1.bls12_381.verify(signature, data, u8a.fromString(publicKeyHex, 'hex'));
|
|
693
|
+
case 'RSA': {
|
|
694
|
+
const signatureAlgorithm = (_b = opts === null || opts === void 0 ? void 0 : opts.signatureAlg) !== null && _b !== void 0 ? _b : ssi_types_1.JoseSignatureAlgorithm.PS256;
|
|
695
|
+
const hashAlg = signatureAlgorithm === (ssi_types_1.JoseSignatureAlgorithm.RS512 || ssi_types_1.JoseSignatureAlgorithm.PS512)
|
|
696
|
+
? sha512_1.sha512
|
|
697
|
+
: signatureAlgorithm === (ssi_types_1.JoseSignatureAlgorithm.RS384 || ssi_types_1.JoseSignatureAlgorithm.PS384)
|
|
698
|
+
? sha512_1.sha384
|
|
699
|
+
: sha256_1.sha256;
|
|
700
|
+
switch (signatureAlgorithm) {
|
|
701
|
+
case ssi_types_1.JoseSignatureAlgorithm.RS256:
|
|
702
|
+
return rsa.PKCS1_SHA256.verify({
|
|
703
|
+
n: jwkPropertyToBigInt(key.n),
|
|
704
|
+
e: jwkPropertyToBigInt(key.e),
|
|
705
|
+
}, data, signature);
|
|
706
|
+
case ssi_types_1.JoseSignatureAlgorithm.RS384:
|
|
707
|
+
return rsa.PKCS1_SHA384.verify({
|
|
708
|
+
n: jwkPropertyToBigInt(key.n),
|
|
709
|
+
e: jwkPropertyToBigInt(key.e),
|
|
710
|
+
}, data, signature);
|
|
711
|
+
case ssi_types_1.JoseSignatureAlgorithm.RS512:
|
|
712
|
+
return rsa.PKCS1_SHA512.verify({
|
|
713
|
+
n: jwkPropertyToBigInt(key.n),
|
|
714
|
+
e: jwkPropertyToBigInt(key.e),
|
|
715
|
+
}, data, signature);
|
|
716
|
+
case ssi_types_1.JoseSignatureAlgorithm.PS256:
|
|
717
|
+
case ssi_types_1.JoseSignatureAlgorithm.PS384:
|
|
718
|
+
case ssi_types_1.JoseSignatureAlgorithm.PS512:
|
|
719
|
+
return rsa.PSS(hashAlg, rsa.mgf1(hashAlg)).verify({
|
|
720
|
+
n: jwkPropertyToBigInt(key.n),
|
|
721
|
+
e: jwkPropertyToBigInt(key.e),
|
|
722
|
+
}, data, signature);
|
|
723
|
+
}
|
|
724
|
+
}
|
|
504
725
|
}
|
|
505
|
-
|
|
506
|
-
const publicKey = yield subtle.importKey('jwk', key, {
|
|
507
|
-
name: alg,
|
|
508
|
-
namedCurve: crv,
|
|
509
|
-
}, true, ['verify']);
|
|
510
|
-
return subtle.verify({
|
|
511
|
-
name: alg,
|
|
512
|
-
hash: 'SHA-256', // fixme; make arg
|
|
513
|
-
}, publicKey, signature, data);
|
|
726
|
+
throw Error(`Unsupported key type for signature validation: ${keyType}`);
|
|
514
727
|
});
|
|
515
728
|
}
|
|
516
729
|
//# sourceMappingURL=functions.js.map
|