stellar-base 0.19.0 → 0.23.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (159) 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 +45 -8
  5. data/generated/stellar/allow_trust_op.rb +5 -4
  6. data/generated/stellar/allow_trust_op/asset.rb +4 -4
  7. data/generated/stellar/asset.rb +2 -2
  8. data/generated/stellar/asset/alpha_num12.rb +2 -2
  9. data/generated/stellar/asset/alpha_num4.rb +2 -2
  10. data/generated/stellar/authenticated_message.rb +4 -4
  11. data/generated/stellar/authenticated_message/v0.rb +4 -4
  12. data/generated/stellar/bucket_entry.rb +6 -0
  13. data/generated/stellar/bucket_entry_type.rb +8 -2
  14. data/generated/stellar/bucket_metadata.rb +32 -0
  15. data/generated/stellar/bucket_metadata/ext.rb +24 -0
  16. data/generated/stellar/claim_offer_atom.rb +2 -2
  17. data/generated/stellar/{create_passive_offer_op.rb → create_passive_sell_offer_op.rb} +2 -2
  18. data/generated/stellar/crypto_key_type.rb +8 -4
  19. data/generated/stellar/curve25519_public.rb +1 -1
  20. data/generated/stellar/curve25519_secret.rb +1 -1
  21. data/generated/stellar/envelope_type.rb +10 -4
  22. data/generated/stellar/fee_bump_transaction.rb +39 -0
  23. data/generated/stellar/fee_bump_transaction/ext.rb +24 -0
  24. data/generated/stellar/fee_bump_transaction/inner_tx.rb +25 -0
  25. data/generated/stellar/fee_bump_transaction_envelope.rb +22 -0
  26. data/generated/stellar/hmac_sha256_key.rb +1 -1
  27. data/generated/stellar/hmac_sha256_mac.rb +1 -1
  28. data/generated/stellar/inner_transaction_result.rb +56 -0
  29. data/generated/stellar/inner_transaction_result/ext.rb +24 -0
  30. data/generated/stellar/inner_transaction_result/result.rb +52 -0
  31. data/generated/stellar/inner_transaction_result_pair.rb +20 -0
  32. data/generated/stellar/ledger_close_meta.rb +23 -0
  33. data/generated/stellar/ledger_close_meta_v0.rb +35 -0
  34. data/generated/stellar/ledger_close_value_signature.rb +20 -0
  35. data/generated/stellar/ledger_key.rb +1 -1
  36. data/generated/stellar/ledger_key/offer.rb +2 -2
  37. data/generated/stellar/manage_buy_offer_op.rb +29 -0
  38. data/generated/stellar/{manage_offer_result.rb → manage_buy_offer_result.rb} +5 -5
  39. data/generated/stellar/manage_buy_offer_result_code.rb +51 -0
  40. data/generated/stellar/{manage_offer_op.rb → manage_sell_offer_op.rb} +4 -4
  41. data/generated/stellar/manage_sell_offer_result.rb +26 -0
  42. data/generated/stellar/manage_sell_offer_result_code.rb +54 -0
  43. data/generated/stellar/message_type.rb +6 -1
  44. data/generated/stellar/muxed_account.rb +35 -0
  45. data/generated/stellar/muxed_account/med25519.rb +22 -0
  46. data/generated/stellar/offer_entry.rb +2 -2
  47. data/generated/stellar/operation.rb +13 -9
  48. data/generated/stellar/operation/body.rb +37 -29
  49. data/generated/stellar/operation_result.rb +10 -6
  50. data/generated/stellar/operation_result/tr.rb +38 -30
  51. data/generated/stellar/operation_result_code.rb +11 -7
  52. data/generated/stellar/operation_type.rb +20 -16
  53. data/generated/stellar/{path_payment_op.rb → path_payment_strict_receive_op.rb} +6 -6
  54. data/generated/stellar/path_payment_strict_receive_result.rb +38 -0
  55. data/generated/stellar/path_payment_strict_receive_result/success.rb +22 -0
  56. data/generated/stellar/path_payment_strict_receive_result_code.rb +56 -0
  57. data/generated/stellar/path_payment_strict_send_op.rb +32 -0
  58. data/generated/stellar/{path_payment_result.rb → path_payment_strict_send_result.rb} +7 -7
  59. data/generated/stellar/{path_payment_result → path_payment_strict_send_result}/success.rb +1 -1
  60. data/generated/stellar/path_payment_strict_send_result_code.rb +55 -0
  61. data/generated/stellar/payment_op.rb +4 -4
  62. data/generated/stellar/peer_stats.rb +48 -0
  63. data/generated/stellar/signed_survey_request_message.rb +20 -0
  64. data/generated/stellar/signed_survey_response_message.rb +20 -0
  65. data/generated/stellar/signer.rb +1 -1
  66. data/generated/stellar/stellar_message.rb +22 -12
  67. data/generated/stellar/stellar_value.rb +7 -5
  68. data/generated/stellar/stellar_value/ext.rb +8 -4
  69. data/generated/stellar/stellar_value_type.rb +22 -0
  70. data/generated/stellar/survey_message_command_type.rb +20 -0
  71. data/generated/stellar/survey_request_message.rb +26 -0
  72. data/generated/stellar/survey_response_body.rb +23 -0
  73. data/generated/stellar/survey_response_message.rb +26 -0
  74. data/generated/stellar/time_bounds.rb +4 -4
  75. data/generated/stellar/topology_response_body.rb +25 -0
  76. data/generated/stellar/transaction.rb +4 -4
  77. data/generated/stellar/transaction_envelope.rb +17 -8
  78. data/generated/stellar/transaction_meta.rb +4 -0
  79. data/generated/stellar/transaction_meta_v1.rb +1 -1
  80. data/generated/stellar/transaction_meta_v2.rb +24 -0
  81. data/generated/stellar/transaction_result.rb +3 -0
  82. data/generated/stellar/transaction_result/result.rb +9 -3
  83. data/generated/stellar/transaction_result_code.rb +21 -14
  84. data/generated/stellar/transaction_result_meta.rb +22 -0
  85. data/generated/stellar/transaction_signature_payload.rb +3 -1
  86. data/generated/stellar/transaction_signature_payload/tagged_transaction.rb +7 -3
  87. data/generated/stellar/transaction_v0.rb +39 -0
  88. data/generated/stellar/transaction_v0/ext.rb +24 -0
  89. data/generated/stellar/transaction_v0_envelope.rb +22 -0
  90. data/generated/stellar/transaction_v1_envelope.rb +22 -0
  91. data/generated/stellar/trust_line_flags.rb +6 -2
  92. data/generated/stellar/upgrade_entry_meta.rb +20 -0
  93. data/lib/stellar-base.rb +28 -23
  94. data/lib/stellar/account_flags.rb +2 -4
  95. data/lib/stellar/asset.rb +6 -6
  96. data/lib/stellar/base.rb +1 -1
  97. data/lib/stellar/compat.rb +21 -0
  98. data/lib/stellar/concerns/transaction.rb +49 -0
  99. data/lib/stellar/convert.rb +2 -2
  100. data/lib/stellar/factories.rb +1 -3
  101. data/lib/stellar/fee_bump_transaction.rb +21 -0
  102. data/lib/stellar/key_pair.rb +9 -6
  103. data/lib/stellar/networks.rb +5 -7
  104. data/lib/stellar/operation.rb +428 -317
  105. data/lib/stellar/{path_payment_result.rb → path_payment_strict_receive_result.rb} +2 -3
  106. data/lib/stellar/price.rb +2 -4
  107. data/lib/stellar/signer_key.rb +4 -8
  108. data/lib/stellar/thresholds.rb +5 -7
  109. data/lib/stellar/transaction.rb +154 -169
  110. data/lib/stellar/transaction_builder.rb +149 -0
  111. data/lib/stellar/transaction_envelope.rb +40 -8
  112. data/lib/stellar/transaction_v0.rb +39 -0
  113. data/lib/stellar/util/continued_fraction.rb +19 -19
  114. data/lib/stellar/util/strkey.rb +39 -14
  115. data/lib/stellar/{base/version.rb → version.rb} +1 -1
  116. metadata +68 -210
  117. data/.gitignore +0 -17
  118. data/.travis.yml +0 -13
  119. data/.yardopts +0 -8
  120. data/CHANGELOG.md +0 -120
  121. data/CONTRIBUTING.md +0 -48
  122. data/Gemfile +0 -15
  123. data/Guardfile +0 -5
  124. data/Rakefile +0 -4
  125. data/examples/create_account.rb +0 -26
  126. data/examples/low_level_transaction_post.rb +0 -46
  127. data/examples/mid_level_transaction_post.rb +0 -33
  128. data/examples/non_native_payment.rb +0 -60
  129. data/examples/offer.rb +0 -75
  130. data/examples/transaction_merge.rb +0 -23
  131. data/generated/stellar/manage_offer_result_code.rb +0 -50
  132. data/generated/stellar/path_payment_result_code.rb +0 -47
  133. data/ruby-stellar-base.gemspec +0 -34
  134. data/spec/lib/stellar/account_flags_spec.rb +0 -19
  135. data/spec/lib/stellar/asset_spec.rb +0 -45
  136. data/spec/lib/stellar/convert_spec.rb +0 -61
  137. data/spec/lib/stellar/key_pair_spec.rb +0 -251
  138. data/spec/lib/stellar/networks_spec.rb +0 -77
  139. data/spec/lib/stellar/operation_spec.rb +0 -71
  140. data/spec/lib/stellar/path_payment_result_spec.rb +0 -95
  141. data/spec/lib/stellar/price_spec.rb +0 -34
  142. data/spec/lib/stellar/signer_key_spec.rb +0 -26
  143. data/spec/lib/stellar/thresholds_spec.rb +0 -62
  144. data/spec/lib/stellar/transaction_envelope_spec.rb +0 -93
  145. data/spec/lib/stellar/transaction_spec.rb +0 -100
  146. data/spec/lib/stellar/util/strkey_spec.rb +0 -54
  147. data/spec/spec_helper.rb +0 -16
  148. data/spec/support/matchers/be_strkey.rb +0 -9
  149. data/spec/support/matchers/eq_bytes.rb +0 -5
  150. data/spec/support/matchers/have_length.rb +0 -5
  151. data/tasks/rspec.rake +0 -6
  152. data/tasks/travis.rake +0 -1
  153. data/tasks/xdr.rake +0 -50
  154. data/xdr/Stellar-SCP.x +0 -86
  155. data/xdr/Stellar-ledger-entries.x +0 -288
  156. data/xdr/Stellar-ledger.x +0 -283
  157. data/xdr/Stellar-overlay.x +0 -146
  158. data/xdr/Stellar-transaction.x +0 -777
  159. data/xdr/Stellar-types.x +0 -81
