How to use the stellar-sdk.StrKey function in stellar-sdk

To help you get started, we’ve selected a few stellar-sdk examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github DnD-industries / stellar_tipping_bot / src / adapters / abstract.js View on Github external
withdrawalAmount = new Big(amountRequested);
    } catch (e) {
      console.log(`Bad data fed to new Big() in Adapter::receiveWithdrawalRequest()\n${JSON.stringify(e)}`);
      console.log(`Withdrawal request amount is ${amountRequested}`);
      this.getLogger().CommandEvents.onWithdrawalInvalidAmountProvided(withdrawalRequest)
      return this.onWithdrawalInvalidAmountProvided(withdrawalRequest);
    }
    const fixedAmount = withdrawalAmount.toFixed(7);

    if(typeof address === 'undefined' || address === null) {
      this.getLogger().CommandEvents.onWithdrawalNoAddressProvided(withdrawalRequest)
        return this.onWithdrawalNoAddressProvided(withdrawalRequest);
    }


    if (!StellarSdk.StrKey.isValidEd25519PublicKey(address)) {
      this.getLogger().CommandEvents.onWithdrawalBadlyFormedAddress(withdrawalRequest, address)
      return this.onWithdrawalInvalidAddress(withdrawalRequest);
    }

    // Fetch the account
    const target = await withdrawalRequest.getSourceAccount();
    // TODO: Rather than having this fetch occur here, I think it might make more sense to move this to the  Command constructor
    if (!target.canPay(withdrawalAmount)) {
      this.getLogger().CommandEvents.onWithdrawalInsufficientBalance(withdrawalRequest, target.balance)
      return this.onWithdrawalFailedWithInsufficientBalance(withdrawalRequest, target.balance);
    }

    // Withdraw
    try {
      // txHash is the hash from the stellar blockchain, not our internal hash
      const txHash = await target.withdraw(this.config.stellar, address, withdrawalAmount, hash);
github DnD-industries / stellar_tipping_bot / src / models / account.js View on Github external
beforeSave: function () {
        const now = new Date()

        // If our walletAddress is set, we need to make sure it's a valid wallet address before saving
        if(typeof this.walletAddress !== 'undefined' && this.walletAddress !== null) {
          if(!StellarSdk.StrKey.isValidEd25519PublicKey(this.walletAddress)) {
            this.walletAddress = null
            return Promise.reject(new Error('BAD_PUBLIC_WALLET_ADDRESS'))
          }
        }

        if(!this.hasAcceptedTerms) {
          this.hasAcceptedTerms = false
        }

        if (!this.createdAt) {
          this.createdAt = now.toISOString()
        }
        if (!this.balance) {
          this.balance = '0.0000000'
        }
        this.updatedAt = now.toISOString()
github BitGo / BitGoJS / test / v2 / unit / coins / xlm.js View on Github external
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);
  });
github chatch / xcat / src / utils.js View on Github external
const isStellarSecretSeed = addr =>
  stellarSdk.StrKey.isValidEd25519SecretSeed(addr)
const isStellarFederatedAddress = addr => /^[^*,]*\*[a-z0-9-.]*$/i.test(addr)
github future-tense / stargazer / app / core / directives / valid-seed.js View on Github external
ngModel.$validators.validSeed = function (modelValue) {
				return StellarSdk.StrKey.isValidEd25519SecretSeed(modelValue);
            };
		}
github ncent / ncent.github.io / hackCent / August2018 / learnCent / server / utils / sdk_utils.js View on Github external
const createKeypair = () => {
  const wallet = sdk.createWalletAddress();
  const publicKey = wallet.publicKey();
  const privateKey = StellarSdk.StrKey.encodeEd25519SecretSeed(wallet._secretSeed);
  return ({publicKey, privateKey});
};
github future-tense / stargazer / app / core / services / commands.js View on Github external
else if (data.stellar.payment) {
				handlePayment(data.stellar.payment);
			}

			else if (data.stellar.challenge) {
				handleChallenge(data.stellar.challenge);
			}
		}

		catch (err) {
			if (qrData.startsWith('centaurus:backup003')) {
				handleCentaurusImport(qrData);
			}

			else if (StellarSdk.StrKey.isValidEd25519PublicKey(qrData)) {
				const contact = {
					id: qrData
				};
				handleContact(contact);
			}
		}
	}
github stellarchat / desktop-client / src / main / authdata.filesystem.v2.js View on Github external
const validateContact = (c) => {
  if(c.address) {
    if(!StellarSdk.StrKey.isValidEd25519PublicKey(c.address)) throw new Error('Not a valid address.');
  }
  if(c.federation) {
    if(typeof c.federation !== 'string') throw new Error('Invalid federation.');
  }
  if(!c.address && !c.federation) throw new Error('Either address or federation required, or both.');
  if(typeof c.name !== 'string') throw new Error('Invalid name.');
  if(c.name.length > 100) throw new Error(`Too long name, max 100 characters. Got ${c.name.length}.`);
  if(typeof c.details !== 'string') throw new Error('Invalid details.');
  if(c.details.length > 10000) throw new Error(`Too long details, max 10000 characters. Got ${c.name.length}.`);

  if(!moment(c.created, 'YYYY-MM-DDTHH:mm:ssZZ', true).isValid()) throw new Error('Invalid created time.')
  if(!moment(c.updated, 'YYYY-MM-DDTHH:mm:ssZZ', true).isValid()) throw new Error('Invalid created time.')

  switch(c.defaultMemoType) {
    case(StellarSdk.MemoNone):
    case(StellarSdk.MemoId):
github BitGo / BitGoJS / modules / core / src / v2 / coins / xlm.ts View on Github external
normalizeAddress({ address, memoId }: AddressDetails): string {
    if (!stellar.StrKey.isValidEd25519PublicKey(address)) {
      throw new Error(`invalid address details: ${address}`);
    }
    if (memoId && this.isValidMemoId(memoId)) {
      return `${address}?memoId=${memoId}`;
    }
    return address;
  }