本文整理汇总了TypeScript中bitcoinjs-lib.ECPair.fromPrivateKey方法的典型用法代码示例。如果您正苦于以下问题:TypeScript ECPair.fromPrivateKey方法的具体用法?TypeScript ECPair.fromPrivateKey怎么用?TypeScript ECPair.fromPrivateKey使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类bitcoinjs-lib.ECPair
的用法示例。
在下文中一共展示了ECPair.fromPrivateKey方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: hexStringToECPair
export function hexStringToECPair(skHex: string) {
const ecPairOptions = {
network: config.network.layer1,
compressed: true
}
if (skHex.length === 66) {
if (skHex.slice(64) !== '01') {
throw new Error('Improperly formatted private-key hex string. 66-length hex usually '
+ 'indicates compressed key, but last byte must be == 1')
}
return ECPair.fromPrivateKey(Buffer.from(skHex.slice(0, 64), 'hex'), ecPairOptions)
} else if (skHex.length === 64) {
ecPairOptions.compressed = false
return ECPair.fromPrivateKey(Buffer.from(skHex, 'hex'), ecPairOptions)
} else {
throw new Error('Improperly formatted private-key hex string: length should be 64 or 66.')
}
}
示例2: getBucketUrl
export async function getBucketUrl(gaiaHubUrl: string, appPrivateKey: string): Promise<string> {
const challengeSigner = bitcoin.ECPair.fromPrivateKey(Buffer.from(appPrivateKey, 'hex'))
const response = await fetch(`${gaiaHubUrl}/hub_info`)
const responseText = await response.text()
const responseJSON = JSON.parse(responseText)
const readURL = responseJSON.read_url_prefix
const address = ecPairToAddress(challengeSigner)
const bucketUrl = `${readURL}${address}/`
return bucketUrl
}
示例3: getNodePrivateKey
/**
*
* @ignore
*/
function getNodePrivateKey(node: BIP32): string {
return ecPairToHexString(ECPair.fromPrivateKey(node.privateKey))
}
示例4: getPublicKeyFromPrivate
export function getPublicKeyFromPrivate(privateKey: string) {
const keyPair = ECPair.fromPrivateKey(Buffer.from(privateKey, 'hex'))
return keyPair.publicKey.toString('hex')
}