Mobius

Suggest Edits

Introduction

 

The Mobius DApp Store SDKs make it easy to integrate Mobius DApp Store MOBI payments into any application.

Official libraries for the Mobius DApp Store are available in Ruby, Javascript, PHP and soon in Unity.

We have released a sample DApp that uses the Ruby SDK, Floppy Bird.

Overview

SDK's have different modules that serve different purposes:

  • Auth - Handles user authentication and validation.
  • App - Interface to user balance in application.
  • Blockchain - Service class used to interact with accounts on Stellar network.
  • Errors - Errors that can be raised while using the SDK.
  • FriendBot - MOBI Friendbot.

Overview

Auth is composed of different modules:

  • Challenge - Generates challenge transaction on developer's side.
  • Jwt - Generates JWT based on valid transaction.
  • Sign - Signs challenge transaction on user's side (client-side).
  • Token - Checks challenge transaction signed by user on DApp's side.
Suggest Edits

Challenge

 

Generates challenge transaction on developer's side.

Challenge Object

Attribute
Type
Description

seed

String

DApp private seed

expire_in

Seconds

Challenge time bounds. 1 day by default.

Secret Seeds

Make sure you keep all the secret seeds stored safely, extracting into ENV variables or equivalent. Keys present throughout the documentation only serve for example purposes and belong to an account in the Test network.

Methods

.call(seed, expire_in = 1d) ⇒ Object

Generates challenge transaction - challenge transaction - A Challenge Transaction (CT) is a 1 lumen payment to and from the DApp account signed by the DApp account’s secret seed. A CT authenticates that the user actually owns the secret seed for that user account. signed by developers secret seed - secret seed - "The [secret seed] is private information that proves you own your account. You should never share the seed with anyone. If you’re familiar with public key cryptography, you might be wondering how the seed differs from a private key. The seed is actually the single secret piece of data that is used to generate both the public and private key for your account." - Stellar Developer Documentation . Minimum valid time bound is set to current time. Maximum valid time bound is set to expire_in seconds from now.

expire_in is optional, 1 day by default.

sdapp = "SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4"

# You can use either the class method shortcut or the instance method.

challenge = Mobius::Client::Auth::Challenge.call(sdapp, 12.hours)
# =>
"AAAAAL...EnB3MF"

const sdapp = 'SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4';

const challengeExpiresIn = 172800; // 2 days || default = 1 day

const challenge = Mobius.Auth.Challenge.call(sdapp, challengeExpiresIn); 
// => 'AAAAAL...EnB3MF'

XDR Viewer

Click the links below to open the Stellar XDR Viewer for each one.

challenge


#call() ⇒ Object

Returns base64-encoded transaction envelope.

challenge = Mobius::Client::Auth::Challenge.new(sdapp)
#<Mobius::Client::Auth::Challenge:0x00007fe6143ab8d8
  @seed="SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4">

challenge.call(12.hours)
# =>
"AAAAAH...Op1j4C"

XDR Viewer

Click the links below to open the Stellar XDR Viewer for each one.

challenge

Generates JWT - JWT - Json Web Token (short for Json Web Token) based on valid token transaction signed by both parties and decodes JWT into hash.

Jwt Object

Attribute
Type
Description

secret

String

JWT Secret

Secret Seeds

Make sure you keep all the secret seeds stored safely, extracting into ENV variables or equivalent. Keys present throughout the documentation only serve for example purposes and belong to an account in the Test network.

Constants

ALG = "HS512".freeze

Used JWT algorithm.

Methods

#encode(token) ⇒ String

Encodes token into JWT.


#decode!(jwt) ⇒ Hash

Returns decoded JWT.

# Json Web Token secret
jwt_secret = "431714...5aa8fb"

jwt = Mobius::Client::Auth::Jwt.new(jwt_secret)

# Token
seed = "SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4"
xdr = "AAAAAL...W62kcE"
address = "GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y"

token = Mobius::Client::Auth::Token.new(seed, xdr, address)
# =>
<Mobius::Client::Auth::Token:0x00007f90ac841b80
  @seed="SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4",
  @xdr="AAAAAB...sYzQAI",
  @address="GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y"
>
  
# Validate token
token.validate!
# =>
true

# Converts issued token into JWT.
# This will be the JWT used by the User in the query param.
user_token = jwt.encode(token)
# =>
eyJ0eX...1YInIQ

