🎉🎉🎉 Bundle ingestion works!!
This commit is contained in:
parent
56781696b2
commit
191a73c419
|
@ -67,21 +67,7 @@ module Pigeon
|
|||
binary_key = decode_multihash(string_key)
|
||||
verify_key = Ed25519::VerifyKey.new(binary_key)
|
||||
|
||||
# puts "=" * 200
|
||||
# puts string
|
||||
# puts "=" * 200
|
||||
# puts "binary_key: #{binary_key.inspect[0..150]}"
|
||||
# puts "binary_signature: #{binary_signature.inspect[0..150]}"
|
||||
# puts "identity: #{identity.inspect[0..150]}"
|
||||
# puts "string_key: #{string_key.inspect[0..150]}"
|
||||
# puts "string_signature: #{string_signature.inspect[0..150]}"
|
||||
# puts "string: #{string.inspect[0..150]}"
|
||||
# puts "verify_key: #{verify_key.inspect[0..150]}"
|
||||
|
||||
verify_key.verify(binary_signature, string)
|
||||
# rescue => e
|
||||
# key1 = identity.instance_variable_get(:@signing_key).verify_key
|
||||
# binding.pry
|
||||
end
|
||||
|
||||
def self.decode_multihash(string)
|
||||
|
|
|
@ -14,16 +14,13 @@ module Pigeon
|
|||
.current
|
||||
.get_message_count_for(author.public_key)
|
||||
count = store.get_message_count_for(author.public_key)
|
||||
raise "TODO: Render a signature here"
|
||||
prev = store.get_message_by_depth(author.public_key, count - 1)
|
||||
msg = self.new(author: author,
|
||||
kind: draft.kind,
|
||||
body: draft.body,
|
||||
depth: depth,
|
||||
prev: store.get_message_by_depth(author.public_key, count - 1),
|
||||
signature: signature)
|
||||
# We might need to add conditional logic here
|
||||
# Currently YAGNI since all Drafts we handle today
|
||||
# are authored by LocalIdentity.current
|
||||
prev: prev)
|
||||
msg.sign!
|
||||
draft.discard
|
||||
msg
|
||||
end
|
||||
|
@ -54,6 +51,13 @@ module Pigeon
|
|||
self.freeze
|
||||
end
|
||||
|
||||
def sign!
|
||||
calculate_signature
|
||||
verify!
|
||||
store.save_message(self)
|
||||
self
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def assert(field, actual, expected)
|
||||
|
@ -76,26 +80,25 @@ module Pigeon
|
|||
Helpers.verify_string(author, signature, tpl)
|
||||
end
|
||||
|
||||
def initialize(author:, kind:, body:, signature:, depth:, prev:)
|
||||
def initialize(author:, kind:, body:, depth:, prev:, signature: nil)
|
||||
raise MISSING_BODY if body.empty?
|
||||
@author = author
|
||||
@kind = kind
|
||||
@body = body
|
||||
@depth = depth
|
||||
@signature = signature
|
||||
@kind = kind
|
||||
@prev = prev || Pigeon::EMPTY_MESSAGE
|
||||
verify!
|
||||
store.save_message(self)
|
||||
@signature = signature
|
||||
end
|
||||
|
||||
def calculate_signature
|
||||
return if @signature
|
||||
@signature = author.sign(template.render_without_signature)
|
||||
end
|
||||
|
||||
def template
|
||||
MessageSerializer.new(self)
|
||||
end
|
||||
|
||||
def self.calculate_signature(author)
|
||||
@author.sign(template.render_without_signature)
|
||||
end
|
||||
|
||||
def self.store
|
||||
Pigeon::Storage.current
|
||||
end
|
||||
|
|
|
@ -78,14 +78,10 @@ RSpec.describe Pigeon::Message do
|
|||
it "verifies accuracy of hash chain" do
|
||||
m1 = create_message({ "a" => "b" })
|
||||
m2 = create_message({ "c" => "d" })
|
||||
# ./dist/pigeon.rb:66:in `verify_string'
|
||||
# ./dist/pigeon/message.rb:70:in `verify_signature'
|
||||
# ./dist/pigeon/message.rb:47:in `verify!'
|
||||
# ./dist/pigeon/message.rb:82:in `initialize'
|
||||
|
||||
m3 = create_message({ "e" => "f" })
|
||||
m4 = create_message({ "g" => "h" })
|
||||
expect(m1.prev).to eq(nil)
|
||||
|
||||
expect(m1.prev).to eq(Pigeon::EMPTY_MESSAGE)
|
||||
expect(m2.prev).to be
|
||||
expect(m2.prev).to eq(m1.multihash)
|
||||
expect(m3.prev).to eq(m2.multihash)
|
||||
|
|
|
@ -1 +1 @@
|
|||
<% if signature %>signature <%= signature %><% else %>signature UNSIGNED<% end %>
|
||||
signature <%= signature %>
|
||||
|
|
Loading…
Reference in New Issue