Skip to content

Commit 684349b

Browse files
authored
Merge pull request #787 from LIT-Protocol/feature/lit-4170-sdk-bug-domain-undefined-error-upon-session-expiry
Feature/lit 4170 sdk bug domain undefined error upon session expiry
2 parents d4e1a64 + 2c1afc4 commit 684349b

File tree

5 files changed

+78
-5
lines changed

5 files changed

+78
-5
lines changed

local-tests/setup/session-sigs/get-pkp-session-sigs.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ export const getPkpSessionSigs = async (
1212
devEnv: TinnyEnvironment,
1313
alice: TinnyPerson,
1414
resourceAbilityRequests?: LitResourceAbilityRequest[],
15-
expiration?: string
15+
expiration?: string,
16+
domain?: string
1617
) => {
1718
const centralisation =
1819
CENTRALISATION_BY_NETWORK[devEnv.litNodeClient.config.litNetwork];
@@ -39,6 +40,7 @@ export const getPkpSessionSigs = async (
3940
pkpPublicKey: alice.authMethodOwnedPkp.publicKey,
4041
authMethods: [alice.authMethod],
4142
expiration,
43+
domain,
4244
resourceAbilityRequests: _resourceAbilityRequests,
4345

4446
...(centralisation === 'decentralised' && {

local-tests/test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
import { ethers } from 'ethers';
2+
3+
import { log } from '@lit-protocol/misc';
4+
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';
15
import { TinnyEnvironment } from './setup/tinny-environment';
26
import { runInBand, runTestsParallel } from './setup/tinny-operations';
37
// import { testBundleSpeed } from './tests/test-bundle-speed';
@@ -109,6 +113,7 @@ import { testFailBatchGeneratePrivateKeysAtomic } from './tests/wrapped-keys/tes
109113

110114
import { setLitActionsCodeToLocal } from './tests/wrapped-keys/util';
111115
import { testUseEoaSessionSigsToRequestSingleResponse } from './tests/testUseEoaSessionSigsToRequestSingleResponse';
116+
import { testPkpSessionSigsDomain } from './tests/testPkpSessionSigsDomain';
112117

113118
// Use the current LIT action code to test against
114119
setLitActionsCodeToLocal();
@@ -185,6 +190,7 @@ setLitActionsCodeToLocal();
185190
testUsePkpSessionSigsToExecuteJsConsoleLog,
186191
testUsePkpSessionSigsToEncryptDecryptString,
187192
testUsePkpSessionSigsToEncryptDecryptFile,
193+
testPkpSessionSigsDomain,
188194
};
189195

190196
const litActionSessionSigsTests = {
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
import { log } from '@lit-protocol/misc';
2+
import { getPkpSessionSigs } from 'local-tests/setup/session-sigs/get-pkp-session-sigs';
3+
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
4+
5+
/**
6+
* Test Commands:
7+
* ✅ NETWORK=datil-dev yarn test:local --filter=testPkpSessionSigsDomain
8+
* ✅ NETWORK=datil-test yarn test:local --filter=testPkpSessionSigsDomain
9+
* ✅ NETWORK=custom yarn test:local --filter=testPkpSessionSigsDomain
10+
*/
11+
export const testPkpSessionSigsDomain = async (devEnv: TinnyEnvironment) => {
12+
const alice = await devEnv.createRandomPerson();
13+
const testDomain = 'test.domain.com';
14+
15+
// AuthNeededCallback props:
16+
// props: {
17+
// chain: 'ethereum',
18+
// statement: 'I further authorize the stated URI to perform the following actions on my behalf:',
19+
// resources: [ 'urn:recap:eyJhdHQiOnt9LCJwcmYiOltdfQ' ],
20+
// expiration: '2025-02-01T16:51:50.358Z',
21+
// uri: 'lit:session:e43c4bdff81bb83e7bedf079f5546f237d6e1344c9981735fe8d3a0bbc07c371',
22+
// sessionKey: {
23+
// publicKey: 'e43c4bdff81bb83e7bedf079f5546f237d6e1344c9981735fe8d3a0bbc07c371',
24+
// secretKey: 'a5f43862612394a59f64708a847825255d66839fd6972d3538cb5dffce7228aee43c4bdff81bb83e7bedf079f5546f237d6e1344c9981735fe8d3a0bbc07c371'
25+
// },
26+
// nonce: '0x53e14ac177c02e4b460432ef2bd639519c589137f16136027505c58793608ef7',
27+
// domain: 'test.domain.com',
28+
// resourceAbilityRequests: [
29+
// { resource: [LitPKPResource], ability: 'pkp-signing' },
30+
// { resource: [LitActionResource], ability: 'lit-action-execution' }
31+
// ]
32+
// }
33+
const pkpSessionSigs = await getPkpSessionSigs(
34+
devEnv,
35+
alice,
36+
undefined,
37+
undefined,
38+
testDomain
39+
);
40+
41+
// Get the first session sig to verify
42+
const firstNodeAddress = Object.keys(pkpSessionSigs)[0];
43+
const firstSessionSig = pkpSessionSigs[firstNodeAddress];
44+
45+
// Parse the signed message to verify domain
46+
const signedMessage = firstSessionSig.signedMessage;
47+
48+
// Verify that the domain is present in the signed message
49+
if (!signedMessage.includes(testDomain)) {
50+
throw new Error(
51+
`Expected domain "${testDomain}" in signed message, but it was not found. Signed message: ${signedMessage}`
52+
);
53+
}
54+
55+
log('✅ Domain parameter successfully passed through in sessionSigs');
56+
57+
// Clean up
58+
devEnv.releasePrivateKeyFromUser(alice);
59+
};

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

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,7 @@ export class LitNodeClientNodeJs
345345
litActionIpfsId,
346346
jsParams,
347347
sessionKey,
348+
domain,
348349
}: GetWalletSigProps): Promise<AuthSig> => {
349350
let walletSig: AuthSig;
350351

@@ -384,6 +385,7 @@ export class LitNodeClientNodeJs
384385
uri: sessionKeyUri,
385386
sessionKey: sessionKey,
386387
nonce,
388+
domain,
387389

388390
// for recap
389391
...(resourceAbilityRequests && { resourceAbilityRequests }),
@@ -418,6 +420,7 @@ export class LitNodeClientNodeJs
418420
expiration,
419421
uri: sessionKeyUri,
420422
nonce,
423+
domain,
421424
});
422425
}
423426