# Decodes JWT into hash and User's public key
# Indentifies the user_dapp account to initialize the @app object.
jwt.decode!(user_token)
# =>
<OpenStruct
  hash="a8f68c74b0d2b32b47c8348e56e82f98fa165076d4ec7e8e8f709619d96b34e2",
  public_key="GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y",
  min_time=1530667902, max_time=1530754302
>
// Json Web Token secret
const jwtSecret = '431714...5aa8fb';

const jwt = new Mobius.Auth.Jwt(jwtSecret);

// Token
const seed = 'SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4';
const xdr = 'AAAAAL...W62kcE';
const address = 'GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y';

const token = new Mobius.Auth.Token(seed, xdr, address);

// Validate token
token.validate(); // => true

// Converts issued token into JWT.
// This will be the JWT used by the User in the query param.
const userToken = jwt.encode(token); // => eyJ0eX...1YInIQ

// Decodes JWT into hash and User's public key
// Indentifies the user account to initialize the dapp object.
const jwtDecoded = jwt.decode(userToken); 
/** jwtDecoded => 
  *  {
  *   jti: 'a8f68c74b0d2b32b47c8348e56e82f98fa165076d4ec7e8e8f709619d96b34e2',
  *   sub: 'GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y',
  *   iat: 1530667902,
  *   exp: 1530754302
  *  }
  */

XDR Viewer

Signs challenge transaction - challenge transaction - A Challenge Transaction (CT) is a 1 lumen payment to and from the DApp account signed by the DApp account’s secret seed. A CT authenticates that the user actually owns the secret seed for that user account. on user's side.

Sign Object

Attribute
Type
Description

seed

String

User private seed

xdr

String

Challenge Transaction XDR

address

String

DApp public key

Secret Seeds

Make sure you keep all the secret seeds stored safely, extracting into ENV variables or equivalent. Keys present throughout the documentation only serve for example purposes and belong to an account in the Test network.

Methods

.call(seed, xdr address) ⇒ String

Constructor shortcut to call instance method.


#call(seed, xdr, address) ⇒ String

Adds signature to given transaction. Returns a Base64-encoded transaction envelope.

# User private seed
seed = "SCRBVUQF4N7JNXSEVQKZ4OEOEORC54BURPI3RCKN4FP3CO6AA7EZTJOA"

# DApp public key
address = "GASD34FQS3V54JK62YV4APLMTW56YW5YUFZWBVCCQ7Y5RSEQ6PLL5COZ"

# Challenge transaction
xdr = "AAAAAA...DbZlkH"

sign = Mobius::Client::Auth::Sign.call(seed, xdr, address)
# => "AAAAAA...w1zoIN"
// User private seed
const seed = 'SCRBVUQF4N7JNXSEVQKZ4OEOEORC54BURPI3RCKN4FP3CO6AA7EZTJOA';

// DApp public key
const address = 'GASD34FQS3V54JK62YV4APLMTW56YW5YUFZWBVCCQ7Y5RSEQ6PLL5COZ';

// Challenge transaction
const xdr = 'AAAAAA...DbZlkH';

const sign = Mobius.Auth.Sign.call(seed, xdr, address);
// => 'AAAAAA...w1zoIN'

XDR Viewer

Click the links below to open the Stellar XDR Viewer for each one.

xdr
sign

Checks challenge transaction signed by user on developer's side.

Token Object

Attribute
Type
Description

seed

String

DApp private seed

xdr

String

Challenge Transaction XDR

address

String

User public key

Secret Seeds

Make sure you keep all the secret seeds stored safely, extracting into ENV variables or equivalent. Keys present throughout the documentation only serve for example purposes and belong to an account in the Test network.

Methods

#hash(format = :binary) ⇒ String

Returns transaction hash.


#validate!(strict = true) ⇒ Boolean

Validates transaction signed by developer and user.

strict

True by default, checks that the transaction respects the time bounds.

Value Mobius::Client::strict_interval is 10s.

Exceptions

