How to use js-xdr - 10 common examples

To help you get started, we’ve selected a few js-xdr 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 tokend / new-js-sdk / src / base / memo.js View on Github external
number = new BigNumber(id)
    } catch (e) {
      throw error
    }

    // Infinity
    if (!number.isFinite()) {
      throw error
    }

    // NaN
    if (number.isNaN()) {
      throw error
    }

    return xdr.Memo.memoId(UnsignedHyper.fromString(id))
  }
github spacemeshos / smapp / app / infra / cryptoService / cryptoService.js View on Github external
const sk = fromHexString(secretKey);
    const types = xdr.config((xdr1) => {
      xdr1.struct('InnerSerializableSignedTransaction', [
        ['AccountNonce', xdr1.uhyper()],
        ['Recipient', xdr1.opaque(20)],
        ['GasLimit', xdr1.uhyper()],
        ['Price', xdr1.uhyper()],
        ['Amount', xdr1.uhyper()]
      ]);
      xdr1.struct('SerializableSignedTransaction', [
        ['InnerSerializableSignedTransaction', xdr1.lookup('InnerSerializableSignedTransaction')],
        ['Signature', xdr1.opaque(64)]
      ]);
    });
    const message = new types.InnerSerializableSignedTransaction({
      AccountNonce: xdr.UnsignedHyper.fromString(accountNonce),
      Recipient: fromHexString(recipient).slice(12),
      GasLimit: xdr.UnsignedHyper.fromString('5'), // TODO: change to real number passed from user selection
      Price: xdr.UnsignedHyper.fromString(`${price}`),
      Amount: xdr.UnsignedHyper.fromString(`${amount}`)
    });
    const bufMessage = message.toXDR();
    return new Promise((resolve) => {
      const bufMessageAsUint8Array = new Uint8Array(bufMessage);
      // eslint-disable-next-line no-undef
      __signTransaction(sk, bufMessageAsUint8Array, (sig) => {
        const tx = new types.SerializableSignedTransaction({
          InnerSerializableSignedTransaction: message,
          Signature: sig
        });
        resolve(tx.toXDR());
      });
github spacemeshos / smapp / app / infra / cryptoService / cryptoService.js View on Github external
xdr1.struct('InnerSerializableSignedTransaction', [
        ['AccountNonce', xdr1.uhyper()],
        ['Recipient', xdr1.opaque(20)],
        ['GasLimit', xdr1.uhyper()],
        ['Price', xdr1.uhyper()],
        ['Amount', xdr1.uhyper()]
      ]);
      xdr1.struct('SerializableSignedTransaction', [
        ['InnerSerializableSignedTransaction', xdr1.lookup('InnerSerializableSignedTransaction')],
        ['Signature', xdr1.opaque(64)]
      ]);
    });
    const message = new types.InnerSerializableSignedTransaction({
      AccountNonce: xdr.UnsignedHyper.fromString(accountNonce),
      Recipient: fromHexString(recipient).slice(12),
      GasLimit: xdr.UnsignedHyper.fromString('5'), // TODO: change to real number passed from user selection
      Price: xdr.UnsignedHyper.fromString(`${price}`),
      Amount: xdr.UnsignedHyper.fromString(`${amount}`)
    });
    const bufMessage = message.toXDR();
    return new Promise((resolve) => {
      const bufMessageAsUint8Array = new Uint8Array(bufMessage);
      // eslint-disable-next-line no-undef
      __signTransaction(sk, bufMessageAsUint8Array, (sig) => {
        const tx = new types.SerializableSignedTransaction({
          InnerSerializableSignedTransaction: message,
          Signature: sig
        });
        resolve(tx.toXDR());
      });
    });
  };
github stellar / js-stellar-base / src / operations / bump_sequence.js View on Github external
export function bumpSequence(opts) {
  const attributes = {};

  if (!isString(opts.bumpTo)) {
    throw new Error('bumpTo must be a string');
  }

  try {
    // eslint-disable-next-line no-new
    new BigNumber(opts.bumpTo);
  } catch (e) {
    throw new Error('bumpTo must be a stringified number');
  }

  attributes.bumpTo = Hyper.fromString(opts.bumpTo);

  const bumpSequenceOp = new xdr.BumpSequenceOp(attributes);

  const opAttributes = {};
  opAttributes.body = xdr.OperationBody.bumpSequence(bumpSequenceOp);
  this.setSourceAccount(opAttributes, opts);

  return new xdr.Operation(opAttributes);
}
github astroband / astrograph / src / orm / entities / account.ts View on Github external
from: (value: string | null) => {
        if (!value) {
          return null;
        }
        const signersArray = new VarArray(xdr.Signer).fromXDR(value, "base64");
        return signersArray.map((signerXDR: any) => SignerFactory.fromXDR(signerXDR));
      },
      // we don't actually need `to` transform,
