stellar-base 0.18.0 → 0.23.0.pre1

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 +5 -5
  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 +69 -211
  117. data/.gitignore +0 -17
  118. data/.travis.yml +0 -14
  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
@@ -0,0 +1,149 @@
1
+ module Stellar
2
+ class TransactionBuilder
3
+ attr_reader :source_account, :sequence_number, :base_fee, :time_bounds, :memo, :operations
4
+
5
+ def initialize(
6
+ source_account:,
7
+ sequence_number:,
8
+ base_fee: 100,
9
+ time_bounds: nil,
10
+ memo: nil,
11
+ v1: false
12
+ )
13
+ raise ArgumentError, "Bad :source_account" unless source_account.is_a?(Stellar::KeyPair)
14
+ raise ArgumentError, "Bad :sequence_number" unless sequence_number.is_a?(Integer) && sequence_number >= 0
15
+ raise ArgumentError, "Bad :time_bounds" unless time_bounds.is_a?(Stellar::TimeBounds) || time_bounds.nil?
16
+ raise ArgumentError, "Bad :base_fee" unless base_fee.is_a?(Integer) && base_fee >= 100
17
+
18
+ @source_account = source_account
19
+ @sequence_number = sequence_number
20
+ @base_fee = base_fee
21
+ @time_bounds = time_bounds
22
+ @memo = make_memo(memo)
23
+ @operations = []
24
+ @v1 = v1
25
+ end
26
+
27
+ def build
28
+ if @time_bounds.nil?
29
+ raise "TransactionBuilder.time_bounds must be set during initialization or by calling set_timeout"
30
+ elsif !@time_bounds.min_time.is_a?(Integer) || !@time_bounds.max_time.is_a?(Integer)
31
+ raise "TimeBounds.min_time and max_time must be Integers"
32
+ elsif @time_bounds.max_time != 0 && @time_bounds.min_time > @time_bounds.max_time
33
+ raise "Timebounds.max_time must be greater than min_time"
34
+ end
35
+
36
+ attrs = {
37
+ fee: @base_fee * @operations.length,
38
+ seq_num: @sequence_number,
39
+ time_bounds: @time_bounds,
40
+ memo: @memo,
41
+ operations: @operations,
42
+ ext: Stellar::Transaction::Ext.new(0)
43
+ }
44
+
45
+ tx = if @v1
46
+ attrs[:source_account] = @source_account.muxed_account
47
+ Stellar::Transaction.new(attrs)
48
+ else
49
+ attrs[:source_account_ed25519] = @source_account.raw_public_key
50
+ Stellar::TransactionV0.new(attrs)
51
+ end
52
+
53
+ @sequence_number += 1
54
+ tx
55
+ end
56
+
57
+ def build_fee_bump(inner_txe:)
58
+ if inner_txe.switch != Stellar::EnvelopeType.envelope_type_tx
59
+ raise "Invalid inner transaction type, it should be a `envelope_type_tx` but received a #{inner_tx.to_envelope.switch}."
60
+ end
61
+
62
+ inner_tx = inner_txe.tx
63
+ inner_ops = inner_tx.operations
64
+ inner_base_fee_rate = inner_tx.fee.fdiv(inner_ops.length)
65
+
66
+ # The fee rate for fee bump is at least the fee rate of the inner transaction
67
+ if @base_fee < inner_base_fee_rate
68
+ raise "Insufficient base_fee, it should be at least #{inner_base_fee_rate} stroops."
69
+ end
70
+
71
+ Stellar::FeeBumpTransaction.new(
72
+ fee_source: @source_account.muxed_account,
73
+ fee: @base_fee * (inner_ops.length + 1),
74
+ inner_tx: Stellar::FeeBumpTransaction::InnerTx.new(:envelope_type_tx, inner_txe.v1!),
75
+ ext: Stellar::FeeBumpTransaction::Ext.new(0)
76
+ )
77
+ end
78
+
79
+ def add_operation(operation)
80
+ raise ArgumentError, "Bad operation" unless operation.is_a? Stellar::Operation
81
+ @operations.push(operation)
82
+ self
83
+ end
84
+
85
+ def clear_operations
86
+ @operations.clear
87
+ self
88
+ end
89
+
90
+ def set_source_account(account_kp)
91
+ raise ArgumentError, "Bad source account" unless account_kp.is_a?(Stellar::KeyPair)
92
+ @source_account = account_kp
93
+ self
94
+ end
95
+
96
+ def set_sequence_number(seq_num)
97
+ raise ArgumentError, "Bad sequence number" unless seq_num.is_a?(Integer) && seq_num >= 0
98
+ @sequence_number = seq_num
99
+ self
100
+ end
101
+
102
+ def set_timeout(timeout)
103
+ if !timeout.is_a?(Integer) || timeout < 0
104
+ raise ArgumentError, "Timeout must be a non-negative integer"
105
+ end
106
+
107
+ if @time_bounds.nil?
108
+ @time_bounds = Stellar::TimeBounds.new(min_time: 0, max_time: nil)
109
+ end
110
+
111
+ @time_bounds.max_time = if timeout == 0
112
+ timeout
113
+ else
114
+ Time.now.to_i + timeout
115
+ end
116
+
117
+ self
118
+ end
119
+
120
+ def set_memo(memo)
121
+ @memo = make_memo(memo)
122
+ self
123
+ end
124
+
125
+ def set_base_fee(base_fee)
126
+ raise ArgumentError, "Bad base fee" unless base_fee.is_a?(Integer) && base_fee >= 100
127
+ @base_fee = base_fee
128
+ self
129
+ end
130
+
131
+ def make_memo(memo)
132
+ case memo
133
+ when Stellar::Memo
134
+ memo
135
+ when nil
136
+ Memo.new(:memo_none)
137
+ when Integer
138
+ Memo.new(:memo_id, memo)
139
+ when String
140
+ Memo.new(:memo_text, memo)
141
+ when Array
142
+ t, val = *memo
143
+ Memo.new(:"memo_#{t}", val)
144
+ else
145
+ raise ArgumentError, "Bad :memo"
146
+ end
147
+ end
148
+ end
149
+ end
@@ -1,23 +1,56 @@
1
1
  module Stellar
