Wake call mechanism
Applications wake the wallet service
Last updated
Applications wake the wallet service
Last updated
Certain wallet applications that implement special adaptation layers support being called from within other applications on the phone.
In this section, we talk about how to wake the wallet from inside an application and implement features such as login and smart contract invocation (including payment method). For more details on the application wake mechanism, please refer to Android application demo.
With respect to the wake call, the development process involves implementing two functions - login and smart contract invocation.
The login process is simpler at it's core, so we won't go into any unnecessary details. The process is illustrated in the following section.
Smart contract invocation has a much broader scope of application. dApps
can use smart contracts to implement various different kinds of logic. For example, in the case of a game, there are different operations and services that can be carried out using smart contracts, such as buying, selling, renting, etc.
The core sequence of the login operation is illustrated in the picture below:
The dApp
communicates with the back end to fetch the callback URL and a message to be sent to the dedicated provider
, along with other information (depending upon the implementation logic), and wakes the wallet.
The provider
wallet carries out user authentication and signs the message.
The signed message is then returned to the dApp
back end using the designated callback URL, along with the signed message, the signature and a public key for verification purposes.
The back end finally verifies the signature and sends a success/failure response to the dApp
.
When the dApp
needs to login, it fetches the relevant login data in order to send it to the provider
wallet.
An example of the data structure:
Establish whether or not Cyano Wallet
is installed on the system. An example verification method is provided below.
dApp
sends the data it received from the dApp
server to the dedicated provider (wallet). This can be realized in the following manner:
The provider
verifies the submitted information and signs it, and transmits it back to the specified callback address. The developer need not execute this step manually.
The dApp
back end verifies the signature to establish whether the login succeeded or failed and notifies the dApp
.
The core contract invocation process is illustrated in the figure below:
dApp
side creates a contract invocation data set and sends it to the dedicated provider
.
The provider
carries out user authentication, signature process, and carries out the transaction by communicating with the blockchain.
The provider
receives the transaction hash from the blockchain and transmits it to the dApp
back end using the specified callback address.
The dApp
server end queries the blockchain for the execution result using the transaction hash
.
The final result is returned to the dApp
, made accessible to the user.
A sample contract invocation data set:
A Base58
address, for e.g., AUr5QUfeBADq6BMY6Tp5yuMsUNGpsD7nLZ
__can be used to fill the %address
parameter. The wallet converts the %address
to the wallet's asset address. If the argument contains the %ontid
, the wallet converts it to the wallet's ontid
address.
Ensuring the Provider-sdk
wallet application is installed and deployed on the phone.
Composing the contract invocation JSON
data set, making the wake call to the wallet.
Sample code:
The provider
authenticates, signs, pre-executes, and finally transmits the transaction to the chain. (This step does not require manual implementation)
The provider
sends the transaction hash retrieved from the blockchain to the dApp
back end. (This step is carried out depending on the dApp's
event sequence)
dApp
queries the result from the blockchain.
Query methods reference:
The dApp
back end returns the result to the dApp
, from where the user can access it. (Depends on the logic of the dApp
)
The provider
initiates transactions, carries out user authentication and signature, pre-executes the contract, and finally passes the transaction has to the callback URL via POST method.
If the transaction succeeds, the wallet returns the following to callback:
If the transaction fails, the wallet returns:
The two example applications demonstrate the wake call for specially designated wallets. The code can be used for reference.
Signature verification methods
Transaction event query methods
Cyano Wallet
dAPI - Mobile provider SDK
dAPI - Mobile client SDK