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


TypeScript Keypair.fromSecret方法代码示例

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


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

示例1: signTransaction

  /**
   * Assemble keychain and half-sign prebuilt transaction
   *
   * @param params
   * @param params.txPrebuild {Object} prebuild object returned by platform
   * @param params.prv {String} user prv
   */
  signTransaction(params) {
    const { txPrebuild, prv } = params;

    if (_.isUndefined(txPrebuild)) {
      throw new Error('missing txPrebuild parameter');
    }
    if (!_.isObject(txPrebuild)) {
      throw new Error(`txPrebuild must be an object, got type ${typeof txPrebuild}`);
    }

    if (_.isUndefined(prv)) {
      throw new Error('missing prv parameter to sign transaction');
    }
    if (!_.isString(prv)) {
      throw new Error(`prv must be a string, got type ${typeof prv}`);
    }

    const keyPair = stellar.Keypair.fromSecret(prv);
    const tx = new stellar.Transaction(txPrebuild.txBase64);
    tx.sign(keyPair);

    return {
      halfSigned: {
        txBase64: tx.toEnvelope().toXDR('base64')
      }
    };
  }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:34,代码来源:xlm.ts

示例2: signMessage

 /**
  * Sign message with private key
  *
  * @param key
  * @param message
  */
 signMessage(key, message) {
   if (!this.isValidPrv(key.prv)) {
     throw new Error(`invalid prv: ${key.prv}`);
   }
   if (!Buffer.isBuffer(message)) {
     message = Buffer.from(message);
   }
   const keypair = stellar.Keypair.fromSecret(key.prv);
   return keypair.sign(message);
 }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:16,代码来源:xlm.ts

示例3: 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


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