Skip to content

Commit

Permalink
docs/1476: Keychain: Update Firefox docs (#1477)
Browse files Browse the repository at this point in the history
* docs: update docs, remove problematic flag from Dockerfile

* fix: add dependency to fix wasm-opt error during docker build

* fix: don't export wasm-bindgen mnemonic size enum

* fix: fix tests

* fix: revert minification setting
  • Loading branch information
jurevans authored Jan 8, 2025
1 parent 2892467 commit 7168683
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 29 deletions.
46 changes: 45 additions & 1 deletion apps/extension/FIREFOX_README.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ exactly as they are described below.

**NOTE** The add-on submission was built in the following environment:

- Ubuntu Server 24.04 LTS **x86_64** - Please ensure your environment matches this to produce an identical build!
- Ubuntu Desktop 24.04 LTS **ARM64** - Please ensure your environment matches this to produce an identical build!
- Docker version 27.x

Follow these instructions to build with Docker:
Expand Down Expand Up @@ -47,6 +47,50 @@ docker run --rm -v ./apps/extension/build:/shared namada-keychain-firefox cp -r

If Docker is not currently installed in your environment, please refer to the [instructions of the official Docker documentation](https://docs.docker.com/engine/install/ubuntu/).

The steps we took to install Docker on Ubuntu Desktop 24.04 ARM64 are as follows:

1. Remove any pre-existing Docker-related packages:

```bash
for pkg in docker.io docker-doc docker-compose docker-compose-v2 podman-docker containerd runc; do sudo apt-get remove $pkg; done
```

2. Setup Docker repository and install keyring

```bash
# Add Docker's official GPG key:
sudo apt-get update
sudo apt-get install ca-certificates curl
sudo install -m 0755 -d /etc/apt/keyrings
sudo curl -fsSL https://download.docker.com/linux/ubuntu/gpg -o /etc/apt/keyrings/docker.asc
sudo chmod a+r /etc/apt/keyrings/docker.asc

# Add the repository to Apt sources:
echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.asc] https://download.docker.com/linux/ubuntu \
$(. /etc/os-release && echo "$VERSION_CODENAME") stable" | \
sudo tee /etc/apt/sources.list.d/docker.list > /dev/null
sudo apt-get update
```

3. Install Docker packages:

```bash
sudo apt-get install docker-ce docker-ce-cli containerd.io docker-buildx-plugin docker-compose-plugin
```

4. Post-install - Add `docker` group to user:

```bash
# If docker group doesn't currently exist:
sudo groupadd docker

# Add current user to docker group:
sudo usermod -aG docker $USER
```

5. Log out, then log back in for group to take effect! This is to ensure that you don't need to run our Docker commands as root via `sudo`.

[ [Table of Contents](#table-of-contents) ]

### Source code
Expand Down
1 change: 0 additions & 1 deletion apps/extension/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ module.exports = {
warningsFilter: [/dependency between chunks.+wasm-bindgen-rayon/],
},
optimization: {
minimize: false,
moduleIds: "deterministic", // Ensures consistent module IDs
chunkIds: "deterministic", // Ensures consistent chunk IDs
},
Expand Down
4 changes: 2 additions & 2 deletions docker/extension/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM --platform=linux/amd64 rust:1.79 AS builder
FROM --platform=linux/arm64 rust:1.79 AS builder

WORKDIR /app

# Installing required packages
RUN apt update && apt install -y nodejs npm clang pkg-config libssl-dev protobuf-compiler curl
RUN apt update && apt install -y nodejs npm clang pkg-config libssl-dev protobuf-compiler curl binaryen
RUN npm install -g yarn
RUN rustup target add wasm32-unknown-unknown
RUN curl https://rustwasm.github.io/wasm-pack/installer/init.sh -sSf | sh -s -- -y
Expand Down
26 changes: 11 additions & 15 deletions packages/crypto/lib/src/crypto/bip39.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,8 @@ use zeroize::Zeroize;
pub enum Bip39Error {
#[error("Invalid phrase")]
InvalidPhrase,
}

#[wasm_bindgen]
#[derive(Copy, Clone)]
pub enum PhraseSize {
N12 = 12,
N24 = 24,
#[error("Invalid phrase size! Must be 12 or 24!")]
InvalidPhraseSize,
}

#[wasm_bindgen]
Expand All @@ -27,15 +22,16 @@ pub struct Mnemonic {
#[wasm_bindgen]
impl Mnemonic {
#[wasm_bindgen(constructor)]
pub fn new(size: PhraseSize) -> Mnemonic {
pub fn new(size: u8) -> Result<Mnemonic, String> {
let mnemonic_type = match size {
PhraseSize::N12 => MnemonicType::Words12,
PhraseSize::N24 => MnemonicType::Words24,
12 => MnemonicType::Words12,
24 => MnemonicType::Words24,
_ => return Err(Bip39Error::InvalidPhraseSize.to_string()),
};

let mnemonic = M::new(mnemonic_type, Language::English);

Mnemonic { mnemonic }
Ok(Mnemonic { mnemonic })
}

pub fn validate(phrase: &str) -> bool {
Expand Down Expand Up @@ -88,13 +84,13 @@ mod tests {

#[wasm_bindgen_test]
fn can_generate_mnemonic_from_size() {
let mnemonic = Mnemonic::new(PhraseSize::N12);
let mnemonic = Mnemonic::new(12).unwrap();
let phrase = mnemonic.phrase();
let words: Vec<&str> = phrase.split(' ').collect();

assert_eq!(words.iter().len(), 12);

let mnemonic = Mnemonic::new(PhraseSize::N24);
let mnemonic = Mnemonic::new(24).unwrap();
let phrase = mnemonic.phrase();
let words: Vec<&str> = phrase.split(' ').collect();

Expand Down Expand Up @@ -141,14 +137,14 @@ mod tests {

#[wasm_bindgen_test]
fn can_generate_word_list_from_mnemonic() {
let mnemonic = Mnemonic::new(PhraseSize::N12);
let mnemonic = Mnemonic::new(12).unwrap();
let words = mnemonic
.to_words()
.expect("Should return a VecStringPointer containing the words");

assert_eq!(words.strings.len(), 12);

let mnemonic = Mnemonic::new(PhraseSize::N24);
let mnemonic = Mnemonic::new(24).unwrap();
let words = mnemonic
.to_words()
.expect("Should return a VecStringPointer containing the words");
Expand Down
9 changes: 4 additions & 5 deletions packages/crypto/src/__tests__/crypto.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import {
ByteSize,
HDWallet,
Mnemonic,
PhraseSize,
Rng,
Salt,
ShieldedHDWallet,
Expand Down Expand Up @@ -41,20 +40,20 @@ const MNEMONIC_WORDS = [

describe("Mnemonic", () => {
test("It should return the correct number of words", () => {
let mnemonic = new Mnemonic(PhraseSize.N12);
let mnemonic = new Mnemonic(12);
let words = readVecStringPointer(mnemonic?.to_words(), memory);
expect(words.length).toBe(12);

mnemonic = new Mnemonic(PhraseSize.N24);
mnemonic = new Mnemonic(24);
words = readVecStringPointer(mnemonic.to_words(), memory);

expect(words.length).toBe(24);
});

test("It should return a seed with a valid length", () => {
const mnemonic12 = new Mnemonic(PhraseSize.N12);
const mnemonic12 = new Mnemonic(12);
const seed = mnemonic12.to_seed();
const mnemonic24 = new Mnemonic(PhraseSize.N24);
const mnemonic24 = new Mnemonic(24);
const seed2 = mnemonic24.to_seed();

expect(seed.length).toBe(SEED_LENGTH);
Expand Down
6 changes: 4 additions & 2 deletions packages/sdk/src/mnemonic.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import {
Mnemonic as MnemonicWasm,
PhraseSize,
StringPointer,
readVecStringPointer,
readVecU8Pointer,
} from "@namada/crypto";

export { PhraseSize } from "@namada/crypto";
export enum PhraseSize {
N12 = 12,
N24 = 24,
}

/**
* Class for accessing mnemonic functionality from wasm
Expand Down
6 changes: 3 additions & 3 deletions packages/sdk/src/tests/mnemonic.test.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { PhraseSize } from "@namada/crypto";
import { PhraseSize } from "mnemonic";
import { MNEMONIC_1 as mnemonic1 } from "./data";
import { initSdk } from "./initSdk";

describe("mnemonic", () => {
it("should generate a 12 word mnemonic phrase", async () => {
const { mnemonic } = initSdk();
const words = await mnemonic.generate();
const words = mnemonic.generate();
expect(words.length).toEqual(12);
});

it("should generate a 24 word mnemonic phrase", async () => {
const { mnemonic } = initSdk();
const words = await mnemonic.generate(PhraseSize.N24);
const words = mnemonic.generate(PhraseSize.N24);
expect(words.length).toEqual(24);
});

Expand Down

1 comment on commit 7168683

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.