From 1b5e9a523a7e39de9c86f0dd92451212ca4a6193 Mon Sep 17 00:00:00 2001 From: "Justin R. Evans" Date: Tue, 6 Sep 2022 12:05:04 -0400 Subject: [PATCH] Move @anoma/wasm -> @anoma/shared --- README.md | 3 ++- apps/extension/src/browsers/chrome/manifest.json | 6 ++++++ apps/namada-interface/package.json | 2 +- packages/crypto/lib/src/crypto/aead.rs | 2 +- packages/crypto/lib/src/crypto/bip44.rs | 6 +----- packages/crypto/lib/src/crypto/mod.rs | 1 - packages/crypto/lib/src/lib.rs | 1 + packages/crypto/lib/src/{crypto => }/utils.rs | 0 packages/crypto/src/index.ts | 13 +++++++++++++ packages/seed-management/package.json | 2 +- packages/seed-management/src/Mnemonic.test.ts | 2 +- packages/seed-management/src/Mnemonic.ts | 2 +- packages/{wasm => shared}/.eslintrc | 0 packages/{wasm => shared}/.gitignore | 0 packages/{wasm => shared}/.prettierignore | 0 packages/{wasm => shared}/.prettierrc | 0 packages/{wasm => shared}/README.md | 0 packages/{wasm => shared}/index.ts | 0 packages/{wasm => shared}/lib/.appveyor.yml | 0 packages/{wasm => shared}/lib/.cargo-ok | 0 packages/{wasm => shared}/lib/.gitignore | 0 packages/{wasm => shared}/lib/.travis.yml | 0 packages/{wasm => shared}/lib/Cargo.toml | 0 packages/{wasm => shared}/lib/LICENSE_APACHE | 0 packages/{wasm => shared}/lib/LICENSE_MIT | 0 packages/{wasm => shared}/lib/src/account.rs | 0 packages/{wasm => shared}/lib/src/ibc_transfer.rs | 0 packages/{wasm => shared}/lib/src/lib.rs | 0 packages/{wasm => shared}/lib/src/transfer.rs | 0 .../lib/src/types/encrypted_keypair.rs | 0 packages/{wasm => shared}/lib/src/types/keypair.rs | 0 packages/{wasm => shared}/lib/src/types/mnemonic.rs | 0 packages/{wasm => shared}/lib/src/types/mod.rs | 0 .../{wasm => shared}/lib/src/types/transaction.rs | 0 packages/{wasm => shared}/lib/src/types/tx.rs | 0 packages/{wasm => shared}/lib/src/types/wrapper.rs | 0 packages/{wasm => shared}/lib/src/utils.rs | 0 packages/{wasm => shared}/lib/src/wallet.rs | 0 packages/{wasm => shared}/lib/tests/web.rs | 0 packages/{wasm => shared}/package.json | 2 +- packages/{wasm => shared}/src/AnomaClient.ts | 0 packages/{wasm => shared}/tsconfig.json | 0 packages/{wasm => shared}/yarn.lock | 0 packages/tx/README.md | 2 +- packages/tx/package.json | 2 +- packages/tx/src/Account.ts | 2 +- packages/tx/src/IBCTransfer.ts | 2 +- packages/tx/src/Transfer.ts | 2 +- packages/wallet/package.json | 2 +- packages/wallet/src/Wallet.test.ts | 2 +- packages/wallet/src/Wallet.ts | 2 +- scripts/build-test.sh | 2 +- scripts/build.sh | 2 +- 53 files changed, 39 insertions(+), 23 deletions(-) rename packages/crypto/lib/src/{crypto => }/utils.rs (100%) rename packages/{wasm => shared}/.eslintrc (100%) rename packages/{wasm => shared}/.gitignore (100%) rename packages/{wasm => shared}/.prettierignore (100%) rename packages/{wasm => shared}/.prettierrc (100%) rename packages/{wasm => shared}/README.md (100%) rename packages/{wasm => shared}/index.ts (100%) rename packages/{wasm => shared}/lib/.appveyor.yml (100%) rename packages/{wasm => shared}/lib/.cargo-ok (100%) rename packages/{wasm => shared}/lib/.gitignore (100%) rename packages/{wasm => shared}/lib/.travis.yml (100%) rename packages/{wasm => shared}/lib/Cargo.toml (100%) rename packages/{wasm => shared}/lib/LICENSE_APACHE (100%) rename packages/{wasm => shared}/lib/LICENSE_MIT (100%) rename packages/{wasm => shared}/lib/src/account.rs (100%) rename packages/{wasm => shared}/lib/src/ibc_transfer.rs (100%) rename packages/{wasm => shared}/lib/src/lib.rs (100%) rename packages/{wasm => shared}/lib/src/transfer.rs (100%) rename packages/{wasm => shared}/lib/src/types/encrypted_keypair.rs (100%) rename packages/{wasm => shared}/lib/src/types/keypair.rs (100%) rename packages/{wasm => shared}/lib/src/types/mnemonic.rs (100%) rename packages/{wasm => shared}/lib/src/types/mod.rs (100%) rename packages/{wasm => shared}/lib/src/types/transaction.rs (100%) rename packages/{wasm => shared}/lib/src/types/tx.rs (100%) rename packages/{wasm => shared}/lib/src/types/wrapper.rs (100%) rename packages/{wasm => shared}/lib/src/utils.rs (100%) rename packages/{wasm => shared}/lib/src/wallet.rs (100%) rename packages/{wasm => shared}/lib/tests/web.rs (100%) rename packages/{wasm => shared}/package.json (96%) rename packages/{wasm => shared}/src/AnomaClient.ts (100%) rename packages/{wasm => shared}/tsconfig.json (100%) rename packages/{wasm => shared}/yarn.lock (100%) diff --git a/README.md b/README.md index f61e4fedff..2674d4ee1a 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,7 @@ namada-interface/ ├── namada-interface/ # Main wallet React App ├── extension/ # Browser Extension React App └── packages/ + ├── crypto/ # Crypto functions related to anoma extension and interface ├── integrations/ # Third-party wallet integrations └── masp-web/ # utilities for performing MASP actions └── rpc/ # Library for handling HTTP and WebSocket RPC calls @@ -56,7 +57,7 @@ namada-interface/ ├── tx/ # Library for interfacing with Anoma transactions ├── utils/ # Shared utilities ├── wallet/ # Library for deriving keys - ├── wasm/ # Rust lib for generating WASM + ├── shared/ # Package for interfacing with `namada/shared` ``` ### Usage diff --git a/apps/extension/src/browsers/chrome/manifest.json b/apps/extension/src/browsers/chrome/manifest.json index b575e3ef80..8452ee4b6a 100644 --- a/apps/extension/src/browsers/chrome/manifest.json +++ b/apps/extension/src/browsers/chrome/manifest.json @@ -17,6 +17,12 @@ "default_popup": "../../static/popup.html" }, "permissions": ["storage", "notifications", "identity"], + "sandbox": { + "pages": ["../../background/index.ts"] + }, + "content_security_policy": { + "sandbox": "sandbox allow-scripts script-src 'self' 'wasm-eval" + }, "web_accessible_resources": [ { "resources": ["scripts/inject.ts"], diff --git a/apps/namada-interface/package.json b/apps/namada-interface/package.json index e7335135aa..4ad1f99c1e 100644 --- a/apps/namada-interface/package.json +++ b/apps/namada-interface/package.json @@ -15,10 +15,10 @@ "@anoma/rpc": "0.1.0", "@anoma/seed-management": "0.1.0", "@anoma/session": "0.1.0", + "@anoma/shared": "0.1.0", "@anoma/tx": "0.1.0", "@anoma/utils": "0.1.0", "@anoma/wallet": "0.1.0", - "@anoma/wasm": "0.1.0", "@reduxjs/toolkit": "^1.8.0", "crypto-browserify": "^3.12.0", "framer-motion": "^6.2.8", diff --git a/packages/crypto/lib/src/crypto/aead.rs b/packages/crypto/lib/src/crypto/aead.rs index cef2657a88..975b7bc176 100644 --- a/packages/crypto/lib/src/crypto/aead.rs +++ b/packages/crypto/lib/src/crypto/aead.rs @@ -3,7 +3,7 @@ use orion::{aead, kdf}; use thiserror::Error; use wasm_bindgen::prelude::*; -use crate::crypto::utils::{encryption_key, encryption_salt}; +use crate::utils::{encryption_key, encryption_salt}; #[allow(missing_docs)] #[derive(Debug, Error)] diff --git a/packages/crypto/lib/src/crypto/bip44.rs b/packages/crypto/lib/src/crypto/bip44.rs index e9153150b6..3fa09f781f 100644 --- a/packages/crypto/lib/src/crypto/bip44.rs +++ b/packages/crypto/lib/src/crypto/bip44.rs @@ -7,7 +7,6 @@ use wasm_bindgen::prelude::*; pub struct Bip44 { root_key: String, seed: Vec, - password: String, } #[wasm_bindgen] @@ -28,9 +27,7 @@ pub struct ExtendedKeys { #[wasm_bindgen] impl Bip44 { - pub fn new( - seed: Vec, - password: String) -> Result { + pub fn new(seed: Vec) -> Result { let seed: &[u8] = &seed; // BIP32 Root Key @@ -38,7 +35,6 @@ impl Bip44 { let root_xprv_str = root_xprv.to_string(Prefix::XPRV).to_string(); Ok(Bip44 { - password, root_key: root_xprv_str, seed: seed.to_vec(), }) diff --git a/packages/crypto/lib/src/crypto/mod.rs b/packages/crypto/lib/src/crypto/mod.rs index 60e8e11b01..af2323502d 100644 --- a/packages/crypto/lib/src/crypto/mod.rs +++ b/packages/crypto/lib/src/crypto/mod.rs @@ -1,4 +1,3 @@ pub mod aead; -pub mod utils; pub mod mnemonic; pub mod bip44; diff --git a/packages/crypto/lib/src/lib.rs b/packages/crypto/lib/src/lib.rs index 274f0edcd3..5283278d1f 100644 --- a/packages/crypto/lib/src/lib.rs +++ b/packages/crypto/lib/src/lib.rs @@ -1 +1,2 @@ pub mod crypto; +pub mod utils; diff --git a/packages/crypto/lib/src/crypto/utils.rs b/packages/crypto/lib/src/utils.rs similarity index 100% rename from packages/crypto/lib/src/crypto/utils.rs rename to packages/crypto/lib/src/utils.rs diff --git a/packages/crypto/src/index.ts b/packages/crypto/src/index.ts index 6a82d35def..d01f87e969 100644 --- a/packages/crypto/src/index.ts +++ b/packages/crypto/src/index.ts @@ -1 +1,14 @@ +/* eslint-disable */ +import wasm from "./crypto"; +/* eslint-enable */ + +export const init = async (): Promise => { + // Support setting wasm-pack target to "nodejs" (for testing) + // A target of "nodejs" will not generate a callable init() function + const _init = + typeof wasm === "function" ? wasm : () => Promise.resolve({ memory: null }); + const { memory } = await _init(); + return memory; +}; + export * from "./crypto"; diff --git a/packages/seed-management/package.json b/packages/seed-management/package.json index d92cf327cc..1e8dde5b83 100644 --- a/packages/seed-management/package.json +++ b/packages/seed-management/package.json @@ -21,7 +21,7 @@ "typescript": "^4.5.5" }, "dependencies": { - "@anoma/wasm": "0.1.0", + "@anoma/shared": "0.1.0", "@iarna/toml": "^2.2.5", "buffer": "^6.0.3" } diff --git a/packages/seed-management/src/Mnemonic.test.ts b/packages/seed-management/src/Mnemonic.test.ts index 8c743e7215..bba85f6904 100644 --- a/packages/seed-management/src/Mnemonic.test.ts +++ b/packages/seed-management/src/Mnemonic.test.ts @@ -1,5 +1,5 @@ import { Mnemonic, MnemonicLength } from "./Mnemonic"; -import { AnomaClient } from "@anoma/wasm"; +import { AnomaClient } from "@anoma/shared"; test("mnemonic should have a correct length", async () => { const mnemonic1 = await Mnemonic.fromMnemonic(MnemonicLength.Twelve); diff --git a/packages/seed-management/src/Mnemonic.ts b/packages/seed-management/src/Mnemonic.ts index be85ec55e7..4dfbf3c105 100644 --- a/packages/seed-management/src/Mnemonic.ts +++ b/packages/seed-management/src/Mnemonic.ts @@ -1,4 +1,4 @@ -import { AnomaClient } from "@anoma/wasm"; +import { AnomaClient } from "@anoma/shared"; import { toBase64, fromBase64 } from "@cosmjs/encoding"; export enum MnemonicLength { diff --git a/packages/wasm/.eslintrc b/packages/shared/.eslintrc similarity index 100% rename from packages/wasm/.eslintrc rename to packages/shared/.eslintrc diff --git a/packages/wasm/.gitignore b/packages/shared/.gitignore similarity index 100% rename from packages/wasm/.gitignore rename to packages/shared/.gitignore diff --git a/packages/wasm/.prettierignore b/packages/shared/.prettierignore similarity index 100% rename from packages/wasm/.prettierignore rename to packages/shared/.prettierignore diff --git a/packages/wasm/.prettierrc b/packages/shared/.prettierrc similarity index 100% rename from packages/wasm/.prettierrc rename to packages/shared/.prettierrc diff --git a/packages/wasm/README.md b/packages/shared/README.md similarity index 100% rename from packages/wasm/README.md rename to packages/shared/README.md diff --git a/packages/wasm/index.ts b/packages/shared/index.ts similarity index 100% rename from packages/wasm/index.ts rename to packages/shared/index.ts diff --git a/packages/wasm/lib/.appveyor.yml b/packages/shared/lib/.appveyor.yml similarity index 100% rename from packages/wasm/lib/.appveyor.yml rename to packages/shared/lib/.appveyor.yml diff --git a/packages/wasm/lib/.cargo-ok b/packages/shared/lib/.cargo-ok similarity index 100% rename from packages/wasm/lib/.cargo-ok rename to packages/shared/lib/.cargo-ok diff --git a/packages/wasm/lib/.gitignore b/packages/shared/lib/.gitignore similarity index 100% rename from packages/wasm/lib/.gitignore rename to packages/shared/lib/.gitignore diff --git a/packages/wasm/lib/.travis.yml b/packages/shared/lib/.travis.yml similarity index 100% rename from packages/wasm/lib/.travis.yml rename to packages/shared/lib/.travis.yml diff --git a/packages/wasm/lib/Cargo.toml b/packages/shared/lib/Cargo.toml similarity index 100% rename from packages/wasm/lib/Cargo.toml rename to packages/shared/lib/Cargo.toml diff --git a/packages/wasm/lib/LICENSE_APACHE b/packages/shared/lib/LICENSE_APACHE similarity index 100% rename from packages/wasm/lib/LICENSE_APACHE rename to packages/shared/lib/LICENSE_APACHE diff --git a/packages/wasm/lib/LICENSE_MIT b/packages/shared/lib/LICENSE_MIT similarity index 100% rename from packages/wasm/lib/LICENSE_MIT rename to packages/shared/lib/LICENSE_MIT diff --git a/packages/wasm/lib/src/account.rs b/packages/shared/lib/src/account.rs similarity index 100% rename from packages/wasm/lib/src/account.rs rename to packages/shared/lib/src/account.rs diff --git a/packages/wasm/lib/src/ibc_transfer.rs b/packages/shared/lib/src/ibc_transfer.rs similarity index 100% rename from packages/wasm/lib/src/ibc_transfer.rs rename to packages/shared/lib/src/ibc_transfer.rs diff --git a/packages/wasm/lib/src/lib.rs b/packages/shared/lib/src/lib.rs similarity index 100% rename from packages/wasm/lib/src/lib.rs rename to packages/shared/lib/src/lib.rs diff --git a/packages/wasm/lib/src/transfer.rs b/packages/shared/lib/src/transfer.rs similarity index 100% rename from packages/wasm/lib/src/transfer.rs rename to packages/shared/lib/src/transfer.rs diff --git a/packages/wasm/lib/src/types/encrypted_keypair.rs b/packages/shared/lib/src/types/encrypted_keypair.rs similarity index 100% rename from packages/wasm/lib/src/types/encrypted_keypair.rs rename to packages/shared/lib/src/types/encrypted_keypair.rs diff --git a/packages/wasm/lib/src/types/keypair.rs b/packages/shared/lib/src/types/keypair.rs similarity index 100% rename from packages/wasm/lib/src/types/keypair.rs rename to packages/shared/lib/src/types/keypair.rs diff --git a/packages/wasm/lib/src/types/mnemonic.rs b/packages/shared/lib/src/types/mnemonic.rs similarity index 100% rename from packages/wasm/lib/src/types/mnemonic.rs rename to packages/shared/lib/src/types/mnemonic.rs diff --git a/packages/wasm/lib/src/types/mod.rs b/packages/shared/lib/src/types/mod.rs similarity index 100% rename from packages/wasm/lib/src/types/mod.rs rename to packages/shared/lib/src/types/mod.rs diff --git a/packages/wasm/lib/src/types/transaction.rs b/packages/shared/lib/src/types/transaction.rs similarity index 100% rename from packages/wasm/lib/src/types/transaction.rs rename to packages/shared/lib/src/types/transaction.rs diff --git a/packages/wasm/lib/src/types/tx.rs b/packages/shared/lib/src/types/tx.rs similarity index 100% rename from packages/wasm/lib/src/types/tx.rs rename to packages/shared/lib/src/types/tx.rs diff --git a/packages/wasm/lib/src/types/wrapper.rs b/packages/shared/lib/src/types/wrapper.rs similarity index 100% rename from packages/wasm/lib/src/types/wrapper.rs rename to packages/shared/lib/src/types/wrapper.rs diff --git a/packages/wasm/lib/src/utils.rs b/packages/shared/lib/src/utils.rs similarity index 100% rename from packages/wasm/lib/src/utils.rs rename to packages/shared/lib/src/utils.rs diff --git a/packages/wasm/lib/src/wallet.rs b/packages/shared/lib/src/wallet.rs similarity index 100% rename from packages/wasm/lib/src/wallet.rs rename to packages/shared/lib/src/wallet.rs diff --git a/packages/wasm/lib/tests/web.rs b/packages/shared/lib/tests/web.rs similarity index 100% rename from packages/wasm/lib/tests/web.rs rename to packages/shared/lib/tests/web.rs diff --git a/packages/wasm/package.json b/packages/shared/package.json similarity index 96% rename from packages/wasm/package.json rename to packages/shared/package.json index 09269a5672..7d46c2c19e 100644 --- a/packages/wasm/package.json +++ b/packages/shared/package.json @@ -1,5 +1,5 @@ { - "name": "@anoma/wasm", + "name": "@anoma/shared", "version": "0.1.0", "type": "module", "license": "MIT", diff --git a/packages/wasm/src/AnomaClient.ts b/packages/shared/src/AnomaClient.ts similarity index 100% rename from packages/wasm/src/AnomaClient.ts rename to packages/shared/src/AnomaClient.ts diff --git a/packages/wasm/tsconfig.json b/packages/shared/tsconfig.json similarity index 100% rename from packages/wasm/tsconfig.json rename to packages/shared/tsconfig.json diff --git a/packages/wasm/yarn.lock b/packages/shared/yarn.lock similarity index 100% rename from packages/wasm/yarn.lock rename to packages/shared/yarn.lock diff --git a/packages/tx/README.md b/packages/tx/README.md index 9d40e4ae8b..68cc515745 100644 --- a/packages/tx/README.md +++ b/packages/tx/README.md @@ -1,5 +1,5 @@ # tx -Anoma Wallet transaction library for interfacing with packages served from `@anoma/wasm`. +Anoma Wallet transaction library for interfacing with packages served from `@anoma/shared`. _TBD_ diff --git a/packages/tx/package.json b/packages/tx/package.json index d1f9e3be5e..83cda668a9 100644 --- a/packages/tx/package.json +++ b/packages/tx/package.json @@ -28,7 +28,7 @@ "typescript": "^4.7.4" }, "dependencies": { - "@anoma/wasm": "0.1.0", + "@anoma/shared": "0.1.0", "slip44": "^1.2.60" } } diff --git a/packages/tx/src/Account.ts b/packages/tx/src/Account.ts index d04786bf2c..d4cb64fc25 100644 --- a/packages/tx/src/Account.ts +++ b/packages/tx/src/Account.ts @@ -1,4 +1,4 @@ -import { AnomaClient } from "@anoma/wasm"; +import { AnomaClient } from "@anoma/shared"; import { Tokens } from "@anoma/tx"; class Account { diff --git a/packages/tx/src/IBCTransfer.ts b/packages/tx/src/IBCTransfer.ts index ee2accce66..9703dcb725 100644 --- a/packages/tx/src/IBCTransfer.ts +++ b/packages/tx/src/IBCTransfer.ts @@ -1,4 +1,4 @@ -import { AnomaClient } from "@anoma/wasm"; +import { AnomaClient } from "@anoma/shared"; class IBCTransfer { private _client: AnomaClient | undefined; diff --git a/packages/tx/src/Transfer.ts b/packages/tx/src/Transfer.ts index 2c65c8ec4e..1e71fb64b6 100644 --- a/packages/tx/src/Transfer.ts +++ b/packages/tx/src/Transfer.ts @@ -1,5 +1,5 @@ import { amountToMicro } from "@anoma/utils"; -import { AnomaClient } from "@anoma/wasm"; +import { AnomaClient } from "@anoma/shared"; type TransactionData = { source: string; diff --git a/packages/wallet/package.json b/packages/wallet/package.json index edd1d418c0..7de4462e99 100644 --- a/packages/wallet/package.json +++ b/packages/wallet/package.json @@ -16,7 +16,7 @@ }, "dependencies": { "@anoma/tx": "0.1.0", - "@anoma/wasm": "0.1.0", + "@anoma/shared": "0.1.0", "@cosmjs/encoding": "^0.27.1", "typescript": "^4.7.4" }, diff --git a/packages/wallet/src/Wallet.test.ts b/packages/wallet/src/Wallet.test.ts index 5e1ba55296..4335c52e25 100644 --- a/packages/wallet/src/Wallet.test.ts +++ b/packages/wallet/src/Wallet.test.ts @@ -2,7 +2,7 @@ import { fromHex, toHex } from "@cosmjs/encoding"; import fetchMock, { enableFetchMocks } from "jest-fetch-mock"; import { Tokens } from "@anoma/tx"; import Wallet from "./Wallet"; -import { AnomaClient } from "@anoma/wasm"; +import { AnomaClient } from "@anoma/shared"; enableFetchMocks(); diff --git a/packages/wallet/src/Wallet.ts b/packages/wallet/src/Wallet.ts index d87b59a8e9..c8d413503e 100644 --- a/packages/wallet/src/Wallet.ts +++ b/packages/wallet/src/Wallet.ts @@ -6,7 +6,7 @@ import { Result, ResultType, Wallet as WalletType, -} from "@anoma/wasm"; +} from "@anoma/shared"; type Encoding = "hex" | "base58" | null; diff --git a/scripts/build-test.sh b/scripts/build-test.sh index 2c5b2149af..b670e86167 100755 --- a/scripts/build-test.sh +++ b/scripts/build-test.sh @@ -2,4 +2,4 @@ SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd -P) -cd $SCRIPT_DIR/../packages/wasm && yarn wasm:build:node +cd $SCRIPT_DIR/../packages/shared && yarn wasm:build:node diff --git a/scripts/build.sh b/scripts/build.sh index e3eb4e625c..42ea719d9d 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -2,4 +2,4 @@ SCRIPT_DIR=$(cd "$(dirname "$0")"; pwd -P) -cd $SCRIPT_DIR/../packages/wasm && yarn wasm:build +cd $SCRIPT_DIR/../packages/shared && yarn wasm:build