fix: better conditional comp for wasm

This commit is contained in:
rvcas 2023-05-11 16:59:54 -04:00
parent 312682e567
commit 1fb31e246c
No known key found for this signature in database
GPG Key ID: C09B64E263F7D68C
4 changed files with 16 additions and 16 deletions

View File

@ -14,7 +14,6 @@ authors = [
rust-version = "1.66.1"
[dependencies]
chumsky = "0.9.2"
hex = "0.4.3"
indexmap = "1.9.2"
indoc = "2.0.1"
@ -25,9 +24,13 @@ owo-colors = { version = "3.5.0", features = ["supports-colors"] }
strum = "0.24.1"
thiserror = "1.0.39"
vec1 = "1.10.1"
uplc = { path = '../uplc', version = "1.0.4-alpha" }
[target.'cfg(not(target_family="wasm"))'.dependencies]
chumsky = "0.9.2"
[target.'cfg(target_family="wasm")'.dependencies]
chumsky = { version = "0.9.2", features = ["ahash", "std"], default-features = false }
[dev-dependencies]
indoc = "2.0.1"
pretty_assertions = "1.3.0"

View File

@ -16,7 +16,6 @@ cryptoxide = "0.4.4"
hex = "0.4.3"
indexmap = "1.9.2"
itertools = "0.10.5"
k256 = { version = "0.13.0", optional = true }
miette = "5.5.0"
num-bigint = "0.4.3"
num-integer = "0.1.45"
@ -29,20 +28,18 @@ pallas-traverse = "0.18.0"
peg = "0.8.1"
pretty = "0.11.3"
pretty_assertions = "1.3.0"
secp256k1 = { version = "0.26.0", optional = true }
serde = { version = "1.0.152", features = ["derive"] }
serde_json = "1.0.94"
strum = "0.24.1"
strum_macros = "0.24.3"
thiserror = "1.0.39"
flat-rs = { path = "../flat-rs", version = "1.0.4-alpha" }
[target.'cfg(not(target_family="wasm"))'.dependencies]
secp256k1 = { version = "0.26.0" }
[target.'cfg(target_family="wasm")'.dependencies]
k256 = { version = "0.13.0" }
[dev-dependencies]
hex = "0.4.3"
indoc = "2.0.1"
[features]
default = ["dep:secp256k1"]
native-secp256k1 = ["dep:k256"]
unstable = []

View File

@ -50,10 +50,10 @@ pub enum Error {
DeserialisationError(String, Value),
#[error("Integer overflow")]
OverflowError,
#[cfg(not(feature = "native-secp256k1"))]
#[cfg(not(target_family = "wasm"))]
#[error(transparent)]
Secp256k1(#[from] secp256k1::Error),
#[cfg(feature = "native-secp256k1")]
#[cfg(target_family = "wasm")]
#[error(transparent)]
Secp256k1(#[from] k256::ecdsa::Error),
}

View File

@ -1041,7 +1041,7 @@ pub fn convert_constr_to_tag(constr: u64) -> Option<u64> {
pub static ANY_TAG: u64 = 102;
#[cfg(not(feature = "native-secp256k1"))]
#[cfg(not(target_family = "wasm"))]
fn verify_ecdsa(public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<Value, Error> {
use secp256k1::{ecdsa::Signature, Message, PublicKey, Secp256k1};
@ -1060,7 +1060,7 @@ fn verify_ecdsa(public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<V
/// Unlike the Haskell implementation the schnorr verification function in Aiken doesn't allow for arbitrary message sizes (at the moment).
/// The message needs to be 32 bytes (ideally prehashed, but not a requirement).
#[cfg(not(feature = "native-secp256k1"))]
#[cfg(not(target_family = "wasm"))]
fn verify_schnorr(public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<Value, Error> {
use secp256k1::{schnorr::Signature, Message, Secp256k1, XOnlyPublicKey};
@ -1077,7 +1077,7 @@ fn verify_schnorr(public_key: &[u8], message: &[u8], signature: &[u8]) -> Result
Ok(Value::Con(Constant::Bool(valid.is_ok()).into()))
}
#[cfg(feature = "native-secp256k1")]
#[cfg(target_family = "wasm")]
fn verify_ecdsa(public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<Value, Error> {
use k256::ecdsa::{self, signature::hazmat::PrehashVerifier};
@ -1090,7 +1090,7 @@ fn verify_ecdsa(public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<V
Ok(Value::Con(Constant::Bool(valid.is_ok()).into()))
}
#[cfg(feature = "native-secp256k1")]
#[cfg(target_family = "wasm")]
fn verify_schnorr(public_key: &[u8], message: &[u8], signature: &[u8]) -> Result<Value, Error> {
use k256::schnorr::{self, signature::hazmat::PrehashVerifier};