2
2
  class TransactionEnvelope
3
+ class << self
4
+ def v0(tx:, signatures:)
5
+ v0_envelope = TransactionV0Envelope.new(tx: tx, signatures: signatures)
6
+ new(:envelope_type_tx_v0, v0_envelope)
7
+ end
8
+
9
+ def v1(tx:, signatures:)
10
+ v1_envelope = TransactionV1Envelope.new(tx: tx, signatures: signatures)
11
+ new(:envelope_type_tx, v1_envelope)
12
+ end
13
+
14
+ def fee_bump(tx:, signatures:)
15
+ fee_bump_envelope = FeeBumpTransactionEnvelope.new(tx: tx, signatures: signatures)
16
+ new(:envelope_type_tx_fee_bump, fee_bump_envelope)
17
+ end
18
+ end
19
+
20
+ # Delegates any undefined method to the currently set arm
21
+ def method_missing(method, *args, &block)
22
+ case switch
23
+ when EnvelopeType.envelope_type_tx_v0
24
+ v0!.public_send(method, *args)
25
+ when EnvelopeType.envelope_type_tx
26
+ v1!.public_send(method, *args)
27
+ when EnvelopeType.envelope_type_tx_fee_bump
28
+ fee_bump!.public_send(method, *args)
29
+ else
30
+ super
31
+ end
32
+ end
33
+
34
+ def respond_to_missing?(method, include_private = false)
35
+ ["tx", "signatures"].include?(method) || super
36
+ end
3
37
 
4
- #
5
38
  # Checks to ensure that every signature for the envelope is
6
39
  # a valid signature of one of the provided `key_pairs`
7
- #
40
+ #
8
41
  # NOTE: this does not do any authorization checks, which requires access to
9
42
  # the current ledger state.
10
- #
43
+ #
11
44
  # @param *key_pairs [Array<Stellar::KeyPair>] The key pairs to check the envelopes signatures against
12
- #
45
+ #
13
46
  # @return [Boolean] true if all signatures are from the provided key_pairs and validly sign the tx's hash
14
47
  def signed_correctly?(*key_pairs)
15
48
  hash = tx.hash
16
49
  return false if signatures.empty?
17
50
 
18
51
  key_index = key_pairs.index_by(&:signature_hint)
19
-
20
- signatures.all? do |sig|
52
+
53
+ signatures.all? do |sig|
21
54
  key_pair = key_index[sig.hint]
22
55
  break false if key_pair.nil?
23
56
 
@@ -34,6 +67,5 @@ module Stellar
34
67
  merged_tx.signatures = [signatures, other.signatures]
