mirror of
https://github.com/fluencelabs/js-libp2p-crypto
synced 2025-03-16 00:30:59 +00:00
584 lines
14 KiB
HTML
584 lines
14 KiB
HTML
<!doctype html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset='utf-8'>
|
|
<title>libp2p-crypto 0.17.8 | Documentation</title>
|
|
<meta name='description' content='Crypto primitives for libp2p'>
|
|
<meta name='viewport' content='width=device-width,initial-scale=1'>
|
|
<link href='assets/bass.css' rel='stylesheet'>
|
|
<link href='assets/style.css' rel='stylesheet'>
|
|
<link href='assets/github.css' rel='stylesheet'>
|
|
<link href='assets/split.css' rel='stylesheet'>
|
|
</head>
|
|
<body class='documentation m0'>
|
|
<div class='flex'>
|
|
<div id='split-left' class='overflow-auto fs0 height-viewport-100'>
|
|
<div class='py1 px2'>
|
|
<h3 class='mb0 no-anchor'>libp2p-crypto</h3>
|
|
<div class='mb1'><code>0.17.8</code></div>
|
|
<input
|
|
placeholder='Filter'
|
|
id='filter-input'
|
|
class='col12 block input'
|
|
spellcheck='false'
|
|
autocapitalize='off'
|
|
autocorrect='off'
|
|
type='text' />
|
|
<div id='toc'>
|
|
<ul class='list-reset h5 py1-ul'>
|
|
|
|
|
|
<li><a
|
|
href='#intro'
|
|
class="h5 bold black caps">
|
|
Intro
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
|
|
<li><a
|
|
href='#id'
|
|
class="">
|
|
id
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
|
|
<li><a
|
|
href='#export'
|
|
class="">
|
|
export
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
|
|
<li><a
|
|
href='#keypair'
|
|
class="">
|
|
keypair
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
|
|
<li><a
|
|
href='#id'
|
|
class="">
|
|
id
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
|
|
<li><a
|
|
href='#id'
|
|
class="">
|
|
id
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
|
|
<li><a
|
|
href='#pbkdf2'
|
|
class="">
|
|
pbkdf2
|
|
|
|
</a>
|
|
|
|
</li>
|
|
|
|
</ul>
|
|
</div>
|
|
<div class='mt1 h6 quiet'>
|
|
<a href='https://documentation.js.org/reading-documentation.html'>Need help reading this?</a>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<div id='split-right' class='relative overflow-auto height-viewport-100'>
|
|
|
|
|
|
<div class='keyline-top-not py2'><section class='py2 clearfix'>
|
|
|
|
<h2 id='intro' class='mt0'>
|
|
Intro
|
|
</h2>
|
|
|
|
|
|
<p>Installable via <code>npm install --save libp2p-crypto</code>, it can also be used directly in the browser.</p>
|
|
<h2>Download</h2>
|
|
<p>The source is available for download from <a href="https://github.com/libp2p/js-libp2p-crypto.git">GitHub</a>. Alternatively, you can install using npm:</p>
|
|
<pre class='hljs'>$ npm install --save libp2p-crypto</pre>
|
|
<p>You can then <code>require()</code> libp2p-crypto as normal:</p>
|
|
<pre class='hljs'><span class="hljs-keyword">const</span> libp2PCrypto = <span class="hljs-built_in">require</span>(<span class="hljs-string">'libp2p-crypto'</span>)</pre>
|
|
<h2>In the Browser</h2>
|
|
<p><code>libp2p-crypto</code> should work in any ECMAScript 2018 environment out of the box.</p>
|
|
<p>Usage:</p>
|
|
<pre class='hljs'><span class="hljs-tag"><<span class="hljs-name">script</span> <span class="hljs-attr">type</span>=<span class="hljs-string">"text/javascript"</span> <span class="hljs-attr">src</span>=<span class="hljs-string">"index.js"</span>></span><span class="hljs-tag"></<span class="hljs-name">script</span>></span></pre>
|
|
<p>The portable versions of <code>libp2p-crypto</code>, including <code>index.js</code> and <code>index.min.js</code>, are included in the <code>/dist</code> folder. <code>libp2p-crypto</code> can also be found on <a href="https://unpkg.com">unpkg.com</a> under</p>
|
|
<ul>
|
|
<li><a href="https://unpkg.com/libp2p-crypto/dist/index.min.js">https://unpkg.com/libp2p-crypto/dist/index.min.js</a></li>
|
|
<li><a href="https://unpkg.com/libp2p-crypto/dist/index.js">https://unpkg.com/libp2p-crypto/dist/index.js</a></li>
|
|
</ul>
|
|
|
|
|
|
</section></div>
|
|
|
|
|
|
|
|
<section class='p2 mb2 clearfix bg-white minishadow'>
|
|
|
|
|
|
<div class='clearfix'>
|
|
|
|
<h3 class='fl m0' id='id'>
|
|
id
|
|
</h3>
|
|
|
|
|
|
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-crypto/blob/609297be65ceaf98b9cfb295bc9334276dccd659/src/keys/rsa-class.js#L103-L106'>
|
|
<span>src/keys/rsa-class.js</span>
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
|
<p>Gets the ID of the key.</p>
|
|
<p>The key id is the base58 encoding of the SHA-256 multihash of its public key.
|
|
The public key is a protobuf encoding containing a type and the DER encoding
|
|
of the PKCS SubjectPublicKeyInfo.</p>
|
|
|
|
<div class='pre p1 fill-light mt0'>id(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class='py1 quiet mt1 prose-big'>Returns</div>
|
|
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>></code>:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section class='p2 mb2 clearfix bg-white minishadow'>
|
|
|
|
|
|
<div class='clearfix'>
|
|
|
|
<h3 class='fl m0' id='export'>
|
|
export
|
|
</h3>
|
|
|
|
|
|
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-crypto/blob/609297be65ceaf98b9cfb295bc9334276dccd659/src/keys/rsa-class.js#L114-L134'>
|
|
<span>src/keys/rsa-class.js</span>
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
|
<p>Exports the key into a password protected PEM format</p>
|
|
|
|
<div class='pre p1 fill-light mt0'>export(password: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, format: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>?)</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class='py1 quiet mt1 prose-big'>Parameters</div>
|
|
<div class='prose'>
|
|
|
|
<div class='space-bottom0'>
|
|
<div>
|
|
<span class='code bold'>password</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code>
|
|
The password to read the encrypted PEM
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class='space-bottom0'>
|
|
<div>
|
|
<span class='code bold'>format</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>?
|
|
= <code>'pkcs-8'</code>)</code>
|
|
Defaults to 'pkcs-8'.
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section class='p2 mb2 clearfix bg-white minishadow'>
|
|
|
|
|
|
<div class='clearfix'>
|
|
|
|
<h3 class='fl m0' id='keypair'>
|
|
keypair
|
|
</h3>
|
|
|
|
|
|
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-crypto/blob/609297be65ceaf98b9cfb295bc9334276dccd659/src/keys/rsa.js#L10-L10'>
|
|
<span>src/keys/rsa.js</span>
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class='pre p1 fill-light mt0'>keypair</div>
|
|
|
|
<p>
|
|
Type:
|
|
PrivateKey
|
|
</p>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section class='p2 mb2 clearfix bg-white minishadow'>
|
|
|
|
|
|
<div class='clearfix'>
|
|
|
|
<h3 class='fl m0' id='id'>
|
|
id
|
|
</h3>
|
|
|
|
|
|
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-crypto/blob/609297be65ceaf98b9cfb295bc9334276dccd659/src/keys/ed25519-class.js#L85-L88'>
|
|
<span>src/keys/ed25519-class.js</span>
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
|
<p>Gets the ID of the key.</p>
|
|
<p>The key id is the base58 encoding of the SHA-256 multihash of its public key.
|
|
The public key is a protobuf encoding containing a type and the DER encoding
|
|
of the PKCS SubjectPublicKeyInfo.</p>
|
|
|
|
<div class='pre p1 fill-light mt0'>id(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class='py1 quiet mt1 prose-big'>Returns</div>
|
|
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">String</a>></code>:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section class='p2 mb2 clearfix bg-white minishadow'>
|
|
|
|
|
|
<div class='clearfix'>
|
|
|
|
<h3 class='fl m0' id='id'>
|
|
id
|
|
</h3>
|
|
|
|
|
|
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-crypto/blob/609297be65ceaf98b9cfb295bc9334276dccd659/src/keys/secp256k1-class.js#L83-L86'>
|
|
<span>src/keys/secp256k1-class.js</span>
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
|
<p>Gets the ID of the key.</p>
|
|
<p>The key id is the base58 encoding of the SHA-256 multihash of its public key.
|
|
The public key is a protobuf encoding containing a type and the DER encoding
|
|
of the PKCS SubjectPublicKeyInfo.</p>
|
|
|
|
<div class='pre p1 fill-light mt0'>id(): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class='py1 quiet mt1 prose-big'>Returns</div>
|
|
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Promise">Promise</a><<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>></code>:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section class='p2 mb2 clearfix bg-white minishadow'>
|
|
|
|
|
|
<div class='clearfix'>
|
|
|
|
<h3 class='fl m0' id='pbkdf2'>
|
|
pbkdf2
|
|
</h3>
|
|
|
|
|
|
<a class='fr fill-darken0 round round pad1x quiet h5' href='https://github.com/libp2p/js-libp2p-crypto/blob/609297be65ceaf98b9cfb295bc9334276dccd659/src/pbkdf2.js#L30-L43'>
|
|
<span>src/pbkdf2.js</span>
|
|
</a>
|
|
|
|
</div>
|
|
|
|
|
|
<p>Computes the Password-Based Key Derivation Function 2.</p>
|
|
|
|
<div class='pre p1 fill-light mt0'>pbkdf2(password: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, salt: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>, iterations: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, keySize: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>, hash: <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>): <a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class='py1 quiet mt1 prose-big'>Parameters</div>
|
|
<div class='prose'>
|
|
|
|
<div class='space-bottom0'>
|
|
<div>
|
|
<span class='code bold'>password</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class='space-bottom0'>
|
|
<div>
|
|
<span class='code bold'>salt</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class='space-bottom0'>
|
|
<div>
|
|
<span class='code bold'>iterations</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</code>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class='space-bottom0'>
|
|
<div>
|
|
<span class='code bold'>keySize</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/Number">number</a>)</code>
|
|
(in bytes)
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
<div class='space-bottom0'>
|
|
<div>
|
|
<span class='code bold'>hash</span> <code class='quiet'>(<a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a>)</code>
|
|
The hash name ('sha1', 'sha2-512, ...)
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<div class='py1 quiet mt1 prose-big'>Returns</div>
|
|
<code><a href="https://developer.mozilla.org/docs/Web/JavaScript/Reference/Global_Objects/String">string</a></code>:
|
|
A new password
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
</div>
|
|
</div>
|
|
<script src='assets/anchor.js'></script>
|
|
<script src='assets/split.js'></script>
|
|
<script src='assets/site.js'></script>
|
|
</body>
|
|
</html>
|