stellar-sdk 0.25.0 → 0.29.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 14f9e7a13e44b5eb83bce5faee3918a49c03cfd9d36f00b49cdec501131702bc
4
- data.tar.gz: cbf8145d6a546359ba66f74bc868cc1f5c6bf82a0e1c077d6073ef242f3989ef
3
+ metadata.gz: 3829133758963683cfff3f2132c55d8bf53540bd731d9cb2e619d2ae36012112
4
+ data.tar.gz: d2ec22a621018102dc93c9cb6e89dbaa5029ef29ec4d1b85f5b6cf6a8b1a8ccb
5
5
  SHA512:
6
- metadata.gz: a1a999329ba74c3a0448c59c4d249c4fecdc1b0961dbc82ba985f8b3fb792b993825a1eabd2df8918566ac1b7f1ca847572a381d61c0194aa8f48cc50fdea6e4
7
- data.tar.gz: b4c7f193cd7fef55798e4788476e30898c2b8517981ad4d05da2c9ac7a1ab4758e5287700cd017b1c62cd97e995b6f645dc15ef9cff22d0cc061aeb85375dfe7
6
+ metadata.gz: 53958e7a613b1a8cfa6b7a36a505c3820337b5a696bc16bfe7b7d3da9060fee01b0dd1afd61f4c48cb2eeee8c6a9b8b3b71d75b39afc1681b985a2a266af6231
7
+ data.tar.gz: b235706bc0f6d4b92298a43dae775d9b7210028c1306171ffd65212478addc929f760e0f6421e795c77d2e58570e6aa81d7665f5d93005695e1c4271e6e074f2
data/CHANGELOG.md CHANGED
@@ -1,12 +1,35 @@
1
1
  # Change Log
2
+
2
3
  All notable changes to this project will be documented in this file.
3
4
 