35
68
  merged_tx
36
69
  end
37
-
38
70
  end
39
- end
71
+ end
@@ -0,0 +1,39 @@
1
+ module Stellar
2
+ class TransactionV0
3
+ include Stellar::Concerns::Transaction
4
+
5
+ def to_envelope(*key_pairs)
6
+ signatures = (key_pairs || []).map(&method(:sign_decorated))
7
+
8
+ TransactionEnvelope.v0(signatures: signatures, tx: self)
9
+ end
10
+
11
+ def signature_base_prefix
12
+ val = Stellar::EnvelopeType.envelope_type_tx_v0
13
+
14
+ Stellar.current_network_id + Stellar::EnvelopeType.to_xdr(val)
15
+ end
16
+
17
+ # Backwards Compatibility: Use ENVELOPE_TYPE_TX to sign ENVELOPE_TYPE_TX_V0
18
+ # we need a Transaction to generate the signature base
19
+ def signature_base
20
+ tx = Stellar::Transaction.from_xdr(
21
+ # TransactionV0 is a transaction with the AccountID discriminant
22
+ # stripped off, we need to put it back to build a valid transaction
23
+ # which we can use to build a TransactionSignaturePayloadTaggedTransaction
24
+ Stellar::PublicKeyType.to_xdr(Stellar::PublicKeyType.public_key_type_ed25519) + to_xdr
25
+ )
26
+
27
+ tagged_tx = Stellar::TransactionSignaturePayload::TaggedTransaction.new(:envelope_type_tx, tx)
28
+
29
+ Stellar::TransactionSignaturePayload.new(
30
+ network_id: Stellar.current_network_id,
31
+ tagged_transaction: tagged_tx
32
+ ).to_xdr
33
+ end
34
+
35
+ def source_account
36
+ source_account_ed25519
37
+ end
38
+ end
39
+ end
@@ -5,13 +5,13 @@ module Stellar
5
5
  attr_reader :i
6
6
  attr_reader :f
7
7
 
8
- def self.best_r(number, max_precision=MAX_PRECISION)
8
+ def self.best_r(number, max_precision = MAX_PRECISION)
9
9
  cur_cf = new(number)
10
10
 
11
11
  loop do
12
- next_cf = cur_cf.extend()
13
- cur_r = cur_cf.to_r(max_precision)
14
- next_r = next_cf.to_r(max_precision)
12
+ next_cf = cur_cf.extend
13
+ cur_r = cur_cf.to_r(max_precision)
14
+ next_r = next_cf.to_r(max_precision)
15
15
 
16
16
  break cur_r if cur_cf.done? || cur_r == next_r
17
17
 
@@ -21,9 +21,9 @@ module Stellar
21
21
  cur_cf.to_r(max_precision)
22
22
  end
23
23
 
24
- def initialize(val, parents=[])
25
- @i = val.floor
26
- @f = val - @i
24
+ def initialize(val, parents = [])
25
+ @i = val.floor
26
+ @f = val - @i
27
27
  @parents = parents
28
28
  end
29
29
 
@@ -43,22 +43,22 @@ module Stellar
43
43
  def convergents
44
44
  return @convergents if defined? @convergents
45
45
 
46
- c = [Fraction.new(0,1), Fraction.new(1,0)]
46
+ c = [Fraction.new(0, 1), Fraction.new(1, 0)]
47
47
  to_a.each_with_index do |a, i|
48
- i = i + 2
48
+ i += 2
49
49
 
50
- h = a * c[i-1].n + c[i-2].n
51
- k = a * c[i-1].d + c[i-2].d
52
- c << Fraction.new(h,k)
50
+ h = a * c[i - 1].n + c[i - 2].n
51
+ k = a * c[i - 1].d + c[i - 2].d
52
+ c << Fraction.new(h, k)
53
53
  end
54
54
 
55
55
  @converegents = c[2..-1]
56
56
  end
57
57
 
58
- def to_r(max_precision=MAX_PRECISION)
59
- fraction = convergents.take_while do |c|
58
+ def to_r(max_precision = MAX_PRECISION)
59
+ fraction = convergents.take_while { |c|
60
60
  c.n <= max_precision && c.d <= max_precision
61
- end.last
61
+ }.last
62
62
 
63
63
  Rational(fraction.n, fraction.d)
64
64
  end
@@ -67,7 +67,7 @@ module Stellar
67
67
  @f == 0
68
68
  end
