Implement NIP-19 bech32-encoded private and public keys
https://github.com/nostr-protocol/nips/blob/master/19.md
This commit is contained in:
@@ -5,19 +5,43 @@ require 'spec_helper'
|
||||
RSpec.describe Nostr::KeyPair do
|
||||
let(:keypair) do
|
||||
described_class.new(
|
||||
private_key: '893c4cc8088924796b41dc788f7e2f746734497010b1a9f005c1faad7074b900',
|
||||
public_key: '2d7661527d573cc8e84f665fa971dd969ba51e2526df00c149ff8e40a58f9558'
|
||||
private_key: Nostr::PrivateKey.new('893c4cc8088924796b41dc788f7e2f746734497010b1a9f005c1faad7074b900'),
|
||||
public_key: Nostr::PublicKey.new('2d7661527d573cc8e84f665fa971dd969ba51e2526df00c149ff8e40a58f9558')
|
||||
)
|
||||
end
|
||||
|
||||
describe '.new' do
|
||||
it 'creates an instance of a key pair' do
|
||||
keypair = described_class.new(
|
||||
private_key: '893c4cc8088924796b41dc788f7e2f746734497010b1a9f005c1faad7074b900',
|
||||
public_key: '2d7661527d573cc8e84f665fa971dd969ba51e2526df00c149ff8e40a58f9558'
|
||||
)
|
||||
context 'when private_key is not an instance of PrivateKey' do
|
||||
it 'raises an error' do
|
||||
expect do
|
||||
described_class.new(
|
||||
private_key: '893c4cc8088924796b41dc788f7e2f746734497010b1a9f005c1faad7074b900',
|
||||
public_key: Nostr::PublicKey.new('2d7661527d573cc8e84f665fa971dd969ba51e2526df00c149ff8e40a58f9558')
|
||||
)
|
||||
end.to raise_error(ArgumentError, 'private_key is not an instance of PrivateKey')
|
||||
end
|
||||
end
|
||||
|
||||
expect(keypair).to be_an_instance_of(described_class)
|
||||
context 'when public_key is not an instance of PublicKey' do
|
||||
it 'raises an error' do
|
||||
expect do
|
||||
described_class.new(
|
||||
private_key: Nostr::PrivateKey.new('893c4cc8088924796b41dc788f7e2f746734497010b1a9f005c1faad7074b900'),
|
||||
public_key: '2d7661527d573cc8e84f665fa971dd969ba51e2526df00c149ff8e40a58f9558'
|
||||
)
|
||||
end.to raise_error(ArgumentError, 'public_key is not an instance of PublicKey')
|
||||
end
|
||||
end
|
||||
|
||||
context 'when private_key is an instance of PrivateKey and public_key is an instance of PublicKey' do
|
||||
it 'creates an instance of a key pair' do
|
||||
keypair = described_class.new(
|
||||
private_key: Nostr::PrivateKey.new('893c4cc8088924796b41dc788f7e2f746734497010b1a9f005c1faad7074b900'),
|
||||
public_key: Nostr::PublicKey.new('2d7661527d573cc8e84f665fa971dd969ba51e2526df00c149ff8e40a58f9558')
|
||||
)
|
||||
|
||||
expect(keypair).to be_an_instance_of(described_class)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
Reference in New Issue
Block a user