import { AxiosInstance } from 'axios'; import { Signature } from 'ethers'; import { TypedDataDomain, TypedDataField } from "../web3/provider"; export class BackendApi { _axiosInstance: AxiosInstance; /** * Construct the Api instance. Pass * the axios instance as a dependency. * @param axiosInstance */ constructor(axiosInstance: AxiosInstance) { this._axiosInstance = axiosInstance; } /** * This returns a nonce for a given user. * @param address * @return nonce */ public async generateNonce(address: string) { const nonce = await this._axiosInstance.post(`/users/${address}`); return nonce.data; } /** * This verifies that a signature is valid. * @param address * @param isSmartWallet * @param domain * @param types * @param signature */ public async verifySignature( address: string, isSmartWallet: boolean, domain: TypedDataDomain, types: { AuthSignature: Array; }, signature: Signature) { const jwtResponse = await this._axiosInstance.post( `/users/${address}/verify-signature`, { address, isSmartWallet, domain, types, signature, } ); return jwtResponse.data; } }