Skip to content

[rc-naga-2025-01-30] Compatibility #786

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 22 commits into
base: feat/naga-fix-bls-wasm-cleanup
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
756eb2c
add combiner for all
mikelodder7 Jan 27, 2025
eb24a01
fix generic-array version
mikelodder7 Jan 27, 2025
4ab5e93
remove unneeded code
mikelodder7 Jan 28, 2025
d3a198b
add tests for combine_and_verify that also print the results
mikelodder7 Jan 30, 2025
80b49b2
Merge pull request #779 from LIT-Protocol/ml/combine_all_signatures
Ansonhkg Jan 31, 2025
5d4ab05
feat: use rust unified combiner to support frost and multiple ecdsa s…
FedericoAmura Feb 11, 2025
63ac695
Merge branch 'refs/heads/feat/naga-fix-bls-wasm-cleanup' into feat/rc…
FedericoAmura Feb 12, 2025
e0b7b66
Merge branch 'refs/heads/feat/rc-naga-2025-01-30b' into feature/lit-4…
FedericoAmura Feb 12, 2025
fcc5757
feat: building fixes and cleanup
FedericoAmura Feb 12, 2025
6e736ff
feat: restore claims inside lit actions signature aggregation
FedericoAmura Feb 12, 2025
42a380f
feat: types unification
FedericoAmura Feb 12, 2025
d617a04
feat: removed unused types and executeJs return fixes
FedericoAmura Feb 12, 2025
f6213a4
feat: update PKPWallets with new signing schemes
FedericoAmura Feb 13, 2025
3112779
feat: linting fixes
FedericoAmura Feb 13, 2025
fe4c47b
feat: a missing linting fix that should complete ci check
FedericoAmura Feb 13, 2025
b04daad
fix: failing unit tests
FedericoAmura Feb 13, 2025
0f7a88e
fix: circular reference with PRODUCT_IDS
FedericoAmura Feb 14, 2025
341ea36
feat: clean ecdsa wasm
FedericoAmura Feb 14, 2025
b2734b7
feat: update pkpSign test to use verify all signing schemes and remov…
FedericoAmura Feb 14, 2025
976e3d7
feat: comment bls usage on pkpSign as it will not be supported yet
FedericoAmura Feb 14, 2025
685f759
feat: remove types import in constants
FedericoAmura Feb 17, 2025
df88cf5
Merge pull request #799 from LIT-Protocol/feature/lit-4007-js-sdk-add…
FedericoAmura Mar 11, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
feat: types unification
  • Loading branch information
FedericoAmura committed Feb 12, 2025
commit 42a380f44e90e4813adcd44b5a04e30834b2c5e9
19 changes: 7 additions & 12 deletions local-tests/tests/testUseEoaSessionSigsToPkpSign.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
verifyLitSignature,
} from '@lit-protocol/crypto';
import { log } from '@lit-protocol/misc';
import { SigningScheme } from '@lit-protocol/types';
import { SigType } from '@lit-protocol/types';

import { getEoaAuthContext } from 'local-tests/setup/session-sigs/get-eoa-session-sigs';
import { TinnyEnvironment } from 'local-tests/setup/tinny-environment';
Expand All @@ -16,7 +16,7 @@ interface SigningSchemeConfig {
hasRecoveryId?: boolean;
hashesMessage: boolean;
recoversPublicKey?: boolean;
signingScheme: SigningScheme;
signingScheme: SigType;
}

