本文整理汇总了TypeScript中bitcoinjs-lib.ECPair.fromPublicKey方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ECPair.fromPublicKey方法的具体用法?TypeScript ECPair.fromPublicKey怎么用?TypeScript ECPair.fromPublicKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitcoinjs-lib.ECPair
的用法示例。
在下文中一共展示了ECPair.fromPublicKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: verifyProfileToken
export function verifyProfileToken(token: string, publicKeyOrAddress: string) {
const decodedToken = decodeToken(token)
const payload = decodedToken.payload
// Inspect and verify the subject
if (payload.hasOwnProperty('subject')) {
if (!payload.subject.hasOwnProperty('publicKey')) {
throw new Error('Token doesn\'t have a subject public key')
}
} else {
throw new Error('Token doesn\'t have a subject')
}
// Inspect and verify the issuer
if (payload.hasOwnProperty('issuer')) {
if (!payload.issuer.hasOwnProperty('publicKey')) {
throw new Error('Token doesn\'t have an issuer public key')
}
} else {
throw new Error('Token doesn\'t have an issuer')
}
// Inspect and verify the claim
if (!payload.hasOwnProperty('claim')) {
throw new Error('Token doesn\'t have a claim')
}
const issuerPublicKey = payload.issuer.publicKey
const publicKeyBuffer = Buffer.from(issuerPublicKey, 'hex')
const compressedKeyPair = ECPair.fromPublicKey(publicKeyBuffer, { compressed: true })
const compressedAddress = ecPairToAddress(compressedKeyPair)
const uncompressedKeyPair = ECPair.fromPublicKey(publicKeyBuffer, { compressed: false })
const uncompressedAddress = ecPairToAddress(uncompressedKeyPair)
if (publicKeyOrAddress === issuerPublicKey) {
// pass
} else if (publicKeyOrAddress === compressedAddress) {
// pass
} else if (publicKeyOrAddress === uncompressedAddress) {
// pass
} else {
throw new Error('Token issuer public key does not match the verifying value')
}
const tokenVerifier = new TokenVerifier(decodedToken.header.alg, issuerPublicKey)
if (!tokenVerifier) {
throw new Error('Invalid token verifier')
}
const tokenVerified = tokenVerifier.verify(token)
if (!tokenVerified) {
throw new Error('Token verification failed')
}
return decodedToken
}
示例2: pubkeyHexToECPair
function pubkeyHexToECPair (pubkeyHex: string) {
const pkBuff = Buffer.from(pubkeyHex, 'hex')
return bitcoin.ECPair.fromPublicKey(pkBuff)
}