Wallet Initialization
First, your system will need a wallet so it can sign Ethereum messages for authentication and sending transactions. You can create a wallet from ethers.js or if you have a private key already, you can initialize it like below. If you haven't reviewed the Getting Started please do so first.
const ethersWallet = new ethers.Wallet(WALLET_PRIV_KEY)
Authentication
Next is the flow to request a message for signing, signing a message, and using the signed message as a bearer token.
Request Signing Message
You need to request for a message to be signed by your wallet and private key. This will be signed and used as a Bearer token for authentication.
const { data } = await axios.get(
'https://b2b-api.riseworks.io/v1/auth/api/siwe', {
params: { wallet: ethersWallet.address }
}
)
const { message } = data.data
Request Signing Message(Impersonate)
You can also impersonate a manager of a company registered in Rise, to do that you will need access to a delegate or the owner wallet of the RiseID address of that company.
const { data } = await axios.get(
'https://b2b-api.riseworks.io/v1/auth/api/siwe', {
params: {
wallet: ethersWallet.address, // Must be the owner or a delegate of the RiseID bellow
rise_id: '0x1234...', // Company RiseID address
impersonate: '[email protected]'// Must be an email of a manager registered in the Rise app
}
}
)
const { message } = data.data
Sign
Now that we have the message, we can sign it and exchange it for a JWT.
const signature = await ethersWallet.signMessage(message)
Pass the signature back to the API with the original message and
const { data } = await axios.post(
'https://b2b-api.riseworks.io/v1/auth/api/siwe', {
wallet: ethersWallet.address,
message,
signature
}
)
const bearerToken = data.data.token
Use
Use your newly created bearerToken
variable as an Authorization
header after encoding
const api = axios.create({
baseURL: 'https://b2b-api.riseworks.io/v1/auth/api/siwe',
headers: {
Authorization: `Bearer ${bearerToken}`
}
})
Now you have a fully authenticated instance of Axios for use throughout your application code