👏 Verify ingested message
This commit is contained in:
parent
17d863eb22
commit
73f653af31
|
@ -60,15 +60,17 @@ module Pigeon
|
|||
# /Constants for internal use only
|
||||
|
||||
class Helpers
|
||||
def self.verify_string(identity, signature, string)
|
||||
key = Ed25519::VerifyKey.new(decode_multihash(identity.public_key))
|
||||
raw_sig = decode_multihash(signature)
|
||||
key.verify(raw_sig, string)
|
||||
end
|
||||
|
||||
def self.decode_multihash(string)
|
||||
case string[0]
|
||||
when BLOB_SIGIL, MESSAGE_SIGIL, IDENTITY_SIGIL
|
||||
inner = string[1..-1].gsub(FOOTERS_REGEX, "")
|
||||
Base64.urlsafe_decode64(inner)
|
||||
if string[SIG_RANGE] == SIG_FOOTER
|
||||
return Base64.urlsafe_decode64(string.gsub(SIG_FOOTER, ""))
|
||||
else
|
||||
if signature[SIG_RANGE] == SIG_FOOTER
|
||||
Base64.urlsafe_decode64(signature.gsub(SIG_FOOTER, ""))
|
||||
end
|
||||
return Base64.urlsafe_decode64(string[1..].gsub(FOOTERS_REGEX, ""))
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -43,10 +43,6 @@ module Pigeon
|
|||
return b64 + SIG_FOOTER
|
||||
end
|
||||
|
||||
def verify(signature, string)
|
||||
raise "TODO"
|
||||
end
|
||||
|
||||
def save!
|
||||
Pigeon::Storage.current.set_config(SEED_CONFIG_KEY, @seed)
|
||||
self
|
||||
|
|
|
@ -3,7 +3,9 @@ require "digest"
|
|||
module Pigeon
|
||||
class Message
|
||||
attr_reader :author, :kind, :body, :signature, :depth, :prev
|
||||
|
||||
class VerificationError < StandardError; end
|
||||
|
||||
VERFIY_ERROR = "Expected field %s to equal %s. Got: %s"
|
||||
# Author a new message.
|
||||
def self.publish(draft, author: LocalIdentity.current)
|
||||
|
@ -66,7 +68,8 @@ module Pigeon
|
|||
end
|
||||
|
||||
def verify_signature
|
||||
author.verify(signature, template.render_without_signature)
|
||||
tpl = template.render_without_signature
|
||||
Helpers.verify_string(author, signature, tpl)
|
||||
end
|
||||
|
||||
def initialize(author:, kind:, body:, signature: nil)
|
||||
|
|
|
@ -9,13 +9,7 @@ module Pigeon
|
|||
attr_reader :public_key
|
||||
|
||||
def initialize(multihash)
|
||||
b64 = Base64.urlsafe_encode64(multihash)
|
||||
@public_key = [IDENTITY_SIGIL, b64, IDENTITY_FOOTER].join("")
|
||||
end
|
||||
|
||||
def verify(signature, string)
|
||||
binding.pry
|
||||
raise "TODO"
|
||||
@public_key = multihash
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue