Swap docs to use vuepress (#330)

* Play around, vuepress docs

* Cleanup old

* Build

* Round out updates
This commit is contained in:
Jaco Greeff
2019-02-26 11:14:20 +01:00
committed by GitHub
parent 4dc3494d4a
commit bc5edc4b42
38 changed files with 3631 additions and 8344 deletions
+31
View File
@@ -0,0 +1,31 @@
module.exports = {
base: '/common/',
title: 'polkadot-js/common',
description: 'Utilities and libraries in-use accross @polkadot projects',
markdown: {
lineNumbers: true
},
themeConfig: {
displayAllHeaders: true,
lastUpdated: 'Last Updated',
nav: [
{ text: 'GitHub', link: 'https://github.com/polkadot-js/common' }
],
sidebar: [
{
title: 'Examples (keyring)',
path: '/examples/keyring/',
collapsable: false,
sidebarDepth: 1,
children: [
['/examples/keyring/01_create_account/', 'Create account'],
['/examples/keyring/02_load_accounts/', 'Load Accounts']
]
},
'/util/',
'/util-crypto/',
'/keyring/',
'/CONTRIBUTING.md'
]
}
};
+1
View File
@@ -0,0 +1 @@
$accentColor = #fd8824
-409
View File
@@ -1,409 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title> · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="./">
<a href="./">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="keyring/">
<a href="keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="trie-db/">
<a href="trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="trie-hash/">
<a href="trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="util/">
<a href="util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="util-crypto/">
<a href="util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="examples/keyring/">
<a href="examples/keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="examples/keyring/01_create_account/">
<a href="examples/keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="examples/keyring/02_load_accounts/">
<a href="examples/keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="examples/util-crypto/">
<a href="examples/util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="examples/util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="examples/util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="examples/util-crypto/02_sign_verify_message_nacl/">
<a href="examples/util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="examples/util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="examples/util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." ></a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"dir":"neutral"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"GLOSSARY.md","mtime":"2019-02-25T16:05:08.437Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":".","book":{"language":""}});
});
</script>
</div>
<script src="gitbook/gitbook.js"></script>
<script src="gitbook/theme.js"></script>
<script src="gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="gitbook/gitbook-plugin-search/search.js"></script>
<script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
View File
+5 -16
View File
@@ -7,31 +7,20 @@ It is split up into a number of internal packages, namely utilities -
- [keyring](keyring/README.md) Keyring management
- [util](util/README.md) General utilities
- [util-crypto](util-crypto/README.md) Crypto and hashing utilities
- [util-rlp](util-rlp/README.md) RLP encoding & decoding
Various useful trie and database interfaces -
- [db](db/README.md) Sync memory and disk database interfaces
- [trie-db](trie-db/README.md) Merkle Patricia Tree implementation adapcted for Polkadot
- [trie-hash](trie-hash/README.md) Calculate hashes (either ordered or unordered) from a set of inputs
This guide describes Polkadot Javascript Common.
{% include "SUMMARY.md" %}
## The Polkadot Project
You can read more about the Polkadot Network at https://polkadot.network/
You can read more about the Polkadot Network at [https://polkadot.network/](https://polkadot.network/)
## Github repositories
You can find the Polkadot repositories at:
- https://github.com/polkadot-js
- https://github.com/paritytech/polkadot
- https://github.com/paritytech/substrate
- [https://github.com/polkadot-js](https://github.com/polkadot-js)
- [https://github.com/paritytech/polkadot](https://github.com/paritytech/polkadot)
- [https://github.com/paritytech/substrate](https://github.com/paritytech/substrate)
This documentation is generated from https://github.com/polkadot-js/api
This documentation is generated from [https://github.com/polkadot-js/common](https://github.com/polkadot-js/common)
## Contributing
-18
View File
@@ -1,18 +0,0 @@
## Packages
- [keyring](keyring/README.md)
- [trie-db](trie-db/README.md)
- [trie-hash](trie-hash/README.md)
- [util](util/README.md)
- [util-crypto](util-crypto/README.md)
## Examples
- [Keyring](examples/keyring/README.md)
- [Create Account](examples/keyring/01_create_account/README.md)
- [Load Accounts](examples/keyring/02_load_accounts/README.md)
- [Util-Crypto](examples/util-crypto/README.md)
- [Encrypt & Decrypt Message](examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md)
- [Sign & Verify Message](examples/util-crypto/02_sign_verify_message_nacl/README.md)
- [Create & Validate Mnemonic](examples/util-crypto/03_mnemonic_generate_validate_bip39/README.md)
@@ -2,4 +2,4 @@
The following example shows how to create and account with keyring.
[include](index.js)
<<< @/docs/examples/keyring/01_create_account/index.js
@@ -1,443 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Create Account · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../../../gitbook/style.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../../../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../02_load_accounts/" />
<link rel="prev" href="../" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../../../">
<a href="../../../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../../../keyring/">
<a href="../../../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../../../trie-db/">
<a href="../../../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../../../trie-hash/">
<a href="../../../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../../../util/">
<a href="../../../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../../../util-crypto/">
<a href="../../../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../">
<a href="../">
Keyring
</a>
<ul class="articles">
<li class="chapter active" data-level="2.1.1" data-path="./">
<a href="./">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../02_load_accounts/">
<a href="../02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../../util-crypto/">
<a href="../../util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../../util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="../../util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../../util-crypto/02_sign_verify_message_nacl/">
<a href="../../util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../../util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="../../util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="../../.." >Create Account</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="create-account">Create Account</h1>
<p>The following example shows how to create and account with keyring.</p>
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-comment">//&#xA0;Import&#xA0;Keyring&#xA0;class&#xA0;and&#xA0;utility&#xA0;function</span>
<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">Keyring</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;@polkadot/keyring&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">default</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">stringToU8a</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;@polkadot/util/string/toU8a&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">default</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-ident">async</span>&#xA0;<span class="sunlight-keyword">function</span>&#xA0;<span class="sunlight-named-ident">main</span>&#xA0;<span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span>&#xA0;<span class="sunlight-punctuation">{</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Create&#xA0;account&#xA0;seed&#xA0;for&#xA0;Alice</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">ALICE_SEED</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-string">&apos;Alice&apos;</span><span class="sunlight-operator">.</span><span class="sunlight-ident">padEnd</span><span class="sunlight-punctuation">(</span><span class="sunlight-number">32</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-string">&apos;&#xA0;&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Create&#xA0;an&#xA0;instance&#xA0;of&#xA0;the&#xA0;Keyring</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">keyring</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-keyword">new</span>&#xA0;<span class="sunlight-ident">Keyring</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Create&#xA0;pair&#xA0;and&#xA0;add&#xA0;Alice&#xA0;to&#xA0;keyring&#xA0;pair&#xA0;dictionary&#xA0;(with&#xA0;account&#xA0;seed)</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">pairAlice</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">keyring</span><span class="sunlight-operator">.</span><span class="sunlight-ident">addFromSeed</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">stringToU8a</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">ALICE_SEED</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">`</span><span class="sunlight-ident">Created</span>&#xA0;<span class="sunlight-ident">keyring</span>&#xA0;<span class="sunlight-ident">pair</span>&#xA0;<span class="sunlight-keyword">for</span>&#xA0;<span class="sunlight-ident">Alice</span>&#xA0;<span class="sunlight-keyword">with</span>&#xA0;<span class="sunlight-ident">address</span><span class="sunlight-operator">:</span>&#xA0;<span class="sunlight-punctuation">`</span>&#xA0;<span class="sunlight-operator">+</span>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<span class="sunlight-punctuation">`</span><span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">keyring</span><span class="sunlight-operator">.</span><span class="sunlight-ident">getPair</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">pairAlice</span><span class="sunlight-operator">.</span><span class="sunlight-ident">address</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-ident">address</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-punctuation">}</span>
<span class="sunlight-ident">main</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">catch</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">error</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">finally</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">_</span>&#xA0;<span class="sunlight-operator">=</span><span class="sunlight-operator">&gt;</span>&#xA0;<span class="sunlight-ident">process</span><span class="sunlight-operator">.</span><span class="sunlight-ident">exit</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../" class="navigation navigation-prev " aria-label="Previous page: Keyring">
<i class="fa fa-angle-left"></i>
</a>
<a href="../02_load_accounts/" class="navigation navigation-next " aria-label="Next page: Load Accounts">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Create Account","level":"2.1.1","depth":2,"next":{"title":"Load Accounts","level":"2.1.2","depth":2,"path":"examples/keyring/02_load_accounts/README.md","ref":"examples/keyring/02_load_accounts/README.md","articles":[]},"previous":{"title":"Keyring","level":"2.1","depth":1,"path":"examples/keyring/README.md","ref":"examples/keyring/README.md","articles":[{"title":"Create Account","level":"2.1.1","depth":2,"path":"examples/keyring/01_create_account/README.md","ref":"examples/keyring/01_create_account/README.md","articles":[]},{"title":"Load Accounts","level":"2.1.2","depth":2,"path":"examples/keyring/02_load_accounts/README.md","ref":"examples/keyring/02_load_accounts/README.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"examples/keyring/01_create_account/README.md","mtime":"2019-02-25T16:05:08.437Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"../../..","book":{"language":""}});
});
</script>
</div>
<script src="../../../gitbook/gitbook.js"></script>
<script src="../../../gitbook/theme.js"></script>
<script src="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
@@ -2,4 +2,4 @@
The following example shows how to load all accounts from the keyring as pairs and convert them into JSON format.
[include](index.js)
<<< @/docs/examples/keyring/02_load_accounts/index.js
@@ -1,455 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Load Accounts · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../../../gitbook/style.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../../../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../../util-crypto/" />
<link rel="prev" href="../01_create_account/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../../../">
<a href="../../../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../../../keyring/">
<a href="../../../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../../../trie-db/">
<a href="../../../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../../../trie-hash/">
<a href="../../../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../../../util/">
<a href="../../../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../../../util-crypto/">
<a href="../../../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../">
<a href="../">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../01_create_account/">
<a href="../01_create_account/">
Create Account
</a>
</li>
<li class="chapter active" data-level="2.1.2" data-path="./">
<a href="./">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../../util-crypto/">
<a href="../../util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../../util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="../../util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../../util-crypto/02_sign_verify_message_nacl/">
<a href="../../util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../../util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="../../util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="../../.." >Load Accounts</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="load-accounts">Load Accounts</h1>
<p>The following example shows how to load all accounts from the keyring as pairs and convert them into JSON format.</p>
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-comment">//&#xA0;Import&#xA0;Keyring&#xA0;class&#xA0;and&#xA0;utility&#xA0;function</span>
<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">Keyring</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;@polkadot/keyring&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">default</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">stringToU8a</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;@polkadot/util/string/toU8a&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">default</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-ident">async</span>&#xA0;<span class="sunlight-keyword">function</span>&#xA0;<span class="sunlight-named-ident">main</span>&#xA0;<span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span>&#xA0;<span class="sunlight-punctuation">{</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Create&#xA0;account&#xA0;seed&#xA0;for&#xA0;Alice&#xA0;and&#xA0;Bob</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">ALICE_SEED</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-string">&apos;Alice&apos;</span><span class="sunlight-operator">.</span><span class="sunlight-ident">padEnd</span><span class="sunlight-punctuation">(</span><span class="sunlight-number">32</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-string">&apos;&#xA0;&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">BOB_SEED</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-string">&apos;Bob&apos;</span><span class="sunlight-operator">.</span><span class="sunlight-ident">padEnd</span><span class="sunlight-punctuation">(</span><span class="sunlight-number">32</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-string">&apos;&#xA0;&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Create&#xA0;an&#xA0;instance&#xA0;of&#xA0;the&#xA0;Keyring</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">keyring</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-keyword">new</span>&#xA0;<span class="sunlight-ident">Keyring</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Create&#xA0;their&#xA0;pairs&#xA0;with&#xA0;account&#xA0;seeds.&#xA0;Add&#xA0;to&#xA0;keyring&#xA0;pair&#xA0;dictionary</span>
&#xA0;&#xA0;<span class="sunlight-ident">keyring</span><span class="sunlight-operator">.</span><span class="sunlight-ident">addFromSeed</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">stringToU8a</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">ALICE_SEED</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-ident">keyring</span><span class="sunlight-operator">.</span><span class="sunlight-ident">addFromSeed</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">stringToU8a</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">BOB_SEED</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Note&#xA0;that&#xA0;we&#xA0;did&#xA0;not&#xA0;use&#xA0;`addFromAddress`&#xA0;since&#xA0;it&#xA0;does&#xA0;not&#xA0;add&#xA0;the</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;secret&#xA0;key&#xA0;to&#xA0;memory&#xA0;so&#xA0;we&#xA0;cannot&#xA0;later&#xA0;retrieve&#xA0;it&#xA0;with&#xA0;`getPairs`</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Retrieve&#xA0;all&#xA0;keyring&#xA0;pairs&#xA0;from&#xA0;the&#xA0;keyring&#xA0;pair&#xA0;dictionary</span>
&#xA0;&#xA0;<span class="sunlight-ident">keyring</span>
&#xA0;&#xA0;&#xA0;&#xA0;<span class="sunlight-operator">.</span><span class="sunlight-ident">getPairs</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span>
&#xA0;&#xA0;&#xA0;&#xA0;<span class="sunlight-operator">.</span><span class="sunlight-ident">forEach</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">pair</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">index</span><span class="sunlight-punctuation">)</span>&#xA0;<span class="sunlight-operator">=</span><span class="sunlight-operator">&gt;</span>&#xA0;<span class="sunlight-punctuation">{</span>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">address</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">pair</span><span class="sunlight-operator">.</span><span class="sunlight-ident">address</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">\</span><span class="sunlight-ident">nAccount</span>&#xA0;<span class="sunlight-keyword">with</span>&#xA0;<span class="sunlight-ident">index</span>&#xA0;<span class="sunlight-punctuation">#</span><span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">index</span><span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-ident">has</span>&#xA0;<span class="sunlight-ident">json</span><span class="sunlight-operator">:</span>&#xA0;<span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">,</span>
&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;&#xA0;<span class="sunlight-globalObject">JSON</span><span class="sunlight-operator">.</span><span class="sunlight-ident">stringify</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">keyring</span><span class="sunlight-operator">.</span><span class="sunlight-ident">toJson</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">address</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-keyword">null</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">2</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;&#xA0;&#xA0;<span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-punctuation">}</span>
<span class="sunlight-ident">main</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">catch</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">error</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">finally</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">_</span>&#xA0;<span class="sunlight-operator">=</span><span class="sunlight-operator">&gt;</span>&#xA0;<span class="sunlight-ident">process</span><span class="sunlight-operator">.</span><span class="sunlight-ident">exit</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../01_create_account/" class="navigation navigation-prev " aria-label="Previous page: Create Account">
<i class="fa fa-angle-left"></i>
</a>
<a href="../../util-crypto/" class="navigation navigation-next " aria-label="Next page: Util-Crypto">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Load Accounts","level":"2.1.2","depth":2,"next":{"title":"Util-Crypto","level":"2.2","depth":1,"path":"examples/util-crypto/README.md","ref":"examples/util-crypto/README.md","articles":[{"title":"Encrypt & Decrypt Message","level":"2.2.1","depth":2,"path":"examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md","ref":"examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md","articles":[]},{"title":"Sign & Verify Message","level":"2.2.2","depth":2,"path":"examples/util-crypto/02_sign_verify_message_nacl/README.md","ref":"examples/util-crypto/02_sign_verify_message_nacl/README.md","articles":[]},{"title":"Create & Validate Mnemonic","level":"2.2.3","depth":2,"path":"examples/util-crypto/03_mnemonic_generate_validate_bip39/README.md","ref":"examples/util-crypto/03_mnemonic_generate_validate_bip39/README.md","articles":[]}]},"previous":{"title":"Create Account","level":"2.1.1","depth":2,"path":"examples/keyring/01_create_account/README.md","ref":"examples/keyring/01_create_account/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"examples/keyring/02_load_accounts/README.md","mtime":"2019-02-25T16:05:08.437Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"../../..","book":{"language":""}});
});
</script>
</div>
<script src="../../../gitbook/gitbook.js"></script>
<script src="../../../gitbook/theme.js"></script>
<script src="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
-428
View File
@@ -1,428 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Keyring · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../../gitbook/style.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="01_create_account/" />
<link rel="prev" href="../../util-crypto/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../../">
<a href="../../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../../keyring/">
<a href="../../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../../trie-db/">
<a href="../../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../../trie-hash/">
<a href="../../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../../util/">
<a href="../../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../../util-crypto/">
<a href="../../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter active" data-level="2.1" data-path="./">
<a href="./">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="01_create_account/">
<a href="01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="02_load_accounts/">
<a href="02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../util-crypto/">
<a href="../util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="../util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../util-crypto/02_sign_verify_message_nacl/">
<a href="../util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="../util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="../.." >Keyring</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="keyring-examples">Keyring Examples</h1>
<p>Here you will find a list of examples that takes you through the basics of connecting to a local node, retrieving data from the Node and chain and execute transactions on the chain.</p>
<h2 id="running-the-examples">Running the examples</h2>
<p>From within each folder run the following to install required dependencies and to execute the example:</p>
<pre><code class="lang-shell"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-shell sunlight-highlighted"><span class="sunlight-plaintext">yarn;
yarn&#xA0;start
</span></pre></div></div></code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../../util-crypto/" class="navigation navigation-prev " aria-label="Previous page: util-crypto">
<i class="fa fa-angle-left"></i>
</a>
<a href="01_create_account/" class="navigation navigation-next " aria-label="Next page: Create Account">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Keyring","level":"2.1","depth":1,"next":{"title":"Create Account","level":"2.1.1","depth":2,"path":"examples/keyring/01_create_account/README.md","ref":"examples/keyring/01_create_account/README.md","articles":[]},"previous":{"title":"util-crypto","level":"1.6","depth":1,"path":"util-crypto/README.md","ref":"util-crypto/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"examples/keyring/README.md","mtime":"2019-02-25T16:05:08.441Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"../..","book":{"language":""}});
});
</script>
</div>
<script src="../../gitbook/gitbook.js"></script>
<script src="../../gitbook/theme.js"></script>
<script src="../../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
@@ -1,447 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Encrypt & Decrypt Message · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../../../gitbook/style.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../../../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../02_sign_verify_message_nacl/" />
<link rel="prev" href="../" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../../../">
<a href="../../../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../../../keyring/">
<a href="../../../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../../../trie-db/">
<a href="../../../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../../../trie-hash/">
<a href="../../../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../../../util/">
<a href="../../../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../../../util-crypto/">
<a href="../../../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../../keyring/">
<a href="../../keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../../keyring/01_create_account/">
<a href="../../keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../../keyring/02_load_accounts/">
<a href="../../keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../">
<a href="../">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter active" data-level="2.2.1" data-path="./">
<a href="./">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../02_sign_verify_message_nacl/">
<a href="../02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../03_mnemonic_generate_validate_bip39/">
<a href="../03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="../../.." >Encrypt & Decrypt Message</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="encrypt--decrypt-message-using-nacl">Encrypt &amp; Decrypt Message using NaCl</h1>
<p>The following example shows how to encrypt and decrypt a message with NaCl (pronouced &quot;salt&quot;), which is a Networking and Cryptography library used in util-crypto.</p>
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">naclEncrypt</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">naclDecrypt</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;@polkadot/util-crypto&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-ident">async</span>&#xA0;<span class="sunlight-keyword">function</span>&#xA0;<span class="sunlight-named-ident">main</span>&#xA0;<span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span>&#xA0;<span class="sunlight-punctuation">{</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">secret</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-keyword">new</span>&#xA0;<span class="sunlight-ident">Uint8Array</span><span class="sunlight-punctuation">(</span><span class="sunlight-number">32</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">messagePreEncryption</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-keyword">new</span>&#xA0;<span class="sunlight-ident">Uint8Array</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">[</span><span class="sunlight-number">1</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">2</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">3</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">4</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">5</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">4</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">3</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">2</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">1</span><span class="sunlight-punctuation">]</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">noncePreEncryption</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-keyword">new</span>&#xA0;<span class="sunlight-ident">Uint8Array</span><span class="sunlight-punctuation">(</span><span class="sunlight-number">24</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Encrypt&#xA0;the&#xA0;message</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">nonce</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">naclEncrypt</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">messagePreEncryption</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">secret</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">noncePreEncryption</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Show&#xA0;contents&#xA0;of&#xA0;the&#xA0;encrypted&#xA0;message</span>
&#xA0;&#xA0;<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">`</span><span class="sunlight-ident">Encrypted</span>&#xA0;<span class="sunlight-ident">message</span><span class="sunlight-operator">:</span>&#xA0;<span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-globalObject">JSON</span><span class="sunlight-operator">.</span><span class="sunlight-ident">stringify</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-keyword">null</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-number">2</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Decrypt&#xA0;the&#xA0;message</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">messageDecrypted</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">naclDecrypt</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">nonce</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">secret</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Convert&#xA0;each&#xA0;Uint8Array&#xA0;to&#xA0;a&#xA0;string&#xA0;for&#xA0;comparison</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">isMatch</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">messagePreEncryption</span><span class="sunlight-operator">.</span><span class="sunlight-ident">toString</span>&#xA0;<span class="sunlight-operator">===</span>&#xA0;<span class="sunlight-ident">messageDecrypted</span><span class="sunlight-operator">.</span><span class="sunlight-ident">toString</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Verify&#xA0;that&#xA0;the&#xA0;decrypted&#xA0;message&#xA0;matches&#xA0;the&#xA0;original&#xA0;message</span>
&#xA0;&#xA0;<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">`</span><span class="sunlight-ident">Does</span>&#xA0;<span class="sunlight-ident">the</span>&#xA0;<span class="sunlight-ident">decrypted</span>&#xA0;<span class="sunlight-ident">message</span>&#xA0;<span class="sunlight-ident">match</span>&#xA0;<span class="sunlight-ident">the</span>&#xA0;<span class="sunlight-ident">original</span>&#xA0;<span class="sunlight-ident">message</span><span class="sunlight-operator">?</span>&#xA0;<span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">isMatch</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-punctuation">}</span>
<span class="sunlight-ident">main</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">catch</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">error</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">finally</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">_</span>&#xA0;<span class="sunlight-operator">=</span><span class="sunlight-operator">&gt;</span>&#xA0;<span class="sunlight-ident">process</span><span class="sunlight-operator">.</span><span class="sunlight-ident">exit</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../" class="navigation navigation-prev " aria-label="Previous page: Util-Crypto">
<i class="fa fa-angle-left"></i>
</a>
<a href="../02_sign_verify_message_nacl/" class="navigation navigation-next " aria-label="Next page: Sign & Verify Message">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Encrypt & Decrypt Message","level":"2.2.1","depth":2,"next":{"title":"Sign & Verify Message","level":"2.2.2","depth":2,"path":"examples/util-crypto/02_sign_verify_message_nacl/README.md","ref":"examples/util-crypto/02_sign_verify_message_nacl/README.md","articles":[]},"previous":{"title":"Util-Crypto","level":"2.2","depth":1,"path":"examples/util-crypto/README.md","ref":"examples/util-crypto/README.md","articles":[{"title":"Encrypt & Decrypt Message","level":"2.2.1","depth":2,"path":"examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md","ref":"examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md","articles":[]},{"title":"Sign & Verify Message","level":"2.2.2","depth":2,"path":"examples/util-crypto/02_sign_verify_message_nacl/README.md","ref":"examples/util-crypto/02_sign_verify_message_nacl/README.md","articles":[]},{"title":"Create & Validate Mnemonic","level":"2.2.3","depth":2,"path":"examples/util-crypto/03_mnemonic_generate_validate_bip39/README.md","ref":"examples/util-crypto/03_mnemonic_generate_validate_bip39/README.md","articles":[]}]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md","mtime":"2019-02-25T16:05:08.441Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"../../..","book":{"language":""}});
});
</script>
</div>
<script src="../../../gitbook/gitbook.js"></script>
<script src="../../../gitbook/theme.js"></script>
<script src="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
@@ -1,453 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Sign & Verify Message · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../../../gitbook/style.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../../../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../03_mnemonic_generate_validate_bip39/" />
<link rel="prev" href="../01_encrypt_decrypt_message_nacl/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../../../">
<a href="../../../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../../../keyring/">
<a href="../../../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../../../trie-db/">
<a href="../../../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../../../trie-hash/">
<a href="../../../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../../../util/">
<a href="../../../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../../../util-crypto/">
<a href="../../../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../../keyring/">
<a href="../../keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../../keyring/01_create_account/">
<a href="../../keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../../keyring/02_load_accounts/">
<a href="../../keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../">
<a href="../">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../01_encrypt_decrypt_message_nacl/">
<a href="../01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter active" data-level="2.2.2" data-path="./">
<a href="./">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../03_mnemonic_generate_validate_bip39/">
<a href="../03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="../../.." >Sign & Verify Message</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="sign--verify-message-using-nacl">Sign &amp; Verify Message using NaCl</h1>
<p>The following example shows how to sign and verify a message with NaCl (pronouced &quot;salt&quot;), which is a Networking and Cryptography library used in util-crypto.</p>
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">stringToU8a</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">u8aToHex</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;@polkadot/util&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">naclEncrypt</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">naclKeypairFromSeed</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">naclSign</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">naclVerify</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">randomAsU8a</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;@polkadot/util-crypto&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-ident">async</span>&#xA0;<span class="sunlight-keyword">function</span>&#xA0;<span class="sunlight-named-ident">main</span>&#xA0;<span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span>&#xA0;<span class="sunlight-punctuation">{</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Create&#xA0;account&#xA0;seed&#xA0;for&#xA0;Alice&#xA0;as&#xA0;fallback&#xA0;if&#xA0;generated&#xA0;mnemonic&#xA0;not&#xA0;valid</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">seedAlice</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-string">&apos;Alice&apos;</span><span class="sunlight-operator">.</span><span class="sunlight-ident">padEnd</span><span class="sunlight-punctuation">(</span><span class="sunlight-number">32</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-string">&apos;&#xA0;&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Generate&#xA0;new&#xA0;public/secret&#xA0;keypair&#xA0;for&#xA0;Alice&#xA0;from&#xA0;the&#xA0;supplied&#xA0;seed</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">secretKey</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">publicKey</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">naclKeypairFromSeed</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">stringToU8a</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">seedAlice</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Encrypt&#xA0;message.&#xA0;Create&#xA0;Uint8Array&apos;s&#xA0;filled&#xA0;with&#xA0;random&#xA0;bytes&#xA0;of&#xA0;specified&#xA0;length</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">secret</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">randomAsU8a</span><span class="sunlight-punctuation">(</span><span class="sunlight-number">32</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">messagePreEncryption</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">stringToU8a</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;please&#xA0;send&#xA0;me&#xA0;DOTs&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">noncePreEncryption</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">randomAsU8a</span><span class="sunlight-punctuation">(</span><span class="sunlight-number">24</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">nonce</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">naclEncrypt</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">messagePreEncryption</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">secret</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">noncePreEncryption</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Sign&#xA0;the&#xA0;message&#xA0;with&#xA0;a&#xA0;valid&#xA0;signature</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">messageSignature</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">naclSign</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">secretKey</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">`</span><span class="sunlight-ident">Message</span>&#xA0;<span class="sunlight-ident">signature</span><span class="sunlight-operator">:</span>&#xA0;<span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">u8aToHex</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">messageSignature</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Validate&#xA0;that&#xA0;the&#xA0;message&#xA0;was&#xA0;correctly&#xA0;signed</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">isValidSignature</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">naclVerify</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">messageSignature</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">publicKey</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">`</span><span class="sunlight-ident">Was</span>&#xA0;<span class="sunlight-ident">the</span>&#xA0;<span class="sunlight-ident">message</span>&#xA0;<span class="sunlight-ident">correctly</span>&#xA0;<span class="sunlight-ident">signed</span><span class="sunlight-operator">?</span>&#xA0;<span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">isValidSignature</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-punctuation">}</span>
<span class="sunlight-ident">main</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">catch</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">error</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">finally</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">_</span>&#xA0;<span class="sunlight-operator">=</span><span class="sunlight-operator">&gt;</span>&#xA0;<span class="sunlight-ident">process</span><span class="sunlight-operator">.</span><span class="sunlight-ident">exit</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../01_encrypt_decrypt_message_nacl/" class="navigation navigation-prev " aria-label="Previous page: Encrypt & Decrypt Message">
<i class="fa fa-angle-left"></i>
</a>
<a href="../03_mnemonic_generate_validate_bip39/" class="navigation navigation-next " aria-label="Next page: Create & Validate Mnemonic">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Sign & Verify Message","level":"2.2.2","depth":2,"next":{"title":"Create & Validate Mnemonic","level":"2.2.3","depth":2,"path":"examples/util-crypto/03_mnemonic_generate_validate_bip39/README.md","ref":"examples/util-crypto/03_mnemonic_generate_validate_bip39/README.md","articles":[]},"previous":{"title":"Encrypt & Decrypt Message","level":"2.2.1","depth":2,"path":"examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md","ref":"examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"examples/util-crypto/02_sign_verify_message_nacl/README.md","mtime":"2019-02-25T16:05:08.441Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"../../..","book":{"language":""}});
});
</script>
</div>
<script src="../../../gitbook/gitbook.js"></script>
<script src="../../../gitbook/theme.js"></script>
<script src="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
@@ -1,442 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Create & Validate Mnemonic · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../../../gitbook/style.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../../../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../../../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../../../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="prev" href="../02_sign_verify_message_nacl/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../../../">
<a href="../../../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../../../keyring/">
<a href="../../../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../../../trie-db/">
<a href="../../../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../../../trie-hash/">
<a href="../../../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../../../util/">
<a href="../../../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../../../util-crypto/">
<a href="../../../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../../keyring/">
<a href="../../keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../../keyring/01_create_account/">
<a href="../../keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../../keyring/02_load_accounts/">
<a href="../../keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../">
<a href="../">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../01_encrypt_decrypt_message_nacl/">
<a href="../01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../02_sign_verify_message_nacl/">
<a href="../02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter active" data-level="2.2.3" data-path="./">
<a href="./">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="../../.." >Create & Validate Mnemonic</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="create--generate-mnemonic-using-bip39">Create &amp; Generate Mnemonic using BIP39</h1>
<p>The following example shows how to create and generate mnemonics using BIP39.</p>
<pre><code class="lang-javascript"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">mnemonicGenerate</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">mnemonicToSeed</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">mnemonicValidate</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">naclKeypairFromSeed</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">&apos;@polkadot/util-crypto&apos;</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-ident">async</span>&#xA0;<span class="sunlight-keyword">function</span>&#xA0;<span class="sunlight-named-ident">main</span>&#xA0;<span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span>&#xA0;<span class="sunlight-punctuation">{</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Create&#xA0;mnemonic&#xA0;string&#xA0;for&#xA0;Alice&#xA0;using&#xA0;BIP39</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">mnemonicAlice</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">mnemonicGenerate</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">`</span><span class="sunlight-ident">Generated</span>&#xA0;<span class="sunlight-ident">mnemonic</span><span class="sunlight-operator">:</span>&#xA0;<span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">mnemonicAlice</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Validate&#xA0;the&#xA0;mnemic&#xA0;string&#xA0;that&#xA0;was&#xA0;generated</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">isValidMnemonic</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">mnemonicValidate</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">mnemonicAlice</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">log</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">`</span><span class="sunlight-ident">isValidMnemonic</span><span class="sunlight-operator">:</span>&#xA0;<span class="sunlight-ident">$</span><span class="sunlight-punctuation">{</span><span class="sunlight-ident">isValidMnemonic</span><span class="sunlight-punctuation">}</span><span class="sunlight-punctuation">`</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Create&#xA0;valid&#xA0;seed&#xA0;from&#xA0;mnemonic&#xA0;as&#xA0;u8a&#xA0;and&#xA0;convert&#xA0;it&#xA0;to&#xA0;a&#xA0;string</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;FIXME&#xA0;-&#xA0;Replace&#xA0;with&#xA0;mnemonicToSeed&#xA0;once&#xA0;exposed</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-ident">seedAlice</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">mnemonicToSeed</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">mnemonicAlice</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Generate&#xA0;new&#xA0;public/secret&#xA0;keypair&#xA0;for&#xA0;Alice&#xA0;from&#xA0;the&#xA0;supplied&#xA0;seed</span>
&#xA0;&#xA0;<span class="sunlight-reservedWord">const</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">secretKey</span><span class="sunlight-punctuation">,</span>&#xA0;<span class="sunlight-ident">publicKey</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-operator">=</span>&#xA0;<span class="sunlight-ident">naclKeypairFromSeed</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">seedAlice</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
&#xA0;&#xA0;<span class="sunlight-comment">//&#xA0;Encrypt,&#xA0;Sign&#xA0;and&#xA0;Validate&#xA0;the&#xA0;message.&#xA0;See&#xA0;Example&#xA0;&apos;Sign&#xA0;&amp;&#xA0;Verify&#xA0;Message&apos;</span>
<span class="sunlight-punctuation">}</span>
<span class="sunlight-ident">main</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">catch</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">console</span><span class="sunlight-operator">.</span><span class="sunlight-ident">error</span><span class="sunlight-punctuation">)</span><span class="sunlight-operator">.</span><span class="sunlight-keyword">finally</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">_</span>&#xA0;<span class="sunlight-operator">=</span><span class="sunlight-operator">&gt;</span>&#xA0;<span class="sunlight-ident">process</span><span class="sunlight-operator">.</span><span class="sunlight-ident">exit</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../02_sign_verify_message_nacl/" class="navigation navigation-prev navigation-unique" aria-label="Previous page: Sign & Verify Message">
<i class="fa fa-angle-left"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Create & Validate Mnemonic","level":"2.2.3","depth":2,"previous":{"title":"Sign & Verify Message","level":"2.2.2","depth":2,"path":"examples/util-crypto/02_sign_verify_message_nacl/README.md","ref":"examples/util-crypto/02_sign_verify_message_nacl/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"examples/util-crypto/03_mnemonic_generate_validate_bip39/README.md","mtime":"2019-02-25T16:05:08.441Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"../../..","book":{"language":""}});
});
</script>
</div>
<script src="../../../gitbook/gitbook.js"></script>
<script src="../../../gitbook/theme.js"></script>
<script src="../../../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../../../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
-428
View File
@@ -1,428 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Util-Crypto · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../../gitbook/style.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="01_encrypt_decrypt_message_nacl/" />
<link rel="prev" href="../keyring/02_load_accounts/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../../">
<a href="../../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../../keyring/">
<a href="../../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../../trie-db/">
<a href="../../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../../trie-hash/">
<a href="../../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../../util/">
<a href="../../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../../util-crypto/">
<a href="../../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../keyring/">
<a href="../keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../keyring/01_create_account/">
<a href="../keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../keyring/02_load_accounts/">
<a href="../keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter active" data-level="2.2" data-path="./">
<a href="./">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="01_encrypt_decrypt_message_nacl/">
<a href="01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="02_sign_verify_message_nacl/">
<a href="02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="03_mnemonic_generate_validate_bip39/">
<a href="03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="../.." >Util-Crypto</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="util-crypto-examples">Util-Crypto Examples</h1>
<p>Here you will find a list of examples that takes you through the basics of encrypting and decrypting messages using NaCl, signing a message with a seed and verifying it using NaCl, and generating and validating mnemonics for account seeds.</p>
<h2 id="running-the-examples">Running the examples</h2>
<p>From within each folder run the following to install required dependencies and to execute the example:</p>
<pre><code class="lang-shell"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-shell sunlight-highlighted"><span class="sunlight-plaintext">yarn;
yarn&#xA0;start
</span></pre></div></div></code></pre>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../keyring/02_load_accounts/" class="navigation navigation-prev " aria-label="Previous page: Load Accounts">
<i class="fa fa-angle-left"></i>
</a>
<a href="01_encrypt_decrypt_message_nacl/" class="navigation navigation-next " aria-label="Next page: Encrypt & Decrypt Message">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Util-Crypto","level":"2.2","depth":1,"next":{"title":"Encrypt & Decrypt Message","level":"2.2.1","depth":2,"path":"examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md","ref":"examples/util-crypto/01_encrypt_decrypt_message_nacl/README.md","articles":[]},"previous":{"title":"Load Accounts","level":"2.1.2","depth":2,"path":"examples/keyring/02_load_accounts/README.md","ref":"examples/keyring/02_load_accounts/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"examples/util-crypto/README.md","mtime":"2019-02-25T16:05:08.441Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"../..","book":{"language":""}});
});
</script>
</div>
<script src="../../gitbook/gitbook.js"></script>
<script src="../../gitbook/theme.js"></script>
<script src="../../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
-465
View File
@@ -1,465 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>Introduction · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="gitbook/style.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="keyring/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter active" data-level="1.1" data-path="./">
<a href="./">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="keyring/">
<a href="keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="trie-db/">
<a href="trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="trie-hash/">
<a href="trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="util/">
<a href="util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="util-crypto/">
<a href="util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="examples/keyring/">
<a href="examples/keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="examples/keyring/01_create_account/">
<a href="examples/keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="examples/keyring/02_load_accounts/">
<a href="examples/keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="examples/util-crypto/">
<a href="examples/util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="examples/util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="examples/util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="examples/util-crypto/02_sign_verify_message_nacl/">
<a href="examples/util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="examples/util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="examples/util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href="." >Introduction</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="polkadot-javascript-common">Polkadot Javascript Common</h1>
<p>Various useful utility functions that are used across all projects in the <a href="https://polkadot.js.org" target="_blank">@polkadot</a> namespace. It provides utility functions with additional safety checks, allowing not only for consistent coding, but also reducing the general boilerplate.</p>
<p>It is split up into a number of internal packages, namely utilities -</p>
<ul>
<li><a href="keyring/">keyring</a> Keyring management</li>
<li><a href="util/">util</a> General utilities</li>
<li><a href="util-crypto/">util-crypto</a> Crypto and hashing utilities</li>
<li><a href="util-rlp/README.md">util-rlp</a> RLP encoding &amp; decoding</li>
</ul>
<p>Various useful trie and database interfaces -</p>
<ul>
<li><a href="db/README.md">db</a> Sync memory and disk database interfaces</li>
<li><a href="trie-db/">trie-db</a> Merkle Patricia Tree implementation adapcted for Polkadot</li>
<li><a href="trie-hash/">trie-hash</a> Calculate hashes (either ordered or unordered) from a set of inputs</li>
</ul>
<p>This guide describes Polkadot Javascript Common.</p>
<h2 id="packages">Packages</h2>
<ul>
<li><a href="keyring/">keyring</a></li>
<li><a href="trie-db/">trie-db</a></li>
<li><a href="trie-hash/">trie-hash</a></li>
<li><a href="util/">util</a></li>
<li><a href="util-crypto/">util-crypto</a></li>
</ul>
<h2 id="examples">Examples</h2>
<ul>
<li><a href="examples/keyring/">Keyring</a><ul>
<li><a href="examples/keyring/01_create_account/">Create Account</a></li>
<li><a href="examples/keyring/02_load_accounts/">Load Accounts</a></li>
</ul>
</li>
<li><a href="examples/util-crypto/">Util-Crypto</a><ul>
<li><a href="examples/util-crypto/01_encrypt_decrypt_message_nacl/">Encrypt &amp; Decrypt Message</a></li>
<li><a href="examples/util-crypto/02_sign_verify_message_nacl/">Sign &amp; Verify Message</a></li>
<li><a href="examples/util-crypto/03_mnemonic_generate_validate_bip39/">Create &amp; Validate Mnemonic</a></li>
</ul>
</li>
</ul>
<h2 id="the-polkadot-project">The Polkadot Project</h2>
<p>You can read more about the Polkadot Network at <a href="https://polkadot.network/" target="_blank">https://polkadot.network/</a></p>
<h2 id="github-repositories">Github repositories</h2>
<p>You can find the Polkadot repositories at:</p>
<ul>
<li><a href="https://github.com/polkadot-js" target="_blank">https://github.com/polkadot-js</a></li>
<li><a href="https://github.com/paritytech/polkadot" target="_blank">https://github.com/paritytech/polkadot</a></li>
<li><a href="https://github.com/paritytech/substrate" target="_blank">https://github.com/paritytech/substrate</a></li>
</ul>
<p>This documentation is generated from <a href="https://github.com/polkadot-js/api" target="_blank">https://github.com/polkadot-js/api</a></p>
<h2 id="contributing">Contributing</h2>
<p>Contribution to Polkadot JS Common are more than welcome. You can <a href="https://github.com/polkadot-js/common/issues/new" target="_blank">report issues</a> and <a href="https://github.com/polkadot-js/common/issues/new" target="_blank">log feature requests</a>.</p>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="keyring/" class="navigation navigation-next navigation-unique" aria-label="Next page: keyring">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"Introduction","level":"1.1","depth":1,"next":{"title":"keyring","level":"1.2","depth":1,"path":"keyring/README.md","ref":"keyring/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"README.md","mtime":"2019-02-25T16:05:08.437Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":".","book":{"language":""}});
});
</script>
</div>
<script src="gitbook/gitbook.js"></script>
<script src="gitbook/theme.js"></script>
<script src="gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="gitbook/gitbook-plugin-search/search.js"></script>
<script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
+5 -7
View File
@@ -17,7 +17,6 @@ Classes and Functions can be imported as follows:
```js
import Keyring from '@polkadot/keyring';
import pair from '@polkadot/keyring/pair';
import testKeyring from '@polkadot/keyring/testing';
```
@@ -26,10 +25,9 @@ Documentation and Available Utilities
Below is a list of currently exposed methods published at the [Polkadot-JS Common Documentation Portal](https://polkadot.js.org/common/keyring/).
* [keyring](https://polkadot.js.org/common/keyring/README.md)
* [keyring](README.md)
* Classes
* [Keyring](https://polkadot.js.org/common/keyring/classes/_index_.keyring.md)
* Functions
* [pair](https://polkadot.js.org/common/keyring/modules/_pair_index_.md)
* [testKeyring](https://polkadot.js.org/common/keyring/modules/_testing_.md)
* [Keyring](classes/_index_.keyring.md)
* Interfaces
* [pair](modules/_pair_index_.md)
* [testKeyring](modules/_testing_.md)
-447
View File
@@ -1,447 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>keyring · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../trie-db/" />
<link rel="prev" href="../" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter active" data-level="1.2" data-path="./">
<a href="./">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../trie-db/">
<a href="../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../trie-hash/">
<a href="../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../util/">
<a href="../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../util-crypto/">
<a href="../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../examples/keyring/">
<a href="../examples/keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../examples/keyring/01_create_account/">
<a href="../examples/keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../examples/keyring/02_load_accounts/">
<a href="../examples/keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../examples/util-crypto/">
<a href="../examples/util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../examples/util-crypto/02_sign_verify_message_nacl/">
<a href="../examples/util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >keyring</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="polkadotkeyring">@polkadot/keyring</h1>
<p>Key management of user accounts including generation and retrieval of keyring pairs from a variety of input combinations.</p>
<h2 id="usage">Usage</h2>
<p>Installation -</p>
<pre><code>yarn add @polkadot/keyring
</code></pre><p>Classes and Functions can be imported as follows:</p>
<pre><code class="lang-js"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span>&#xA0;<span class="sunlight-ident">Keyring</span>&#xA0;<span class="sunlight-ident">from</span>&#xA0;<span class="sunlight-string">&apos;@polkadot/keyring&apos;</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-reservedWord">import</span>&#xA0;<span class="sunlight-ident">pair</span>&#xA0;<span class="sunlight-ident">from</span>&#xA0;<span class="sunlight-string">&apos;@polkadot/keyring/pair&apos;</span><span class="sunlight-punctuation">;</span>
<span class="sunlight-reservedWord">import</span>&#xA0;<span class="sunlight-ident">testKeyring</span>&#xA0;<span class="sunlight-ident">from</span>&#xA0;<span class="sunlight-string">&apos;@polkadot/keyring/testing&apos;</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
<h2 id="documentation-and-available-utilities">Documentation and Available Utilities</h2>
<p>Below is a list of currently exposed methods published at the <a href="https://polkadot.js.org/common/keyring/" target="_blank">Polkadot-JS Common Documentation Portal</a>.</p>
<ul>
<li><a href="https://polkadot.js.org/common/keyring/README.md" target="_blank">keyring</a><ul>
<li>Classes<ul>
<li><a href="https://polkadot.js.org/common/keyring/classes/_index_.keyring.md" target="_blank">Keyring</a></li>
</ul>
</li>
<li>Functions<ul>
<li><a href="https://polkadot.js.org/common/keyring/modules/_pair_index_.md" target="_blank">pair</a></li>
<li><a href="https://polkadot.js.org/common/keyring/modules/_testing_.md" target="_blank">testKeyring</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../" class="navigation navigation-prev " aria-label="Previous page: Introduction">
<i class="fa fa-angle-left"></i>
</a>
<a href="../trie-db/" class="navigation navigation-next " aria-label="Next page: trie-db">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"keyring","level":"1.2","depth":1,"next":{"title":"trie-db","level":"1.3","depth":1,"path":"trie-db/README.md","ref":"trie-db/README.md","articles":[]},"previous":{"title":"Introduction","level":"1.1","depth":1,"path":"README.md","ref":"README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"keyring/README.md","mtime":"2019-02-25T16:08:25.142Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
File diff suppressed because one or more lines are too long
-451
View File
@@ -1,451 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>trie-db · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../trie-hash/" />
<link rel="prev" href="../keyring/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../keyring/">
<a href="../keyring/">
keyring
</a>
</li>
<li class="chapter active" data-level="1.3" data-path="./">
<a href="./">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../trie-hash/">
<a href="../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../util/">
<a href="../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../util-crypto/">
<a href="../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../examples/keyring/">
<a href="../examples/keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../examples/keyring/01_create_account/">
<a href="../examples/keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../examples/keyring/02_load_accounts/">
<a href="../examples/keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../examples/util-crypto/">
<a href="../examples/util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../examples/util-crypto/02_sign_verify_message_nacl/">
<a href="../examples/util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >trie-db</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="polkadottrie-db">@polkadot/trie-db</h1>
<p>A re-implementation of a Patricia Trie. Unlike other implementations, this allows for the specification of a hash function as well as encoder/decoder and operates in a sync fashion by default.</p>
<p>This is a JavaScript port of the <a href="https://github.com/ethereum/py-trie" target="_blank">Python Ethereum Trie</a> with additions to support transactions (checkpoints) and multiple codecs, by default only the Substrate codec.</p>
<h2 id="usage">Usage</h2>
<p>Installation -</p>
<pre><code>yarn add @polkadot/trie-db
</code></pre><p>Classes can be imported as follows:</p>
<pre><code class="lang-js"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span>&#xA0;<span class="sunlight-ident">Trie</span>&#xA0;<span class="sunlight-ident">from</span>&#xA0;<span class="sunlight-string">&apos;@polkadot/trie-db&apos;</span><span class="sunlight-punctuation">;</span>&#xA0;<span class="sunlight-comment">//&#xA0;Default&#xA0;export</span>
</span></pre></div></div></code></pre>
<h2 id="documentation-and-available-utilities">Documentation and Available Utilities</h2>
<p>Below is a list of currently exposed methods published at the <a href="https://polkadot.js.org/common/trie-db/" target="_blank">Polkadot-JS Common Documentation Portal</a>.</p>
<ul>
<li><a href="https://polkadot.js.org/common/trie-db/README.md" target="_blank">trie-db</a><ul>
<li>Classes<ul>
<li><a href="https://polkadot.js.org/common/trie-db/classes/_index_.trie.md" target="_blank">Trie</a></li>
</ul>
</li>
<li>Functions<ul>
<li>Util<ul>
<li><a href="https://polkadot.js.org/common/trie-db/modules/_util_is_.md" target="_blank">is</a></li>
<li><a href="https://polkadot.js.org/common/trie-db/modules/_util_key_.md" target="_blank">key</a></li>
<li><a href="https://polkadot.js.org/common/trie-db/modules/_util_nibbles_.md" target="_blank">nibbles</a></li>
<li><a href="https://polkadot.js.org/common/trie-db/modules/_util_node_.md" target="_blank">node</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../keyring/" class="navigation navigation-prev " aria-label="Previous page: keyring">
<i class="fa fa-angle-left"></i>
</a>
<a href="../trie-hash/" class="navigation navigation-next " aria-label="Next page: trie-hash">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"trie-db","level":"1.3","depth":1,"next":{"title":"trie-hash","level":"1.4","depth":1,"path":"trie-hash/README.md","ref":"trie-hash/README.md","articles":[]},"previous":{"title":"keyring","level":"1.2","depth":1,"path":"keyring/README.md","ref":"keyring/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"trie-db/README.md","mtime":"2019-02-25T16:08:40.339Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
-441
View File
@@ -1,441 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>trie-hash · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../util/" />
<link rel="prev" href="../trie-db/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../keyring/">
<a href="../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../trie-db/">
<a href="../trie-db/">
trie-db
</a>
</li>
<li class="chapter active" data-level="1.4" data-path="./">
<a href="./">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../util/">
<a href="../util/">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../util-crypto/">
<a href="../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../examples/keyring/">
<a href="../examples/keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../examples/keyring/01_create_account/">
<a href="../examples/keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../examples/keyring/02_load_accounts/">
<a href="../examples/keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../examples/util-crypto/">
<a href="../examples/util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../examples/util-crypto/02_sign_verify_message_nacl/">
<a href="../examples/util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >trie-hash</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="polkadottrie-hash">@polkadot/trie-hash</h1>
<p>Calculate ordered and unordered <a href="https://github.com/ethereum/wiki/wiki/Patricia-Tree" target="_blank">Trie hashes</a> from inputs.</p>
<h2 id="usage">Usage</h2>
<p>Installation -</p>
<pre><code>yarn add @polkadot/trie-hash
</code></pre><p>Functions can be imported as follows:</p>
<pre><code class="lang-js"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">trieRoot</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-ident">from</span>&#xA0;<span class="sunlight-string">&apos;@polkadot/trie-hash&apos;</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
<h2 id="documentation-and-available-utilities">Documentation and Available Utilities</h2>
<p>Below is a list of currently exposed methods published at the <a href="https://polkadot.js.org/common/trie-hash/" target="_blank">Polkadot-JS Common Documentation Portal</a>.</p>
<ul>
<li><a href="https://polkadot.js.org/common/trie-hash/README.md" target="_blank">trie-hash</a><ul>
<li>Functions<ul>
<li><a href="https://polkadot.js.org/common/trie-hash/modules/_trieroot_.md" target="_blank">trieRoot</a></li>
<li><a href="https://polkadot.js.org/common/trie-hash/modules/_trierootordered_.md" target="_blank">trieRootOrdered</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../trie-db/" class="navigation navigation-prev " aria-label="Previous page: trie-db">
<i class="fa fa-angle-left"></i>
</a>
<a href="../util/" class="navigation navigation-next " aria-label="Next page: util">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"trie-hash","level":"1.4","depth":1,"next":{"title":"util","level":"1.5","depth":1,"path":"util/README.md","ref":"util/README.md","articles":[]},"previous":{"title":"trie-db","level":"1.3","depth":1,"path":"trie-db/README.md","ref":"trie-db/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"trie-hash/README.md","mtime":"2019-02-25T16:08:47.979Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
-535
View File
@@ -1,535 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>util-crypto · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../examples/keyring/" />
<link rel="prev" href="../util/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../keyring/">
<a href="../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../trie-db/">
<a href="../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../trie-hash/">
<a href="../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter " data-level="1.5" data-path="../util/">
<a href="../util/">
util
</a>
</li>
<li class="chapter active" data-level="1.6" data-path="./">
<a href="./">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../examples/keyring/">
<a href="../examples/keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../examples/keyring/01_create_account/">
<a href="../examples/keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../examples/keyring/02_load_accounts/">
<a href="../examples/keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../examples/util-crypto/">
<a href="../examples/util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../examples/util-crypto/02_sign_verify_message_nacl/">
<a href="../examples/util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >util-crypto</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="polkadotutil-crypto">@polkadot/util-crypto</h1>
<p>Various useful cyrpto utility functions that are used across all projects in the <a href="https://polkadot.js.org" target="_blank">@polkadot</a> namespace. It provides utility functions with additional safety checks, allowing not only for consistent coding, but also reducing the general boilerplate.</p>
<h2 id="usage">Usage</h2>
<p>Installation -</p>
<pre><code>yarn add @polkadot/util-crypto
</code></pre><p>Functions can be imported as follows:</p>
<pre><code class="lang-js"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">mnemonicGenerate</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-ident">from</span>&#xA0;<span class="sunlight-string">&apos;@polkadot/util-crypto&apos;</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
<h2 id="documentation-and-available-utilities">Documentation and Available Utilities</h2>
<p>Below is a list of currently exposed methods published at the <a href="https://polkadot.js.org/common/util-crypto/" target="_blank">Polkadot-JS Common Documentation Portal</a>.</p>
<ul>
<li><a href="https://polkadot.js.org/common/util-crypto/README.md" target="_blank">util-crypto</a><ul>
<li>Functions<ul>
<li>Blake2b<ul>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_blake2_ashex_.md" target="_blank">blake2AsHex</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_blake2_asu8a_.md" target="_blank">blake2AsU8a</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_blake2_blake2b_ashex_.md" target="_blank">blake2bAsHex</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_blake2_blake2b_asu8a_.md" target="_blank">blake2bAsU8a</a></li>
</ul>
</li>
<li>Keccak<ul>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_keccak_ashex_.md" target="_blank">keccakAsHex</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_keccak_asu8a_.md" target="_blank">keccakAsU8a</a></li>
</ul>
</li>
<li>Mnemonic<ul>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_mnemonic_generate_.md" target="_blank">mnemonicGenerate</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_mnemonic_toseed_.md" target="_blank">mnemonicToSeed</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_mnemonic_validate_.md" target="_blank">mnemonicValidate</a></li>
</ul>
</li>
<li>Nacl<ul>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_nacl_decrypt_.md" target="_blank">naclDecrypt</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_nacl_encrypt_.md" target="_blank">naclEncrypt</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_nacl_keypair_fromrandom_.md" target="_blank">naclKeypairFromRandom</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_nacl_keypair_fromsecret_.md" target="_blank">naclKeypairFromSecret</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_nacl_keypair_fromseed_.md" target="_blank">naclKeypairFromSeed</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_nacl_keypair_fromstring_.md" target="_blank">naclKeypairFromString</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_nacl_sign_.md" target="_blank">naclSign</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_nacl_verify_.md" target="_blank">naclVerify</a></li>
</ul>
</li>
<li>Random<ul>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_random_ashex_.md" target="_blank">randomAsHex</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_random_asnumber_.md" target="_blank">randomAsNumber</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_random_asu8a_.md" target="_blank">randomAsU8a</a></li>
</ul>
</li>
<li>SHA-512<ul>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_sha512_asu8a_.md" target="_blank">sha512AsU8a</a></li>
</ul>
</li>
<li>xxHash<ul>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_xxhash_ashex_.md" target="_blank">xxhashAsHex</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_xxhash_asu8a_.md" target="_blank">xxhashAsU8a</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_xxhash_xxhash64_asbn_.md" target="_blank">xxhash64AsBn</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_xxhash_xxhash64_ashex_.md" target="_blank">xxhash64AsHex</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_xxhash_xxhash64_asraw_.md" target="_blank">xxhash64AsRaw</a></li>
<li><a href="https://polkadot.js.org/common/util-crypto/modules/_xxhash_xxhash64_asvalue_.md" target="_blank">xxhash64AsValue</a></li>
</ul>
</li>
</ul>
</li>
</ul>
</li>
</ul>
<h3 id="blake2b">Blake2b</h3>
<ul>
<li>Creates a blake2b u8a output containing a hash from a u8a input bytes using given bit-length or default bit-length of 256. An optional key u8a of up to 64 bytes may be provided</li>
<li>Creates a blake2b hex string with optionally specified bit-length from the u8a input or default bit-length used is 256</li>
<li>Uses the <a href="https://blake2.net/" target="_blank">Blake2b</a> hash function of <a href="https://www.npmjs.com/package/blakejs" target="_blank">blakejs</a> library</li>
<li>Note: All hashes used in Polkadot-JS are 32 bytes (i.e. 256 / 8)</li>
<li>Note: BLAKE hash functions are in the Nacl library</li>
<li>Note: Only handles up to 2**53 bytes of input</li>
</ul>
<h3 id="keccak">Keccak</h3>
<ul>
<li>Creates a Keccak-256 hex string from the input (such as for conversion from seed phrase)</li>
<li>Creates a Keccak-256 Uint8Array from the input</li>
<li>Uses the Keccak-256 hash function from the <a href="https://www.npmjs.com/package/js-sha3" target="_blank">js-sha3</a> library</li>
</ul>
<h3 id="mnemonic">Mnemonic</h3>
<ul>
<li>Generate valid mnemonics (for account seed phrase) using <a href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki" target="_blank">BIP39</a></li>
<li>Converts mnemonics to a valid seed secret with Uint8Array output</li>
</ul>
<h3 id="nacl">Nacl</h3>
<ul>
<li>Implements <a href="http://nacl.cr.yp.to/" target="_blank">NaCl</a> secret-key authenticated encryption, public-key authenticated encryption, hashing, and public-key signatures</li>
<li>Decrypts a message that has been encrypted with a secret key using Nacl</li>
<li>Encrypts a message with a secret key and generates an associated nonce using Nacl</li>
<li>Signing a message with a secret key to generate a valid signature using Nacl</li>
<li>Verifies a signed message by providing the message, signature, and public key (associated with the secret key that signed it) using Nacl</li>
</ul>
<h3 id="random">Random</h3>
<ul>
<li>Returns a sequence of secure random bytes in a variety of formats</li>
<li>Creates a u8a with a specified (optional) bit-length (default 32) filled with random bytes</li>
<li>Creates a hex string with a specified (optional) bit-length (default 32) filled with random bytes</li>
<li>Creates a random number from random secure bytes</li>
</ul>
<h3 id="sha-512">SHA-512</h3>
<ul>
<li>Implements SHA-512 hashing functions for a variety of input and outputs</li>
<li>Creates a SHA-512 hash of u8a input</li>
<li>Uses the SHA-512 hash function of <a href="https://www.npmjs.com/package/tweetnacl" target="_blank">tweetnacl</a> library</li>
</ul>
<h3 id="xxhash">xxHash</h3>
<ul>
<li>Create xxhash64 values with specified bitlengths</li>
<li>Creates a xxhash64 u8a from the input with a specified (optional) bit-length (default 64)</li>
<li>Creates a xxhash64 hex string from the input with a specified (optional) bit-length (default 64)</li>
<li>Uses <a href="http://cyan4973.github.io/xxHash/" target="_blank">xxHash</a> to generate values as BN, hex &amp; number output</li>
</ul>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../util/" class="navigation navigation-prev " aria-label="Previous page: util">
<i class="fa fa-angle-left"></i>
</a>
<a href="../examples/keyring/" class="navigation navigation-next " aria-label="Next page: Keyring">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"util-crypto","level":"1.6","depth":1,"next":{"title":"Keyring","level":"2.1","depth":1,"path":"examples/keyring/README.md","ref":"examples/keyring/README.md","articles":[{"title":"Create Account","level":"2.1.1","depth":2,"path":"examples/keyring/01_create_account/README.md","ref":"examples/keyring/01_create_account/README.md","articles":[]},{"title":"Load Accounts","level":"2.1.2","depth":2,"path":"examples/keyring/02_load_accounts/README.md","ref":"examples/keyring/02_load_accounts/README.md","articles":[]}]},"previous":{"title":"util","level":"1.5","depth":1,"path":"util/README.md","ref":"util/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"util-crypto/README.md","mtime":"2019-02-25T16:09:03.968Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>
-466
View File
@@ -1,466 +0,0 @@
<!DOCTYPE HTML>
<html lang="" >
<head>
<meta charset="UTF-8">
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
<title>util · Polkadot Common Book</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="description" content="">
<meta name="generator" content="GitBook 3.2.3">
<link rel="stylesheet" href="../gitbook/style.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-insert-logo-link/plugin.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-sunlight-highlighter/sunlight.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
<link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
<link rel="stylesheet" href="../styles/website.css">
<meta name="HandheldFriendly" content="true"/>
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black">
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
<link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">
<link rel="next" href="../util-crypto/" />
<link rel="prev" href="../trie-hash/" />
</head>
<body>
<div class="book">
<div class="book-summary">
<div id="book-search-input" role="search">
<input type="text" placeholder="Type to search" />
</div>
<nav role="navigation">
<ul class="summary">
<li class="header">Packages</li>
<li class="chapter " data-level="1.1" data-path="../">
<a href="../">
Introduction
</a>
</li>
<li class="chapter " data-level="1.2" data-path="../keyring/">
<a href="../keyring/">
keyring
</a>
</li>
<li class="chapter " data-level="1.3" data-path="../trie-db/">
<a href="../trie-db/">
trie-db
</a>
</li>
<li class="chapter " data-level="1.4" data-path="../trie-hash/">
<a href="../trie-hash/">
trie-hash
</a>
</li>
<li class="chapter active" data-level="1.5" data-path="./">
<a href="./">
util
</a>
</li>
<li class="chapter " data-level="1.6" data-path="../util-crypto/">
<a href="../util-crypto/">
util-crypto
</a>
</li>
<li class="header">Examples</li>
<li class="chapter " data-level="2.1" data-path="../examples/keyring/">
<a href="../examples/keyring/">
Keyring
</a>
<ul class="articles">
<li class="chapter " data-level="2.1.1" data-path="../examples/keyring/01_create_account/">
<a href="../examples/keyring/01_create_account/">
Create Account
</a>
</li>
<li class="chapter " data-level="2.1.2" data-path="../examples/keyring/02_load_accounts/">
<a href="../examples/keyring/02_load_accounts/">
Load Accounts
</a>
</li>
</ul>
</li>
<li class="chapter " data-level="2.2" data-path="../examples/util-crypto/">
<a href="../examples/util-crypto/">
Util-Crypto
</a>
<ul class="articles">
<li class="chapter " data-level="2.2.1" data-path="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
<a href="../examples/util-crypto/01_encrypt_decrypt_message_nacl/">
Encrypt & Decrypt Message
</a>
</li>
<li class="chapter " data-level="2.2.2" data-path="../examples/util-crypto/02_sign_verify_message_nacl/">
<a href="../examples/util-crypto/02_sign_verify_message_nacl/">
Sign & Verify Message
</a>
</li>
<li class="chapter " data-level="2.2.3" data-path="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
<a href="../examples/util-crypto/03_mnemonic_generate_validate_bip39/">
Create & Validate Mnemonic
</a>
</li>
</ul>
</li>
<li class="divider"></li>
<li>
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
Published with GitBook
</a>
</li>
</ul>
</nav>
</div>
<div class="book-body">
<div class="body-inner">
<div class="book-header" role="navigation">
<!-- Title -->
<h1>
<i class="fa fa-circle-o-notch fa-spin"></i>
<a href=".." >util</a>
</h1>
</div>
<div class="page-wrapper" tabindex="-1" role="main">
<div class="page-inner">
<div id="book-search-results">
<div class="search-noresults">
<section class="normal markdown-section">
<h1 id="polkadotutil">@polkadot/util</h1>
<p>Various useful utility functions that are used across all projects in the <a href="https://polkadot.js.org" target="_blank">@polkadot</a> namespace. It provides utility functions with additional safety checks, allowing not only for consistent coding, but also reducing the general boilerplate.</p>
<h2 id="usage">Usage</h2>
<p>Installation -</p>
<pre><code>yarn add @polkadot/util
</code></pre><p>Functions can be imported directly from the package, e.g.</p>
<pre><code class="lang-js"><div class="sunlight-container sunlight-theme-gitbook"><div class="sunlight-code-container"><pre class="sunlight-highlight-javascript sunlight-highlighted"><span class="sunlight-javascript"><span class="sunlight-reservedWord">import</span>&#xA0;<span class="sunlight-punctuation">{</span>&#xA0;<span class="sunlight-ident">isHex</span>&#xA0;<span class="sunlight-punctuation">}</span>&#xA0;<span class="sunlight-ident">from</span>&#xA0;<span class="sunlight-string">&apos;@polkadot/util&apos;</span><span class="sunlight-punctuation">;</span>
</span></pre></div></div></code></pre>
<h2 id="documentation-and-available-utilities">Documentation and Available Utilities</h2>
<p>Below is a list of currently exposed methods published at the <a href="https://polkadot.js.org/common/util/" target="_blank">Polkadot-JS Common Documentation Portal</a>.</p>
<p>Utility methods for this package are split into groups, some of which are included in the list below:</p>
<ul>
<li><a href="https://polkadot.js.org/common/util/README.md" target="_blank">util</a><ul>
<li>Classes<ul>
<li><a href="https://polkadot.js.org/common/util/classes/_ext_error_.exterror.md" target="_blank">Error</a></li>
</ul>
</li>
<li>Functions<ul>
<li><a href="https://polkadot.js.org/common/util/modules/_array_filter_.md" target="_blank">arrayFilter</a></li>
<li><a href="https://polkadot.js.org/common/util/modules/_assert_.md" target="_blank">assert</a></li>
<li><a href="https://polkadot.js.org/common/util/modules/_logger_.md" target="_blank">logger</a></li>
<li><a href="https://polkadot.js.org/common/util/modules/_promisify_.md" target="_blank">promisify</a></li>
<li><a href="https://polkadot.js.org/common/util/modules/_syncify_.md" target="_blank">syncify</a></li>
</ul>
</li>
</ul>
</li>
</ul>
<p>Below is information about some of the available methods:</p>
<h3 id="assert">Assert</h3>
<ul>
<li>Checks for a valid test, if not <code>ExtError</code> is thrown</li>
</ul>
<h3 id="logger">Logger</h3>
<ul>
<li>Creates a consistent log interface for messages that has <code>.log</code>, <code>.error</code>, <code>.warn</code> and <code>.debug</code> (controlled with environment <code>DEBUG=typeA,typeB</code>) methods.</li>
</ul>
<h3 id="promisify">Promisify</h3>
<ul>
<li>Wraps a supplied asynchronous callback function into a Promise, passing supplied parameters. When <code>error</code> is set, the Promise is rejected, else the Promise resolves with the <code>result</code> value.</li>
</ul>
<h3 id="syncify">Syncify</h3>
<ul>
<li>This is currently for Node environments only.</li>
</ul>
</section>
</div>
<div class="search-results">
<div class="has-results">
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
<ul class="search-results-list"></ul>
</div>
<div class="no-results">
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
</div>
</div>
</div>
</div>
</div>
</div>
<a href="../trie-hash/" class="navigation navigation-prev " aria-label="Previous page: trie-hash">
<i class="fa fa-angle-left"></i>
</a>
<a href="../util-crypto/" class="navigation navigation-next " aria-label="Next page: util-crypto">
<i class="fa fa-angle-right"></i>
</a>
</div>
<script>
var gitbook = gitbook || [];
gitbook.push(function() {
gitbook.page.hasChanged({"page":{"title":"util","level":"1.5","depth":1,"next":{"title":"util-crypto","level":"1.6","depth":1,"path":"util-crypto/README.md","ref":"util-crypto/README.md","articles":[]},"previous":{"title":"trie-hash","level":"1.4","depth":1,"path":"trie-hash/README.md","ref":"trie-hash/README.md","articles":[]},"dir":"ltr"},"config":{"plugins":["include-codeblock","insert-logo-link","mermaid-gb3","-highlight","sunlight-highlighter"],"root":"docs","styles":{"website":"styles/website.css"},"pluginsConfig":{"insert-logo-link":{"src":"/common/logo.png","url":"https://polkadot.js.org"},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"fontsettings":{"theme":"white","family":"sans","size":2},"mermaid-gb3":{},"include-codeblock":{"check":false,"edit":false,"lang":"","fixlang":false,"template":"default","theme":"chrome","unindent":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false},"sunlight-highlighter":{"theme":"gitbook","lineNumbers":false}},"theme":"default","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"Polkadot Common Book","gitbook":">=2.4.0"},"file":{"path":"util/README.md","mtime":"2019-02-25T16:08:55.740Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-02-25T16:09:42.846Z"},"basePath":"..","book":{"language":""}});
});
</script>
</div>
<script src="../gitbook/gitbook.js"></script>
<script src="../gitbook/theme.js"></script>
<script src="../gitbook/gitbook-plugin-insert-logo-link/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/book/plugin.js"></script>
<script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
<script src="../gitbook/gitbook-plugin-search/search.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
<script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
<script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
<script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
<script src="../gitbook/gitbook-plugin-mermaid-gb3/mermaid/mermaid.min.js"></script>
</body>
</html>