gray-market-js
Version:
Utility library for the Gray Market rental marketplace
40 lines (36 loc) • 1.07 kB
JavaScript
class AuthClient {
constructor(axiosInstance) {
this.axiosInstance = axiosInstance;
}
async loginWithWallet(signer) {
const validUntil = Math.round(Date.now() / 1000) + 120;
const signature = await signer.signMessage(
`Authenticate with wallet\n` +
"\n" +
"This message is read-only and will not trigger any blockchain transactions.\n" +
"\n" +
`Valid until: ${validUntil}\n` +
`Wallet: ${await signer.getAddress()}`
);
return this.axiosInstance.post("/auth/walletlogin", {
signer: await signer.getAddress(),
signature,
validUntil
});
}
async getCurrentDetails(token) {
return this.axiosInstance.get(`/auth/current`, {
headers: token ? {
"Authorization": `Bearer ${token}`
} : undefined
});
}
async extend(token) {
return this.axiosInstance.post(`/auth/extend`, null, {
headers: token ? {
"Authorization": `Bearer ${token}`
} : undefined
});
}
}
module.exports = AuthClient;