An aggregate wallet for Peerpiper, made from the following WebAssembly Components:
seed-keeper-wit
- To manage the 32 bytes seedseed-keeper-wit-ui
- User Interface Enginedelano-wallet
- Delegatable Anonymous Credentialsdelano-wit-ui
- Delano User Interface Engine
Future:
recrypted
- Transform re-encryption
This crate is an aggregate of guest WIT components. Each guest needs to be added. Below are the steps to add a new guest.
The Wallet architecture makes it safe and easy to use other people's code, due to the sandboxing of WebAssembly. Thus, the code you want to use is likely in someone else's repository. We need their:
- *.wasm binary, and;
- *.wit file
This crates uses git submodules to link to those external repos so we can build from their source and link to their Wasm Interfaces (WIT).
To clone this repo and the submodules use:
git clone --recurse-submodules
If you already cloned the project and forgot --recurse-submodules
, you can combine the git submodule init
and git submodule update
steps by running git submodule update --init
. To also initialize, fetch and checkout any nested submodules, you can use the foolproof git submodule update --init --recursive
.
If the source repo changed, you can always update the submodules to the latest commit with:
git submodule update --remote
If you want to add even more functionality to the wallet, you can add a new guest.
If we wanted to add the delanocreds
repo as a submodule, in the root of the workspace, run:
git submodule add https://github.com/DougAnderson444/delanocreds.git submodules/delanocreds
In order to run tests on our aggregate we have made symlinks to their .wit
files in our ./wit/deps
folder. In order to avoid copy-pasting, we can instead symlink the files like this:
cd wit/deps
ln -s ../../../../../submodules/seed-keeper/crates/seed-keeper-wit-ui/wit/index.wit
Ensure that the submodules are built:
cargo component build --manifest-path=submodules/seed-keeper/Cargo.toml --workspace --release
cargo component build --manifest-path=submodules/delanocreds/crates/delano-wallet/Cargo.toml --release
cargo component build --manifest-path=submodules/delanocreds/crates/delano-wit-ui/Cargo.toml --release
That will makes the *.wasm
files available to the config.yml
so we can compose them together.
Next build the wallet itself:
cd crates/peerpiper-wallet
cargo component build --release
Then use wasm-tools
to compose
the dependencies into an aggregate wallet, run:
# from workspace root dir
wasm-tools compose --config crates/peerpiper-wallet/config.yml -o dist/peerpiper_wallet_aggregate.wasm target/wasm32-wasi/release/peerpiper_wallet.wasm
All of the commands above are saved into a justfile
in the workspace root so you can run them with the compose
recipe:
just compose
Now the PeerPiper wallet is built and composed, and can be used from a Host client, such as the example app:
cd examples/svelte-app
npm run build
npm run preview -- --open
The Protocol is to use Base64 URL unpadded strings for bytes arrays.
When passing byte arrays between WebAssembly and JavaScript (and back!) there is a conversion issue between plain Arrays and TypedArrays. To avoid this issue, we convert the byte array to a base64 URL unpadded string. The reason we use Base64Url is so that data can be passed via URL, see RFC 4648.