Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
const fs = require("fs");
const { createPrepareTransfers, generateAddress } = require('@iota/core');
const { asTransactionObject } = require("@iota/transaction-converter");
const NUM_BUNDLES = 100;
const MAX_BUNDLE_SIZE = 10;
// prepare transfers offline
const prepareTransfers = createPrepareTransfers(undefined, Date.now());
function randomInt(min, max, excluding) {
let value;
do {
value = Math.floor(Math.random() * (max - min + 1)) + min;
} while (excluding.includes(value));
return value;
}
function randomTrytes(length) {
const possible = "NOPQRSTUVWXYZ9ABCDEFGHIJKLM";
let text = "";
for (let i = 0; i < length; i++) {
text += possible.charAt(Math.floor(Math.random() * possible.length));
export function addressGeneration(this: any, addressGenerationParams: AddressGenerationParams) {
const { seed, persistence, timeSource, network, now } = addressGenerationParams
const prepareTransfers = createPrepareTransfers(undefined, now)
const emitter = this // tslint:disable-line
function generateCDA(cdaParams: CDAParams): Promise {
if (!cdaParams) {
throw new Error(
'Provide an object with conditions for the CDA: { timeoutAt, [multiUse], [exeptectedAmount], [security=2] }'
)
}
const { timeoutAt, expectedAmount, multiUse } = cdaParams
return Promise.try(() => timeSource().then(currentTime => verifyCDAParams(currentTime, cdaParams)))
.then(persistence.increment)
.then(index => {
const security = cdaParams.security || addressGenerationParams.security
const address = signingAddress(digests(key(subseed(seed, tritsToValue(index)), security)))
const transferFunds = async (wallet, totalAmount, transfers) => {
try {
const { address, keyIndex, seed } = wallet;
const { sendTrytes, getLatestInclusion } = composeAPI({ provider });
const prepareTransfers = createPrepareTransfers();
const balance = await getBalance(address);
if (balance === 0) {
console.error('transferFunds. Insufficient balance', address);
return null;
}
if (balance < totalAmount) {
throw new Error(`Insufficient balance: ${balance}. Needed: ${totalAmount}`);
}
return new Promise((resolve, reject) => {
const remainderAddress = generateAddress(seed, keyIndex + 1);
const options = {
inputs: [{
address,
keyIndex,
export function transactionIssuance(
this: any,
{ seed, deposits, persistence, network, timeSource, now }: TransactionIssuanceParams
) {
const { getBalance, wereAddressesSpentFrom } = network
const prepareTransfers = createPrepareTransfers(undefined, now)
const noChecksum = (address: string) => address.slice(0, -(CDA_CHECKSUM_LENGTH / TRYTE_WIDTH))
const transactionIssuer = {
sendToCDA: (cdaTransfer: CDATransfer): Promise> => {
if (!cdaTransfer) {
throw new Error(
'Provide an object with conditions and value for the CDA transfer: { timeoutAt, [multiUse], [exeptectedAmount], [security=2], value }'
)
}
return (cdaTransfer.multiUse === true
? Promise.resolve()
: persistence
.get([SENT_TO_ADDRESS_PREFIX, noChecksum(cdaTransfer.address)].join(':'))
.then(() => {
throw new Error(