Skip to content

Commit c78f4b8

Browse files
authored
Merge pull request #701 from LIT-Protocol/remove/verify-jwt-for-v7
Remove/verify jwt for v7
2 parents 5c7eb1d + e7476a3 commit c78f4b8

File tree

6 files changed

+37
-264
lines changed

6 files changed

+37
-264
lines changed

packages/access-control-conditions/src/lib/validator.spec.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -314,8 +314,8 @@ describe('validator.ts', () => {
314314
}
315315

316316
expect(error).toBeDefined();
317-
expect(error!.errorKind).toBe(LIT_ERROR.INVALID_PARAM_TYPE.kind);
318-
expect(error!.errorCode).toBe(LIT_ERROR.INVALID_PARAM_TYPE.name);
317+
expect(error!.errorKind).toBe(LIT_ERROR['INVALID_PARAM_TYPE'].kind);
318+
expect(error!.errorCode).toBe(LIT_ERROR['INVALID_PARAM_TYPE'].name);
319319
});
320320

321321
it('should throw when schema has invalid fields', async () => {
@@ -348,8 +348,8 @@ describe('validator.ts', () => {
348348
}
349349

350350
expect(error).toBeDefined();
351-
expect(error!.errorKind).toBe(LIT_ERROR.INVALID_PARAM_TYPE.kind);
352-
expect(error!.errorCode).toBe(LIT_ERROR.INVALID_PARAM_TYPE.name);
351+
expect(error!.errorKind).toBe(LIT_ERROR['INVALID_PARAM_TYPE'].kind);
352+
expect(error!.errorCode).toBe(LIT_ERROR['INVALID_PARAM_TYPE'].name);
353353
});
354354

355355
it('should throw when schema of a nested ACC does not validate', async () => {
@@ -407,7 +407,7 @@ describe('validator.ts', () => {
407407
}
408408

409409
expect(error).toBeDefined();
410-
expect(error!.errorKind).toBe(LIT_ERROR.INVALID_PARAM_TYPE.kind);
411-
expect(error!.errorCode).toBe(LIT_ERROR.INVALID_PARAM_TYPE.name);
410+
expect(error!.errorKind).toBe(LIT_ERROR['INVALID_PARAM_TYPE'].kind);
411+
expect(error!.errorCode).toBe(LIT_ERROR['INVALID_PARAM_TYPE'].name);
412412
});
413413
});

packages/crypto/src/lib/crypto.ts

Lines changed: 0 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,10 @@ import { checkType, log } from '@lit-protocol/misc';
1212
import { nacl } from '@lit-protocol/nacl';
1313
import {
1414
CombinedECDSASignature,
15-
IJWT,
1615
NodeAttestation,
1716
SessionKeyPair,
1817
SigningAccessControlConditionJWTPayload,
1918
SigShare,
20-
VerifyJWTProps,
2119
} from '@lit-protocol/types';
2220
import {
2321
uint8arrayFromString,
@@ -473,59 +471,3 @@ declare global {
473471
// eslint-disable-next-line no-var, @typescript-eslint/no-explicit-any
474472
var LitNodeClient: any;
475473
}
476-
477-
/**
478-
* // TODO check for expiration
479-
*
480-
* Verify a JWT from the LIT network. Use this for auth on your server. For some background, users can specify access control conditions for various URLs, and then other users can then request a signed JWT proving that their ETH account meets those on-chain conditions using the getSignedToken function. Then, servers can verify that JWT using this function. A successful verification proves that the user meets the access control conditions defined earlier. For example, the on-chain condition could be posession of a specific NFT.
481-
*
482-
* @param { VerifyJWTProps } jwt
483-
*
484-
* @returns { IJWT<T> } An object with 4 keys: "verified": A boolean that represents whether or not the token verifies successfully. A true result indicates that the token was successfully verified. "header": the JWT header. "payload": the JWT payload which includes the resource being authorized, etc. "signature": A uint8array that represents the raw signature of the JWT.
485-
*/
486-
export const verifyJwt = async ({
487-
publicKey,
488-
jwt,
489-
}: VerifyJWTProps): Promise<IJWT<SigningAccessControlConditionJWTPayload>> => {
490-
// -- validate
491-
if (
492-
!checkType({
493-
value: jwt,
494-
allowedTypes: ['String'],
495-
paramName: 'jwt',
496-
functionName: 'verifyJwt',
497-
})
498-
)
499-
throw new InvalidParamType(
500-
{
501-
info: {
502-
jwt,
503-
},
504-
},
505-
'jwt must be a string'
506-
);
507-
508-
log('verifyJwt', jwt);
509-
510-
const jwtParts = jwt.split('.');
511-
const signature = uint8arrayFromString(jwtParts[2], 'base64url');
512-
513-
const unsignedJwt = `${jwtParts[0]}.${jwtParts[1]}`;
514-
515-
const message = uint8arrayFromString(unsignedJwt);
516-
517-
await verifySignature(publicKey, message, signature);
518-
519-
const _jwt: IJWT<SigningAccessControlConditionJWTPayload> = {
520-
verified: true,
521-
header: JSON.parse(
522-
uint8arrayToString(uint8arrayFromString(jwtParts[0], 'base64url'))
523-
),
524-
payload: JSON.parse(
525-
uint8arrayToString(uint8arrayFromString(jwtParts[1], 'base64url'))
526-
),
527-
signature,
528-
};
529-
530-
return _jwt;
531-
};

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

Lines changed: 31 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,38 @@
11
import { computeAddress } from '@ethersproject/transactions';
22
import { BigNumber, ethers } from 'ethers';
3-
import { joinSignature, sha256 } from 'ethers/lib/utils';
3+
import { sha256 } from 'ethers/lib/utils';
44
import { SiweMessage } from 'siwe';
55

66
import {
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';
1616
import {
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';
4037
import { LitCore, composeLitUrl } from '@lit-protocol/core';
4138
import {
@@ -56,8 +53,8 @@ import {
5653
logWithRequestId,
5754
mostCommonString,
5855
normalizeAndStringify,
59-
safeParams,
6056
removeHexPrefix,
57+
safeParams,
6158
validateSessionSigs,
6259
} from '@lit-protocol/misc';
6360
import {
@@ -66,17 +63,17 @@ import {
6663
setStorageItem,
6764
} from '@lit-protocol/misc-browser';
6865
import { nacl } from '@lit-protocol/nacl';
66+
import { ILitResource, ISessionCapabilityObject } from '@lit-protocol/types';
6967
import {
7068
uint8arrayFromString,
7169
uint8arrayToString,
7270
} from '@lit-protocol/uint8arrays';
73-
import { ILitResource, ISessionCapabilityObject } from '@lit-protocol/types';
7471

7572
import { encodeCode } from './helpers/encode-code';
7673
import { getBlsSignatures } from './helpers/get-bls-signatures';
7774
import { getClaims } from './helpers/get-claims';
7875
import { getClaimsList } from './helpers/get-claims-list';
79-
import { getFlattenShare, getSignatures } from './helpers/get-signatures';
76+
import { getSignatures } from './helpers/get-signatures';
8077
import { normalizeArray } from './helpers/normalize-array';
8178
import { normalizeJsParams } from './helpers/normalize-params';
8279
import { 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

144137
export 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

Comments
 (0)