How to use the js-xdr.UnsignedHyper function in js-xdr

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 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 / lib / index.js View on Github external
});

var xdr = _interopRequire(require("./generated/stellar-xdr_generated"));

exports.xdr = xdr;
exports.hash = require("./hashing").hash;

var _signing = require("./signing");

exports.sign = _signing.sign;
exports.verify = _signing.verify;
exports.Keypair = require("./keypair").Keypair;

var _jsXdr = require("js-xdr");

exports.UnsignedHyper = _jsXdr.UnsignedHyper;
exports.Hyper = _jsXdr.Hyper;
exports.Transaction = require("./transaction").Transaction;
exports.TransactionBuilder = require("./transaction_builder").TransactionBuilder;
exports.Asset = require("./asset").Asset;
exports.Operation = require("./operation").Operation;
exports.Memo = require("./memo").Memo;
exports.Account = require("./account").Account;

_defaults(exports, _interopRequireWildcard(require("./strkey")));
github tokend / new-js-sdk / lib / base / operations / sale_request_builder.js View on Github external
value: function checkSaleState(opts) {
      if ((0, _isUndefined.default)(opts.saleID)) {
        throw new Error('Invalid opts.saleID');
      }

      var checkSaleStateOp = new _xdr_generated.default.CheckSaleStateOp({
        saleId: _jsXdr.UnsignedHyper.fromString(opts.saleID),
        ext: new _xdr_generated.default.CheckSaleStateOpExt(_xdr_generated.default.LedgerVersion.emptyVersion())
      });
      var opAttributes = {};
      opAttributes.body = _xdr_generated.default.OperationBody.checkSaleState(checkSaleStateOp);

      _base_operation.BaseOperation.setSourceAccount(opAttributes, opts);

      return new _xdr_generated.default.Operation(opAttributes);
    }
  }, {
github tokend / new-js-sdk / lib / base / operations / base_operation.js View on Github external
value: function _toUnsignedXDRAmount(value) {
      var amount = new _bignumber.default(value).mul(ONE);
      return _jsXdr.UnsignedHyper.fromString(amount.toString());
    }
    /**
github tokend / new-js-sdk / lib / base / operations / manage_asset_builder.js View on Github external
value: function _createManageAssetOp(opts, request) {
      if ((0, _isUndefined.default)(opts.requestID)) {
        throw new Error('opts.requestID is invalid');
      }

      var assetUpdateOp = new _xdr_generated.default.ManageAssetOp({
        requestId: _jsXdr.UnsignedHyper.fromString(opts.requestID),
        request: request,
        ext: new _xdr_generated.default.ManageAssetOpExt(_xdr_generated.default.LedgerVersion.emptyVersion())
      });
      var opAttributes = {
        source: undefined
      };
      opAttributes.body = _xdr_generated.default.OperationBody.manageAsset(assetUpdateOp);

      _base_operation.BaseOperation.setSourceAccount(opAttributes, opts);

      return new _xdr_generated.default.Operation(opAttributes);
    }
  }, {
github tokend / new-js-sdk / lib / base / operations / review_request_builder.js View on Github external
value: function _prepareAttrs(opts) {
      var attrs = {};

      if ((0, _isUndefined.default)(opts.requestID) || opts.requestID === '0') {
        throw new Error('opts.requestID is invalid');
      }

      attrs.requestId = _jsXdr.UnsignedHyper.fromString(opts.requestID);
      attrs.requestHash = _hasher.Hasher.hash(opts.requestHash);

      var validAction = opts.action && _xdr_generated.default.ReviewRequestOpAction._byValue.has(opts.action);

      if (!validAction) {
        throw new Error('opts.action is invalid');
      }

      attrs.action = _xdr_generated.default.ReviewRequestOpAction._byValue.get(opts.action);

      if (!_base_operation.BaseOperation.isValidString(opts.reason, 0, 256)) {
        throw new Error('opts.reason is invalid');
      }

      attrs.reason = opts.reason;
github tokend / new-js-sdk / lib / base / operations / sale_request_builder.js View on Github external
value: function createSaleCreationRequest(opts) {
      var request = this.validateSaleCreationRequest(opts);
      var createSaleCreationRequestOp = new _xdr_generated.default.CreateSaleCreationRequestOp({
        requestId: _jsXdr.UnsignedHyper.fromString(opts.requestID),
        request: request,
        allTasks: opts.allTasks,
        ext: new _xdr_generated.default.CreateSaleCreationRequestOpExt(_xdr_generated.default.LedgerVersion.emptyVersion())
      });
      var opAttributes = {};
      opAttributes.body = _xdr_generated.default.OperationBody.createSaleRequest(createSaleCreationRequestOp);

      _base_operation.BaseOperation.setSourceAccount(opAttributes, opts);

      return new _xdr_generated.default.Operation(opAttributes);
    }
    /**
github tokend / new-js-sdk / lib / base / operations / create_update_kyc_request_builder.js View on Github external
value: function createChangeRoleRequest(opts) {
      var attrs = {};

      if ((0, _isUndefined.default)(opts.requestID)) {
        throw new Error('opts.requestID is invalid');
      }

      if (!_keypair.Keypair.isValidPublicKey(opts.destinationAccount)) {
        throw new Error('opts.accountToUpdateKYC is invalid');
      }

      attrs.destinationAccount = _keypair.Keypair.fromAccountId(opts.destinationAccount).xdrAccountId();
      attrs.accountRoleToSet = _jsXdr.UnsignedHyper.fromString(opts.accountRoleToSet);
      attrs.kycData = (0, _stringify.default)(opts.kycData);
      attrs.requestId = _jsXdr.UnsignedHyper.fromString(opts.requestID);
      attrs.allTasks = _base_operation.BaseOperation._checkUnsignedIntValue('allTasks', opts.allTasks);
      attrs.ext = new _xdr_generated.default.CreateChangeRoleRequestOpExt(_xdr_generated.default.LedgerVersion.emptyVersion());
      var kycRequestOp = new _xdr_generated.default.CreateChangeRoleRequestOp(attrs);
      var opAttributes = {};
      opAttributes.body = _xdr_generated.default.OperationBody.createChangeRoleRequest(kycRequestOp);

      _base_operation.BaseOperation.setSourceAccount(opAttributes, opts);

      return new _xdr_generated.default.Operation(opAttributes);
    }
  }, {
github tokend / new-js-sdk / lib / base / index.js View on Github external
get: function get() {
    return _jsXdr.UnsignedHyper;
  }
});

js-xdr

Read/write XDR encoded data structures (RFC 4506)

Apache-2.0
Latest version published 4 months ago

Package Health Score

56 / 100
Full package analysis

Similar packages