stellar-base 0.27.0 → 0.28.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f3f2262b18e995857495f0209dff368bf75d5ca0fb946a77c890a859e816f916
4
- data.tar.gz: ef32817bb66be06efe55f7da2ef204837895f4f6966c4fd55b91e2f1bbff8bb9
3
+ metadata.gz: 747484cfbd2ecc3339c7f02db339afd3259cbfc438c752b88384437d92b7dd8e
4
+ data.tar.gz: 85490bd0247c71f517fdc1c66cabe961d4ce8c4b574d42b2f3cddeeb54b2e395
5
5
  SHA512:
6
- metadata.gz: d6a82d8306b2c62d57b4467fcbfef426d276b7c11612dfed13fb2db13b43c6aa9091f7cfd1c7d6c464b3d93f6faf7d72b7262fdfd9d6dc9dfb7ca7557c9b5254
7
- data.tar.gz: ab279d7660378ed94d5d1fdfd2367714c10d78bd7f109dba50dafbcd186de0de97de0893b4b50620029a9189a0ad5d0e98604769ec4a4b0e82c1ceaa8c99278a
6
+ metadata.gz: d6a0f7794d178e34799db7dad0c64ed37830896b30c7a53b204c055fb71289a535b5044d5340663ccfec96c33317f1754eed6a9ee7eba7aaa37da7431cfd26f2
7
+ data.tar.gz: 623a2e0bee087f04c3b512c63ccaefdc9d85f9cecc8bde008cdaed01d017577fbbb07910b621809913557d7fff5bb559928b3b341295c544d90a1fda4d584e16
data/CHANGELOG.md CHANGED
@@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/).
7
7
  As this project is pre 1.0, breaking changes may happen for minor version
8
8
  bumps. A breaking change will get clearly notified in this log.
9
9
 
