Skip to content

Commit e14730c

Browse files
committed
feat: frost signature aggregation and verification support in wasm using lit-frost
1 parent ab70116 commit e14730c

File tree

14 files changed

+494
-99
lines changed

14 files changed

+494
-99
lines changed

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@
7272
"tslib": "^2.7.0",
7373
"tweetnacl": "^1.0.3",
7474
"tweetnacl-util": "^0.15.1",
75-
"uint8arrays": "^4.0.3"
75+
"uint8arrays": "^4.0.3",
76+
"zod": "^3.24.1"
7677
},
7778
"devDependencies": {
7879
"@nx/devkit": "17.3.0",

packages/constants/src/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ export * from './lib/version';
33

44
// ----------- Constants -----------
55
export * from './lib/constants/constants';
6-
export * from './lib/constants/mappers';
6+
export * from './lib/constants/crypto';
77
export * from './lib/constants/endpoints';
88
export * from './lib/constants/mappers';
99

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

Lines changed: 0 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1264,42 +1264,6 @@ export const VMTYPE = {
12641264
export type VMTYPE_TYPE = keyof typeof VMTYPE;
12651265
export type VMTYPE_VALUES = (typeof VMTYPE)[keyof typeof VMTYPE];
12661266

1267-
// pub enum SigningScheme {
1268-
1269-
// -- BLS
1270-
// Bls12381,
1271-
1272-
// -- ECDSA
1273-
// EcdsaK256Sha256,
1274-
// EcdsaP256Sha256,
1275-
// EcdsaP384Sha384,
1276-
1277-
// -- Frost
1278-
// SchnorrEd25519Sha512,
1279-
// SchnorrK256Sha256,
1280-
// SchnorrP256Sha256,
1281-
// SchnorrP384Sha384,
1282-
// SchnorrRistretto25519Sha512,
1283-
// SchnorrEd448Shake256,
1284-
// SchnorrRedJubjubBlake2b512,
1285-
// SchnorrK256Taproot,
1286-
// SchnorrRedDecaf377Blake2b512,
1287-
// SchnorrkelSubstrate,
1288-
// }
1289-
export const LIT_CURVE = {
1290-
BLS: 'BLS',
1291-
EcdsaK256: 'K256',
1292-
EcdsaCaitSith: 'ECDSA_CAIT_SITH', // Legacy alias of K256
1293-
EcdsaCAITSITHP256: 'EcdsaCaitSithP256',
1294-
EcdsaK256Sha256: 'EcdsaK256Sha256', // same as caitsith
1295-
EcdsaP256Sha256: 'EcdsaP256Sha256',
1296-
EcdsaP384Sha384: 'EcdsaP384Sha384',
1297-
} as const;
1298-
1299-
export type LIT_CURVE_TYPE = keyof typeof LIT_CURVE;
1300-
// This should replicate SigShare.sigType in types package
1301-
export type LIT_CURVE_VALUES = (typeof LIT_CURVE)[keyof typeof LIT_CURVE];
1302-
13031267
// ========== Either Types ==========
13041268
export const EITHER_TYPE = {
13051269
ERROR: 'ERROR',
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import { z } from 'zod';
2+
3+
import { ObjectMapFromArray } from './utils';
4+
5+
// pub enum SigningScheme {
6+
7+
// -- BLS
8+
// Bls12381,
9+
10+
// -- ECDSA
11+
// EcdsaK256Sha256,
12+
// EcdsaP256Sha256,
13+
// EcdsaP384Sha384,
14+
15+
// -- Frost
16+
// SchnorrEd25519Sha512,
17+
// SchnorrK256Sha256,
18+
// SchnorrP256Sha256,
19+
// SchnorrP384Sha384,
20+
// SchnorrRistretto25519Sha512,
21+
// SchnorrEd448Shake256,
22+
// SchnorrRedJubjubBlake2b512,
23+
// SchnorrK256Taproot,
24+
// SchnorrRedDecaf377Blake2b512,
25+
// SchnorrkelSubstrate,
26+
// }
27+
28+
// ----- Frost Variant
29+
export const LIT_FROST_VARIANT_VALUES = [
30+
'Ed25519Sha512',
31+
'Ed448Shake256',
32+
'Ristretto25519Sha512',
33+
'K256Sha256',
34+
'P256Sha256',
35+
'P384Sha384',
36+
'RedJubjubBlake2b512',
37+
'K256Taproot',
38+
] as const;
39+
export const LIT_FROST_VARIANT = ObjectMapFromArray(LIT_FROST_VARIANT_VALUES);
40+
export const LIT_FROST_VARIANT_SCHEMA = z.enum(LIT_FROST_VARIANT_VALUES);
41+
export type LitFrostVariantType = z.infer<typeof LIT_FROST_VARIANT_SCHEMA>;
42+
43+
// ----- BLS Variant
44+
export const LIT_BLS_VARIANT_VALUES = ['BLS'] as const;
45+
export const LIT_BLS_VARIANT = ObjectMapFromArray(LIT_BLS_VARIANT_VALUES);
46+
export const LIT_BLS_VARIANT_SCHEMA = z.enum(LIT_BLS_VARIANT_VALUES);
47+
export type LitBlsVariantType = z.infer<typeof LIT_BLS_VARIANT_SCHEMA>;
48+
49+
// ----- ECDSA Variant
50+
export const LIT_ECDSA_VARIANT_VALUES = [
51+
'EcdsaK256Sha256',
52+
'EcdsaP256Sha256',
53+
'EcdsaP384Sha384',
54+
] as const;
55+
export const LIT_ECDSA_VARIANT = {
56+
// Legacy values
57+
EcdsaK256: 'K256',
58+
EcdsaCaitSith: 'ECDSA_CAIT_SITH',
59+
EcdsaCAITSITHP256: 'EcdsaCaitSithP256',
60+
...ObjectMapFromArray(LIT_ECDSA_VARIANT_VALUES),
61+
} as const;
62+
export const LIT_ECDSA_VARIANT_SCHEMA = z.enum(LIT_ECDSA_VARIANT_VALUES);
63+
export type LitEcdsaVariantType = z.infer<typeof LIT_ECDSA_VARIANT_SCHEMA>;
64+
65+
// ----- All Curve Types
66+
export const LIT_CURVE = {
67+
...LIT_BLS_VARIANT,
68+
...LIT_FROST_VARIANT,
69+
...LIT_ECDSA_VARIANT,
70+
};
71+
72+
export type LIT_CURVE_TYPE = keyof typeof LIT_CURVE;
73+
// This should replicate SigShare.sigType in types package
74+
export type LIT_CURVE_VALUES = (typeof LIT_CURVE)[keyof typeof LIT_CURVE];

packages/constants/src/lib/constants/mappers.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
1-
import depd from 'depd';
2-
31
import { datilDev, datilTest, datil, _nagaDev } from '@lit-protocol/contracts';
42

53
import { LIT_NETWORK_VALUES } from './constants';
64

7-
const deprecated = depd('lit-js-sdk:constants:mappers');
8-
95
/**
106
* Mapping of network context by network value.
117
*/
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/**
2+
* @example
3+
* const obj = ['a', 'b', 'c']
4+
* ObjectMapFromArray(obj) // { a: 'a', b: 'b', c: 'c' }
5+
*/
6+
export const ObjectMapFromArray = <T extends readonly string[]>(arr: T) => {
7+
return arr.reduce(
8+
(acc, scope) => ({ ...acc, [scope]: scope }),
9+
{} as { [K in T[number]]: K }
10+
);
11+
};

packages/crypto/src/lib/crypto.ts

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,19 @@ import {
2121
uint8arrayToString,
2222
} from '@lit-protocol/uint8arrays';
2323
import {
24-
EcdsaVariant,
24+
// BLS
2525
blsCombine,
2626
blsDecrypt,
2727
blsEncrypt,
2828
blsVerify,
29+
// ECDSA
30+
EcdsaVariant,
2931
ecdsaCombine,
3032
ecdsaDeriveKey,
3133
ecdsaVerify,
34+
// FROST
35+
// FrostVariant,
36+
// SEV-SNP
3237
sevSnpGetVcekUrl,
3338
sevSnpVerify,
3439
} from '@lit-protocol/wasm';
@@ -335,7 +340,7 @@ async function doDecrypt(
335340
async function doCombineSignatureShares(
336341
shares: BlsSignatureShare[]
337342
): Promise<Uint8Array> {
338-
const sigShares = shares.map((s, index) => {
343+
const sigShares = shares.map((s) => {
339344
return JSON.stringify({
340345
ProofOfPossession: {
341346
identifier: s.ProofOfPossession.identifier,

packages/wasm/rust/Cargo.toml

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -13,52 +13,37 @@ crate-type = ["cdylib", "rlib"]
1313
[features]
1414

1515
[dependencies]
16+
# wasm and serialization support
1617
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
17-
blsful = { version = "3.0.0-pre8", default-features = false, features = ["rust"] }
18-
base64_light = "0.1"
19-
getrandom = { version = "0.2", features = ["js"] }
20-
hex = "0.4"
21-
hd-keys-curves-wasm = { version = "1.0.1", default-features = false, features = ["k256", "p256", "p384"] }
2218
serde = "1.0"
2319
serde_json = "1.0"
2420
serde_bare = "0.5"
21+
serde_bytes = "0.11.14"
2522
serde-wasm-bindgen = "0.6"
2623

24+
# cryptographic dependencies
25+
blsful = { version = "3.0.0-pre8", default-features = false, features = ["rust"] }
26+
hd-keys-curves-wasm = { version = "1.0.1", default-features = false, features = ["k256", "p256", "p384"] }
27+
lit-frost = { version = "0.2.0", git = "https://github.com/LIT-Protocol/lit-frost" }
28+
29+
# curve and elliptic-curve cryptography
2730
elliptic-curve = "0.13"
28-
k256 = { version = "0.13", features = ["arithmetic"] }
31+
k256 = { version = "0.13", features = ["arithmetic", "schnorr"] }
2932
p256 = { version = "0.13", features = ["arithmetic"] }
3033
p384 = { version = "0.13", features = ["arithmetic"] }
31-
sha2 = "0.10"
34+
subtle = "2.6"
3235

33-
wee_alloc = { version = "0.4.5", optional = true }
36+
# hash and encoding utilities
37+
sha2 = "0.10"
38+
hex = "0.4"
3439

35-
console_error_panic_hook = { version = "0.1.7", optional = true }
36-
wasm-bindgen-futures = "0.4.40"
40+
# WASM and JS bindings
3741
js-sys = "0.3.67"
38-
39-
sev = { version = "2.0.2", default-features = false, features = [
40-
"snp",
41-
"crypto_nossl",
42-
] }
43-
rand = "0.8"
44-
serde_bytes = "0.11.14"
4542
tsify = { version = "0.4.5", default-features = false, features = ["js"] }
46-
jubjub-plus = { version = "0.10.4" }
4743

48-
web-sys = { version = "0.3", features = ["console"] }
44+
# SEV (Secure Encrypted Virtualization) support
45+
sev = { version = "2.0.2", default-features = false, features = ["snp", "crypto_nossl"] }
4946

47+
# development dependencies
5048
[dev-dependencies]
51-
wasm-bindgen-test = "0.3.34"
52-
ciborium = "0.2"
53-
k256 = "0.13"
54-
rand = "0.8"
55-
rand_chacha = "0.3"
56-
digest = "0.10"
57-
58-
[profile.release]
59-
opt-level = "z"
60-
lto = true
61-
wasm-opt=['-Os']
62-
63-
[package.metadata.wasm-pack.profile.profiling]
64-
wasm-opt = ['-g', '-O']
49+
group = "0.13"

0 commit comments

Comments
 (0)