// 

import bcoin from 'bcoin'

import { patchPbkdf2, patchSecp256k1 } from './patchCrypto.js'
import { patchTransaction } from './replayProtection.js'































let cryptoReplaced = false
patchTransaction(bcoin)

export const addNetwork = (bcoinInfo) => {
  const type = bcoinInfo.type

  if (bcoin.networks.types.indexOf(type) === -1) {
    bcoin.networks.types.push(type)
    bcoin.networks[type] = { ...bcoin.networks.main, ...bcoinInfo }
  }
}

export const patchCrypto = (secp256k1 = null, pbkdf2 = null) => {
  if (!cryptoReplaced) {
    if (secp256k1) {
      patchSecp256k1(bcoin, secp256k1)
      cryptoReplaced = true
    }
    if (pbkdf2) {
      patchPbkdf2(bcoin, pbkdf2)
      cryptoReplaced = true
    }
  }
}
