Skip to content

Commit 2111f65

Browse files
committed
fix: define NodeAttestation to complete and fix LitNodeClient schema
1 parent 42dd84f commit 2111f65

File tree

6 files changed

+39
-62
lines changed

6 files changed

+39
-62
lines changed

packages/auth-helpers/src/lib/models.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,6 @@
11
import { LIT_ABILITY_VALUES } from '@lit-protocol/constants';
22
import { ILitResource } from '@lit-protocol/types';
33

4-
// This is here to prevent circular dependency issue
5-
export interface AuthSig {
6-
sig: any;
7-
derivedVia: string;
8-
signedMessage: string;
9-
address: string;
10-
}
114
export type PlainJSON =
125
| boolean
136
| number

packages/auth-helpers/src/lib/recap/recap-session-capability-object.ts

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,7 @@ import { SiweMessage } from 'siwe';
77
import { Recap } from 'siwe-recap';
88
import { LIT_ABILITY_VALUES } from '@lit-protocol/constants';
99
import { ILitResource, ISessionCapabilityObject } from '@lit-protocol/types';
10-
import {
11-
AuthSig,
12-
AttenuationsObject,
13-
CID as CIDString,
14-
PlainJSON,
15-
} from '../models';
10+
import { AttenuationsObject, CID as CIDString } from '../models';
1611
import { getRecapNamespaceAndAbility } from './utils';
1712
import { sanitizeSiweMessage } from '../siwe/siwe-helper';
1813

