Skip to content

Commit

Permalink
feat: frost signature aggregation and verification support in wasm us…
Browse files Browse the repository at this point in the history
…ing lit-frost
  • Loading branch information
FedericoAmura committed Jan 22, 2025
1 parent ab70116 commit e14730c
Show file tree
Hide file tree
Showing 14 changed files with 494 additions and 99 deletions.
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,8 @@
"tslib": "^2.7.0",
"tweetnacl": "^1.0.3",
"tweetnacl-util": "^0.15.1",
"uint8arrays": "^4.0.3"
"uint8arrays": "^4.0.3",
"zod": "^3.24.1"
},
"devDependencies": {
"@nx/devkit": "17.3.0",
Expand Down
2 changes: 1 addition & 1 deletion packages/constants/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export * from './lib/version';

// ----------- Constants -----------
export * from './lib/constants/constants';
export * from './lib/constants/mappers';
export * from './lib/constants/crypto';
export * from './lib/constants/endpoints';
export * from './lib/constants/mappers';

Expand Down
36 changes: 0 additions & 36 deletions packages/constants/src/lib/constants/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1264,42 +1264,6 @@ export const VMTYPE = {
export type VMTYPE_TYPE = keyof typeof VMTYPE;
export type VMTYPE_VALUES = (typeof VMTYPE)[keyof typeof VMTYPE];

// pub enum SigningScheme {

// -- BLS
// Bls12381,

// -- ECDSA
// EcdsaK256Sha256,
// EcdsaP256Sha256,
// EcdsaP384Sha384,

// -- Frost
// SchnorrEd25519Sha512,
// SchnorrK256Sha256,
// SchnorrP256Sha256,
// SchnorrP384Sha384,
// SchnorrRistretto25519Sha512,
// SchnorrEd448Shake256,
// SchnorrRedJubjubBlake2b512,
// SchnorrK256Taproot,
// SchnorrRedDecaf377Blake2b512,
// SchnorrkelSubstrate,
// }
export const LIT_CURVE = {
BLS: 'BLS',
EcdsaK256: 'K256',
EcdsaCaitSith: 'ECDSA_CAIT_SITH', // Legacy alias of K256
EcdsaCAITSITHP256: 'EcdsaCaitSithP256',
EcdsaK256Sha256: 'EcdsaK256Sha256', // same as caitsith
EcdsaP256Sha256: 'EcdsaP256Sha256',
EcdsaP384Sha384: 'EcdsaP384Sha384',
} as const;

export type LIT_CURVE_TYPE = keyof typeof LIT_CURVE;
// This should replicate SigShare.sigType in types package
export type LIT_CURVE_VALUES = (typeof LIT_CURVE)[keyof typeof LIT_CURVE];

// ========== Either Types ==========
export const EITHER_TYPE = {
ERROR: 'ERROR',
Expand Down
74 changes: 74 additions & 0 deletions packages/constants/src/lib/constants/crypto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import { z } from 'zod';

import { ObjectMapFromArray } from './utils';

// pub enum SigningScheme {

// -- BLS
// Bls12381,

// -- ECDSA
// EcdsaK256Sha256,
// EcdsaP256Sha256,
// EcdsaP384Sha384,

// -- Frost
// SchnorrEd25519Sha512,
// SchnorrK256Sha256,
// SchnorrP256Sha256,
// SchnorrP384Sha384,
// SchnorrRistretto25519Sha512,
// SchnorrEd448Shake256,
// SchnorrRedJubjubBlake2b512,
// SchnorrK256Taproot,
// SchnorrRedDecaf377Blake2b512,
// SchnorrkelSubstrate,
// }

// ----- Frost Variant
export const LIT_FROST_VARIANT_VALUES = [
'Ed25519Sha512',
'Ed448Shake256',
'Ristretto25519Sha512',
'K256Sha256',
'P256Sha256',
'P384Sha384',
'RedJubjubBlake2b512',
'K256Taproot',
] as const;
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 = ['BLS'] as const;
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>;

// ----- ECDSA Variant
export const LIT_ECDSA_VARIANT_VALUES = [
'EcdsaK256Sha256',
'EcdsaP256Sha256',
'EcdsaP384Sha384',
] as const;
export const LIT_ECDSA_VARIANT = {
// Legacy values
EcdsaK256: 'K256',
EcdsaCaitSith: 'ECDSA_CAIT_SITH',
EcdsaCAITSITHP256: 'EcdsaCaitSithP256',
...ObjectMapFromArray(LIT_ECDSA_VARIANT_VALUES),
} as const;
export const LIT_ECDSA_VARIANT_SCHEMA = z.enum(LIT_ECDSA_VARIANT_VALUES);
export type LitEcdsaVariantType = z.infer<typeof LIT_ECDSA_VARIANT_SCHEMA>;

// ----- All Curve Types
export const LIT_CURVE = {
...LIT_BLS_VARIANT,
...LIT_FROST_VARIANT,
...LIT_ECDSA_VARIANT,
};

export type LIT_CURVE_TYPE = keyof typeof LIT_CURVE;
// This should replicate SigShare.sigType in types package
export type LIT_CURVE_VALUES = (typeof LIT_CURVE)[keyof typeof LIT_CURVE];
4 changes: 0 additions & 4 deletions packages/constants/src/lib/constants/mappers.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
import depd from 'depd';

import { datilDev, datilTest, datil, _nagaDev } from '@lit-protocol/contracts';

import { LIT_NETWORK_VALUES } from './constants';

const deprecated = depd('lit-js-sdk:constants:mappers');

/**
* Mapping of network context by network value.
*/
Expand Down
11 changes: 11 additions & 0 deletions packages/constants/src/lib/constants/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/**
* @example
* const obj = ['a', 'b', 'c']
* ObjectMapFromArray(obj) // { a: 'a', b: 'b', c: 'c' }
*/
export const ObjectMapFromArray = <T extends readonly string[]>(arr: T) => {
return arr.reduce(
(acc, scope) => ({ ...acc, [scope]: scope }),
{} as { [K in T[number]]: K }
);
};
9 changes: 7 additions & 2 deletions packages/crypto/src/lib/crypto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,19 @@ import {
uint8arrayToString,
} from '@lit-protocol/uint8arrays';
import {
EcdsaVariant,
// BLS
blsCombine,
blsDecrypt,
blsEncrypt,
blsVerify,
// ECDSA
EcdsaVariant,
ecdsaCombine,
ecdsaDeriveKey,
ecdsaVerify,
// FROST
// FrostVariant,
// SEV-SNP
sevSnpGetVcekUrl,
sevSnpVerify,
} from '@lit-protocol/wasm';
Expand Down Expand Up @@ -335,7 +340,7 @@ async function doDecrypt(
async function doCombineSignatureShares(
shares: BlsSignatureShare[]
): Promise<Uint8Array> {
const sigShares = shares.map((s, index) => {
const sigShares = shares.map((s) => {
return JSON.stringify({
ProofOfPossession: {
identifier: s.ProofOfPossession.identifier,
Expand Down
51 changes: 18 additions & 33 deletions packages/wasm/rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,52 +13,37 @@ crate-type = ["cdylib", "rlib"]
[features]

[dependencies]
# wasm and serialization support
wasm-bindgen = { version = "0.2", features = ["serde-serialize"] }
blsful = { version = "3.0.0-pre8", default-features = false, features = ["rust"] }
base64_light = "0.1"
getrandom = { version = "0.2", features = ["js"] }
hex = "0.4"
hd-keys-curves-wasm = { version = "1.0.1", default-features = false, features = ["k256", "p256", "p384"] }
serde = "1.0"
serde_json = "1.0"
serde_bare = "0.5"
serde_bytes = "0.11.14"
serde-wasm-bindgen = "0.6"

# cryptographic dependencies
blsful = { version = "3.0.0-pre8", default-features = false, features = ["rust"] }
hd-keys-curves-wasm = { version = "1.0.1", default-features = false, features = ["k256", "p256", "p384"] }
lit-frost = { version = "0.2.0", git = "https://github.com/LIT-Protocol/lit-frost" }

# curve and elliptic-curve cryptography
elliptic-curve = "0.13"
k256 = { version = "0.13", features = ["arithmetic"] }
k256 = { version = "0.13", features = ["arithmetic", "schnorr"] }
p256 = { version = "0.13", features = ["arithmetic"] }
p384 = { version = "0.13", features = ["arithmetic"] }
sha2 = "0.10"
subtle = "2.6"

wee_alloc = { version = "0.4.5", optional = true }
# hash and encoding utilities
sha2 = "0.10"
hex = "0.4"

console_error_panic_hook = { version = "0.1.7", optional = true }
wasm-bindgen-futures = "0.4.40"
# WASM and JS bindings
js-sys = "0.3.67"

sev = { version = "2.0.2", default-features = false, features = [
"snp",
"crypto_nossl",
] }
rand = "0.8"
serde_bytes = "0.11.14"
tsify = { version = "0.4.5", default-features = false, features = ["js"] }
jubjub-plus = { version = "0.10.4" }

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

# development dependencies
[dev-dependencies]
wasm-bindgen-test = "0.3.34"
ciborium = "0.2"
k256 = "0.13"
rand = "0.8"
rand_chacha = "0.3"
digest = "0.10"

[profile.release]
opt-level = "z"
lto = true
wasm-opt=['-Os']

[package.metadata.wasm-pack.profile.profiling]
wasm-opt = ['-g', '-O']
group = "0.13"
Loading

0 comments on commit e14730c

Please sign in to comment.