/**
Expand All @@ -32,10 +32,6 @@ export const testUseEoaSessionSigsToPkpSign = async (
const signingSchemeConfigs: SigningSchemeConfig[] = [
// BLS
// {
// 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?
// hashesMessage: false,
// },
// {
// signingScheme: 'Bls12381G1ProofOfPossession', // TODO pkpSignature.signature: '{ProofOfPossession:984ffb9ef7a0e6225dd074bade4b9494fab3487ff543f25a90d86f794cbf190ed20179df6eb6dd3eb9a285838d3cf4980e5e7028688e0461bd1cb95c075046fcafa343d3702e7edff70fb8eb8ada130f58fa45140ab2d90f24b1309b026d98d6}'
// hashesMessage: false,
// },
Expand Down Expand Up @@ -128,7 +124,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
!pkpSignature[hexString].startsWith('0x')
) {
throw new Error(
`Expected "${hexString}" hex string in pkpSignature. SigningScheme: ${signingScheme}`
`Expected "${hexString}" hex string in pkpSignature. Signing Scheme: ${signingScheme}`
);
}
}
Expand All @@ -139,7 +135,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
: pkpSignature.recoveryId !== null
) {
throw new Error(
`Expected "recoveryId" to be 0/1 for ECDSA and "null" for the rest of curves. SigningScheme: ${signingScheme}`
`Expected "recoveryId" to be 0/1 for ECDSA and "null" for the rest of curves. Signing Scheme: ${signingScheme}`
);
}

Expand All @@ -152,7 +148,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
);
if (!signatureVerification) {
throw new Error(
`Expected pkpSignature to consistently verify its components. SigningScheme: ${signingScheme}`
`Expected pkpSignature to consistently verify its components. Signing Scheme: ${signingScheme}`
);
}

Expand All @@ -161,7 +157,6 @@ export const testUseEoaSessionSigsToPkpSign = async (
const signatureBytes = hexToBytes(
pkpSignature.signature.replace(/^0x/, '')
);
// @ts-expect-error In progress. ECDSA works, not yet Frost
const signature = curve.Signature.fromCompact(
signatureBytes
).addRecoveryBit(pkpSignature.recoveryId);
Expand All @@ -181,7 +176,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
alice.pkp.publicKey !== recoveredPubKey
) {
throw new Error(
`Expected recovered public key to match alice.pkp.publicKey. SigningScheme: ${signingSchemeConfig}`
`Expected recovered public key to match alice.pkp.publicKey. Signing Scheme: ${signingSchemeConfig}`
);
}
}
Expand All @@ -192,7 +187,7 @@ export const testUseEoaSessionSigsToPkpSign = async (
const messageHashHex = Buffer.from(messageHash).toString('hex');
if (pkpSignature.signedData.replace('0x', '') !== messageHashHex) {
throw new Error(
`Expected signed data to match hashLitMessage(signingScheme, alice.loveLetter). SigningScheme: ${signingScheme}`
`Expected signed data to match hashLitMessage(signingScheme, alice.loveLetter). Signing Scheme: ${signingScheme}`
);
}

Expand Down
16 changes: 4 additions & 12 deletions packages/constants/src/lib/constants/curves.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { z } from 'zod';

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

import { ObjectMapFromArray } from './utils';

Expand All @@ -16,16 +16,15 @@ export const LIT_FROST_VARIANT_VALUES = [
'SchnorrK256Taproot',
'SchnorrRedDecaf377Blake2b512',
'SchnorrkelSubstrate',
] as const satisfies readonly SigningScheme[];
] as const satisfies readonly FrostSigType[];
export const LIT_FROST_VARIANT = ObjectMapFromArray(LIT_FROST_VARIANT_VALUES);
export const LIT_FROST_VARIANT_SCHEMA = z.enum(LIT_FROST_VARIANT_VALUES);
export type LitFrostVariantType = z.infer<typeof LIT_FROST_VARIANT_SCHEMA>;

// ----- BLS Variant
export const LIT_BLS_VARIANT_VALUES = [
'Bls12381',
'Bls12381G1ProofOfPossession',
] as const satisfies readonly SigningScheme[];
] as const satisfies readonly BlsSigType[];
export const LIT_BLS_VARIANT = ObjectMapFromArray(LIT_BLS_VARIANT_VALUES);
export const LIT_BLS_VARIANT_SCHEMA = z.enum(LIT_BLS_VARIANT_VALUES);
export type LitBlsVariantType = z.infer<typeof LIT_BLS_VARIANT_SCHEMA>;
Expand All @@ -35,7 +34,7 @@ export const LIT_ECDSA_VARIANT_VALUES = [
'EcdsaK256Sha256',
'EcdsaP256Sha256',
'EcdsaP384Sha384',
] as const satisfies readonly SigningScheme[];
] as const satisfies readonly EcdsaSigType[];
export const LIT_ECDSA_VARIANT = ObjectMapFromArray(LIT_ECDSA_VARIANT_VALUES);
export const LIT_ECDSA_VARIANT_SCHEMA = z.enum(LIT_ECDSA_VARIANT_VALUES);
export type LitEcdsaVariantType = z.infer<typeof LIT_ECDSA_VARIANT_SCHEMA>;
Expand All @@ -51,20 +50,13 @@ export type LIT_CURVE_TYPE = keyof typeof LIT_CURVE; // Identical to Sig
// This should replicate SigShare.sigType in types package
export type LIT_CURVE_VALUES = (typeof LIT_CURVE)[keyof typeof LIT_CURVE];

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

/**
* CHANGE: This is not needed when the combiner is integrated
*/
export const CURVE_GROUP_BY_CURVE_TYPE: Record<
LIT_CURVE_VALUES,
(typeof CURVE_GROUPS)[number]
> = {
// BLS
[LIT_CURVE.Bls12381]: CURVE_GROUPS[0],
[LIT_CURVE.Bls12381G1ProofOfPossession]: CURVE_GROUPS[0],
// ECDSA
[LIT_CURVE.EcdsaK256Sha256]: CURVE_GROUPS[1],
Expand Down
11 changes: 10 additions & 1 deletion packages/contracts-sdk/src/lib/contracts-sdk.ts
Original file line number Diff line number Diff line change
Expand Up @@ -639,7 +639,16 @@ export class LitContracts {
);
break;
default:
throw new Error('Wrong contract name'); // TODO improve this error
throw new InvalidArgumentException(
{
info: {
contract,
environment,
contractNames,
},
},
'Contract not found'
);
}