@@ -62,9 +57,9 @@ export class RecapSessionCapabilityObject implements ISessionCapabilityObject {
6257

6358
addAttenuation(
6459
resource: string,
65-
namespace: string = '*',
66-
name: string = '*',
67-
restriction: { [key: string]: PlainJSON } = {}
60+
namespace = '*',
61+
name = '*',
62+
restriction = {}
6863
) {
6964
return this._inner.addAttenuation(resource, namespace, name, restriction);
7065
}

packages/core/src/lib/lit-core.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@ import {
6666
NodeClientErrorV0,
6767
NodeClientErrorV1,
6868
NodeCommandServerKeysResponse,
69-
NodeErrorV3,
7069
RejectedNodePromises,
7170
SendNodeCommand,
7271
SessionSigsMap,

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

Lines changed: 15 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
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 {
@@ -25,9 +25,6 @@ import {
2525
LOCAL_STORAGE_KEYS,
2626
ParamsMissingError,
2727
ParamNullError,
28-
NoValidShares,
29-
UnknownSignatureType,
30-
UnknownSignatureError,
3128
LitNodeClientNotReadyError,
3229
InvalidParamType,
3330
InvalidArgumentException,
@@ -75,7 +72,7 @@ import { encodeCode } from './helpers/encode-code';
7572
import { getBlsSignatures } from './helpers/get-bls-signatures';
7673
import { getClaims } from './helpers/get-claims';
7774
import { getClaimsList } from './helpers/get-claims-list';
78-
import { getFlattenShare, getSignatures } from './helpers/get-signatures';
75+
import { getSignatures } from './helpers/get-signatures';
7976
import { normalizeArray } from './helpers/normalize-array';
8077
import { normalizeJsParams } from './helpers/normalize-params';
8178
import { parseAsJsonOrString } from './helpers/parse-as-json-or-string';
@@ -107,9 +104,7 @@ import type {
107104
LitNodeClientConfig,
108105
NodeBlsSigningShare,
109106
NodeCommandResponse,
110-
NodeLog,
111107
NodeShare,
112-
PKPSignShare,
113108
RejectedNodePromises,
114109
SessionKeyPair,
115110
SessionSigningTemplate,
@@ -137,7 +132,6 @@ import type {
137132
EncryptionSignRequest,
138133
SigningAccessControlConditionRequest,
139134
JsonPKPClaimKeyRequest,
140-
IpfsOptions,
141135
} from '@lit-protocol/types';
142136

143137
export class LitNodeClientNodeJs
@@ -606,6 +600,7 @@ export class LitNodeClientNodeJs
606600
* Combine Shares from network public key set and signature shares
607601
*
608602
* @param { NodeBlsSigningShare } signatureShares
603+
* @param { string } requestId
609604
*
610605
* @returns { string } final JWT (convert the sig to base64 and append to the jwt)
611606
*
@@ -717,9 +712,7 @@ export class LitNodeClientNodeJs
717712
*/
718713
runOnTargetedNodes = async (
719714
params: JsonExecutionSdkParamsTargetNode
720-
): Promise<
721-
SuccessNodePromises<NodeCommandResponse> | RejectedNodePromises
722-
> => {
715+
): Promise<SuccessNodePromises | RejectedNodePromises> => {
723716
log('running runOnTargetedNodes:', params.targetNodeRange);
724717

725718
if (!params.targetNodeRange) {
@@ -812,7 +805,7 @@ export class LitNodeClientNodeJs
812805
nodePromises,
813806
requestId,
814807
params.targetNodeRange
815-
)) as SuccessNodePromises<NodeCommandResponse> | RejectedNodePromises;
808+
)) as SuccessNodePromises | RejectedNodePromises;
816809
};
817810

818811
// ========== Scoped Business Logics ==========
@@ -969,7 +962,7 @@ export class LitNodeClientNodeJs
969962
}
970963

971964
// -- case: promises success (TODO: check the keys of "values")
972-
const responseData = (res as SuccessNodePromises<NodeShare>).values;
965+
const responseData = (res as SuccessNodePromises).values as NodeShare[];
973966

974967
logWithRequestId(
975968
requestId,
@@ -1032,9 +1025,7 @@ export class LitNodeClientNodeJs
10321025
const parsedResponse = parseAsJsonOrString(mostCommonResponse.response);
10331026

10341027
// -- 3. combine logs
1035-
const mostCommonLogs: string = mostCommonString(
1036-
responseData.map((r: NodeLog) => r.logs)
1037-
);
1028+
const mostCommonLogs = mostCommonString(responseData.map((r) => r.logs));
10381029

10391030
// -- 4. combine claims
10401031
const claimsList = getClaimsList(responseData);
@@ -1174,7 +1165,7 @@ export class LitNodeClientNodeJs
11741165
}
11751166

11761167
// -- case: promises success (TODO: check the keys of "values")
1177-
const responseData = (res as SuccessNodePromises<PKPSignShare>).values;
1168+
const responseData = (res as SuccessNodePromises).values;
11781169

11791170
logWithRequestId(
11801171
requestId,
@@ -1304,9 +1295,8 @@ export class LitNodeClientNodeJs
13041295
this._throwNodeError(res, requestId);
13051296
}
13061297

1307-
const signatureShares: NodeBlsSigningShare[] = (
1308-
res as SuccessNodePromises<NodeBlsSigningShare>
1309-
).values;
1298+
const signatureShares: NodeBlsSigningShare[] = (res as SuccessNodePromises)
1299+
.values;
13101300

13111301
log('signatureShares', signatureShares);
13121302

@@ -1553,9 +1543,8 @@ export class LitNodeClientNodeJs
15531543
this._throwNodeError(res, requestId);
15541544
}
15551545

1556-
const signatureShares: NodeBlsSigningShare[] = (
1557-
res as SuccessNodePromises<NodeBlsSigningShare>
1558-
).values;
1546+
const signatureShares: NodeBlsSigningShare[] = (res as SuccessNodePromises)
1547+
.values;
15591548

15601549
logWithRequestId(requestId, 'signatureShares', signatureShares);
15611550

@@ -1930,9 +1919,9 @@ export class LitNodeClientNodeJs
19301919
return signSessionKeyRes;
19311920
};
19321921

