code style, let to const

This commit is contained in:
stjet
2024-06-30 19:36:19 +00:00
parent d9fa4dee0d
commit 9086c544aa
76 changed files with 413 additions and 380 deletions

View File

@@ -14,6 +14,7 @@ npm install banani
```
Embedding in the browser is easy to - just download and add `banani-browser.js` to your website:
```html
<script src="/path/to/banani-browser.js"></script>
```
@@ -21,23 +22,25 @@ Embedding in the browser is easy to - just download and add `banani-browser.js`
Take a look in `browser_test/index.html` for an example.
## Documentation
The docs are hosted at https://banani.prussia.dev (can also be accessed at https://stjet.github.io/banani/).
## Examples
Banani allows you to send, receive, and change representative. If you are using Banani on the web, replace `banani` with `window.banani`.
```js
let rpc = new banani.RPC("https://kaliumapi.appditto.com/api");
const rpc = new banani.RPC("https://kaliumapi.appditto.com/api");
console.log(await rpc.get_block_count());
let wallet = new banani.Wallet(rpc, process.env.seed);
const wallet = new banani.Wallet(rpc, process.env.seed);
let zero_index_address = wallet.address;
const zero_index_address = wallet.address;
wallet.index = 1;
let send_hash = await wallet.send(zero_index_address, "1"); //send 1 banano
const send_hash = await wallet.send(zero_index_address, "1"); //send 1 banano
wallet.index = 0;
@@ -47,15 +50,17 @@ await wallet.change_rep("placeholder");
```
Banani also comes with some useful utilities, and message signing:
```js
let rpc = new banani.RPC("https://kaliumapi.appditto.com/api");
let random_wallet = banani.Wallet.gen_random_wallet(rpc);
const rpc = new banani.RPC("https://kaliumapi.appditto.com/api");
const random_wallet = banani.Wallet.gen_random_wallet(rpc);
console.log(banani.whole_to_raw("4.20069") === 420069000000000000000000000000n);
console.log(random_wallet.sign_message("test message\ntest test"));
```
## Contributing
```
git clone https://github.com/stjet/banani.git
cd banani
@@ -70,18 +75,22 @@ Then commit and push your changes.
In most cases, you will only need to touch the typescript (`.ts`) files.
## Work Generation
Though Kalium's public work will generate work for you, it is suggested that you generate your own work for the following reasons:
- it is relatively "easy" (in terms of computation) to do
- if Boompow goes offline (as it has done in the past), many Banano services will go down, which is not great for users and is not a very decentralized or resilient way to make your thing
Unrelated, do remember that Nano has harder work thresholds than Banano.
## Using for Nano instead of Banano
The main differences between Nano and Banano; or at least those relevant to a library like this, are the different amount of decimals. So, when creating a `Wallet` with banani, make sure to do `my_rpc.DECIMALS = 31` otherwise your sends will be off by two magnitudes which is bad.
Also, a different preamble should be used for message signing.
## Dependencies
Banani has two external dependencies, tweetnacl and blake2b. Blake2b probably has its own dependencies, but I haven't checked.
Tweetnacl is not listed as a dependency in the package.json because it has been modified to use blake2b for the hashing algorithm. So, a modified version of it is distributed directly along with the package (see `tweetnacl_mod.js`). Clone the repo and run `npm run cryptodiff` to see the changes made from regular tweetnacl.
@@ -89,6 +98,6 @@ Tweetnacl is not listed as a dependency in the package.json because it has been
Banani also has many dev dependencies for contributing/developing the package (see the "Contributing" section), but they are not needed for regular users of the package.
## Todo
- More extensive testing
- Example work generating function