Skip to content

Commit

Permalink
expose addressToAccountSigningData
Browse files Browse the repository at this point in the history
  • Loading branch information
luca992 committed Oct 31, 2022
1 parent aa41b19 commit d6a7781
Showing 1 changed file with 7 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ sealed class BaseWallet(
val bech32Prefix: String = "secret"
) : Wallet {

private val addressToAccounts: MutableMap<String, AccountSigningData> = mutableMapOf()
val accountAddresses get() = addressToAccounts.keys
val addressToAccountSigningData: MutableMap<String, AccountSigningData> = mutableMapOf()
val accountAddresses get() = addressToAccountSigningData.keys

init {
addAccount(mnemonic)
Expand All @@ -71,8 +71,8 @@ sealed class BaseWallet(
val uncompressed = Secp256k1.makeKeypair(privkey).pubkey
val pubkey = Secp256k1.compressPubkey(uncompressed)
val address = pubkeyToAddress(encodeSecp256k1Pubkey(pubkey), bech32Prefix)
addressToAccounts[address] = AccountSigningData(address, Algo.secp256k1, pubkey, privkey)
return addressToAccounts[address]!!
addressToAccountSigningData[address] = AccountSigningData(address, Algo.secp256k1, pubkey, privkey)
return addressToAccountSigningData[address]!!
}

/**
Expand All @@ -81,10 +81,10 @@ sealed class BaseWallet(
* @return Returns [AccountData] if account is successfully removed from wallet.
*/
fun removeAccount(address: String): AccountData? {
return addressToAccounts.remove(address)?.publicData
return addressToAccountSigningData.remove(address)?.publicData
}

val accounts get() = addressToAccounts.values.map { it.publicData }.toList()
val accounts get() = addressToAccountSigningData.values.map { it.publicData }.toList()

/**
* Get AccountData array from wallet. Rejects if not enabled.
Expand All @@ -109,7 +109,7 @@ sealed class BaseWallet(
signBytes: UByteArray,
prehashType: PrehashType = PrehashType.SHA256
): StdSignature {
val account = addressToAccounts[signerAddress] ?: throw Error("Address $signerAddress not found in wallet")
val account = addressToAccountSigningData[signerAddress] ?: throw Error("Address $signerAddress not found in wallet")
val messageHash = prehash(signBytes, prehashType)
val signature = Secp256k1.createSignature(messageHash, account.privkey)
val fixedLengthSignature = signature.r.getPadded(32) + signature.s.getPadded(32)
Expand Down

0 comments on commit d6a7781

Please sign in to comment.