-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a new signing method because it doesn't exist as far as I can tel…
…l, and get message skip working
- Loading branch information
1 parent
00089af
commit 2c9b77b
Showing
2 changed files
with
45 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
server/src/main/kotlin/io/provenance/invoice/util/provenance/KeySigner.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.provenance.invoice.util.provenance | ||
|
||
import com.google.protobuf.ByteString | ||
import cosmos.crypto.secp256k1.Keys | ||
import io.provenance.client.grpc.Signer | ||
import io.provenance.hdwallet.ec.toECKeyPair | ||
import io.provenance.hdwallet.ec.toECPrivateKey | ||
import io.provenance.hdwallet.signer.BCECSigner | ||
import io.provenance.scope.util.sha256 | ||
import java.security.PrivateKey | ||
|
||
|
||
class KeySigner( | ||
private val address: String, | ||
privateKey: PrivateKey | ||
): Signer { | ||
private val keyPair = privateKey.toECPrivateKey().toECKeyPair() | ||
|
||
override fun address(): String = address | ||
|
||
override fun pubKey(): Keys.PubKey = | ||
Keys.PubKey.newBuilder().setKey(ByteString.copyFrom(keyPair.publicKey.compressed())).build() | ||
|
||
override fun sign(data: ByteArray): ByteArray = BCECSigner() | ||
.sign(keyPair.privateKey, data.sha256()) | ||
.encodeAsBTC() | ||
} |