Skip to content

Commit

Permalink
docs update
Browse files Browse the repository at this point in the history
  • Loading branch information
kjur committed May 21, 2024
1 parent c9fabe1 commit 0052b6d
Show file tree
Hide file tree
Showing 27 changed files with 228 additions and 74 deletions.
37 changes: 35 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,40 @@ The 'typepki-webcrypto' is W3C Web Crypto API [[1]](https://developer.mozilla.or

## FEATURE
- easy use for
- keypair generation
- keypair/key generation
- key import
- key export
- signing and verification
- PEM key format
- Dual CommonJS/ES module package supporting CommonJS(CJS) and ES modules

## Signing
The {@link signHex} function can sign a data with RSA, RSA-PSS and ECDSA algorithms very easily.

### RSA signing
Here is an example to sign a string "apple りんご":
```JavaScript
const pemPrivateKey = `-----BEGIN PRIVATE KEY-----
MI...
-----END PRIVATE KEY-----`;
(async () = {
const privateKey = await importPEM(pemPrivateKey, "SHA256withRSA");
const hexSignatureValue = await signHex("SHA256withRSA", privateKey, utf8tohex("apple りんご"));
})();
```
The [typepki-strconv] provide many functions convert any data to a hexadecimal string such as
ArrayBuffer, Base64, Base64URL or raw string.

## Signature Verification
The {@link verifyHex} function can verify a RSA, RSA-PSS and ECDSA signature very easily too.
```JavaScript
const pemPublicKey = `-----BEGIN PUBLIC KEY-----
MI...
-----END PRIVATE KEY-----`;
const hexSignature = "12ab...";
(async () = {
const publicKey = await importPEM(pemPublicKey, "SHA256withRSA");
const isValid = await verifyHex("SHA256withRSA", publicKey, hexSignature, utf8tohex("apple りんご"));
})();
```


39 changes: 23 additions & 16 deletions docs/assets/highlight.css
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
:root {
--light-hl-0: #AF00DB;
--dark-hl-0: #C586C0;
--light-hl-0: #0000FF;
--dark-hl-0: #569CD6;
--light-hl-1: #000000;
--dark-hl-1: #D4D4D4;
--light-hl-2: #795E26;
--dark-hl-2: #DCDCAA;
--light-hl-2: #0070C1;
--dark-hl-2: #4FC1FF;
--light-hl-3: #A31515;
--dark-hl-3: #CE9178;
--light-hl-4: #001080;
--dark-hl-4: #9CDCFE;
--light-hl-5: #008000;
--dark-hl-5: #6A9955;
--light-hl-6: #098658;
--dark-hl-6: #B5CEA8;
--light-hl-7: #EE0000;
--dark-hl-7: #D7BA7D;
--light-hl-8: #0000FF;
--dark-hl-8: #569CD6;
--light-hl-9: #CD3131;
--dark-hl-9: #F44747;
--light-hl-4: #795E26;
--dark-hl-4: #DCDCAA;
--light-hl-5: #001080;
--dark-hl-5: #9CDCFE;
--light-hl-6: #AF00DB;
--dark-hl-6: #C586C0;
--light-hl-7: #008000;
--dark-hl-7: #6A9955;
--light-hl-8: #098658;
--dark-hl-8: #B5CEA8;
--light-hl-9: #EE0000;
--dark-hl-9: #D7BA7D;
--light-hl-10: #CD3131;
--dark-hl-10: #F44747;
--light-code-background: #FFFFFF;
--dark-code-background: #1E1E1E;
}
Expand All @@ -34,6 +36,7 @@
--hl-7: var(--light-hl-7);
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--hl-10: var(--light-hl-10);
--code-background: var(--light-code-background);
} }

Expand All @@ -48,6 +51,7 @@
--hl-7: var(--dark-hl-7);
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--hl-10: var(--dark-hl-10);
--code-background: var(--dark-code-background);
} }

Expand All @@ -62,6 +66,7 @@
--hl-7: var(--light-hl-7);
--hl-8: var(--light-hl-8);
--hl-9: var(--light-hl-9);
--hl-10: var(--light-hl-10);
--code-background: var(--light-code-background);
}

Expand All @@ -76,6 +81,7 @@
--hl-7: var(--dark-hl-7);
--hl-8: var(--dark-hl-8);
--hl-9: var(--dark-hl-9);
--hl-10: var(--dark-hl-10);
--code-background: var(--dark-code-background);
}

