Skip to content

Commit

Permalink
fix up the wallet address
Browse files Browse the repository at this point in the history
  • Loading branch information
nplasterer committed Nov 3, 2024
1 parent 89f0e6b commit cd8b714
Showing 1 changed file with 13 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ import com.google.protobuf.kotlin.toByteString
import kotlinx.coroutines.runBlocking
import org.web3j.crypto.ECKeyPair
import org.web3j.crypto.Hash
import org.web3j.crypto.Keys
import org.web3j.crypto.Sign
import org.xmtp.android.library.KeyUtil
import org.xmtp.android.library.SigningKey
import org.xmtp.android.library.toHex
import org.xmtp.proto.message.contents.PublicKeyOuterClass
import org.xmtp.proto.message.contents.SignatureOuterClass
import java.security.SecureRandom
import java.util.Arrays
import java.util.Date

typealias PrivateKey = org.xmtp.proto.message.contents.PrivateKeyOuterClass.PrivateKey
Expand Down Expand Up @@ -96,7 +99,16 @@ fun PrivateKey.generate(): PrivateKey {
}

val PrivateKey.walletAddress: String
get() = publicKey.walletAddress
get() {
val address = Keys.getAddress(
Arrays.copyOfRange(
publicKey.secp256K1Uncompressed.bytes.toByteArray(),
1,
publicKey.secp256K1Uncompressed.bytes.toByteArray().size
)
)
return Keys.toChecksumAddress(address.toHex())
}

fun PrivateKey.sign(key: PublicKeyOuterClass.UnsignedPublicKey): PublicKeyOuterClass.SignedPublicKey {
val bytes = key.toByteArray()
Expand Down

0 comments on commit cd8b714

Please sign in to comment.