stellar-base 0.20.0 → 0.23.0.rc2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (136) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +35 -21
  3. data/{LICENSE.txt → LICENSE} +0 -0
  4. data/README.md +2 -3
  5. data/generated/stellar-base-generated.rb +31 -4
  6. data/generated/stellar/allow_trust_op.rb +3 -2
  7. data/generated/stellar/authenticated_message.rb +4 -4
  8. data/generated/stellar/authenticated_message/v0.rb +4 -4
  9. data/generated/stellar/change_trust_result_code.rb +1 -1
  10. data/generated/stellar/crypto_key_type.rb +8 -4
  11. data/generated/stellar/curve25519_public.rb +1 -1
  12. data/generated/stellar/curve25519_secret.rb +1 -1
  13. data/generated/stellar/envelope_type.rb +9 -5
  14. data/generated/stellar/fee_bump_transaction.rb +39 -0
  15. data/generated/stellar/fee_bump_transaction/ext.rb +24 -0
  16. data/generated/stellar/fee_bump_transaction/inner_tx.rb +25 -0
  17. data/generated/stellar/fee_bump_transaction_envelope.rb +22 -0
  18. data/generated/stellar/hmac_sha256_key.rb +1 -1
  19. data/generated/stellar/hmac_sha256_mac.rb +1 -1
  20. data/generated/stellar/inner_transaction_result.rb +56 -0
  21. data/generated/stellar/inner_transaction_result/ext.rb +24 -0
  22. data/generated/stellar/inner_transaction_result/result.rb +52 -0
  23. data/generated/stellar/inner_transaction_result_pair.rb +20 -0
  24. data/generated/stellar/ledger_close_meta.rb +23 -0
  25. data/generated/stellar/ledger_close_meta_v0.rb +35 -0
  26. data/generated/stellar/manage_buy_offer_result_code.rb +5 -4
  27. data/generated/stellar/manage_sell_offer_result_code.rb +12 -8
  28. data/generated/stellar/message_type.rb +6 -1
  29. data/generated/stellar/muxed_account.rb +35 -0
  30. data/generated/stellar/muxed_account/med25519.rb +22 -0
  31. data/generated/stellar/operation.rb +7 -5
  32. data/generated/stellar/operation/body.rb +31 -27
  33. data/generated/stellar/operation_result.rb +5 -3
  34. data/generated/stellar/operation_result/tr.rb +33 -29
  35. data/generated/stellar/operation_result_code.rb +3 -3
  36. data/generated/stellar/operation_type.rb +17 -15
  37. data/generated/stellar/{path_payment_op.rb → path_payment_strict_receive_op.rb} +6 -6
  38. data/generated/stellar/path_payment_strict_receive_result.rb +38 -0
  39. data/generated/stellar/path_payment_strict_receive_result/success.rb +22 -0
  40. data/generated/stellar/path_payment_strict_receive_result_code.rb +56 -0
  41. data/generated/stellar/path_payment_strict_send_op.rb +32 -0
  42. data/generated/stellar/{path_payment_result.rb → path_payment_strict_send_result.rb} +7 -7
  43. data/generated/stellar/{path_payment_result → path_payment_strict_send_result}/success.rb +1 -1
  44. data/generated/stellar/path_payment_strict_send_result_code.rb +55 -0
  45. data/generated/stellar/payment_op.rb +4 -4
  46. data/generated/stellar/peer_stats.rb +48 -0
  47. data/generated/stellar/signed_survey_request_message.rb +20 -0
  48. data/generated/stellar/signed_survey_response_message.rb +20 -0
  49. data/generated/stellar/stellar_message.rb +22 -12
  50. data/generated/stellar/survey_message_command_type.rb +20 -0
  51. data/generated/stellar/survey_request_message.rb +26 -0
  52. data/generated/stellar/survey_response_body.rb +23 -0
  53. data/generated/stellar/survey_response_message.rb +26 -0
  54. data/generated/stellar/topology_response_body.rb +25 -0
  55. data/generated/stellar/transaction.rb +2 -2
  56. data/generated/stellar/transaction_envelope.rb +17 -8
  57. data/generated/stellar/transaction_meta.rb +4 -0
  58. data/generated/stellar/transaction_meta_v2.rb +24 -0
  59. data/generated/stellar/transaction_result.rb +3 -0
  60. data/generated/stellar/transaction_result/result.rb +9 -3
  61. data/generated/stellar/transaction_result_code.rb +21 -14
  62. data/generated/stellar/transaction_result_meta.rb +22 -0
  63. data/generated/stellar/transaction_signature_payload.rb +3 -1
  64. data/generated/stellar/transaction_signature_payload/tagged_transaction.rb +7 -3
  65. data/generated/stellar/transaction_v0.rb +39 -0
  66. data/generated/stellar/transaction_v0/ext.rb +24 -0
  67. data/generated/stellar/transaction_v0_envelope.rb +22 -0
  68. data/generated/stellar/transaction_v1_envelope.rb +22 -0
  69. data/generated/stellar/trust_line_flags.rb +6 -2
  70. data/generated/stellar/upgrade_entry_meta.rb +20 -0
  71. data/lib/stellar-base.rb +27 -24
  72. data/lib/stellar/account_flags.rb +2 -4
  73. data/lib/stellar/asset.rb +6 -6
  74. data/lib/stellar/base.rb +1 -1
  75. data/lib/stellar/{base/compat.rb → compat.rb} +6 -7
  76. data/lib/stellar/concerns/transaction.rb +49 -0
  77. data/lib/stellar/convert.rb +2 -2
  78. data/lib/stellar/factories.rb +1 -3
  79. data/lib/stellar/fee_bump_transaction.rb +21 -0
  80. data/lib/stellar/key_pair.rb +9 -6
  81. data/lib/stellar/networks.rb +5 -7
  82. data/lib/stellar/operation.rb +427 -336
  83. data/lib/stellar/{path_payment_result.rb → path_payment_strict_receive_result.rb} +2 -3
  84. data/lib/stellar/price.rb +2 -4
  85. data/lib/stellar/signer_key.rb +4 -8
  86. data/lib/stellar/thresholds.rb +5 -7
  87. data/lib/stellar/transaction.rb +154 -175
  88. data/lib/stellar/transaction_builder.rb +149 -0
  89. data/lib/stellar/transaction_envelope.rb +40 -8
  90. data/lib/stellar/transaction_v0.rb +39 -0
  91. data/lib/stellar/util/continued_fraction.rb +19 -19
  92. data/lib/stellar/util/strkey.rb +39 -14
  93. data/lib/stellar/{base/version.rb → version.rb} +1 -1
  94. metadata +61 -211
  95. data/.gitignore +0 -17
  96. data/.travis.yml +0 -16
  97. data/.yardopts +0 -8
  98. data/CONTRIBUTING.md +0 -48
  99. data/Gemfile +0 -15
  100. data/Guardfile +0 -5
  101. data/Rakefile +0 -4
  102. data/examples/allow_trust.rb +0 -51
  103. data/examples/create_account.rb +0 -26
  104. data/examples/low_level_transaction_post.rb +0 -46
  105. data/examples/mid_level_transaction_post.rb +0 -33
  106. data/examples/non_native_payment.rb +0 -60
  107. data/examples/offer.rb +0 -75
  108. data/examples/transaction_merge.rb +0 -23
  109. data/generated/stellar/path_payment_result_code.rb +0 -47
  110. data/ruby-stellar-base.gemspec +0 -34
  111. data/spec/lib/stellar/account_flags_spec.rb +0 -19
  112. data/spec/lib/stellar/asset_spec.rb +0 -45
  113. data/spec/lib/stellar/convert_spec.rb +0 -61
  114. data/spec/lib/stellar/key_pair_spec.rb +0 -251
  115. data/spec/lib/stellar/networks_spec.rb +0 -77
  116. data/spec/lib/stellar/operation_spec.rb +0 -71
  117. data/spec/lib/stellar/path_payment_result_spec.rb +0 -95
  118. data/spec/lib/stellar/price_spec.rb +0 -34
  119. data/spec/lib/stellar/signer_key_spec.rb +0 -26
  120. data/spec/lib/stellar/thresholds_spec.rb +0 -62
  121. data/spec/lib/stellar/transaction_envelope_spec.rb +0 -93
  122. data/spec/lib/stellar/transaction_spec.rb +0 -100
  123. data/spec/lib/stellar/util/strkey_spec.rb +0 -54
  124. data/spec/spec_helper.rb +0 -16
  125. data/spec/support/matchers/be_strkey.rb +0 -9
  126. data/spec/support/matchers/eq_bytes.rb +0 -5
  127. data/spec/support/matchers/have_length.rb +0 -5
  128. data/tasks/rspec.rake +0 -6
  129. data/tasks/travis.rake +0 -1
  130. data/tasks/xdr.rake +0 -45
  131. data/xdr/Stellar-SCP.x +0 -86
  132. data/xdr/Stellar-ledger-entries.x +0 -295
  133. data/xdr/Stellar-ledger.x +0 -318
  134. data/xdr/Stellar-overlay.x +0 -146
  135. data/xdr/Stellar-transaction.x +0 -834
  136. data/xdr/Stellar-types.x +0 -81
