Skip to content

Commit

Permalink
Merge branch 'np/smart-contract-wallet-support' of https://github.com…
Browse files Browse the repository at this point in the history
…/xmtp/xmtp-android into np/smart-contract-wallet-support
  • Loading branch information
nplasterer committed Oct 3, 2024
2 parents 96ef790 + 13abd5e commit 6f55da2
Showing 1 changed file with 23 additions and 15 deletions.
38 changes: 23 additions & 15 deletions library/src/main/java/org/xmtp/android/library/SigningKey.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,16 @@ import java.util.Date

interface SigningKey {
val address: String
/// If this signing key is a smart contract wallet

// If this signing key is a smart contract wallet
val isSmartContractWallet: Boolean
get() = false

// Default chainId value set to 1
var chainId: Long
get() = 1
set(_) {}

// Default blockNumber value set to null
var blockNumber: Long?
get() = null
Expand All @@ -47,10 +50,13 @@ fun SigningKey.createIdentity(
identity: PrivateKeyOuterClass.PrivateKey,
preCreateIdentityCallback: PreEventCallback? = null,
): AuthorizedIdentity {
val slimKey = PublicKeyOuterClass.PublicKey.newBuilder().apply {
timestamp = Date().time
secp256K1Uncompressed = identity.publicKey.secp256K1Uncompressed
}.build()
val slimKey =
PublicKeyOuterClass.PublicKey
.newBuilder()
.apply {
timestamp = Date().time
secp256K1Uncompressed = identity.publicKey.secp256K1Uncompressed
}.build()

preCreateIdentityCallback?.let {
runBlocking {
Expand All @@ -64,17 +70,19 @@ fun SigningKey.createIdentity(
val signature = runBlocking { sign(signatureText) } ?: throw XMTPException("Illegal signature")

val signatureData = KeyUtil.getSignatureData(signature.rawData.toByteString().toByteArray())
val publicKey = Sign.recoverFromSignature(
BigInteger(1, signatureData.v).toInt(),
ECDSASignature(BigInteger(1, signatureData.r), BigInteger(1, signatureData.s)),
digest,
)
val publicKey =
Sign.recoverFromSignature(
BigInteger(1, signatureData.v).toInt(),
ECDSASignature(BigInteger(1, signatureData.r), BigInteger(1, signatureData.s)),
digest,
)

val authorized = PublicKey.newBuilder().also {
it.secp256K1Uncompressed = slimKey.secp256K1Uncompressed
it.timestamp = slimKey.timestamp
it.signature = signature
}
val authorized =
PublicKey.newBuilder().also {
it.secp256K1Uncompressed = slimKey.secp256K1Uncompressed
it.timestamp = slimKey.timestamp
it.signature = signature
}
return AuthorizedIdentity(
address = Keys.toChecksumAddress(Keys.getAddress(publicKey)),
authorized = authorized.build(),
Expand Down

0 comments on commit 6f55da2

Please sign in to comment.