Expand All @@ -89,4 +95,5 @@
.hl-7 { color: var(--hl-7); }
.hl-8 { color: var(--hl-8); }
.hl-9 { color: var(--hl-9); }
.hl-10 { color: var(--hl-10); }
pre, code { background: var(--code-background); }
2 changes: 1 addition & 1 deletion docs/assets/navigation.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion docs/assets/search.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions docs/functions/generateKeypairJWK.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
</ul>
<h4>Description</h4><p>This function generates a RFC 7517 JSON Web Key (JWK) RSA
or EC key pair by W3C Web Crypto API.</p>
<h4>Example</h4><pre><code class="language-ts"><span class="hl-0">await</span><span class="hl-1"> </span><span class="hl-2">generateKeyPairJWK</span><span class="hl-1">(</span><span class="hl-3">&quot;EC&quot;</span><span class="hl-1">) -&gt; [{</span><br/><span class="hl-1"> </span><span class="hl-4">kty:</span><span class="hl-1"> </span><span class="hl-3">&quot;EC&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">crv:</span><span class="hl-1"> </span><span class="hl-3">&quot;P-256&quot;</span><br/><span class="hl-1"> </span><span class="hl-4">d</span><span class="hl-1">: </span><span class="hl-3">&quot;...&quot;</span><br/><span class="hl-1"> ...</span><br/><span class="hl-1">},{</span><br/><span class="hl-1"> </span><span class="hl-4">kty:</span><span class="hl-1"> </span><span class="hl-3">&quot;EC&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">crv:</span><span class="hl-1"> </span><span class="hl-3">&quot;P-256&quot;</span><br/><span class="hl-1"> </span><span class="hl-4">x</span><span class="hl-1">: </span><span class="hl-3">&quot;...&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">y:</span><span class="hl-1"> </span><span class="hl-3">&quot;...&quot;</span><span class="hl-1">,</span><br/><span class="hl-1">}]</span>
<h4>Example</h4><pre><code class="language-ts"><span class="hl-6">await</span><span class="hl-1"> </span><span class="hl-4">generateKeyPairJWK</span><span class="hl-1">(</span><span class="hl-3">&quot;EC&quot;</span><span class="hl-1">) -&gt; [{</span><br/><span class="hl-1"> </span><span class="hl-5">kty:</span><span class="hl-1"> </span><span class="hl-3">&quot;EC&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-5">crv:</span><span class="hl-1"> </span><span class="hl-3">&quot;P-256&quot;</span><br/><span class="hl-1"> </span><span class="hl-5">d</span><span class="hl-1">: </span><span class="hl-3">&quot;...&quot;</span><br/><span class="hl-1"> ...</span><br/><span class="hl-1">},{</span><br/><span class="hl-1"> </span><span class="hl-5">kty:</span><span class="hl-1"> </span><span class="hl-3">&quot;EC&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-5">crv:</span><span class="hl-1"> </span><span class="hl-3">&quot;P-256&quot;</span><br/><span class="hl-1"> </span><span class="hl-5">x</span><span class="hl-1">: </span><span class="hl-3">&quot;...&quot;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-5">y:</span><span class="hl-1"> </span><span class="hl-3">&quot;...&quot;</span><span class="hl-1">,</span><br/><span class="hl-1">}]</span>
</code><button>Copy</button></pre>
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/kjur/typepki-webcrypto/blob/966dd79f113bf7a6aaf5243d3489f0eff4541f36/src/index.mts#L430">index.mts:430</a></li></ul></aside></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>typepki-webcrypto - v0.2.0</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
</div><aside class="tsd-sources"><ul><li>Defined in <a href="https://github.com/kjur/typepki-webcrypto/blob/c9fabe15fe71775b2e8a399ad151c6e1a7bb0f3c/src/index.mts#L502">index.mts:502</a></li></ul></aside></li></ul></section></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-index-accordion"><summary class="tsd-accordion-summary"><h3><svg width="20" height="20" viewBox="0 0 24 24" fill="none"><use href="../assets/icons.svg#icon-chevronDown"></use></svg>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><h4 class="uppercase">Member Visibility</h4><form><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-protected" name="protected"/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Protected</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li></ul></form></div><div class="tsd-theme-toggle"><h4 class="uppercase">Theme</h4><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div></div><div class="site-menu"><nav class="tsd-navigation"><a href="../modules.html"><svg class="tsd-kind-icon" viewBox="0 0 24 24"><use href="../assets/icons.svg#icon-1"></use></svg><span>typepki-webcrypto - v0.2.0</span></a><ul class="tsd-small-nested-navigation" id="tsd-nav-container" data-base=".."><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
Loading

0 comments on commit 0052b6d

Please sign in to comment.