more tests, finish readme

This commit is contained in:
stjet
2024-06-28 03:46:43 +00:00
parent 4b525aab6b
commit d4ef861ea2
64 changed files with 294 additions and 149 deletions

View File

@@ -2,10 +2,22 @@
<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 <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>The docs are hosted at <a href="https://banani.prussia.dev">https://banani.prussia.dev</a>.</p>
<p>Currently being written, and heavy work in progress.</p>
<a id="md:examples" class="tsd-anchor"></a><h2><a href="#md:examples">Examples</a></h2><a id="md:documentation" class="tsd-anchor"></a><h2><a href="#md:documentation">Documentation</a></h2><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-2">https</span><span class="hl-1">:</span><span class="hl-3">//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">&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>
<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>
@@ -20,4 +32,8 @@ how to install banani on react.js</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>
</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:examples"><span>Examples</span></a></li><li><a href="#md:documentation"><span>Documentation</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></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>
<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>