Files
banani/docs/index.html
2024-06-28 03:46:43 +00:00

39 lines
16 KiB
HTML

<!DOCTYPE html><html class="default" lang="en"><head><meta charSet="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>banani</title><meta name="description" content="Documentation for banani"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><div class="table-cell" id="tsd-search" data-base="."><div class="field"><label for="tsd-search-field" class="tsd-widget tsd-toolbar-icon search no-caption"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-search"></use></svg></label><input type="text" id="tsd-search-field" aria-label="Search"/></div><div class="field"><div id="tsd-toolbar-links"></div></div><ul class="results"><li class="state loading">Preparing search index...</li><li class="state failure">The search index is not available</li></ul><a href="index.html" class="title">banani</a></div><div class="table-cell" id="tsd-widgets"><a href="#" class="tsd-widget tsd-toolbar-icon menu no-caption" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><h2>banani</h2></div><div class="tsd-panel tsd-typography"><a id="md:banani" class="tsd-anchor"></a><h1><a href="#md:banani">Banani</a></h1><blockquote>
<p><del>how to buy banani from beatrice</del>
how to install banani on react.js</p>
</blockquote>
<p>Banani is a library for the Banano cryptocurrency that will support sending, receiving, changing rep, RPC calls, message signing, wallet management, etc. It aims to be a more powerful and sensible version of @bananocoin/bananojs. Banani takes heavy inspiration from the Python <a href="https://github.com/stjet/bananopie">bananopie</a> (which I also wrote), which in turn takes some inspiration from my experiences with ethers.js.</p>
<p><strong>Please report any bugs or request features by opening an Github issue.</strong> You can ask for help or ask questions in the #frankensteins-lab channel of the Banano discord and people will be typically be eager to assist if they can.</p>
<a id="md:installing" class="tsd-anchor"></a><h2><a href="#md:installing">Installing</a></h2><pre><code><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-0">install</span><span class="hl-1"> </span><span class="hl-0">banani</span>
</code><button>Copy</button></pre>
<p>Embedding in the browser is easy to - just download and add <code>banani-browser.js</code> to your website:</p>
<pre><code class="language-html"><span class="hl-2">&lt;</span><span class="hl-3">script</span><span class="hl-4"> </span><span class="hl-5">src</span><span class="hl-4">=</span><span class="hl-6">&quot;/path/to/banani-browser.js&quot;</span><span class="hl-2">&gt;&lt;/</span><span class="hl-3">script</span><span class="hl-2">&gt;</span>
</code><button>Copy</button></pre>
<p>Take a look in <code>browser_test/index.html</code> for an example.</p>
<a id="md:documentation" class="tsd-anchor"></a><h2><a href="#md:documentation">Documentation</a></h2><p>The docs are hosted at <a href="https://banani.prussia.dev">https://banani.prussia.dev</a> (can also be accessed at <a href="https://stjet.github.io/banani/">https://stjet.github.io/banani/</a>).</p>
<a id="md:examples" class="tsd-anchor"></a><h2><a href="#md:examples">Examples</a></h2><p>Banani allows you to send, receive, and change representative. If you are using Banani on the web, replace <code>banani</code> with <code>window.banani</code>.</p>
<pre><code class="language-js"><span class="hl-7">let</span><span class="hl-1"> </span><span class="hl-0">rpc</span><span class="hl-1"> = </span><span class="hl-7">new</span><span class="hl-1"> </span><span class="hl-0">banani</span><span class="hl-1">.</span><span class="hl-8">RPC</span><span class="hl-1">(</span><span class="hl-9">&quot;https://kaliumapi.appditto.com/api&quot;</span><span class="hl-1">);</span><br/><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-8">log</span><span class="hl-1">(</span><span class="hl-10">await</span><span class="hl-1"> </span><span class="hl-0">rpc</span><span class="hl-1">.</span><span class="hl-8">get_block_count</span><span class="hl-1">());</span><br/><br/><span class="hl-7">let</span><span class="hl-1"> </span><span class="hl-0">wallet</span><span class="hl-1"> = </span><span class="hl-7">new</span><span class="hl-1"> </span><span class="hl-0">banani</span><span class="hl-1">.</span><span class="hl-8">Wallet</span><span class="hl-1">(</span><span class="hl-0">rpc</span><span class="hl-1">, </span><span class="hl-0">process</span><span class="hl-1">.</span><span class="hl-0">env</span><span class="hl-1">.</span><span class="hl-0">seed</span><span class="hl-1">);</span><br/><br/><span class="hl-7">let</span><span class="hl-1"> </span><span class="hl-0">zero_index_address</span><span class="hl-1"> = </span><span class="hl-0">wallet</span><span class="hl-1">.</span><span class="hl-0">address</span><span class="hl-1">;</span><br/><br/><span class="hl-0">wallet</span><span class="hl-1">.</span><span class="hl-0">index</span><span class="hl-1"> = </span><span class="hl-11">1</span><span class="hl-1">;</span><br/><br/><span class="hl-7">let</span><span class="hl-1"> </span><span class="hl-0">send_hash</span><span class="hl-1"> = </span><span class="hl-10">await</span><span class="hl-1"> </span><span class="hl-0">wallet</span><span class="hl-1">.</span><span class="hl-8">send</span><span class="hl-1">(</span><span class="hl-0">zero_index_address</span><span class="hl-1">, </span><span class="hl-9">&quot;1&quot;</span><span class="hl-1">); </span><span class="hl-12">//send 1 banano</span><br/><br/><span class="hl-0">wallet</span><span class="hl-1">.</span><span class="hl-0">index</span><span class="hl-1"> = </span><span class="hl-11">0</span><span class="hl-1">;</span><br/><br/><span class="hl-10">await</span><span class="hl-1"> </span><span class="hl-0">wallet</span><span class="hl-1">.</span><span class="hl-8">receive</span><span class="hl-1">(</span><span class="hl-0">send_hash</span><span class="hl-1">); </span><span class="hl-12">//receive the bananos we just send (can also do `await wallet.receive_all()`)</span><br/><br/><span class="hl-10">await</span><span class="hl-1"> </span><span class="hl-0">wallet</span><span class="hl-1">.</span><span class="hl-8">change_rep</span><span class="hl-1">(</span><span class="hl-9">&quot;placeholder&quot;</span><span class="hl-1">);</span>
</code><button>Copy</button></pre>
<p>Banani also comes with some useful utilities, and message signing:</p>
<pre><code class="language-js"><span class="hl-7">let</span><span class="hl-1"> </span><span class="hl-0">rpc</span><span class="hl-1"> = </span><span class="hl-7">new</span><span class="hl-1"> </span><span class="hl-0">banani</span><span class="hl-1">.</span><span class="hl-8">RPC</span><span class="hl-1">(</span><span class="hl-9">&quot;https://kaliumapi.appditto.com/api&quot;</span><span class="hl-1">);</span><br/><span class="hl-7">let</span><span class="hl-1"> </span><span class="hl-0">random_wallet</span><span class="hl-1"> = </span><span class="hl-0">banani</span><span class="hl-1">.</span><span class="hl-0">Wallet</span><span class="hl-1">.</span><span class="hl-8">gen_random_wallet</span><span class="hl-1">(</span><span class="hl-0">rpc</span><span class="hl-1">);</span><br/><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-8">log</span><span class="hl-1">(</span><span class="hl-0">banani</span><span class="hl-1">.</span><span class="hl-8">whole_to_raw</span><span class="hl-1">(</span><span class="hl-9">&quot;4.20069&quot;</span><span class="hl-1">) === </span><span class="hl-11">420069000000000000000000000000</span><span class="hl-7">n</span><span class="hl-1">);</span><br/><span class="hl-0">console</span><span class="hl-1">.</span><span class="hl-8">log</span><span class="hl-1">(</span><span class="hl-0">random_wallet</span><span class="hl-1">.</span><span class="hl-8">sign_message</span><span class="hl-1">(</span><span class="hl-9">&quot;test message</span><span class="hl-13">\n</span><span class="hl-9">test test&quot;</span><span class="hl-1">));</span>
</code><button>Copy</button></pre>
<a id="md:contributing" class="tsd-anchor"></a><h2><a href="#md:contributing">Contributing</a></h2><pre><code><span class="hl-0">git</span><span class="hl-1"> </span><span class="hl-0">clone</span><span class="hl-1"> </span><span class="hl-14">https</span><span class="hl-1">:</span><span class="hl-12">//github.com/stjet/banani.git</span><br/><span class="hl-0">cd</span><span class="hl-1"> </span><span class="hl-0">banani</span><br/><span class="hl-1">...</span><br/><span class="hl-1">&lt;</span><span class="hl-0">make</span><span class="hl-1"> </span><span class="hl-0">your</span><span class="hl-1"> </span><span class="hl-0">changes</span><span class="hl-1"> </span><span class="hl-10">with</span><span class="hl-1"> </span><span class="hl-0">your</span><span class="hl-1"> </span><span class="hl-0">favourite</span><span class="hl-1"> </span><span class="hl-0">editor</span><span class="hl-1">&gt;</span><br/><span class="hl-1">...</span><br/><span class="hl-0">npm</span><span class="hl-1"> </span><span class="hl-0">run</span><span class="hl-1"> </span><span class="hl-0">build</span>
</code><button>Copy</button></pre>
<p>Then commit and push your changes.</p>
<p>In most cases, you will only need to touch the typescript (<code>.ts</code>) files.</p>
<a id="md:work-generation" class="tsd-anchor"></a><h2><a href="#md:work-generation">Work Generation</a></h2><p>Though Kalium&#39;s public work will generate work for you, it is suggested that you generate your own work for the following reasons:</p>
<ul>
<li>it is relatively &quot;easy&quot; (in terms of computation) to do</li>
<li>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</li>
</ul>
<p>Unrelated, do remember that Nano has harder work thresholds than Banano.</p>
<a id="md:using-for-nano-instead-of-banano" class="tsd-anchor"></a><h2><a href="#md:using-for-nano-instead-of-banano">Using for Nano instead of Banano</a></h2><p>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 <code>Wallet</code> with banani, make sure to do <code>my_rpc.DECIMALS = 31</code> otherwise your sends will be off by two magnitudes which is bad.</p>
<p>Also, a different preamble should be used for message signing.</p>
<a id="md:dependencies" class="tsd-anchor"></a><h2><a href="#md:dependencies">Dependencies</a></h2><p>Banani has two external dependencies, tweetnacl and blake2b. Blake2b probably has its own dependencies, but I haven&#39;t checked.</p>
<p>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 <code>tweetnacl_mod.js</code>). Clone the repo and run <code>npm run cryptodiff</code> to see the changes made from regular tweetnacl.</p>
<p>Banani also has many dev dependencies for contributing/developing the package (see the &quot;Contributing&quot; section), but they are not needed for regular users of the package.</p>
<a id="md:todo" class="tsd-anchor"></a><h2><a href="#md:todo">Todo</a></h2><ul>
<li>More extensive testing</li>
<li>Example work generating function</li>
</ul>
</div></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-private" name="private"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Private</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-index-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="assets/icons.svg#icon-chevronDown"></use></svg>On This Page</h3></summary><div class="tsd-accordion-details"><a href="#md:banani"><span>Banani</span></a><ul><li><a href="#md:installing"><span>Installing</span></a></li><li><a href="#md:documentation"><span>Documentation</span></a></li><li><a href="#md:examples"><span>Examples</span></a></li><li><a href="#md:contributing"><span>Contributing</span></a></li><li><a href="#md:work-generation"><span>Work <wbr/>Generation</span></a></li><li><a href="#md:using-for-nano-instead-of-banano"><span>Using for <wbr/>Nano instead of <wbr/>Banano</span></a></li><li><a href="#md:dependencies"><span>Dependencies</span></a></li><li><a href="#md:todo"><span>Todo</span></a></li></ul></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html" class="current"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="assets/icons.svg#icon-1"></use></svg><span>banani</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base="."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>