2019-10-21 03:17:07 -07:00
|
|
|
package cash.z.wallet.sdk.demoapp.demos.getprivatekey
|
|
|
|
|
|
|
|
import android.view.LayoutInflater
|
2019-11-01 13:25:28 -07:00
|
|
|
import cash.z.wallet.sdk.Initializer
|
2019-10-21 03:17:07 -07:00
|
|
|
import cash.z.wallet.sdk.demoapp.App
|
|
|
|
import cash.z.wallet.sdk.demoapp.BaseDemoFragment
|
|
|
|
import cash.z.wallet.sdk.demoapp.databinding.FragmentGetPrivateKeyBinding
|
|
|
|
|
|
|
|
class GetPrivateKeyFragment : BaseDemoFragment<FragmentGetPrivateKeyBinding>() {
|
|
|
|
private var seed: ByteArray = App.instance.defaultConfig.seed
|
2019-11-01 13:25:28 -07:00
|
|
|
private val initializer: Initializer = Initializer(App.instance)
|
2020-02-24 11:51:45 -08:00
|
|
|
private val birthday = App.instance.defaultConfig.newWalletBirthday()
|
2019-11-01 13:25:28 -07:00
|
|
|
private lateinit var spendingKeys: Array<String>
|
|
|
|
private lateinit var viewingKeys: Array<String>
|
2019-10-21 03:17:07 -07:00
|
|
|
|
|
|
|
override fun inflateBinding(layoutInflater: LayoutInflater): FragmentGetPrivateKeyBinding =
|
|
|
|
FragmentGetPrivateKeyBinding.inflate(layoutInflater)
|
|
|
|
|
|
|
|
override fun resetInBackground() {
|
|
|
|
/*
|
|
|
|
* Initialize with the seed and retrieve one private key for each account specified (by
|
|
|
|
* default, only 1 account is created). In a normal circumstance, a wallet app would then
|
|
|
|
* store these keys in its secure storage for retrieval, later. Private keys are only needed
|
|
|
|
* for sending funds.
|
|
|
|
*/
|
2020-02-24 11:51:45 -08:00
|
|
|
spendingKeys = initializer.new(seed, birthday)
|
2019-11-01 13:25:28 -07:00
|
|
|
|
|
|
|
/*
|
2020-02-25 23:43:27 -08:00
|
|
|
* Alternatively, viewing keys can also be derived directly from a seed or spending keys.
|
2019-11-01 13:25:28 -07:00
|
|
|
*/
|
|
|
|
viewingKeys = initializer.deriveViewingKeys(seed)
|
|
|
|
|
|
|
|
// just for demonstration purposes to show that these approaches produce the same result.
|
|
|
|
require(spendingKeys.first() == initializer.deriveSpendingKeys(seed).first())
|
|
|
|
require(viewingKeys.first() == initializer.deriveViewingKey(spendingKeys.first()))
|
2019-10-21 03:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onResetComplete() {
|
2019-11-01 13:25:28 -07:00
|
|
|
binding.textInfo.text = "Spending Key:\n${spendingKeys[0]}\n\nViewing Key:\n${viewingKeys[0]}"
|
2019-10-21 03:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
override fun onClear() {
|
2019-11-01 13:25:28 -07:00
|
|
|
initializer.clear()
|
2019-10-21 03:17:07 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|