From 3c6d8e20d87616af297bd8a9c45ddb9ae8540830 Mon Sep 17 00:00:00 2001
From: Piotr Roslaniec
Date: Thu, 4 Jan 2024 17:28:54 +0100
Subject: [PATCH] update snap docs
---
docs/_config.yml | 26 +++++-
docs/assets/images/aleph-zero-logo.png | Bin 0 -> 3987 bytes
docs/assets/images/favicon.svg | 1 +
docs/index.md | 35 ++++----
docs/integration.md | 97 +++++++++++++++++++++
docs/security.md | 24 ++++++
docs/snap.md | 113 +++++++++++++++++++++++++
7 files changed, 272 insertions(+), 24 deletions(-)
create mode 100644 docs/assets/images/aleph-zero-logo.png
create mode 100644 docs/assets/images/favicon.svg
create mode 100644 docs/integration.md
create mode 100644 docs/security.md
create mode 100644 docs/snap.md
diff --git a/docs/_config.yml b/docs/_config.yml
index faa6eaa..1df26f2 100644
--- a/docs/_config.yml
+++ b/docs/_config.yml
@@ -1,8 +1,26 @@
-title: Just the Docs Template
-description: A starter template for a Jeykll site using the Just the Docs theme!
+title: Aleph Zero Wallet Documentation
+description: Aleph Zero Wallet is a MetaMask snap for Aleph Zero blockchain.
theme: just-the-docs
-url: https://just-the-docs.github.io
+url: https://test.azero.dev
aux_links:
- Template Repository: https://github.com/just-the-docs/just-the-docs-template
+ Source Repository: https://github.com/bide-dev/azero-wallet
+
+logo: "/assets/images/aleph-zero-logo.png"
+favicon_ico: "/assets/images/favicon.svg"
+
+mermaid:
+ # Version of mermaid library
+ # Pick an available version from https://cdn.jsdelivr.net/npm/mermaid/
+ version: "9.1.3"
+
+heading_anchors: true
+
+# Footer "Edit this page on GitHub" link text
+gh_edit_link: true
+gh_edit_link_text: "Edit this page on GitHub."
+gh_edit_repository: "https://github.com/bide-dev/azero-wallet"
+gh_edit_branch: "main" # the branch that your docs is served from
+gh_edit_source: docs
+gh_edit_view_mode: "edit"
diff --git a/docs/assets/images/aleph-zero-logo.png b/docs/assets/images/aleph-zero-logo.png
new file mode 100644
index 0000000000000000000000000000000000000000..c4e998c32cf1a97ae83f180f7144f4a6ba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Zb|bQ)yRI#gFR
zbs;X8y5*ELAydwxw(6M)aYC*CCL9HsumzP>&qWX?jNCk31xS?qJ)>k3(eihYXt~m+
z>H0vN-kG|ZpffUBUI3Wtk07!njF$g
tN}8m$JQL^_^{={X1D|yd{6
\ No newline at end of file
diff --git a/docs/index.md b/docs/index.md
index ca0c545..9751c83 100644
--- a/docs/index.md
+++ b/docs/index.md
@@ -1,35 +1,30 @@
---
title: Home
layout: home
+nav_order: 0
---
-This is a *bare-minimum* template to create a Jekyll site that uses the [Just the Docs] theme. You can easily set the created site to be published on [GitHub Pages] – the [README] file explains how to do that, along with other details.
+# Azero Wallet snap
-If [Jekyll] is installed on your computer, you can also build and preview the created site *locally*. This lets you test changes before committing them, and avoids waiting for GitHub Pages.[^1] And you will be able to deploy your local build to a different platform than GitHub Pages.
+This documentation explains how to use Aleph Zero Wallet snap, or `azero-wallet`. In order to use the snap on the Aleph
+Zero network, visit [azero.dev][azero-dev].
-More specifically, the created site:
+To understand how the snap works and it's limitations, visit the [snap documentation](/snap).
-- uses a gem-based approach, i.e. uses a `Gemfile` and loads the `just-the-docs` gem
-- uses the [GitHub Pages / Actions workflow] to build and publish the site on GitHub Pages
+If you're interested in integrating the snap into your web app, see the [integration documentation](/integration).
-Other than that, you're free to customize sites that you create with this template, however you like. You can easily change the versions of `just-the-docs` and Jekyll it uses, as well as adding further plugins.
+## Learn more
-[Browse our documentation][Just the Docs] to learn more about how to use this theme.
+- You can learn more about Aleph Zero [here][Aleph Zero docs].
+- You can see a live demo of the snap [here][live demo].
+- To learn more about MetaMask snaps, see the [MetaMask snap documentation][MetaMask snap documentations].
-To get started with creating a site, simply:
-
-1. click "[use this template]" to create a GitHub repository
-2. go to Settings > Pages > Build and deployment > Source, and select GitHub Actions
+----
-If you want to maintain your docs in the `docs` directory of an existing project repo, see [Hosting your docs from an existing project repo](https://github.com/just-the-docs/just-the-docs-template/blob/main/README.md#hosting-your-docs-from-an-existing-project-repo) in the template README.
+[azero-dev]: https://azero.dev
-----
+[Aleph Zero docs]: https://docs.alephzero.org/aleph-zero/
-[^1]: [It can take up to 10 minutes for changes to your site to publish after you push the changes to GitHub](https://docs.github.com/en/pages/setting-up-a-github-pages-site-with-jekyll/creating-a-github-pages-site-with-jekyll#creating-your-site).
+[live demo]: https://azero-snap.netlify.app/
-[Just the Docs]: https://just-the-docs.github.io/just-the-docs/
-[GitHub Pages]: https://docs.github.com/en/pages
-[README]: https://github.com/just-the-docs/just-the-docs-template/blob/main/README.md
-[Jekyll]: https://jekyllrb.com
-[GitHub Pages / Actions workflow]: https://github.blog/changelog/2022-07-27-github-pages-custom-github-actions-workflows-beta/
-[use this template]: https://github.com/just-the-docs/just-the-docs-template/generate
+[MetaMask snap documentations]: https://docs.metamask.io/guide/snap.html
diff --git a/docs/integration.md b/docs/integration.md
new file mode 100644
index 0000000..e0791c5
--- /dev/null
+++ b/docs/integration.md
@@ -0,0 +1,97 @@
+---
+layout: default
+title: Integration Guide
+nav_order: 4
+---
+
+# Integration guide
+
+This document outlines the step-by-step process of integrating `azero-wallet` into a web app using React.
+
+Aleph Zero Snap consists of three packages:
+
+- [azero-wallet-snap]: The core snap functionality.
+- [azero-wallet-adapter]: A wrapper to facilitate interaction with the snap API.
+- [azero-wallet-types]: TypeScript types shared by the snap and snap API.
+
+As a developer who wants to integrate the snap into a web app, you will primarily be interested
+in `azero-wallet-adapter` and `azero-wallet-types` packages.
+
+## Integration using `azero-wallet-adapter`
+
+While direct integration with `azero-wallet` is possible, using [azero-wallet-adapter] is recommended for ease and
+efficiency. This package contains the API methods exposed by the snap.
+
+### Installation
+
+```bash
+npm install azero-wallet-adapter
+```
+
+### Usage
+
+Below we outline the usage of the `azero-wallet-adapter` package. For a complete list of methods and their parameters,
+refer to the [API documentation](/snap).
+
+First, we implement the `MetaMaskSnapSigner` class which we'll use to sign transactions in our app. `MetaMaskSnapSigner`
+will connect to (and install, if needed) the snap and sign transactions using the snap API.
+
+```typescript
+import {signSignerPayload} from 'azero-wallet-adapter';
+import {connectSnap} from './snap';
+
+export class MetaMaskSnapSigner {
+ public async signPayload(payload: SignerPayloadJSON): Promise {
+ // Connect to snap
+ await connectSnap();
+
+ // Sign payload
+ const signingResult = await signSignerPayload({payload});
+
+ // Did that work?
+ if (!signingResult.success) {
+ throw new Error(signingResult.error);
+ }
+
+ return {
+ signature: signingResult.data.signature
+ };
+ }
+}
+```
+
+For the `signPayload` method to work, the snap connection must be established. Below is the `connectSnap` function which
+connects to the snap and sets up the RPC URL. Here, we use the public testnet RPC URL.
+
+```typescript
+import * as snap from 'azero-wallet-adapter';
+
+export const connectSnap = async () => {
+ // Actually connect to snap
+ await snap.connect();
+
+ // Set RPC URL - if we skip this part, we will connect to the default RPC URL at https://rpc.azero.dev/
+ await snap.setRpcUrl({rpcUrl: 'https://rpc.test.azero.dev/'});
+
+ // Get account
+ const accountResult = await snap.getAccount();
+
+ // Did that work?
+ if (!accountResult.success) {
+ throw accountResult.error;
+ }
+ const {address} = accountResult.data;
+ console.log(`Connected to snap with account ${address}`);
+};
+```
+
+In this function, `snap.connect()` is used to establish a connection to the snap. The RPC URL is then set
+using `snap.setRpcUrl()`. Lastly, the account is fetched using `snap.getAccount()` and printed.
+
+We see that snap API methods return a `Result` object. This object contains a `success` boolean and either an `error`
+or `data` object. The `data` object contains the result of the API call. The `error` object contains the error message
+if the API call failed.
+
+---
+
+[azero-wallet-adapter]: https://www.npmjs.com/package/azero-wallet-adapter
diff --git a/docs/security.md b/docs/security.md
new file mode 100644
index 0000000..189d721
--- /dev/null
+++ b/docs/security.md
@@ -0,0 +1,24 @@
+---
+layout: default
+title: Security & Support
+nav_order: 5
+---
+
+# Security
+
+## Audit
+
+Aleph Zero Wallet snap has been audited by [Sayfer]. The audit report is available [here][audit report].
+
+## Support and Feedback
+
+If you have any questions or feedback, please reach out to us at [support@bide.dev][support]
+
+
+---
+
+[Sayfer]: https://sayfer.io/audits/metamask-snap-audit-report-for-alephzero/
+
+[audit report]: https://sayfer.io/audits/metamask-snap-audit-report-for-alephzero/
+
+[support]: mailto:support@bide.dev.
diff --git a/docs/snap.md b/docs/snap.md
new file mode 100644
index 0000000..d0a0ce1
--- /dev/null
+++ b/docs/snap.md
@@ -0,0 +1,113 @@
+---
+layout: default
+title: Snap API docs
+nav_order: 3
+---
+
+# Snap API Docs
+
+This document explains how the workings of the snap and it's limitations.
+
+## Account derivation
+
+The snap implements a single Aleph Zero-compatible account. This account is derived automatically and deterministically
+upon the snap startup. This implies a consistent account for a given MetaMask wallet. The deterministic derivation
+eliminates the need for backing up the account seed phrase, just the MetaMask seed phrase is required.
+
+### Limitations
+
+- It's currently not possible to derive multiple accounts from a single MetaMask wallet.
+- Exporting the account from the snap is not possible.
+- Accounts may only be viewed using snap API calls, not from MetaMask interface.
+
+## Snap methods
+
+The snap avails the following methods:
+
+### 1. Get Account Address
+
+The `getAccount` method extracts the account address without needing any additional parameters.
+
+```typescript
+import {getAccount, isSuccess} from 'azero-wallet-adapter';
+
+const result: Result = await getAccount();
+if (isSuccess(result)) {
+ console.log(result.data); // {address: "account address"}
+} else {
+ console.error(result.error);
+}
+```
+
+### 2. Sign and Send Payload
+
+This method sends and signs a payload via the `SignAndSendTransactionRequestParams` type parameters.
+
+```typescript
+import {signAndSendExtrinsicTransactionPayload, SignAndSendTransactionRequestParams, isSuccess}
+ from 'azero-wallet-adapter';
+
+const txParams: SignAndSendTransactionRequestParams = {transaction: /*...*/, payload: /*...*/}
+
+signAndSendExtrinsicTransactionPayload(txParams).then(result => {
+ if (isSuccess(result)) {
+ // handle result transaction
+ } else {
+ // handle error
+ }
+});
+```
+
+### 3. Sign Payload
+
+This method signs a payload without sending it. It uses the `SignSignerPayloadRequestParams`.
+
+```typescript
+import {signSignerPayload, SignSignerPayloadRequestParams, isSuccess} from 'azero-wallet-adapter';
+
+const signParams: SignSignerPayloadRequestParams = {payload: /*...*/};
+
+signSignerPayload(signParams).then(result => {
+ if (isSuccess(result)) {
+ // handle result transaction
+ } else {
+ // handle error
+ }
+});
+```
+
+### 4. Transfer Native Assets
+
+This function transfers native assets using the `TransferNativeAssetRequestParams` type for its parameters.
+
+```typescript
+import {transferNativeAsset, TransferNativeAssetRequestParams, isSuccess} from 'azero-wallet-adapter';
+
+const transferParams: TransferNativeAssetRequestParams = {recipient: /*...*/, amount: /*...*/};
+
+transferNativeAsset(transferParams).then(result => {
+ if (isSuccess(result)) {
+ // handle result transaction
+ } else {
+ // handle error
+ }
+});
+```
+
+### 5. Set the RPC URL
+
+To configure the RPC URL, use the `setRpcUrl` with `SetRpcUrlRequestParams` as its parameters.
+
+```typescript
+import {setRpcUrl, SetRpcUrlRequestParams, isSuccess,} from 'azero-wallet-adapter';
+
+const rpcParams: SetRpcUrlRequestParams = {rpcUrl: 'http://my-rpc-url'};
+
+setRpcUrl(rpcParams).then((result) => {
+ if (isSuccess(result)) {
+ // execute callback after RPC URL is set
+ } else {
+ // handle error
+ }
+});
+```