digibyte-cigs 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +46 -0
- data/Gemfile +4 -0
- data/Gemfile.lock +29 -0
- data/LICENSE.txt +21 -0
- data/README.md +85 -0
- data/Rakefile +7 -0
- data/bin/digibyte-cigs +52 -0
- data/digibyte-cigs.gemspec +23 -0
- data/lib/digibyte-cigs.rb +1 -0
- data/lib/digibyte_cigs.rb +278 -0
- data/lib/digibyte_cigs/base_58.rb +42 -0
- data/lib/digibyte_cigs/compact_int.rb +33 -0
- data/lib/digibyte_cigs/crypto_helper.rb +67 -0
- data/lib/digibyte_cigs/curve_fp.rb +15 -0
- data/lib/digibyte_cigs/ec_key.rb +13 -0
- data/lib/digibyte_cigs/error.rb +4 -0
- data/lib/digibyte_cigs/point.rb +91 -0
- data/lib/digibyte_cigs/private_key.rb +28 -0
- data/lib/digibyte_cigs/public_key.rb +57 -0
- data/lib/digibyte_cigs/signature.rb +16 -0
- data/lib/digibyte_cigs/version.rb +3 -0
- data/misc/bitaddress.org.html +6487 -0
- data/misc/jasvet.py +632 -0
- data/spec/digibyte_cigs/base_58_spec.rb +28 -0
- data/spec/digibyte_cigs/compact_int_spec.rb +25 -0
- data/spec/digibyte_cigs_spec.rb +254 -0
- data/spec/spec_helper.rb +6 -0
- metadata +103 -0
@@ -0,0 +1,28 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'base64'
|
3
|
+
|
4
|
+
describe DigiByteCigs::Base58 do
|
5
|
+
describe "decode" do
|
6
|
+
let(:base_58_encoded_data) { "13C5HZKutjMDeuc7f5mPj6XGpJCZu7xKh2" }
|
7
|
+
|
8
|
+
subject { DigiByteCigs::Base58.decode(base_58_encoded_data) }
|
9
|
+
|
10
|
+
context "with valid data" do
|
11
|
+
it "decodes properly" do
|
12
|
+
expect(subject.unpack('H*').first).to eq("001808678bea2510c902a6cc3cd28ac0734516031620933591")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
describe "encode" do
|
18
|
+
let(:data) { ["001808678bea2510c902a6cc3cd28ac0734516031620933591"].pack('H*') }
|
19
|
+
|
20
|
+
subject { DigiByteCigs::Base58.encode(data) }
|
21
|
+
|
22
|
+
context "with valid data" do
|
23
|
+
it "encodes properly" do
|
24
|
+
expect(subject).to eq("13C5HZKutjMDeuc7f5mPj6XGpJCZu7xKh2")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DigiByteCigs::CompactInt do
|
4
|
+
describe "decode" do
|
5
|
+
subject do
|
6
|
+
DigiByteCigs::CompactInt.new(value).encode
|
7
|
+
end
|
8
|
+
|
9
|
+
context "with a value <= 252" do
|
10
|
+
let(:value) { 252 }
|
11
|
+
|
12
|
+
it "should encode to a single byte" do
|
13
|
+
expect(subject).to eq("\xFC")
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
context "with a value > 252" do
|
18
|
+
let(:value) { 253 }
|
19
|
+
|
20
|
+
it "should encode to a three bytes" do
|
21
|
+
expect(subject).to eq("\xFD\xFD\x00")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,254 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe DigiByteCigs do
|
4
|
+
def self.use_mainnet
|
5
|
+
let(:wallet_key) { "5JFZuDkLgbEXK4CUEiXyyz4fUqzAsQ5QUqufdJy8MoLA9S1RdNX" }
|
6
|
+
let(:address) { "11o51X3ciSjoLWFN3sbg3yzCM8RSuD2q9" }
|
7
|
+
let(:original_address) { "11o51X3ciSjoLWFN3sbg3yzCM8RSuD2q9" }
|
8
|
+
let(:private_key) { ["39678A14ECA8479B3C58DCD25A5C94BE768389E823435C4DDFCAEB13519AB10E"].pack('H*') }
|
9
|
+
let(:signature) { "HIBYi2g3yFimzD/YSD9j+PYwtsdCuHR2xwIQ6n0AN6RPUVDGttgOmlnsiwx90ZSjmaWrH1/HwrINJbaP7eMA6V4=" }
|
10
|
+
let(:network) { :mainnet }
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.use_testnet
|
14
|
+
let(:wallet_key) { "92FqDytA43K8unrrZgpzMddhmEbMMRNhBJAU59a3MkYfsUgH8st" }
|
15
|
+
let(:address) { "mh9nRF1ZSqLJB3hbUjPLmfDHdnGUURdYdK" }
|
16
|
+
let(:original_address) { "mh9nRF1ZSqLJB3hbUjPLmfDHdnGUURdYdK" }
|
17
|
+
let(:private_key) { ["585C660C887913E5F40B8E34D99C62766443F9D043B1DE1DFDCC94E386BC6DF6"].pack('H*') }
|
18
|
+
let(:signature) { "HIZQbBLAGJLhSZ310FCQMAo9l1X2ysxyt0kXkf6KcBN3znl2iClC6V9wz9Nkn6mMDUaq4kRlgYQDUUlsm29Bl0o=" }
|
19
|
+
let(:network) { :testnet }
|
20
|
+
end
|
21
|
+
|
22
|
+
use_mainnet
|
23
|
+
let(:message) { "this is a message" }
|
24
|
+
|
25
|
+
describe "sign_message!" do
|
26
|
+
subject { DigiByteCigs.sign_message!(wallet_key, message, :network => network) }
|
27
|
+
|
28
|
+
context "with valid data" do
|
29
|
+
it "generates the correct signature" do
|
30
|
+
expect(DigiByteCigs.verify_message(address, subject, message, :network => network)).to be_true
|
31
|
+
end
|
32
|
+
|
33
|
+
context "with a message > 252 characters" do
|
34
|
+
let(:message) { "a" * 253 }
|
35
|
+
|
36
|
+
it "generates the correct signature" do
|
37
|
+
expect(DigiByteCigs.verify_message(address, subject, message, :network => network)).to be_true
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "invalid wallet key" do
|
44
|
+
let(:wallet_key) { "invalid wallet key" }
|
45
|
+
|
46
|
+
it "raises an error" do
|
47
|
+
expect { subject }.to raise_error(::DigiByteCigs::Error, "Unknown Wallet Format")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
context "with testnet" do
|
52
|
+
use_testnet
|
53
|
+
|
54
|
+
context "with valid data" do
|
55
|
+
it "generates the correct signature" do
|
56
|
+
expect(DigiByteCigs.verify_message(address, subject, message, :network => network)).to be_true
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
describe "sign_message" do
|
63
|
+
subject { DigiByteCigs.sign_message(wallet_key, message) }
|
64
|
+
|
65
|
+
context "with valid data" do
|
66
|
+
it "generates the correct signature" do
|
67
|
+
expect(DigiByteCigs.verify_message(address, subject, message)).to be_true
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "invalid wallet key" do
|
72
|
+
let(:wallet_key) { "invalid wallet key" }
|
73
|
+
|
74
|
+
it "returns nil" do
|
75
|
+
expect(subject).to be_nil
|
76
|
+
end
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe "convert_wallet_format_to_bytes!" do
|
81
|
+
subject { DigiByteCigs.convert_wallet_format_to_bytes!(wallet_key, network) }
|
82
|
+
|
83
|
+
context "with wallet import format" do
|
84
|
+
let(:wallet_key) { "5JFZuDkLgbEXK4CUEiXyyz4fUqzAsQ5QUqufdJy8MoLA9S1RdNX" }
|
85
|
+
|
86
|
+
it "converts to correct bytes" do
|
87
|
+
expect(subject).to eq(private_key)
|
88
|
+
end
|
89
|
+
|
90
|
+
context "with testnet" do
|
91
|
+
use_testnet
|
92
|
+
|
93
|
+
let(:wallet_key) { "92FqDytA43K8unrrZgpzMddhmEbMMRNhBJAU59a3MkYfsUgH8st" }
|
94
|
+
|
95
|
+
it "converts to correct bytes" do
|
96
|
+
expect(subject).to eq(private_key)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
|
101
|
+
context "with compressed wallet import format" do
|
102
|
+
let(:wallet_key) { "Ky9JDVGHsk6gnh7dDYKkWWsAquDLZSrSdtsTVGJjUoVZN7sYjyyP" }
|
103
|
+
|
104
|
+
it "converts to correct bytes" do
|
105
|
+
expect(subject).to eq(private_key)
|
106
|
+
end
|
107
|
+
|
108
|
+
context "with testnet" do
|
109
|
+
use_testnet
|
110
|
+
|
111
|
+
let(:wallet_key) { "cQYTrJ4nxRD3v1R3mGnpA4gzvEzcq8akLSknVJpqQbCnZeD6WfNC" }
|
112
|
+
|
113
|
+
it "converts to correct bytes" do
|
114
|
+
expect(subject).to eq(private_key)
|
115
|
+
end
|
116
|
+
end
|
117
|
+
end
|
118
|
+
|
119
|
+
context "with mini format" do
|
120
|
+
let(:wallet_key) { "S6c56bnXQiBjk9mqSYE7ykVQ7NzrRy" }
|
121
|
+
let(:private_key) { ["4C7A9640C72DC2099F23715D0C8A0D8A35F8906E3CAB61DD3F78B67BF887C9AB"].pack('H*') }
|
122
|
+
|
123
|
+
it "converts to correct bytes" do
|
124
|
+
expect(subject).to eq(private_key)
|
125
|
+
end
|
126
|
+
end
|
127
|
+
|
128
|
+
context "with hex format" do
|
129
|
+
let(:wallet_key) { "39678A14ECA8479B3C58DCD25A5C94BE768389E823435C4DDFCAEB13519AB10E" }
|
130
|
+
|
131
|
+
it "converts to correct bytes" do
|
132
|
+
expect(subject).to eq(private_key)
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "with base 64 format" do
|
137
|
+
let(:wallet_key) { "OWeKFOyoR5s8WNzSWlyUvnaDiegjQ1xN38rrE1GasQ4=" }
|
138
|
+
|
139
|
+
it "converts to correct bytes" do
|
140
|
+
expect(subject).to eq(private_key)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "verify_message!" do
|
146
|
+
subject { DigiByteCigs.verify_message!(address, signature, message, :network => network) }
|
147
|
+
|
148
|
+
context "with valid data" do
|
149
|
+
it "verifies valid message" do
|
150
|
+
expect(subject).to be_nil
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "with invalid address" do
|
155
|
+
let(:address) { "invalid" }
|
156
|
+
|
157
|
+
it "raises ::DigiByteCigs::Error" do
|
158
|
+
expect { subject }.to raise_error(::DigiByteCigs::Error, "Incorrect address or message for signature.")
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
context "with invalid signature" do
|
163
|
+
let(:signature) { "invalid" }
|
164
|
+
|
165
|
+
it "raises ::DigiByteCigs::Error" do
|
166
|
+
expect { subject }.to raise_error(::DigiByteCigs::Error, "Bad signature length")
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "with invalid message" do
|
171
|
+
let(:message) { "invalid" }
|
172
|
+
|
173
|
+
it "raises ::DigiByteCigs::Error" do
|
174
|
+
expect { subject }.to raise_error(::DigiByteCigs::Error, "Incorrect address or message for signature.")
|
175
|
+
end
|
176
|
+
end
|
177
|
+
|
178
|
+
context "with testnet" do
|
179
|
+
use_testnet
|
180
|
+
|
181
|
+
context "with valid data" do
|
182
|
+
it "verifies valid message" do
|
183
|
+
expect(subject).to be_nil
|
184
|
+
end
|
185
|
+
end
|
186
|
+
end
|
187
|
+
end
|
188
|
+
|
189
|
+
describe "verify_message" do
|
190
|
+
subject { DigiByteCigs.verify_message(address, signature, message) }
|
191
|
+
|
192
|
+
context "with valid data" do
|
193
|
+
it "returns true" do
|
194
|
+
expect(subject).to be_true
|
195
|
+
end
|
196
|
+
end
|
197
|
+
|
198
|
+
context "with invalid data" do
|
199
|
+
let(:address) { "invalid" }
|
200
|
+
|
201
|
+
it "returns false" do
|
202
|
+
expect(subject).to be_false
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
|
207
|
+
describe "get_signature_address!" do
|
208
|
+
subject { DigiByteCigs.get_signature_address!(signature, message, :network => network) }
|
209
|
+
|
210
|
+
context "with valid data" do
|
211
|
+
it "returns correct address" do
|
212
|
+
expect(subject).to eq(address)
|
213
|
+
end
|
214
|
+
end
|
215
|
+
|
216
|
+
context "with invalid signature" do
|
217
|
+
let(:signature) { "invalid" }
|
218
|
+
|
219
|
+
it "raises ::DigiByteCigs::Error" do
|
220
|
+
expect { subject }.to raise_error(::DigiByteCigs::Error, "Bad signature length")
|
221
|
+
end
|
222
|
+
end
|
223
|
+
|
224
|
+
context "with invalid message" do
|
225
|
+
let(:message) { "invalid" }
|
226
|
+
|
227
|
+
it "returns wrong address" do
|
228
|
+
expect(subject).not_to eq(address)
|
229
|
+
end
|
230
|
+
end
|
231
|
+
|
232
|
+
context "with testnet" do
|
233
|
+
use_testnet
|
234
|
+
|
235
|
+
context "with valid data" do
|
236
|
+
it "returns valid address" do
|
237
|
+
expect(subject).to eq(address)
|
238
|
+
end
|
239
|
+
end
|
240
|
+
end
|
241
|
+
end
|
242
|
+
|
243
|
+
describe "get_signature_address" do
|
244
|
+
subject { DigiByteCigs.get_signature_address(signature, message) }
|
245
|
+
|
246
|
+
context "with valid data" do
|
247
|
+
it "returns true" do
|
248
|
+
expect(subject).to eq(address)
|
249
|
+
end
|
250
|
+
end
|
251
|
+
end
|
252
|
+
|
253
|
+
|
254
|
+
end
|
data/spec/spec_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: digibyte-cigs
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vertbase
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2019-03-05 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: rspec
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 2.13.0
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.13.0
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.0.4
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.0.4
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- dev@vertbase.com
|
44
|
+
executables:
|
45
|
+
- digibyte-cigs
|
46
|
+
extensions: []
|
47
|
+
extra_rdoc_files: []
|
48
|
+
files:
|
49
|
+
- ".gitignore"
|
50
|
+
- Gemfile
|
51
|
+
- Gemfile.lock
|
52
|
+
- LICENSE.txt
|
53
|
+
- README.md
|
54
|
+
- Rakefile
|
55
|
+
- bin/digibyte-cigs
|
56
|
+
- digibyte-cigs.gemspec
|
57
|
+
- lib/digibyte-cigs.rb
|
58
|
+
- lib/digibyte_cigs.rb
|
59
|
+
- lib/digibyte_cigs/base_58.rb
|
60
|
+
- lib/digibyte_cigs/compact_int.rb
|
61
|
+
- lib/digibyte_cigs/crypto_helper.rb
|
62
|
+
- lib/digibyte_cigs/curve_fp.rb
|
63
|
+
- lib/digibyte_cigs/ec_key.rb
|
64
|
+
- lib/digibyte_cigs/error.rb
|
65
|
+
- lib/digibyte_cigs/point.rb
|
66
|
+
- lib/digibyte_cigs/private_key.rb
|
67
|
+
- lib/digibyte_cigs/public_key.rb
|
68
|
+
- lib/digibyte_cigs/signature.rb
|
69
|
+
- lib/digibyte_cigs/version.rb
|
70
|
+
- misc/bitaddress.org.html
|
71
|
+
- misc/jasvet.py
|
72
|
+
- spec/digibyte_cigs/base_58_spec.rb
|
73
|
+
- spec/digibyte_cigs/compact_int_spec.rb
|
74
|
+
- spec/digibyte_cigs_spec.rb
|
75
|
+
- spec/spec_helper.rb
|
76
|
+
homepage: https://github.com/vertbase/digibyte-cigs
|
77
|
+
licenses: []
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project: digibyte-cigs
|
95
|
+
rubygems_version: 2.6.4
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: Create and Verify DigiByte Signatures
|
99
|
+
test_files:
|
100
|
+
- spec/digibyte_cigs/base_58_spec.rb
|
101
|
+
- spec/digibyte_cigs/compact_int_spec.rb
|
102
|
+
- spec/digibyte_cigs_spec.rb
|
103
|
+
- spec/spec_helper.rb
|