Implement NIP-19 bech32-encoded private and public keys

https://github.com/nostr-protocol/nips/blob/master/19.md
This commit is contained in:
Wilson Silva
2023-11-20 09:59:27 +07:00
parent 3fffcd1a4e
commit 3520cf8219
58 changed files with 1189 additions and 104 deletions

View File

@@ -0,0 +1,15 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Nostr::InvalidHRPError do
describe '#initialize' do
let(:given_hrp) { 'nwrong' }
let(:allowed_hrp) { 'nsec' }
let(:error) { described_class.new(given_hrp, allowed_hrp) }
it 'builds a useful error message' do
expect(error.message).to eq("Invalid hrp: nwrong. The allowed hrp value for this kind of entity is 'nsec'.")
end
end
end

View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Nostr::InvalidKeyFormatError do
describe '#initialize' do
let(:key_kind) { 'private' }
let(:error) { described_class.new(key_kind) }
it 'builds a useful error message' do
expect(error.message).to eq('Only lowercase hexadecimal characters are allowed in private keys.')
end
end
end

View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Nostr::InvalidKeyLengthError do
describe '#initialize' do
let(:key_kind) { 'private' }
let(:error) { described_class.new(key_kind) }
it 'builds a useful error message' do
expect(error.message).to eq('Invalid private key length. It should have 64 characters.')
end
end
end

View File

@@ -0,0 +1,14 @@
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Nostr::InvalidKeyTypeError do
describe '#initialize' do
let(:key_kind) { 'private' }
let(:error) { described_class.new(key_kind) }
it 'builds a useful error message' do
expect(error.message).to eq('Invalid private key type')
end
end
end