Skip to content

Commit dd42b70

Browse files
committed
feat: add assertConnected at pkpSign
1 parent 6e071ea commit dd42b70

File tree

2 files changed

+26
-31
lines changed

2 files changed

+26
-31
lines changed

local-tests/tests/testUseEoaAuthContextToPkpSign.ts

Lines changed: 24 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
import { ethers } from 'ethers';
22

3-
import { LitPKPResource } from '@lit-protocol/auth-helpers';
3+
import { createSiweMessageWithRecaps, generateAuthSig, LitPKPResource } from '@lit-protocol/auth-helpers';
44
import { LIT_ABILITY } from '@lit-protocol/constants';
5-
import { EthWalletProvider } from '@lit-protocol/lit-auth-client';
6-
import { LitNodeClient } from '@lit-protocol/lit-node-client';
75
import { log } from '@lit-protocol/misc';
86
import { AuthCallbackParams, AuthSig } from '@lit-protocol/types';
97
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
@@ -27,36 +25,31 @@ export const testUseEoaAuthContextToPkpSign = async (
2725
ability: LIT_ABILITY.PKPSigning,
2826
},
2927
];
30-
const litNodeClient = new LitNodeClient({
31-
litNetwork: alice.envConfig.network,
32-
authContext: {
33-
getSessionSigsProps: {
34-
resourceAbilityRequests,
35-
expiration,
36-
authNeededCallback: async function (
37-
params: AuthCallbackParams
38-
): Promise<AuthSig> {
39-
const response = await litNodeClient.signSessionKey({
40-
sessionKey: params.sessionKey,
41-
statement: params.statement || 'Some custom statement.',
42-
authMethods: [
43-
await EthWalletProvider.authenticate({
44-
signer: alice.wallet,
45-
litNodeClient: litNodeClient,
46-
expiration: params.expiration,
47-
}),
48-
],
49-
pkpPublicKey: alice.pkp.publicKey,
50-
expiration: params.expiration,
51-
resources: params.resources,
52-
chainId: 1,
28+
const litNodeClient = alice.envConfig.litNodeClient;
5329

54-
// -- required fields
55-
resourceAbilityRequests: params.resourceAbilityRequests,
56-
});
30+
litNodeClient.setAuthContext({
31+
getSessionSigsProps: {
32+
chain: 'ethereum',
33+
resourceAbilityRequests,
34+
expiration,
35+
authNeededCallback: async function (
36+
params: AuthCallbackParams
37+
): Promise<AuthSig> {
38+
const toSign = await createSiweMessageWithRecaps({
39+
uri: params.uri,
40+
expiration: params.expiration,
41+
resources: params.resourceAbilityRequests,
42+
walletAddress: alice.wallet.address,
43+
nonce: await litNodeClient.getLatestBlockhash(),
44+
litNodeClient: devEnv.litNodeClient,
45+
});
5746

58-
return response.authSig;
59-
},
47+
const authSig = await generateAuthSig({
48+
signer: alice.wallet,
49+
toSign,
50+
});
51+
52+
return authSig;
6053
},
6154
},
6255
});

packages/lit-node-client-nodejs/src/lib/lit-node-client-nodejs.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1130,6 +1130,8 @@ export class LitNodeClientNodeJs
11301130
* @param [params.getSessionSigsPropsOverride] - The props override when obtaining sessionSigs from the auth context
11311131
*/
11321132
pkpSign = async (params: JsonPkpSignSdkParams): Promise<SigResponse> => {
1133+
await this.assertConnected();
1134+
11331135
// -- validate required params
11341136
const requiredParamKeys = ['toSign', 'pubKey'];
11351137
(requiredParamKeys as (keyof JsonPkpSignSdkParams)[]).forEach((key) => {

0 commit comments

Comments
 (0)