Skip to content

Commit

Permalink
WASM Bundle With Demo App (#8)
Browse files Browse the repository at this point in the history
Fixes #5

This PR adds a WASM bundle with an (_unpublished_) NPM `package.json` so
that it can be used on the Web.

An example web page is included in the `wasm/example` sub-directory (see
`wasm/README.md` for instructions).

As a design choice, the source is bundled into a single file, which
includes base-64 encoded WASM binary blob and uses `Blob` URLs for the
worker. This allows the worker to be bundled without requiring
additional HTTP requests for additional resources.
  • Loading branch information
Nicholas Rodrigues Lordello committed Jun 30, 2023
1 parent 4bb4c51 commit cb5bb6c
Show file tree
Hide file tree
Showing 21 changed files with 702 additions and 62 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/wasm.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: WASM

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

env:
CARGO_TERM_COLOR: always
RUSTFLAGS: "-Dwarnings"

jobs:
build:

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3
- name: Requirements
run: |
sudo apt-get update && sudo apt-get install binaryen
curl -fsSL https://rustwasm.github.io/wasm-pack/installer/init.sh | sh
curl -fsSL https://deno.land/x/install/install.sh | sh
echo "${HOME}/.deno/bin" >> "${GITHUB_PATH}"
- name: Versions
run: |
wasm-opt --version
wasm-pack --version
deno --version
- name: Tests
run: |
cd wasm
make test
169 changes: 168 additions & 1 deletion Cargo.lock

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

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
members = [
"cli",
"core",
"wasm",
]
1 change: 1 addition & 0 deletions cli/LICENSE
23 changes: 12 additions & 11 deletions cli/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,32 +95,33 @@ fn main() {
let threads = (0..num_cpus::get())
.map(|_| {
thread::spawn({
let safe = Safe::new(contracts.clone(), args.owners.clone(), args.threshold);
let mut safe = Safe::new(contracts.clone(), args.owners.clone(), args.threshold);
let prefix = args.prefix.0.clone();
let result = sender.clone();
move || {
let safe = deadbeef_core::search(safe, &prefix);
deadbeef_core::search(&mut safe, &prefix);
let _ = result.send(safe);
}
})
})
.collect::<Vec<_>>();

let safe = receiver.recv().expect("missing result");
let transaction = safe.transaction();

if args.quiet {
println!("0x{}", hex::encode(&safe.calldata));
println!("0x{}", hex::encode(&transaction.calldata));
} else {
println!("address: {}", safe.creation_address);
println!("factory: {}", safe.factory);
println!("singleton: {}", safe.singleton);
println!("fallback: {}", safe.fallback_handler);
println!("owners: {}", safe.owners[0]);
for owner in &safe.owners[1..] {
println!("address: {}", safe.creation_address());
println!("factory: {}", contracts.proxy_factory);
println!("singleton: {}", contracts.singleton);
println!("fallback: {}", contracts.fallback_handler);
println!("owners: {}", args.owners[0]);
for owner in &args.owners[1..] {
println!(" {}", owner);
}
println!("threshold: {}", safe.threshold);
println!("calldata: 0x{}", hex::encode(&safe.calldata));
println!("threshold: {}", args.threshold);
println!("calldata: 0x{}", hex::encode(&transaction.calldata));
}

let _ = threads;
Expand Down
1 change: 1 addition & 0 deletions core/LICENSE
5 changes: 2 additions & 3 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,10 @@ pub use self::{
pub use hex_literal::hex;
use rand::{rngs::SmallRng, Rng as _, SeedableRng as _};

/// For the specified Safe parameters
pub fn search(mut safe: Safe, prefix: &[u8]) -> Transaction {
/// Search for a vanity address with the specified Safe parameters and prefix.
pub fn search(safe: &mut Safe, prefix: &[u8]) {
let mut rng = SmallRng::from_entropy();
while !safe.creation_address().0.starts_with(prefix) {
safe.update_salt_nonce(|n| rng.fill(n));
}
safe.transaction()
}
Loading

0 comments on commit cb5bb6c

Please sign in to comment.