stellar-base 0.22.0 → 0.23.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (117) hide show
  1. checksums.yaml +4 -4
  2. data/{LICENSE.txt → LICENSE} +0 -0
  3. data/README.md +2 -3
  4. data/generated/stellar-base-generated.rb +10 -1
  5. data/generated/stellar/allow_trust_op.rb +3 -2
  6. data/generated/stellar/authenticated_message.rb +4 -4
  7. data/generated/stellar/authenticated_message/v0.rb +4 -4
  8. data/generated/stellar/change_trust_result_code.rb +1 -1
  9. data/generated/stellar/crypto_key_type.rb +8 -4
  10. data/generated/stellar/curve25519_public.rb +1 -1
  11. data/generated/stellar/curve25519_secret.rb +1 -1
  12. data/generated/stellar/envelope_type.rb +9 -5
  13. data/generated/stellar/fee_bump_transaction.rb +39 -0
  14. data/generated/stellar/fee_bump_transaction/ext.rb +24 -0
  15. data/generated/stellar/fee_bump_transaction/inner_tx.rb +25 -0
  16. data/generated/stellar/fee_bump_transaction_envelope.rb +22 -0
  17. data/generated/stellar/hmac_sha256_key.rb +1 -1
  18. data/generated/stellar/hmac_sha256_mac.rb +1 -1
  19. data/generated/stellar/inner_transaction_result.rb +56 -0
  20. data/generated/stellar/inner_transaction_result/ext.rb +24 -0
  21. data/generated/stellar/inner_transaction_result/result.rb +52 -0
  22. data/generated/stellar/inner_transaction_result_pair.rb +20 -0
  23. data/generated/stellar/ledger_close_meta.rb +1 -1
  24. data/generated/stellar/manage_buy_offer_result_code.rb +5 -4
  25. data/generated/stellar/manage_sell_offer_result_code.rb +12 -8
  26. data/generated/stellar/muxed_account.rb +35 -0
  27. data/generated/stellar/muxed_account/med25519.rb +22 -0
  28. data/generated/stellar/operation.rb +3 -3
  29. data/generated/stellar/operation/body.rb +2 -2
  30. data/generated/stellar/operation_result.rb +1 -1
  31. data/generated/stellar/operation_result/tr.rb +1 -1
  32. data/generated/stellar/operation_result_code.rb +3 -3
  33. data/generated/stellar/path_payment_strict_receive_op.rb +4 -4
  34. data/generated/stellar/path_payment_strict_receive_result_code.rb +21 -12
  35. data/generated/stellar/path_payment_strict_send_op.rb +6 -6
  36. data/generated/stellar/path_payment_strict_send_result_code.rb +20 -12
  37. data/generated/stellar/payment_op.rb +4 -4
  38. data/generated/stellar/survey_response_body.rb +2 -2
  39. data/generated/stellar/transaction.rb +2 -2
  40. data/generated/stellar/transaction_envelope.rb +17 -8
  41. data/generated/stellar/transaction_result.rb +3 -0
  42. data/generated/stellar/transaction_result/result.rb +9 -3
  43. data/generated/stellar/transaction_result_code.rb +21 -14
  44. data/generated/stellar/transaction_signature_payload.rb +3 -1
  45. data/generated/stellar/transaction_signature_payload/tagged_transaction.rb +7 -3
  46. data/generated/stellar/transaction_v0.rb +39 -0
  47. data/generated/stellar/transaction_v0/ext.rb +24 -0
  48. data/generated/stellar/transaction_v0_envelope.rb +22 -0
  49. data/generated/stellar/transaction_v1_envelope.rb +22 -0
  50. data/generated/stellar/trust_line_flags.rb +6 -2
  51. data/lib/stellar-base.rb +27 -25
  52. data/lib/stellar/account_flags.rb +2 -4
  53. data/lib/stellar/asset.rb +6 -6
  54. data/lib/stellar/base.rb +1 -1
  55. data/lib/stellar/{base/compat.rb → compat.rb} +6 -7
  56. data/lib/stellar/concerns/transaction.rb +49 -0
  57. data/lib/stellar/convert.rb +2 -2
  58. data/lib/stellar/factories.rb +1 -3
  59. data/lib/stellar/fee_bump_transaction.rb +21 -0
  60. data/lib/stellar/key_pair.rb +9 -6
  61. data/lib/stellar/networks.rb +5 -7
  62. data/lib/stellar/operation.rb +421 -416
  63. data/lib/stellar/path_payment_strict_receive_result.rb +1 -2
  64. data/lib/stellar/price.rb +2 -4
  65. data/lib/stellar/signer_key.rb +4 -8
  66. data/lib/stellar/thresholds.rb +5 -7
  67. data/lib/stellar/transaction.rb +154 -198
  68. data/lib/stellar/transaction_builder.rb +66 -23
  69. data/lib/stellar/transaction_envelope.rb +40 -8
  70. data/lib/stellar/transaction_v0.rb +39 -0
  71. data/lib/stellar/util/continued_fraction.rb +19 -19
  72. data/lib/stellar/util/strkey.rb +39 -14
  73. data/lib/stellar/{base/version.rb → version.rb} +1 -1
  74. metadata +33 -203
  75. data/.gitignore +0 -17
  76. data/.travis.yml +0 -16
  77. data/.yardopts +0 -8
  78. data/CHANGELOG.md +0 -149
  79. data/CONTRIBUTING.md +0 -48
  80. data/Gemfile +0 -9
  81. data/Guardfile +0 -5
  82. data/Rakefile +0 -4
  83. data/examples/allow_trust.rb +0 -51
  84. data/examples/create_account.rb +0 -26
  85. data/examples/low_level_transaction_post.rb +0 -46
  86. data/examples/mid_level_transaction_post.rb +0 -33
  87. data/examples/non_native_payment.rb +0 -60
  88. data/examples/offer.rb +0 -75
  89. data/examples/transaction_merge.rb +0 -23
  90. data/ruby-stellar-base.gemspec +0 -34
  91. data/spec/lib/stellar/account_flags_spec.rb +0 -19
  92. data/spec/lib/stellar/asset_spec.rb +0 -45
  93. data/spec/lib/stellar/convert_spec.rb +0 -61
  94. data/spec/lib/stellar/key_pair_spec.rb +0 -251
  95. data/spec/lib/stellar/networks_spec.rb +0 -77
  96. data/spec/lib/stellar/operation_spec.rb +0 -131
  97. data/spec/lib/stellar/path_payment_strict_receive_result_spec.rb +0 -95
  98. data/spec/lib/stellar/price_spec.rb +0 -34
  99. data/spec/lib/stellar/signer_key_spec.rb +0 -26
  100. data/spec/lib/stellar/thresholds_spec.rb +0 -62
  101. data/spec/lib/stellar/transaction_builder_spec.rb +0 -263
  102. data/spec/lib/stellar/transaction_envelope_spec.rb +0 -93
  103. data/spec/lib/stellar/transaction_spec.rb +0 -132
  104. data/spec/lib/stellar/util/strkey_spec.rb +0 -54
  105. data/spec/spec_helper.rb +0 -16
  106. data/spec/support/matchers/be_strkey.rb +0 -9
  107. data/spec/support/matchers/eq_bytes.rb +0 -5
  108. data/spec/support/matchers/have_length.rb +0 -5
  109. data/tasks/rspec.rake +0 -6
  110. data/tasks/travis.rake +0 -1
  111. data/tasks/xdr.rake +0 -45
  112. data/xdr/Stellar-SCP.x +0 -86
  113. data/xdr/Stellar-ledger-entries.x +0 -295
  114. data/xdr/Stellar-ledger.x +0 -372
  115. data/xdr/Stellar-overlay.x +0 -229
  116. data/xdr/Stellar-transaction.x +0 -901
  117. data/xdr/Stellar-types.x +0 -81
