diff --git a/.changeset/cuddly-rats-yawn.md b/.changeset/cuddly-rats-yawn.md new file mode 100644 index 000000000..47f428f1e --- /dev/null +++ b/.changeset/cuddly-rats-yawn.md @@ -0,0 +1,5 @@ +--- +'@lit-protocol/auth': patch +--- + +Allows `WalletClientAuthenticator.authenticate` to build SIWE messages with user-specified fields (`domain`, `uri`, `statement`, etc.) while still managing the nonce internally. diff --git a/docs/sdk/auth/pkp-native-auth/pkp-eoa-auth.mdx b/docs/sdk/auth/pkp-native-auth/pkp-eoa-auth.mdx index 704b008f6..8e2ab08aa 100644 --- a/docs/sdk/auth/pkp-native-auth/pkp-eoa-auth.mdx +++ b/docs/sdk/auth/pkp-native-auth/pkp-eoa-auth.mdx @@ -41,11 +41,21 @@ description: "Externally Owned Account (EOA) authentication uses your existing E Use the WalletClientAuthenticator/ViemAccountAuthenticator to authenticate your connected wallet and generate auth data. - ```ts wagmi +```ts wagmi import { WalletClientAuthenticator } from '@lit-protocol/auth'; const authData = await WalletClientAuthenticator.authenticate(walletClient); - ``` + +// Override SIWE fields (e.g., when running on production domains) +const authDataForProd = await WalletClientAuthenticator.authenticate( + walletClient, + undefined, + { + domain: 'example.com', + uri: 'https://example.com/login', + } +); +``` ```ts viem/accounts import { ViemAccountAuthenticator } from '@lit-protocol/auth'; @@ -111,4 +121,4 @@ const authContext = await authManager.createPkpAuthContext({ }); ``` - \ No newline at end of file + diff --git a/docs/sdk/introduction.mdx b/docs/sdk/introduction.mdx index 6aff260c3..6a4d64c7c 100644 --- a/docs/sdk/introduction.mdx +++ b/docs/sdk/introduction.mdx @@ -17,14 +17,14 @@ The Lit JS SDK provides a comprehensive toolkit for integrating Lit Protocol's d - **[Lit Client Setup](/sdk/getting-started/lit-client)**: Configure the Lit Protocol client - **[Auth Manager Setup](/sdk/getting-started/auth-manager)**: Set up authentication management with configurable storage options -- **[Payment Manager Setup](/sdk/getting-started/payment-setup)**: Configure payment processing capabilities +- **[Payment Manager Setup](/sdk/getting-started/payment-manager-setup)**: Configure payment processing capabilities - **[Auth Services Setup](/sdk/getting-started/auth-services)**: Configure auth services ### 2. Authentication Options - **[PKP Native Authentication](/sdk/auth/pkp-native-auth)**: Programmable Key Pair native authentication options - **[PKP Custom Authentication](/sdk/auth/pkp-custom-auth)**: Custom PKP authentication implementations -- **[EOA Authentication](/sdk/auth/eoa-auth)**: Externally Owned Account authentication +- **[EOA Authentication](/sdk/auth/eoa/eoa-auth)**: Externally Owned Account authentication ### 3. Auth Context Consumption / Core API Methods @@ -40,4 +40,4 @@ The Lit JS SDK provides a comprehensive toolkit for integrating Lit Protocol's d ### 5. Network Status & Monitoring -- **[Network Status](/sdk/resources/network-status)**: - Monitor real-time uptime and performance of Lit Protocol networks \ No newline at end of file +- **[Network Status](/sdk/resources/network-status)**: - Monitor real-time uptime and performance of Lit Protocol networks diff --git a/packages/auth/src/lib/authenticators/WalletClientAuthenticator.ts b/packages/auth/src/lib/authenticators/WalletClientAuthenticator.ts index 33cd25faf..258a6e0c2 100644 --- a/packages/auth/src/lib/authenticators/WalletClientAuthenticator.ts +++ b/packages/auth/src/lib/authenticators/WalletClientAuthenticator.ts @@ -9,7 +9,7 @@ import { } from '@lit-protocol/constants'; import { getChildLogger } from '@lit-protocol/logger'; import { AuthData } from '@lit-protocol/schemas'; -import { AuthMethod, AuthSig } from '@lit-protocol/types'; +import { AuthMethod, AuthSig, BaseSiweMessage } from '@lit-protocol/types'; import { GetWalletClientReturnType } from '@wagmi/core'; import { getAddress, Hex, keccak256, stringToBytes, WalletClient } from 'viem'; import { fetchBlockchainData } from './helper/fetchBlockchainData'; @@ -18,6 +18,10 @@ const _logger = getChildLogger({ module: 'WalletClientAuthenticator', }); +export type WalletClientAuthenticateOverrides = Partial< + Omit +>; + export class WalletClientAuthenticator { public readonly type = 'walletClient'; @@ -42,16 +46,30 @@ export class WalletClientAuthenticator { }); } + /** + * Generate an AuthSig for the connected wallet. Provide a full message to sign via `messageToSign`, + * or let the helper build one while overriding specific SIWE fields with `siweMessageOverrides`. + */ static async authenticate( account: GetWalletClientReturnType | WalletClient, - messageToSign?: string + messageToSign?: string, + siweMessageOverrides?: WalletClientAuthenticateOverrides ): Promise { let _toSign = messageToSign; if (!_toSign) { - _toSign = await createSiweMessage({ + const restOverrides = siweMessageOverrides ?? {}; + + const nonce = await fetchBlockchainData(); + + const siweParams: BaseSiweMessage = { walletAddress: account.account!.address, - nonce: await fetchBlockchainData(), + nonce, + ...restOverrides, + }; + + _toSign = await createSiweMessage({ + ...siweParams, }); }