Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
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))
}
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());
});
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());
});
});
};
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);
}
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,
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
// 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 ============================================================
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))
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)
}
})
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)
}