Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
for (let i = 0; i < quantity; i++) {
if (this.builder.constructor.name === "TransferBuilder") {
// @FIXME: when we use any of the "withPassphrase*" methods the builder will
// always remember the previous vendor field instead generating a new one on each iteration
const vendorField: string = this.builder.data.vendorField;
if (!vendorField || (vendorField && vendorField.startsWith("Test Transaction"))) {
this.builder.vendorField(`Test Transaction ${i + 1}`);
}
}
if (this.builder.constructor.name === "DelegateRegistrationBuilder") {
// @FIXME: when we use any of the "withPassphrase*" methods the builder will
// always remember the previous username instead generating a new one on each iteration
if (!this.builder.data.asset.delegate.username) {
this.builder = Transactions.BuilderFactory.delegateRegistration().usernameAsset(
this.getRandomUsername(),
);
}
}
if (this.version) {
this.builder.version(this.version);
}
if (this.fee) {
this.builder.fee(this.fee.toFixed());
}
if (this.timestamp) {
this.builder.data.timestamp = this.timestamp;
}
it('should return true when below min required signatures', () => {
const multiSignatureAsset = {
min: 5,
publicKeys: []
}
for (let i = 1; i <= 10; i++) {
multiSignatureAsset.publicKeys.push(Identities.PublicKey.fromPassphrase(`passphrase ${i}`))
}
const transactionObject = Transactions.BuilderFactory
.transfer()
.amount(1)
.fee(1)
.recipientId(recipientAddress)
transactionObject.data.senderPublicKey = senderPublicKey
transactionObject.data.signatures = []
const transaction = transactionObject.getStruct()
transaction.multiSignature = multiSignatureAsset
expect(TransactionService.needsSignatures(transaction)).toBe(true)
})
public static multiSignature(participants?: string[], min?: number): TransactionFactory {
let passphrases: string[];
if (!participants) {
passphrases = [secrets[0], secrets[1], secrets[2]];
}
participants = participants || [
Identities.PublicKey.fromPassphrase(secrets[0]),
Identities.PublicKey.fromPassphrase(secrets[1]),
Identities.PublicKey.fromPassphrase(secrets[2]),
];
const factory: TransactionFactory = new TransactionFactory(
Transactions.BuilderFactory.multiSignature().multiSignatureAsset({
publicKeys: participants,
min: min || participants.length,
}),
);
if (passphrases) {
factory.withPassphraseList(passphrases);
}
factory.builder.senderPublicKey(participants[0]);
return factory;
}
beforeEach(() => {
Managers.configManager.getMilestone().aip11 = true
transaction = Transactions.BuilderFactory
.multiSignature()
.multiSignatureAsset({
min: 1,
publicKeys: [
Identities.PublicKey.fromPassphrase(passphrase)
]
})
.sign('passphrase')
.fee(1)
})
public makeDelegate(opts: Record): any {
const transaction = Transactions.BuilderFactory.delegateRegistration()
.fee(this.toSatoshi(opts.delegateFee))
.network(this.network)
.usernameAsset(opts.username)
.sign(opts.passphrase);
if (opts.secondPassphrase) {
transaction.secondSign(opts.secondPassphrase);
}
return transaction.getStruct();
}
private createTransferTransaction(senderWallet, receiverWallet, amount) {
const { data: transaction } = Transactions.BuilderFactory.transfer()
.recipientId(receiverWallet.address)
.amount(amount)
.sign(senderWallet.passphrase);
return this.formatGenesisTransaction(transaction, senderWallet);
}
async method(params: {
userId: string;
bip38: string;
recipientId: string;
amount: string;
vendorField?: string;
}) {
try {
const wallet: IWallet = await getBIP38Wallet(params.userId, params.bip38);
if (!wallet) {
return Boom.notFound(`User ${params.userId} could not be found.`);
}
const transactionBuilder = Transactions.BuilderFactory.transfer()
.recipientId(params.recipientId)
.amount(params.amount);
if (params.vendorField) {
transactionBuilder.vendorField(params.vendorField);
}
const transaction: Interfaces.ITransactionData = transactionBuilder.signWithWif(wallet.wif).getStruct();
if (!Transactions.Verifier.verifyHash(transaction)) {
return Boom.badData();
}
await database.set(transaction.id, transaction);
return transaction;
async method(params) {
const transaction = Transactions.BuilderFactory.transfer()
.recipientId(params.recipientId)
.amount(params.amount)
.sign(params.passphrase)
.getStruct();
await database.set(transaction.id, transaction);
return transaction;
},
schema: {
async buildTransfer ({ amount, fee, recipientId, vendorField, passphrase, secondPassphrase, wif, networkWif, networkId }, isAdvancedFee = false, returnObject = false) {
const staticFee = store.getters['transaction/staticFee'](TRANSACTION_TYPES.TRANSFER)
if (!isAdvancedFee && fee.gt(staticFee)) {
throw new Error(`Transfer fee should be smaller than ${staticFee}`)
}
const transaction = Transactions.BuilderFactory
.transfer()
.amount(amount)
.fee(fee)
.recipientId(recipientId)
transaction.data.vendorField = vendorField
passphrase = this.normalizePassphrase(passphrase)
secondPassphrase = this.normalizePassphrase(secondPassphrase)
return this.__signTransaction({
transaction,
passphrase,
secondPassphrase,
wif,
networkWif,