Skip to content

Commit

Permalink
feat(auth): expose siwe message creator to user-facing api
Browse files Browse the repository at this point in the history
  • Loading branch information
piotr-roslaniec committed Jun 24, 2024
1 parent 8f795b5 commit 839775b
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions packages/taco-auth/src/eip4361.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,17 @@ export class EIP4361SignatureProvider {

private async createSiweMessage(): Promise<AuthSignature> {
const address = await this.signer.getAddress();
const chainId = (await this.provider.getNetwork()).chainId;
const { domain, uri } = this.getParametersOrDefault();
const message = EIP4361SignatureProvider.prepareSiweMessage(address, chainId, domain, uri);
const signature = await this.signer.signMessage(message);
const scheme = 'EIP4361';
return { signature, address, scheme, typedData: message };
}

public static prepareSiweMessage(address: string, chainId: number, domain: string, uri: string) {
const version = '1';
const nonce = generateNonce();
const chainId = (await this.provider.getNetwork()).chainId;
const siweMessage = new SiweMessage({
domain,
address,
Expand All @@ -47,10 +54,7 @@ export class EIP4361SignatureProvider {
nonce,
chainId,
});
const scheme = 'EIP4361';
const message = siweMessage.prepareMessage();
const signature = await this.signer.signMessage(message);
return { signature, address, scheme, typedData: message };
return siweMessage.prepareMessage();
}

private getParametersOrDefault() {
Expand Down

0 comments on commit 839775b

Please sign in to comment.