Skip to content

Commit f99cb5e

Browse files
HSM integration
1 parent 4d9ab69 commit f99cb5e

File tree

49 files changed

+531
-240
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+531
-240
lines changed

btc-address-generation/src/main/kotlin/com/d3/btc/generation/config/BtcAddressGenerationAppConfiguration.kt

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ package com.d3.btc.generation.config
77

88
import com.d3.btc.generation.BTC_ADDRESS_GENERATION_SERVICE_NAME
99
import com.d3.btc.provider.BtcChangeAddressProvider
10-
import com.d3.btc.provider.network.BtcNetworkConfigProvider
11-
import com.d3.btc.wallet.createWalletIfAbsent
1210
import com.d3.commons.config.loadLocalConfigs
1311
import com.d3.commons.expansion.ServiceExpansion
1412
import com.d3.commons.model.IrohaCredential
@@ -22,10 +20,8 @@ import com.d3.commons.util.createPrettySingleThreadPool
2220
import io.grpc.ManagedChannelBuilder
2321
import jp.co.soramitsu.iroha.java.IrohaAPI
2422
import jp.co.soramitsu.iroha.java.Utils
25-
import org.bitcoinj.wallet.Wallet
2623
import org.springframework.context.annotation.Bean
2724
import org.springframework.context.annotation.Configuration
28-
import java.io.File
2925

