-
Notifications
You must be signed in to change notification settings - Fork 121
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: set up docs toc, better init function definitions, clean up
- Loading branch information
Showing
12 changed files
with
195 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,110 @@ | ||
# @namada/sdk specs | ||
|
||
TODO: Specs for `@namada/sdk` package | ||
The `@namada/sdk` package is a wrapper library to provides an easy way to integrate with the `@namada/shared` WebAssembly Rust library. | ||
|
||
[API](./api.md) | ||
View the [API](./api.md) docs for specific information on API interfaces. | ||
|
||
## Table of Contents | ||
|
||
- [Basic Usage](#basic-usage) | ||
- [Keys](#keys) | ||
- [Rpc](#rpc) | ||
- [Tx](#tx) | ||
- [Ledger](#ledger) | ||
- [Masp](#masp) | ||
- [Mnemonic](#mnemonic) | ||
- [Signing](#signing) | ||
|
||
## Basic Usage | ||
|
||
The initialization of the `Sdk` must happen asynchronously for web applications. | ||
|
||
In your application, you can initialize the Sdk with the following: | ||
|
||
```typescript | ||
import { Sdk } from "@namada/sdk"; | ||
|
||
async function myApp() { | ||
const rpcUrl = "http://localhost:27657"; | ||
|
||
// You can use deconstruction to access submodules | ||
const { tx, keys, signing, mnemonic, keys } = await Sdk.init(rpcUrl); | ||
|
||
// ..... | ||
} | ||
|
||
myApp(); | ||
``` | ||
|
||
Alternatively, you can import the `initAsync` function, which will also return an instance of the SDK: | ||
|
||
```typescript | ||
import { initAsync } from "@namada/sdk"; | ||
|
||
async function myApp() { | ||
const rpcUrl = "http://localhost:27657"; | ||
const sdk = await initAsync(rpcUrl); | ||
} | ||
|
||
myApp(); | ||
``` | ||
|
||
[ [Table of Contents](#table-of-contents) ] | ||
|
||
## Keys | ||
|
||
This module contains the functionality to generate transparent and shielded keys for Namada. | ||
|
||
More info _TBD_ | ||
|
||
[ [Table of Contents](#table-of-contents) ] | ||
|
||
## Rpc | ||
|
||
This module contains RPC queries for interacting with the chain, as well as Tx broadcasting. | ||
|
||
More info _TBD_ | ||
|
||
[ [Table of Contents](#table-of-contents) ] | ||
|
||
## Tx | ||
|
||
This module contains functionality for building and signing transactions. | ||
|
||
More info _TBD_ | ||
|
||
[ [Table of Contents](#table-of-contents) ] | ||
|
||
## Ledger | ||
|
||
This class provides functionality for interacting with `NamadaApp` for the Ledger Hardware Wallet. | ||
|
||
More info _TBD_ | ||
|
||
[ [Table of Contents](#table-of-contents) ] | ||
|
||
## Masp | ||
|
||
This module provides a few basic utilities for handling `Masp` params, as well as adding spending keys to the | ||
wallet context. | ||
|
||
More info _TBD_ | ||
|
||
[ [Table of Contents](#table-of-contents) ] | ||
|
||
## Mnemonic | ||
|
||
This provides basic funcitonality for generating 12 or 24 word mnemonics, validating mnemonics, and generating | ||
seeds from mnemonics. | ||
|
||
More info _TBD_ | ||
|
||
[ [Table of Contents](#table-of-contents) ] | ||
|
||
## Signing | ||
|
||
This class provides the functionality from our Rust library for signing and verifying arbitrary data. | ||
|
||
More info _TBD_ | ||
|
||
[ [Table of Contents](#table-of-contents) ] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { Query as QueryWasm, Sdk as SdkWasm } from "@namada/shared"; | ||
import { Sdk } from "./sdk"; | ||
|
||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const cryptoMemory = require("@namada/crypto").__wasm.memory; | ||
|
||
/** | ||
* Initialize SDK for Node JS environments | ||
* @param {string} url | ||
* @param {string} nativeToken | ||
* @returns {Sdk} | ||
*/ | ||
export default function initSync(url: string, nativeToken: string): Sdk { | ||
const sdk = new SdkWasm(url, nativeToken); | ||
const query = new QueryWasm(url); | ||
return new Sdk(sdk, query, cryptoMemory, url, nativeToken); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,8 @@ | ||
import { Query as QueryWasm, Sdk as SdkWasm } from "@namada/shared"; | ||
import initSync from "initSync"; | ||
import { Sdk } from "../sdk"; | ||
import { NATIVE_TOKEN as nativeToken, RPC_URL as rpcUrl } from "./data"; | ||
|
||
/* eslint-disable @typescript-eslint/no-var-requires */ | ||
const cryptoMemory = require("@namada/crypto").__wasm.memory; | ||
|
||
export const initSdk = async (): Promise<Sdk> => { | ||
const sdk = new SdkWasm(rpcUrl, nativeToken); | ||
const query = new QueryWasm(rpcUrl); | ||
|
||
return new Sdk(sdk, query, cryptoMemory, rpcUrl, nativeToken); | ||
// Simplified wrapper to handle initializing SDK for tests | ||
export const initSdk = (): Sdk => { | ||
return initSync(rpcUrl, nativeToken); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,24 @@ | ||
import { PhraseSize } from "@namada/crypto"; | ||
import { MNEMONIC_1 as mnemonic1 } from "./data"; | ||
import { initSdk } from "./initSdk"; | ||
|
||
describe("mnemonic", () => { | ||
it("should generate a 12 word mnemonic phrase", async () => { | ||
const { mnemonic } = await initSdk(); | ||
const { mnemonic } = initSdk(); | ||
const words = await mnemonic.generate(); | ||
expect(words.length).toEqual(12); | ||
}); | ||
|
||
it("should generate a 24 word mnemonic phrase", async () => { | ||
const { mnemonic } = await initSdk(); | ||
const { mnemonic } = initSdk(); | ||
const words = await mnemonic.generate(PhraseSize.N24); | ||
expect(words.length).toEqual(24); | ||
}); | ||
|
||
it("should generate a seed from mnemonic", () => { | ||
const { mnemonic } = initSdk(); | ||
const seed = mnemonic.toSeed(mnemonic1); | ||
expect(seed).toBeDefined(); | ||
expect(seed.length).toEqual(64); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters