30 lines
719 B
TypeScript
30 lines
719 B
TypeScript
import { apiFetch } from "./api";
|
|
|
|
export async function getNonce(): Promise<string> {
|
|
const data = await apiFetch<{ nonce: string }>("/v1/auth/nonce");
|
|
return data.nonce;
|
|
}
|
|
|
|
export function createSiweMessage(
|
|
address: string,
|
|
nonce: string,
|
|
chainId: number
|
|
): string {
|
|
const domain = window.location.host;
|
|
const origin = window.location.origin;
|
|
const issuedAt = new Date().toISOString();
|
|
|
|
return [
|
|
`${domain} wants you to sign in with your Ethereum account:`,
|
|
address,
|
|
"",
|
|
"Sign in to rSocials to provision your social media instance.",
|
|
"",
|
|
`URI: ${origin}`,
|
|
`Version: 1`,
|
|
`Chain ID: ${chainId}`,
|
|
`Nonce: ${nonce}`,
|
|
`Issued At: ${issuedAt}`,
|
|
].join("\n");
|
|
}
|