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


TypeScript Keypair.fromPublicKey方法代码示例

本文整理汇总了TypeScript中stellar-sdk.Keypair.fromPublicKey方法的典型用法代码示例。如果您正苦于以下问题:TypeScript Keypair.fromPublicKey方法的具体用法?TypeScript Keypair.fromPublicKey怎么用?TypeScript Keypair.fromPublicKey使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在stellar-sdk.Keypair的用法示例。


在下文中一共展示了Keypair.fromPublicKey方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的TypeScript代码示例。

示例1: initiateRecovery

  /**
   * Generates Stellar keypairs from the user key and backup key
   * @param params
   *  - userKey: user keypair private key (encrypted or plaintext)
   *  - backupKey: backup keypair public key (plaintext) or private key (encrypted or plaintext)
   * @returns {stellar.Keypair[]} array of user and backup keypairs
   */
  initiateRecovery(params) {
    const keys = [];
    let userKey = params.userKey;
    let backupKey = params.backupKey;

    // Stellar's Ed25519 public keys start with a G, while private keys start with an S
    const isKrsRecovery = backupKey.startsWith('G') && !userKey.startsWith('G');
    const isUnsignedSweep = backupKey.startsWith('G') && userKey.startsWith('G');


    if (isKrsRecovery && _.isUndefined(config.krsProviders[params.krsProvider])) {
      throw new Error(`Unknown key recovery service provider - ${params.krsProvider}`);
    }

    if (isKrsRecovery && !config.krsProviders[params.krsProvider].supportedCoins.includes(this.getFamily())) {
      throw new Error(`Specified key recovery service does not support recoveries for ${this.getChain()}`);
    }

    if (!this.isValidAddress(params.recoveryDestination)) {
      throw new Error('Invalid destination address!');
    }

    try {
      if (!userKey.startsWith('S') && !userKey.startsWith('G')) {
        userKey = this.bitgo.decrypt({
          input: userKey,
          password: params.walletPassphrase
        });
      }

      const userKeyPair = isUnsignedSweep ? stellar.Keypair.fromPublicKey(userKey) : stellar.Keypair.fromSecret(userKey);
      keys.push(userKeyPair);
    } catch (e) {
      throw new Error('Failed to decrypt user key with passcode - try again!');
    }

    try {
      if (!backupKey.startsWith('S') && !isKrsRecovery && !isUnsignedSweep) {
        backupKey = this.bitgo.decrypt({
          input: backupKey,
          password: params.walletPassphrase
        });
      }

      if (isKrsRecovery || isUnsignedSweep) {
        keys.push(stellar.Keypair.fromPublicKey(backupKey));
      } else {
        keys.push(stellar.Keypair.fromSecret(backupKey));
      }
    } catch (e) {
      throw new Error('Failed to decrypt backup key with passcode - try again!');
    }

    return keys;
  }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:62,代码来源:xlm.ts

示例2: verifySignature

 /**
  * Verifies if signature for message is valid.
  *
  * @param pub {String} public key
  * @param message {Buffer|String} signed message
  * @param signature {Buffer} signature to verify
  * @returns {Boolean} true if signature is valid.
  */
 verifySignature(pub, message, signature) {
   if (!this.isValidPub(pub)) {
     throw new Error(`invalid pub: ${pub}`);
   }
   if (!Buffer.isBuffer(message)) {
     message = Buffer.from(message);
   }
   const keyPair = stellar.Keypair.fromPublicKey(pub);
   return keyPair.verify(message, signature);
 }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:18,代码来源:xlm.ts


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