@sphereon/ssi-sdk-ext.key-utils 0.34.1-feature.SSISDK.46.41 → 0.34.1-feature.SSISDK.50.98
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 +8 -8
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +8 -8
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
- package/src/functions.ts +21 -21
package/src/functions.ts
CHANGED
|
@@ -115,7 +115,7 @@ export async function importProvidedOrGeneratedKey(
|
|
|
115
115
|
args: IImportProvidedOrGeneratedKeyArgs & {
|
|
116
116
|
kms: string
|
|
117
117
|
},
|
|
118
|
-
context: IAgentContext<IKeyManager
|
|
118
|
+
context: IAgentContext<IKeyManager>,
|
|
119
119
|
): Promise<IKey> {
|
|
120
120
|
// @ts-ignore
|
|
121
121
|
const type = args.options?.type ?? args.options?.key?.type ?? args.options?.keyType ?? 'Secp256r1'
|
|
@@ -172,8 +172,8 @@ export const calculateJwkThumbprintForKey = (args: {
|
|
|
172
172
|
const jwk = key.publicKeyHex
|
|
173
173
|
? toJwk(key.publicKeyHex, key.type, { key: key, isPrivateKey: false })
|
|
174
174
|
: 'privateKeyHex' in key && key.privateKeyHex
|
|
175
|
-
|
|
176
|
-
|
|
175
|
+
? toJwk(key.privateKeyHex, key.type, { isPrivateKey: true })
|
|
176
|
+
: undefined
|
|
177
177
|
if (!jwk) {
|
|
178
178
|
throw Error(`Could not determine jwk from key ${key.kid}`)
|
|
179
179
|
}
|
|
@@ -231,7 +231,7 @@ export const toJwkFromKey = (
|
|
|
231
231
|
opts?: {
|
|
232
232
|
use?: JwkKeyUse
|
|
233
233
|
noKidThumbprint?: boolean
|
|
234
|
-
}
|
|
234
|
+
},
|
|
235
235
|
): JWK => {
|
|
236
236
|
const isPrivateKey = 'privateKeyHex' in key
|
|
237
237
|
return toJwk(key.publicKeyHex!, key.type, { ...opts, key, isPrivateKey })
|
|
@@ -247,7 +247,7 @@ export const toJwkFromKey = (
|
|
|
247
247
|
export const toJwk = (
|
|
248
248
|
publicKeyHex: string,
|
|
249
249
|
type: TKeyType,
|
|
250
|
-
opts?: { use?: JwkKeyUse; key?: IKey | MinimalImportableKey; isPrivateKey?: boolean; noKidThumbprint?: boolean }
|
|
250
|
+
opts?: { use?: JwkKeyUse; key?: IKey | MinimalImportableKey; isPrivateKey?: boolean; noKidThumbprint?: boolean },
|
|
251
251
|
): JWK => {
|
|
252
252
|
const { key, noKidThumbprint = false } = opts ?? {}
|
|
253
253
|
if (key && key.publicKeyHex !== publicKeyHex && opts?.isPrivateKey !== true) {
|
|
@@ -433,10 +433,10 @@ export const jwkDetermineUse = (type: TKeyType, suppliedUse?: JwkKeyUse): JwkKey
|
|
|
433
433
|
return suppliedUse
|
|
434
434
|
? suppliedUse
|
|
435
435
|
: SIG_KEY_ALGS.includes(type)
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
436
|
+
? JwkKeyUse.Signature
|
|
437
|
+
: ENC_KEY_ALGS.includes(type)
|
|
438
|
+
? JwkKeyUse.Encryption
|
|
439
|
+
: undefined
|
|
440
440
|
}
|
|
441
441
|
|
|
442
442
|
/**
|
|
@@ -451,7 +451,7 @@ const assertProperKeyLength = (keyHex: string, expectedKeyLength: number | numbe
|
|
|
451
451
|
throw Error(
|
|
452
452
|
`Invalid key length. Needs to be a hex string with length from ${JSON.stringify(expectedKeyLength)} instead of ${
|
|
453
453
|
keyHex.length
|
|
454
|
-
}. Input: ${keyHex}
|
|
454
|
+
}. Input: ${keyHex}`,
|
|
455
455
|
)
|
|
456
456
|
}
|
|
457
457
|
} else if (keyHex.length !== expectedKeyLength) {
|
|
@@ -484,8 +484,8 @@ const toSecp256k1Jwk = (keyHex: string, opts?: { use?: JwkKeyUse; isPrivateKey?:
|
|
|
484
484
|
...(use !== undefined && { use }),
|
|
485
485
|
kty: JwkKeyType.EC,
|
|
486
486
|
crv: JoseCurve.secp256k1,
|
|
487
|
-
x: hexToBase64(pubPoint.getX().toString('hex'), 'base64url'),
|
|
488
|
-
y: hexToBase64(pubPoint.getY().toString('hex'), 'base64url'),
|
|
487
|
+
x: hexToBase64(pubPoint.getX().toString('hex').padStart(64, '0'), 'base64url'),
|
|
488
|
+
y: hexToBase64(pubPoint.getY().toString('hex').padStart(64, '0'), 'base64url'),
|
|
489
489
|
...(opts?.isPrivateKey && { d: hexToBase64(keyPair.getPrivate('hex'), 'base64url') }),
|
|
490
490
|
})
|
|
491
491
|
}
|
|
@@ -515,8 +515,8 @@ const toSecp256r1Jwk = (keyHex: string, opts?: { use?: JwkKeyUse; isPrivateKey?:
|
|
|
515
515
|
...(use !== undefined && { use }),
|
|
516
516
|
kty: JwkKeyType.EC,
|
|
517
517
|
crv: JoseCurve.P_256,
|
|
518
|
-
x: hexToBase64(pubPoint.getX().toString('hex'), 'base64url'),
|
|
519
|
-
y: hexToBase64(pubPoint.getY().toString('hex'), 'base64url'),
|
|
518
|
+
x: hexToBase64(pubPoint.getX().toString('hex').padStart(64, '0'), 'base64url'),
|
|
519
|
+
y: hexToBase64(pubPoint.getY().toString('hex').padStart(64, '0'), 'base64url'),
|
|
520
520
|
...(opts?.isPrivateKey && { d: hexToBase64(keyPair.getPrivate('hex'), 'base64url') }),
|
|
521
521
|
})
|
|
522
522
|
}
|
|
@@ -532,7 +532,7 @@ const toEd25519OrX25519Jwk = (
|
|
|
532
532
|
opts: {
|
|
533
533
|
use?: JwkKeyUse
|
|
534
534
|
crv: JoseCurve.Ed25519 | JoseCurve.X25519
|
|
535
|
-
}
|
|
535
|
+
},
|
|
536
536
|
): JWK => {
|
|
537
537
|
assertProperKeyLength(publicKeyHex, 64)
|
|
538
538
|
const { use } = opts ?? {}
|
|
@@ -954,8 +954,8 @@ export async function verifyRawSignature({
|
|
|
954
954
|
signatureAlgorithm === JoseSignatureAlgorithm.RS512 || signatureAlgorithm === JoseSignatureAlgorithm.PS512
|
|
955
955
|
? sha512
|
|
956
956
|
: signatureAlgorithm === JoseSignatureAlgorithm.RS384 || signatureAlgorithm === JoseSignatureAlgorithm.PS384
|
|
957
|
-
|
|
958
|
-
|
|
957
|
+
? sha384
|
|
958
|
+
: sha256
|
|
959
959
|
switch (signatureAlgorithm) {
|
|
960
960
|
case JoseSignatureAlgorithm.RS256:
|
|
961
961
|
return rsa.PKCS1_SHA256.verify(
|
|
@@ -964,7 +964,7 @@ export async function verifyRawSignature({
|
|
|
964
964
|
e: jwkPropertyToBigInt(jwk.e!),
|
|
965
965
|
},
|
|
966
966
|
data,
|
|
967
|
-
signature
|
|
967
|
+
signature,
|
|
968
968
|
)
|
|
969
969
|
case JoseSignatureAlgorithm.RS384:
|
|
970
970
|
return rsa.PKCS1_SHA384.verify(
|
|
@@ -973,7 +973,7 @@ export async function verifyRawSignature({
|
|
|
973
973
|
e: jwkPropertyToBigInt(jwk.e!),
|
|
974
974
|
},
|
|
975
975
|
data,
|
|
976
|
-
signature
|
|
976
|
+
signature,
|
|
977
977
|
)
|
|
978
978
|
case JoseSignatureAlgorithm.RS512:
|
|
979
979
|
return rsa.PKCS1_SHA512.verify(
|
|
@@ -982,7 +982,7 @@ export async function verifyRawSignature({
|
|
|
982
982
|
e: jwkPropertyToBigInt(jwk.e!),
|
|
983
983
|
},
|
|
984
984
|
data,
|
|
985
|
-
signature
|
|
985
|
+
signature,
|
|
986
986
|
)
|
|
987
987
|
case JoseSignatureAlgorithm.PS256:
|
|
988
988
|
case JoseSignatureAlgorithm.PS384:
|
|
@@ -1002,7 +1002,7 @@ export async function verifyRawSignature({
|
|
|
1002
1002
|
e: jwkPropertyToBigInt(jwk.e!),
|
|
1003
1003
|
},
|
|
1004
1004
|
data,
|
|
1005
|
-
signature
|
|
1005
|
+
signature,
|
|
1006
1006
|
)
|
|
1007
1007
|
}
|
|
1008
1008
|
}
|