11import { computeAddress } from '@ethersproject/transactions' ;
22import { BigNumber , ethers } from 'ethers' ;
3- import { joinSignature , sha256 } from 'ethers/lib/utils' ;
3+ import { sha256 } from 'ethers/lib/utils' ;
44import { SiweMessage } from 'siwe' ;
55
66import {
77 LitAccessControlConditionResource ,
88 LitResourceAbilityRequest ,
9- decode ,
109 RecapSessionCapabilityObject ,
11- generateAuthSig ,
10+ createSiweMessage ,
1211 createSiweMessageWithCapacityDelegation ,
1312 createSiweMessageWithRecaps ,
14- createSiweMessage ,
13+ decode ,
14+ generateAuthSig ,
1515} from '@lit-protocol/auth-helpers' ;
1616import {
1717 AUTH_METHOD_TYPE ,
1818 EITHER_TYPE ,
1919 FALLBACK_IPFS_GATEWAYS ,
2020 GLOBAL_OVERWRITE_IPFS_CODE_BY_NETWORK ,
21+ InvalidArgumentException ,
22+ InvalidParamType ,
23+ InvalidSessionSigs ,
24+ InvalidSignatureError ,
2125 LIT_ACTION_IPFS_HASH ,
2226 LIT_CURVE ,
2327 LIT_ENDPOINT ,
2428 LIT_SESSION_KEY_URI ,
2529 LOCAL_STORAGE_KEYS ,
26- ParamsMissingError ,
27- ParamNullError ,
28- NoValidShares ,
29- UnknownSignatureType ,
30- UnknownSignatureError ,
3130 LitNodeClientNotReadyError ,
32- InvalidParamType ,
33- InvalidArgumentException ,
34- WalletSignatureNotFoundError ,
31+ ParamNullError ,
32+ ParamsMissingError ,
3533 UnknownError ,
36- InvalidSignatureError ,
3734 UnsupportedMethodError ,
38- InvalidSessionSigs ,
35+ WalletSignatureNotFoundError ,
3936} from '@lit-protocol/constants' ;
4037import { LitCore , composeLitUrl } from '@lit-protocol/core' ;
4138import {
@@ -56,8 +53,8 @@ import {
5653 logWithRequestId ,
5754 mostCommonString ,
5855 normalizeAndStringify ,
59- safeParams ,
6056 removeHexPrefix ,
57+ safeParams ,
6158 validateSessionSigs ,
6259} from '@lit-protocol/misc' ;
6360import {
@@ -66,17 +63,17 @@ import {
6663 setStorageItem ,
6764} from '@lit-protocol/misc-browser' ;
6865import { nacl } from '@lit-protocol/nacl' ;
66+ import { ILitResource , ISessionCapabilityObject } from '@lit-protocol/types' ;
6967import {
7068 uint8arrayFromString ,
7169 uint8arrayToString ,
7270} from '@lit-protocol/uint8arrays' ;
73- import { ILitResource , ISessionCapabilityObject } from '@lit-protocol/types' ;
7471
7572import { encodeCode } from './helpers/encode-code' ;
7673import { getBlsSignatures } from './helpers/get-bls-signatures' ;
7774import { getClaims } from './helpers/get-claims' ;
7875import { getClaimsList } from './helpers/get-claims-list' ;
79- import { getFlattenShare , getSignatures } from './helpers/get-signatures' ;
76+ import { getSignatures } from './helpers/get-signatures' ;
8077import { normalizeArray } from './helpers/normalize-array' ;
8178import { normalizeJsParams } from './helpers/normalize-params' ;
8279import { parseAsJsonOrString } from './helpers/parse-as-json-or-string' ;
@@ -89,6 +86,9 @@ import type {
8986 AuthCallback ,
9087 AuthCallbackParams ,
9188 AuthSig ,
89+ BlsResponseData ,
90+ CapacityCreditsReq ,
91+ CapacityCreditsRes ,
9292 ClaimKeyResponse ,
9393 ClaimProcessor ,
9494 ClaimRequest ,
@@ -97,13 +97,25 @@ import type {
9797 DecryptResponse ,
9898 EncryptRequest ,
9999 EncryptResponse ,
100+ EncryptSdkParams ,
101+ EncryptionSignRequest ,
102+ ExecuteJsNoSigningResponse ,
100103 ExecuteJsResponse ,
101104 FormattedMultipleAccs ,
105+ GetLitActionSessionSigs ,
106+ GetPkpSessionSigs ,
102107 GetSessionSigsProps ,
103- GetSignedTokenRequest ,
108+ GetSignSessionKeySharesProp ,
104109 GetWalletSigProps ,
110+ ILitNodeClient ,
105111 JsonExecutionRequest ,
112+ JsonExecutionRequestTargetNode ,
113+ JsonExecutionSdkParams ,
114+ JsonExecutionSdkParamsTargetNode ,
115+ JsonPKPClaimKeyRequest ,
106116 JsonPkpSignRequest ,
117+ JsonPkpSignSdkParams ,
118+ JsonSignSessionKeyRequestV1 ,
107119 LitClientSessionManager ,
108120 LitNodeClientConfig ,
109121 NodeBlsSigningShare ,
@@ -115,30 +127,11 @@ import type {
115127 SessionKeyPair ,
116128 SessionSigningTemplate ,
117129 SessionSigsMap ,
118- SigShare ,
130+ SigResponse ,
119131 SignSessionKeyProp ,
120132 SignSessionKeyResponse ,
121133 Signature ,
122134 SuccessNodePromises ,
123- ILitNodeClient ,
124- GetPkpSessionSigs ,
125- CapacityCreditsReq ,
126- CapacityCreditsRes ,
127- JsonSignSessionKeyRequestV1 ,
128- BlsResponseData ,
129- JsonExecutionSdkParamsTargetNode ,
130- JsonExecutionRequestTargetNode ,
131- JsonExecutionSdkParams ,
132- ExecuteJsNoSigningResponse ,
133- JsonPkpSignSdkParams ,
134- SigResponse ,
135- EncryptSdkParams ,
136- GetLitActionSessionSigs ,
137- GetSignSessionKeySharesProp ,
138- EncryptionSignRequest ,
139- SigningAccessControlConditionRequest ,
140- JsonPKPClaimKeyRequest ,
141- IpfsOptions ,
142135} from '@lit-protocol/types' ;
143136
144137export class LitNodeClientNodeJs
@@ -1215,127 +1208,6 @@ export class LitNodeClientNodeJs
12151208 return signatures . signature ; // only a single signature is ever present, so we just return it.
12161209 } ;
12171210
1218- /**
1219- *
1220- * Request a signed JWT from the LIT network. Before calling this function, you must know the access control conditions for the item you wish to gain authorization for.
1221- *
1222- * @param { GetSignedTokenRequest } params
1223- *
1224- * @returns { Promise<string> } final JWT
1225- *
1226- */
1227- getSignedToken = async ( params : GetSignedTokenRequest ) : Promise < string > => {
1228- // ========== Prepare Params ==========
1229- const { chain, authSig, sessionSigs } = params ;
1230-
1231- // ========== Validation ==========
1232- // -- validate if it's ready
1233- if ( ! this . ready ) {
1234- throw new LitNodeClientNotReadyError (
1235- { } ,
1236- '3 LitNodeClient is not ready. Please call await litNodeClient.connect() first.'
1237- ) ;
1238- }
1239-
1240- // -- validate if this.networkPubKeySet is null
1241- if ( this . networkPubKeySet === null ) {
1242- throw new ParamNullError ( { } , 'networkPubKeySet cannot be null' ) ;
1243- }
1244-
1245- const paramsIsSafe = safeParams ( {
1246- functionName : 'getSignedToken' ,
1247- params,
1248- } ) ;
1249-
1250- if ( ! paramsIsSafe ) {
1251- throw new InvalidParamType (
1252- {
1253- info : {
1254- params,
1255- } ,
1256- } ,
1257- 'Parameter validation failed.'
1258- ) ;
1259- }
1260-
1261- // ========== Prepare ==========
1262- // we need to send jwt params iat (issued at) and exp (expiration)
1263- // because the nodes may have different wall clock times
1264- // the nodes will verify that these params are withing a grace period
1265- const { iat, exp } = this . getJWTParams ( ) ;
1266-
1267- // ========== Formatting Access Control Conditions =========
1268- const {
1269- error,
1270- formattedAccessControlConditions,
1271- formattedEVMContractConditions,
1272- formattedSolRpcConditions,
1273- formattedUnifiedAccessControlConditions,
1274- } : FormattedMultipleAccs = this . getFormattedAccessControlConditions ( params ) ;
1275-
1276- if ( error ) {
1277- throw new InvalidArgumentException (
1278- {
1279- info : {
1280- params,
1281- } ,
1282- } ,
1283- 'You must provide either accessControlConditions or evmContractConditions or solRpcConditions or unifiedAccessControlConditions'
1284- ) ;
1285- }
1286-
1287- // ========== Get Node Promises ==========
1288- const requestId = this . _getNewRequestId ( ) ;
1289- const nodePromises = this . getNodePromises ( ( url : string ) => {
1290- // -- if session key is available, use it
1291- const authSigToSend = sessionSigs ? sessionSigs [ url ] : authSig ;
1292-
1293- const reqBody : SigningAccessControlConditionRequest = {
1294- accessControlConditions : formattedAccessControlConditions ,
1295- evmContractConditions : formattedEVMContractConditions ,
1296- solRpcConditions : formattedSolRpcConditions ,
1297- unifiedAccessControlConditions : formattedUnifiedAccessControlConditions ,
1298- chain,
1299- authSig : authSigToSend ,
1300- iat,
1301- exp,
1302- } ;
1303-
1304- const urlWithPath = composeLitUrl ( {
1305- url,
1306- endpoint : LIT_ENDPOINT . SIGN_ACCS ,
1307- } ) ;
1308-
1309- return this . generatePromise ( urlWithPath , reqBody , requestId ) ;
1310- } ) ;
1311-
1312- // -- resolve promises
1313- const res = await this . handleNodePromises (
1314- nodePromises ,
1315- requestId ,
1316- this . config . minNodeCount
1317- ) ;
1318-
1319- // -- case: promises rejected
1320- if ( ! res . success ) {
1321- this . _throwNodeError ( res , requestId ) ;
1322- }
1323-
1324- const signatureShares : NodeBlsSigningShare [ ] = (
1325- res as SuccessNodePromises < NodeBlsSigningShare >
1326- ) . values ;
1327-
1328- log ( 'signatureShares' , signatureShares ) ;
1329-
1330- // ========== Result ==========
1331- const finalJwt : string = await this . combineSharesAndGetJWT (
1332- signatureShares ,
1333- requestId
1334- ) ;
1335-
1336- return finalJwt ;
1337- } ;
1338-
13391211 /**
13401212 *
13411213 * Encrypt data using the LIT network public key.
0 commit comments