How to use the @arkecosystem/crypto.Transactions.BuilderFactory function in @arkecosystem/crypto

To help you get started, we’ve selected a few @arkecosystem/crypto 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 ArkEcosystem / core / __tests__ / helpers / transaction-factory.ts View on Github external
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;
            }
github ArkEcosystem / desktop-wallet / __tests__ / unit / services / transaction.spec.js View on Github external
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)
    })
github ArkEcosystem / core / __tests__ / helpers / transaction-factory.ts View on Github external
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;
    }
github ArkEcosystem / desktop-wallet / __tests__ / unit / services / transaction.spec.js View on Github external
beforeEach(() => {
      Managers.configManager.getMilestone().aip11 = true
      transaction = Transactions.BuilderFactory
        .multiSignature()
        .multiSignatureAsset({
          min: 1,
          publicKeys: [
            Identities.PublicKey.fromPassphrase(passphrase)
          ]
        })
        .sign('passphrase')
        .fee(1)
    })
github ArkEcosystem / core / packages / core-tester-cli / src / signer.ts View on Github external
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();
    }
github ArkEcosystem / core / packages / core / src / commands / network / generate.ts View on Github external
private createTransferTransaction(senderWallet, receiverWallet, amount) {
        const { data: transaction } = Transactions.BuilderFactory.transfer()
            .recipientId(receiverWallet.address)
            .amount(amount)
            .sign(senderWallet.passphrase);

        return this.formatGenesisTransaction(transaction, senderWallet);
    }
github ArkEcosystem / core / deprecated / core-json-rpc / src / server / modules.ts View on Github external
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;
github ArkEcosystem / core / packages / core-json-rpc / src / server / methods / transactions / create.ts View on Github external
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: {
github ArkEcosystem / desktop-wallet / src / renderer / services / client.js View on Github external
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,