1- import { expectEvmAddress , expectSignature } from '@polymarket/types' ;
2- import type { Account , WalletClient } from 'viem' ;
1+ import {
2+ expectEvmAddress ,
3+ expectSignature ,
4+ invariant ,
5+ } from '@polymarket/types' ;
6+ import type { Account , Chain , Transport , WalletClient } from 'viem' ;
37import type { AuthenticationWorkflow } from '../authentication' ;
48import type { SecureClient } from '../clients' ;
59
6- function getAccount ( walletClient : WalletClient ) : Account | `0x${string } ` {
7- const account = walletClient . account ;
8-
9- if ( account ) {
10- return account ;
11- }
12-
13- throw new Error ( 'Expected a WalletClient with a hoisted account.' ) ;
10+ function isWalletClientWithAccount (
11+ walletClient : WalletClient ,
12+ ) : walletClient is WalletClient < Transport , Chain , Account > {
13+ return walletClient . account !== undefined ;
1414}
1515
1616export function authenticateWith ( walletClient : WalletClient ) {
17- const account = getAccount ( walletClient ) ;
17+ invariant (
18+ isWalletClientWithAccount ( walletClient ) ,
19+ 'Wallet client with account is required' ,
20+ ) ;
21+
22+ const account = walletClient . account ;
1823 const address = expectEvmAddress (
19- typeof account === 'string' ? account : account . address ,
24+ typeof walletClient . account === 'string'
25+ ? walletClient . account
26+ : walletClient . account . address ,
2027 ) ;
2128
2229 return async function authenticate (
@@ -30,15 +37,12 @@ export function authenticateWith(walletClient: WalletClient) {
3037 case 'requestAddress' :
3138 result = await workflow . next ( address ) ;
3239 break ;
33- case 'signTypedData ' :
40+ case 'signAuthMessage ' :
3441 result = await workflow . next (
3542 expectSignature (
3643 await walletClient . signTypedData ( {
3744 account,
38- ...( result . value . payload as Omit <
39- Parameters < WalletClient [ 'signTypedData' ] > [ 0 ] ,
40- 'account'
41- > ) ,
45+ ...result . value . payload ,
4246 } ) ,
4347 ) ,
4448 ) ;
0 commit comments