How to use the @arkecosystem/crypto.constants 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 / packages / core-test-utils / lib / matchers / transactions / types / transfer.js View on Github external
'use strict'

const { TRANSFER } = require('@arkecosystem/crypto').constants

const toBeTransferType = (received) => {
  return {
    message: () => 'Expected value to be a valid TRANSFER transaction.',
    pass: received.type === TRANSFER
  }
}

expect.extend({
  toBeTransferType
})
github ArkEcosystem / core / packages / core-test-utils / lib / matchers / transactions / types / multi-payment.js View on Github external
'use strict'

const { MULTI_PAYMENT } = require('@arkecosystem/crypto').constants

const toBeMultiPaymentType = (received) => {
  return {
    message: () => 'Expected value to be a valid MULTI_PAYMENT transaction.',
    pass: received.type === MULTI_PAYMENT
  }
}

expect.extend({
  toBeMultiPaymentType
})
github ArkEcosystem / core / packages / core-test-utils / lib / matchers / transactions / types / vote.js View on Github external
'use strict'

const { VOTE } = require('@arkecosystem/crypto').constants

const toBeVoteType = (received) => {
  return {
    message: () => 'Expected value to be a valid VOTE transaction.',
    pass: received.type === VOTE
  }
}

expect.extend({
  toBeVoteType
})
github ArkEcosystem / core / packages / core-test-utils / lib / matchers / transactions / types / second-signature.js View on Github external
'use strict'

const { SECOND_SIGNATURE } = require('@arkecosystem/crypto').constants

const toBeSecondSignatureType = (received) => {
  return {
    message: () => 'Expected value to be a valid SECOND_SIGNATURE transaction.',
    pass: received.type === SECOND_SIGNATURE
  }
}

expect.extend({
  toBeSecondSignatureType
})
github ArkEcosystem / core / packages / core-test-utils / lib / matchers / transactions / types / timelock-transfer.js View on Github external
'use strict'

const { TRANSACTION_TYPES } = require('@arkecosystem/crypto').constants

const toBeTimelockTransferType = (received) => {
  return {
    message: () => 'Expected value to be a valid TIMELOCK_TRANSFER transaction.',
    pass: received.type === TRANSACTION_TYPES.TIMELOCK_TRANSFER
  }
}

expect.extend({
  toBeTimelockTransferType
})
github ArkEcosystem / core / packages / core-test-utils / lib / generators / transactions.js View on Github external
const assert = require('assert')
const { client, crypto } = require('@arkecosystem/crypto')
const { TRANSACTION_TYPES } = require('@arkecosystem/crypto').constants
const config = require('../../config')
const superheroes = require('superheroes')

module.exports = (network, type, testWallet, testAddress, amount = 2, quantity = 10) => {
  network = network || 'testnet'
  type = type || TRANSACTION_TYPES.TRANSFER
  amount = amount * Math.pow(10, 8)

  assert.ok(['mainnet', 'devnet', 'testnet'].includes(network), 'Invalid network')
  assert.ok([
    TRANSACTION_TYPES.TRANSFER,
    TRANSACTION_TYPES.SECOND_SIGNATURE,
    TRANSACTION_TYPES.DELEGATE_REGISTRATION,
    TRANSACTION_TYPES.VOTE
  ].includes(type), 'Invalid transaction type')
github ArkEcosystem / core / packages / core-database / lib / wallet-manager.js View on Github external
'use strict'

const Promise = require('bluebird')

const { crypto } = require('@arkecosystem/crypto')
const { Wallet } = require('@arkecosystem/crypto').models
const { TRANSACTION_TYPES } = require('@arkecosystem/crypto').constants

const container = require('@arkecosystem/core-container')
const config = container.resolvePlugin('config')
const logger = container.resolvePlugin('logger')
const emitter = container.resolvePlugin('event-emitter')

const map = require('lodash/map')
const genesisWallets = map(config.genesisBlock.transactions, 'senderId')

module.exports = class WalletManager {
  /**
   * Create a new wallet manager instance.
   * @constructor
   */
  constructor () {
    this.reset()
github ArkEcosystem / core / packages / core-database-sequelize / lib / spv.js View on Github external
const { Transaction } = require('@arkecosystem/crypto').models
const { TRANSACTION_TYPES } = require('@arkecosystem/crypto').constants
const container = require('@arkecosystem/core-container')
const logger = container.resolvePlugin('logger')
const config = container.resolvePlugin('config')

module.exports = class SPV {
  /**
   * Create a new wallet builder instance.
   * @param  {SequelizeConnection} database
   * @return {void}
   */
  constructor (database) {
    this.connection = database.connection
    this.models = database.models
    this.walletManager = database.walletManager
    this.query = database.query
  }
github ArkEcosystem / core / packages / core-api / lib / repositories / transactions.js View on Github external
const app = require('@arkecosystem/core-container')

const database = app.resolvePlugin('database')

const dayjs = require('dayjs-ext')
const { slots } = require('@arkecosystem/crypto')
const { TRANSACTION_TYPES } = require('@arkecosystem/crypto').constants
const buildFilterQuery = require('./utils/filter-query')
const Repository = require('./repository')

class TransactionsRepository extends Repository {
  /**
   * Get all transactions.
   * @param  {Object}  params
   * @return {Object}
   */
  async findAll(parameters = {}) {
    const selectQuery = this.query.select().from(this.query)
    const countQuery = this._makeEstimateQuery()

    if (parameters.senderId) {
      const senderPublicKey = this.__publicKeyFromSenderId(parameters.senderId)
github ArkEcosystem / mobile-wallet / src / providers / ark-api / ark-api.ts View on Github external
return observer.complete();
      }

      const epochTime = moment(this._network.epoch).utc().valueOf();
      const now = moment().valueOf();

      const keys = ArkCrypto.Keys.fromPassphrase(key);

      transaction.timestamp = Math.floor((now - epochTime) / 1000);
      transaction.senderPublicKey = keys.publicKey;
      transaction.signature = null;
      transaction.id = null;

      const data: ArkCrypto.ITransactionData = {
        network: this._network.version,
        type: ArkCrypto.constants.TransactionTypes[ArkCrypto.constants.TransactionTypes[transaction.type]],
        senderPublicKey: transaction.senderPublicKey,
        timestamp: transaction.timestamp,
        amount: transaction.amount,
        fee: transaction.fee,
        vendorField: transaction.vendorField,
        recipientId: transaction.recipientId,
        asset: transaction.asset
      };

      data.signature = ArkCrypto.crypto.sign(data, keys);

      secondPassphrase = secondKey || secondPassphrase;

      if (secondPassphrase) {
        const secondKeys = ArkCrypto.Keys.fromPassphrase(secondPassphrase);
        data.secondSignature = ArkCrypto.crypto.secondSign(data, secondKeys);