Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/cuddly-rats-yawn.md
Original file line number Diff line number Diff line change
@@ -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.
16 changes: 13 additions & 3 deletions docs/sdk/auth/pkp-native-auth/pkp-eoa-auth.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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.

<CodeGroup>
```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';
Expand Down Expand Up @@ -111,4 +121,4 @@ const authContext = await authManager.createPkpAuthContext({
});
```
</Step>
</Steps>
</Steps>
6 changes: 3 additions & 3 deletions docs/sdk/introduction.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
- **[Network Status](/sdk/resources/network-status)**: - Monitor real-time uptime and performance of Lit Protocol networks
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -18,6 +18,10 @@ const _logger = getChildLogger({
module: 'WalletClientAuthenticator',
});

export type WalletClientAuthenticateOverrides = Partial<
Omit<BaseSiweMessage, 'walletAddress' | 'nonce'>
>;

export class WalletClientAuthenticator {
public readonly type = 'walletClient';

Expand All @@ -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<AuthData> {
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,
});
}

Expand Down
Loading