-
Notifications
You must be signed in to change notification settings - Fork 204
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add Multikey as supported vm type (#1720)
- Loading branch information
Showing
7 changed files
with
90 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
50 changes: 50 additions & 0 deletions
50
packages/core/src/modules/dids/domain/verificationMethod/Multikey.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import type { VerificationMethod } from './VerificationMethod' | ||
|
||
import { Key } from '../../../../crypto/Key' | ||
import { AriesFrameworkError } from '../../../../error' | ||
|
||
export const VERIFICATION_METHOD_TYPE_MULTIKEY = 'Multikey' | ||
|
||
type GetMultikeyOptions = { | ||
did: string | ||
key: Key | ||
verificationMethodId?: string | ||
} | ||
|
||
/** | ||
* Get a Multikey verification method. | ||
*/ | ||
export function getMultikey({ did, key, verificationMethodId }: GetMultikeyOptions) { | ||
if (!verificationMethodId) { | ||
verificationMethodId = `${did}#${key.fingerprint}` | ||
} | ||
|
||
return { | ||
id: verificationMethodId, | ||
type: VERIFICATION_METHOD_TYPE_MULTIKEY, | ||
controller: did, | ||
publicKeyMultibase: key.fingerprint, | ||
} | ||
} | ||
|
||
/** | ||
* Check whether a verification method is a Multikey verification method. | ||
*/ | ||
export function isMultikey( | ||
verificationMethod: VerificationMethod | ||
): verificationMethod is VerificationMethod & { type: 'Multikey' } { | ||
return verificationMethod.type === VERIFICATION_METHOD_TYPE_MULTIKEY | ||
} | ||
|
||
/** | ||
* Get a key from a Multikey verification method. | ||
*/ | ||
export function getKeyFromMultikey(verificationMethod: VerificationMethod & { type: 'Multikey' }) { | ||
if (!verificationMethod.publicKeyMultibase) { | ||
throw new AriesFrameworkError( | ||
`Missing publicKeyMultibase on verification method with type ${VERIFICATION_METHOD_TYPE_MULTIKEY}` | ||
) | ||
} | ||
|
||
return Key.fromFingerprint(verificationMethod.publicKeyMultibase) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters