Dive into secure and efficient coding practices with our curated list of the top 10 examples showcasing 'stellar-base' in functional components in JavaScript. Our advanced machine learning engine meticulously scans each line of code, cross-referencing millions of open source libraries to ensure your implementation is not just functional, but also robust and secure. Elevate your React applications to new heights by mastering the art of handling side effects, API calls, and asynchronous operations with confidence and precision.
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);
);
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 {
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];
}
}
_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;
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;
});
}
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,
},
.attr("id", () => stellar.Keypair.random().publicKey())
.attr("balance", "19729999500")
.attr("signer", () => stellar.Keypair.random().publicKey())
.attr("weight", () => Math.floor(Math.random() * 5));
.attr("accountID", () => stellar.Keypair.random().publicKey())
.attr("signer", () => stellar.Keypair.random().publicKey())
.attr("id", () => stellar.Keypair.random().publicKey())
.attr("balance", "19729999500")