Skip to content

Commit 341ea36

Browse files
committed
feat: clean ecdsa wasm
1 parent 0f7a88e commit 341ea36

File tree

6 files changed

+12
-294
lines changed

6 files changed

+12
-294
lines changed

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

Lines changed: 4 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import {
2323
STAKING_STATES_VALUES,
2424
UnknownError,
2525
version,
26-
LitEcdsaVariantType,
2726
} from '@lit-protocol/constants';
2827
import { LitContracts } from '@lit-protocol/contracts-sdk';
2928
import { checkSevSnpAttestation, computeHDPubKey } from '@lit-protocol/crypto';
@@ -1230,28 +1229,20 @@ export class LitCore {
12301229
};
12311230

12321231
/**
1233-
* Calculates an HD public key from a given keyId
1234-
* The curve type or signature type is assumed to be k256 unless provided
1232+
* Calculates an K256 HD public key from a given keyId
1233+
*
12351234
* @param keyId
1236-
* @param {LitEcdsaVariantType} sigType
12371235
* @returns {string} public key
12381236
*/
1239-
computeHDPubKey = async (
1240-
keyId: string,
1241-
sigType: LitEcdsaVariantType = LIT_CURVE.EcdsaK256Sha256
1242-
): Promise<string> => {
1237+
computeHDPubKey = async (keyId: string): Promise<string> => {
12431238
if (!this.hdRootPubkeys) {
12441239
logError('root public keys not found, have you connected to the nodes?');
12451240
throw new LitNodeClientNotReadyError(
12461241
{},
12471242
'root public keys not found, have you connected to the nodes?'
12481243
);
12491244
}
1250-
return await computeHDPubKey(
1251-
this.hdRootPubkeys as string[],
1252-
keyId,
1253-
sigType
1254-
);
1245+
return await computeHDPubKey(this.hdRootPubkeys as string[], keyId);
12551246
};
12561247

12571248
/**

packages/crypto/src/lib/crypto.ts

Lines changed: 1 addition & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import { sha384, sha512 } from '@noble/hashes/sha512';
1313
import {
1414
CurveTypeNotFoundError,
1515
InvalidParamType,
16-
LIT_CURVE,
17-
LitEcdsaVariantType,
1816
NetworkError,
1917
NoValidShares,
2018
UnknownError,
@@ -49,7 +47,6 @@ import {
4947
BlsSignatureShareJsonString,
5048
blsVerify,
5149
ecdsaDeriveKey,
52-
EcdsaVariant,
5350
sevSnpGetVcekUrl,
5451
sevSnpVerify,
5552
unifiedCombineAndVerify,
@@ -107,21 +104,6 @@ export const encrypt = async (
107104
);
108105
};
109106

110-
/**
111-
* Decrypt ciphertext using BLS signature shares.
112-
*
113-
* @param ciphertextBase64 base64-encoded string of the ciphertext to decrypt
114-
* @param shares hex-encoded array of the BLS signature shares
115-
* @returns Uint8Array of the decrypted data
116-
*/
117-
export const decryptWithSignatureShares = async (
118-
ciphertextBase64: string,
119-
shares: BlsSignatureShare[]
120-
): Promise<Uint8Array> => {
121-
const sigShares = toJSONShares(shares);
122-
return doDecrypt(ciphertextBase64, sigShares);
123-
};
124-
125107
/**
126108
* Verify and decrypt ciphertext using BLS signature shares.
127109
*
@@ -194,12 +176,6 @@ export const verifySignature = async (
194176
await blsVerify(publicKey, message, signature);
195177
};
196178

197-
const ecdsaSigntureTypeMap: Record<LitEcdsaVariantType, EcdsaVariant> = {
198-
[LIT_CURVE.EcdsaK256Sha256]: 'K256',
199-
[LIT_CURVE.EcdsaP256Sha256]: 'P256',
200-
[LIT_CURVE.EcdsaP384Sha384]: 'P384',
201-
};
202-
203179
const parseCombinedSignature = (
204180
combinedSignature: CombinedLitNodeSignature
205181
): CleanLitNodeSignature => {
@@ -290,35 +266,14 @@ export const combinePKPSignNodeShares = async (
290266

291267
export const computeHDPubKey = async (
292268
pubkeys: string[],
293-
keyId: string,
294-
sigType: LitEcdsaVariantType
269+
keyId: string
295270
): Promise<string> => {
296-
const variant = ecdsaSigntureTypeMap[sigType];
297-
298-
if (
299-
![
300-
LIT_CURVE.EcdsaK256Sha256,
301-
LIT_CURVE.EcdsaP256Sha256,
302-
LIT_CURVE.EcdsaP384Sha384,
303-
].includes(sigType)
304-
) {
305-
throw new InvalidParamType(
306-
{
307-
info: {
308-
sigType,
309-
},
310-
},
311-
`Non supported signature type`
312-
);
313-
}
314-
315271
// a bit of preprocessing to remove characters which will cause our wasm module to reject the values.
316272
pubkeys = pubkeys.map((value: string) => {
317273
return value.replace('0x', '');
318274
});
319275
keyId = keyId.replace('0x', '');
320276
const preComputedPubkey = await ecdsaDeriveKey(
321-
variant,
322277
Buffer.from(keyId, 'hex'),
323278
pubkeys.map((hex: string) => Buffer.from(hex, 'hex'))
324279
);

packages/wasm/rust/Cargo.toml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,11 @@ base64_light = "0.1.5"
2222
ecdsa = "0.16.9"
2323
generic-array = "1.1.1"
2424
lit-frost = { git = "https://github.com/LIT-Protocol/lit-frost.git" }
25-
getrandom = { version = "0.2", features = ["js"] }
2625
hex = "0.4"
2726
hd-keys-curves-wasm = { version = "1.0.1", default-features = false, features = ["k256", "p256"] }
2827
lit-bls-wasm = { git = "https://github.com/LIT-Protocol/lit-bls-wasm" }
2928
serde = "1.0"
3029
serde_json = "1.0"
31-
serde_bare = "0.5"
3230
serde-wasm-bindgen = "0.6"
3331

3432
elliptic-curve = "0.13"
@@ -39,10 +37,6 @@ p384 = { version = "0.13", features = ["arithmetic", "serde"] }
3937
sha2 = "0.10"
4038
vsss-rs = { version = "5.1.0", optional = true }
4139

42-
wee_alloc = { version = "0.4.5", optional = true }
43-
44-
console_error_panic_hook = { version = "0.1.7", optional = true }
45-
wasm-bindgen-futures = "0.4.40"
4640
js-sys = "0.3.67"
4741

4842
sev = { version = "2.0.2", default-features = false, features = [
@@ -53,15 +47,10 @@ rand = "0.8"
5347
serde_bytes = "0.11.14"
5448
tsify = { version = "0.4.5", default-features = false, features = ["js"] }
5549

56-
web-sys = { version = "0.3", features = ["console"] }
5750

5851
[dev-dependencies]
59-
wasm-bindgen-test = "0.3.34"
60-
ciborium = "0.2"
6152
k256 = "0.13"
6253
rand = "0.8"
63-
rand_chacha = "0.3"
64-
digest = "0.10"
6554

6655
[profile.release]
6756
opt-level = "z"

packages/wasm/rust/src/ecdsa.rs

Lines changed: 1 addition & 108 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,12 @@ use elliptic_curve::{
1111
use hd_keys_curves_wasm::{HDDerivable, HDDeriver};
1212
use js_sys::Uint8Array;
1313
use k256::Secp256k1;
14-
use p256::NistP256;
15-
use p384::NistP384;
16-
use serde::Deserialize;
1714
use serde_bytes::Bytes;
1815
use tsify::Tsify;
1916
use wasm_bindgen::{prelude::*, JsError};
2017

2118
use crate::abi::{from_js, into_js, into_uint8array, JsResult};
2219

23-
#[derive(Tsify, Deserialize)]
24-
#[tsify(from_wasm_abi)]
25-
pub enum EcdsaVariant {
26-
K256,
27-
P256,
28-
P384,
29-
}
30-
3120
struct Ecdsa<C>(C);
3221

3322
trait HdCtx {
@@ -38,14 +27,6 @@ impl HdCtx for Secp256k1 {
3827
const CTX: &'static [u8] = b"LIT_HD_KEY_ID_K256_XMD:SHA-256_SSWU_RO_NUL_";
3928
}
4029

41-
impl HdCtx for NistP256 {
42-
const CTX: &'static [u8] = b"LIT_HD_KEY_ID_P256_XMD:SHA-256_SSWU_RO_NUL_";
43-
}
44-
45-
impl HdCtx for NistP384 {
46-
const CTX: &'static [u8] = b"LIT_HD_KEY_ID_P384_XMD:SHA-384_SSWU_RO_NUL_";
47-
}
48-
4930
#[wasm_bindgen]
5031
extern "C" {
5132
#[wasm_bindgen(typescript_type = "[Uint8Array, Uint8Array, number]")]
@@ -260,98 +241,10 @@ where
260241
}
261242
}
262243

263-
/// Perform all three functions at once
264-
#[wasm_bindgen(js_name = "ecdsaCombineAndVerifyWithDerivedKey")]
265-
pub fn ecdsa_combine_and_verify_with_derived_key(
266-
variant: EcdsaVariant,
267-
pre_signature: Uint8Array,
268-
signature_shares: Vec<Uint8Array>,
269-
message_hash: Uint8Array,
270-
id: Uint8Array,
271-
public_keys: Vec<Uint8Array>,
272-
) -> JsResult<EcdsaSignature> {
273-
match variant {
274-
EcdsaVariant::K256 => Ecdsa::<Secp256k1>::combine_and_verify_with_derived_key(
275-
pre_signature,
276-
signature_shares,
277-
message_hash,
278-
id,
279-
public_keys,
280-
),
281-
EcdsaVariant::P256 => Ecdsa::<NistP256>::combine_and_verify_with_derived_key(
282-
pre_signature,
283-
signature_shares,
284-
message_hash,
285-
id,
286-
public_keys,
287-
),
288-
EcdsaVariant::P384 => todo!(),
289-
}
290-
}
291-
292-
/// Perform combine and verify with a specified public key
293-
#[wasm_bindgen(js_name = "ecdsaCombineAndVerify")]
294-
pub fn ecdsa_combine_and_verify(
295-
variant: EcdsaVariant,
296-
pre_signature: Uint8Array,
297-
signature_shares: Vec<Uint8Array>,
298-
message_hash: Uint8Array,
299-
public_key: Uint8Array,
300-
) -> JsResult<EcdsaSignature> {
301-
match variant {
302-
EcdsaVariant::K256 => Ecdsa::<Secp256k1>::combine_and_verify_with_specified_key(
303-
pre_signature,
304-
signature_shares,
305-
message_hash,
306-
public_key,
307-
),
308-
EcdsaVariant::P256 => Ecdsa::<NistP256>::combine_and_verify_with_specified_key(
309-
pre_signature,
310-
signature_shares,
311-
message_hash,
312-
public_key,
313-
),
314-
EcdsaVariant::P384 => todo!(),
315-
}
316-
}
317-
318-
/// Combine ECDSA signatures shares
319-
#[wasm_bindgen(js_name = "ecdsaCombine")]
320-
pub fn ecdsa_combine(
321-
variant: EcdsaVariant,
322-
presignature: Uint8Array,
323-
signature_shares: Vec<Uint8Array>,
324-
) -> JsResult<EcdsaSignature> {
325-
match variant {
326-
EcdsaVariant::K256 => Ecdsa::<Secp256k1>::combine(presignature, signature_shares),
327-
EcdsaVariant::P256 => Ecdsa::<NistP256>::combine(presignature, signature_shares),
328-
EcdsaVariant::P384 => todo!(),
329-
}
330-
}
331-
332-
#[wasm_bindgen(js_name = "ecdsaVerify")]
333-
pub fn ecdsa_verify(
334-
variant: EcdsaVariant,
335-
message_hash: Uint8Array,
336-
public_key: Uint8Array,
337-
signature: EcdsaSignature,
338-
) -> JsResult<()> {
339-
match variant {
340-
EcdsaVariant::K256 => Ecdsa::<Secp256k1>::verify(message_hash, public_key, signature),
341-
EcdsaVariant::P256 => Ecdsa::<NistP256>::verify(message_hash, public_key, signature),
342-
EcdsaVariant::P384 => todo!(),
343-
}
344-
}
345-
346244
#[wasm_bindgen(js_name = "ecdsaDeriveKey")]
347245
pub fn ecdsa_derive_key(
348-
variant: EcdsaVariant,
349246
id: Uint8Array,
350247
public_keys: Vec<Uint8Array>,
351248
) -> JsResult<Uint8Array> {
352-
match variant {
353-
EcdsaVariant::K256 => Ecdsa::<Secp256k1>::derive_key(id, public_keys),
354-
EcdsaVariant::P256 => Ecdsa::<NistP256>::derive_key(id, public_keys),
355-
EcdsaVariant::P384 => todo!(),
356-
}
249+
Ecdsa::<Secp256k1>::derive_key(id, public_keys)
357250
}

0 commit comments

Comments
 (0)