69
69
 
70
- def extend(count=1)
70
+ def extend(count = 1)
71
71
  result = self
72
72
 
73
73
  count.times do
@@ -78,11 +78,11 @@ module Stellar
78
78
  result
79
79
  end
80
80
 
81
- class Fraction
81
+ class Fraction
82
82
  attr_reader :n
83
83
  attr_reader :d
84
84
 
85
- def initialize(n,d)
85
+ def initialize(n, d)
86
86
  @n = n
87
87
  @d = d
88
88
  end
@@ -93,4 +93,4 @@ module Stellar
93
93
  end
94
94
  end
95
95
  end
96
- end
96
+ end
@@ -1,33 +1,59 @@
1
1
  module Stellar
2
2
  module Util
3
-
4
- require 'base32'
5
- require 'digest/crc16_xmodem'
3
+ require "base32"
4
+ require "digest/crc16_xmodem"
6
5
 
7
6
  class StrKey
8
-
9
7
  VERSION_BYTES = {
10
- account_id: [ 6 << 3].pack("C"), # Base32-encodes to 'G...'
11
- seed: [18 << 3].pack("C"), # Base32-encodes to 'S...'
8
+ account_id: [6 << 3].pack("C"), # Base32-encodes to 'G...'
9
+ seed: [18 << 3].pack("C"), # Base32-encodes to 'S...'
12
10
  pre_auth_tx: [19 << 3].pack("C"), # Base32-encodes to 'T...'
13
- hash_x: [23 << 3].pack("C") # Base32-encodes to 'X...'
11
+ hash_x: [23 << 3].pack("C") # Base32-encodes to 'X...'
14
12
  }
15
13
 
16
14
  def self.check_encode(version, byte_str)
17
15
  version_byte = VERSION_BYTES[version]
18
16
  raise ArgumentError, "Invalid version: #{version}" if version_byte.blank?
19
17
  payload = version_byte + byte_str.dup.force_encoding("BINARY")
20
- check = checksum(payload)
21
- Base32.encode(payload + check)
18
+ check = checksum(payload)
19
+ # TODO: sort out, is it 100% safe to remove padding
20
+ # SEP-23 says yes, but shit happens
21
+ Base32.encode(payload + check).tr("=", "")
22
+ end
23
+
24
+ # Converts an Stellar::MuxedAccount to its string representation, forcing the ed25519 representation.
25
+ # @param [Stellar::MuxedAccount] muxed account
26
+ # @return [String] "G.."-like address
27
+ def self.encode_muxed_account(muxed_account)
28
+ ed25519 = if muxed_account.switch == Stellar::CryptoKeyType.key_type_ed25519
29
+ muxed_account.ed25519
30
+ else
31
+ muxed_account.med25519!.ed25519
32
+ end
33
+
34
+ check_encode(:account_id, ed25519)
35
+ end
36
+
37
+ # Returns a Stellar::MuxedAccount, forcing the ed25519 discriminant
38
+ #
39
+ # @param [String] address to decode to XDR
40
+ # @return [Stellar::MuxedAccount] MuxedAccount with ed25519 discriminant
41
+ def self.decode_muxed_account(strkey)
42
+ Stellar::MuxedAccount.new(:key_type_ed25519, check_decode(:account_id, strkey))
22
43
  end
23
44
 
24
45
  def self.check_decode(expected_version, str)
25
- decoded = Base32.decode(str) rescue (raise ArgumentError, "Invalid base32 string")
46
+ decoded = begin
47
+ Base32.decode(str)
48
+ rescue
49
+ raise ArgumentError, "Invalid base32 string"
50
+ end
26
51
  version_byte = decoded[0]
27
- payload = decoded[1...-2]
28
- check = decoded[-2..-1]
29
- version = VERSION_BYTES.key(version_byte)
52
+ payload = decoded[1...-2]
53
+ check = decoded[-2..-1]
54
+ version = VERSION_BYTES.key(version_byte)
30
55
 
56
+ raise ArgumentError, "invalid encoded string" if str != Base32.encode(decoded).tr("=", "")
31
57
  raise ArgumentError, "Unexpected version: #{version.inspect}" if version != expected_version
32
58
  raise ArgumentError, "Invalid checksum" if check != checksum(decoded[0...-2])
33
59
  payload
@@ -39,7 +65,6 @@ module Stellar
39
65
  crc = Digest::CRC16XModem.checksum(bytes)
