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


TypeScript stellar-sdk.Keypair类代码示例

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


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

示例1: generateKeyPair

 /**
  * Generate ed25519 key pair
  *
  * @param seed
  * @returns {Object} object with generated pub and prv
  */
 generateKeyPair(seed) {
   const pair = seed ? stellar.Keypair.fromRawEd25519Seed(seed) : stellar.Keypair.random();
   return {
     pub: pair.publicKey(),
     prv: pair.secret()
   };
 }
开发者ID:BitGo,项目名称:BitGoJS,代码行数:13,代码来源:xlm.ts

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

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

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

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

示例6:

import * as StellarSdk from 'stellar-sdk';

const sourceKey = StellarSdk.Keypair.random(); // $ExpectType Keypair
const destKey = StellarSdk.Keypair.random();
const account = new StellarSdk.Account(sourceKey.publicKey(), '1');
const transaction = new StellarSdk.TransactionBuilder(account)
    .addOperation(StellarSdk.Operation.accountMerge({destination: destKey.publicKey()}))
    .addMemo(new StellarSdk.Memo(StellarSdk.MemoText, "memo"))
    .build(); // $ExpectType () => Transaction
transaction; // $ExpectType Transaction

StellarSdk.StellarTomlResolver.resolve("example.com", {allowHttp: true, timeout: 100})
    .then(toml => toml.FEDERATION_SERVER);

const sig = StellarSdk.xdr.DecoratedSignature.fromXDR(Buffer.of(1, 2)); // $ExpectType DecoratedSignature
sig.hint(); // $ExpectType Buffer
sig.signature(); // $ExpectType Buffer

StellarSdk.Memo.none(); // $ExpectType Memo<"none">
StellarSdk.Memo.text('asdf'); // $ExpectType Memo<"text">
StellarSdk.Memo.id('asdf'); // $ExpectType Memo<"id">
StellarSdk.Memo.return('asdf'); // $ExpectType Memo<"return">
StellarSdk.Memo.hash('asdf'); // $ExpectType Memo<"hash">
StellarSdk.Memo.none().value; // $ExpectType null
StellarSdk.Memo.id('asdf').value; // $ExpectType string
StellarSdk.Memo.text('asdf').value; // $ExpectType string
StellarSdk.Memo.return('asdf').value; // $ExpectType Buffer
StellarSdk.Memo.hash('asdf').value; // $ExpectType Buffer

// P.S. don't use Memo constructor
(new StellarSdk.Memo(StellarSdk.MemoHash, 'asdf')).value; // $ExpectType AnyValue
开发者ID:,项目名称:,代码行数:31,代码来源:


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