How to use the @arkecosystem/crypto.crypto.getAddress 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__ / utils / fixtures / testnet / delegates.ts View on Github external
export const delegates: any = secrets.map(secret => {
    const publicKey = crypto.getKeys(secret).publicKey;
    const address = crypto.getAddress(publicKey);
    const balance = genesisTransactions.find(
        transaction => transaction.recipientId === address && transaction.type === 0,
    ).amount;
    return {
        secret,
        passphrase: secret, // just an alias for delegate secret
        publicKey,
        address,
        balance,
    };
});
github ArkEcosystem / core / packages / core-database / lib / wallet-manager.js View on Github external
async revertBlock (block) {
    let delegate = this.getWalletByPublicKey(block.data.generatorPublicKey)

    if (!delegate) {
      const generator = crypto.getAddress(block.data.generatorPublicKey, config.network.pubKeyHash)

      delegate = new Wallet(generator)
      delegate.publicKey = block.data.generatorPublicKey

      this.reindex(delegate)
    }

    const revertedTransactions = []

    try {
      // TODO Use Promise.all or explain why not
      // - Promise.each is applied sequentially
      // - Promise.all is applied in parallel
      await Promise.each(block.transactions, async (transaction) => {
        await this.revertTransaction(transaction)
github ArkEcosystem / core / packages / core-database / lib / interface.js View on Github external
async verifyTransaction(transaction) {
    const senderId = crypto.getAddress(
      transaction.data.senderPublicKey,
      config.network.pubKeyHash,
    )

    const sender = this.walletManager.findByAddress(senderId) // should exist

    if (!sender.publicKey) {
      sender.publicKey = transaction.data.senderPublicKey
      this.walletManager.reindex(sender)
    }

    const dbTransaction = await this.getTransaction(transaction.data.id)

    return sender.canApply(transaction.data, []) && !dbTransaction
  }
github ArkEcosystem / core / packages / core-tester-cli / src / commands / transfer.ts View on Github external
public async run(): Promise {
        await this.initialize(TransferCommand);

        const primaryAddress = crypto.getAddress(
            crypto.getKeys(this.config.passphrase).publicKey,
            this.config.network.version,
        );

        let wallets = this.options.wallets;
        if (wallets === undefined) {
            wallets = this.generateWallets();
        }

        logger.info(`Sending ${wallets.length} transfer ${pluralize("transaction", wallets.length)}`);

        const walletBalance = await this.getWalletBalance(primaryAddress);

        if (!this.options.skipValidation) {
            logger.info(`Sender starting balance: ${satoshiToArk(walletBalance)}`);
        }
github ArkEcosystem / core / packages / core-tester-cli / lib / utils / generate-wallets.js View on Github external
module.exports = (quantity = 1, config) => {
  let wallets = []

  for (let i = 0; i < quantity; i++) {
    const passphrase = bip39.generateMnemonic()
    const keys = crypto.getKeys(passphrase)
    const address = crypto.getAddress(keys.publicKey, config.publicKeyHash)

    wallets.push({ address, keys, passphrase })
  }

  const testWalletsPath = path.resolve(__dirname, '../../test-wallets')
  for (const wallet of wallets) {
    fs.appendFileSync(testWalletsPath, `${wallet.address}: ${wallet.passphrase}\n`)
  }
  fs.appendFileSync(testWalletsPath, `${'-'.repeat(80)}\n`)

  return wallets
}
github ArkEcosystem / core / packages / core-p2p / lib / server / versions / peer / handlers / transactions.js View on Github external
const transactions = rows.map(row => {
      const transaction = Transaction.deserialize(
        row.serialized.toString('hex'),
      )
      transaction.blockId = row.block_id
      transaction.senderId = crypto.getAddress(transaction.senderPublicKey)
      return transaction
    })
github ArkEcosystem / core / packages / core-api / lib / versions / 1 / transformers / transaction.js View on Github external
module.exports = model => {
  const data = new Transaction(model.serialized.toString('hex'))

  return {
    id: data.id,
    blockid: model.blockId,
    type: data.type,
    timestamp: model.timestamp || data.timestamp,
    amount: +bignumify(data.amount).toFixed(),
    fee: +bignumify(data.fee).toFixed(),
    recipientId: data.recipientId,
    senderId: crypto.getAddress(
      data.senderPublicKey,
      config.network.pubKeyHash,
    ),
    senderPublicKey: data.senderPublicKey,
    vendorField: data.vendorField,
    signature: data.signature,
    signSignature: data.signSignature,
    signatures: data.signatures,
    asset: data.asset || {},
    confirmations: model.block
      ? blockchain.getLastBlock().data.height - model.block.height
      : 0,
  }
}
github ArkEcosystem / desktop-wallet / src / renderer / services / wallet.js View on Github external
static generate (pubKeyHash, language) {
    const passphrase = bip39.generateMnemonic(null, null, bip39.wordlists[language])
    const publicKey = crypto.getKeys(this.normalizePassphrase(passphrase)).publicKey
    return {
      address: crypto.getAddress(publicKey, pubKeyHash),
      passphrase
    }
  }
github ArkEcosystem / desktop-wallet / src / renderer / services / wallet.js View on Github external
static getAddress (passphrase, pubKeyHash) {
    const publicKey = crypto.getKeys(this.normalizePassphrase(passphrase)).publicKey
    return crypto.getAddress(publicKey, pubKeyHash)
  }
github ArkEcosystem / core / packages / core-json-rpc / lib / server / methods / wallets / bip38 / create.js View on Github external
async method(params) {
    try {
      const { keys, wif } = await getBIP38Wallet(params.userId, params.bip38)

      return {
        publicKey: keys.publicKey,
        address: crypto.getAddress(keys.publicKey),
        wif,
      }
    } catch (error) {
      const { publicKey, privateKey } = crypto.getKeys(bip39.generateMnemonic())

      const encryptedWIF = bip38.encrypt(
        Buffer.from(privateKey, 'hex'),
        true,
        params.bip38 + params.userId,
      )
      await database.set(
        utils.sha256(Buffer.from(params.userId)).toString('hex'),
        encryptedWIF,
      )

      const { wif } = decryptWIF(encryptedWIF, params.userId, params.bip38)