3026
val btcAddressGenerationConfig =
3127
loadLocalConfigs(
@@ -101,13 +97,6 @@ class BtcAddressGenerationAppConfiguration {
10197
@Bean
10298
fun btcAddressGenerationConfig() = btcAddressGenerationConfig
10399

104-
@Bean
105-
fun keysWallet(networkProvider: BtcNetworkConfigProvider): Wallet {
106-
val walletPath = btcAddressGenerationConfig.btcKeysWalletPath
107-
createWalletIfAbsent(walletPath, networkProvider)
108-
return Wallet.loadFromFile(File(walletPath))!!
109-
}
110-
111100
@Bean
112101
fun notaryPeerListProvider(): NotaryPeerListProvider {
113102
return NotaryPeerListProviderImpl(

btc-address-generation/src/main/kotlin/com/d3/btc/generation/config/BtcAddressGenerationConfig.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@ interface BtcAddressGenerationConfig {
2020
//Iroha config
2121
val iroha: IrohaConfig
2222

23-
//Path to BTC wallet file
24-
val btcKeysWalletPath: String
25-
2623
//TODO the only purpose of this account is creating PeerListProvider. This account must be removed from config.
2724
//Account that is used to register BTC addresses
2825
val registrationAccount: IrohaCredentialRawConfig

btc-address-generation/src/main/kotlin/com/d3/btc/generation/init/BtcAddressGenerationInitialization.kt

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ import com.d3.btc.provider.generation.ADDRESS_GENERATION_NODE_ID_KEY
1717
import com.d3.btc.provider.generation.ADDRESS_GENERATION_TIME_KEY
1818
import com.d3.btc.provider.generation.BtcPublicKeyProvider
1919
import com.d3.btc.provider.network.BtcNetworkConfigProvider
20-
import com.d3.btc.wallet.checkWalletNetwork
21-
import com.d3.btc.wallet.safeSave
2220
import com.d3.commons.sidechain.iroha.CLIENT_DOMAIN
2321
import com.d3.commons.sidechain.iroha.IrohaChainListener
2422
import com.d3.commons.sidechain.iroha.util.IrohaQueryHelper
@@ -34,7 +32,6 @@ import io.reactivex.schedulers.Schedulers
3432
import iroha.protocol.BlockOuterClass
3533
import iroha.protocol.Commands
3634
import mu.KLogging
37-
import org.bitcoinj.wallet.Wallet
3835
import org.springframework.beans.factory.annotation.Qualifier
3936
import org.springframework.stereotype.Component
4037

@@ -43,7 +40,6 @@ import org.springframework.stereotype.Component
4340
*/
4441
@Component
4542
class BtcAddressGenerationInitialization(
46-
private val keysWallet: Wallet,
4743
@Qualifier("registrationQueryHelper")
4844
private val registrationQueryHelper: IrohaQueryHelper,
4945
private val btcAddressGenerationConfig: BtcAddressGenerationConfig,
@@ -59,10 +55,7 @@ class BtcAddressGenerationInitialization(
5955
* @param onIrohaFail - function that will be called on Iroha failure
6056
*/
6157
fun init(onIrohaFail: () -> Unit): Result<Unit, Exception> {
62-
//Check wallet network
63-
return keysWallet.checkWalletNetwork(btcNetworkConfigProvider.getConfig()).flatMap {
64-
irohaChainListener.getBlockObservable()
65-
}.map { irohaObservable ->
58+
return irohaChainListener.getBlockObservable().map { irohaObservable ->
6659
initIrohaObservable(irohaObservable, onIrohaFail)
6760
}.flatMap {
6861
// Start free address generation at initial phase
@@ -174,7 +167,7 @@ class BtcAddressGenerationInitialization(
174167

175168
// Generates new key
176169
private fun onGenerateKey(sessionAccountName: String): Result<String, Exception> {
177-
return btcPublicKeyProvider.createKey(sessionAccountName) { saveWallet() }
170+
return btcPublicKeyProvider.createKey(sessionAccountName)
178171
}
179172

180173
/**
@@ -203,18 +196,13 @@ class BtcAddressGenerationInitialization(
203196
addressType,
204197
time,
205198
nodeId
206-
) { saveWallet() }
199+
)
207200
} else {
208201
Result.of { Unit }
209202
}
210203
}
211204
}
212205

213-
// Safes wallet full of keys
214-
private fun saveWallet() {
215-
keysWallet.safeSave(btcAddressGenerationConfig.btcKeysWalletPath)
216-
}
217-
218206
/**
219207
* Logger
220208
*/

btc-address-generation/src/main/kotlin/com/d3/btc/generation/main.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
package com.d3.btc.generation
99

1010
import com.d3.btc.generation.init.BtcAddressGenerationInitialization
11+
import com.d3.btc.keypair.getKeyProviderProfile
1112
import com.d3.commons.config.getProfile
1213
import com.github.kittinunf.result.Result
1314
import com.github.kittinunf.result.failure
@@ -24,7 +25,9 @@ const val BTC_ADDRESS_GENERATION_SERVICE_NAME = "btc-add-gen"
2425
"com.d3.btc.healthcheck",
2526
"com.d3.btc.provider.generation",
2627
"com.d3.btc.provider.network",
27-
"com.d3.btc.generation.trigger"]
28+
"com.d3.btc.generation.trigger",
29+
"com.d3.btc.keypair"
30+
]
2831
)
2932
class BtcAddressGenerationApplication
3033

@@ -33,7 +36,7 @@ private val logger = KLogging().logger
3336
fun main(args: Array<String>) {
3437
Result.of {
3538
val context = AnnotationConfigApplicationContext()
36-
context.environment.setActiveProfiles(getProfile())
39+
context.environment.setActiveProfiles(getProfile(), getKeyProviderProfile())
3740
context.register(BtcAddressGenerationApplication::class.java)
3841
context.refresh()
3942
context

btc-address-generation/src/main/resources/address_generation_local.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,3 @@ btc-address-generation.mstRegistrationAccount.privkey=e457ce0afc8059e7a2e4d14339
2323
btc-address-generation.iroha.hostname=d3-iroha
2424
# Iroha peer port
2525
btc-address-generation.iroha.port=50051
26-
# --------- Bitcoin ---------
27-
btc-address-generation.btcKeysWalletPath=deploy/bitcoin/regtest/keys.d3.wallet

btc-address-generation/src/main/resources/address_generation_mainnet.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,3 @@ btc-address-generation.mstRegistrationAccount.privkey=e457ce0afc8059e7a2e4d14339
2222
btc-address-generation.iroha.hostname=d3-iroha
2323
# Iroha peer port
2424
btc-address-generation.iroha.port=50051
25-
# --------- Bitcoin ---------
26-
btc-address-generation.btcKeysWalletPath=deploy/bitcoin/mainnet/keys.d3.wallet

btc-address-generation/src/main/resources/address_generation_testnet.properties

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,5 +23,3 @@ btc-address-generation.mstRegistrationAccount.privkey=e457ce0afc8059e7a2e4d14339
2323
btc-address-generation.iroha.hostname=d3-iroha
2424
# Iroha peer port
2525
btc-address-generation.iroha.port=50051
26-
# --------- Bitcoin ---------
27-
btc-address-generation.btcKeysWalletPath=deploy/bitcoin/testnet/keys.d3.wallet

btc-dw-bridge/src/main/kotlin/com/d3/btc/dwbridge/main.kt

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ package com.d3.btc.dwbridge
99

1010
import com.d3.btc.deposit.init.BtcNotaryInitialization
1111
import com.d3.btc.dwbridge.config.dwBridgeConfig
12+
import com.d3.btc.keypair.getKeyProviderProfile
1213
import com.d3.btc.withdrawal.init.BtcWithdrawalInitialization
1314
import com.d3.commons.config.getProfile
1415
import com.d3.commons.util.createFolderIfDoesntExist
@@ -43,7 +44,8 @@ const val BTC_DW_BRIDGE_SERVICE_NAME = "btc-dw-bridge"
4344
"com.d3.btc.deposit.expansion",
4445
"com.d3.btc.peer",
4546
"com.d3.btc.dwbridge",
46-
"com.d3.btc.healthcheck"]
47+
"com.d3.btc.healthcheck",
48+
"com.d3.btc.keypair"]
4749
)
4850
class BtcDWBridgeApplication
4951

@@ -58,7 +60,7 @@ fun main(args: Array<String>) {
5860
createFolderIfDoesntExist(dwBridgeConfig.bitcoin.blockStoragePath)
5961
}.map {
6062
val context = AnnotationConfigApplicationContext()
61-
context.environment.setActiveProfiles(getProfile())
63+
context.environment.setActiveProfiles(getProfile(), getKeyProviderProfile())
6264
context.register(BtcDWBridgeApplication::class.java)
6365
context.refresh()
6466
context

btc-withdrawal/src/main/kotlin/com/d3/btc/withdrawal/config/BtcWithdrawalConfig.kt

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,6 @@ interface BtcWithdrawalConfig {
3333
val irohaBlockQueue: String
3434
// Path to wallet that stores transfers(UTXO)
3535
val btcTransfersWalletPath: String
36-
// Path to wallet that stores keys
37-
val btcKeysWalletPath: String
3836
// Account that is used to store created Bitcoin transactions
3937
val txStorageAccount: String
4038
// Account that is used to store used UTXO

btc-withdrawal/src/main/kotlin/com/d3/btc/withdrawal/handler/NewTransactionCreatedHandler.kt

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
package com.d3.btc.withdrawal.handler
22

3-
import com.d3.btc.withdrawal.config.BtcWithdrawalConfig
43
import com.d3.btc.withdrawal.service.BtcRollbackService
54
import com.d3.btc.withdrawal.transaction.SignCollector
65
import com.d3.btc.withdrawal.transaction.TransactionsStorage
@@ -14,7 +13,6 @@ import org.springframework.stereotype.Component
1413
class NewTransactionCreatedHandler(
1514
private val signCollector: SignCollector,
1615
private val transactionsStorage: TransactionsStorage,
17-
private val btcWithdrawalConfig: BtcWithdrawalConfig,
1816
private val btcRollbackService: BtcRollbackService
1917
) {
2018

@@ -28,7 +26,7 @@ class NewTransactionCreatedHandler(
2826
val txHash = createNewTxCommand.key
2927
transactionsStorage.get(createNewTxCommand.key).map { (withdrawalDetails, transaction) ->
3028
logger.info { "Tx to sign\n$transaction" }
31-
signCollector.signAndSave(transaction, btcWithdrawalConfig.btcKeysWalletPath).fold({
29+
signCollector.signAndSave(transaction).fold({
3230
logger.info { "Signatures for ${transaction.hashAsString} were successfully processed" }
3331
}, { ex ->
3432
logger.error("Cannot sign transaction $transaction", ex)

0 commit comments

Comments
 (0)