Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
17 changes: 6 additions & 11 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 0 additions & 4 deletions hash/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,6 @@ solana-frozen-abi-macro = { workspace = true, optional = true, features = [
] }
solana-sanitize = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
js-sys = { workspace = true }
wasm-bindgen = { workspace = true }

[dev-dependencies]
bs58 = { workspace = true, default-features = false, features = ["alloc"] }

Expand Down
68 changes: 2 additions & 66 deletions hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
#![cfg_attr(feature = "frozen-abi", feature(min_specialization))]
#[cfg(feature = "borsh")]
use borsh::{BorshDeserialize, BorshSchema, BorshSerialize};
#[cfg(any(feature = "std", target_arch = "wasm32"))]
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "bytemuck")]
use bytemuck_derive::{Pod, Zeroable};
#[cfg(feature = "serde")]
use serde_derive::{Deserialize, Serialize};
#[cfg(any(all(feature = "borsh", feature = "std"), target_arch = "wasm32"))]
#[cfg(all(feature = "borsh", feature = "std"))]
use std::string::ToString;
use {
core::{
Expand All @@ -18,12 +18,6 @@ use {
},
solana_sanitize::Sanitize,
};
#[cfg(target_arch = "wasm32")]
use {
js_sys::{Array, Uint8Array},
std::{boxed::Box, format, string::String, vec},
wasm_bindgen::{prelude::*, JsCast},
};

/// Size of a hash in bytes.
pub const HASH_BYTES: usize = 32;
Expand All @@ -37,7 +31,6 @@ pub const MAX_BASE58_LEN: usize = 44;
///
/// [SHA-256]: https://en.wikipedia.org/wiki/SHA-2
/// [blake3]: https://github.com/BLAKE3-team/BLAKE3
#[cfg_attr(target_arch = "wasm32", wasm_bindgen)]
#[cfg_attr(feature = "frozen-abi", derive(solana_frozen_abi_macro::AbiExample))]
#[cfg_attr(
feature = "borsh",
Expand Down Expand Up @@ -148,63 +141,6 @@ impl Hash {
}
}

#[cfg(target_arch = "wasm32")]
#[allow(non_snake_case)]
#[wasm_bindgen]
impl Hash {
/// Create a new Hash object
///
/// * `value` - optional hash as a base58 encoded string, `Uint8Array`, `[number]`
#[wasm_bindgen(constructor)]
pub fn constructor(value: JsValue) -> Result<Hash, JsValue> {
if let Some(base58_str) = value.as_string() {
base58_str
.parse::<Hash>()
.map_err(|x| JsValue::from(x.to_string()))
} else if let Some(uint8_array) = value.dyn_ref::<Uint8Array>() {
<[u8; HASH_BYTES]>::try_from(uint8_array.to_vec())
.map(Hash::new_from_array)
.map_err(|err| format!("Invalid Hash value: {err:?}").into())
} else if let Some(array) = value.dyn_ref::<Array>() {
let mut bytes = vec![];
let iterator = js_sys::try_iter(&array.values())?.expect("array to be iterable");
for x in iterator {
let x = x?;

if let Some(n) = x.as_f64() {
if n >= 0. && n <= 255. {
bytes.push(n as u8);
continue;
}
}
return Err(format!("Invalid array argument: {:?}", x).into());
}
<[u8; HASH_BYTES]>::try_from(bytes)
.map(Hash::new_from_array)
.map_err(|err| format!("Invalid Hash value: {err:?}").into())
} else if value.is_undefined() {
Ok(Hash::default())
} else {
Err("Unsupported argument".into())
}
}

/// Return the base58 string representation of the hash
pub fn toString(&self) -> String {
self.to_string()
}

/// Checks if two `Hash`s are equal
pub fn equals(&self, other: &Hash) -> bool {
self == other
}

/// Return the `Uint8Array` representation of the hash
pub fn toBytes(&self) -> Box<[u8]> {
self.0.clone().into()
}
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 1 addition & 5 deletions instruction/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = { workspace = true }
edition = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
targets = ["x86_64-unknown-linux-gnu"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]

Expand Down Expand Up @@ -38,10 +38,6 @@ solana-frozen-abi-macro = { workspace = true, optional = true }
solana-instruction-error = { workspace = true, features = ["num-traits"] }
solana-pubkey = { workspace = true, default-features = false }

[target.'cfg(target_arch = "wasm32")'.dependencies]
getrandom = { workspace = true, features = ["js", "wasm-bindgen"] }
wasm-bindgen = { workspace = true }

[target.'cfg(target_os = "solana")'.dependencies]
solana-define-syscall = { workspace = true }

Expand Down
1 change: 0 additions & 1 deletion instruction/src/account_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ use solana_pubkey::Pubkey;
///
/// [`Instruction`]: crate::Instruction
#[repr(C)]
#[cfg_attr(target_arch = "wasm32", wasm_bindgen::prelude::wasm_bindgen)]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
Expand Down
23 changes: 1 addition & 22 deletions instruction/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,6 @@ pub use account_meta::AccountMeta;
pub use solana_instruction_error as error;
#[cfg(any(feature = "syscalls", target_os = "solana"))]
pub mod syscalls;
#[cfg(all(feature = "std", target_arch = "wasm32"))]
pub mod wasm;

/// A directive for a single invocation of a Solana program.
///
Expand Down Expand Up @@ -87,7 +85,7 @@ pub mod wasm;
/// Programs may require signatures from some accounts, in which case they
/// should be specified as signers during `Instruction` construction. The
/// program must still validate during execution that the account is a signer.
#[cfg(all(feature = "std", not(target_arch = "wasm32")))]
#[cfg(feature = "std")]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
Expand All @@ -102,25 +100,6 @@ pub struct Instruction {
pub data: Vec<u8>,
}

/// wasm-bindgen version of the Instruction struct.
/// This duplication is required until https://github.com/rustwasm/wasm-bindgen/issues/3671
/// is fixed. This must not diverge from the regular non-wasm Instruction struct.
#[cfg(all(feature = "std", target_arch = "wasm32"))]
#[wasm_bindgen::prelude::wasm_bindgen]
#[cfg_attr(
feature = "serde",
derive(serde_derive::Serialize, serde_derive::Deserialize)
)]
#[derive(Debug, PartialEq, Eq, Clone)]
pub struct Instruction {
#[wasm_bindgen(skip)]
pub program_id: Pubkey,
#[wasm_bindgen(skip)]
pub accounts: Vec<AccountMeta>,
#[wasm_bindgen(skip)]
pub data: Vec<u8>,
}

#[cfg(feature = "std")]
impl Instruction {
#[cfg(feature = "borsh")]
Expand Down
63 changes: 0 additions & 63 deletions instruction/src/wasm.rs

This file was deleted.

5 changes: 1 addition & 4 deletions keypair/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ license = { workspace = true }
edition = { workspace = true }

[package.metadata.docs.rs]
targets = ["x86_64-unknown-linux-gnu", "wasm32-unknown-unknown"]
targets = ["x86_64-unknown-linux-gnu"]
all-features = true
rustdoc-args = ["--cfg=docsrs"]

Expand All @@ -33,9 +33,6 @@ solana-seed-phrase = { workspace = true }
solana-signature = { workspace = true, features = ["std", "verify"] }
solana-signer = { workspace = true }

[target.'cfg(target_arch = "wasm32")'.dependencies]
wasm-bindgen = { workspace = true }

[dev-dependencies]
serde_json = { workspace = true }
static_assertions = { workspace = true }
Expand Down
Loading
Loading