Done with lipmaalinks, but probably not partial verification.

This commit is contained in:
Netscape Navigator 2020-04-14 07:33:41 -05:00
parent 48625599d6
commit 975d7cde57
6 changed files with 29 additions and 15 deletions

View File

@ -55,6 +55,7 @@ Eg: `pigeon identity show` becomes `./pigeon-cli show`.
- [X] Run Flog / Flay and friends to find duplications. Will aid in port to other languages.
- [X] Make all methods private except those required for the CLI.
- [ ] Add Lipmaa links like the Bamboo folks do.
- [ ] Verification of `depth` and `lipmaa` may need a re-look to support partial verification.
- [ ] Make the switch to LevelDB, RocksDB, [UNQLite](https://unqlite.org/features.html) or similar (currently using Ruby PStore).
- [ ] Make CLI names consistent with API names. Eg: find vs. read.
- [ ] Create regexes in ::Lexer using strings and Regexp.new() for cleaner regexes.

2
dist/pigeon.rb vendored
View File

@ -87,7 +87,7 @@ module Pigeon
# The original lipmaa function returns -1 for 0
# but that does not mesh well with our serialization
# scheme. Comments welcome on this one.
return 0 if n == 0 # Prevent -1 return value.
return 0 if n < 1 # Prevent -1, division by zero etc..
m, po3, x = 1, 3, n
# find k such that (3^k - 1)/2 >= n

View File

@ -100,7 +100,7 @@ module Pigeon
end
if scanner.scan(LIPMAA)
depth = scanner.matched.chomp.gsub("depth ", "").to_i
depth = scanner.matched.chomp.gsub("lipmaa ", "").to_i
@tokens << [:LIPMAA, depth]
return
end

View File

@ -39,7 +39,7 @@ module Pigeon
def save!
return store.read_message(multihash) if store.message?(multihash)
verify_depth_prev_and_depth
verify_counted_fields
verify_signature
self.freeze
store.save_message(self)
@ -53,11 +53,14 @@ module Pigeon
end
end
def verify_depth_prev_and_depth
def verify_counted_fields
count = store.get_message_count_for(author.multihash)
expected_prev = store.get_message_by_depth(author.multihash, count - 1) || Pigeon::NOTHING
assert("depth", count, depth)
assert("lipmaa", Helpers.lipmaa(count), lipmaa)
# TODO: Re-visit this. Our current verification method
# is probably too strict and won't allow for partial
# verification of feeds.
assert("lipmaa", Helpers.lipmaa(depth), lipmaa)
assert("prev", prev, expected_prev)
end
@ -83,16 +86,6 @@ module Pigeon
@signature = signature
end
def params
{ author: @author,
kind: @kind,
body: @body,
depth: @depth,
prev: @prev,
lipmaa: @lipmaa,
signature: @signature }
end
def template
MessageSerializer.new(self)
end

View File

@ -1,4 +1,23 @@
RSpec.describe Pigeon::Helpers do
it "creates lipmalinks" do
[
[-1, 0],
[0, 0],
[1, 0],
[2, 1],
[3, 2],
[4, 1],
[5, 4],
[6, 5],
[7, 6],
[8, 4],
[13, 4],
].map do |(input, expected)|
actual = Pigeon::Helpers.lipmaa(input)
expect(actual).to eq(expected)
end
end
it "handles Crockford Base 32 values" do
10.times do
raw_bytes = SecureRandom.random_bytes(32)

View File

@ -50,6 +50,7 @@ RSpec.describe Pigeon::Message do
"kind unit_test",
"prev NONE",
"depth 0",
"lipmaa 0",
"",
"a:\"bar\"",
"b:&CHHABX8Q9D9Q0BY2BBZ6FA7SMAFNE9GGMSDTZVZZC9TK2N9F15QG.sha256",