Skip to content

Commit

Permalink
refactor: rewrite conversion method
Browse files Browse the repository at this point in the history
Signed-off-by: Karim Stekelenburg <[email protected]>
  • Loading branch information
karimStekelenburg committed May 9, 2022
1 parent 1e30b56 commit beeaf68
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { DocumentLoader, JsonLdDoc, Proof, VerificationMethod } from '../../../utils'
import { DocumentLoader, JsonLdDoc, Proof, TypedArrayEncoder, VerificationMethod } from '../../../utils'
import type { JwsLinkedDataSignatureOptions, ProofPurpose } from '../JwsLinkedDataSignature'

// @ts-ignore
Expand Down Expand Up @@ -80,18 +80,15 @@ export class Ed25519Signature2018 extends JwsLinkedDataSignature {
}

public async getVerificationMethod(options: { proof: Proof; documentLoader: DocumentLoader }) {
const verificationMethod = await super.getVerificationMethod({
let verificationMethod = await super.getVerificationMethod({
proof: options.proof,
documentLoader: options.documentLoader,
})

// convert Ed25519VerificationKey2020 to Ed25519VerificationKey2018
if (_isEd2020Key(verificationMethod)) {
// -- convert multibase to base58 --
const pubKeyBuffer = MultiBaseEncoder.decode(verificationMethod.publicKeyMultibase)
const pubKeyBase58 = encodeToBase58(pubKeyBuffer.data)
delete verificationMethod.publicKeyMultibase
verificationMethod.publicKeyBase58 = pubKeyBase58
const publicKeyBuffer = MultiBaseEncoder.decode(verificationMethod.publicKeyMultibase)

// -- update context --
// remove 2020 context
Expand All @@ -102,7 +99,13 @@ export class Ed25519Signature2018 extends JwsLinkedDataSignature {
verificationMethod['@context'].push(ED25519_SUITE_CONTEXT_URL_2018)

// -- update type
verificationMethod['@type'] = 'Ed25519VerificationKey2018'
verificationMethod.type = 'Ed25519VerificationKey2018'

verificationMethod = {
...verificationMethod,
publicKeyMultibase: undefined,
publicKeyBase58: TypedArrayEncoder.toBase58(publicKeyBuffer.data),
}
}

return verificationMethod
Expand Down

0 comments on commit beeaf68

Please sign in to comment.