Class: MoneriumClient
In the Monerium UI, create an application to get the clientId
and register your redirectUri
.
import { MoneriumClient } from '@monerium/sdk';
const monerium = new MoneriumClient() // defaults to `sandbox`
// or
new MoneriumClient('production')
// or
new MoneriumClient({
environment: 'sandbox',
clientId: 'your-client-id',
redirectUri: 'http://your-redirect-url.com/monerium'
});
Constructors
new MoneriumClient()
new MoneriumClient(
envOrOptions
?:ENV
|ClassOptions
):MoneriumClient
Parameters
Parameter | Type |
---|---|
envOrOptions ? | ENV | ClassOptions |
Returns
Default Value
sandbox
Properties
Property | Type | Description |
---|---|---|
bearerProfile? | BearerProfile | The bearer profile will be available after authentication, it includes the access_token and refresh_token |
isAuthorized | boolean | The client is authorized if the bearer profile is available |
state | undefined | string | The state parameter is used to maintain state between the request and the callback. |
Authentication
authorize()
authorize(
params
?:AuthFlowOptions
):Promise
<void
>
Constructs the url to the authorization code flow and redirects,
Code Verifier needed for the code challenge is stored in local storage
For automatic wallet link, add the following properties: address
, signature
& chain
This authorization code is then used to request an access token via the token endpoint. (https://monerium.dev/api-docs#operation/auth-token)
Parameters
Parameter | Type | Description |
---|---|---|
params ? | AuthFlowOptions | the auth flow params |
Returns
Promise
<void
>
void
See
disconnect()
disconnect():
Promise
<void
>
Cleanups the localstorage and websocket connections
Returns
Promise
<void
>
getAccess()
getAccess(
refreshToken
?:string
):Promise
<boolean
>
Will use the authorization code flow code to get access token
Parameters
Parameter | Type | Description |
---|---|---|
refreshToken ? | string | provide the refresh token to get a new access token |
Returns
Promise
<boolean
>
boolean to indicate if access has been granted
Example
import { MoneriumClient } from '@monerium/sdk';
// Initialize the client with credentials
const monerium = new MoneriumClient({
environment: 'sandbox',
clientId: 'your_client_credentials_uuid', // replace with your client ID
clientSecret: 'your_client_secret', // replace with your client secret
});
await monerium.getAccess();
const refreshToken = monerium.bearerProfile?.refresh_token;
// TODO: store the refresh token securely
// reconnect...
await monerium.getAccess(refreshToken);