Rename KeyPair to LocalIdentity to disambiguate (were dealing with peers now).
This commit is contained in:
parent
8d9deb90af
commit
f3373863a6
|
@ -35,7 +35,7 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`.
|
|||
- [X] Move literals into `Pigeon` module as constants, again.
|
||||
- [X] pigeon message find
|
||||
- [X] pigeon message find-all for local feed.
|
||||
- [ ] pigeon bundle consume
|
||||
- [ ] pigeon bundle consume (We are minimally feature complete at this point)
|
||||
- [ ] Change all the `{40,90}` values in ::Lexer to real length values
|
||||
- [ ] Rename `message find` to `message read`, since other finders return a multihash.
|
||||
- [ ] Don't allow carriage return in `kind`. Write a test for this.
|
||||
|
|
|
@ -54,11 +54,12 @@ module Pigeon
|
|||
MISSING_BODY = "BODY CANT BE EMPTY"
|
||||
end
|
||||
|
||||
require_relative File.join("pigeon", "key_pair.rb")
|
||||
require_relative File.join("pigeon", "local_identity.rb")
|
||||
require_relative File.join("pigeon", "storage.rb")
|
||||
require_relative File.join("pigeon", "draft_serializer.rb")
|
||||
require_relative File.join("pigeon", "message_serializer.rb")
|
||||
require_relative File.join("pigeon", "message.rb")
|
||||
require_relative File.join("pigeon", "draft.rb")
|
||||
require_relative File.join("pigeon", "lexer.rb")
|
||||
require_relative File.join("pigeon", "parser.rb")
|
||||
require_relative File.join("pigeon", "bundle.rb")
|
||||
|
|
|
@ -3,7 +3,7 @@ module Pigeon
|
|||
def self.create(file_path = DEFAULT_BUNDLE_PATH)
|
||||
s = Pigeon::Storage.current
|
||||
last = s.message_count
|
||||
author = Pigeon::KeyPair.current
|
||||
author = Pigeon::LocalIdentity.current
|
||||
range = (0...last).to_a
|
||||
content = range
|
||||
.map { |depth| s.get_message_by_depth(author, depth) }
|
||||
|
|
|
@ -1,8 +1,11 @@
|
|||
module Pigeon
|
||||
# This is a wrapper around the `ed25519` gem to
|
||||
# A public and private key pair that represents the local
|
||||
# user who "owns" the database.
|
||||
#
|
||||
# Provides a wrapper around the `ed25519` gem to
|
||||
# help us maintain our sanity when the Gem's API
|
||||
# changes.
|
||||
class KeyPair
|
||||
class LocalIdentity
|
||||
def self.reset
|
||||
@current = nil
|
||||
end
|
|
@ -4,13 +4,13 @@ module Pigeon
|
|||
class Message
|
||||
attr_reader :author, :kind, :body, :signature, :depth, :prev
|
||||
|
||||
def self.publish(draft, author: KeyPair.current)
|
||||
msg = self.new(author: KeyPair.current,
|
||||
def self.publish(draft, author: LocalIdentity.current)
|
||||
msg = self.new(author: LocalIdentity.current,
|
||||
kind: draft.kind,
|
||||
body: draft.body)
|
||||
# We might need to add conditional logic here
|
||||
# Currently YAGNI since all Drafts we handle today
|
||||
# are authored by KeyPair.current
|
||||
# are authored by LocalIdentity.current
|
||||
draft.discard
|
||||
msg
|
||||
end
|
||||
|
|
|
@ -1,7 +1,24 @@
|
|||
module Pigeon
|
||||
class Parser
|
||||
def self.parse(tokens)
|
||||
raise "WIP"
|
||||
self.new(tokens).parse
|
||||
end
|
||||
|
||||
def initialize(tokens)
|
||||
@scratchpad = {}
|
||||
@tokens = tokens
|
||||
@results = []
|
||||
end
|
||||
|
||||
def parse()
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def collect_tokens
|
||||
end
|
||||
|
||||
def validate_message
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -39,7 +39,7 @@ module Pigeon
|
|||
|
||||
def find_all
|
||||
# TODO: Ability to pass an author ID to `find-all`
|
||||
author = Pigeon::KeyPair.current
|
||||
author = Pigeon::LocalIdentity.current
|
||||
store = Pigeon::Storage.current
|
||||
all = []
|
||||
depth = -1
|
||||
|
@ -88,7 +88,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
def add_peer(identity)
|
||||
path = KeyPair.strip_headers(identity)
|
||||
path = LocalIdentity.strip_headers(identity)
|
||||
store.transaction do
|
||||
store[PEER_NS].add(identity)
|
||||
end
|
||||
|
@ -96,7 +96,7 @@ module Pigeon
|
|||
end
|
||||
|
||||
def remove_peer(identity)
|
||||
path = KeyPair.strip_headers(identity)
|
||||
path = LocalIdentity.strip_headers(identity)
|
||||
store.transaction do
|
||||
store[PEER_NS].delete(identity)
|
||||
end
|
||||
|
|
|
@ -30,7 +30,7 @@ module Pigeon
|
|||
Remove config dir or switch to a different directory."
|
||||
raise ConfigAlreadyExists
|
||||
end
|
||||
kp = Pigeon::KeyPair.new()
|
||||
kp = Pigeon::LocalIdentity.new()
|
||||
kp.save!
|
||||
puts kp.public_key
|
||||
end
|
||||
|
@ -38,7 +38,7 @@ module Pigeon
|
|||
desc "show", "Prints a base64 identiy string to STDOUT"
|
||||
|
||||
def show
|
||||
puts Pigeon::KeyPair.current.public_key
|
||||
puts Pigeon::LocalIdentity.current.public_key
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -146,7 +146,7 @@ module Pigeon
|
|||
desc "last", "Grab your last message. INTERNAL USE ONLY"
|
||||
|
||||
def last
|
||||
me = Pigeon::KeyPair.current
|
||||
me = Pigeon::LocalIdentity.current
|
||||
store = Pigeon::Storage.current
|
||||
multihash = store.get_message_by_depth(me, store.message_count - 1)
|
||||
puts multihash
|
||||
|
@ -163,7 +163,7 @@ module Pigeon
|
|||
_) ( Peers: #{Pigeon::Storage.current.all_peers.count}
|
||||
/ ) Blocked: #{Pigeon::Storage.current.all_blocks.count}
|
||||
/_,' / Logs: #{Pigeon::Storage.current.message_count}
|
||||
\\ / Ident: #{Pigeon::KeyPair.current.public_key}
|
||||
\\ / Ident: #{Pigeon::LocalIdentity.current.public_key}
|
||||
===m" "m===
|
||||
"
|
||||
end
|
||||
|
|
|
@ -3,7 +3,7 @@ require "spec_helper"
|
|||
RSpec.describe Pigeon::Message do
|
||||
before(:each) do
|
||||
Pigeon::Storage.reset
|
||||
Pigeon::KeyPair.reset
|
||||
Pigeon::LocalIdentity.reset
|
||||
end
|
||||
|
||||
def create_message(params)
|
||||
|
|
|
@ -11,7 +11,7 @@ RSpec.describe Pigeon::Draft do
|
|||
|
||||
before(:each) do
|
||||
Pigeon::Storage.reset
|
||||
Pigeon::KeyPair.reset
|
||||
Pigeon::LocalIdentity.reset
|
||||
end
|
||||
|
||||
MSG = [
|
||||
|
@ -25,7 +25,7 @@ RSpec.describe Pigeon::Draft do
|
|||
].join("\n")
|
||||
|
||||
it "renders a message" do
|
||||
pk = Pigeon::KeyPair.current.public_key
|
||||
pk = Pigeon::LocalIdentity.current.public_key
|
||||
actual = message.render
|
||||
expected = MSG.gsub("___", pk)
|
||||
expect(actual).to start_with(expected)
|
||||
|
|
|
@ -2,9 +2,9 @@ require "spec_helper"
|
|||
|
||||
RSpec.describe "Kitch sink spec" do
|
||||
it "does everything" do
|
||||
kp = Pigeon::KeyPair.new()
|
||||
kp = Pigeon::LocalIdentity.new()
|
||||
kp.save!
|
||||
Pigeon::KeyPair.current.public_key
|
||||
Pigeon::LocalIdentity.current.public_key
|
||||
# ./pigeon-cli identity new
|
||||
# ./pigeon-cli identity show
|
||||
# cat scratchpad.jpg | ./pigeon-cli blob set
|
||||
|
|
|
@ -46,7 +46,7 @@ RSpec.describe Pigeon::Lexer do
|
|||
|
||||
before(:each) do
|
||||
Pigeon::Storage.reset
|
||||
Pigeon::KeyPair.reset
|
||||
Pigeon::LocalIdentity.reset
|
||||
end
|
||||
|
||||
it "tokenizes a bundle" do
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
require "spec_helper"
|
||||
|
||||
RSpec.describe Pigeon::KeyPair do
|
||||
RSpec.describe Pigeon::LocalIdentity do
|
||||
FAKE_SEED = "\x15\xB1\xA8\x1D\xE1\x1Cx\xF0" \
|
||||
"\xC6\xDCK\xDE\x9A\xB7>\x86o\x92\xEF\xB7\x17" \
|
||||
")\xFF\x01E\b$b)\xC9\x82\b"
|
||||
let(:kp) { Pigeon::KeyPair.new(FAKE_SEED) }
|
||||
let(:kp) { Pigeon::LocalIdentity.new(FAKE_SEED) }
|
||||
|
||||
HELLO_SIGNATURE = [
|
||||
"erGeJdWiWzDJpKJdkLSc5uBc90j5t90aPcbCehLp6Xg",
|
||||
|
@ -29,12 +29,12 @@ RSpec.describe Pigeon::KeyPair do
|
|||
whatever,
|
||||
Pigeon::FOOTER,
|
||||
].join("")
|
||||
result = Pigeon::KeyPair.strip_headers(example)
|
||||
result = Pigeon::LocalIdentity.strip_headers(example)
|
||||
expect(result).to eq(whatever)
|
||||
end
|
||||
|
||||
it "caches KeyPair.current" do
|
||||
first_kp = Pigeon::KeyPair.current
|
||||
expect(Pigeon::KeyPair.current).to be(first_kp) # Need strict equality here!
|
||||
it "caches LocalIdentity.current" do
|
||||
first_kp = Pigeon::LocalIdentity.current
|
||||
expect(Pigeon::LocalIdentity.current).to be(first_kp) # Need strict equality here!
|
||||
end
|
||||
end
|
|
@ -3,7 +3,7 @@ require "spec_helper"
|
|||
RSpec.describe Pigeon::Message do
|
||||
before(:each) do
|
||||
Pigeon::Storage.reset
|
||||
Pigeon::KeyPair.reset
|
||||
Pigeon::LocalIdentity.reset
|
||||
end
|
||||
|
||||
def create_draft(params)
|
||||
|
@ -35,7 +35,7 @@ RSpec.describe Pigeon::Message do
|
|||
|
||||
it "creates a single message" do
|
||||
message = Pigeon::Message.publish(draft)
|
||||
expect(message.author).to eq(Pigeon::KeyPair.current)
|
||||
expect(message.author).to eq(Pigeon::LocalIdentity.current)
|
||||
expect(message.body).to eq(draft.body)
|
||||
expect(message.depth).to eq(0)
|
||||
expect(message.kind).to eq("unit_test")
|
||||
|
@ -90,19 +90,19 @@ RSpec.describe Pigeon::Message do
|
|||
expect(m4.prev).to be
|
||||
end
|
||||
|
||||
# Init keypair
|
||||
# Init LocalIdentity
|
||||
# Get secret
|
||||
# Create signing key
|
||||
|
||||
it "verifies accuracy of signatures" do
|
||||
# === Initial setup
|
||||
Pigeon::KeyPair.current
|
||||
Pigeon::LocalIdentity.current
|
||||
secret = Pigeon::Storage.current.get_config(Pigeon::SEED_CONFIG_KEY)
|
||||
message = template.message
|
||||
plaintext = template.render_without_signature
|
||||
|
||||
# Make fake pairs of data for cross-checking
|
||||
key1 = Pigeon::KeyPair.current.instance_variable_get(:@signing_key)
|
||||
key1 = Pigeon::LocalIdentity.current.instance_variable_get(:@signing_key)
|
||||
key2 = Ed25519::SigningKey.new(secret)
|
||||
|
||||
sig1 = key1.sign(plaintext)
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
require "spec_helper"
|
||||
|
||||
RSpec.describe Pigeon::Lexer do
|
||||
before(:each) do
|
||||
Pigeon::Storage.reset
|
||||
Pigeon::LocalIdentity.reset
|
||||
end
|
||||
|
||||
let(:tokens) { Pigeon::Lexer.tokenize(File.read("./example.bundle")) }
|
||||
|
||||
it "parses tokens" do
|
||||
results = Pigeon::Parser.parse(tokens)
|
||||
expect(results.length).to e(2)
|
||||
end
|
||||
|
||||
it "crashes on forged messages"
|
||||
end
|
|
@ -11,14 +11,14 @@ RSpec.describe Pigeon::MessageSerializer do
|
|||
BOTTOM_HALF = "signature XYZ.sig.sha256"
|
||||
EXPECTED_DRAFT = TOP_HALF + BOTTOM_HALF
|
||||
|
||||
class FakeKeypair
|
||||
class FakeLocalIdentity
|
||||
def self.public_key
|
||||
"FAKE_AUTHOR"
|
||||
end
|
||||
end
|
||||
|
||||
it "renders a draft" do
|
||||
args = [FakeKeypair,
|
||||
args = [FakeLocalIdentity,
|
||||
{ foo: "bar".inspect },
|
||||
"FAKE_KIND",
|
||||
23,
|
||||
|
|
Loading…
Reference in New Issue