4
5
  The format is based on [Keep a Changelog](http://keepachangelog.com/)
5
6
  and this project adheres to [Semantic Versioning](http://semver.org/).
6
7
 
7
- ## [Unreleased](https://github.com/stellar/ruby-stellar-sdk/compare/v0.25.0...master)
8
+ ## [0.29.0](https://www.github.com/astroband/ruby-stellar-sdk/compare/v0.28.0...v0.29.0) (2021-09-07)
9
+
10
+ ### Added
11
+ * support for client domain in SEP-10
12
+ ### Deprecated
13
+ * `Stellar::Client` class is marked as deprecated in favour of new `stellar-horizon` gem
14
+
15
+ ## [0.28.0](https://www.github.com/astroband/ruby-stellar-sdk/compare/v0.27.0...v0.28.0) (2021-07-17)
16
+
17
+ ### Changed
18
+ * `Stellar::Account` class is now part of `stellar-base` gem
19
+ * `Stellar::Account.lookup` is deprecated, use `Stellar::Federation.lookup` instead
20
+
21
+ ## [0.27.0](https://github.com/astroband/ruby-stellar-sdk/compare/v0.26.0...v0.27.0) (2021-05-08)
22
+ - No changes
23
+
24
+ ## [0.26.0](https://github.com/astroband/ruby-stellar-sdk/compare/v0.25.0...v0.26.0) - 2021-02-05
25
+ ### Changed
26
+ - `Stellar::SEP10` is updated to comply with SEP10 v3.0.0 and v3.1.0
27
+ - `read_challenge_tx`` now verifies `domain` in challenge auth operation, as per SEP10 v3.0.0
28
+ - it is now possible to provide `auth_domain` parameter to enforce auth server domain verification:
29
+ - `build_challenge_tx` will encode the extra auth domain operation into the challenge tx
30
+ - `read_challenge_tx` will verify that the challenge includes the correct auth domain operation
8
31
 
9
- ## [0.25.0](https://github.com/stellar/ruby-stellar-sdk/compare/v0.24.0...0.25.0)
32
+ ## [0.25.0](https://github.com/astroband/ruby-stellar-sdk/compare/v0.24.0...v0.25.0) - 2020-10-30
10
33
  ### Changed
11
34
  - `Stellar::SEP10` is updated to comply with SEP10 v2.1.0
12
35
  - `build_challenge_tx` now accepts `domain` instead of `anchor_name`, using the
@@ -16,25 +39,25 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
16
39
  ### Removed:
17
40
  - Deprecated `Stellar::SEP10.verify_challenge_tx` method is removed
18
41
 
19
- ## [0.24.0](https://github.com/stellar/ruby-stellar-sdk/compare/v0.23.1...v0.24.0) - 2020-10-20
42
+ ## [0.24.0](https://github.com/astroband/ruby-stellar-sdk/compare/v0.23.1...v0.24.0) - 2020-10-20
20
43
  - Protocol 14 support
21
44
 
22
- ## [0.23.1](https://github.com/stellar/ruby-stellar-sdk/compare/v0.23.0...v0.23.1) - 2020-06-18
45
+ ## [0.23.1](https://github.com/astroband/ruby-stellar-sdk/compare/v0.23.0...v0.23.1) - 2020-06-18
23
46
  - Fix SEP10, considering muxed accounts
24
47
 
25
- ## [0.23.0](https://github.com/stellar/ruby-stellar-sdk/compare/v0.9.0...v0.23.0)
48
+ ## [0.23.0](https://github.com/astroband/ruby-stellar-sdk/compare/v0.9.0-rc.1...v0.23.0)
26
49
  - No changes. We bumped this version to sync `stellar-sdk` and `stellar-base` versions
27
50
 
28
- ## [0.9.0](https://github.com/stellar/ruby-stellar-sdk/compare/v0.9.0...v0.8.0)
51
+ ## [0.9.0](https://github.com/astroband/ruby-stellar-sdk/compare/v0.8.0...v0.9.0-rc.1)
29
52
  ### Added
30
53
  - Stellar Protocol 13 support
31
54
  - Fee-Bump transactions ([CAP-0015](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0015.md))
32
55
  - Multiplexed accounts ([CAP-0027](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0027.md))
33
56
  - Fine-Grained control on trustline authorization ([CAP-0018](https://github.com/stellar/stellar-protocol/blob/master/core/cap-0018.md))
34
57
 
35
- ## [0.8.0](https://github.com/stellar/ruby-stellar-sdk/compare/v0.7.0...v0.8.0)
58
+ ## [0.8.0](https://github.com/astroband/ruby-stellar-sdk/compare/v0.7.0...v0.8.0)
36
59
  ### Added
37
- - SEP-10 Multisig Support [#69](https://github.com/stellar/ruby-stellar-sdk/pull/69)
60
+ - SEP-10 Multisig Support [#69](https://github.com/astroband/ruby-stellar-sdk/pull/69)
38
61
  - `X-Client-Name` and `X-Client-Version` headers
39
62
 
40
63
  ## [0.7.0] - 2019-04-26
data/README.md CHANGED
@@ -39,7 +39,7 @@ client.send_payment({
39
39
  })
40
40
  ```
41
41
 
42
- Be sure to set the network when submitting to the public network (more information in [stellar-base](https://www.github.com/bloom-solutions/ruby-stellar-base)):
42
+ Be sure to set the network when submitting to the public network (more information in [stellar-base](https://www.github.com/astroband/ruby-stellar-base)):
43
43
 
44
44
  ```ruby
45
45
  Stellar.default_network = Stellar::Networks::PUBLIC
@@ -57,7 +57,7 @@ Stellar.default_network = Stellar::Networks::PUBLIC
57
57
  ## Contributing
58
58
 
59
59
  1. Sign the [Contributor License Agreement](https://docs.google.com/forms/d/1g7EF6PERciwn7zfmfke5Sir2n10yddGGSXyZsq98tVY/viewform?usp=send_form)
60
- 2. Fork it ( https://github.com/bloom-solutions/ruby-stellar-lib/fork )
60
+ 2. Fork it ( https://github.com/astroband/ruby-stellar-sdk/fork )
61
61
  2. Create your feature branch (`git checkout -b my-new-feature`)
62
62
  3. Commit your changes (`git commit -am 'Add some feature'`)
63
63
  4. Push to the branch (`git push origin my-new-feature`)
@@ -44,6 +44,8 @@ module Stellar
44
44
 
45
45
  # @option options [String] :horizon The Horizon server URL.
46
46
  def initialize(options)
47
+ ActiveSupport::Deprecation.warn("`Stellar::Horizon` is deprecated and will be removed from `stellar-sdk` next relase. Use `stellar-horizon` gem for requesting Horizon API")
48
+
47
49
  @options = options
48
50
  @horizon = Hyperclient.new(options[:horizon]) { |client|
49
51
  client.faraday_block = lambda do |conn|
@@ -0,0 +1,4 @@
1
+ class << Stellar::Account
2
+ delegate :lookup, to: Stellar::Federation
3
+ deprecate deprecator: Stellar::Deprecation, lookup: "Use `Stellar::Federation.lookup` method"
4
+ end
@@ -0,0 +1,51 @@
1
+ require "toml-rb"
2
+ require "uri"
3
+ require "faraday"
4
+ require "json"
5
+
6
+ module Stellar
7
+ class Federation
8
+ def self.lookup(federated_name)
9
+ _, domain = federated_name.split("*")
10
+ if domain.nil?
11
+ raise InvalidFederationAddress.new
12
+ end
13
+
14
+ domain_req = Faraday.new("https://#{domain}/.well-known/stellar.toml").get
15
+
16
+ unless domain_req.status == 200
17
+ raise InvalidStellarDomain, "Domain does not contain stellar.toml file"
18
+ end
19
+
20
+ fed_server_url = TomlRB.parse(domain_req.body)["FEDERATION_SERVER"]
21
+ if fed_server_url.nil?
22
+ raise InvalidStellarTOML, "Invalid Stellar TOML file"
23
+ end
24
+
25
+ unless fed_server_url&.match?(URI::DEFAULT_PARSER.make_regexp)
26
+ raise InvalidFederationURL, "Invalid Federation Server URL"
27
+ end
28
+
29
+ lookup_req = Faraday.new(fed_server_url).get { |req|
30
+ req.params[:q] = federated_name
31
+ req.params[:type] = "name"
32
+ }
33
+
34
+ unless lookup_req.status == 200
35
+ raise AccountNotFound, "Account not found"
36
+ end
37
+
38
+ JSON.parse(lookup_req.body)["account_id"]
39
+ end
40
+ end
41
+
42
+ class AccountNotFound < StandardError; end
43
+
44
+ class InvalidStellarTOML < StandardError; end
45
+
46
+ class InvalidFederationAddress < StandardError; end
47
+
48
+ class InvalidStellarDomain < StandardError; end
49
+
50
+ class InvalidFederationURL < StandardError; end
51
+ end
data/lib/stellar/sep10.rb CHANGED
@@ -30,10 +30,6 @@ module Stellar
30
30
  MSG
31
31
  domain = options[:anchor_name]
32
32
  end
33
- # The value must be 64 bytes long. It contains a 48 byte
34
- # cryptographic-quality random string encoded using base64 (for a total of
35
- # 64 bytes after encoding).
36
- value = SecureRandom.base64(48)
37
33
 
38
34
  now = Time.now.to_i
39
35
  time_bounds = Stellar::TimeBounds.new(
@@ -41,19 +37,48 @@ module Stellar
41
37
  max_time: now + timeout
42
38
  )
43
39
 
44
- tx = Stellar::TransactionBuilder.new(
40
+ tb = Stellar::TransactionBuilder.new(
45
41
  source_account: server,
46
42
  sequence_number: 0,
47
43
  time_bounds: time_bounds
48
- ).add_operation(
44
+ )
45
+
46
+ # The value must be 64 bytes long. It contains a 48 byte
47
+ # cryptographic-quality random string encoded using base64 (for a total of
48
+ # 64 bytes after encoding).
49
+ tb.add_operation(
49
50
  Stellar::Operation.manage_data(
50
51
  name: "#{domain} auth",
51
- value: value,
52
+ value: SecureRandom.base64(48),
52
53
  source_account: client
53
54
  )
54
- ).build
55
+ )
56
+
57
+ if options.key?(:auth_domain)
58
+ tb.add_operation(
59
+ Stellar::Operation.manage_data(
60
+ name: "web_auth_domain",
61
+ value: options[:auth_domain],
62
+ source_account: server
63
+ )
64
+ )
65
+ end
66
+
67
+ if options[:client_domain].present?
68
+ if options[:client_domain_account].blank?
69
+ raise "`client_domain_account` is required, if `client_domain` is provided"
70
+ end
71
+
72
+ tb.add_operation(
73
+ Stellar::Operation.manage_data(
74
+ name: "client_domain",
75
+ value: options[:client_domain],
76
+ source_account: options[:client_domain_account]
77
+ )
78
+ )
79
+ end
55
80
 
56
- tx.to_envelope(server).to_xdr(:base64)
81
+ tb.build.to_envelope(server).to_xdr(:base64)
57
82
  end
58
83
 
59
84
  # Reads a SEP 10 challenge transaction and returns the decoded transaction envelope and client account ID contained within.
@@ -68,8 +93,8 @@ module Stellar
68
93
  # @example
69
94
  # sep10 = Stellar::SEP10
70
95
  # server = Stellar::KeyPair.random # this should be the SIGNING_KEY from your stellar.toml
71
- # challenge = sep10.build_challenge_tx(server: server, client: user, home_domain: domain, timeout: timeout)
72
- # envelope, client_address = sep10.read_challenge_tx(server: server, challenge: challenge)
96
+ # challenge = sep10.build_challenge_tx(server: server, client: user, domain: domain, timeout: timeout)
97
+ # envelope, client_address = sep10.read_challenge_tx(server: server, challenge_xdr: challenge)
73
98
  #
74
99
  # @param challenge_xdr [String] SEP0010 transaction challenge in base64.
75
100
  # @param server [Stellar::KeyPair] keypair for server where the challenge was generated.
@@ -94,7 +119,9 @@ module Stellar
94
119
  auth_op, *rest_ops = transaction.operations
95
120
  client_account_id = auth_op.source_account
96
121
 
97
- if client_account_id.nil?
122
+ auth_op_body = auth_op.body.value
123
+
124
+ if client_account_id.blank?
98
125
  raise InvalidSep10ChallengeError, "The transaction's operation should contain a source account"
99
126
  end
100
127
 
@@ -102,15 +129,24 @@ module Stellar
102
129
  raise InvalidSep10ChallengeError, "The transaction's first operation should be manageData"
103
130
  end
104
131
 
105
- if auth_op.body.value.data_value.unpack1("m").size != 48
132
+ if options.key?(:domain) && auth_op_body.data_name != "#{options[:domain]} auth"
133
+ raise InvalidSep10ChallengeError, "The transaction's operation data name is invalid"
134
+ end
135
+
136
+ if auth_op_body.data_value.unpack1("m").size != 48
106
137
  raise InvalidSep10ChallengeError, "The transaction's operation value should be a 64 bytes base64 random string"
107
138
  end
108
139
 
109
140
  rest_ops.each do |op|
110
- if op.body.arm != :manage_data_op
141
+ body = op.body
142
+ op_params = body.value
143
+
144
+ if body.arm != :manage_data_op
111
145
  raise InvalidSep10ChallengeError, "The transaction has operations that are not of type 'manageData'"
112
- elsif op.source_account != server.muxed_account
146
+ elsif op.source_account != server.muxed_account && op_params.data_name != "client_domain"
113
147
  raise InvalidSep10ChallengeError, "The transaction has operations that are unrecognized"
148
+ elsif op_params.data_name == "web_auth_domain" && options.key?(:auth_domain) && op_params.data_value != options[:auth_domain]
149
+ raise InvalidSep10ChallengeError, "The transaction has 'manageData' operation with 'web_auth_domain' key and invalid value"
114
150
  end
115
151
  end
116
152
 
@@ -121,7 +157,7 @@ module Stellar
121
157
  time_bounds = transaction.time_bounds
122
158
  now = Time.now.to_i
123
159
 
124
- if time_bounds.nil? || !now.between?(time_bounds.min_time, time_bounds.max_time)
160
+ if time_bounds.blank? || !now.between?(time_bounds.min_time, time_bounds.max_time)
125
161
  raise InvalidSep10ChallengeError, "The transaction has expired"
126
162
  end
127
163
 
@@ -186,6 +222,9 @@ module Stellar
186
222
  client_signers = signers.select { |s| s =~ /G[A-Z0-9]{55}/ && s != server.address }.to_set
187
223
  raise InvalidSep10ChallengeError, "at least one regular signer must be provided" if client_signers.empty?
188
224
 
225
+ client_domain_account_address = extract_client_domain_account(te.tx)
226
+ client_signers.add(client_domain_account_address) if client_domain_account_address.present?
227
+
189
228
  # verify all signatures in one pass
190
229
  client_signers.add(server.address)
191
230
  signers_found = verify_tx_signatures(tx_envelope: te, signers: client_signers)
@@ -205,6 +244,10 @@ module Stellar
205
244
  raise InvalidSep10ChallengeError, "Transaction has unrecognized signatures."
206
245
  end
207
246
 
247
+ if client_domain_account_address.present? && !signers_found.include?(client_domain_account_address)
248
+ raise InvalidSep10ChallengeError, "Transaction not signed by client domain account."
249
+ end
250
+
208
251
  signers_found
209
252
  end
210
253
 
@@ -225,7 +268,7 @@ module Stellar
225
268
  to_keypair = Stellar::DSL.method(:KeyPair)
226
269
  keys_by_hint = signers.map(&to_keypair).index_by(&:signature_hint)
227
270
 
228
- tx_envelope.signatures.each.with_object(Set.new) do |sig, result|
271
+ signatures.each_with_object(Set.new) do |sig, result|
229
272
  key = keys_by_hint.delete(sig.hint)
230
273
  result.add(key.address) if key&.verify(sig.signature, tx_hash)
231
274
  end
@@ -248,5 +291,16 @@ module Stellar
248
291
  keypair.verify(sig.signature, tx_hash)
249
292
  end
250
293
  end
294
+
295
+ def self.extract_client_domain_account(transaction)
296
+ client_domain_account_op =
297
+ transaction
298
+ .operations
299
+ .find { |op| op.body.value.data_name == "client_domain" }
300
+
301
+ return if client_domain_account_op.blank?
302
+
303
+ Util::StrKey.encode_muxed_account(client_domain_account_op.source_account)
304
+ end
251
305
  end
252
306
  end
data/lib/stellar-sdk.rb CHANGED
@@ -1,10 +1,13 @@
1
1
  require "stellar-base"
2
- require_relative "stellar/sdk/version"
3
2
 
4
3
  module Stellar
5
- autoload :Account
4
+ module SDK
5
+ VERSION = ::Stellar::VERSION
6
+ end
7
+
6
8
  autoload :Amount
7
9
  autoload :Client
10
+ autoload :Federation
8
11
  autoload :SEP10
9
12
 
10
13
  module Horizon
@@ -16,3 +19,5 @@ module Stellar
16
19
 
17
20
  autoload :TransactionPage
18
21
  end
22
+
23
+ require_relative "stellar/compat"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stellar-sdk
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.25.0
4
+ version: 0.29.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Scott Fleckenstein
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-10-30 00:00:00.000000000 Z
13
+ date: 2021-09-07 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: stellar-base
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 0.25.0
21
+ version: 0.29.0
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 0.25.0
28
+ version: 0.29.0
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: activesupport
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -75,7 +75,7 @@ dependencies:
75
75
  version: 0.7.0
76
76
  - - "<"
77
77
  - !ruby/object:Gem::Version
78
- version: '1.0'
78
+ version: '2.0'
79
79
  type: :runtime
80
80
  prerelease: false
81
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -85,7 +85,7 @@ dependencies:
85
85
  version: 0.7.0
86
86
  - - "<"
87
87
  - !ruby/object:Gem::Version
88
- version: '1.0'
88
+ version: '2.0'
89
89
  - !ruby/object:Gem::Dependency
90
90
  name: toml-rb
91
91
  requirement: !ruby/object:Gem::Requirement
@@ -112,14 +112,14 @@ dependencies:
112
112
  requirements:
113
113
  - - "~>"
114
114
  - !ruby/object:Gem::Version
115
- version: '2.0'
115
+ version: '2.2'
116
116
  type: :development
117
117
  prerelease: false
118
118
  version_requirements: !ruby/object:Gem::Requirement
119
119
  requirements:
120
120
  - - "~>"
121
121
  - !ruby/object:Gem::Version
122
- version: '2.0'
122
+ version: '2.2'
123
123
  - !ruby/object:Gem::Dependency
124
124
  name: rake
125
125
  requirement: !ruby/object:Gem::Requirement
@@ -161,21 +161,23 @@ files:
161
161
  - LICENSE
162
162
  - README.md
163
163
  - lib/stellar-sdk.rb
164
- - lib/stellar/account.rb
165
164
  - lib/stellar/amount.rb
166
165
  - lib/stellar/client.rb
166
+ - lib/stellar/compat.rb
167
+ - lib/stellar/federation.rb
167
168
  - lib/stellar/horizon/problem.rb
168
- - lib/stellar/sdk/version.rb
169
169
  - lib/stellar/sep10.rb
170
170
  - lib/stellar/transaction_page.rb
171
- homepage: https://github.com/stellar/ruby-stellar-sdk/tree/master/sdk
171
+ homepage: https://github.com/astroband/ruby-stellar-sdk
172
172
  licenses:
173
173
  - Apache-2.0
174
174
  metadata:
175
+ bug_tracker_uri: https://github.com/astroband/ruby-stellar-sdk/issues
176
+ changelog_uri: https://github.com/astroband/ruby-stellar-sdk/blob/v0.29.0/sdk/CHANGELOG.md
177
+ documentation_uri: https://rubydoc.info/gems/stellar-sdk/0.29.0/
175
178
  github_repo: ssh://github.com/astroband/ruby-stellar-sdk
176
- documentation_uri: https://rubydoc.info/gems/stellar-sdk/0.25.0/
177
- changelog_uri: https://github.com/astroband/ruby-stellar-sdk/blob/v0.25.0/sdk/CHANGELOG.md
178
- source_code_uri: https://github.com/astroband/ruby-stellar-sdk/tree/v0.25.0/sdk
179
+ homepage_uri: https://github.com/astroband/ruby-stellar-sdk/tree/main/sdk
180
+ source_code_uri: https://github.com/astroband/ruby-stellar-sdk/tree/v0.29.0/sdk
179
181
  post_install_message:
180
182
  rdoc_options: []
181
183
  require_paths:
@@ -191,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
191
193
  - !ruby/object:Gem::Version
192
194
  version: '0'
193
195
  requirements: []
194
- rubygems_version: 3.2.0.rc.2
196
+ rubygems_version: 3.1.4
195
197
  signing_key:
196
198
  specification_version: 4
197
199
  summary: Stellar client library
@@ -1,89 +0,0 @@
1
- require "toml-rb"
2
- require "uri"
3
- require "faraday"
4
- require "json"
5
-
6
- module Stellar
7
- class Account
8
- delegate :address, to: :keypair
9
-
10
- def self.random
11
- keypair = Stellar::KeyPair.random
12
- new(keypair)
13
- end
14
-
15
- def self.from_seed(seed)
16
- keypair = Stellar::KeyPair.from_seed(seed)
17
- new(keypair)
18
- end
19
-
20
- def self.from_address(address)
21
- keypair = Stellar::KeyPair.from_address(address)
22
- new(keypair)
23
- end
24
-
25
- def self.lookup(federated_name)
26
- _, domain = federated_name.split("*")
27
- if domain.nil?
28
- raise InvalidFederationAddress.new
29
- end
30
-
31
- domain_req = Faraday.new("https://#{domain}/.well-known/stellar.toml").get
32
-
33
- unless domain_req.status == 200
34
- raise InvalidStellarDomain.new("Domain does not contain stellar.toml file")
35
- end
36
-
37
- fed_server_url = TomlRB.parse(domain_req.body)["FEDERATION_SERVER"]
38
- if fed_server_url.nil?
39
- raise InvalidStellarTOML.new("Invalid Stellar TOML file")
40
- end
41
-
42
- unless fed_server_url&.match?(URI::DEFAULT_PARSER.make_regexp)
43
- raise InvalidFederationURL.new("Invalid Federation Server URL")
44
- end
45
-
46
- lookup_req = Faraday.new(fed_server_url).get { |req|
47
- req.params[:q] = federated_name
48
- req.params[:type] = "name"
49
- }
50
-
51
- unless lookup_req.status == 200
52
- raise AccountNotFound.new("Account not found")
53
- end
54
-
55
- JSON.parse(lookup_req.body)["account_id"]
56
- end
57
-
58
- def self.master
59
- keypair = Stellar::KeyPair.from_raw_seed("allmylifemyhearthasbeensearching")
60
- new(keypair)
61
- end
62
-
63
- attr_reader :keypair
64
-
65
- # @param [Stellar::KeyPair] keypair
66
- def initialize(keypair)
67
- @keypair = keypair
68
- end
69
-
70
- def to_keypair
71
- keypair
72
- end
73
- end
74
-
75
- class AccountNotFound < StandardError
76
- end
77
-
78
- class InvalidStellarTOML < StandardError
79
- end
80
-
81
- class InvalidFederationAddress < StandardError
82
- end
83
-
84
- class InvalidStellarDomain < StandardError
85
- end
86
-
87
- class InvalidFederationURL < StandardError
88
- end
89
- end
@@ -1,5 +0,0 @@
1
- module Stellar
2
- module SDK
3
- VERSION = "0.25.0"
4
- end
5
- end