{"id":25948833,"url":"https://github.com/mobius-network/mobius-client-ruby","last_synced_at":"2025-07-25T22:38:26.286Z","repository":{"id":56884128,"uuid":"125530670","full_name":"mobius-network/mobius-client-ruby","owner":"mobius-network","description":"Mobius Ruby API","archived":false,"fork":false,"pushed_at":"2019-05-01T21:32:14.000Z","size":175,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":10,"default_branch":"master","last_synced_at":"2024-04-23T15:43:26.713Z","etag":null,"topics":["blockchain","blockchain-service","dapps","mobius-dapp-store","payment","ruby","stellar"],"latest_commit_sha":null,"homepage":"","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/mobius-network.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-03-16T14:54:28.000Z","updated_at":"2022-04-14T03:11:58.000Z","dependencies_parsed_at":"2022-08-20T22:31:09.018Z","dependency_job_id":null,"html_url":"https://github.com/mobius-network/mobius-client-ruby","commit_stats":null,"previous_names":[],"tags_count":11,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobius-network%2Fmobius-client-ruby","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobius-network%2Fmobius-client-ruby/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobius-network%2Fmobius-client-ruby/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/mobius-network%2Fmobius-client-ruby/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/mobius-network","download_url":"https://codeload.github.com/mobius-network/mobius-client-ruby/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":241787483,"owners_count":20020099,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["blockchain","blockchain-service","dapps","mobius-dapp-store","payment","ruby","stellar"],"created_at":"2025-03-04T11:24:30.820Z","updated_at":"2025-03-04T11:24:31.540Z","avatar_url":"https://github.com/mobius-network.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"[![Gem Version](https://badge.fury.io/rb/mobius-client.svg)](https://badge.fury.io/rb/mobius-client)\n[![Build Status](https://travis-ci.org/mobius-network/mobius-client-ruby.svg?branch=master)](https://travis-ci.org/mobius-network/mobius-client-ruby)\n[![Maintainability](https://api.codeclimate.com/v1/badges/f6810e8244fc0dceb5bd/maintainability)](https://codeclimate.com/github/mobius-network/mobius-client-ruby/maintainability)\n[![Test Coverage](https://api.codeclimate.com/v1/badges/f6810e8244fc0dceb5bd/test_coverage)](https://codeclimate.com/github/mobius-network/mobius-client-ruby/test_coverage)\n\n# Mobius DApp Store Ruby SDK\n\nThe Mobius DApp Store Ruby SDK makes it easy to integrate Mobius DApp Store MOBI payments into any Ruby application.\n\nA big advantage of the Mobius DApp Store over centralized competitors such as the Apple App Store or Google Play Store is significantly lower fees - currently 0% compared to 30% - for in-app purchases.\n\n## DApp Store Overview\n\nThe Mobius DApp Store will be an open-source, non-custodial \"wallet\" interface for easily sending crypto payments to apps. You can think of the DApp Store like https://stellarterm.com/ or https://www.myetherwallet.com/ but instead of a wallet interface it is an App Store interface.\n\nThe DApp Store is non-custodial meaning Mobius never holds the secret key of either the user or developer.\n\nAn overview of the DApp Store architecture is:\n\n- Every application holds the private key for the account where it receives MOBI.\n- An application specific unique account where a user deposits MOBI for use with the application is generated for each app based on the user's seed phrase.\n- When a user opens an app through the DApp Store:\n  1) Adds the application's public key as a signer so the application can access the MOBI and\n  2) Signs a challenge transaction from the app with its secret key to authenticate that this user owns the account. This prevents a different person from pretending they own the account and spending the MOBI (more below under Authentication).\n\n## Sample Application\n\n[Flappy Bird](https://github.com/mobius-network/flappy-bird-dapp) has been reimplemented using this new arhictecture and the above simple server code!\n\n## Documentation\n\n[[RDoc.info](http://www.rubydoc.info/github/mobius-network/mobius-client-ruby/master)]\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'mobius-client'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself with:\n\n    $ gem install mobius-client\n\n### Setting up the developer's application account\n\nRun:\n\n    $ mobius-cli create dapp-account\n\nCreates a new Stellar account with 1,000 test-net MOBI.\n\nYou can also obtain free test network MOBI from https://mobius.network/friendbot\n\n### Setting up test user accounts\n\n1. Create an empty Stellar account without a MOBI trustline.\n    ```\n      $ mobius-cli create account\n    ```\n2. Create a stellar account with 1,000 test-net MOBI\n    ```\n      $ mobius-cli create dapp-account\n    ```\n3. Create a stellar account with 1,000 test-net MOBI and the specified application public key added as a signer\n    ```\n      $ mobius-cli create dapp-account -a \u003cYour application public key\u003e\n    ```\n\n### Account Creation Wizard\n\nThe below command will create and setup the 4 account types above for testing and generate a simple HTML test interface that simulates the DApp Store authentication functionality (obtaining a challenge request from an app, signing it, and then opening the specified app passing in a JWT encoded token the application will use to verify this request is from the user that owns the specified MOBI account).\n\n```\n  $ mobius-cli create dev-wallet\n```\n\n## Production Server Setup\n\nYour production server must use HTTPS and set the below header on the `/auth` endpoint:\n\n`Access-Control-Allow-Origin: *`\n\n## Authentication\n\n### Explanation\n\nWhen a user opens an app through the DApp Store it tells the app what Mobius account it should use for payment.\n\nThe application needs to ensure that the user actually owns the secret key to the Mobius account and that this isn't a replay attack from a user who captured a previous request and is replaying it.\n\nThis authentication is accomplished through the following process:\n\n* When the user opens an app in the DApp Store it requests a challenge from the application.\n* The challenge is a payment transaction of 1 XLM from and to the application account. It is never sent to the network - it is just used for authentication.\n* The application generates the challenge transaction on request, signs it with its own private key, and sends it to user.\n* The user receives the challenge transaction and verifies it is signed by the application's secret key by checking it against the application's published public key (that it receives through the DApp Store). Then the user signs the transaction with its own private key and sends it back to application along with its public key.\n* Application checks that challenge transaction is now signed by itself and the public key that was passed in. Time bounds are also checked to make sure this isn't a replay attack. If everything passes the server replies with a token the application can pass in to \"login\" with the specified public key and use it for payment (it would have previously given the app access to the public key by adding the app's public key as a signer).\n\nNote: the challenge transaction also has time bounds to restrict the time window when it can be used.\n\nSee demo at:\n\n    $ git clone git@github.com/mobius-network/mobius-client-ruby.git\n    $ cd mobius-client-ruby \u0026\u0026 bundle\n    $ cd examples/auth \u0026\u0026 bundle \u0026\u0026 ruby auth.rb\n\n### Sample Server Implementation\n\n```ruby\nclass AuthController \u003c ApplicationController\n  skip_before_action :verify_authenticity_token, :only =\u003e [:authenticate]\n\n  # GET /auth\n  # Generates and returns challenge transaction XDR signed by application to user\n  def challenge\n    render plain: Mobius::Client::Auth::Challenge.call(\n      Rails.application.secrets.app[:secret_key], # SA2VTRSZPZ5FIC.....I4QD7LBWUUIK\n      12.hours                                    # Session duration\n    )\n  end\n\n  # POST /auth\n  # Validates challenge transaction. It must be:\n  #   - Signed by application and requesting user.\n  #   - Not older than 10 seconds from now (see Mobius::Client.strict_interval`)\n  def authenticate\n    token = Mobius::Client::Auth::Token.new(\n      Rails.application.secrets.app[:secret_key], # SA2VTRSZPZ5FIC.....I4QD7LBWUUIK\n      params[:xdr],                               # Challenge transaction\n      params[:public_key]                         # User's public key\n    )\n\n    # Important! Otherwise, token will be considered valid.\n    token.validate!\n\n    # Converts issued token into JWT and sends it to user.\n    #\n    # Note: this is not the requirement. Instead of JWT, application might save token.hash along\n    # with time frame and public key to local database and validate over it.\n    render plain: Mobius::Client::Auth::Jwt.new(\n      Rails.application.secrets.app[:jwt_secret]\n    ).encode(token)\n  rescue Mobius::Client::Error::Unauthorized\n    # Signatures are invalid\n    render plain: \"Access denied!\"\n  rescue Mobius::Client::Error::TokenExpired\n    # Current time is outside session time bounds\n    render plain: \"Session expired!\"\n  rescue Mobius::Client::Error::TokenTooOld\n    # Challenge transaction was issued more than 10 seconds ago\n    render plain: \"Challenge tx expired!\"\n  end\nend\n```\n\n## Payment\n\n### Explanation\n\nAfter the user completes the authentication process they have a token. They now pass it to the application to \"login\" which tells the application which Mobius account to withdraw MOBI from (the user public key) when a payment is needed. For a web application the token is generally passed in via a `token` request parameter. Upon opening the website/loading the application it checks that the token is valid (within time bounds etc) and the account in the token has added the app as a signer so it can withdraw MOBI from it.\n\n\nSee demo at:\n\n    $ git clone git@github.com/mobius-network/mobius-client-ruby.git\n    $ cd mobius-client-ruby \u0026\u0026 bundle\n    $ cd examples/app \u0026\u0026 bundle \u0026\u0026 ruby app.rb\n\n### Sample Server Implementation\n\n```ruby\nclass AppController \u003c ApplicationController\n  skip_before_action :verify_authenticity_token, :only =\u003e [:pay]\n\n  ROUND_PRICE = 5\n\n  # GET /\n  # User opens the application passing in the token variable.\n  def index\n    # User has opened application page without a token\n    return render plain: \"Visit https://store.mobius.network to register in the DApp Store\" unless app\n\n    # User has not granted access to his MOBI account so we can't use it for payments\n    return render plain: \"Visit https://store.mobius.network and open our app\" unless app.authorized?\n\n    # token is valid - should render the application or redirect to the main application page etc\n  end\n\n  # GET /balance\n  def balance\n    render plain: app.user_balance\n  end\n\n  # POST /charge\n  def charge\n    app.charge(ROUND_PRICE)\n    render plain: app.user_balance\n  rescue Mobius::Client::Error::InsufficientFunds\n    render :gone\n  end\n\n  private\n\n  def token_s\n    session[:token] = params[:token] || session[:token]\n  end\n\n  def token\n    @token ||= Mobius::Client::Auth::Jwt.new(Rails.application.secrets.app[:jwt_secret]).decode!(token_s)\n  rescue Mobius::Client::Error\n    nil # We treat all invalid tokens as missing\n  end\n\n  def app\n    @app ||= token \u0026\u0026 Mobius::Client::App.new(\n      Rails.application.secrets.app[:secret_key], # SA2VTRSZPZ5FIC.....I4QD7LBWUUIK\n      token.public_key                            # Current user\n    )\n  end\nend\n```\n\n## CLI Test Implementation\n\n  Normally the Mobius DApp Store will request a challenge, validate and sign it, pass it back to the application to obtain an access token, and then open the application and pass in the token.\n\n  For development purposes you can use the simple HTML test interface generated via `mobius-cli create dev-wallet` as mentioned above in the \"Account Creation Wizard\" section or you can use the these CLI commands.\n\n```\n  # Fetch token from working application\n  # mobius-cli auth fetch \u003cURL\u003e \u003cUser secret\u003e \u003cApp public\u003e\n  $ mobius-cli auth fetch -j secret \\\n    http://localhost:4567/auth SA2VTRSZPZ5FIC.....I4QD7LBWUUIK GCWYXW7RXJ5.....SV4AK32ECXFJ\n\n  # Generate token locally using the provided app secret\n  # mobius-cli auth token \u003cUser secret\u003e \u003cApp secret\u003e\n  $ mobius-cli auth token -j secret \\\n    SA2VTRSZPZ5FIC.....I4QD7LBWUUIK SGZKDAKASDSD.....I4QD7LBWUUIK\n```\n\n  Use `-j` if you want to return JWT token, otherwise transaction hash will be returned.\n\n  Check `lib/mobius/cli/auth.rb` for details.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/mobius-network/mobius-client-ruby. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Code of Conduct\n\nEveryone interacting in the Mobius::Client project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/mobius-network/mobius-client-ruby/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobius-network%2Fmobius-client-ruby","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmobius-network%2Fmobius-client-ruby","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmobius-network%2Fmobius-client-ruby/lists"}