当前位置: 首页>>代码示例>>TypeScript>>正文


TypeScript bip32.fromBase58函数代码示例

本文整理汇总了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)
 }
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:36,代码来源:wallet.ts

示例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)
 }
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:21,代码来源:wallet.ts

示例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)
  }
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:17,代码来源:wallet.ts

示例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))
 }
开发者ID:blockstack,项目名称:blockstack-cli,代码行数:9,代码来源:wallet.ts

示例5: fromBase58

import { fromBase58 } from 'bip32';

const node = fromBase58("xprv9s21ZrQH143K3QTDL4LXw2F7HEK3wJUD2nW2nRk4stbPy6cq3jPPqjiChkVvvNKmPGJxWUtg6LnF5kejMRNNU3TGtRBeJgk33yuGBxrMPHi");

const child = node.derivePath('m/0');

const grandchild = child.derive(2);

grandchild.toWIF() === 'Kxtby4wzfHeCaRXma16dBNLgUE7Ct3Xkb6sRs3aZ56Bmtf1rcNWs';
开发者ID:AlexGalays,项目名称:DefinitelyTyped,代码行数:9,代码来源:bip32-tests.ts


注:本文中的bip32.fromBase58函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。