Session Token and Wallet Signing
Fetch Session Token and Auth with Wallet
In order to start the authentication process with Ratio you must provide the library with a function that will call Ratio's API.
An async function that calls your backend to return the session token from the
/v1/clients/session
API.get
https://api.ratio.me
/v1/client/sessions/{sessionId}
Returns the client session
The Ratio API uses client authentication which requires a
client_id
and client_secret.
This client secret should be treated securely and should be protected within your backend.const fetchSessionToken = async () => {
try {
let sessionTokenResponse = await fetch(
'https://your.api.com/clients/session',
{
method: 'POST',
body: JSON.stringify({
signingAddress: walletAddress,
depositAddress: walletAddress,
signingNetwork: walletNetwork,
}),
}
);
let data = await sessionTokenResponse.json();
return data.id;
} catch (e) {
console.error(e);
}
return null;
};
<RatioComponent
fetchSessionToken={async () => {
return await fetchSessionToken();
}}/>
TYPE | REQUIRED |
---|---|
function | Yes |
Ratio uses wallet authentication in order to link your client wallet to a Ratio user's account. To set up this authentication method you must provide the Ratio React Native Library with a
signingCallback.
The signing callback is an async function that accepts a string that contains the
challenge
that is returned from the Ratio /v1/auth/cryptoWallet:start
call (documentation). This will allow you to perform asynchronous activities, such as a biometrics check, during the signing.For example, using the Web3.js library
<RatioComponent
signingCallback={async (challenge: string) => {
let sign = web3.eth.accounts.sign(challenge, privateKey);
return Promise.resolve({
signature: sign.signature,
});
}}/>
.png?alt=media&token=db49f912-1323-48f1-b89f-0e8e3ef073e8)
Last modified 2mo ago