@@ -9,7 +9,11 @@ import {
99} from '@lit-protocol/constants' ;
1010import { getChildLogger } from '@lit-protocol/logger' ;
1111import { AuthData } from '@lit-protocol/schemas' ;
12- import { AuthMethod , AuthSig } from '@lit-protocol/types' ;
12+ import {
13+ AuthMethod ,
14+ AuthSig ,
15+ BaseSiweMessage ,
16+ } from '@lit-protocol/types' ;
1317import { GetWalletClientReturnType } from '@wagmi/core' ;
1418import { getAddress , Hex , keccak256 , stringToBytes , WalletClient } from 'viem' ;
1519import { fetchBlockchainData } from './helper/fetchBlockchainData' ;
@@ -18,6 +22,10 @@ const _logger = getChildLogger({
1822 module : 'WalletClientAuthenticator' ,
1923} ) ;
2024
25+ export type WalletClientAuthenticateOverrides = Partial <
26+ Omit < BaseSiweMessage , 'walletAddress' | 'nonce' >
27+ > ;
28+
2129export class WalletClientAuthenticator {
2230 public readonly type = 'walletClient' ;
2331
@@ -42,16 +50,30 @@ export class WalletClientAuthenticator {
4250 } ) ;
4351 }
4452
53+ /**
54+ * Generate an AuthSig for the connected wallet. Provide a full message to sign via `messageToSign`,
55+ * or let the helper build one while overriding specific SIWE fields with `siweMessageOverrides`.
56+ */
4557 static async authenticate (
4658 account : GetWalletClientReturnType | WalletClient ,
47- messageToSign ?: string
59+ messageToSign ?: string ,
60+ siweMessageOverrides ?: WalletClientAuthenticateOverrides
4861 ) : Promise < AuthData > {
4962 let _toSign = messageToSign ;
5063
5164 if ( ! _toSign ) {
52- _toSign = await createSiweMessage ( {
65+ const restOverrides = siweMessageOverrides ?? { } ;
66+
67+ const nonce = await fetchBlockchainData ( ) ;
68+
69+ const siweParams : BaseSiweMessage = {
5370 walletAddress : account . account ! . address ,
54- nonce : await fetchBlockchainData ( ) ,
71+ nonce,
72+ ...restOverrides ,
73+ } ;
74+
75+ _toSign = await createSiweMessage ( {
76+ ...siweParams ,
5577 } ) ;
5678 }
5779
0 commit comments