Rename .public_key attributes to .multihash for consistency

This commit is contained in:
Netscape Navigator 2020-04-06 07:22:24 -05:00
parent 6d6e8ffa37
commit dd7456cc88
16 changed files with 28 additions and 27 deletions

View File

@ -46,7 +46,8 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`.
- [X] Implement pigeon message find-all for peer feed. I will need to add index for `author => message_count`
- [X] Switch to Crockford base32- Simplifies support for legacy systems. Easy to implement.
- [X] Fix `scratchpad.sh` to use Base32
- [ ] Rename (RemoteIdentity|LocalIdentity)#public_key to #multihash for consistency with other types.
- [X] Rename (RemoteIdentity|LocalIdentity)#public_key to #multihash for consistency with other types.
- [ ] Fix diagram in spec doc
- [ ] refactor `Bundle.create` to use `message find-all`.
- [ ] Need a way of importing / exporting a feeds blobs. (see "Bundle Brainstorming" below)
- [ ] Need a way of adding peers messages / gossip to bundles. (see "Bundle Brainstorming" below)

2
dist/pigeon.rb vendored
View File

@ -117,7 +117,7 @@ module Pigeon
def self.verify_string(identity, string_signature, string)
binary_signature = decode_multihash(string_signature)
string_key = identity.public_key
string_key = identity.multihash
binary_key = decode_multihash(string_key)
verify_key = Ed25519::VerifyKey.new(binary_key)

View File

@ -6,7 +6,7 @@ module Pigeon
author = Pigeon::LocalIdentity.current
range = (0...last).to_a
content = range
.map { |depth| s.get_message_by_depth(author.public_key, depth) }
.map { |depth| s.get_message_by_depth(author.multihash, depth) }
.map { |multihash| s.find_message(multihash) }
.map { |message| message.render }
.join(BUNDLE_MESSAGE_SEPARATOR)

View File

@ -30,11 +30,11 @@ module Pigeon
@private_key ||= Helpers.b32_encode(@seed)
end
def public_key
def multihash
bytes = @signing_key.verify_key.to_bytes
b64 = Helpers.b32_encode(bytes)
@public_key ||= [IDENTITY_SIGIL, b64, IDENTITY_FOOTER].join("")
@multihash ||= [IDENTITY_SIGIL, b64, IDENTITY_FOOTER].join("")
end
def sign(string)

View File

@ -12,9 +12,9 @@ module Pigeon
author = LocalIdentity.current
depth = Pigeon::Storage
.current
.get_message_count_for(author.public_key)
count = store.get_message_count_for(author.public_key)
prev = store.get_message_by_depth(author.public_key, count - 1)
.get_message_count_for(author.multihash)
count = store.get_message_count_for(author.multihash)
prev = store.get_message_by_depth(author.multihash, count - 1)
msg = self.new(author: author,
kind: draft.kind,
body: draft.body,
@ -65,8 +65,8 @@ module Pigeon
end
def verify_depth_prev_and_depth
count = store.get_message_count_for(author.public_key)
expected_prev = store.get_message_by_depth(author.public_key, count - 1) || Pigeon::EMPTY_MESSAGE
count = store.get_message_count_for(author.multihash)
expected_prev = store.get_message_by_depth(author.multihash, count - 1) || Pigeon::EMPTY_MESSAGE
assert("depth", count, depth)
assert("prev", prev, expected_prev)
end

View File

@ -21,7 +21,7 @@ module Pigeon
private
def do_render(template)
author = message.author.public_key
author = message.author.multihash
body = message.body
depth = message.depth
kind = message.kind

View File

@ -6,10 +6,10 @@ module Pigeon
# help us maintain our sanity when the Gem's API
# changes.
class RemoteIdentity
attr_reader :public_key
attr_reader :multihash
def initialize(multihash)
@public_key = multihash
@multihash = multihash
end
end
end

View File

@ -136,7 +136,7 @@ module Pigeon
end
def insert_and_update_index(message)
pub_key = message.author.public_key
pub_key = message.author.multihash
# STEP 1: Update MESG_NS, the main storage spot.
store[MESG_NS][message.multihash] = message

0
kitchen_sink.sh Normal file → Executable file
View File

View File

@ -32,13 +32,13 @@ module Pigeon
end
kp = Pigeon::LocalIdentity.new()
kp.save!
puts kp.public_key
puts kp.multihash
end
desc "show", "Prints your identiy string to STDOUT"
def show
puts Pigeon::LocalIdentity.current.public_key
puts Pigeon::LocalIdentity.current.multihash
end
end
@ -138,7 +138,7 @@ module Pigeon
desc "find-all", "Find a pigeon message in the local DB"
def find_all(author = Pigeon::LocalIdentity.current.public_key)
def find_all(author = Pigeon::LocalIdentity.current.multihash)
# TODO: Ability to find-all messages by author ID
puts Pigeon::Storage
.current
@ -151,7 +151,7 @@ module Pigeon
def last
me = Pigeon::LocalIdentity.current
store = Pigeon::Storage.current
multihash = store.get_message_by_depth(me.public_key, store.message_count - 1)
multihash = store.get_message_by_depth(me.multihash, store.message_count - 1)
puts multihash
end
end
@ -166,7 +166,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::LocalIdentity.current.public_key}
\\ / Ident: #{Pigeon::LocalIdentity.current.multihash}
===m" "m===
"
end

View File

@ -25,7 +25,7 @@ RSpec.describe Pigeon::Draft do
].join("\n")
it "renders a message" do
pk = Pigeon::LocalIdentity.current.public_key
pk = Pigeon::LocalIdentity.current.multihash
actual = message.render
expected = MSG.gsub("___", pk)
expect(actual).to start_with(expected)

View File

@ -139,7 +139,7 @@ RSpec.describe Pigeon::Lexer do
h
end
expect(hash[:AUTHOR]).to eq(message.author.public_key)
expect(hash[:AUTHOR]).to eq(message.author.multihash)
expect(hash[:BODY]).to eq(message.body)
expect(hash[:DEPTH]).to eq(message.depth)
expect(hash[:KIND]).to eq(message.kind)

View File

@ -17,7 +17,7 @@ RSpec.describe Pigeon::LocalIdentity do
it "generates a pair from a seed" do
x = "@XSZY1ME6QMA5BBSJ8QSDJCSG6EVDTCKYNMV221SB7B2NZR5K09J0.ed25519"
expect(kp.public_key).to eq(x)
expect(kp.multihash).to eq(x)
y = "2PRTG7F13HWF1HPW9FF9NDSYGSQS5VXQ2WMZY0A510J64AE9G840"
expect(kp.private_key).to eq(y)
end

View File

@ -54,7 +54,7 @@ RSpec.describe Pigeon::Message do
"",
"signature __SIGNATURE__",
].join("\n")
.gsub("__AUTHOR__", message.author.public_key)
.gsub("__AUTHOR__", message.author.multihash)
.gsub("__SIGNATURE__", message.signature)
expect(actual).to eq(expected)
end

View File

@ -52,7 +52,7 @@ RSpec.describe Pigeon::Storage do
it "finds all authored by a particular feed" do
ingested_messages = Pigeon::Bundle.ingest("./spec/fixtures/normal.bundle")
author = ingested_messages.first.author.public_key
author = ingested_messages.first.author.multihash
actual_messages = Pigeon::Storage.current.find_all(author)
search_results = Pigeon::Storage.current.find_all(author)
end
@ -67,10 +67,10 @@ RSpec.describe Pigeon::Storage do
"e" => Pigeon::Storage.current.set_blob(File.read("./logo.png")),
}),
Pigeon::Helpers.create_message("g", {
"me_myself_and_i" => Pigeon::LocalIdentity.current.public_key,
"me_myself_and_i" => Pigeon::LocalIdentity.current.multihash,
}),
]
me = Pigeon::LocalIdentity.current.public_key
me = Pigeon::LocalIdentity.current.multihash
results = Pigeon::Storage.current.find_all(me)
expect(results.length).to eq(3)
expect(msgs[0].multihash).to eq(results[0])

View File

@ -12,7 +12,7 @@ RSpec.describe Pigeon::MessageSerializer do
EXPECTED_DRAFT = TOP_HALF + BOTTOM_HALF
class FakeLocalIdentity
def self.public_key
def self.multihash
"FAKE_AUTHOR"
end
end