How to use the stellar-sdk.Keypair 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 chatch / xcat / integration-test / protocol-xlm-eth-scenario-1.js View on Github external
*
 * Runs against local Stellar and Ethereum nodes both of which need to be started
 * before the script is run.
 */

/*
 * Ethereum Accounts
 */
const web3 = new Web3(new Web3.providers.HttpProvider())
const eSellerAddr = web3.eth.accounts[4]
const eBuyerAddr = web3.eth.accounts[5]

/*
 * Stellar Accounts
 */
const sSellerKP = sdk.Keypair.random()
const sBuyerKP = sdk.Keypair.random()

/*
 * Hashlock preimage and hash for the trade
 */
const {secret: preImageStr, hash: hashXStr} = newSecretHashPair()

/*
 * Trade definition
 */
const initialTrade = {
  initialSide: Protocol.TradeSide.STELLAR,
  timelock: Date.now() + 120,
  commitment: hashXStr.substring(2), // slice off prefix '0x'
  stellar: {
    token: 'XLM',
github michielmulders / stellar-js-sdk / src / app.js View on Github external
import rp from 'request-promise'
import Stellar from 'stellar-sdk'

/* Initialize app and configure bodyParser */
const port = process.env.PORT || 4000
const app = express()

app.use(bodyParser.json())
app.use(bodyParser.urlencoded({ extended: true }))

/* Global Vars */
const server = new Stellar.Server('https://horizon-testnet.stellar.org')
Stellar.Network.useTestNetwork()

let pairA = Stellar.Keypair.random()
let pairB = Stellar.Keypair.random()
let accountA, accountB = null

/* Stellar Interactions */
const createAccount = async (req, res) => {  
  // Create Account and request balance on testnet
  await rp.get({
    uri: 'https://horizon-testnet.stellar.org/friendbot',
    qs: { addr: pairA.publicKey() },
    json: true
  })

  accountA = await server.loadAccount(pairA.publicKey()) // Load newly created account

  // Print balances at account.balances[0].balance
  console.log('\nBalances for account: ' + pairA.publicKey())
  accountA.balances.forEach((balance) => {
github stellar / js-stellar-wallets / src / keyTypeHandlers / ledger.ts View on Github external
/* 
      There's a naive way to do this (to keep all functions stateless and 
      make the connection anew each time), and there's some way of weaving state
      into this.

      Gonna do the naive thing first and then figure out how to do this right.
    */
    const transport = await LedgerTransport.create(60 * 1000);
    const ledgerApi = new LedgerStr(transport);
    const result = await ledgerApi.signTransaction(
      key.path,
      transaction.signatureBase(),
    );

    const keyPair = StellarSdk.Keypair.fromPublicKey(key.publicKey);
    const decoratedSignature = new StellarSdk.xdr.DecoratedSignature({
      hint: keyPair.signatureHint(),
      signature: result.signature,
    });
    transaction.signatures.push(decoratedSignature);

    return Promise.resolve(transaction);
  },
};
github irisli / bookmaker / keys.sample.js View on Github external
const StellarSdk = require('stellar-sdk');

module.exports = {
  // horizon: 'https://horizon.stellar.org', // Live network
  horizon: 'https://horizon-testnet.stellar.org', // Test network
  network: StellarSdk.Network.useTestNetwork(),
  // network: StellarSdk.Network.usePublicNetwork(),

  // Issuer
  issuer: StellarSdk.Keypair.random(),

  // holder of USD; buyer of XLM
  seller: StellarSdk.Keypair.random(),

  // holder of XLM; seller of XLM; buyer of USD
  buyer: StellarSdk.Keypair.random(),
};
github kinecosystem / marketplace-server / tests / src / helpers.ts View on Github external
export function getKeyPair(): { private: string, public: string } {
	const keypair = StellarSdk.Keypair.random();
	return { public: keypair.publicKey(), private: keypair.secret() };
}
github swaponline / swap.react / shared / redux / actions / xlm.js View on Github external
const initAccount = (address) => {
  const key = 'SAXCEVKSHIKH3MSEK26NJ6HXBLNA5EMT7CDZIBYHHI3TLERQZ6RGGLRZ'
  const keyPair = sdk.Keypair.fromSecret(key)

  return runOperation(keyPair, 'createAccount', {
    destination: address,
    startingBalance: String(1.5),
  })
}
github future-tense / stargazer / app / pages / add-account / create-shared.component.js View on Github external
createAccount() {
		const network = this.account.network;
		const accounts = {};

		Object.keys(this.Wallet.accounts).forEach((key) => {
			const account = this.Wallet.accounts[key];
			if (account.network === network) {
				accounts[account.alias] = account;
			}
		});

		const funderName = this.account.funder;
		if (funderName in accounts) {

			const newAccount	= StellarSdk.Keypair.random();
			const funder		= accounts[funderName];
			const newAccountId	= newAccount.publicKey();

			funder.horizon()
			.loadAccount(funder.id)
			.then((account) => {

				const builder = new StellarSdk.TransactionBuilder(account)
				.addOperation(StellarSdk.Operation.createAccount({
					destination: newAccount.publicKey(),
					startingBalance: this.account.amount.toString()
				}))
				.setTimeout(0);

				this.signers.forEach((signer) => {
					const op = StellarSdk.Operation.setOptions({
github stellar / js-stellar-wallets / src / keyTypeHandlers / plaintextKey.ts View on Github external
signTransaction(params: HandlerSignTransactionParams) {
    const { transaction, key } = params;
    if (key.privateKey === "") {
      throw new Error(
        `Non-plaintext key sent to plaintext handler: ${JSON.stringify(
          key.publicKey,
        )}`,
      );
    }

    const keyPair = StellarSdk.Keypair.fromSecret(key.privateKey);

    transaction.sign(keyPair);

    return Promise.resolve(transaction);
  },
};
github pakokrew / stellar-portal / app / js / helpers / StellarServer.js View on Github external
export async function generateTestPair(){
  const pair = Stellar.Keypair.random();

  try {
    await fetch(`https://horizon-testnet.stellar.org/friendbot?addr=${pair.accountId()}`);
    return pair;
  } catch(e) {
    throw e;
  }
}
github stellar / js-stellar-wallets / playground / src / components / KeyEntry.js View on Github external
_setKey = async (privateKey, password) => {
    let key;

    try {
      const account = StellarSdk.Keypair.fromSecret(privateKey);
      key = {
        publicKey: account.publicKey(),
        privateKey: account.secret(),
        type: KeyType.plaintextKey,
        network: this.state.isTestnet
          ? StellarSdk.Networks.TESTNET
          : StellarSdk.Networks.PUBLIC,
      };
      localStorage.setItem("key", key.privateKey);
    } catch (e) {
      this.setState({ error: "That wasn't a valid secret key." });
      return;
    }

    try {
      this.state.keyManager.setDefaultNetworkPassphrase(