bitcoin-addrgen 0.0.2 → 0.1.0
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.
- data/Gemfile.lock +1 -1
- data/lib/bitcoin_addrgen/addrgen.rb +26 -0
- data/lib/bitcoin_addrgen/version.rb +1 -1
- data/spec/bitcoin_addrgen_spec.rb +25 -6
- metadata +2 -2
data/Gemfile.lock
CHANGED
@@ -32,6 +32,7 @@ module GMP
|
|
32
32
|
attach_function :__gmpz_add, [:pointer, :pointer, :pointer], :void
|
33
33
|
attach_function :__gmpz_add_ui, [:pointer, :pointer, :ulong], :void
|
34
34
|
attach_function :__gmpz_and, [:pointer, :pointer, :pointer], :void
|
35
|
+
attach_function :__gmpz_clear, [:pointer], :void
|
35
36
|
attach_function :__gmpz_cmp, [:pointer, :pointer], :int
|
36
37
|
attach_function :__gmpz_cmp_si, [:pointer, :long], :int
|
37
38
|
attach_function :__gmpz_fdiv_q_ui, [:pointer, :pointer, :ulong], :ulong
|
@@ -42,10 +43,25 @@ module GMP
|
|
42
43
|
attach_function :__gmpz_neg, [:pointer, :pointer], :void
|
43
44
|
attach_function :__gmpz_pow_ui, [:pointer, :pointer, :ulong], :void
|
44
45
|
attach_function :__gmpz_sub, [:pointer, :pointer, :pointer], :void
|
46
|
+
|
47
|
+
@ptrlist = []
|
48
|
+
|
49
|
+
def self.collect(ptr)
|
50
|
+
@ptrlist << ptr
|
51
|
+
end
|
52
|
+
|
53
|
+
def self.collect_clear
|
54
|
+
@ptrlist.each { |p|
|
55
|
+
GMP::__gmpz_clear(p)
|
56
|
+
}
|
57
|
+
@ptrlist = []
|
58
|
+
end
|
59
|
+
|
45
60
|
end
|
46
61
|
|
47
62
|
def gmp_init(str, base)
|
48
63
|
ptr = FFI::MemoryPointer.new :char, 16
|
64
|
+
GMP::collect(ptr)
|
49
65
|
GMP::__gmpz_init_set_str(ptr, str, base)
|
50
66
|
ptr
|
51
67
|
end
|
@@ -56,6 +72,7 @@ end
|
|
56
72
|
|
57
73
|
def gmp_add(a, b)
|
58
74
|
ptr = FFI::MemoryPointer.new :char, 16
|
75
|
+
GMP::collect(ptr)
|
59
76
|
if a.instance_of? Fixnum
|
60
77
|
GMP::__gmpz_add_ui(ptr, b, a)
|
61
78
|
elsif b.instance_of? Fixnum
|
@@ -68,6 +85,7 @@ end
|
|
68
85
|
|
69
86
|
def gmp_and(a, b)
|
70
87
|
ptr = FFI::MemoryPointer.new :char, 16
|
88
|
+
GMP::collect(ptr)
|
71
89
|
GMP::__gmpz_and(ptr, a, b)
|
72
90
|
ptr
|
73
91
|
end
|
@@ -86,24 +104,28 @@ end
|
|
86
104
|
|
87
105
|
def gmp_div(a, b)
|
88
106
|
ptr = FFI::MemoryPointer.new :char, 16
|
107
|
+
GMP::collect(ptr)
|
89
108
|
GMP::__gmpz_fdiv_q_ui(ptr, a, b)
|
90
109
|
ptr
|
91
110
|
end
|
92
111
|
|
93
112
|
def gmp_invert(a, b)
|
94
113
|
ptr = FFI::MemoryPointer.new :char, 16
|
114
|
+
GMP::collect(ptr)
|
95
115
|
GMP::__gmpz_invert(ptr, a, b)
|
96
116
|
ptr
|
97
117
|
end
|
98
118
|
|
99
119
|
def gmp_mod(a, b)
|
100
120
|
ptr = FFI::MemoryPointer.new :char, 16
|
121
|
+
GMP::collect(ptr)
|
101
122
|
GMP::__gmpz_fdiv_r(ptr, a, b)
|
102
123
|
ptr
|
103
124
|
end
|
104
125
|
|
105
126
|
def gmp_mul(a, b)
|
106
127
|
ptr = FFI::MemoryPointer.new :char, 16
|
128
|
+
GMP::collect(ptr)
|
107
129
|
if a.instance_of? Fixnum
|
108
130
|
GMP::__gmpz_mul_si(ptr, b, a)
|
109
131
|
elsif b.instance_of? Fixnum
|
@@ -116,18 +138,21 @@ end
|
|
116
138
|
|
117
139
|
def gmp_neg(a)
|
118
140
|
ptr = FFI::MemoryPointer.new :char, 16
|
141
|
+
GMP::collect(ptr)
|
119
142
|
GMP::__gmpz_neg(ptr, a)
|
120
143
|
ptr
|
121
144
|
end
|
122
145
|
|
123
146
|
def gmp_pow(a, b)
|
124
147
|
ptr = FFI::MemoryPointer.new :char, 16
|
148
|
+
GMP::collect(ptr)
|
125
149
|
GMP::__gmpz_pow_ui(ptr, a, b)
|
126
150
|
ptr
|
127
151
|
end
|
128
152
|
|
129
153
|
def gmp_sub(a, b)
|
130
154
|
ptr = FFI::MemoryPointer.new :char, 16
|
155
|
+
GMP::collect(ptr)
|
131
156
|
GMP::__gmpz_sub(ptr, a, b)
|
132
157
|
ptr
|
133
158
|
end
|
@@ -298,6 +323,7 @@ module BitcoinAddrgen
|
|
298
323
|
n += 2
|
299
324
|
end
|
300
325
|
|
326
|
+
GMP::collect_clear
|
301
327
|
pad + num
|
302
328
|
end
|
303
329
|
end
|
@@ -9,28 +9,47 @@ describe BitcoinAddrgen do
|
|
9
9
|
BitcoinAddrgen.generate_public_address(master_public_key, address_index)
|
10
10
|
end
|
11
11
|
|
12
|
-
context "with
|
12
|
+
context "with address index 0" do
|
13
13
|
let(:address_index) { 0 }
|
14
|
-
|
15
14
|
it "generates the correct public address" do
|
16
15
|
expect(subject).to eq('13EfJ1hQBGMBbEwvPa3MLeH6buBhiMSfCC')
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
|
-
context "with
|
19
|
+
context "with address index 6" do
|
21
20
|
let(:address_index) { 6 }
|
22
|
-
|
23
21
|
it "generates the correct public address" do
|
24
22
|
expect(subject).to eq('1jmA5ySdFz7cDwWb15rWQe63ZUo8spiBa')
|
25
23
|
end
|
26
24
|
end
|
27
25
|
|
28
|
-
context "with
|
26
|
+
context "with address index 9" do
|
29
27
|
let(:address_index) { 9 }
|
30
|
-
|
31
28
|
it "generates the correct public address" do
|
32
29
|
expect(subject).to eq('1J7yTE8Cm9fMV9nqCjnM6kTTzTkksVic98')
|
33
30
|
end
|
34
31
|
end
|
32
|
+
|
33
|
+
context "with address index 100" do
|
34
|
+
let(:address_index) { 100 }
|
35
|
+
it "generates the correct public address" do
|
36
|
+
expect(subject).to eq('1LNUmaHWMybREGszq8wiDTULJR3tvsjx7')
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with address index 65537" do
|
41
|
+
let(:address_index) { 65537 }
|
42
|
+
it "generates the correct public address" do
|
43
|
+
expect(subject).to eq('1JnjQQ5LcMDYDLNd31bEU2L5wZ9fipvEQ6')
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
context "with address index 4294967296" do
|
48
|
+
let(:address_index) { 4294967296 }
|
49
|
+
it "generates the correct public address" do
|
50
|
+
expect(subject).to eq('1KJwuVF7hm7EoT1AYJas2WM3yodCzsEhAQ')
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
35
54
|
end
|
36
55
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bitcoin-addrgen
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-08-30 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|