@@ -1,75 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # This is an example of using the higher level "payment" wrapper. Notice
4
- # that we are using KeyPair instead of the raw rbnacl keys and that we need
5
- # not build the entire heirarchy of xdr object manually.
6
- #
7
- # You can see where these helpers are defined in the files underneath /lib,
8
- # which is where we extend the xdrgen generated source files with our higher
9
- # level api.
10
- #
11
- # NOTE: due to the way that sequence number for a new account are set, this
12
- # example is pretty cumbersome to run. It is only used for illustrative purposes
13
- # of the flow
14
-
15
- require 'stellar-base'
16
- require 'faraday'
17
- require 'faraday_middleware'
18
-
19
- $server = Faraday.new(url: "http://localhost:39132") do |conn|
20
- conn.response :json
21
- conn.adapter Faraday.default_adapter
22
- end
23
-
24
- def submit(key, tx)
25
- b64 = tx.to_envelope(key).to_xdr(:base64)
26
- response = $server.get('tx', blob: b64)
27
- p response.body
28
- end
29
-
30
- master = Stellar::KeyPair.master
31
- destination = Stellar::KeyPair.master
32
-
33
- submit master, Stellar::Transaction.payment({
34
- account: master,
35
- destination: destination,
36
- sequence: 1,
37
- amount: [:native, 2000]
38
- })
39
-
40
- # NOTE: after this step, you need to get the sequence number for destination
41
- # Which is based off of the ledger sequence number it was funded in.
42
- gets # pause to get the account's sequence from the hayashi db
43
-
44
- destination_sequence = FILL_ME_IN
45
- # destination_sequence = 17179869185
46
-
47
- submit destination, Stellar::Transaction.change_trust({
48
- account: destination,
49
- sequence: destination_sequence,
50
- line: [:alphanum4, "USD\x00", master],
51
- limit: 1000
52
- })
53
-
54
- submit destination, Stellar::Transaction.change_trust({
55
- account: destination,
56
- sequence: destination_sequence + 1,
57
- line: [:alphanum4, "EUR\x00", master],
58
- limit: 1000
59
- })
60
-
61
- submit master, Stellar::Transaction.payment({
62
- account: master,
63
- destination: destination,
64
- sequence: destination_sequence + 2,
65
- amount: [:alphanum4, "USD\x00", master, 1000]
66
- })
67
-
68
- submit master, Stellar::Transaction.manage_offer({
69
- account: destination,
70
- sequence: destination_sequence + 3,
71
- selling: [:alphanum4, "USD\x00", usd_gateway],
72
- buying: [:alphanum4, "EUR\x00", eur_gateway],
73
- amount: 100,
74
- price: 2.0,
75
- })
@@ -1,23 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'stellar-base'
4
-
5
- master = Stellar::KeyPair.master
6
- destination = Stellar::KeyPair.master
7
-
8
- tx1 = Stellar::Transaction.payment({
9
- account: master,
10
- destination: destination,
11
- sequence: 1,
12
- amount: [:native, 20]
13
- })
14
-
15
- tx2 = Stellar::Transaction.payment({
16
- account: master,
17
- destination: destination,
18
- sequence: 2,
19
- amount: [:native, 20]
20
- })
21
-
22
- hex = tx1.merge(tx2).to_envelope(master).to_xdr(:base64)
23
- puts hex
@@ -1,34 +0,0 @@
1
- # coding: utf-8
2
- require_relative './lib/stellar/base/version'
3
-
4
- Gem::Specification.new do |spec|
5
- spec.name = "stellar-base"
6
- spec.version = Stellar::Base::VERSION
7
- spec.authors = ["Scott Fleckenstein"]
8
- spec.email = ["scott@stellar.org"]
9
- spec.summary = %q{Stellar client library: XDR}
10
- spec.homepage = "https://github.com/stellar/ruby-stellar-base"
11
- spec.license = "Apache 2.0"
12
-
13
- spec.files = `git ls-files -z`.split("\x0")
14
- spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
15
- spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
- spec.require_paths = ["generated", "lib"]
17
-
18
- spec.add_dependency "xdr", "~> 3.0.0"
19
- spec.add_dependency "digest-crc"
20
- spec.add_dependency "base32"
21
- spec.add_dependency "rbnacl", ">= 6.0"
22
- spec.add_dependency "activesupport", ">= 5.0.0"
23
-
24
- spec.add_development_dependency "bundler", "~> 2.0"
25
- spec.add_development_dependency "rake", "~> 12.0"
26
- spec.add_development_dependency "xdrgen"
27
- spec.add_development_dependency "rspec", "~> 3.1"
28
- spec.add_development_dependency "guard-rspec"
29
- spec.add_development_dependency "simplecov"
30
- spec.add_development_dependency "octokit"
31
- spec.add_development_dependency "netrc"
32
- spec.add_development_dependency "yard"
33
-
34
- end
@@ -1,19 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Stellar::AccountFlags do
4
- subject{ Stellar::AccountFlags }
5
- let(:raw) { 3 }
6
- let(:result) { subject.parse_mask raw }
7
-
8
- it "parses correctly" do
9
- expect(subject.parse_mask(1)).to eq([Stellar::AccountFlags.auth_required_flag])
10
- expect(subject.parse_mask(2)).to eq([Stellar::AccountFlags.auth_revocable_flag])
11
- expect(subject.parse_mask(3)).to eq([Stellar::AccountFlags.auth_required_flag, Stellar::AccountFlags.auth_revocable_flag])
12
- end
13
-
14
- it "makes correctly" do
15
- expect(subject.make_mask([Stellar::AccountFlags.auth_required_flag])).to eq(1)
16
- expect(subject.make_mask([Stellar::AccountFlags.auth_revocable_flag])).to eq(2)
17
- expect(subject.make_mask([Stellar::AccountFlags.auth_required_flag, Stellar::AccountFlags.auth_revocable_flag])).to eq(3)
18
- end
19
- end
@@ -1,45 +0,0 @@
1
- require "spec_helper"
2
-
3
- describe Stellar::Asset, ".native" do
4
- it "returns a asset instance whose type is 'AssetType.asset_type_native'" do
5
- expect(Stellar::Asset.native.type).to eq(Stellar::AssetType.asset_type_native)
6
- end
7
- end
8
-
9
- describe Stellar::Asset, ".alphanum4" do
10
- it "returns a asset instance whose type is 'AssetType.asset_type_credit_alphanum4'" do
11
- result = Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master)
12
- expect(result.type).to eq(Stellar::AssetType.asset_type_credit_alphanum4)
13
- end
14
-
15
- it "pads the code to 4 bytes, padding on the right and with null bytes" do
16
- result = Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master)
17
- expect(result.code).to eq("USD\x00")
18
- end
19
- end
20
-
21
- describe Stellar::Asset, ".alphanum12" do
22
- it "returns a asset instance whose type is 'AssetType.asset_type_credit_alphanum12'" do
23
- result = Stellar::Asset.alphanum12("USD", Stellar::KeyPair.master)
24
- expect(result.type).to eq(Stellar::AssetType.asset_type_credit_alphanum12)
25
- end
26
-
27
- it "pads the code to 12 bytes, padding on the right and with null bytes" do
28
- result = Stellar::Asset.alphanum12("USD", Stellar::KeyPair.master)
29
- expect(result.code).to eq("USD\x00\x00\x00\x00\x00\x00\x00\x00\x00")
30
- end
31
- end
32
-
33
- describe Stellar::Asset, "#code" do
34
- it "returns the asset_code for either alphanum4 or alphanum12 assets" do
35
- a4 = Stellar::Asset.alphanum4("USD", Stellar::KeyPair.master)
36
- a12 = Stellar::Asset.alphanum12("USD", Stellar::KeyPair.master)
37
-
38
- expect(a4.code.strip).to eq("USD")
39
- expect(a12.code.strip).to eq("USD")
40
- end
41
-
42
- it "raises an error when called on a native asset" do
43
- expect{ Stellar::Asset.native.code }.to raise_error(RuntimeError)
44
- end
45
- end
@@ -1,61 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Stellar::Convert do
4
- subject{ Stellar::Convert }
5
- let(:raw) { "\x01\x02\x03\x04" }
6
- let(:hex) { "01020304" }
7
- let(:base64){ "AQIDBA==" }
8
-
9
- describe "hex encoding" do
10
- it "decodes" do
11
- expect(subject.from_hex(hex)).to eq(raw)
12
- end
13
-
14
- it "encodes" do
15
- expect(subject.to_hex(raw)).to eq(hex)
16
- end
17
-
18
- it "round trips" do
19
- raw1 = subject.from_hex(hex)
20
- hex1 = subject.to_hex(raw1)
21
- expect(hex1).to eq(hex)
22
-
23
-
24
- hex2 = subject.to_hex(raw)
25
- raw2 = subject.from_hex(hex2)
26
- expect(raw2).to eq(raw)
27
- end
28
- end
29
-
30
- describe "base64 encoding" do
31
- it "decodes" do
32
- expect(subject.from_base64(base64)).to eq(raw)
33
- end
34
-
35
- it "encodes" do
36
- expect(subject.to_base64(raw)).to eq(base64)
37
- end
38
-
39
- it "round trips" do
40
- raw1 = subject.from_base64(base64)
41
- base641 = subject.to_base64(raw1)
42
- expect(base641).to eq(base64)
43
-
44
-
45
- base642 = subject.to_base64(raw)
46
- raw2 = subject.from_base64(base642)
47
- expect(raw2).to eq(raw)
48
- end
49
- end
50
-
51
-
52
- describe "#pk_to_address" do
53
- let(:pk_raw){ "\x00" * 32 }
54
- let(:pk_account_id){ Stellar::AccountID.new(:public_key_type_ed25519, pk_raw)}
55
-
56
- it "converts a Stellar::AccountID into an address using StrKey.check_encode(:account_id)" do
57
- address = Stellar::Util::StrKey.check_encode(:account_id, pk_raw)
58
- expect(subject.pk_to_address(pk_account_id)).to eql(address)
59
- end
60
- end
61
- end
@@ -1,251 +0,0 @@
1
- # encoding: utf-8
2
- require "spec_helper"
3
-
4
- describe Stellar::KeyPair do
5
-
6
- describe ".from_seed" do
7
- subject{ Stellar::KeyPair.from_seed(seed) }
8
-
9
- context "when provided a strkey encoded seed" do
10
- let(:seed){ "SBDA4J4PYZJEXWDTHFZBIGFVF2745BTKDKADWDQF72QXP55BP6XOV3B6" }
11
- it { should be_a(Stellar::KeyPair) }
12
- end
13
-
14
- context "provided value is not strkey encoded" do
15
- let(:seed){ "allmylifemyhearthasbeensearching" }
16
- it { expect{ subject }.to raise_error(ArgumentError) }
17
- end
18
-
19
- context "provided value is not strkey encoded as a seed" do
20
- let(:raw_seed){ "allmylifemyhearthasbeensearching" }
21
- let(:seed){ Stellar::Util::StrKey.check_encode(:account_id, raw_seed) }
22
- it { expect{ subject }.to raise_error(ArgumentError) }
23
- end
24
- end
25
-
26
- describe ".from_raw_seed" do
27
- subject{ Stellar::KeyPair.from_raw_seed(raw_seed) }
28
-
29
- context "when the provided value is a 32-byte string" do
30
- let(:raw_seed){ "allmylifemyhearthasbeensearching" }
31
- it { should be_a(Stellar::KeyPair) }
32
- end
33
-
34
- context "when the provided value is < 32-byte string" do
35
- let(:raw_seed){ "\xFF" * 31 }
36
- it { expect{ subject }.to raise_error(ArgumentError) }
37
- end
38
-
39
- context "when the provided value is > 32-byte string" do
40
- let(:raw_seed){ "\xFF" * 33 }
41
- it { expect{ subject }.to raise_error(ArgumentError) }
42
- end
43
-
44
- context "when the provided value is a 32 character, but > 32 byte string (i.e. multi-byte characters)" do
45
- let(:raw_seed){ "ü" + ("\x00" * 31) }
46
- it { expect{ subject }.to raise_error(ArgumentError) }
47
- end
48
- end
49
-
50
- describe ".from_public_key" do
51
- subject{ Stellar::KeyPair.from_public_key(key) }
52
-
53
- context "when the provided value is a 32-byte string" do
54
- let(:key){ "\xFF" * 32 }
55
- it { should be_a(Stellar::KeyPair) }
56
- end
57
-
58
- context "when the provided value is < 32-byte string" do
59
- let(:key){ "\xFF" * 31 }
60
- it { expect{ subject }.to raise_error(ArgumentError) }
61
- end
62
-
63
- context "when the provided value is > 32-byte string" do
64
- let(:key){ "\xFF" * 33 }
65
- it { expect{ subject }.to raise_error(ArgumentError) }
66
- end
67
-
68
- context "when the provided value is a 32 character, but > 32 byte string (i.e. multi-byte characters)" do
69
- let(:key){ "ü" + ("\x00" * 31) }
70
- it { expect{ subject }.to raise_error(ArgumentError) }
71
- end
72
- end
73
-
74
- describe ".from_address" do
75
- subject{ Stellar::KeyPair.from_address(address) }
76
-
77
- context "when provided a strkey encoded account_id" do
78
- let(:address){ "GBRAINV4XDXEINVTNN53GOIGTN4B3BK65N6Q2ZBOMXHGHT347OQVNYZQ" }
79
- it { should be_a(Stellar::KeyPair) }
80
- end
81
-
82
- context "provided value is not strkey encoded" do
83
- let(:address){ "some address" }
84
- it { expect{ subject }.to raise_error(ArgumentError) }
85
- end
86
-
87
- context "provided value is not strkey encoded as an account_id" do
88
- let(:public_key){ "\xFF" * 32 }
89
- let(:address){ Stellar::Util::StrKey.check_encode(:seed, public_key) }
90
- it { expect{ subject }.to raise_error(ArgumentError) }
91
- end
92
-
93
- end
94
-
95
- describe ".random" do
96
- subject{ Stellar::KeyPair.random }
97
-
98
- it "returns a new KeyPair every time" do
99
- other = Stellar::KeyPair.random
100
- expect(subject.raw_seed == other.raw_seed).to eq(false)
101
- end
102
- end
103
-
104
- describe ".master" do
105
- subject{ Stellar::KeyPair.master }
106
-
107
- it "returns a keypair whose raw_seed is the current_network_id" do
108
- expect(subject.raw_seed).to eql(Stellar.current_network_id)
109
- end
110
- end
111
-
112
- describe "#raw_public_key" do
113
- let(:key_pair){ Stellar::KeyPair.random }
114
- subject{ key_pair.raw_public_key }
115
-
116
- it { should be_a(String) }
117
- it { should have_length(32) }
118
- end
119
-
120
- describe "#public_key" do
121
- let(:key_pair){ Stellar::KeyPair.random }
122
- subject{ key_pair.public_key }
123
-
124
- it { should be_a(Stellar::PublicKey) }
125
- end
126
-
127
- describe "#account_id" do
128
- let(:key_pair){ Stellar::KeyPair.random }
129
- subject{ key_pair.account_id }
130
-
131
- it { should be_a(Stellar::AccountID) }
132
-
133
- it "contains the public key" do
134
- expect(subject.ed25519!).to eql(key_pair.raw_public_key)
135
- end
136
- end
137
-
138
- describe "#signer_key" do
139
- let(:key_pair){ Stellar::KeyPair.random }
140
- subject{ key_pair.signer_key }
141
-
142
- it { should be_a(Stellar::SignerKey) }
143
-
144
- it "contains the public key" do
145
- expect(subject.ed25519!).to eql(key_pair.raw_public_key)
146
- end
147
- end
148
-
149
- describe "#raw_seed" do
150
- let(:key_pair){ Stellar::KeyPair.random }
151
- subject{ key_pair.raw_seed }
152
-
153
- it { should be_a(String) }
154
- it { should have_length(32) }
155
- end
156
-
157
- describe "#signature_hint" do
158
- let(:key_pair){ Stellar::KeyPair.random }
159
- subject{ key_pair.signature_hint }
160
-
161
- it { should be_a(String) }
162
- it { should have_length(4) }
163
-
164
- it "is the last 4 bytes of the encoded account_id" do
165
- expected = key_pair.account_id.to_xdr[-4..-1]
166
- expect(subject).to eql(expected)
167
- end
168
- end
169
-
170
- describe "#address" do
171
- let(:key_pair){ Stellar::KeyPair.random }
172
- subject{ key_pair.address }
173
- it{ should be_strkey(:account_id)}
174
- end
175
-
176
- describe "#seed" do
177
- let(:key_pair){ Stellar::KeyPair.random }
178
- subject{ key_pair.seed }
179
- it{ should be_strkey(:seed)}
180
- end
181
-
182
-
183
-
184
- describe "#sign" do
185
- let(:message) { "hello" }
186
- subject{ key_pair.sign(message) }
187
-
188
- context "when the key_pair has no private key" do
189
- let(:key_pair){ Stellar::KeyPair.from_public_key("\x00" * 32)}
190
-
191
- it{ expect{ subject }.to raise_error("no private key") }
192
- end
193
-
194
- context "when the key_pair has both public/private keys" do
195
- let(:key_pair){ Stellar::KeyPair.from_raw_seed("\x00" * 32)}
196
-
197
- it { should have_length(64) }
198
-
199
- it "should be a ed25519 signature" do
200
- verification = key_pair.rbnacl_verify_key.verify(subject, message)
201
- expect(verification).to be_truthy
202
- end
203
-
204
- context "when the message is nil" do
205
- let(:message){ nil }
206
- it { expect{subject}.to raise_error(TypeError) }
207
- end
208
- end
209
- end
210
-
211
- describe "#verify" do
212
- let(:key_pair) { Stellar::KeyPair.random }
213
- let(:message) { "hello" }
214
- subject { key_pair.verify(signature, message) }
215
-
216
- context "when the signature is correct" do
217
- let(:signature) { key_pair.sign(message) }
218
- it{ should be_truthy }
219
- end
220
-
221
- context "when the signature is incorrect" do
222
- let(:signature) { key_pair.sign("some other message") }
223
- it{ should be_falsey }
224
- end
225
-
226
- context "when the signature is invalid" do
227
- let(:signature) { "food" }
228
- it{ should be_falsey }
229
- end
230
-
231
- context "when the signature is from a different key" do
232
- let(:signature) { Stellar::KeyPair.random.sign(message) }
233
- it{ should be_falsey }
234
- end
235
-
236
- end
237
-
238
- describe "#sign?" do
239
- subject{ key_pair.sign? }
240
-
241
- context "when the key_pair has no private key" do
242
- let(:key_pair){ Stellar::KeyPair.from_public_key("\x00" * 32)}
243
- it{ should eq(false) }
244
- end
245
-
246
- context "when the key_pair has both public/private keys" do
247
- let(:key_pair){ Stellar::KeyPair.from_raw_seed("\x00" * 32)}
248
- it{ should eq(true) }
249
- end
250
- end
251
- end