@sphereon/ssi-sdk-ext.key-utils 0.34.1-fix.80 → 0.34.1-next.299
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 +30 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +3 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.js +31 -16
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/functions.ts +47 -30
- package/src/types/key-util-types.ts +1 -0
package/dist/index.d.cts
CHANGED
|
@@ -28,6 +28,7 @@ interface X509Opts {
|
|
|
28
28
|
certificateChainPEM?: string;
|
|
29
29
|
}
|
|
30
30
|
interface IImportProvidedOrGeneratedKeyArgs {
|
|
31
|
+
providerName: string;
|
|
31
32
|
kms?: string;
|
|
32
33
|
alias?: string;
|
|
33
34
|
options?: IKeyOpts;
|
|
@@ -117,6 +118,7 @@ declare const jwkToRawHexKey: (jwk: JWK) => Promise<string>;
|
|
|
117
118
|
* @returns A string representing the RSA key in raw hexadecimal format.
|
|
118
119
|
*/
|
|
119
120
|
declare function rsaJwkToRawHexKey(jwk: JsonWebKey): string;
|
|
121
|
+
declare function x25519PublicHexFromPrivateHex(privateKeyHex: string): string;
|
|
120
122
|
/**
|
|
121
123
|
* Determines the use param based upon the key/signature type or supplied use value.
|
|
122
124
|
*
|
|
@@ -228,4 +230,4 @@ declare const digestMethodParams: (hashAlgorithm: HashAlgorithm) => {
|
|
|
228
230
|
};
|
|
229
231
|
declare const shaHasher: HasherSync;
|
|
230
232
|
|
|
231
|
-
export { ENC_KEY_ALGS, type HashAlgorithm, type IImportProvidedOrGeneratedKeyArgs, type IKeyOpts, JWK_JCS_PUB_NAME, JWK_JCS_PUB_PREFIX, JwkKeyUse, Key, type KeyTypeFromCryptographicSuiteArgs, type KeyVisibility, SIG_KEY_ALGS, type SignatureAlgorithmFromKeyArgs, type SignatureAlgorithmFromKeyTypeArgs, type TDigestMethod, type TKeyType, type X509Opts, asn1DerToRawPublicKey, calculateJwkThumbprint, calculateJwkThumbprintForKey, coseKeyToJwk, coseToJoseCurve, coseToJoseKeyOperation, coseToJoseKty, coseToJoseSignatureAlg, digestMethodParams, generatePrivateKeyHex, getKms, globalCrypto, hexStringFromUint8Array, importProvidedOrGeneratedKey, isAsn1Der, isRawCompressedPublicKey, jcsCanonicalize, joseToCoseCurve, joseToCoseKeyOperation, joseToCoseKty, joseToCoseSignatureAlg, jwkDetermineUse, jwkJcsDecode, jwkJcsEncode, jwkToCoseKey, jwkToRawHexKey, keyTypeFromCryptographicSuite, logger, minimalJwk, padLeft, removeNulls, rsaJwkToRawHexKey, sanitizedJwk, shaHasher, signatureAlgorithmFromKey, signatureAlgorithmFromKeyType, toBase64url, toJwk, toJwkFromKey, toPkcs1, toPkcs1FromHex, toRawCompressedHexPublicKey, validateJwk, verifyRawSignature };
|
|
233
|
+
export { ENC_KEY_ALGS, type HashAlgorithm, type IImportProvidedOrGeneratedKeyArgs, type IKeyOpts, JWK_JCS_PUB_NAME, JWK_JCS_PUB_PREFIX, JwkKeyUse, Key, type KeyTypeFromCryptographicSuiteArgs, type KeyVisibility, SIG_KEY_ALGS, type SignatureAlgorithmFromKeyArgs, type SignatureAlgorithmFromKeyTypeArgs, type TDigestMethod, type TKeyType, type X509Opts, asn1DerToRawPublicKey, calculateJwkThumbprint, calculateJwkThumbprintForKey, coseKeyToJwk, coseToJoseCurve, coseToJoseKeyOperation, coseToJoseKty, coseToJoseSignatureAlg, digestMethodParams, generatePrivateKeyHex, getKms, globalCrypto, hexStringFromUint8Array, importProvidedOrGeneratedKey, isAsn1Der, isRawCompressedPublicKey, jcsCanonicalize, joseToCoseCurve, joseToCoseKeyOperation, joseToCoseKty, joseToCoseSignatureAlg, jwkDetermineUse, jwkJcsDecode, jwkJcsEncode, jwkToCoseKey, jwkToRawHexKey, keyTypeFromCryptographicSuite, logger, minimalJwk, padLeft, removeNulls, rsaJwkToRawHexKey, sanitizedJwk, shaHasher, signatureAlgorithmFromKey, signatureAlgorithmFromKeyType, toBase64url, toJwk, toJwkFromKey, toPkcs1, toPkcs1FromHex, toRawCompressedHexPublicKey, validateJwk, verifyRawSignature, x25519PublicHexFromPrivateHex };
|
package/dist/index.d.ts
CHANGED
|
@@ -28,6 +28,7 @@ interface X509Opts {
|
|
|
28
28
|
certificateChainPEM?: string;
|
|
29
29
|
}
|
|
30
30
|
interface IImportProvidedOrGeneratedKeyArgs {
|
|
31
|
+
providerName: string;
|
|
31
32
|
kms?: string;
|
|
32
33
|
alias?: string;
|
|
33
34
|
options?: IKeyOpts;
|
|
@@ -117,6 +118,7 @@ declare const jwkToRawHexKey: (jwk: JWK) => Promise<string>;
|
|
|
117
118
|
* @returns A string representing the RSA key in raw hexadecimal format.
|
|
118
119
|
*/
|
|
119
120
|
declare function rsaJwkToRawHexKey(jwk: JsonWebKey): string;
|
|
121
|
+
declare function x25519PublicHexFromPrivateHex(privateKeyHex: string): string;
|
|
120
122
|
/**
|
|
121
123
|
* Determines the use param based upon the key/signature type or supplied use value.
|
|
122
124
|
*
|
|
@@ -228,4 +230,4 @@ declare const digestMethodParams: (hashAlgorithm: HashAlgorithm) => {
|
|
|
228
230
|
};
|
|
229
231
|
declare const shaHasher: HasherSync;
|
|
230
232
|
|
|
231
|
-
export { ENC_KEY_ALGS, type HashAlgorithm, type IImportProvidedOrGeneratedKeyArgs, type IKeyOpts, JWK_JCS_PUB_NAME, JWK_JCS_PUB_PREFIX, JwkKeyUse, Key, type KeyTypeFromCryptographicSuiteArgs, type KeyVisibility, SIG_KEY_ALGS, type SignatureAlgorithmFromKeyArgs, type SignatureAlgorithmFromKeyTypeArgs, type TDigestMethod, type TKeyType, type X509Opts, asn1DerToRawPublicKey, calculateJwkThumbprint, calculateJwkThumbprintForKey, coseKeyToJwk, coseToJoseCurve, coseToJoseKeyOperation, coseToJoseKty, coseToJoseSignatureAlg, digestMethodParams, generatePrivateKeyHex, getKms, globalCrypto, hexStringFromUint8Array, importProvidedOrGeneratedKey, isAsn1Der, isRawCompressedPublicKey, jcsCanonicalize, joseToCoseCurve, joseToCoseKeyOperation, joseToCoseKty, joseToCoseSignatureAlg, jwkDetermineUse, jwkJcsDecode, jwkJcsEncode, jwkToCoseKey, jwkToRawHexKey, keyTypeFromCryptographicSuite, logger, minimalJwk, padLeft, removeNulls, rsaJwkToRawHexKey, sanitizedJwk, shaHasher, signatureAlgorithmFromKey, signatureAlgorithmFromKeyType, toBase64url, toJwk, toJwkFromKey, toPkcs1, toPkcs1FromHex, toRawCompressedHexPublicKey, validateJwk, verifyRawSignature };
|
|
233
|
+
export { ENC_KEY_ALGS, type HashAlgorithm, type IImportProvidedOrGeneratedKeyArgs, type IKeyOpts, JWK_JCS_PUB_NAME, JWK_JCS_PUB_PREFIX, JwkKeyUse, Key, type KeyTypeFromCryptographicSuiteArgs, type KeyVisibility, SIG_KEY_ALGS, type SignatureAlgorithmFromKeyArgs, type SignatureAlgorithmFromKeyTypeArgs, type TDigestMethod, type TKeyType, type X509Opts, asn1DerToRawPublicKey, calculateJwkThumbprint, calculateJwkThumbprintForKey, coseKeyToJwk, coseToJoseCurve, coseToJoseKeyOperation, coseToJoseKty, coseToJoseSignatureAlg, digestMethodParams, generatePrivateKeyHex, getKms, globalCrypto, hexStringFromUint8Array, importProvidedOrGeneratedKey, isAsn1Der, isRawCompressedPublicKey, jcsCanonicalize, joseToCoseCurve, joseToCoseKeyOperation, joseToCoseKty, joseToCoseSignatureAlg, jwkDetermineUse, jwkJcsDecode, jwkJcsEncode, jwkToCoseKey, jwkToRawHexKey, keyTypeFromCryptographicSuite, logger, minimalJwk, padLeft, removeNulls, rsaJwkToRawHexKey, sanitizedJwk, shaHasher, signatureAlgorithmFromKey, signatureAlgorithmFromKeyType, toBase64url, toJwk, toJwkFromKey, toPkcs1, toPkcs1FromHex, toRawCompressedHexPublicKey, validateJwk, verifyRawSignature, x25519PublicHexFromPrivateHex };
|
package/dist/index.js
CHANGED
|
@@ -4,7 +4,7 @@ var __name = (target, value) => __defProp(target, "name", { value, configurable:
|
|
|
4
4
|
// src/functions.ts
|
|
5
5
|
import { randomBytes } from "@ethersproject/random";
|
|
6
6
|
import { bls12_381 } from "@noble/curves/bls12-381";
|
|
7
|
-
import { ed25519 } from "@noble/curves/ed25519";
|
|
7
|
+
import { ed25519, x25519 } from "@noble/curves/ed25519";
|
|
8
8
|
import { p256 } from "@noble/curves/p256";
|
|
9
9
|
import { p384 } from "@noble/curves/p384";
|
|
10
10
|
import { p521 } from "@noble/curves/p521";
|
|
@@ -193,17 +193,17 @@ __name(jcsCanonicalize, "jcsCanonicalize");
|
|
|
193
193
|
// src/types/key-util-types.ts
|
|
194
194
|
var JWK_JCS_PUB_NAME = "jwk_jcs-pub";
|
|
195
195
|
var JWK_JCS_PUB_PREFIX = 60241;
|
|
196
|
-
var Key = /* @__PURE__ */ function(Key2) {
|
|
196
|
+
var Key = /* @__PURE__ */ (function(Key2) {
|
|
197
197
|
Key2["Ed25519"] = "Ed25519";
|
|
198
198
|
Key2["Secp256k1"] = "Secp256k1";
|
|
199
199
|
Key2["Secp256r1"] = "Secp256r1";
|
|
200
200
|
return Key2;
|
|
201
|
-
}({});
|
|
202
|
-
var JwkKeyUse = /* @__PURE__ */ function(JwkKeyUse2) {
|
|
201
|
+
})({});
|
|
202
|
+
var JwkKeyUse = /* @__PURE__ */ (function(JwkKeyUse2) {
|
|
203
203
|
JwkKeyUse2["Encryption"] = "enc";
|
|
204
204
|
JwkKeyUse2["Signature"] = "sig";
|
|
205
205
|
return JwkKeyUse2;
|
|
206
|
-
}({});
|
|
206
|
+
})({});
|
|
207
207
|
var SIG_KEY_ALGS = [
|
|
208
208
|
"ES256",
|
|
209
209
|
"ES384",
|
|
@@ -296,14 +296,19 @@ var keyMetaAlgorithmsFromKeyType = /* @__PURE__ */ __name((type) => {
|
|
|
296
296
|
async function importProvidedOrGeneratedKey(args, context) {
|
|
297
297
|
const type = args.options?.type ?? args.options?.key?.type ?? args.options?.keyType ?? "Secp256r1";
|
|
298
298
|
const key = args?.options?.key;
|
|
299
|
-
if (
|
|
299
|
+
if (key) {
|
|
300
300
|
key.meta = {
|
|
301
|
-
|
|
302
|
-
x509: {
|
|
303
|
-
...args.options.x509,
|
|
304
|
-
...key.meta?.x509
|
|
305
|
-
}
|
|
301
|
+
providerName: args.providerName
|
|
306
302
|
};
|
|
303
|
+
if (args.options?.x509) {
|
|
304
|
+
key.meta = {
|
|
305
|
+
...key.meta,
|
|
306
|
+
x509: {
|
|
307
|
+
...args.options.x509,
|
|
308
|
+
...key.meta?.x509
|
|
309
|
+
}
|
|
310
|
+
};
|
|
311
|
+
}
|
|
307
312
|
}
|
|
308
313
|
if (args.options && args.options?.use === JwkKeyUse.Encryption && !ENC_KEY_ALGS.includes(type)) {
|
|
309
314
|
throw new Error(`${type} keys are not valid for encryption`);
|
|
@@ -550,6 +555,15 @@ function octJwkToRawHexKey(jwk) {
|
|
|
550
555
|
return toString2(key, "hex");
|
|
551
556
|
}
|
|
552
557
|
__name(octJwkToRawHexKey, "octJwkToRawHexKey");
|
|
558
|
+
function x25519PublicHexFromPrivateHex(privateKeyHex) {
|
|
559
|
+
if (!/^[0-9a-fA-F]{64}$/.test(privateKeyHex)) {
|
|
560
|
+
throw new Error("Private key must be 32-byte hex (64 chars)");
|
|
561
|
+
}
|
|
562
|
+
const priv = Uint8Array.from(Buffer.from(privateKeyHex, "hex"));
|
|
563
|
+
const pub = x25519.getPublicKey(priv);
|
|
564
|
+
return Buffer.from(pub).toString("hex");
|
|
565
|
+
}
|
|
566
|
+
__name(x25519PublicHexFromPrivateHex, "x25519PublicHexFromPrivateHex");
|
|
553
567
|
var jwkDetermineUse = /* @__PURE__ */ __name((type, suppliedUse) => {
|
|
554
568
|
return suppliedUse ? suppliedUse : SIG_KEY_ALGS.includes(type) ? JwkKeyUse.Signature : ENC_KEY_ALGS.includes(type) ? JwkKeyUse.Encryption : void 0;
|
|
555
569
|
}, "jwkDetermineUse");
|
|
@@ -586,8 +600,8 @@ var toSecp256k1Jwk = /* @__PURE__ */ __name((keyHex, opts) => {
|
|
|
586
600
|
},
|
|
587
601
|
kty: JwkKeyType.EC,
|
|
588
602
|
crv: JoseCurve.secp256k1,
|
|
589
|
-
x: hexToBase64(pubPoint.getX().toString("hex"), "base64url"),
|
|
590
|
-
y: hexToBase64(pubPoint.getY().toString("hex"), "base64url"),
|
|
603
|
+
x: hexToBase64(pubPoint.getX().toString("hex").padStart(64, "0"), "base64url"),
|
|
604
|
+
y: hexToBase64(pubPoint.getY().toString("hex").padStart(64, "0"), "base64url"),
|
|
591
605
|
...opts?.isPrivateKey && {
|
|
592
606
|
d: hexToBase64(keyPair.getPrivate("hex"), "base64url")
|
|
593
607
|
}
|
|
@@ -618,8 +632,8 @@ var toSecp256r1Jwk = /* @__PURE__ */ __name((keyHex, opts) => {
|
|
|
618
632
|
},
|
|
619
633
|
kty: JwkKeyType.EC,
|
|
620
634
|
crv: JoseCurve.P_256,
|
|
621
|
-
x: hexToBase64(pubPoint.getX().toString("hex"), "base64url"),
|
|
622
|
-
y: hexToBase64(pubPoint.getY().toString("hex"), "base64url"),
|
|
635
|
+
x: hexToBase64(pubPoint.getX().toString("hex").padStart(64, "0"), "base64url"),
|
|
636
|
+
y: hexToBase64(pubPoint.getY().toString("hex").padStart(64, "0"), "base64url"),
|
|
623
637
|
...opts?.isPrivateKey && {
|
|
624
638
|
d: hexToBase64(keyPair.getPrivate("hex"), "base64url")
|
|
625
639
|
}
|
|
@@ -1417,6 +1431,7 @@ export {
|
|
|
1417
1431
|
toPkcs1FromHex,
|
|
1418
1432
|
toRawCompressedHexPublicKey,
|
|
1419
1433
|
validateJwk,
|
|
1420
|
-
verifyRawSignature
|
|
1434
|
+
verifyRawSignature,
|
|
1435
|
+
x25519PublicHexFromPrivateHex
|
|
1421
1436
|
};
|
|
1422
1437
|
//# sourceMappingURL=index.js.map
|