40
66
  [crc].pack("S<")
41
67
  end
42
-
43
68
  end
44
69
  end
45
70
  end
@@ -1,5 +1,5 @@
1
1
  module Stellar
2
2
  module Base
3
- VERSION = "0.18.0"
3
+ VERSION = "0.23.0.pre1"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.18.0
4
+ version: 0.23.0.pre1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-29 00:00:00.000000000 Z
11
+ date: 2020-05-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: xdr
@@ -16,42 +16,42 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 3.0.0
19
+ version: 3.0.1
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 3.0.0
26
+ version: 3.0.1
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: digest-crc
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - ">="
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: '0.5'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: '0.5'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: base32
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '0.3'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - ">="
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '0.3'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rbnacl
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -72,140 +72,14 @@ dependencies:
72
72
  requirements:
73
73
  - - ">="
74
74
  - !ruby/object:Gem::Version
75
- version: 5.2.0
75
+ version: 5.0.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
- version: 5.2.0
83
- - !ruby/object:Gem::Dependency
84
- name: bundler
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: '1.7'
90
- type: :development
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: '1.7'
97
- - !ruby/object:Gem::Dependency
98
- name: rake
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
101
- - - "~>"
102
- - !ruby/object:Gem::Version
103
- version: '12.0'
104
- type: :development
105
- prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
108
- - - "~>"
109
- - !ruby/object:Gem::Version
110
- version: '12.0'
111
- - !ruby/object:Gem::Dependency
112
- name: xdrgen
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ">="
116
- - !ruby/object:Gem::Version
117
- version: '0'
118
- type: :development
119
- prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
122
- - - ">="
123
- - !ruby/object:Gem::Version
124
- version: '0'
125
- - !ruby/object:Gem::Dependency
126
- name: rspec
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - "~>"
130
- - !ruby/object:Gem::Version
131
- version: '3.1'
132
- type: :development
133
- prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - "~>"
137
- - !ruby/object:Gem::Version
138
- version: '3.1'
139
- - !ruby/object:Gem::Dependency
140
- name: guard-rspec
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - ">="
144
- - !ruby/object:Gem::Version
145
- version: '0'
146
- type: :development
147
- prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - ">="
151
- - !ruby/object:Gem::Version
152
- version: '0'
153
- - !ruby/object:Gem::Dependency
154
- name: simplecov
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - ">="
158
- - !ruby/object:Gem::Version
159
- version: '0'
160
- type: :development
161
- prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - ">="
165
- - !ruby/object:Gem::Version
166
- version: '0'
167
- - !ruby/object:Gem::Dependency
168
- name: octokit
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- version: '0'
174
- type: :development
175
- prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ">="
179
- - !ruby/object:Gem::Version
180
- version: '0'
181
- - !ruby/object:Gem::Dependency
182
- name: netrc
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
185
- - - ">="
186
- - !ruby/object:Gem::Version
187
- version: '0'
188
- type: :development
189
- prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
192
- - - ">="
193
- - !ruby/object:Gem::Version
194
- version: '0'
195
- - !ruby/object:Gem::Dependency
196
- name: yard
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ">="
200
- - !ruby/object:Gem::Version
201
- version: '0'
202
- type: :development
203
- prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
206
- - - ">="
207
- - !ruby/object:Gem::Version
208
- version: '0'
82
+ version: 5.0.0
209
83
  description:
210
84
  email:
211
85
  - scott@stellar.org
@@ -213,22 +87,8 @@ executables: []
213
87
  extensions: []
214
88
  extra_rdoc_files: []
215
89
  files:
216
- - ".gitignore"
217
- - ".travis.yml"
218
- - ".yardopts"
219
- - CHANGELOG.md
220
- - CONTRIBUTING.md
221
- - Gemfile
222
- - Guardfile
223
- - LICENSE.txt
90
+ - LICENSE
224
91
  - README.md
225
- - Rakefile
226
- - examples/create_account.rb
227
- - examples/low_level_transaction_post.rb
228
- - examples/mid_level_transaction_post.rb
229
- - examples/non_native_payment.rb
230
- - examples/offer.rb
231
- - examples/transaction_merge.rb
232
92
  - generated/stellar-base-generated.rb
233
93
  - generated/stellar/account_entry.rb
234
94
  - generated/stellar/account_entry/ext.rb
@@ -251,6 +111,8 @@ files:
251
111
  - generated/stellar/authenticated_message/v0.rb
