Skip to content

Commit c6ac406

Browse files
committed
doc(getSessionSigs): improve jsDocs
1 parent 6003741 commit c6ac406

File tree

1 file changed

+33
-27
lines changed

1 file changed

+33
-27
lines changed

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

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

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

142141
// ========== Constructor ==========
@@ -1293,8 +1292,8 @@ export class LitNodeClientNodeJs
12931292
// -- optional params
12941293
...(params.authMethods &&
12951294
params.authMethods.length > 0 && {
1296-
authMethods: params.authMethods,
1297-
}),
1295+
authMethods: params.authMethods,
1296+
}),
12981297
};
12991298

13001299
logWithRequestId(requestId, 'reqBody:', reqBody);
@@ -2066,23 +2065,30 @@ export class LitNodeClientNodeJs
20662065
};
20672066

20682067
/**
2069-
* Get session signatures for a set of [Lit resources](https://v6-api-doc-lit-js-sdk.vercel.app/interfaces/types_src.ILitResource.html#resource).
2070-
*
2071-
* How this function works on a high level:
2072-
* 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)
2073-
* 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)
2074-
* 3. Sign the specific resources with the session key
2075-
*
2076-
*
2077-
* Note: When generating session signatures for different PKPs or auth methods,
2078-
* be sure to call disconnectWeb3 to clear auth signatures stored in local storage
2079-
*
2080-
*
2081-
* @param { GetSessionSigsProps } params
2082-
*
2083-
* 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).
2084-
*
2085-
*/
2068+
*
2069+
* Retrieves or generates sessionSigs (think access token) for accessing Lit Network resources.
2070+
*
2071+
* How this function works on a high level:
2072+
* 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)
2073+
* 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)
2074+
* 3. Sign the specific resources with the session key
2075+
*
2076+
* The process follows these steps:
2077+
* 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.
2078+
* 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.
2079+
* 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.
2080+
* 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`.
2081+
*
2082+
* See Sequence Diagram: https://www.plantuml.com/plantuml/uml/VPH1RnCn48Nl_XLFlT1Av00eGkm15QKLWY8K9K9SO-rEar4sjcLFalBl6NjJAuaMRl5utfjlPjQvJsAZx7UziQtuY5-9eWaQufQ3TOAR77cJy407Rka6zlNdHTRouUbIzSEtjiTIBUswg5v_NwMnuAVlA9KKFPN3I0x9qSSj7bqNF3iPykl9c4o9oUSJMuElv2XQ8IHAYRt3bluWM8wuVUpUJwVlFjsP8JUh5B_1DyV2AYdD6DjhLsTQTaYd3W3ad28SGWqM997fG5ZrB9DJqOaALuRwH1TMpik8tIYze-E8OrPKU5I6cMqtem2kCqOhr4vdaRAvtSjcoMkTo68scKu_Vi1EPMfrP_xVtj7sFMaHNg-6GVqk0MW0z18uKdVULTvDWtdqko28b7KktvUB2hKOBd1asU2QgDfTzrj7T4bLPdv6TR0zLwPQKkkZpIRTY4CTMbrBpg_VKuXyi49beUAHqIlirOUrL2zq9JPPdpRR5OMLVQGoGlLcjyRyQNv6MHz4W_fG42W--xWhUfNyOxiLL1USS6lRLeyAkYLNjrkVJuClm_qp5I8Lq0krUw7lwIt2DgY9oiozrjA_Yhy0
2083+
*
2084+
* Note: When generating session signatures for different PKPs or auth methods,
2085+
* be sure to call disconnectWeb3 to clear auth signatures stored in local storage
2086+
*
2087+
* @param { GetSessionSigsProps } params
2088+
*
2089+
* 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).
2090+
*
2091+
*/
20862092
getSessionSigs = async (
20872093
params: GetSessionSigsProps
20882094
): Promise<SessionSigsMap> => {
@@ -2096,8 +2102,8 @@ export class LitNodeClientNodeJs
20962102
const sessionCapabilityObject = params.sessionCapabilityObject
20972103
? params.sessionCapabilityObject
20982104
: await this.generateSessionCapabilityObjectWithWildcards(
2099-
params.resourceAbilityRequests.map((r) => r.resource)
2100-
);
2105+
params.resourceAbilityRequests.map((r) => r.resource)
2106+
);
21012107
const expiration = params.expiration || LitNodeClientNodeJs.getExpiration();
21022108

21032109
// -- (TRY) to get the wallet signature
@@ -2180,10 +2186,10 @@ export class LitNodeClientNodeJs
21802186

21812187
const capabilities = params.capacityDelegationAuthSig
21822188
? [
2183-
...(params.capabilityAuthSigs ?? []),
2184-
params.capacityDelegationAuthSig,
2185-
authSig,
2186-
]
2189+
...(params.capabilityAuthSigs ?? []),
2190+
params.capacityDelegationAuthSig,
2191+
authSig,
2192+
]
21872193
: [...(params.capabilityAuthSigs ?? []), authSig];
21882194

21892195
const signingTemplate = {

0 commit comments

Comments
 (0)