Skip to content

Commit

Permalink
fix: musapKMS improved determineAlgorithm handling
Browse files Browse the repository at this point in the history
  • Loading branch information
sanderPostma committed Aug 2, 2024
1 parent 73415ed commit 24d8218
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
2 changes: 1 addition & 1 deletion packages/kms-musap-rn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
"dependencies": {
"@sphereon/ssi-types": "0.28.1-next.60",
"@sphereon/ssi-sdk-ext.key-utils": "workspace:*",
"@sphereon/musap-react-native": "0.0.1-next.152",
"@sphereon/musap-react-native": "0.0.1-next.154",
"@veramo/core": "4.2.0",
"@veramo/key-manager": "4.2.0",
"@veramo/kms-local": "4.2.0",
Expand Down
20 changes: 19 additions & 1 deletion packages/kms-musap-rn/src/MusapKeyManagerSystem.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { IKey, ManagedKeyInfo, MinimalImportableKey, TKeyType } from '@veramo/core'
import {
isSignatureAlgorithmType, JWSAlgorithm,
KeyAlgorithm,
KeyAlgorithmType,
KeyGenReq,
Expand Down Expand Up @@ -106,6 +107,23 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
}
}

private determineAlgorithm(
providedAlgorithm: string | undefined,
keyAlgorithm: KeyAlgorithm,
): SignatureAlgorithmType {

if (providedAlgorithm === undefined) {
return signatureAlgorithmFromKeyAlgorithm(keyAlgorithm)
}

if (isSignatureAlgorithmType(providedAlgorithm)) {
return providedAlgorithm
}

// Veramo translates TKeyType to JWSAlgorithm
return signatureAlgorithmFromKeyAlgorithm(providedAlgorithm as JWSAlgorithm)
}

async sign(args: { keyRef: Pick<IKey, 'kid'>; algorithm?: string; data: Uint8Array; [x: string]: any }): Promise<string> {
if (!args.keyRef) {
throw new Error('key_not_found: No key ref provided')
Expand All @@ -117,7 +135,7 @@ export class MusapKeyManagementSystem extends AbstractKeyManagementSystem {
const signatureReq: SignatureReq = {
keyUri: key.keyUri,
data,
algorithm: (args.algorithm as SignatureAlgorithmType) ?? signatureAlgorithmFromKeyAlgorithm(key.algorithm),
algorithm: this.determineAlgorithm(args.algorithm, key.algorithm),
displayText: args.displayText,
transId: args.transId,
format: (args.format as SignatureFormat) ?? 'RAW',
Expand Down
14 changes: 7 additions & 7 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 24d8218

Please sign in to comment.