252
112
  - generated/stellar/bucket_entry.rb
253
113
  - generated/stellar/bucket_entry_type.rb
114
+ - generated/stellar/bucket_metadata.rb
115
+ - generated/stellar/bucket_metadata/ext.rb
254
116
  - generated/stellar/bump_sequence_op.rb
255
117
  - generated/stellar/bump_sequence_result.rb
256
118
  - generated/stellar/bump_sequence_result_code.rb
@@ -261,7 +123,7 @@ files:
261
123
  - generated/stellar/create_account_op.rb
262
124
  - generated/stellar/create_account_result.rb
263
125
  - generated/stellar/create_account_result_code.rb
264
- - generated/stellar/create_passive_offer_op.rb
126
+ - generated/stellar/create_passive_sell_offer_op.rb
265
127
  - generated/stellar/crypto_key_type.rb
266
128
  - generated/stellar/curve25519_public.rb
267
129
  - generated/stellar/curve25519_secret.rb
@@ -272,13 +134,24 @@ files:
272
134
  - generated/stellar/envelope_type.rb
273
135
  - generated/stellar/error.rb
274
136
  - generated/stellar/error_code.rb
137
+ - generated/stellar/fee_bump_transaction.rb
138
+ - generated/stellar/fee_bump_transaction/ext.rb
139
+ - generated/stellar/fee_bump_transaction/inner_tx.rb
140
+ - generated/stellar/fee_bump_transaction_envelope.rb
275
141
  - generated/stellar/hello.rb
276
142
  - generated/stellar/hmac_sha256_key.rb
277
143
  - generated/stellar/hmac_sha256_mac.rb
278
144
  - generated/stellar/inflation_payout.rb
279
145
  - generated/stellar/inflation_result.rb
280
146
  - generated/stellar/inflation_result_code.rb
147
+ - generated/stellar/inner_transaction_result.rb
148
+ - generated/stellar/inner_transaction_result/ext.rb
149
+ - generated/stellar/inner_transaction_result/result.rb
150
+ - generated/stellar/inner_transaction_result_pair.rb
281
151
  - generated/stellar/ip_addr_type.rb
152
+ - generated/stellar/ledger_close_meta.rb
153
+ - generated/stellar/ledger_close_meta_v0.rb
154
+ - generated/stellar/ledger_close_value_signature.rb
282
155
  - generated/stellar/ledger_entry.rb
283
156
  - generated/stellar/ledger_entry/data.rb
284
157
  - generated/stellar/ledger_entry/ext.rb
@@ -298,18 +171,23 @@ files:
298
171
  - generated/stellar/ledger_upgrade.rb
299
172
  - generated/stellar/ledger_upgrade_type.rb
300
173
  - generated/stellar/liabilities.rb
174
+ - generated/stellar/manage_buy_offer_op.rb
175
+ - generated/stellar/manage_buy_offer_result.rb
176
+ - generated/stellar/manage_buy_offer_result_code.rb
301
177
  - generated/stellar/manage_data_op.rb
302
178
  - generated/stellar/manage_data_result.rb
303
179
  - generated/stellar/manage_data_result_code.rb
304
180
  - generated/stellar/manage_offer_effect.rb
305
- - generated/stellar/manage_offer_op.rb
306
- - generated/stellar/manage_offer_result.rb
307
- - generated/stellar/manage_offer_result_code.rb
308
181
  - generated/stellar/manage_offer_success_result.rb
309
182
  - generated/stellar/manage_offer_success_result/offer.rb
183
+ - generated/stellar/manage_sell_offer_op.rb
184
+ - generated/stellar/manage_sell_offer_result.rb
185
+ - generated/stellar/manage_sell_offer_result_code.rb
310
186
  - generated/stellar/memo.rb
311
187
  - generated/stellar/memo_type.rb
312
188
  - generated/stellar/message_type.rb
189
+ - generated/stellar/muxed_account.rb
190
+ - generated/stellar/muxed_account/med25519.rb
313
191
  - generated/stellar/offer_entry.rb
314
192
  - generated/stellar/offer_entry/ext.rb
315
193
  - generated/stellar/offer_entry_flags.rb
@@ -320,15 +198,20 @@ files:
320
198
  - generated/stellar/operation_result/tr.rb
321
199
  - generated/stellar/operation_result_code.rb
322
200
  - generated/stellar/operation_type.rb
