How to use stellar-base - 10 common examples

To help you get started, we’ve selected a few stellar-base 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 stellar / js-stellar-sdk / src / federation_server.ts View on Github external
public static async resolve(
    value: string,
    opts: FederationServer.Options = {},
  ): Promise {
    // Check if `value` is in account ID format
    if (value.indexOf("*") < 0) {
      if (!StrKey.isValidEd25519PublicKey(value)) {
        return Promise.reject(new Error("Invalid Account ID"));
      }
      return Promise.resolve({ account_id: value });
    }

    const addressParts = value.split("*");
    const [, domain] = addressParts;

    if (addressParts.length !== 2 || !domain) {
      return Promise.reject(new Error("Invalid Stellar address"));
    }
    const federationServer = await FederationServer.createForDomain(
      domain,
      opts,
    );
    return federationServer.resolveAddress(value);
github stellar / js-stellar-sdk / src / server.ts View on Github external
);
                  const claimedOfferAmountSold = new BigNumber(
                    // amountBought is a js-xdr hyper
                    offerClaimed.amountSold().toString(),
                  );

                  // This is an offer that was filled by the one just submitted.
                  // So this offer has an _opposite_ bought/sold frame of ref
                  // than from what we just submitted!
                  // So add this claimed offer's bought to the SOLD count and vice v

                  amountBought = amountBought.add(claimedOfferAmountSold);
                  amountSold = amountSold.add(claimedOfferAmountBought);

                  const sold = Asset.fromOperation(offerClaimed.assetSold());
                  const bought = Asset.fromOperation(
                    offerClaimed.assetBought(),
                  );

                  const assetSold = {
                    type: sold.getAssetType(),
                    assetCode: sold.getCode(),
                    issuer: sold.getIssuer(),
                  };

                  const assetBought = {
                    type: bought.getAssetType(),
                    assetCode: bought.getCode(),
                    issuer: bought.getIssuer(),
                  };

                  return {
github stellar / js-stellar-sdk / src / transaction.js View on Github external
constructor(envelope) {
        if (typeof envelope === "string") {
            let buffer = new Buffer(envelope, "hex");
            envelope = xdr.TransactionEnvelope.fromXdr(buffer);
        }
        // since this transaction is immutable, save the tx
        this.tx = envelope._attributes.tx;
        this.source = encodeBase58Check("accountId", envelope._attributes.tx._attributes.sourceAccount);
        this.fee = envelope._attributes.tx._attributes.fee;
        this.sequence = envelope._attributes.tx._attributes.seqNum.toString();
        this.minLedger = envelope._attributes.tx._attributes.minLedger;
        this.maxLedger = envelope._attributes.tx._attributes.maxLedger;
        let operations = envelope._attributes.tx._attributes.operations;
        this.operations = [];
        for (let i = 0; i < operations.length; i++) {
            this.operations[i] = Operation.operationToObject(operations[i]._attributes);
        }
        let signatures = envelope._attributes.signatures;
        this.signatures = [];
        for (let i = 0; i < signatures.length; i++) {
            this.signatures[i] = signatures[i];
        }
    }
github stellar / js-stellar-sdk / lib / index.js View on Github external
_defaults(exports, _interopRequireWildcard(require("./errors")));

exports.Server = require("./server").Server;

// expose classes from stellar-base

var _stellarBase = require("stellar-base");

exports.Account = _stellarBase.Account;
exports.Transaction = _stellarBase.Transaction;
exports.TransactionBuilder = _stellarBase.TransactionBuilder;
exports.Asset = _stellarBase.Asset;
exports.Operation = _stellarBase.Operation;
exports.Keypair = _stellarBase.Keypair;
exports.Memo = _stellarBase.Memo;
exports.xdr = _stellarBase.xdr;
github stellar / js-stellar-sdk / src / account_response.ts View on Github external
constructor(response: ServerApi.AccountRecord) {
    this._baseAccount = new BaseAccount(response.account_id, response.sequence);
    // Extract response fields
    // TODO: do it in type-safe manner.
    forIn(response, (value, key) => {
      (this as any)[key] = value;
    });
  }
github stellar / js-stellar-sdk / src / utils.ts View on Github external
export function buildChallengeTx(
    serverKeypair: Keypair,
    clientAccountID: string,
    anchorName: string,
    timeout: number = 300,
    networkPassphrase?: string,
  ): string {
    const account = new Account(serverKeypair.publicKey(), "-1");
    const now = Math.floor(Date.now() / 1000);

    // A Base64 digit represents 6 bits, to generate a random 64 bytes
    // base64 string, we need 48 random bytes = (64 * 6)/8
    //
    // Each Base64 digit is in ASCII and each ASCII characters when
    // turned into binary represents 8 bits = 1 bytes.
    const value = randomBytes(48).toString("base64");

    const transaction = new TransactionBuilder(account, {
      fee: BASE_FEE,
      networkPassphrase,
      timebounds: {
        minTime: now,
        maxTime: now + timeout,
      },
github astroband / astrograph / tests / factories / account.ts View on Github external
  .attr("id", () => stellar.Keypair.random().publicKey())
  .attr("balance", "19729999500")
github astroband / astrograph / tests / factories / signer.ts View on Github external
  .attr("signer", () => stellar.Keypair.random().publicKey())
  .attr("weight", () => Math.floor(Math.random() * 5));
github astroband / astrograph / tests / factories / signer.ts View on Github external
  .attr("accountID", () => stellar.Keypair.random().publicKey())
  .attr("signer", () => stellar.Keypair.random().publicKey())
github astroband / astrograph / tests / factories / account_values.ts View on Github external
  .attr("id", () => stellar.Keypair.random().publicKey())
  .attr("balance", "19729999500")