Skip to content
This repository has been archived by the owner on Nov 22, 2023. It is now read-only.

Commit

Permalink
feat: update README
Browse files Browse the repository at this point in the history
  • Loading branch information
einaralex committed Oct 27, 2023
1 parent 68c62ea commit fd093a9
Show file tree
Hide file tree
Showing 6 changed files with 461 additions and 83 deletions.
179 changes: 115 additions & 64 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,122 +1,149 @@
# @monerium/sdk
# Monerium SDK Documentation

Everything you need to interact with the [Monerium API](https://monerium.dev/api-docs) - an electronic money issuer.
Monerium connects your web3 wallet to any euro bank account with your personal IBAN.
All incoming euro payments are automatically minted as EURe tokens to your wallet.
Sending EURe to traditional bank accounts is just as easy.
With a single signature from your wallet, your EURe is burned and sent as Euros to any bank account.

_This package is in development. Please make sure to check if any future updates contain commits
that may change the behavior of your application before you upgrade. If you find any issues please report them [here](https://github.com/monerium/sdk/issues)._
## Table of Contents

[NPM package](https://www.npmjs.com/package/@monerium/sdk)
- [Installation](#installation)
- [Configuration](#configuration)
- [Usage Examples](#usage-examples)
- [API Reference](#api-reference)
- [Contributing](#contributing)
- [FAQs](#faqs)
- [Support](#support)
- [Release Notes](#release-notes)
- [License](#license)

[Source code](https://github.com/monerium/sdk)
## Installation

[SDK Documentation](https://monerium.github.io/sdk/)
### Prerequisites

[SDK JS-Docs](https://monerium.github.io/sdk/)

[Code coverage](https://monerium.github.io/sdk/coverage)

## Installing
Node v16.15 or higher is required.

```sh
# Node
yarn add @monerium/sdk
```

## Usage

- `watch`: Run Vite in watch mode to detect changes to files during development
- `build`: Run Vite to build a production release distributable

### Environments
## Configuration

#### Sandbox:
### Environments - URLs

chains: `ethereum`, `polygon`, `gnosis`.
| Environment | Web | API |
| ----------- | -------------------- | ------------------------ |
| sandbox | https://monerium.dev | https://api.monerium.dev |
| production | https://monerium.app | https://api.monerium.app |

networks: `goerli`, `mumbai`, `chiado`.
### Environments - Networks

#### Production:
| Environment | Chain | Network |
| ----------- | -------- | ------- |
| sandbox | ethereum | goerli |
| | polygon | mumbai |
| | gnosis | chiado |
| production | ethereum | mainnet |
| | polygon | mainnet |
| | gnosis | mainnet |

chains: `ethereum`, `polygon`, `gnosis`.

networks: `mainnet`, `mainnet`, `mainnet`.

## Getting started
## Usage Examples

We recommend starting in the [Developer Portal](https://monerium.dev/docs/welcome). There you will learn more about `client_id`'s and ways of authenticating.

### Import the SDK and initialize a client
#### Import the SDK and initialize a client

```ts
import { MoneriumClient } from '@monerium/sdk';

// By default, the client will use the sandbox environment.
// To change to production, pass "production" as the first argument.
// Initialize the client. By default, it uses the sandbox environment.
// For using the production environment, replace 'sandbox' with 'production'.
const client = new MoneriumClient('sandbox');
```

### Authenticate using client credentials
#### Authenticate using client credentials

```ts
await client.auth({
client_id: "your_client_credentials_uuid"
client_secret: "your_client_secret"
})
client_id: 'your_client_credentials_uuid', // replace with your client ID
client_secret: 'your_client_secret', // replace with your client secret
});

// User is now authenticated, get authentication data
await client.getAuthContext()
// Retrieve authentication data after successful authentication.
await client.getAuthContext();

// You can now find your access and refresh token here:
const { access_token, refresh_token } = client.bearerProfile;
// Access tokens are now available for use.
const { access_token, refresh_token } = client.bearerProfile;
```

### Authenticate using auth flow
#### Authenticate using auth flow

First you have to navigate the user to the Monerium authentication flow. This can be done by generating a URL and redirecting the user to it. After the user has authenticated, Monerium will redirect back to your specified URI with a code. You can then finalize the authentication process by exchanging the code for access and refresh tokens.

```ts
// Construct the authFlowUrl for your application and redirect your customer.
// Generate the URL where users will be redirected to authenticate.
let authFlowUrl = client.getAuthFlowURI({
client_id: "your_client_authflow_uuid",
redirect_uri: "http://your-webpage.com/monerium-integration"
// optional automatic wallet selection:
network: "mumbai",
chain: "polygon",
address: "0xValidAddress72413Fa92980B889A1eCE84dD",
signature: "0xValidSignature0df2b6c9e0fc067ab29bdbf322bec30aad7c46dcd97f62498a91ef7795957397e0f49426e000b0f500c347219ddd98dc5080982563055e918031c"

})
// Store the code verifier in localStorage
window.localStorage.setItem("myCodeVerifier", client.codeVerifier);
// Redirecting to the Monerium onboarding / Authentication flow.
window.location.replace(authFlowUrl)
client_id: 'your_client_authflow_uuid', // replace with your auth flow client ID
redirect_uri: 'http://your-webpage.com/monerium-integration', // specify your redirect URI
// Optional parameters for automatic wallet selection (if applicable)
network: 'mumbai', // specify the network
chain: 'polygon', // specify the chain
address: '0xValidAddress72413Fa92980B889A1eCE84dD', // user wallet address
signature:
'0xValidSignature0df2b6c9e0fc067ab29bdbf322bec30aad7c46dcd97f62498a91ef7795957397e0f49426e000b0f500c347219ddd98dc5080982563055e918031c', // user wallet signature
});

// Store the code verifier securely between requests.
window.localStorage.setItem('myCodeVerifier', client.codeVerifier);

// Redirect the user to the Monerium authentication flow.
window.location.replace(authFlowUrl);
```

```ts
// As the final step of the flow, the customer will be routed back to the `redirect_uri` with a `code` parameter attached to it.
// i.e. http://your-webpage.com/monerium-integration?code=1234abcd
// After user authentication, Monerium redirects back to your specified URI with a code.
// Capture this code from the URL and proceed with the authentication.

// Extract the 'code' URL parameter.
const authCode = new URLSearchParams(window.location.search).get('code');

// Retrieve the stored code verifier.
const retrievedCodeVerifier = window.localStorage.getItem('myCodeVerifier');

// Finalize the authentication process.
await client.auth({
client_id: 'your_client_authflow_uuid',
code: new URLSearchParams(window.location.search).get('code'),
code_verifier: window.localStorage.getItem('myCodeVerifier'),
redirect_url: 'http://your-webpage.com/monerium-integration',
client_id: 'your_client_authflow_uuid', // replace with your client ID
code: authCode,
code_verifier: retrievedCodeVerifier,
redirect_url: 'http://your-webpage.com/monerium-integration', // ensure this matches the redirect_uri used initially
});

// User is now authenticated, get authentication data
// Confirm the user is authenticated and retrieve the authentication data.
await client.getAuthContext();

// You can now find your access and refresh token here:
// Your access and refresh tokens are now available.
const { access_token, refresh_token } = client.bearerProfile;
```

## API Reference

[API Documentation](https://monerium.dev/docs/api)

## Contributing

We are using [commitlint](https://github.com/conventional-changelog/commitlint/tree/master/@commitlint/config-conventional) to enforce that developers format the commit messages according to the [Conventional Commits](https://www.conventionalcommits.org/en/v1.0.0/) guidelines.

We are using Yarn as a package manager.

```
```sh
# Install dependencies
yarn

# Run Vite to build a production release distributable
yarn build

# Run Vite in watch mode to detect changes to files during development
yarn watch
```

Smart IDEs (such as VSCode) require [special configuration](https://yarnpkg.com/getting-started/editor-sdks) for TypeScript to work when using Yarn Plug'n'Play installs.
Expand All @@ -138,6 +165,30 @@ cd ../your-project
yarn link "@monerium/sdk"
```

## Publishing
#### Publishing

When changes are merged to the `main` branch that follows the [conventional commits](https://www.conventionalcommits.org/en/v1.0.0/) standard, [release-please](https://github.com/googleapis/release-please) workflow creates a pull request, preparing for the next release. If kept open, the following commits will also be added to the PR. Merging that PR will create a new release, a workflow will publish it on NPM and tag it on Github.

## FAQs

Common questions developers have regarding the SDK.

## Support

[Support](https://monerium.app/help)
[Telegram](https://t.me/+lGtM1gY9zWthNGE8)
[Github Issues](https://github.com/monerium/sdk/issues)

## Release Notes

https://github.com/monerium/sdk/releases

## License

Information about the software license.

[End of the SDK Documentation]

---

This template is a comprehensive starting point. Each section should contain detailed information relevant to your SDK to guide your users from installation to effective usage and troubleshooting. Be sure to adjust the headers and content to suit your SDK's unique needs and features.
2 changes: 1 addition & 1 deletion configs/typedoc.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
},
"entryPointStrategy": "expand",
"plugin": ["typedoc-theme-hierarchy"],
"theme": "hierarchy"
"theme": "hierarchy",
}
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
"build:main": "tsc && vite --config ./configs/vite.config.ts build && dts-bundle-generator --config ./configs/dts-bundle-generator.ts",
"clean": "rm -rf dist && rm -rf node_modules && rm -rf static",
"docs": "typedoc --options configs/typedoc.json && node scripts/editStatic.js",
"docs:watch": "typedoc --options configs/typedoc.json --watch",
"docs:watch": "nodemon --watch . --ignore static -e ts,css,md --exec 'typedoc --options configs/typedoc.json && node scripts/editStatic.js'",
"format": "prettier . --write --ignore-path ./configs/.prettierignore",
"lint": "eslint . -c ./.eslintrc --ext .ts",
"prepare": "husky install",
Expand All @@ -57,12 +57,13 @@
"husky": "^8.0.2",
"jest": "^29.5.0",
"jest-fetch-mock": "^3.0.3",
"nodemon": "^3.0.1",
"prettier": "^2.8.8",
"ts-jest": "^29.0.3",
"ts-node": "^10.9.1",
"tslib": "^2.4.1",
"typedoc": "^0.23.23",
"typedoc-theme-hierarchy": "^3.0.2",
"typedoc-theme-hierarchy": "^3.2.1",
"typescript": "^5.0.4",
"vite": "^4.0.0"
},
Expand Down
24 changes: 22 additions & 2 deletions scripts/editStatic.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

var fs = require('fs');

function readWriteAsync() {
function forceOpenSidebar() {
fs.readFile('static/index.html', 'utf-8', function (err, data) {
if (err) throw err;

Expand All @@ -20,5 +20,25 @@ function readWriteAsync() {
});
});
}
function forceCustomCss() {
fs.copyFile('src/styles/typedoc.css', 'static/assets/monerium.css', (err) => {
if (err) throw err;
console.log('typedoc.css was copied to static/assets/monerium.css');
});
fs.readFile('static/index.html', 'utf-8', function (err, data) {
if (err) throw err;

var newValue = data.replace(
'<link rel="stylesheet" href="assets/custom.css"/>',
'<link rel="stylesheet" href="assets/custom.css"/><link rel="stylesheet" href="assets/monerium.css"/>',
);

fs.writeFile('static/index.html', newValue, 'utf-8', function (err) {
if (err) throw err;
console.log('Finished manually editing static/index.html');
});
});
}

readWriteAsync();
forceOpenSidebar();
forceCustomCss();
Loading

0 comments on commit fd093a9

Please sign in to comment.