@sphereon/ssi-sdk-ext.key-utils 0.36.1-feature.integration.fides.71 → 0.36.1-feature.integration.fides.82
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 +38 -3
- 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 +38 -3
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/functions.ts +41 -3
- package/src/types/key-util-types.ts +1 -0
package/src/functions.ts
CHANGED
|
@@ -789,11 +789,49 @@ export const hexStringFromUint8Array = (value: Uint8Array): string => toString(v
|
|
|
789
789
|
|
|
790
790
|
export const signatureAlgorithmFromKey = async (args: SignatureAlgorithmFromKeyArgs): Promise<JoseSignatureAlgorithm> => {
|
|
791
791
|
const { key } = args
|
|
792
|
-
return signatureAlgorithmFromKeyType({ type: key.type })
|
|
792
|
+
return signatureAlgorithmFromKeyType({ type: key.type, algorithms: key.meta?.algorithms })
|
|
793
|
+
}
|
|
794
|
+
|
|
795
|
+
export function signatureAlgorithmToJoseAlgorithm(alg: string): JoseSignatureAlgorithm {
|
|
796
|
+
switch (alg) {
|
|
797
|
+
case 'RSA_SHA256':
|
|
798
|
+
return JoseSignatureAlgorithm.RS256
|
|
799
|
+
case 'RSA_SHA384':
|
|
800
|
+
return JoseSignatureAlgorithm.RS384
|
|
801
|
+
case 'RSA_SHA512':
|
|
802
|
+
return JoseSignatureAlgorithm.RS512
|
|
803
|
+
case 'RSA_SSA_PSS_SHA256_MGF1':
|
|
804
|
+
return JoseSignatureAlgorithm.PS256
|
|
805
|
+
case 'RSA_SSA_PSS_SHA384_MGF1':
|
|
806
|
+
return JoseSignatureAlgorithm.PS384
|
|
807
|
+
case 'RSA_SSA_PSS_SHA512_MGF1':
|
|
808
|
+
return JoseSignatureAlgorithm.PS512
|
|
809
|
+
case 'ECDSA_SHA256':
|
|
810
|
+
return JoseSignatureAlgorithm.ES256
|
|
811
|
+
case 'ECDSA_SHA384':
|
|
812
|
+
return JoseSignatureAlgorithm.ES384
|
|
813
|
+
case 'ECDSA_SHA512':
|
|
814
|
+
return JoseSignatureAlgorithm.ES512
|
|
815
|
+
case 'ES256K':
|
|
816
|
+
return JoseSignatureAlgorithm.ES256K
|
|
817
|
+
case 'ED25519':
|
|
818
|
+
case 'EdDSA':
|
|
819
|
+
return JoseSignatureAlgorithm.EdDSA
|
|
820
|
+
default:
|
|
821
|
+
// If already in JOSE format, return as-is
|
|
822
|
+
return alg as JoseSignatureAlgorithm
|
|
823
|
+
}
|
|
793
824
|
}
|
|
794
825
|
|
|
795
826
|
export const signatureAlgorithmFromKeyType = (args: SignatureAlgorithmFromKeyTypeArgs): JoseSignatureAlgorithm => {
|
|
796
|
-
const { type } = args
|
|
827
|
+
const { type, algorithms } = args
|
|
828
|
+
|
|
829
|
+
// If algorithms metadata is provided, use the first one
|
|
830
|
+
if (algorithms && algorithms.length > 0) {
|
|
831
|
+
return signatureAlgorithmToJoseAlgorithm(algorithms[0])
|
|
832
|
+
}
|
|
833
|
+
|
|
834
|
+
// Fallback to type-based defaults
|
|
797
835
|
switch (type) {
|
|
798
836
|
case 'Ed25519':
|
|
799
837
|
case 'X25519':
|
|
@@ -807,7 +845,7 @@ export const signatureAlgorithmFromKeyType = (args: SignatureAlgorithmFromKeyTyp
|
|
|
807
845
|
case 'Secp256k1':
|
|
808
846
|
return JoseSignatureAlgorithm.ES256K
|
|
809
847
|
case 'RSA':
|
|
810
|
-
return JoseSignatureAlgorithm.PS256
|
|
848
|
+
return JoseSignatureAlgorithm.RS256 // Default to RS256 instead of PS256
|
|
811
849
|
default:
|
|
812
850
|
throw new Error(`Key type '${type}' not supported`)
|
|
813
851
|
}
|