Calling this method can raise on of the following exceptions:
Unauthorized — if one of the signatures is invalid
Invalid — if transaction is malformed or time bounds are missing
Expired — if transaction is expired (current time outside it's time bounds)


#time_bounds ⇒ Stellar::TimeBounds

Returns time bounds for given transaction.

Exceptions

Calling this method can raise on of the following exceptions:
Unauthorized – if one of the signatures is invalid.
Invalid – if transaction is malformed or time bounds are missing.

seed = "SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4"
xdr = "AAAAAB...sYzQAI"
address = "GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y"

token = Mobius::Client::Auth::Token.new(seed, xdr, address)
# =>
<Mobius::Client::Auth::Token:0x00007f90ac841b80
  @seed="SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4",
  @xdr="AAAAAB...sYzQAI",
  @address="GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y"
>

token.validate! 
# => 
true

token.time_bounds
# =>
<Stellar::TimeBounds:0x00007f90ac840f50
  @attributes={
    min_time: 1530665318,
    max_time: 1530751718
  }
>
  
token.hash
# =>
%CX8ѤU>r;
const seed = 'SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4';
const xdr = 'AAAAAB...sYzQAI';
const address = 'GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y';

const token = Mobius.Auth.Token(seed, xdr, address);

token.validate(); // => true
token.timeBounds; // => { minTime: 1530665318, maxTime: 1530751718 }
token.hash;       // => '%CX8ѤU>r;'

XDR Viewer

Click the links below to open the Stellar XDR Viewer for each one.

xdr

Overview

App is an interface to the user account - user account - For every application the user accesses, a new user account is created using the application ID of the DApp and the user’s mnemonic phrase. This account is also signed by the DApp account associated with the DApp so that the DApp can withdraw funds as a user performs paid actions in the DApp. A user can deposit MOBI on those accounts from their primary user account. balance and it is used to transfer MOBI within accounts.

App Object

Attribute
Type
Description

seed

String

DApp private seed

address

String

User public key

Secret Seeds

Make sure you keep all the secret seeds stored safely, extracting into ENV variables or equivalent. Keys present throughout the documentation only serve for example purposes and belong to an account in the Test network.

Initializing

# App private seed
sdapp = "SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4"

# User public key
guser = "GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y"

dapp = Mobius::Client::App.new(sdapp, guser)
# =>
#<Mobius::Client::App:0x00007fe654093bd8
  @seed="SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4",
  @address="GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y">
// App private seed
const sdapp = 'SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4';

// User public key
const guser = 'GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y';

const dapp = await Mobius.AppBuilder.build(sdapp, guser);

Methods

App Account

Returns the dapp account details.

dapp.app_account # object => dapp_account
dapp.appAccount // object => {...}

App Balance

Returns the dapp balance.

dapp.app_balance # float => 990.0
dapp.appBalance // int => 990

App Keypair

Returns the dapp keypair

dapp.app_kepair # object => dapp_keypair
dapp.appKeypair // object => {...}

Authorized

Returns boolean based on user authorization

app.authorized? # bool => true
app.authorized // bool => true

User Account

Returns the user account details

dapp.user_account # object => user_account
dapp.userAccount // object => {...}

User Balance

Returns the user balance

dapp.user_balance # float => 990.0
dapp.userBalance // int => 990

User Keypair

Returns the user public key

dapp.user_keypair # object => user_keypair
dapp.userKeypair // object => {...}

Charge

Charges a users wallet and optionally transfers to a target address.

#charge(amount, target_address: nil) ⇒ Object

dapp.charge(5)
#<Hyperclient::Resource self_link:nil attributes:
  #<Hyperclient::Attributes:0x00007fe65480ba50
    @collection={
      "hash"=>"821c60...5fc09f",
      "ledger"=>9634000,
      "envelope_xdr"=>"AAAAAN...eqaQU=",
      "result_xdr"=>"AAAAAA...AAAAA=",
      "result_meta_xdr"=>"AAAAAA...AAAAAA"
    }>>
const result = await dapp.charge(5);
/**  result => 
  *  {
  *   hash: '821c60...5fc09f',
  *   legder: 9634000,
  *   envelope_xdr: "AAAAAN...eqaQU=",
  *   result_xdr: "AAAAAA...AAAAA=",
  *   result_meta_xdr: 'AAAAAA...AAAAAA'
  *  }
  */

XDR Viewer

Click the links below to open the Stellar XDR Viewer for each one.

envelope_xdr
result_xdr
result_meta_xdr


Payout

Sends money from DApp account to the user's account or target_address, if given.

Ruby: #payout(amount, target_address: user_keypair.address) ⇒ Object

dapp.payout(2)
#<Hyperclient::Resource self_link:nil attributes:
  #<Hyperclient::Attributes:0x00007ff65445fc48
    @collection={
      "hash"=>"4c4ce8...dc8cc4",
      "ledger"=>9824154,
      "envelope_xdr"=>"AAAAAN...tXwAY=",
      "result_xdr"=>"AAAAAA...AAAAA=",
      "result_meta_xdr"=>"AAAAAA...AAAAAA"
    }>>

const result = await dapp.payout(2);
 /**  result => 
  *  {
  *   hash: '4c4ce8...dc8cc4',
  *   legder: 9824154,
  *   envelope_xdr: "AAAAAN...tXwAY",
  *   result_xdr: "AAAAAA...AAAAA=",
  *   result_meta_xdr: 'AAAAAA...AAAAAA'
  *  }
  */

XDR Viewer

Click the links below to open the Stellar XDR Viewer for each one.

envelope_xdr
result_xdr
result_meta_xdr


Transfer

Sends money from the users account to third party.

#transfer(amount, address) ⇒ Object

# Target address public key
target = "GASD34FQS3V54JK62YV4APLMTW56YW5YUFZWBVCCQ7Y5RSEQ6PLL5COZ"

dapp.transfer(2, target)
  
<Hyperclient::Resource self_link:nil attributes:  
  <Hyperclient::Attributes:0x00007f01a8009ed8
    @collection={
      "hash"=>"e61351...dd7a37",
      "ledger"=>9842412,
      "envelope_xdr"=>"AAAAAN...KaMQQ=",
      "result_xdr"=>"AAAAAA...AAAAA=",
      "result_meta_xdr"=>"AAAAAA...AAAAAA"
    }>>
// Target address public key
const target = 'GASD34FQS3V54JK62YV4APLMTW56YW5YUFZWBVCCQ7Y5RSEQ6PLL5COZ';

const result = await dapp.transfer(2, target);
 /**  result => 
  *  {
  *   hash: 'e61351...dd7a37',
  *   legder: 9842412,
  *   envelope_xdr: "AAAAAN...KaMQQ=",
  *   result_xdr: "AAAAAA...AAAAA=",
  *   result_meta_xdr: 'AAAAAA...AAAAAA'
  *  }
  */

XDR Viewer

Click the links below to open the Stellar XDR Viewer for each one.

envelope_xdr
result_xdr
result_meta_xdr

Suggest Edits

Blockchain

 

Overview

Blockchain is composed of different modules:

  • Account - Service class used to interact with account on Stellar network.
  • AddCosigner - Adds account as cosigner to other account.
  • CreateTrustline - Creates MOBI trustline - trustline - "To trust an issuing account, you create a trustline. Trustlines are entries that persist in the Stellar ledger. They track the limit for which your account trusts the issuing account and the amount of credit from the issuing account that your account currently holds." - Stellar Developer Documentation .
  • FriendBot - Calls Stellar Friendbot - Stellar Friendbot - "The Stellar test network provides the Friendbot, a tool that developers can use to get testnet lumens for testing purposes." - Stellar Developer Documenation .
  • KeyPairFactory - Transforms given value into Stellar::Keypair object.
 

Overview

Service class used to interact with account on Stellar network.

Account Object

Attribute
Type
Description

keypair

Stellar::Keypair

Account keypair

Initializing

# Account seed
seed = "SBBT7NRAKW43LN6ZGSZI37HEJDYWOC62LIZUL35KHO6NI2SKJLEPVAY4"

# Get a keypair from seed
keypair = Mobius::Client::Blockchain::KeyPairFactory.produce(seed)
# =>
<Stellar::KeyPair:0x00007f01b86a8040
  @public_key=<RbNaCl::Signatures::Ed25519::VerifyKey:243df0b0>,
  @secret_seed=<RbNaCl::Signatures::Ed25519::SigningKey:433fb620>
>

# Initialize account from keypair
account = Mobius::Client::Blockchain::Account.new(keypair)
# =>
<Mobius::Client::Blockchain::Account:0x00007f01b8694e00
  @keypair=<Stellar::KeyPair:0x00007f01b86a8040
  @public_key=<RbNaCl::Signatures::Ed25519::VerifyKey:243df0b0>,
  @secret_seed=<RbNaCl::Signatures::Ed25519::SigningKey:433fb620>
>>

Methods

#account ⇒ Stellar::Account

Returns Stellar::Account instance for given keypair.

account.account
<Stellar::Account:0x00007f01b86627c0 @keypair=#		 
	<Stellar::KeyPair:0x00007f01b86627e8 
		@public_key=#
			<RbNaCl::Signatures::Ed25519::VerifyKey:243df0b0>,
    @secret_seed=#
			<RbNaCl::Signatures::Ed25519::SigningKey:433fb620>>

#authorized?(to_keypair) ⇒ Boolean

Returns true if given keypair is added as cosigner to current account.

account.authorized?(keypair)
# =>
true

#balance(asset = Mobius::Client.stellar_asset) ⇒ Float

Returns balance for given asset.

account.balance
# =>
52.0

#info ⇒ Stellar::Account

Requests and caches Stellar::Account information from network.

account.info
# =>
<Hyperclient::Link(account) {
  "href"=>"https://horizon-testnet.stellar.org/accounts/{account_id}", 
  "templated"=>true
}>

#next_sequence_value ⇒ Integer

Invalidates cache and returns next sequence value for given account.

account.next_sequence_value
# =>
41376336245161986

#reload! ⇒ Object

Invalidates account information cache.

account.reload!

#trustline_exists?(asset = Mobius::Client.stellar_asset) ⇒ Boolean

Returns true if trustline exists for given asset and limit is positive.

account.trustline_exists?
# =>
true
Suggest Edits

AddCosigner

 

Overview

Adds account as cosigner to other account.

AddCosigner Object

Attribute
Type
Description

keypair

Stellar::Keypair

Account keypair

cosigner

Stellar::Keypair

Cosigner account keypair

weight

Integer

Cosigner weight, default: 1

Methods

.call(keypair, cosigner, weight)

Constructor shortcut to instance method.

#call

Executes the operation, adding account as cosigner to the other account.

# User Keypair from seed
user_seed = "SCRBVUQF4N7JNXSEVQKZ4OEOEORC54BURPI3RCKN4FP3CO6AA7EZTJOA"
user_keypair = Mobius::Client::Blockchain::KeyPairFactory.produce(user_seed)
  
# Dapp Keypair from public key
gdapp = "GASD34FQS3V54JK62YV4APLMTW56YW5YUFZWBVCCQ7Y5RSEQ6PLL5COZ"
dapp_keypair = Mobius::Client::Blockchain::KeyPairFactory.produce(gdapp)

#
sign = Mobius::Client::Blockchain::AddCosigner.call(user_ keypair, dapp_keypair)
# =>
<Hyperclient::Resource self_link:nil attributes:#
	<Hyperclient::Attributes:0x00007f01b820ddf0 
		@collection{
      "hash"=>"e3a30f...434940",
      "ledger"=>9844732,
      "envelope_xdr"=>"AAAAAN...XYXAM=", 
      "result_xdr"=>"AAAAAA...AAAAA=", 
      "result_meta_xdr"=>"AAAAAA...AAAAA="}>>
Suggest Edits

CreateTrustline

 

Overview

Creates unlimited trustline - trustline - "To trust an issuing account, you create a trustline. Trustlines are entries that persist in the Stellar ledger. They track the limit for which your account trusts the issuing account and the amount of credit from the issuing account that your account currently holds." - Stellar Developer Documentation for given asset.

CreateTrustline Object

Attribute
Type
Description

keypair

Stellar::Keypair

Account keypair

asset

Stellar::Asset

Asset, MOBI by default.

Trustline Limit

LIMIT = 922337203685

ruby-stellar-base needs to be fixed, it does not accept unlimited for now.

Methods

.call(keypair, asset)

Constructor shortcut to instance method.

#call

Creates trustline for given asset.

suser = "SCRBVUQF4N7JNXSEVQKZ4OEOEORC54BURPI3RCKN4FP3CO6AA7EZTJOA"
keypair = Mobius::Client::Blockchain::KeyPairFactory.produce(suser)

trustline = Mobius::Client::Blockchain::CreateTrustline.call(keypair)
# =>
<Hyperclient::Resource self_link:nil attributes:#
	<Hyperclient::Attributes:0x00007f01a4012208 @collection={
    "hash"=>"d0d7d93ddc0d68548a15065dca5294ec862792631693288bf4f4fadf6a7c8dc0", 
    "ledger"=>9844916, 
    "envelope_xdr"=>"AAAAAN...zmBA8=", 
    "result_xdr"=>"AAAAAA...AAAAA=", 
    "result_meta_xdr"=>"AAAAAA...AAAAAA"}>>

XDR Viewer

Click the links below to open the Stellar XDR Viewer for each one.

envelope_xdr
result_xdr
result_meta_xdr

Suggest Edits

Stellar FriendBot

 

Overview

Interface to Stellar Friendbot - Stellar Friendbot - "The Stellar test network provides the Friendbot, a tool that developers can use to get testnet lumens for testing purposes." - Stellar Developer Documenation .

FriendBot Object

Attribute
Type
Description

keypair

Stellar::Keypair

Account keypair

Methods

.call(keypair)

Constructor shortcut to instance method.

#call

Calls Stellar FriendBot.

guser = "GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y"
keypair = Mobius::Client::Blockchain::KeyPairFactory.produce(guser)

friendbot = Mobius::Client::Blockchain::FriendBot.call(keypair)
*** Faraday::ClientError Exception: the server responded with status 400
Suggest Edits

KeyPairFactory

 

Overview

Transforms given value into Stellar::Keypair object.

KeyPairFactory Object

Attribute
Type
Description

subject

String

Given value to identify keypair

subject

subject can be any of the following:

  • String
  • Stellar::Account
  • Stellar::PublicKey
  • Stellar::SignerKey
  • Stellar::Keypair

Methods

#produce(subject) ⇒ Stellar::Keypair

Generates Stellar::Keypair from subject, use Stellar::Client.to_keypair as shortcut.

# From a public key
guser = "GDPNZJR42G4PVA3235JHCGGTU2J54X4XGJIMQGDJXYGHQDY6MQW5SZ5Y"
keypair = Mobius::Client::Blockchain::KeyPairFactory.produce(guser)
# =>
<Stellar::KeyPair:0x00007f01c0004da8 @public_key=# 
<RbNaCl::Signatures::Ed25519::VerifyKey:dedca63c>, @secret_seed=nil>
  
# From a private seed
suser = "SCRBVUQF4N7JNXSEVQKZ4OEOEORC54BURPI3RCKN4FP3CO6AA7EZTJOA"
keypair = Mobius::Client::Blockchain::KeyPairFactory.produce(suser)
# =>
<Stellar::KeyPair:0x00007f01b8565638 @public_key=#
<RbNaCl::Signatures::Ed25519::VerifyKey:dedca63c>, @secret_seed=#
<RbNaCl::Signatures::Ed25519::SigningKey:a21ad205>>

Overview

The SDK can raise different exceptions, depending on the scenario. Find a list below for the errors defined in Mobius::Client::Error.

Errors

Mobius::Client::Error::AccountMissing

Raised if stellar account is missing on network.

Mobius::Client::Error::AuthorisationMissing

Raises if account does not contain MOBI trustline.

Mobius::Client::Error::InsufficientFunds

Raised if there is insufficient balance for payment.

Mobius::Client::Error::MalformedTransaction

Raised if transaction in question has invalid structure.

Mobius::Client::Error::TokenExpired

Raised if transaction has expired.

Mobius::Client::Error::TokenTooOld

Raised if transaction has expired (strict mode).

Mobius::Client::Error::TrustlineMissing

Raises if account does not contain MOBI trustline.

Mobius::Client::Error::Unauthorized

Raised in transaction in question has invalid or does not have required signatures.

Mobius::Client::Error::UnknownKeyPairType

Raised if unknown or empty value has passed to KeyPairFactory.

Suggest Edits

Mobius FriendBot

 

Overview

Calls Mobius Friendbot - Mobius Friendbot - The Mobius Friendbot is aa tool that developers can use to get testnet MOBI for testing purposes. for given account.

FriendBot Object

Attribute
Type
Description

seed

String

Account private seed

amount

Integer

Amount to send, defaults to 1000

Methods

.call(seed, amount: 1000) ⇒ Object

Constructor shortcut to call instance method.

#call ⇒ Object

Sends MOBI amount to account.

# Account private seed
seed = "SCRBVUQF4N7JNXSEVQKZ4OEOEORC54BURPI3RCKN4FP3CO6AA7EZTJOA"

friendbot = Mobius::Client::FriendBot.call(seed)
# =>
true

friendbot = Mobius::Client::FriendBot.call(seed, 5000)
# =>
true
gethttps://wt-your-id.sandbox.auth0-extend.com/your-app/auth/
curl --request GET \
  --url https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/
var request = require("request");

var options = { method: 'GET',
  url: 'https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
var data = JSON.stringify(false);

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/");

xhr.send(data);
import requests

url = "https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/"

response = requests.request("GET", url)

print(response.text)
A binary file was returned

You couldn't be authenticated

AAAAAM2UIqsQQkSH7tRt7rAkIusGzfe6jv7AS6bi32CwqrGaAAAAZAAAAAAF9SzMAAAAAQAAAABbO8+jAAAAAFs9ISMAAAABAAAAFU1vYml1cyBhdXRoZW50aWNhdGlvbgAAAAAAAAEAAAAAAAAAAQAAAADNlCKrEEJEh+7Ube6wJCLrBs33uo7+wEum4t9gsKqxmgAAAAAAAAAAAAAACgAAAAAAAAABsKqxmgAAAEDX/9FlVbkEp61ePJ7ZLO6517uPSM41WBfN1woE2bqo4MlNAqD/CWjPGqOIbN96keok9FN+yh0iA8jfobCDpkkE
 

Get an authentication challenge transaction

$.get('https://yoursite.com/auth/', function(data) {
  // returns a Mobius Auth challgenge transaction signed by
  // app secret seed (in XDR format)
  console.log(data);
});
Suggest Edits

/auth/

Perform authentication and receive JWT token to use at /api/* endpoints

 
posthttps://wt-your-id.sandbox.auth0-extend.com/your-app/auth/
curl --request POST \
  --url 'https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/?xdr=xdr&public_key=public_key'
var request = require("request");

var options = { method: 'POST',
  url: 'https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/',
  qs: 
   { xdr: 'xdr',
     public_key: 'public_key' } };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/?xdr=xdr&public_key=public_key")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
var data = JSON.stringify(false);

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/?xdr=xdr&public_key=public_key");

xhr.send(data);
import requests

url = "https://wt-your-id.sandbox.auth0-extend.com/your-app/auth/"

querystring = {"xdr":"xdr","public_key":"public_key"}

response = requests.request("POST", url, params=querystring)

print(response.text)
A binary file was returned

You couldn't be authenticated

eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiJHQUNDUlE0QkkzRFRJNlUzN09MQk9RNkZCWTNDU0Y1QzY3MkxXSUlPQ0JSUTNHWUxDSzJJR1o2VSIsImp0aSI6ImJkOTZmNTAwYmIwMGVlMzYwNzdmODQ0MGU1MGJlYjJiNmJiODEwODI2ZGUwNTk2NTNlZDU0ZWJlZDg4NDM2YmEiLCJpc3MiOiJodHRwczovL2ZsYXBweS1iaXJkLWRhcHAuZmlyZWJhc2VhcHAuY29tLyIsImlhdCI6MTUzMDY0NDA5MywiZXhwIjoxNTMwNzMwNDkzfQ.gk2jH9U-QCwIeJ7dUcLSX_183X8PU_1ktrR-IBIC2R8

Query Params

xdr
string
required

Original challenge transaction signed by the user's secret seed

public_key
string
required

Public key of authenticating account

 

Perform authentication by submitting a signed challenge back to the app

$.post(
  'https://yoursite.com/auth/', 
  { 
    xdr: 'AAAA....sdfdkfjk', 
    public_key: 'GACCRQ4BI3DTI6U37OLBOQ6FBY3CSF5C672LWIIOCBRQ3GYLCK2IGZ6U' 
  },
  function(data) {
    // returns a JWT token issued by the app backend which can then
    // be used to authenticate for /api/* endpoints
    console.log(data);
});
Suggest Edits

/api/balance

 
gethttps://wt-your-id.sandbox.auth0-extend.com/your-app/api/balance
curl --request GET \
  --url https://wt-your-id.sandbox.auth0-extend.com/your-app/api/balance
var request = require("request");

var options = { method: 'GET',
  url: 'https://wt-your-id.sandbox.auth0-extend.com/your-app/api/balance' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://wt-your-id.sandbox.auth0-extend.com/your-app/api/balance")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Get.new(url)

response = http.request(request)
puts response.read_body
var data = JSON.stringify(false);

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("GET", "https://wt-your-id.sandbox.auth0-extend.com/your-app/api/balance");

xhr.send(data);
import requests

url = "https://wt-your-id.sandbox.auth0-extend.com/your-app/api/balance"

response = requests.request("GET", url)

print(response.text)
A binary file was returned

You couldn't be authenticated

{
  "balance": 9.875
}
 

Get balance of the currently authenticated user

$.get(
  'https://yoursite.com/your-app/balance/', 
  function(data) {
    console.log(data);
	}
);
Suggest Edits

/api/charge

Charge a user some MOBI (GUSER ➞ GDAPP)

 
posthttps://wt-your-id.sandbox.auth0-extend.com/your-app/api/charge
curl --request POST \
  --url https://wt-your-id.sandbox.auth0-extend.com/your-app/api/charge
var request = require("request");

var options = { method: 'POST',
  url: 'https://wt-your-id.sandbox.auth0-extend.com/your-app/api/charge' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://wt-your-id.sandbox.auth0-extend.com/your-app/api/charge")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
var data = JSON.stringify(false);

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://wt-your-id.sandbox.auth0-extend.com/your-app/api/charge");

xhr.send(data);
import requests

url = "https://wt-your-id.sandbox.auth0-extend.com/your-app/api/charge"

response = requests.request("POST", url)

print(response.text)
A binary file was returned

You couldn't be authenticated

{
  "status":"ok",
  "tx_hash":"831aab94d163b27c06dad3b7bbe824819353e4f40eb777d9762fdc187e554f5c",
  "balance":0.9
}

Form Data

amount
float
required

Amount of MOBI to charge

target_address
string

Address to forward the charged amount to

 

Charge the currently authenticated user and optionally forwards the amount to the third-party in the same transaction

$.post(
  'https://yoursite.com/your-app/api/charge',
  { amount: 5.0 },
  function(data) {
    console.log(data);
  }
);
Suggest Edits

/api/transfer

Transfer MOBI to a third-party address (GUSER ➞ GEXT)

 
posthttps://wt-your-id.sandbox.auth0-extend.com/your-app/api/transfer
curl --request POST \
  --url https://wt-your-id.sandbox.auth0-extend.com/your-app/api/transfer
var request = require("request");

var options = { method: 'POST',
  url: 'https://wt-your-id.sandbox.auth0-extend.com/your-app/api/transfer' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://wt-your-id.sandbox.auth0-extend.com/your-app/api/transfer")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
var data = JSON.stringify(false);

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://wt-your-id.sandbox.auth0-extend.com/your-app/api/transfer");

xhr.send(data);
import requests

url = "https://wt-your-id.sandbox.auth0-extend.com/your-app/api/transfer"

response = requests.request("POST", url)

print(response.text)
A binary file was returned

You couldn't be authenticated

{
  "status":"ok",
  "tx_hash":"831aab94d163b27c06dad3b7bbe824819353e4f40eb777d9762fdc187e554f5c",
  "balance":0.9
}

Form Data

amount
float
required

Amount of MOBI to transfer

target_address
string
required

Destination address

 

Directly transfer the specified amount of MOBI from the authenticated account to the third-party

$.post(
  'https://yoursite.com/your-app/api/transfer',
  { amount: 5.0, target_address: 'GADCD4JJAYBVI4X3QBLKSSL63V2EPNNICIXX3NEV2JWFYEA6BFURCMDP' },
  function(data) {
    console.log(data);
  }
);
Suggest Edits

/api/payout

Payout some MOBI to a user or third-party (GDAPP ➞ GUSER)

 
posthttps://wt-your-id.sandbox.auth0-extend.com/your-app/api/payout
curl --request POST \
  --url https://wt-your-id.sandbox.auth0-extend.com/your-app/api/payout
var request = require("request");

var options = { method: 'POST',
  url: 'https://wt-your-id.sandbox.auth0-extend.com/your-app/api/payout' };

request(options, function (error, response, body) {
  if (error) throw new Error(error);

  console.log(body);
});
require 'uri'
require 'net/http'

url = URI("https://wt-your-id.sandbox.auth0-extend.com/your-app/api/payout")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)

response = http.request(request)
puts response.read_body
var data = JSON.stringify(false);

var xhr = new XMLHttpRequest();
xhr.withCredentials = true;

xhr.addEventListener("readystatechange", function () {
  if (this.readyState === this.DONE) {
    console.log(this.responseText);
  }
});

xhr.open("POST", "https://wt-your-id.sandbox.auth0-extend.com/your-app/api/payout");

xhr.send(data);
import requests

url = "https://wt-your-id.sandbox.auth0-extend.com/your-app/api/payout"

response = requests.request("POST", url)

print(response.text)
A binary file was returned

You couldn't be authenticated

{
  "status":"ok",
  "tx_hash":"831aab94d163b27c06dad3b7bbe824819353e4f40eb777d9762fdc187e554f5c",
  "balance":0.9
}

Form Data

amount
float
required

Amount of MOBI to payout

target_address
string

Destination address (if omitted will payout to the authenticated user account)

 

Payout the specified amount of MOBI from the application account to the destination address

$.post(
  'https://yoursite.com/your-app/api/payout',
  { amount: 5.0, target_address: 'GADCD4JJAYBVI4X3QBLKSSL63V2EPNNICIXX3NEV2JWFYEA6BFURCMDP' },
  function(data) {
    console.log(data);
  }
);