Authentication Using a Fuel Wallet
In order to authenticate using a Fuel Wallet, first you need a Fuel Wallet Extension (opens in a new tab) installed on your browser.
import { Auth, TypeUser, IAuthCreateRequest, BakoSafe } from 'bakosafe'
const params: IAuthCreateRequest = {
address: 'your-fuel-wallet-address', // fuel1...
provider: BakoSafe.getProviders('CHAIN_URL'), // https://beta-5.fuel.network/graphql for example
type: TypeUser.FUEL, // TypeUser.FUEL
}
const auth = await Auth.create(params)
// sign auth code using your fuel wallet, to create your session
const wallet_sign = 'your-signature-from-fuel-wallet'
await auth.sign(wallet_sign)
//use your BakoSafeAuth on Auth to instance other services on BakoSafe
console.log(auth.BakoSafeAuth)In this code snippet, Auth.create method is used to create a new instance of the Auth. It requires the wallet address (fuels..dsai) and the Provider URL (https://beta-5.fuel.network/graphql). You need to specify the type of user as TypeUser.FUEL. After this, sign your Auth.code using your Fuel Wallet, and send your signature using auth.sign() to create your session.
Authentication Using a Private Key You can also authenticate by using a Private Key as follows:
import { Auth, TypeUser, IAuthCreateRequest, BakoSafe } from "bakosafe"
const YOUR_PRIVATE_KEY = 'your-private-key'
const YOUR_ADDRESS = 'your-address'
const params: IAuthCreateRequest = {
address: YOUR_ADDRESS, // fuels..dsai
provider: BakoSafe.getProviders('CHAIN_URL'), // https://beta-5.fuel.network/graphql for example
type: TypeUser.FUEL, // TypeUser.FUEL
};
const auth = await Auth.create(params);
//sign auth code using your PK
const sig = await Auth.signerByPk(YOUR_PRIVATE_KEY, auth.code);
await auth.sign(sig);
//use your BakoSafeAuth on Auth to instance other services on BakoSafe
console.log(auth.BakoSafeAuth);In this code snippet, Auth.create method is used to create a new instance of the Auth. It requires the wallet address (YOUR_ADDRESS), the Provider URL (https://beta-5.fuel.network/graphql) and the private key of account (YOUR_PRIVATE_KEY). You need to specify the type of user as TypeUser.FUEL.
Then, the signerByPk method is used to sign in using the provided Private Key for the authentication process.