Skip to content

Commit 42a380f

Browse files
committed
feat: types unification
1 parent 6e736ff commit 42a380f

File tree

8 files changed

+63
-73
lines changed

8 files changed

+63
-73
lines changed

local-tests/tests/testUseEoaSessionSigsToPkpSign.ts

Lines changed: 7 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import {
77
verifyLitSignature,
88
} from '@lit-protocol/crypto';
99
import { log } from '@lit-protocol/misc';
10-
import { SigningScheme } from '@lit-protocol/types';
10+
import { SigType } from '@lit-protocol/types';
1111

1212
import { getEoaAuthContext } from 'local-tests/setup/session-sigs/get-eoa-session-sigs';
1313
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
@@ -16,7 +16,7 @@ interface SigningSchemeConfig {
1616
hasRecoveryId?: boolean;
1717
hashesMessage: boolean;
1818
recoversPublicKey?: boolean;
19-
signingScheme: SigningScheme;
19+
signingScheme: SigType;
2020
}
2121

2222
/**
@@ -32,10 +32,6 @@ export const testUseEoaSessionSigsToPkpSign = async (
3232
const signingSchemeConfigs: SigningSchemeConfig[] = [
3333
// BLS
3434
// {
35-
// signingScheme: 'Bls12381', // TODO NodeErrror: Unsupported key type when for Signable. No esta en tss_state.rs::TssState::get_signing_state, puede que no sea posible firmar con esto?
36-
// hashesMessage: false,
37-
// },
38-
// {
3935
// signingScheme: 'Bls12381G1ProofOfPossession', // TODO pkpSignature.signature: '{ProofOfPossession:984ffb9ef7a0e6225dd074bade4b9494fab3487ff543f25a90d86f794cbf190ed20179df6eb6dd3eb9a285838d3cf4980e5e7028688e0461bd1cb95c075046fcafa343d3702e7edff70fb8eb8ada130f58fa45140ab2d90f24b1309b026d98d6}'
4036
// hashesMessage: false,
4137
// },
@@ -128,7 +124,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
128124
!pkpSignature[hexString].startsWith('0x')
129125
) {
130126
throw new Error(
131-
`Expected "${hexString}" hex string in pkpSignature. SigningScheme: ${signingScheme}`
127+
`Expected "${hexString}" hex string in pkpSignature. Signing Scheme: ${signingScheme}`
132128
);
133129
}
134130
}
@@ -139,7 +135,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
139135
: pkpSignature.recoveryId !== null
140136
) {
141137
throw new Error(
142-
`Expected "recoveryId" to be 0/1 for ECDSA and "null" for the rest of curves. SigningScheme: ${signingScheme}`
138+
`Expected "recoveryId" to be 0/1 for ECDSA and "null" for the rest of curves. Signing Scheme: ${signingScheme}`
143139
);
144140
}
145141

@@ -152,7 +148,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
152148
);
153149
if (!signatureVerification) {
154150
throw new Error(
155-
`Expected pkpSignature to consistently verify its components. SigningScheme: ${signingScheme}`
151+
`Expected pkpSignature to consistently verify its components. Signing Scheme: ${signingScheme}`
156152
);
157153
}
158154

@@ -161,7 +157,6 @@ export const testUseEoaSessionSigsToPkpSign = async (
161157
const signatureBytes = hexToBytes(
162158
pkpSignature.signature.replace(/^0x/, '')
163159
);
164-
// @ts-expect-error In progress. ECDSA works, not yet Frost
165160
const signature = curve.Signature.fromCompact(
166161
signatureBytes
167162
).addRecoveryBit(pkpSignature.recoveryId);
@@ -181,7 +176,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
181176
alice.pkp.publicKey !== recoveredPubKey
182177
) {
183178
throw new Error(
184-
`Expected recovered public key to match alice.pkp.publicKey. SigningScheme: ${signingSchemeConfig}`
179+
`Expected recovered public key to match alice.pkp.publicKey. Signing Scheme: ${signingSchemeConfig}`
185180
);
186181
}
187182
}
@@ -192,7 +187,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
192187
const messageHashHex = Buffer.from(messageHash).toString('hex');
193188
if (pkpSignature.signedData.replace('0x', '') !== messageHashHex) {
194189
throw new Error(
195-
`Expected signed data to match hashLitMessage(signingScheme, alice.loveLetter). SigningScheme: ${signingScheme}`
190+
`Expected signed data to match hashLitMessage(signingScheme, alice.loveLetter). Signing Scheme: ${signingScheme}`
196191
);
197192
}
198193

packages/constants/src/lib/constants/curves.ts

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { z } from 'zod';
22

3-
import { SigningScheme } from '@lit-protocol/types';
3+
import { BlsSigType, EcdsaSigType, FrostSigType } from '@lit-protocol/types';
44

55
import { ObjectMapFromArray } from './utils';
66

@@ -16,16 +16,15 @@ export const LIT_FROST_VARIANT_VALUES = [
1616
'SchnorrK256Taproot',
1717
'SchnorrRedDecaf377Blake2b512',
1818
'SchnorrkelSubstrate',
19-
] as const satisfies readonly SigningScheme[];
19+
] as const satisfies readonly FrostSigType[];
2020
export const LIT_FROST_VARIANT = ObjectMapFromArray(LIT_FROST_VARIANT_VALUES);
2121
export const LIT_FROST_VARIANT_SCHEMA = z.enum(LIT_FROST_VARIANT_VALUES);
2222
export type LitFrostVariantType = z.infer<typeof LIT_FROST_VARIANT_SCHEMA>;
2323

2424
// ----- BLS Variant
2525
export const LIT_BLS_VARIANT_VALUES = [
26-
'Bls12381',
2726
'Bls12381G1ProofOfPossession',
28-
] as const satisfies readonly SigningScheme[];
27+
] as const satisfies readonly BlsSigType[];
2928
export const LIT_BLS_VARIANT = ObjectMapFromArray(LIT_BLS_VARIANT_VALUES);
3029
export const LIT_BLS_VARIANT_SCHEMA = z.enum(LIT_BLS_VARIANT_VALUES);
3130
export type LitBlsVariantType = z.infer<typeof LIT_BLS_VARIANT_SCHEMA>;
@@ -35,7 +34,7 @@ export const LIT_ECDSA_VARIANT_VALUES = [
3534
'EcdsaK256Sha256',
3635
'EcdsaP256Sha256',
3736
'EcdsaP384Sha384',
38-
] as const satisfies readonly SigningScheme[];
37+
] as const satisfies readonly EcdsaSigType[];
3938
export const LIT_ECDSA_VARIANT = ObjectMapFromArray(LIT_ECDSA_VARIANT_VALUES);
4039
export const LIT_ECDSA_VARIANT_SCHEMA = z.enum(LIT_ECDSA_VARIANT_VALUES);
4140
export type LitEcdsaVariantType = z.infer<typeof LIT_ECDSA_VARIANT_SCHEMA>;
@@ -51,20 +50,13 @@ export type LIT_CURVE_TYPE = keyof typeof LIT_CURVE; // Identical to Sig
5150
// This should replicate SigShare.sigType in types package
5251
export type LIT_CURVE_VALUES = (typeof LIT_CURVE)[keyof typeof LIT_CURVE];
5352

54-
/**
55-
* CHANGE: This is not needed when the combiner is integrated
56-
*/
5753
export const CURVE_GROUPS = ['BLS', 'ECDSA', 'FROST'] as const;
5854

