Skip to content

Commit def7c3c

Browse files
committed
Merge branch 'feat/auto-ci-fmt' of https://github.com/LIT-Protocol/js-sdk into feat/auto-ci-fmt
2 parents 760191e + 0848970 commit def7c3c

File tree

1 file changed

+20
-15
lines changed

1 file changed

+20
-15
lines changed

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

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ import type {
135135

136136
export class LitNodeClientNodeJs
137137
extends LitCore
138-
implements LitClientSessionManager, ILitNodeClient {
138+
implements LitClientSessionManager, ILitNodeClient
139+
{
139140
defaultAuthCallback?: (authSigParams: AuthCallbackParams) => Promise<AuthSig>;
140141

141142
// ========== Constructor ==========
@@ -1292,8 +1293,8 @@ export class LitNodeClientNodeJs
12921293
// -- optional params
12931294
...(params.authMethods &&
12941295
params.authMethods.length > 0 && {
1295-
authMethods: params.authMethods,
1296-
}),
1296+
authMethods: params.authMethods,
1297+
}),
12971298
};
12981299

12991300
logWithRequestId(requestId, 'reqBody:', reqBody);
@@ -2065,18 +2066,25 @@ export class LitNodeClientNodeJs
20652066
};
20662067

20672068
/**
2068-
* Get session signatures for a set of [Lit resources](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.ILitResource.html#resource).
2069+
*
2070+
* Retrieves or generates sessionSigs (think access token) for accessing Lit Network resources.
20692071
*
20702072
* How this function works on a high level:
20712073
* 1. Generate or retrieve [session keys](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.SessionKeyPair.html) (a public and private key pair)
20722074
* 2. Generate or retrieve the [`AuthSig`](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.AuthSig.html) that specifies the session [abilities](https://v6-api-doc-lit-js-sdk.vercel.app/enums/auth_helpers_src.LitAbility.html)
20732075
* 3. Sign the specific resources with the session key
20742076
*
2077+
* The process follows these steps:
2078+
* 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.
2079+
* 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.
2080+
* 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.
2081+
* 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`.
2082+
*
2083+
* See Sequence Diagram: https://www.plantuml.com/plantuml/uml/VPH1RnCn48Nl_XLFlT1Av00eGkm15QKLWY8K9K9SO-rEar4sjcLFalBl6NjJAuaMRl5utfjlPjQvJsAZx7UziQtuY5-9eWaQufQ3TOAR77cJy407Rka6zlNdHTRouUbIzSEtjiTIBUswg5v_NwMnuAVlA9KKFPN3I0x9qSSj7bqNF3iPykl9c4o9oUSJMuElv2XQ8IHAYRt3bluWM8wuVUpUJwVlFjsP8JUh5B_1DyV2AYdD6DjhLsTQTaYd3W3ad28SGWqM997fG5ZrB9DJqOaALuRwH1TMpik8tIYze-E8OrPKU5I6cMqtem2kCqOhr4vdaRAvtSjcoMkTo68scKu_Vi1EPMfrP_xVtj7sFMaHNg-6GVqk0MW0z18uKdVULTvDWtdqko28b7KktvUB2hKOBd1asU2QgDfTzrj7T4bLPdv6TR0zLwPQKkkZpIRTY4CTMbrBpg_VKuXyi49beUAHqIlirOUrL2zq9JPPdpRR5OMLVQGoGlLcjyRyQNv6MHz4W_fG42W--xWhUfNyOxiLL1USS6lRLeyAkYLNjrkVJuClm_qp5I8Lq0krUw7lwIt2DgY9oiozrjA_Yhy0
20752084
*
20762085
* Note: When generating session signatures for different PKPs or auth methods,
20772086
* be sure to call disconnectWeb3 to clear auth signatures stored in local storage
20782087
*
2079-
*
20802088
* @param { GetSessionSigsProps } params
20812089
*
20822090
* An example of how this function is used can be found in the Lit developer-guides-code repository [here](https://github.com/LIT-Protocol/developer-guides-code/tree/master/session-signatures/getSessionSigs).
@@ -2085,21 +2093,18 @@ export class LitNodeClientNodeJs
20852093
getSessionSigs = async (
20862094
params: GetSessionSigsProps
20872095
): Promise<SessionSigsMap> => {
2088-
20892096
// -- prepare
20902097
// Try to get it from local storage, if not generates one~
20912098
const sessionKey = params.sessionKey ?? this.getSessionKey();
20922099

20932100
const sessionKeyUri = this.getSessionKeyUri(sessionKey.publicKey);
20942101

20952102
// First get or generate the session capability object for the specified resources.
2096-
const sessionCapabilityObject = params.sessionCapabilityObject
2103+
const sessionCapabilityObject = params.sessionCapabilityObject
20972104
? params.sessionCapabilityObject
20982105
: await this.generateSessionCapabilityObjectWithWildcards(
2099-
params.resourceAbilityRequests.map((
2100-
r
2101-
) => r.resource)
2102-
);
2106+
params.resourceAbilityRequests.map((r) => r.resource)
2107+
);
21032108
const expiration = params.expiration || LitNodeClientNodeJs.getExpiration();
21042109

21052110
// -- (TRY) to get the wallet signature
@@ -2182,10 +2187,10 @@ export class LitNodeClientNodeJs
21822187

21832188
const capabilities = params.capacityDelegationAuthSig
21842189
? [
2185-
...(params.capabilityAuthSigs ?? []),
2186-
params.capacityDelegationAuthSig,
2187-
authSig,
2188-
]
2190+
...(params.capabilityAuthSigs ?? []),
2191+
params.capacityDelegationAuthSig,
2192+
authSig,
2193+
]
21892194
: [...(params.capabilityAuthSigs ?? []), authSig];
21902195

21912196
const signingTemplate = {

0 commit comments

Comments
 (0)