1933-
private _isSuccessNodePromises = <T>(
1934-
res: SuccessNodePromises<T> | RejectedNodePromises
1935-
): res is SuccessNodePromises<T> => {
1922+
private _isSuccessNodePromises = (
1923+
res: SuccessNodePromises | RejectedNodePromises
1924+
): res is SuccessNodePromises => {
19361925
return res.success;
19371926
};
19381927

packages/schemas/src/lib/schemas.ts

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -497,7 +497,7 @@ export const JsonSigningResourceIdSchema = z.object({
497497
export const JsonAccsRequestSchema =
498498
MultipleAccessControlConditionsSchema.extend({
499499
// The chain name of the chain that you are querying. See ALL_LIT_CHAINS for currently supported chains.
500-
chain: ChainSchema,
500+
chain: ChainSchema.optional(),
501501

502502
// The resourceId representing something on the web via a URL
503503
resourceId: JsonSigningResourceIdSchema.optional(),
@@ -668,13 +668,25 @@ export const HandshakeWithNodeSchema = z.object({
668668
challenge: z.string(),
669669
});
670670

671+
export const NodeAttestationSchema = z.object({
672+
type: z.string(),
673+
noonce: z.string(),
674+
data: z.object({
675+
INSTANCE_ID: z.string(),
676+
RELEASE_ID: z.string(),
677+
UNIX_TIME: z.string(),
678+
}),
679+
signatures: z.array(z.string()),
680+
report: z.string(),
681+
});
682+
671683
export const NodeCommandServerKeysResponseSchema = z.object({
672684
serverPublicKey: z.string(),
673685
subnetPublicKey: z.string(),
674686
networkPublicKey: z.string(),
675687
networkPublicKeySet: z.string(),
676688
hdRootPubkeys: z.array(z.string()),
677-
attestation: z.string().optional(),
689+
attestation: NodeAttestationSchema,
678690
latestBlockhash: z.string().optional(),
679691
});
680692

@@ -863,7 +875,7 @@ export const ILitNodeClientSchema = z.object({
863875

864876
// ========== Constructor ==========
865877
// ** IMPORTANT !! You have to create your constructor when implementing this class **
866-
constructor: z.function(),
878+
// constructor: z.function().args(z.union([LitNodeClientConfigSchema, CustomNetworkSchema])),
867879

868880
// ========== Scoped Class Helpers ==========
869881

@@ -894,7 +906,7 @@ export const ILitNodeClientSchema = z.object({
894906
*/
895907
combineSharesAndGetJWT: z
896908
.function()
897-
.args(z.array(NodeBlsSigningShareSchema))
909+
.args(z.array(NodeBlsSigningShareSchema), z.string().optional())
898910
.returns(z.promise(z.string())),
899911
/**
900912
*
@@ -936,7 +948,7 @@ export const ILitNodeClientSchema = z.object({
936948
*/
937949
getNodePromises: z
938950
.function()
939-
.args(z.function()) // TODO improve
951+
.args(z.function().args(z.string()).returns(z.promise(z.any()))) // TODO improve
940952
.returns(z.array(z.promise(z.any()))), // TODO
941953
/**
942954
* Handle node promises

packages/types/src/lib/interfaces.ts

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -40,11 +40,11 @@ import {
4040
SuccessNodePromisesSchema,
4141
NodeErrorV1Schema,
4242
RejectedNodePromisesSchema,
43+
NodeAttestationSchema,
4344
} from '@lit-protocol/schemas';
4445

4546
import { ILitNodeClient } from './ILitNodeClient';
4647
import { ISessionCapabilityObject, LitResourceAbilityRequest } from './models';
47-
import { SigningAccessControlConditionRequest } from './node-interfaces/node-interfaces';
4848
import {
4949
AcceptedFileType,
5050
AccessControlConditions,
@@ -463,14 +463,13 @@ export interface PkpSignedData {
463463
sigType: string;
464464
dataSigned: string;
465465
}
466-
export interface NodeShare {
466+
export interface NodeShare extends NodeLog {
467467
claimData: any;
468468
shareIndex: any;
469469
unsignedJwt: any;
470470
signedData: SigShare;
471471
decryptedData: any;
472472
response: any;
473-
logs: any;
474473
success?: boolean | '';
475474
}
476475

@@ -609,17 +608,7 @@ export interface CombinedECDSASignature {
609608

610609
export type HandshakeWithNode = z.infer<typeof HandshakeWithNodeSchema>;
611610

612-
export interface NodeAttestation {
613-
type: string;
614-
noonce: string;
615-
data: {
616-
INSTANCE_ID: string;
617-
RELEASE_ID: string;
618-
UNIX_TIME: string;
619-
};
620-
signatures: string[];
621-
report: string;
622-
}
611+
export type NodeAttestation = z.infer<typeof NodeAttestationSchema>;
623612

624613
export type JsonHandshakeResponse = z.infer<typeof JsonHandshakeResponseSchema>;
625614

0 commit comments

Comments
 (0)