Skip to content

Commit a2f1a56

Browse files
committed
fix(auth): allow overriding siwe message fields
1 parent f43c2d9 commit a2f1a56

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

packages/auth/src/lib/authenticators/WalletClientAuthenticator.ts

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ import {
99
} from '@lit-protocol/constants';
1010
import { getChildLogger } from '@lit-protocol/logger';
1111
import { 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';
1317
import { GetWalletClientReturnType } from '@wagmi/core';
1418
import { getAddress, Hex, keccak256, stringToBytes, WalletClient } from 'viem';
1519
import { 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+
2129
export 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

Comments
 (0)