本文整理汇总了TypeScript中bip32.fromBase58函数的典型用法代码示例。如果您正苦于以下问题:TypeScript fromBase58函数的具体用法?TypeScript fromBase58怎么用?TypeScript fromBase58使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了fromBase58函数的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。
示例1: getAppPrivateKey
/**
* Get a ECDSA private key hex-string for an application-specific
* address.
* @param {String} appsNodeKey - the base58-encoded private key for
* applications node (the `appsNodeKey` return in getIdentityKeyPair())
* @param {String} salt - a string, used to salt the
* application-specific addresses
* @param {String} appDomain - the appDomain to generate a key for
* @return {String} the private key hex-string. this will be a 64
* character string
*/
static getAppPrivateKey(appsNodeKey: string, salt: string, appDomain: string): string {
const hash = crypto
.createHash('sha256')
.update(`${appDomain}${salt}`)
.digest('hex')
const appIndexHexes: string[] = []
// note: there's hardcoded numbers here, precisely because I want this
// code to be very specific to the derivation paths we expect.
if (hash.length !== 64) {
throw new Error(`Unexpected app-domain hash length of ${hash.length}`)
}
for (let i = 0; i < 11; i++) { // split the hash into 3-byte chunks
// because child nodes can only be up to 2^31,
// and we shouldn't deal in partial bytes.
appIndexHexes.push(hash.slice(i * 6, i * 6 + 6))
}
let appNode = bip32.fromBase58(appsNodeKey)
appIndexHexes.forEach((hex) => {
if (hex.length > 6) {
throw new Error('Invalid hex string length')
}
appNode = appNode.deriveHardened(parseInt(hex, 16))
})
return getNodePrivateKey(appNode).slice(0, 64)
}
示例2: getLegacyAppPrivateKey
/**
* Get a ECDSA private key hex-string for an application-specific
* address.
* @param {String} appsNodeKey - the base58-encoded private key for
* applications node (the `appsNodeKey` return in getIdentityKeyPair())
* @param {String} salt - a string, used to salt the
* application-specific addresses
* @param {String} appDomain - the appDomain to generate a key for
* @return {String} the private key hex-string. this will be a 64
* character string
*/
static getLegacyAppPrivateKey(appsNodeKey: string,
salt: string, appDomain: string): string {
const hash = crypto
.createHash('sha256')
.update(`${appDomain}${salt}`)
.digest('hex')
const appIndex = hashCode(hash)
const appNode = bip32.fromBase58(appsNodeKey).deriveHardened(appIndex)
return getNodePrivateKey(appNode).slice(0, 64)
}
示例3: getNodeFromBitcoinKeychain
static getNodeFromBitcoinKeychain(
keychainBase58: string,
addressIndex: number,
chainType: string = EXTERNAL_ADDRESS
): BIP32 {
let chain
if (chainType === EXTERNAL_ADDRESS) {
chain = 0
} else if (chainType === CHANGE_ADDRESS) {
chain = 1
} else {
throw new Error('Invalid chain type')
}
const keychain = bip32.fromBase58(keychainBase58)
return keychain.derive(chain).derive(addressIndex)
}
示例4: fromBase58
/**
* Initialize a Blockstack wallet from a base58 string
* @param {string} keychain - the Base58 string used to initialize
* the root node of the hierarchical wallet
* @return {BlockstackWallet} the constructed wallet
*/
static fromBase58(keychain: string): BlockstackWallet {
return new BlockstackWallet(bip32.fromBase58(keychain))
}
示例5: fromBase58
import { fromBase58 } from 'bip32';
const node = fromBase58("xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi");
const child = node.derivePath('m/0');
const grandchild = child.derive(2);
grandchild.toWIF() === 'Kxtby4wzfHeCaRXma16dBNLgUE7Ct3Xkb6sRs3aZ56Bmtf1rcNWs';