@@ -1857,7 +1860,7 @@ export class LitNodeClientNodeJs
18571860
*
18581861
* The process follows these steps:
18591862
* 1. Retrieves or generates a session key pair (Ed25519) for the user's device. The session key is either fetched from local storage or newly created if not found. The key does not expire.
1860-
* 2. Generates an authentication signature (`authSig`) by signing an ERC-5573 Sign-in with Ethereum message, which includes resource ability requests, capabilities, expiration, the user's device session public key, and a nonce. The `authSig` is retrieved from local storage, and if it has expired, the user will be prompted to re-sign.
1863+
* 2. Generates an authentication signature (`authSig`) by signing an ERC-5573 "Sign-in with Ethereum" message, which includes resource ability requests, capabilities, expiration, the user's device session public key, and a nonce. The `authSig` is retrieved from local storage, and if it has expired, the user will be prompted to re-sign.
18611864
* 3. Uses the session private key to sign the session public key along with the resource ability requests, capabilities, issuedAt, and expiration details. This creates a device-generated signature.
18621865
* 4. Constructs the session signatures (`sessionSigs`) by including the device-generated signature and the original message. The `sessionSigs` provide access to Lit Network features such as `executeJs` and `pkpSign`.
18631866
*
@@ -1898,6 +1901,7 @@ export class LitNodeClientNodeJs
18981901
sessionKey: sessionKey,
18991902
sessionKeyUri: sessionKeyUri,
19001903
nonce: await this.getLatestBlockhash(),
1904+
domain: params.domain,
19011905

19021906
// -- for recap
19031907
resourceAbilityRequests: params.resourceAbilityRequests,
@@ -2119,6 +2123,7 @@ export class LitNodeClientNodeJs
21192123
expiration: props.expiration,
21202124
resources: props.resources,
21212125
chainId: 1,
2126+
domain: props.domain,
21222127

21232128
// -- required fields
21242129
resourceAbilityRequests: props.resourceAbilityRequests,

packages/types/src/lib/interfaces.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ export interface AuthCallbackParams extends LitActionSdkParams {
114114

115115
uri?: string;
116116

117+
domain?: string;
117118
/**
118119
* Cosmos wallet type, to support mutliple popular cosmos wallets
119120
* Keplr & Cypher -> window.keplr
@@ -1018,9 +1019,6 @@ export interface SignSessionKeyProp extends LitActionSdkParams {
10181019

10191020
chainId?: number;
10201021

1021-
/**
1022-
* domain param is required, when calling from environment that doesn't have the 'location' object. i.e. NodeJs server.
1023-
*/
10241022
domain?: string;
10251023

10261024
/**
@@ -1091,6 +1089,8 @@ export interface CommonGetSessionSigsProps {
10911089
* Not limited to capacityDelegationAuthSig. Other AuthSigs with other purposes can also be in this array.
10921090
*/
10931091
capabilityAuthSigs?: AuthSig[];
1092+
1093+
domain?: string;
10941094
}
10951095

10961096
export interface BaseProviderGetSessionSigsProps
@@ -1149,6 +1149,7 @@ export interface GetWalletSigProps extends LitActionSdkParams {
11491149
sessionKeyUri: string;
11501150
nonce: string;
11511151
resourceAbilityRequests?: LitResourceAbilityRequest[];
1152+
domain?: string;
11521153
}
11531154

11541155
export interface SessionSigningTemplate {

0 commit comments

Comments
 (0)