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 { AuthMethod , AuthSig , BaseSiweMessage } from '@lit-protocol/types' ;
1313import { GetWalletClientReturnType } from '@wagmi/core' ;
1414import { getAddress , Hex , keccak256 , stringToBytes , WalletClient } from 'viem' ;
1515import { fetchBlockchainData } from './helper/fetchBlockchainData' ;
@@ -18,6 +18,10 @@ const _logger = getChildLogger({
1818 module : 'WalletClientAuthenticator' ,
1919} ) ;
2020
21+ export type WalletClientAuthenticateOverrides = Partial <
22+ Omit < BaseSiweMessage , 'walletAddress' | 'nonce' >
23+ > ;
24+
2125export class WalletClientAuthenticator {
2226 public readonly type = 'walletClient' ;
2327
@@ -42,16 +46,30 @@ export class WalletClientAuthenticator {
4246 } ) ;
4347 }
4448
49+ /**
50+ * Generate an AuthSig for the connected wallet. Provide a full message to sign via `messageToSign`,
51+ * or let the helper build one while overriding specific SIWE fields with `siweMessageOverrides`.
52+ */
4553 static async authenticate (
4654 account : GetWalletClientReturnType | WalletClient ,
47- messageToSign ?: string
55+ messageToSign ?: string ,
56+ siweMessageOverrides ?: WalletClientAuthenticateOverrides
4857 ) : Promise < AuthData > {
4958 let _toSign = messageToSign ;
5059
5160 if ( ! _toSign ) {
52- _toSign = await createSiweMessage ( {
61+ const restOverrides = siweMessageOverrides ?? { } ;
62+
63+ const nonce = await fetchBlockchainData ( ) ;
64+
65+ const siweParams : BaseSiweMessage = {
5366 walletAddress : account . account ! . address ,
54- nonce : await fetchBlockchainData ( ) ,
67+ nonce,
68+ ...restOverrides ,
69+ } ;
70+
71+ _toSign = await createSiweMessage ( {
72+ ...siweParams ,
5573 } ) ;
5674 }
5775
0 commit comments