10
+ ## [0.28.0](https://www.github.com/astroband/ruby-stellar-sdk/compare/v0.27.0...v0.28.0) (2021-07-17)
11
+
12
+ ### Features
13
+
14
+ * support muxed accounts in tx builder ([#162](https://www.github.com/astroband/ruby-stellar-sdk/issues/162)) ([37cd954](https://www.github.com/astroband/ruby-stellar-sdk/commit/37cd954f92c7999a74ca779e795dde74a3d71aad))
15
+
10
16
  ## [0.27.0](https://github.com/astroband/ruby-stellar-sdk/compare/v0.26.0...v0.27.0) (2021-05-08)
11
17
 
12
18
  ### Features
@@ -10,7 +10,7 @@ require 'xdr'
10
10
  # case ENVELOPE_TYPE_OP_ID:
11
11
  # struct
12
12
  # {
13
- # MuxedAccount sourceAccount;
13
+ # AccountID sourceAccount;
14
14
  # SequenceNumber seqNum;
15
15
  # uint32 opNum;
16
16
  # } id;
@@ -7,7 +7,7 @@ require 'xdr'
7
7
  #
8
8
  # struct
9
9
  # {
10
- # MuxedAccount sourceAccount;
10
+ # AccountID sourceAccount;
11
11
  # SequenceNumber seqNum;
12
12
  # uint32 opNum;
13
13
  # }
@@ -16,7 +16,7 @@ require 'xdr'
16
16
  module Stellar
17
17
  class OperationID
18
18
  class Id < XDR::Struct
19
- attribute :source_account, MuxedAccount
19
+ attribute :source_account, AccountID
20
20
  attribute :seq_num, SequenceNumber
21
21
  attribute :op_num, Uint32
22
22
  end
data/lib/stellar-base.rb CHANGED
@@ -23,6 +23,7 @@ Stellar::Deprecation = ActiveSupport::Deprecation.new("next release", "stellar-b
23
23
 
24
24
  # extensions onto the generated files must be loaded manually, below
25
25
 
26
+ require_relative "./stellar/account"
26
27
  require_relative "./stellar/account_flags"
27
28
  require_relative "./stellar/asset"
28
29
  require_relative "./stellar/claim_predicate"
@@ -0,0 +1,59 @@
1
+ module Stellar
2
+ class Account
3
+ delegate :address, to: :keypair
4
+
5
+ def self.random
6
+ keypair = Stellar::KeyPair.random
7
+ new(keypair)
8
+ end
9
+
10
+ def self.from_seed(seed)
11
+ keypair = Stellar::KeyPair.from_seed(seed)
12
+ new(keypair)
13
+ end
14
+
15
+ def self.from_address(address)
16
+ muxed_xdr = Util::StrKey.decode_muxed_account(address)
17
+
18
+ if muxed_xdr.ed25519
19
+ new(KeyPair.from_public_key(muxed_xdr.ed25519))
20
+ else
21
+ muxed_xdr = muxed_xdr.med25519!
22
+ new(KeyPair.from_public_key(muxed_xdr.ed25519), muxed_xdr.id)
23
+ end
24
+ end
25
+
26
+ def self.master
27
+ keypair = Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching")
28
+ new(keypair)
29
+ end
30
+
31
+ attr_reader :keypair, :id
32
+
33
+ # @param [Stellar::KeyPair] keypair
34
+ # @param [Integer] id
35
+ def initialize(keypair, id = nil)
36
+ @keypair = keypair
37
+ @id = id
38
+ end
39
+
40
+ def base_account
41
+ Stellar::MuxedAccount.ed25519(keypair.raw_public_key)
42
+ end
43
+
44
+ def muxed_account
45
+ return base_account unless id
46
+ Stellar::MuxedAccount.med25519(ed25519: keypair.raw_public_key, id: id)
47
+ end
48
+
49
+ def address(force_account_id: true)
50
+ return keypair.address if force_account_id
51
+
52
+ Util::StrKey.check_encode(:muxed, keypair.raw_public_key + [id].pack("Q>"))
53
+ end
54
+
55
+ def to_keypair
56
+ keypair
57
+ end
58
+ end
59
+ end
@@ -2,8 +2,10 @@ class << Stellar::Operation
2
2
  alias_method :manage_offer, :manage_sell_offer
3
3
  alias_method :create_passive_offer, :create_passive_sell_offer
4
4
 
5
- deprecate deprecator: Stellar::Deprecation,
6
- manage_offer: :manage_sell_offer,
7
- create_passive_offer: :create_passive_sell_offer,
8
- allow_trust: :set_trust_line_flags
5
+ deprecate(
6
+ deprecator: Stellar::Deprecation,
7
+ manage_offer: :manage_sell_offer,
8
+ create_passive_offer: :create_passive_sell_offer,
9
+ allow_trust: :set_trust_line_flags
10
+ )
9
11
  end
data/lib/stellar/dsl.rb CHANGED
@@ -27,6 +27,25 @@ module Stellar
27
27
  )
28
28
  end
29
29
 
30
+ def Account(subject = nil)
31
+ case subject
32
+ when Account
33
+ subject
34
+ when /^M[A-Z0-9]{68}$/
35
+ Account.from_address(subject.to_str)
36
+ when nil
37
+ Account.random
38
+ else
39
+ begin
40
+ keypair = KeyPair(subject)
41
+
42
+ Account.new(keypair)
43
+ rescue TypeError
44
+ raise TypeError, "Cannot convert #{subject.inspect} to Stellar::Account"
45
+ end
46
+ end
47
+ end
48
+
30
49
  # @param [Asset, String, nil] subject
31
50
  # @return [Stellar::Asset] instance of the Stellar::Asset
32
51
  # @raise [TypeError] if subject cannot be converted to Stellar::Asset
@@ -1,5 +1,7 @@
1
1
  module Stellar
2
2
  class TransactionBuilder
3
+ include Stellar::DSL
4
+
3
5
  attr_reader :source_account, :sequence_number, :base_fee, :time_bounds, :memo, :operations
4
6
 
5
7
  class << self
@@ -29,21 +31,20 @@ module Stellar
29
31
  base_fee: 100,
30
32
  time_bounds: nil,
31
33
  memo: nil,
34
+ enable_muxed_accounts: false,
32
35
  **_ # ignore any additional parameters without errors
33
36
  )
34
- raise ArgumentError, "Bad :source_account" unless source_account.is_a?(Stellar::KeyPair)
35
37
  raise ArgumentError, "Bad :sequence_number" unless sequence_number.is_a?(Integer) && sequence_number >= 0
36
38
  raise ArgumentError, "Bad :time_bounds" unless time_bounds.is_a?(Stellar::TimeBounds) || time_bounds.nil?
37
39
  raise ArgumentError, "Bad :base_fee" unless base_fee.is_a?(Integer) && base_fee >= 100
38
40
 
39
- @source_account = source_account
41
+ @source_account = Account(source_account)
40
42
  @sequence_number = sequence_number
41
43
  @base_fee = base_fee
42
44
  @time_bounds = time_bounds
45
+ @enable_muxed_accounts = enable_muxed_accounts
43
46
 
44
- if time_bounds.nil?
45
- set_timeout(0)
46
- end
47
+ set_timeout(0) if time_bounds.nil?
47
48
 
48
49
  @memo = make_memo(memo)
49
50
  @operations = []
@@ -59,7 +60,7 @@ module Stellar
59
60
  end
60
61
 
61
62
  attrs = {
62
- source_account: @source_account.muxed_account,
63
+ source_account: source_muxed_account,
63
64
  fee: @base_fee * @operations.length,
64
65
  seq_num: @sequence_number,
65
66
  time_bounds: @time_bounds,
@@ -90,7 +91,7 @@ module Stellar
90
91
  end
91
92
 
92
93
  Stellar::FeeBumpTransaction.new(
93
- fee_source: @source_account.muxed_account,
94
+ fee_source: source_muxed_account,
94
95
  fee: @base_fee * (inner_ops.length + 1),
95
96
  inner_tx: Stellar::FeeBumpTransaction::InnerTx.new(:envelope_type_tx, inner_txe.v1!),
96
97
  ext: Stellar::FeeBumpTransaction::Ext.new(0)
@@ -162,5 +163,17 @@ module Stellar
162
163
  raise ArgumentError, "Bad :memo"
163
164
  end
164
165
  end
166
+
167
+ def source_muxed_account
168
+ if with_muxed_accounts?
169
+ @source_account.muxed_account
170
+ else
171
+ @source_account.base_account
172
+ end
173
+ end
174
+
175
+ def with_muxed_accounts?
176
+ @enable_muxed_accounts
177
+ end
165
178
  end
166
179
  end
@@ -8,7 +8,8 @@ module Stellar
8
8
  account_id: [6 << 3].pack("C"), # Base32-encodes to 'G...'
9
9
  seed: [18 << 3].pack("C"), # Base32-encodes to 'S...'
10
10
  pre_auth_tx: [19 << 3].pack("C"), # Base32-encodes to 'T...'
11
- hash_x: [23 << 3].pack("C") # Base32-encodes to 'X...'
11
+ hash_x: [23 << 3].pack("C"), # Base32-encodes to 'X...'
12
+ muxed: [12 << 3].pack("C") # Base32-encodes to 'M...'
12
13
  }
13
14
 
14
15
  def self.check_encode(version, byte_str)
@@ -25,13 +26,11 @@ module Stellar
25
26
  # @param muxed_account [Stellar::MuxedAccount] account
26
27
  # @return [String] "G.."-like address
27
28
  def self.encode_muxed_account(muxed_account)
28
- ed25519 = if muxed_account.switch == Stellar::CryptoKeyType.key_type_ed25519
29
- muxed_account.ed25519!
29
+ if muxed_account.ed25519
30
+ check_encode(:account_id, muxed_account.ed25519)
30
31
  else
31
- muxed_account.med25519!.ed25519
32
+ check_encode(:muxed, muxed_account.med25519!.ed25519 + [muxed_account.med25519!.id].pack("Q>"))
32
33
  end
33
-
34
- check_encode(:account_id, ed25519)
35
34
  end
36
35
 
37
36
  # Returns a Stellar::MuxedAccount, forcing the ed25519 discriminant
@@ -39,7 +38,16 @@ module Stellar
39
38
  # @param strkey [String] address string to decode
40
39
  # @return [Stellar::MuxedAccount] MuxedAccount with ed25519 discriminant
41
40
  def self.decode_muxed_account(strkey)
42
- Stellar::MuxedAccount.new(:key_type_ed25519, check_decode(:account_id, strkey))
41
+ case strkey
42
+ when /^G[0-9A-Z]{55}$/
43
+ ed25519 = check_decode(:account_id, strkey)
44
+ Stellar::MuxedAccount.ed25519(ed25519)
45
+ when /^M[0-9A-Z]{68}$/
46
+ payload = check_decode(:muxed, strkey)
47
+ Stellar::MuxedAccount.med25519(ed25519: payload[0, 32], id: payload[32, 8].unpack1("Q>"))
48
+ else
49
+ raise "cannot decode MuxedAccount from #{strkey}"
50
+ end
43
51
  end
44
52
 
45
53
  def self.check_decode(expected_version, str)
@@ -1,3 +1,3 @@
1
1
  module Stellar
2
- VERSION = "0.27.0"
2
+ VERSION = "0.28.0"
3
3
  end
metadata CHANGED
@@ -1,16 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar-base
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.27.0
4
+ version: 0.28.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
8
8
  - Sergey Nebolsin
9
9
  - Timur Ramazanov
10
- autorequire:
10
+ autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2021-05-09 00:00:00.000000000 Z
13
+ date: 2021-07-20 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: activesupport
@@ -171,7 +171,7 @@ dependencies:
171
171
  description: |
172
172
  The stellar-base library is the lowest-level stellar helper library. It consists of classes to read, write,
173
173
  hash, and sign the xdr structures that are used in stellar-core.
174
- email:
174
+ email:
175
175
  executables: []
176
176
  extensions: []
177
177
  extra_rdoc_files:
@@ -415,6 +415,7 @@ files:
415
415
  - generated/stellar/trust_line_flags.rb
416
416
  - generated/stellar/upgrade_entry_meta.rb
417
417
  - lib/stellar-base.rb
418
+ - lib/stellar/account.rb
418
419
  - lib/stellar/account_flags.rb
419
420
  - lib/stellar/asset.rb
420
421
  - lib/stellar/base.rb
@@ -447,12 +448,12 @@ licenses:
447
448
  - Apache-2.0
448
449
  metadata:
449
450
  bug_tracker_uri: https://github.com/astroband/ruby-stellar-sdk/issues
450
- changelog_uri: https://github.com/astroband/ruby-stellar-sdk/blob/v0.27.0/base/CHANGELOG.md
451
- documentation_uri: https://rubydoc.info/gems/stellar-base/0.27.0/
451
+ changelog_uri: https://github.com/astroband/ruby-stellar-sdk/blob/v0.28.0/base/CHANGELOG.md
452
+ documentation_uri: https://rubydoc.info/gems/stellar-base/0.28.0/
452
453
  github_repo: ssh://github.com/astroband/ruby-stellar-sdk
453
454
  homepage_uri: https://github.com/astroband/ruby-stellar-sdk/tree/main/base
454
- source_code_uri: https://github.com/astroband/ruby-stellar-sdk/tree/v0.27.0/base
455
- post_install_message:
455
+ source_code_uri: https://github.com/astroband/ruby-stellar-sdk/tree/v0.28.0/base
456
+ post_install_message:
456
457
  rdoc_options: []
457
458
  require_paths:
458
459
  - generated
@@ -468,8 +469,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
468
469
  - !ruby/object:Gem::Version
469
470
  version: '0'
470
471
  requirements: []
471
- rubygems_version: 3.2.16
472
- signing_key:
472
+ rubygems_version: 3.2.22
473
+ signing_key:
473
474
  specification_version: 4
474
475
  summary: 'Stellar client library: XDR'
475
476
  test_files: []