59-
/**
60-
* CHANGE: This is not needed when the combiner is integrated
61-
*/
6255
export const CURVE_GROUP_BY_CURVE_TYPE: Record<
6356
LIT_CURVE_VALUES,
6457
(typeof CURVE_GROUPS)[number]
6558
> = {
6659
// BLS
67-
[LIT_CURVE.Bls12381]: CURVE_GROUPS[0],
6860
[LIT_CURVE.Bls12381G1ProofOfPossession]: CURVE_GROUPS[0],
6961
// ECDSA
7062
[LIT_CURVE.EcdsaK256Sha256]: CURVE_GROUPS[1],

packages/contracts-sdk/src/lib/contracts-sdk.ts

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,16 @@ export class LitContracts {
639639
);
640640
break;
641641
default:
642-
throw new Error('Wrong contract name'); // TODO improve this error
642+
throw new InvalidArgumentException(
643+
{
644+
info: {
645+
contract,
646+
environment,
647+
contractNames,
648+
},
649+
},
650+
'Contract not found'
651+
);
643652
}
644653

645654
return address;

packages/crypto/src/lib/crypto.ts

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ import { shake256 } from '@noble/hashes/sha3';
1111
import { sha384, sha512 } from '@noble/hashes/sha512';
1212

1313
import {
14+
CurveTypeNotFoundError,
1415
InvalidParamType,
1516
LIT_CURVE,
1617
LitEcdsaVariantType,
1718
NetworkError,
1819
NoValidShares,
1920
UnknownError,
20-
UnknownSignatureType,
2121
} from '@lit-protocol/constants';
2222
import {
2323
applyTransformations,
@@ -36,7 +36,7 @@ import {
3636
NodeAttestation,
3737
PKPSignEndpointResponse,
3838
SessionKeyPair,
39-
SigningScheme,
39+
SigType,
4040
} from '@lit-protocol/types';
4141
import {
4242
uint8arrayFromString,
@@ -534,8 +534,7 @@ export const checkSevSnpAttestation = async (
534534
};
535535

536536
// Map the right hash function per signing scheme
537-
export const hashFunctions = {
538-
Bls12381: sha256, // TODO needed here? Which hash?
537+
export const hashFunctions: Record<SigType, any> = {
539538
Bls12381G1ProofOfPossession: sha256, // TODO needed here? Which hash?
540539
EcdsaK256Sha256: sha256,
541540
EcdsaP256Sha256: sha256,
@@ -554,8 +553,7 @@ export const hashFunctions = {
554553
} as const;
555554

556555
// Map the right curve function per signing scheme
557-
export const curveFunctions = {
558-
Bls12381: bls12_381,
556+
export const curveFunctions: Record<SigType, any> = {
559557
Bls12381G1ProofOfPossession: bls12_381,
560558
EcdsaK256Sha256: secp256k1,
561559
EcdsaP256Sha256: p256,
@@ -574,13 +572,13 @@ export const curveFunctions = {
574572
} as const;
575573

576574
export function hashLitMessage(
577-
signingScheme: SigningScheme,
575+
signingScheme: SigType,
578576
message: Uint8Array
579577
): Uint8Array {
580578
const hashFn = hashFunctions[signingScheme];
581579

582580
if (!hashFn) {
583-
throw new UnknownSignatureType(
581+
throw new CurveTypeNotFoundError(
584582
{
585583
info: {
586584
signingScheme,
@@ -594,14 +592,14 @@ export function hashLitMessage(
594592
}
595593

596594
export function verifyLitSignature(
597-
signingScheme: SigningScheme,
595+
signingScheme: SigType,
598596
publicKey: string,
599597
message: string,
600598
signature: string
601599
) {
602600
const curve = curveFunctions[signingScheme];
603601
if (!curve) {
604-
throw new UnknownSignatureType(
602+
throw new CurveTypeNotFoundError(
605603
{
606604
info: {
607605
signingScheme,
@@ -611,6 +609,6 @@ export function verifyLitSignature(
611609
);
612610
}
613611

614-
// @ts-expect-error TODO call correct verification on all curve functions
612+
// TODO call correct verification on all curve functions
615613
return curve.verify(signature, message, publicKey);
616614
}

packages/lit-node-client-nodejs/src/lib/helpers/get-claims-list.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,11 @@ import { ClaimsList, ExecuteJsValueResponse } from '@lit-protocol/types';
66
* @param responseData The response data containing the claims.
77
* @returns An array of claims.
88
*/
9-
export const getClaimsList = (responseData: ExecuteJsValueResponse[]): ClaimsList => {
9+
export const getClaimsList = (
10+
responseData: ExecuteJsValueResponse[]
11+
): ClaimsList => {
1012
const claimsList = responseData
11-
.map(rd => applyTransformations(rd.claimData, [cleanStringValues]))
13+
.map((rd) => applyTransformations(rd.claimData, [cleanStringValues]))
1214
.filter((item) => item !== null);
1315

1416
return claimsList as unknown as ClaimsList;

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1368,7 +1368,6 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
13681368
...(params?.litActionCode && { code: params.litActionCode }),
13691369
...(params?.jsParams && { jsParams: params.jsParams }),
13701370
...(this.currentEpochNumber && { epoch: this.currentEpochNumber }),
1371-
// signingScheme: LIT_CURVE.BLS,
13721371
};
13731372

13741373
log(`[signSessionKey] body:`, body);

packages/types/src/lib/EndpointResponses.ts

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,37 @@
11
import { Hex } from './types';
22

3-
// TODO these types are defined in @lit-protocol/constants -> curves.ts. Unify them.
4-
export type BlsSigType = 'BLS';
3+
export type BlsSigType = 'Bls12381G1ProofOfPossession';
54

65
export type EcdsaSigType =
7-
| 'K256'
8-
| 'ECDSA_CAIT_SITH'
9-
| 'EcdsaCaitSithP256'
106
| 'EcdsaK256Sha256'
117
| 'EcdsaP256Sha256'
128
| 'EcdsaP384Sha384';
139

1410
export type FrostSigType =
15-
| 'Ed25519Sha512'
16-
| 'Ed448Shake256'
17-
| 'Ristretto25519Sha512'
18-
| 'K256Sha256'
19-
| 'P256Sha256'
20-
| 'P384Sha384'
21-
| 'RedJubjubBlake2b512'
22-
| 'K256Taproot';
11+
| 'SchnorrEd25519Sha512'
12+
| 'SchnorrK256Sha256'
13+
| 'SchnorrP256Sha256'
14+
| 'SchnorrP384Sha384'
15+
| 'SchnorrRistretto25519Sha512'
16+
| 'SchnorrEd448Shake256'
17+
| 'SchnorrRedJubjubBlake2b512'
18+
| 'SchnorrK256Taproot'
19+
| 'SchnorrRedDecaf377Blake2b512'
20+
| 'SchnorrkelSubstrate';
2321

2422
export type SigType = BlsSigType | EcdsaSigType | FrostSigType;
2523

2624
// See src/p2p_comms/web/models.rs > BlsSignedMessageShare
2725
// Example output:
2826
// "BlsSignedMessageShare": {
29-
// TODO
27+
// "message": "0102030405",
28+
// "result": "success",
29+
// "peer_id": "5d6549a90c835b672953dec25b20f278de72b5a47019c74a2e4e8207e01b684a",
30+
// "share_id": "\"19a7c43a2b7bbedcea0a40ab17fe0f4a1acf31bdecb9ebeb96c1d3a62e4885f0\"",
31+
// "signature_share": "{\"ProofOfPossession\":{\"identifier\":\"f085482ea6d3c196ebebb9ecbd31cf1a4a0ffe17ab400aeadcbe7b2b3ac4a719\",\"value\":\"8a56ee7b1f7c1eb93e1ccfa2ec02c0f344dcbb66d3cb0742ceaad2aa655da431575b70635db1aa6208061ebdc64442e108c6ae49eb996d72f590ac99d4edda180cb4ef4610bf58b00f75910fda6670bd58eb9b4397f38c8ea5886d9914cb2d24\"}}",
32+
// "verifying_share": "{\"identifier\":\"f085482ea6d3c196ebebb9ecbd31cf1a4a0ffe17ab400aeadcbe7b2b3ac4a719\",\"value\":\"911725a46083ac660d283be18965f2fc3c3f817272b8499c4b46477e868a2d515d670f4fb89cb837bc1cd0dc7c00655b\"}",
33+
// "public_key": "\"8fb7104e7fcfae43b77646d6ade34b116c7a69aa53cba75167e267fff36150727dd1064ca477b6cd763f8382c737a35d\"",
34+
// "sig_type": "Bls12381G1ProofOfPossession"
3035
// }
3136
// Notice how some values are double quoted, and some are not. We need to clean this up.
3237
export interface BlsSignedMessageShareRaw {
@@ -140,7 +145,14 @@ export interface ExecuteJsValueResponse {
140145
*
141146
* @example
142147
* {
143-
* TODO
148+
* "message": "0x0102030405",
149+
* "peerId": "0x5d6549a90c835b672953dec25b20f278de72b5a47019c74a2e4e8207e01b684a",
150+
* "shareId": "0x19a7c43a2b7bbedcea0a40ab17fe0f4a1acf31bdecb9ebeb96c1d3a62e4885f0",
151+
* "signatureShare": "{ProofOfPossession:{identifier:f085482ea6d3c196ebebb9ecbd31cf1a4a0ffe17ab400aeadcbe7b2b3ac4a719,value:8a56ee7b1f7c1eb93e1ccfa2ec02c0f344dcbb66d3cb0742ceaad2aa655da431575b70635db1aa6208061ebdc64442e108c6ae49eb996d72f590ac99d4edda180cb4ef4610bf58b00f75910fda6670bd58eb9b4397f38c8ea5886d9914cb2d24}}",
152+
* "verifyingShare": "{identifier:f085482ea6d3c196ebebb9ecbd31cf1a4a0ffe17ab400aeadcbe7b2b3ac4a719,value:911725a46083ac660d283be18965f2fc3c3f817272b8499c4b46477e868a2d515d670f4fb89cb837bc1cd0dc7c00655b}",
153+
* "publicKey": "0x8fb7104e7fcfae43b77646d6ade34b116c7a69aa53cba75167e267fff36150727dd1064ca477b6cd763f8382c737a35d",
154+
* "sigType": "Bls12381G1ProofOfPossession",
155+
* "dataSigned": "0x0102030405"
144156
* }
145157
*/
146158
export interface BlsSignedMessageShareParsed {

packages/types/src/lib/interfaces.ts

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -161,30 +161,13 @@ export interface ClaimKeyResponse {
161161
mintTx: string;
162162
}
163163

164-
export type SigningScheme =
165-
| 'Bls12381'
166-
| 'Bls12381G1ProofOfPossession'
167-
| 'EcdsaK256Sha256'
168-
| 'EcdsaP256Sha256'
169-
| 'EcdsaP384Sha384'
170-
| 'SchnorrEd25519Sha512'
171-
| 'SchnorrK256Sha256'
172-
| 'SchnorrP256Sha256'
173-
| 'SchnorrP384Sha384'
174-
| 'SchnorrRistretto25519Sha512'
175-
| 'SchnorrEd448Shake256'
176-
| 'SchnorrRedJubjubBlake2b512'
177-
| 'SchnorrK256Taproot'
178-
| 'SchnorrRedDecaf377Blake2b512'
179-
| 'SchnorrkelSubstrate';
180-
181164
export interface Node {
182165
socketAddress: string;
183166
value: number;
184167
}
185168

186169
export interface BaseJsonPkpSignRequest {
187-
signingScheme: SigningScheme;
170+
signingScheme: SigType;
188171
}
189172

190173
/**
@@ -561,7 +544,7 @@ export interface SigResponse {
561544
r: string;
562545
s: string;
563546
recid: number;
564-
signature: `0x${string}`;
547+
signature: Hex;
565548
publicKey: string; // pkp public key (no 0x prefix)
566549
dataSigned: string;
567550
}

0 commit comments

Comments
 (0)