return address;
Expand Down
20 changes: 9 additions & 11 deletions packages/crypto/src/lib/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,13 @@ import { shake256 } from '@noble/hashes/sha3';
import { sha384, sha512 } from '@noble/hashes/sha512';

import {
CurveTypeNotFoundError,
InvalidParamType,
LIT_CURVE,
LitEcdsaVariantType,
NetworkError,
NoValidShares,
UnknownError,
UnknownSignatureType,
} from '@lit-protocol/constants';
import {
applyTransformations,
Expand All @@ -36,7 +36,7 @@ import {
NodeAttestation,
PKPSignEndpointResponse,
SessionKeyPair,
SigningScheme,
SigType,
} from '@lit-protocol/types';
import {
uint8arrayFromString,
Expand Down Expand Up @@ -534,8 +534,7 @@ export const checkSevSnpAttestation = async (
};

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

// Map the right curve function per signing scheme
export const curveFunctions = {
Bls12381: bls12_381,
export const curveFunctions: Record<SigType, any> = {
Bls12381G1ProofOfPossession: bls12_381,
EcdsaK256Sha256: secp256k1,
EcdsaP256Sha256: p256,
Expand All @@ -574,13 +572,13 @@ export const curveFunctions = {
} as const;

export function hashLitMessage(
signingScheme: SigningScheme,
signingScheme: SigType,
message: Uint8Array
): Uint8Array {
const hashFn = hashFunctions[signingScheme];

if (!hashFn) {
throw new UnknownSignatureType(
throw new CurveTypeNotFoundError(
{
info: {
signingScheme,
Expand All @@ -594,14 +592,14 @@ export function hashLitMessage(
}

export function verifyLitSignature(
signingScheme: SigningScheme,
signingScheme: SigType,
publicKey: string,
message: string,
signature: string
) {
const curve = curveFunctions[signingScheme];
if (!curve) {
throw new UnknownSignatureType(
throw new CurveTypeNotFoundError(
{
info: {
signingScheme,
Expand All @@ -611,6 +609,6 @@ export function verifyLitSignature(
);
}

// @ts-expect-error TODO call correct verification on all curve functions
// TODO call correct verification on all curve functions
return curve.verify(signature, message, publicKey);
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import { ClaimsList, ExecuteJsValueResponse } from '@lit-protocol/types';
* @param responseData The response data containing the claims.
* @returns An array of claims.
*/
export const getClaimsList = (responseData: ExecuteJsValueResponse[]): ClaimsList => {
export const getClaimsList = (
responseData: ExecuteJsValueResponse[]
): ClaimsList => {
const claimsList = responseData
.map(rd => applyTransformations(rd.claimData, [cleanStringValues]))
.map((rd) => applyTransformations(rd.claimData, [cleanStringValues]))
.filter((item) => item !== null);

return claimsList as unknown as ClaimsList;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1368,7 +1368,6 @@ export class LitNodeClientNodeJs extends LitCore implements ILitNodeClient {
...(params?.litActionCode && { code: params.litActionCode }),
...(params?.jsParams && { jsParams: params.jsParams }),
...(this.currentEpochNumber && { epoch: this.currentEpochNumber }),
// signingScheme: LIT_CURVE.BLS,
};

log(`[signSessionKey] body:`, body);
Expand Down
42 changes: 27 additions & 15 deletions packages/types/src/lib/EndpointResponses.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,37 @@
import { Hex } from './types';

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

export type EcdsaSigType =
| 'K256'
| 'ECDSA_CAIT_SITH'
| 'EcdsaCaitSithP256'
| 'EcdsaK256Sha256'
| 'EcdsaP256Sha256'
| 'EcdsaP384Sha384';

export type FrostSigType =
| 'Ed25519Sha512'
| 'Ed448Shake256'
| 'Ristretto25519Sha512'
| 'K256Sha256'
| 'P256Sha256'
| 'P384Sha384'
| 'RedJubjubBlake2b512'
| 'K256Taproot';
| 'SchnorrEd25519Sha512'
| 'SchnorrK256Sha256'
| 'SchnorrP256Sha256'
| 'SchnorrP384Sha384'
| 'SchnorrRistretto25519Sha512'
| 'SchnorrEd448Shake256'
| 'SchnorrRedJubjubBlake2b512'
| 'SchnorrK256Taproot'
| 'SchnorrRedDecaf377Blake2b512'
| 'SchnorrkelSubstrate';

export type SigType = BlsSigType | EcdsaSigType | FrostSigType;

// See src/p2p_comms/web/models.rs > BlsSignedMessageShare
// Example output:
// "BlsSignedMessageShare": {
// TODO
// "message": "0102030405",
// "result": "success",
// "peer_id": "5d6549a90c835b672953dec25b20f278de72b5a47019c74a2e4e8207e01b684a",
// "share_id": "\"19a7c43a2b7bbedcea0a40ab17fe0f4a1acf31bdecb9ebeb96c1d3a62e4885f0\"",
// "signature_share": "{\"ProofOfPossession\":{\"identifier\":\"f085482ea6d3c196ebebb9ecbd31cf1a4a0ffe17ab400aeadcbe7b2b3ac4a719\",\"value\":\"8a56ee7b1f7c1eb93e1ccfa2ec02c0f344dcbb66d3cb0742ceaad2aa655da431575b70635db1aa6208061ebdc64442e108c6ae49eb996d72f590ac99d4edda180cb4ef4610bf58b00f75910fda6670bd58eb9b4397f38c8ea5886d9914cb2d24\"}}",
// "verifying_share": "{\"identifier\":\"f085482ea6d3c196ebebb9ecbd31cf1a4a0ffe17ab400aeadcbe7b2b3ac4a719\",\"value\":\"911725a46083ac660d283be18965f2fc3c3f817272b8499c4b46477e868a2d515d670f4fb89cb837bc1cd0dc7c00655b\"}",
// "public_key": "\"8fb7104e7fcfae43b77646d6ade34b116c7a69aa53cba75167e267fff36150727dd1064ca477b6cd763f8382c737a35d\"",
// "sig_type": "Bls12381G1ProofOfPossession"
// }
// Notice how some values are double quoted, and some are not. We need to clean this up.
export interface BlsSignedMessageShareRaw {
Expand Down Expand Up @@ -140,7 +145,14 @@ export interface ExecuteJsValueResponse {
*
* @example
* {
* TODO
* "message": "0x0102030405",
* "peerId": "0x5d6549a90c835b672953dec25b20f278de72b5a47019c74a2e4e8207e01b684a",
* "shareId": "0x19a7c43a2b7bbedcea0a40ab17fe0f4a1acf31bdecb9ebeb96c1d3a62e4885f0",
* "signatureShare": "{ProofOfPossession:{identifier:f085482ea6d3c196ebebb9ecbd31cf1a4a0ffe17ab400aeadcbe7b2b3ac4a719,value:8a56ee7b1f7c1eb93e1ccfa2ec02c0f344dcbb66d3cb0742ceaad2aa655da431575b70635db1aa6208061ebdc64442e108c6ae49eb996d72f590ac99d4edda180cb4ef4610bf58b00f75910fda6670bd58eb9b4397f38c8ea5886d9914cb2d24}}",
* "verifyingShare": "{identifier:f085482ea6d3c196ebebb9ecbd31cf1a4a0ffe17ab400aeadcbe7b2b3ac4a719,value:911725a46083ac660d283be18965f2fc3c3f817272b8499c4b46477e868a2d515d670f4fb89cb837bc1cd0dc7c00655b}",
* "publicKey": "0x8fb7104e7fcfae43b77646d6ade34b116c7a69aa53cba75167e267fff36150727dd1064ca477b6cd763f8382c737a35d",
* "sigType": "Bls12381G1ProofOfPossession",
* "dataSigned": "0x0102030405"
* }
*/
export interface BlsSignedMessageShareParsed {
Expand Down
21 changes: 2 additions & 19 deletions packages/types/src/lib/interfaces.ts
Original file line number Diff line number Diff line change
Expand Up @@ -161,30 +161,13 @@ export interface ClaimKeyResponse {
mintTx: string;
}

export type SigningScheme =
| 'Bls12381'
| 'Bls12381G1ProofOfPossession'
| 'EcdsaK256Sha256'
| 'EcdsaP256Sha256'
| 'EcdsaP384Sha384'
| 'SchnorrEd25519Sha512'
| 'SchnorrK256Sha256'
| 'SchnorrP256Sha256'
| 'SchnorrP384Sha384'
| 'SchnorrRistretto25519Sha512'
| 'SchnorrEd448Shake256'
| 'SchnorrRedJubjubBlake2b512'
| 'SchnorrK256Taproot'
| 'SchnorrRedDecaf377Blake2b512'
| 'SchnorrkelSubstrate';

export interface Node {
socketAddress: string;
value: number;
}

export interface BaseJsonPkpSignRequest {
signingScheme: SigningScheme;
signingScheme: SigType;
}

/**
Expand Down Expand Up @@ -561,7 +544,7 @@ export interface SigResponse {
r: string;
s: string;
recid: number;
signature: `0x${string}`;
signature: Hex;
publicKey: string; // pkp public key (no 0x prefix)
dataSigned: string;
}
Expand Down
Loading