@@ -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,50 +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 ManageOfferResultCode
9
- # {
10
- # // codes considered as "success" for the operation
11
- # MANAGE_OFFER_SUCCESS = 0,
12
- #
13
- # // codes considered as "failure" for the operation
14
- # MANAGE_OFFER_MALFORMED = -1, // generated offer would be invalid
15
- # MANAGE_OFFER_SELL_NO_TRUST = -2, // no trust line for what we're selling
16
- # MANAGE_OFFER_BUY_NO_TRUST = -3, // no trust line for what we're buying
17
- # MANAGE_OFFER_SELL_NOT_AUTHORIZED = -4, // not authorized to sell
18
- # MANAGE_OFFER_BUY_NOT_AUTHORIZED = -5, // not authorized to buy
19
- # MANAGE_OFFER_LINE_FULL = -6, // can't receive more of what it's buying
20
- # MANAGE_OFFER_UNDERFUNDED = -7, // doesn't hold what it's trying to sell
21
- # MANAGE_OFFER_CROSS_SELF = -8, // would cross an offer from the same user
22
- # MANAGE_OFFER_SELL_NO_ISSUER = -9, // no issuer for what we're selling
23
- # MANAGE_OFFER_BUY_NO_ISSUER = -10, // no issuer for what we're buying
24
- #
25
- # // update errors
26
- # MANAGE_OFFER_NOT_FOUND = -11, // offerID does not match an existing offer
27
- #
28
- # MANAGE_OFFER_LOW_RESERVE = -12 // not enough funds to create a new Offer
29
- # };
30
- #
31
- # ===========================================================================
32
- module Stellar
33
- class ManageOfferResultCode < XDR::Enum
34
- member :manage_offer_success, 0
35
- member :manage_offer_malformed, -1
36
- member :manage_offer_sell_no_trust, -2
37
- member :manage_offer_buy_no_trust, -3
38
- member :manage_offer_sell_not_authorized, -4
39
- member :manage_offer_buy_not_authorized, -5
40
- member :manage_offer_line_full, -6
41
- member :manage_offer_underfunded, -7
42
- member :manage_offer_cross_self, -8
43
- member :manage_offer_sell_no_issuer, -9
44
- member :manage_offer_buy_no_issuer, -10
45
- member :manage_offer_not_found, -11
46
- member :manage_offer_low_reserve, -12
47
-
48
- seal
49
- end
50
- end
@@ -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