@@ -1,47 +0,0 @@
1
- # This code was automatically generated using xdrgen
2
- # DO NOT EDIT or your changes may be overwritten
3
-
4
- require 'xdr'
5
-
6
- # === xdr source ============================================================
7
- #
8
- # enum PathPaymentResultCode
9
- # {
10
- # // codes considered as "success" for the operation
11
- # PATH_PAYMENT_SUCCESS = 0, // success
12
- #
13
- # // codes considered as "failure" for the operation
14
- # PATH_PAYMENT_MALFORMED = -1, // bad input
15
- # PATH_PAYMENT_UNDERFUNDED = -2, // not enough funds in source account
16
- # PATH_PAYMENT_SRC_NO_TRUST = -3, // no trust line on source account
17
- # PATH_PAYMENT_SRC_NOT_AUTHORIZED = -4, // source not authorized to transfer
18
- # PATH_PAYMENT_NO_DESTINATION = -5, // destination account does not exist
19
- # PATH_PAYMENT_NO_TRUST = -6, // dest missing a trust line for asset
20
- # PATH_PAYMENT_NOT_AUTHORIZED = -7, // dest not authorized to hold asset
21
- # PATH_PAYMENT_LINE_FULL = -8, // dest would go above their limit
22
- # PATH_PAYMENT_NO_ISSUER = -9, // missing issuer on one asset
23
- # PATH_PAYMENT_TOO_FEW_OFFERS = -10, // not enough offers to satisfy path
24
- # PATH_PAYMENT_OFFER_CROSS_SELF = -11, // would cross one of its own offers
25
- # PATH_PAYMENT_OVER_SENDMAX = -12 // could not satisfy sendmax
26
- # };
27
- #
28
- # ===========================================================================
29
- module Stellar
30
- class PathPaymentResultCode < XDR::Enum
31
- member :path_payment_success, 0
32
- member :path_payment_malformed, -1
33
- member :path_payment_underfunded, -2
34
- member :path_payment_src_no_trust, -3
35
- member :path_payment_src_not_authorized, -4
36
- member :path_payment_no_destination, -5
37
- member :path_payment_no_trust, -6
38
- member :path_payment_not_authorized, -7
39
- member :path_payment_line_full, -8
40
- member :path_payment_no_issuer, -9
41
- member :path_payment_too_few_offers, -10
42
- member :path_payment_offer_cross_self, -11
43
- member :path_payment_over_sendmax, -12
44
-
45
- seal
46
- end
47
- end
@@ -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/bloom-solutions/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