mirror of
https://github.com/vitorpamplona/amethyst.git
synced 2026-08-12 01:07:46 +00:00
Better checks the id and sig before verifying the event.
This commit is contained in:
@@ -27,12 +27,12 @@ import com.vitorpamplona.quartz.utils.Log
|
||||
fun Event.generateId(): String = EventHasher.hashId(pubKey, createdAt, kind, tags, content)
|
||||
|
||||
fun Event.verifyId(): Boolean {
|
||||
if (id.isEmpty()) return false
|
||||
if (id.length != 64) return false
|
||||
return EventHasher.hashIdCheck(id, pubKey, createdAt, kind, tags, content)
|
||||
}
|
||||
|
||||
fun Event.verifySignature(): Boolean {
|
||||
if (id.isEmpty() || sig.isEmpty()) return false
|
||||
if (id.length != 64 || pubKey.length != 64 || sig.length != 128) return false
|
||||
return Nip01Crypto.verify(Hex.decode(sig), Hex.decode(id), Hex.decode(pubKey))
|
||||
}
|
||||
|
||||
|
||||
@@ -146,7 +146,9 @@ object Hex {
|
||||
|
||||
fun decode(hex: String): ByteArray {
|
||||
// faster version of hex decoder
|
||||
require(hex.length and 1 == 0)
|
||||
require(hex.length and 1 == 0) {
|
||||
"Invalid hex $hex"
|
||||
}
|
||||
return ByteArray(hex.length / 2) {
|
||||
(hexToByte[hex[2 * it].code] shl 4 or hexToByte[hex[2 * it + 1].code]).toByte()
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user