Skip to content

Commit

Permalink
fix: replace internal keytype with keytype strings
Browse files Browse the repository at this point in the history
Signed-off-by: Karim <[email protected]>
  • Loading branch information
karimStekelenburg committed Jul 8, 2022
1 parent c2bef38 commit edf8cd8
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import type { KeyDidMapping } from './keyDidMapping'
import { KeyType } from '../../../../crypto'
import { Key } from '../../../../crypto/Key'

const VERIFICATION_METHOD_TYPE_BLS12381G2_KEY_2020 = 'Bls12381G2Key2020'
export const VERIFICATION_METHOD_TYPE_BLS12381G2_KEY_2020 = 'Bls12381G2Key2020'

export function getBls12381g2VerificationMethod(did: string, key: Key) {
return {
Expand Down
17 changes: 12 additions & 5 deletions packages/core/src/modules/dids/domain/key-type/ed25519.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ import { convertPublicKeyToX25519 } from '@stablelib/ed25519'
import { KeyType } from '../../../../crypto'
import { Key } from '../../../../crypto/Key'

const VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2018 = 'Ed25519VerificationKey2018'
export const VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2018 = 'Ed25519VerificationKey2018'
export const VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2020 = 'Ed25519VerificationKey2020'

export function getEd25519VerificationMethod({ key, id, controller }: { id: string; key: Key; controller: string }) {
return {
Expand All @@ -24,13 +25,19 @@ export const keyDidEd25519: KeyDidMapping = {
],
getKeyFromVerificationMethod: (verificationMethod: VerificationMethod) => {
if (
verificationMethod.type !== VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2018 ||
!verificationMethod.publicKeyBase58
verificationMethod.type !== VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2018 &&
verificationMethod.publicKeyBase58
) {
throw new Error('Invalid verification method passed')
return Key.fromPublicKeyBase58(verificationMethod.publicKeyBase58, KeyType.Ed25519)
}
if (
verificationMethod.type !== VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2020 &&
verificationMethod.publicKeyMultibase
) {
return Key.fromFingerprint(verificationMethod.publicKeyMultibase)
}

return Key.fromPublicKeyBase58(verificationMethod.publicKeyBase58, KeyType.Ed25519)
throw new Error('Invalid verification method passed')
},
}

Expand Down
25 changes: 15 additions & 10 deletions packages/core/src/modules/vc/SignatureSuiteRegistry.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { KeyType } from '../../crypto'
import type { KeyType } from '../../crypto'

import { AriesFrameworkError } from '../../error'
import { VERIFICATION_METHOD_TYPE_BLS12381G2_KEY_2020 } from '../dids/domain/key-type/bls12381g2'
import {
VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2018,
VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2020,
} from '../dids/domain/key-type/ed25519'

import { suites } from './libraries/jsonld-signatures'
import { Ed25519Signature2018 } from './signature-suites'
Expand All @@ -10,29 +16,28 @@ const LinkedDataSignature = suites.LinkedDataSignature
export interface SuiteInfo {
suiteClass: typeof LinkedDataSignature
proofType: string
requiredKeyType: string
keyTypes: [KeyType]
keyTypes: string[]
}

export class SignatureSuiteRegistry {
private suiteMapping: SuiteInfo[] = [
{
suiteClass: Ed25519Signature2018,
proofType: 'Ed25519Signature2018',
requiredKeyType: 'Ed25519VerificationKey2018',
keyTypes: [KeyType.Ed25519],
keyTypes: [
VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2018,
VERIFICATION_METHOD_TYPE_ED25519_VERIFICATION_KEY_2020,
],
},
{
suiteClass: BbsBlsSignature2020,
proofType: 'BbsBlsSignature2020',
requiredKeyType: 'BbsBlsSignatureProof2020',
keyTypes: [KeyType.Bls12381g2],
keyTypes: [VERIFICATION_METHOD_TYPE_BLS12381G2_KEY_2020],
},
{
suiteClass: BbsBlsSignatureProof2020,
proofType: 'BbsBlsSignatureProof2020',
requiredKeyType: 'BbsBlsSignatureProof2020',
keyTypes: [KeyType.Bls12381g2],
keyTypes: [VERIFICATION_METHOD_TYPE_BLS12381G2_KEY_2020],
},
]

Expand All @@ -54,7 +59,7 @@ export class SignatureSuiteRegistry {
return suiteInfo
}

public getKeyTypesByProofType(proofType: string): KeyType[] {
public getKeyTypesByProofType(proofType: string): string[] {
const suiteInfo = this.suiteMapping.find((suiteInfo) => suiteInfo.proofType === proofType)

if (!suiteInfo) {
Expand Down
2 changes: 1 addition & 1 deletion packages/core/src/modules/vc/W3cCredentialService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -353,7 +353,7 @@ export class W3cCredentialService {
return result.map((record) => record.credential)
}

public getKeyTypesByProofType(proofType: string): KeyType[] {
public getKeyTypesByProofType(proofType: string): string[] {
return this.suiteRegistry.getKeyTypesByProofType(proofType)
}

Expand Down

0 comments on commit edf8cd8

Please sign in to comment.