Swap docs to use vuepress (#330)
* Play around, vuepress docs * Cleanup old * Build * Round out updates
This commit is contained in:
@@ -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">// Import Keyring class and utility function</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">Keyring</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/keyring'</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> <span class="sunlight-ident">stringToU8a</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/util/string/toU8a'</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> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-comment">// Create account seed for Alice</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">ALICE_SEED</span> <span class="sunlight-operator">=</span> <span class="sunlight-string">'Alice'</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> <span class="sunlight-string">' '</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Create an instance of the Keyring</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">keyring</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">Keyring</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Create pair and add Alice to keyring pair dictionary (with account seed)</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">pairAlice</span> <span class="sunlight-operator">=</span> <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>
|
||||
|
||||
  <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> <span class="sunlight-ident">keyring</span> <span class="sunlight-ident">pair</span> <span class="sunlight-keyword">for</span> <span class="sunlight-ident">Alice</span> <span class="sunlight-keyword">with</span> <span class="sunlight-ident">address</span><span class="sunlight-operator">:</span> <span class="sunlight-punctuation">`</span> <span class="sunlight-operator">+</span>
|
||||
              <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> <span class="sunlight-operator">=</span><span class="sunlight-operator">></span> <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">// Import Keyring class and utility function</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">Keyring</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/keyring'</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> <span class="sunlight-ident">stringToU8a</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/util/string/toU8a'</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> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-comment">// Create account seed for Alice and Bob</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">ALICE_SEED</span> <span class="sunlight-operator">=</span> <span class="sunlight-string">'Alice'</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> <span class="sunlight-string">' '</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">BOB_SEED</span> <span class="sunlight-operator">=</span> <span class="sunlight-string">'Bob'</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> <span class="sunlight-string">' '</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Create an instance of the Keyring</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">keyring</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <span class="sunlight-ident">Keyring</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Create their pairs with account seeds. Add to keyring pair dictionary</span>
|
||||
  <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>
|
||||
  <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>
|
||||
|
||||
  <span class="sunlight-comment">// Note that we did not use `addFromAddress` since it does not add the</span>
|
||||
  <span class="sunlight-comment">// secret key to memory so we cannot later retrieve it with `getPairs`</span>
|
||||
|
||||
  <span class="sunlight-comment">// Retrieve all keyring pairs from the keyring pair dictionary</span>
|
||||
  <span class="sunlight-ident">keyring</span>
|
||||
    <span class="sunlight-operator">.</span><span class="sunlight-ident">getPairs</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span>
|
||||
    <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> <span class="sunlight-ident">index</span><span class="sunlight-punctuation">)</span> <span class="sunlight-operator">=</span><span class="sunlight-operator">></span> <span class="sunlight-punctuation">{</span>
|
||||
      <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">address</span> <span class="sunlight-operator">=</span> <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>
|
||||
|
||||
      <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> <span class="sunlight-keyword">with</span> <span class="sunlight-ident">index</span> <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> <span class="sunlight-ident">has</span> <span class="sunlight-ident">json</span><span class="sunlight-operator">:</span> <span class="sunlight-punctuation">`</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">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> <span class="sunlight-keyword">null</span><span class="sunlight-punctuation">,</span> <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><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> <span class="sunlight-operator">=</span><span class="sunlight-operator">></span> <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>
|
||||
|
||||
@@ -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 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 & Decrypt Message using NaCl</h1>
|
||||
<p>The following example shows how to encrypt and decrypt a message with NaCl (pronouced "salt"), 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> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">naclEncrypt</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">naclDecrypt</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/util-crypto'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">async</span> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">secret</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <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>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">messagePreEncryption</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <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> <span class="sunlight-number">2</span><span class="sunlight-punctuation">,</span> <span class="sunlight-number">3</span><span class="sunlight-punctuation">,</span> <span class="sunlight-number">4</span><span class="sunlight-punctuation">,</span> <span class="sunlight-number">5</span><span class="sunlight-punctuation">,</span> <span class="sunlight-number">4</span><span class="sunlight-punctuation">,</span> <span class="sunlight-number">3</span><span class="sunlight-punctuation">,</span> <span class="sunlight-number">2</span><span class="sunlight-punctuation">,</span> <span class="sunlight-number">1</span><span class="sunlight-punctuation">]</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">noncePreEncryption</span> <span class="sunlight-operator">=</span> <span class="sunlight-keyword">new</span> <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>
|
||||
|
||||
  <span class="sunlight-comment">// Encrypt the message</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">nonce</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">naclEncrypt</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">messagePreEncryption</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">secret</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">noncePreEncryption</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Show contents of the encrypted message</span>
|
||||
  <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> <span class="sunlight-ident">message</span><span class="sunlight-operator">:</span> <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> <span class="sunlight-keyword">null</span><span class="sunlight-punctuation">,</span> <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>
|
||||
|
||||
  <span class="sunlight-comment">// Decrypt the message</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">messageDecrypted</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">naclDecrypt</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">nonce</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">secret</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
  <span class="sunlight-comment">// Convert each Uint8Array to a string for comparison</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">isMatch</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">messagePreEncryption</span><span class="sunlight-operator">.</span><span class="sunlight-ident">toString</span> <span class="sunlight-operator">===</span> <span class="sunlight-ident">messageDecrypted</span><span class="sunlight-operator">.</span><span class="sunlight-ident">toString</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Verify that the decrypted message matches the original message</span>
|
||||
  <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> <span class="sunlight-ident">the</span> <span class="sunlight-ident">decrypted</span> <span class="sunlight-ident">message</span> <span class="sunlight-ident">match</span> <span class="sunlight-ident">the</span> <span class="sunlight-ident">original</span> <span class="sunlight-ident">message</span><span class="sunlight-operator">?</span> <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> <span class="sunlight-operator">=</span><span class="sunlight-operator">></span> <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 & Verify Message using NaCl</h1>
|
||||
<p>The following example shows how to sign and verify a message with NaCl (pronouced "salt"), 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> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">stringToU8a</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">u8aToHex</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/util'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
<span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">naclEncrypt</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">naclKeypairFromSeed</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">naclSign</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">naclVerify</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">randomAsU8a</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/util-crypto'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">async</span> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-comment">// Create account seed for Alice as fallback if generated mnemonic not valid</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">seedAlice</span> <span class="sunlight-operator">=</span> <span class="sunlight-string">'Alice'</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> <span class="sunlight-string">' '</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Generate new public/secret keypair for Alice from the supplied seed</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">secretKey</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">publicKey</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <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>
|
||||
|
||||
  <span class="sunlight-comment">// Encrypt message. Create Uint8Array's filled with random bytes of specified length</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">secret</span> <span class="sunlight-operator">=</span> <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>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">messagePreEncryption</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">stringToU8a</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'please send me DOTs'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">noncePreEncryption</span> <span class="sunlight-operator">=</span> <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>
|
||||
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">nonce</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">naclEncrypt</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">messagePreEncryption</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">secret</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">noncePreEncryption</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <span class="sunlight-comment">// Sign the message with a valid signature</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">messageSignature</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">naclSign</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">secretKey</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <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> <span class="sunlight-ident">signature</span><span class="sunlight-operator">:</span> <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>
|
||||
|
||||
  <span class="sunlight-comment">// Validate that the message was correctly signed</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">isValidSignature</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">naclVerify</span><span class="sunlight-punctuation">(</span><span class="sunlight-ident">encrypted</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">messageSignature</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">publicKey</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <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> <span class="sunlight-ident">the</span> <span class="sunlight-ident">message</span> <span class="sunlight-ident">correctly</span> <span class="sunlight-ident">signed</span><span class="sunlight-operator">?</span> <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> <span class="sunlight-operator">=</span><span class="sunlight-operator">></span> <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 & 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> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">mnemonicGenerate</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">mnemonicToSeed</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">mnemonicValidate</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">naclKeypairFromSeed</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">require</span><span class="sunlight-punctuation">(</span><span class="sunlight-string">'@polkadot/util-crypto'</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
<span class="sunlight-ident">async</span> <span class="sunlight-keyword">function</span> <span class="sunlight-named-ident">main</span> <span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span> <span class="sunlight-punctuation">{</span>
|
||||
  <span class="sunlight-comment">// Create mnemonic string for Alice using BIP39</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">mnemonicAlice</span> <span class="sunlight-operator">=</span> <span class="sunlight-ident">mnemonicGenerate</span><span class="sunlight-punctuation">(</span><span class="sunlight-punctuation">)</span><span class="sunlight-punctuation">;</span>
|
||||
|
||||
  <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> <span class="sunlight-ident">mnemonic</span><span class="sunlight-operator">:</span> <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>
|
||||
|
||||
  <span class="sunlight-comment">// Validate the mnemic string that was generated</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">isValidMnemonic</span> <span class="sunlight-operator">=</span> <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>
|
||||
|
||||
  <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> <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>
|
||||
|
||||
  <span class="sunlight-comment">// Create valid seed from mnemonic as u8a and convert it to a string</span>
|
||||
  <span class="sunlight-comment">// FIXME - Replace with mnemonicToSeed once exposed</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-ident">seedAlice</span> <span class="sunlight-operator">=</span> <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>
|
||||
|
||||
  <span class="sunlight-comment">// Generate new public/secret keypair for Alice from the supplied seed</span>
|
||||
  <span class="sunlight-reservedWord">const</span> <span class="sunlight-punctuation">{</span> <span class="sunlight-ident">secretKey</span><span class="sunlight-punctuation">,</span> <span class="sunlight-ident">publicKey</span> <span class="sunlight-punctuation">}</span> <span class="sunlight-operator">=</span> <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>
|
||||
|
||||
  <span class="sunlight-comment">// Encrypt, Sign and Validate the message. See Example 'Sign & Verify Message'</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> <span class="sunlight-operator">=</span><span class="sunlight-operator">></span> <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>
|
||||
|
||||
@@ -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 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>
|
||||
|
||||
Reference in New Issue
Block a user