323
- - generated/stellar/path_payment_op.rb
324
- - generated/stellar/path_payment_result.rb
325
- - generated/stellar/path_payment_result/success.rb
326
- - generated/stellar/path_payment_result_code.rb
201
+ - generated/stellar/path_payment_strict_receive_op.rb
202
+ - generated/stellar/path_payment_strict_receive_result.rb
203
+ - generated/stellar/path_payment_strict_receive_result/success.rb
204
+ - generated/stellar/path_payment_strict_receive_result_code.rb
205
+ - generated/stellar/path_payment_strict_send_op.rb
206
+ - generated/stellar/path_payment_strict_send_result.rb
207
+ - generated/stellar/path_payment_strict_send_result/success.rb
208
+ - generated/stellar/path_payment_strict_send_result_code.rb
327
209
  - generated/stellar/payment_op.rb
328
210
  - generated/stellar/payment_result.rb
329
211
  - generated/stellar/payment_result_code.rb
330
212
  - generated/stellar/peer_address.rb
331
213
  - generated/stellar/peer_address/ip.rb
214
+ - generated/stellar/peer_stats.rb
332
215
  - generated/stellar/price.rb
333
216
  - generated/stellar/public_key.rb
334
217
  - generated/stellar/public_key_type.rb
@@ -347,6 +230,8 @@ files:
347
230
  - generated/stellar/set_options_op.rb
348
231
  - generated/stellar/set_options_result.rb
349
232
  - generated/stellar/set_options_result_code.rb
233
+ - generated/stellar/signed_survey_request_message.rb
234
+ - generated/stellar/signed_survey_response_message.rb
350
235
  - generated/stellar/signer.rb
351
236
  - generated/stellar/signer_key.rb
352
237
  - generated/stellar/signer_key_type.rb
@@ -354,8 +239,14 @@ files:
354
239
  - generated/stellar/stellar_message.rb
355
240
  - generated/stellar/stellar_value.rb
356
241
  - generated/stellar/stellar_value/ext.rb
242
+ - generated/stellar/stellar_value_type.rb
243
+ - generated/stellar/survey_message_command_type.rb
244
+ - generated/stellar/survey_request_message.rb
245
+ - generated/stellar/survey_response_body.rb
246
+ - generated/stellar/survey_response_message.rb
357
247
  - generated/stellar/threshold_indexes.rb
358
248
  - generated/stellar/time_bounds.rb
249
+ - generated/stellar/topology_response_body.rb
359
250
  - generated/stellar/transaction.rb
360
251
  - generated/stellar/transaction/ext.rb
361
252
  - generated/stellar/transaction_envelope.rb
@@ -365,68 +256,53 @@ files:
365
256
  - generated/stellar/transaction_history_result_entry/ext.rb
366
257
  - generated/stellar/transaction_meta.rb
367
258
  - generated/stellar/transaction_meta_v1.rb
259
+ - generated/stellar/transaction_meta_v2.rb
368
260
  - generated/stellar/transaction_result.rb
369
261
  - generated/stellar/transaction_result/ext.rb
370
262
  - generated/stellar/transaction_result/result.rb
371
263
  - generated/stellar/transaction_result_code.rb
264
+ - generated/stellar/transaction_result_meta.rb
372
265
  - generated/stellar/transaction_result_pair.rb
373
266
  - generated/stellar/transaction_result_set.rb
374
267
  - generated/stellar/transaction_set.rb
375
268
  - generated/stellar/transaction_signature_payload.rb
376
269
  - generated/stellar/transaction_signature_payload/tagged_transaction.rb
270
+ - generated/stellar/transaction_v0.rb
271
+ - generated/stellar/transaction_v0/ext.rb
272
+ - generated/stellar/transaction_v0_envelope.rb
273
+ - generated/stellar/transaction_v1_envelope.rb
377
274
  - generated/stellar/trust_line_entry.rb
378
275
  - generated/stellar/trust_line_entry/ext.rb
379
276
  - generated/stellar/trust_line_entry/ext/v1.rb
380
277
  - generated/stellar/trust_line_entry/ext/v1/ext.rb
381
278
  - generated/stellar/trust_line_flags.rb
279
+ - generated/stellar/upgrade_entry_meta.rb
382
280
  - lib/stellar-base.rb
383
281
  - lib/stellar/account_flags.rb
384
282
  - lib/stellar/asset.rb
385
283
  - lib/stellar/base.rb