github spacemeshos / smapp / app / infra / cryptoService / cryptoService.js View on Github external
signTransaction = ({ accountNonce, recipient, price, amount, secretKey }: { accountNonce: number, recipient: string, price: number, amount: number, secretKey: string }) => {
    const sk = fromHexString(secretKey);
    const types = xdr.config((xdr1) => {
      xdr1.struct('InnerSerializableSignedTransaction', [
        ['AccountNonce', xdr1.uhyper()],
        ['Recipient', xdr1.opaque(20)],
        ['GasLimit', xdr1.uhyper()],
        ['Price', xdr1.uhyper()],
        ['Amount', xdr1.uhyper()]
      ]);
      xdr1.struct('SerializableSignedTransaction', [
        ['InnerSerializableSignedTransaction', xdr1.lookup('InnerSerializableSignedTransaction')],
        ['Signature', xdr1.opaque(64)]
      ]);
    });
    const message = new types.InnerSerializableSignedTransaction({
      AccountNonce: xdr.UnsignedHyper.fromString(accountNonce),
      Recipient: fromHexString(recipient).slice(12),
      GasLimit: xdr.UnsignedHyper.fromString('5'), // TODO: change to real number passed from user selection
github stellar / js-stellar-base / src / generated / stellar-xdr_generated.js View on Github external
// Automatically generated on 2019-10-02T15:45:16-07:00
// DO NOT EDIT or your changes may be overwritten

/* jshint maxstatements:2147483647  */
/* jshint esnext:true  */

import * as XDR from 'js-xdr';


var types = XDR.config(xdr => {

// === xdr source ============================================================
//
//   typedef PublicKey AccountID;
//
// ===========================================================================
xdr.typedef("AccountId", xdr.lookup("PublicKey"));

// === xdr source ============================================================
//
//   typedef opaque Thresholds[4];
//
// ===========================================================================
xdr.typedef("Thresholds", xdr.opaque(4));

// === xdr source ============================================================
github tokend / new-js-sdk / src / base / operations / create_account_builder.js View on Github external
ext: new xdr.CreateAccountOpExt(xdr.LedgerVersion.emptyVersion())
    }

    if (!isUndefined(opts.referrer) && !(opts.referrer === '')) {
      console.log(opts.referrer)
      if (!Keypair.isValidPublicKey(opts.referrer)) {
        throw new TypeError('referrer is invalid')
      }
      attrs.referrer = Keypair.fromAccountId(opts.referrer).xdrAccountId()
    }

    if (isUndefined(opts.roleID)) {
      throw new Error('roleID is undefined')
    }

    attrs.roleId = UnsignedHyper.fromString(opts.roleID)

    if (isUndefined(opts.signersData)) {
      throw new Error('signersData is undefined')
    }

    if (!isArray(opts.signersData)) {
      throw new Error('signersData is not array')
    }

    if (opts.signersData.length === 0) {
      throw new Error('signersData is empty')
    }

    attrs.signersData = []
    for (let signerData of opts.signersData) {
      attrs.signersData.push(ManageSignerBuilder.prepareUpdateSignerData(signerData))
github tokend / new-js-sdk / src / base / operations / manage_sale.js View on Github external
static cancelSale (opts) {
    if (isUndefined(opts.saleID)) {
      throw new Error('opts.saleID is invalid')
    }

    let manageSaleOp = new xdr.ManageSaleOp({
      saleId: UnsignedHyper.fromString(opts.saleID),
      data: new xdr.ManageSaleOpData.cancel(),
      ext: new xdr.ManageSaleOpExt(xdr.LedgerVersion.emptyVersion())
    })

    let opAttrs = {}
    opAttrs.body = xdr.OperationBody.manageSale(manageSaleOp)
    BaseOperation.setSourceAccount(opAttrs, opts)
    return new xdr.Operation(opAttrs)
  }
github tokend / new-js-sdk / src / base / operations / manage_reviewable_request_builder.js View on Github external
})
    validateArray({
      value: opts.operations,
      fieldName: 'opts.operations',
      minLength: 1,
      maxLength: 100
    })

    let rrOperations = []
    for (let op of opts.operations) {
      rrOperations.push(this.convertOperationToReviewableRequestOperation(op))
    }

    let attributes = {
      creatorDetails: JSON.stringify(opts.creatorDetails),
      requestId: UnsignedHyper.fromString(opts.requestID),
      operations: rrOperations,
      ext: new xdr.EmptyExt(xdr.LedgerVersion.emptyVersion())
    }

    let updateRequest = new xdr.UpdateReviewableRequestOp(attributes)

    let opAttributes = {}
    opAttributes.body = new xdr.OperationBody.updateReviewableRequest(updateRequest)
    BaseOperation.setSourceAccount(opAttributes, opts)
    return new xdr.Operation(opAttributes)
  }

js-xdr

Read/write XDR encoded data structures (RFC 4506)

Apache-2.0
Latest version published 5 months ago

Package Health Score

56 / 100
Full package analysis

Similar packages