did-jwt
Version:
Library for Signing and Verifying JWTs that use DIDs as issuers and JWEs that use DIDs as recipients
25 lines (23 loc) • 832 B
text/typescript
import { publicKeyToAddress as bip122 } from './bip122.js'
import { publicKeyToAddress as cosmos } from './cosmos.js'
import { toEthereumAddress } from '../Digest.js'
export function verifyBlockchainAccountId(publicKey: string, blockchainAccountId: string | undefined): boolean {
if (blockchainAccountId) {
const chain = blockchainAccountId.split(':')
switch (chain[0]) {
case 'bip122':
chain[chain.length - 1] = bip122(publicKey, chain[chain.length - 1])
break
case 'cosmos':
chain[chain.length - 1] = cosmos(publicKey, chain[1])
break
case 'eip155':
chain[chain.length - 1] = toEthereumAddress(publicKey)
break
default:
return false
}
return chain.join(':').toLowerCase() === blockchainAccountId.toLowerCase()
}
return false
}