386
- - lib/stellar/base/version.rb
284
+ - lib/stellar/compat.rb
285
+ - lib/stellar/concerns/transaction.rb
387
286
  - lib/stellar/convert.rb
388
287
  - lib/stellar/factories.rb
288
+ - lib/stellar/fee_bump_transaction.rb
389
289
  - lib/stellar/key_pair.rb
390
290
  - lib/stellar/networks.rb
391
291
  - lib/stellar/operation.rb
392
- - lib/stellar/path_payment_result.rb
292
+ - lib/stellar/path_payment_strict_receive_result.rb
393
293
  - lib/stellar/price.rb
394
294
  - lib/stellar/signer_key.rb
395
295
  - lib/stellar/thresholds.rb
396
296
  - lib/stellar/transaction.rb
297
+ - lib/stellar/transaction_builder.rb
397
298
  - lib/stellar/transaction_envelope.rb
299
+ - lib/stellar/transaction_v0.rb
398
300
  - lib/stellar/util/continued_fraction.rb
399
301
  - lib/stellar/util/strkey.rb
400
- - ruby-stellar-base.gemspec
401
- - spec/lib/stellar/account_flags_spec.rb
402
- - spec/lib/stellar/asset_spec.rb
403
- - spec/lib/stellar/convert_spec.rb
404
- - spec/lib/stellar/key_pair_spec.rb
405
- - spec/lib/stellar/networks_spec.rb
406
- - spec/lib/stellar/operation_spec.rb
407
- - spec/lib/stellar/path_payment_result_spec.rb
408
- - spec/lib/stellar/price_spec.rb
409
- - spec/lib/stellar/signer_key_spec.rb
410
- - spec/lib/stellar/thresholds_spec.rb
411
- - spec/lib/stellar/transaction_envelope_spec.rb
412
- - spec/lib/stellar/transaction_spec.rb
413
- - spec/lib/stellar/util/strkey_spec.rb
414
- - spec/spec_helper.rb
415
- - spec/support/matchers/be_strkey.rb
416
- - spec/support/matchers/eq_bytes.rb
417
- - spec/support/matchers/have_length.rb
418
- - tasks/rspec.rake
419
- - tasks/travis.rake
420
- - tasks/xdr.rake
421
- - xdr/Stellar-SCP.x
422
- - xdr/Stellar-ledger-entries.x
423
- - xdr/Stellar-ledger.x
424
- - xdr/Stellar-overlay.x
425
- - xdr/Stellar-transaction.x
426
- - xdr/Stellar-types.x
302
+ - lib/stellar/version.rb
427
303
  homepage: https://github.com/stellar/ruby-stellar-base
428
304
  licenses:
429
- - Apache 2.0
305
+ - Apache-2.0
430
306
  metadata: {}
431
307
  post_install_message:
432
308
  rdoc_options: []
@@ -440,30 +316,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
440
316
  version: '0'
441
317
  required_rubygems_version: !ruby/object:Gem::Requirement
442
318
  requirements:
443
- - - ">="
319
+ - - ">"
444
320
  - !ruby/object:Gem::Version
445
- version: '0'
321
+ version: 1.3.1
446
322
  requirements: []
447
- rubyforge_project:
448
- rubygems_version: 2.5.1
323
+ rubygems_version: 3.1.3
449
324
  signing_key:
450
325
  specification_version: 4
451
326
  summary: 'Stellar client library: XDR'
452
- test_files:
453
- - spec/lib/stellar/account_flags_spec.rb
454
- - spec/lib/stellar/asset_spec.rb
455
- - spec/lib/stellar/convert_spec.rb
456
- - spec/lib/stellar/key_pair_spec.rb
457
- - spec/lib/stellar/networks_spec.rb
458
- - spec/lib/stellar/operation_spec.rb
459
- - spec/lib/stellar/path_payment_result_spec.rb
460
- - spec/lib/stellar/price_spec.rb
461
- - spec/lib/stellar/signer_key_spec.rb
462
- - spec/lib/stellar/thresholds_spec.rb
463
- - spec/lib/stellar/transaction_envelope_spec.rb
464
- - spec/lib/stellar/transaction_spec.rb
465
- - spec/lib/stellar/util/strkey_spec.rb
466
- - spec/spec_helper.rb
467
- - spec/support/matchers/be_strkey.rb
468
- - spec/support/matchers/eq_bytes.rb
469
- - spec/support/matchers/have_length.rb
327
+ test_files: []