-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add module with support for EIP191 - closes #51
- Loading branch information
Showing
5 changed files
with
53 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/build |
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,9 @@ | ||
dependencies { | ||
implementation project(":model") | ||
implementation project(":crypto") | ||
implementation project(":crypto_api") | ||
implementation project(":functions") | ||
implementation project(":rlp") | ||
|
||
testImplementation "com.github.walleth:khex:$khex_version" | ||
} |
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,19 @@ | ||
package org.kethereum.eip191 | ||
|
||
import org.kethereum.crypto.model.ECKeyPair | ||
import org.kethereum.crypto.signMessage | ||
|
||
/* | ||
* | ||
* http://eips.ethereum.org/EIPS/eip-191 | ||
* | ||
*/ | ||
|
||
|
||
fun ECKeyPair.signWithEIP191(version: Byte, versionSpecificData: ByteArray, message: ByteArray) = | ||
signMessage(0x19.toByte().toByteArray() + version.toByteArray() + versionSpecificData + message) | ||
|
||
fun ECKeyPair.signWithEIP191PersonalSign(message: ByteArray) = | ||
signWithEIP191(0x45, ("thereum Signed Message:\n" + message.size).toByteArray(), message) | ||
|
||
private fun Byte.toByteArray() = ByteArray(1) { this } |
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,22 @@ | ||
package org.kethereum.eip191 | ||
|
||
import org.assertj.core.api.Assertions.assertThat | ||
import org.junit.jupiter.api.Test | ||
import org.kethereum.crypto.createEthereumKeyPair | ||
import org.kethereum.crypto.signMessage | ||
|
||
val KEY_PAIR = createEthereumKeyPair() | ||
|
||
class TheSignatures { | ||
|
||
@Test | ||
fun createsCorrectPersonalSignSignature() { | ||
|
||
val payload = "Test Payload".toByteArray() | ||
|
||
assertThat(KEY_PAIR.signWithEIP191PersonalSign(payload)) | ||
.isEqualTo(KEY_PAIR.signMessage(("\u0019Ethereum Signed Message:\n" + payload.size).toByteArray() + payload)) | ||
} | ||
|
||
|
||
} |
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