當前位置: 首頁>>代碼示例>>TypeScript>>正文


TypeScript stellar-sdk.StrKey類代碼示例

本文整理匯總了TypeScript中stellar-sdk.StrKey的典型用法代碼示例。如果您正苦於以下問題:TypeScript StrKey類的具體用法?TypeScript StrKey怎麽用?TypeScript StrKey使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了StrKey類的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的TypeScript代碼示例。

示例1: getAddressDetails

  /**
   * Process address into address and memo id
   *
   * @param address {String} the address
   * @returns {Object} object containing address and memo id
   */
  getAddressDetails(address) {
    const destinationDetails = url.parse(address);
    const queryDetails = querystring.parse(destinationDetails.query);
    const destinationAddress = destinationDetails.pathname;
    if (!stellar.StrKey.isValidEd25519PublicKey(destinationAddress)) {
      throw new Error(`invalid address: ${address}`);
    }
    // address doesn't have a memo id
    if (destinationDetails.pathname === address) {
      return {
        address: address,
        memoId: null
      };
    }

    if (!queryDetails.memoId) {
      // if there are more properties, the query details need to contain the memo id property
      throw new Error(`invalid address: ${address}`);
    }

    try {
      new BigNumber(queryDetails.memoId);
    } catch (e) {
      throw new Error(`invalid address: ${address}`);
    }

    if (!this.isValidMemoId(queryDetails.memoId)) {
      throw new Error(`invalid address: ${address}`);
    }

    return {
      address: destinationAddress,
      memoId: queryDetails.memoId
    };
  }
開發者ID:BitGo,項目名稱:BitGoJS,代碼行數:41,代碼來源:xlm.ts

示例2: normalizeAddress

 /**
  * Validate and return address with appended memo id
  *
  * @param address {String} address
  * @param memoId {String} memo id
  * @returns {String} address with memo id
  */
 normalizeAddress({ address, memoId }) {
   if (!stellar.StrKey.isValidEd25519PublicKey(address)) {
     throw new Error(`invalid address details: ${address}`);
   }
   if (this.isValidMemoId(memoId)) {
     return `${address}?memoId=${memoId}`;
   }
   return address;
 }
開發者ID:BitGo,項目名稱:BitGoJS,代碼行數:16,代碼來源:xlm.ts

示例3: it

  it('should generate a keypair from seed', function() {
    const seed = crypto.randomBytes(32);
    const keyPair = basecoin.generateKeyPair(seed);
    keyPair.should.have.property('pub');
    keyPair.should.have.property('prv');

    const address = keyPair.pub;
    basecoin.isValidAddress(address).should.equal(true);

    basecoin.isValidPub(keyPair.pub).should.equal(true);
    basecoin.isValidPrv(keyPair.prv).should.equal(true);

    const secret = keyPair.prv;
    stellar.StrKey.encodeEd25519SecretSeed(seed).should.equal(secret);
  });
開發者ID:BitGo,項目名稱:BitGoJS,代碼行數:15,代碼來源:xlm.ts

示例4: co

 return co(function *() {
   // The wallet will have 3 keychains on it, usually 2 of those are generated by the platform, and 1 is generated by the user.
   // Initially, we need a root prv to generate the account, which has to be distinct from all three keychains on the wallet.
   // If a root prv is not provided, we generate a random one.
   let seed;
   const rootPrv = walletParams.rootPrivateKey;
   if (rootPrv) {
     if (!this.isValidPrv(rootPrv)) {
       throw new Error('rootPrivateKey needs to be valid ed25519 secret seed');
     }
     seed = stellar.StrKey.decodeEd25519SecretSeed(rootPrv);
   }
   const keyPair = this.generateKeyPair(seed);
   // extend the wallet initialization params
   walletParams.rootPrivateKey = keyPair.prv;
   return walletParams;
 }).call(this);
開發者ID:BitGo,項目名稱:BitGoJS,代碼行數:17,代碼來源:xlm.ts

示例5: isValidPub

 /**
  * Return boolean indicating whether input is valid public key for the coin.
  *
  * @param {String} pub the pub to be checked
  * @returns {Boolean} is it valid?
  */
 isValidPub(pub) {
   return stellar.StrKey.isValidEd25519PublicKey(pub);
 }
開發者ID:BitGo,項目名稱:BitGoJS,代碼行數:9,代碼來源:xlm.ts

示例6: getPrvFromRaw

 /**
  * Get decoded ed25519 private key from raw data
  *
  * @param prv {String} Raw private key
  * @returns {String} Encoded private key
  */
 getPrvFromRaw(prv) {
   return stellar.StrKey.encodeEd25519SecretSeed(Buffer.from(prv, 'hex'));
 }
開發者ID:BitGo,項目名稱:BitGoJS,代碼行數:9,代碼來源:xlm.ts

示例7: getPubFromRaw

 /**
  * Get decoded ed25519 public key from raw data
  *
  * @param pub {String} Raw public key
  * @returns {String} Encoded public key
  */
 getPubFromRaw(pub) {
   return stellar.StrKey.encodeEd25519PublicKey(Buffer.from(pub, 'hex'));
 }
開發者ID:BitGo,項目名稱:BitGoJS,代碼行數:9,代碼來源:xlm.ts

示例8: isValidPrv

 /**
  * Return boolean indicating whether input is valid private key for the coin
  *
  * @param {String} prv the prv to be checked
  * @returns {Boolean} is it valid?
  */
 isValidPrv(prv) {
   return stellar.StrKey.isValidEd25519SecretSeed(prv);
 }
開發者ID:BitGo,項目名稱:BitGoJS,代碼行數:9,代碼來源:xlm.ts


注:本文中的stellar-sdk.StrKey類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。