Skip to content

Commit

Permalink
chore(docs): automated update typedocs after release
Browse files Browse the repository at this point in the history
  • Loading branch information
connorjburton committed Mar 13, 2022
1 parent bb89417 commit dc3b8f3
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 13 deletions.
2 changes: 1 addition & 1 deletion docs/assets/main.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion docs/classes/AuthError.html

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ <h2>Generating your HMAC digest</h2>
<pre><code class="language-javascript"><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">crypto</span><span class="hl-1"> = </span><span class="hl-3">require</span><span class="hl-1">(</span><span class="hl-4">&#39;crypto&#39;</span><span class="hl-1">);</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">hmac</span><span class="hl-1"> = </span><span class="hl-6">crypto</span><span class="hl-1">.</span><span class="hl-3">createHmac</span><span class="hl-1">(</span><span class="hl-4">&#39;sha256&#39;</span><span class="hl-1">, </span><span class="hl-4">&#39;secret&#39;</span><span class="hl-1">);</span><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">time</span><span class="hl-1"> = </span><span class="hl-9">Date</span><span class="hl-1">.</span><span class="hl-3">now</span><span class="hl-1">().</span><span class="hl-3">toString</span><span class="hl-1">();</span><br/><br/><span class="hl-6">hmac</span><span class="hl-1">.</span><span class="hl-3">update</span><span class="hl-1">(</span><span class="hl-6">time</span><span class="hl-1">);</span><br/><span class="hl-6">hmac</span><span class="hl-1">.</span><span class="hl-3">update</span><span class="hl-1">(</span><span class="hl-4">&#39;POST&#39;</span><span class="hl-1">);</span><br/><span class="hl-6">hmac</span><span class="hl-1">.</span><span class="hl-3">update</span><span class="hl-1">(</span><span class="hl-4">&#39;/api/order&#39;</span><span class="hl-1">);</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">contentHash</span><span class="hl-1"> = </span><span class="hl-6">crypto</span><span class="hl-1">.</span><span class="hl-3">createHash</span><span class="hl-1">(</span><span class="hl-4">&#39;md5&#39;</span><span class="hl-1">);</span><br/><span class="hl-6">contentHash</span><span class="hl-1">.</span><span class="hl-3">update</span><span class="hl-1">(</span><span class="hl-9">JSON</span><span class="hl-1">.</span><span class="hl-3">stringify</span><span class="hl-1">({ </span><span class="hl-6">foo:</span><span class="hl-1"> </span><span class="hl-4">&#39;bar&#39;</span><span class="hl-1"> }));</span><br/><br/><span class="hl-6">hmac</span><span class="hl-1">.</span><span class="hl-3">update</span><span class="hl-1">(</span><span class="hl-6">contentHash</span><span class="hl-1">.</span><span class="hl-3">digest</span><span class="hl-1">(</span><span class="hl-4">&#39;hex&#39;</span><span class="hl-1">));</span><br/><br/><span class="hl-6">console</span><span class="hl-1">.</span><span class="hl-3">log</span><span class="hl-1">(</span><span class="hl-4">`HMAC </span><span class="hl-0">${</span><span class="hl-6">time</span><span class="hl-0">}</span><span class="hl-4">:</span><span class="hl-0">${</span><span class="hl-6">hmac</span><span class="hl-11">.</span><span class="hl-3">digest</span><span class="hl-11">(</span><span class="hl-4">&#39;hex&#39;</span><span class="hl-11">)</span><span class="hl-0">}</span><span class="hl-4">`</span><span class="hl-1">);</span>
</code></pre>
<p>You can also use the <a href="https://connorjburton.github.io/hmac-auth-express/modules.html#generate">exported generate function</a> if you are using JavaScript on your client.</p>
<pre><code class="language-javascript"><span class="hl-0">const</span><span class="hl-1"> { </span><span class="hl-2">generate</span><span class="hl-1"> } = </span><span class="hl-3">require</span><span class="hl-1">(</span><span class="hl-4">&#39;hmac-auth-express&#39;</span><span class="hl-1">);</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">digest</span><span class="hl-1"> = </span><span class="hl-3">generate</span><span class="hl-1">(</span><br/><span class="hl-1"> </span><span class="hl-4">&#39;secret&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">&#39;sha256&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-9">Date</span><span class="hl-1">.</span><span class="hl-3">now</span><span class="hl-1">().</span><span class="hl-3">toString</span><span class="hl-1">(),</span><br/><span class="hl-1"> </span><span class="hl-4">&#39;POST&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> </span><span class="hl-4">&#39;/api/order&#39;</span><span class="hl-1">,</span><br/><span class="hl-1"> { </span><span class="hl-6">foo:</span><span class="hl-1"> </span><span class="hl-4">&#39;bar&#39;</span><span class="hl-1"> }</span><br/><span class="hl-1">).</span><span class="hl-3">digest</span><span class="hl-1">(</span><span class="hl-4">&#39;hex&#39;</span><span class="hl-1">); </span><span class="hl-8">// 76251c6323fbf6355f23816a4c2e12edfd10672517104763ab1b10f078277f86</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">hmac</span><span class="hl-1"> = </span><span class="hl-4">`HMAC </span><span class="hl-0">${</span><span class="hl-9">Date</span><span class="hl-11">.</span><span class="hl-3">now</span><span class="hl-11">().</span><span class="hl-3">toString</span><span class="hl-11">()</span><span class="hl-0">}</span><span class="hl-4">:</span><span class="hl-0">${</span><span class="hl-6">digest</span><span class="hl-0">}</span><span class="hl-4">`</span><span class="hl-1">;</span>
<pre><code class="language-javascript"><span class="hl-0">const</span><span class="hl-1"> { </span><span class="hl-2">generate</span><span class="hl-1"> } = </span><span class="hl-3">require</span><span class="hl-1">(</span><span class="hl-4">&#39;hmac-auth-express&#39;</span><span class="hl-1">);</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">time</span><span class="hl-1"> = </span><span class="hl-9">Date</span><span class="hl-1">.</span><span class="hl-3">now</span><span class="hl-1">().</span><span class="hl-3">toString</span><span class="hl-1">();</span><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">digest</span><span class="hl-1"> = </span><span class="hl-3">generate</span><span class="hl-1">(</span><span class="hl-4">&#39;secret&#39;</span><span class="hl-1">, </span><span class="hl-4">&#39;sha256&#39;</span><span class="hl-1">, </span><span class="hl-6">time</span><span class="hl-1">, </span><span class="hl-4">&#39;POST&#39;</span><span class="hl-1">, </span><span class="hl-4">&#39;/api/order&#39;</span><span class="hl-1">, {</span><br/><span class="hl-1"> </span><span class="hl-6">foo:</span><span class="hl-1"> </span><span class="hl-4">&#39;bar&#39;</span><span class="hl-1">,</span><br/><span class="hl-1">}).</span><span class="hl-3">digest</span><span class="hl-1">(</span><span class="hl-4">&#39;hex&#39;</span><span class="hl-1">); </span><span class="hl-8">// 76251c6323fbf6355f23816a4c2e12edfd10672517104763ab1b10f078277f86</span><br/><br/><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">hmac</span><span class="hl-1"> = </span><span class="hl-4">`HMAC </span><span class="hl-0">${</span><span class="hl-6">time</span><span class="hl-0">}</span><span class="hl-4">:</span><span class="hl-0">${</span><span class="hl-6">digest</span><span class="hl-0">}</span><span class="hl-4">`</span><span class="hl-1">;</span>
</code></pre>

<a href="#replay-attacks" id="replay-attacks" style="color: inherit; text-decoration: none;">
Expand Down Expand Up @@ -196,7 +196,7 @@ <h2>FAQs</h2>
<pre><code class="language-javascript"><span class="hl-5">import</span><span class="hl-1"> { </span><span class="hl-6">HMAC</span><span class="hl-1"> </span><span class="hl-5">as</span><span class="hl-1"> </span><span class="hl-6">hmac</span><span class="hl-1"> } </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-4">&#39;hmac-auth-express&#39;</span><span class="hl-1">;</span>
</code></pre>
<p><em>Why is there no default export?</em> It seems to be non-trivial to export a default that has consistent behaviour between CommonJS &amp; ECMAScript, the example below shows the behavioural differences when exporting a default from TypeScript.</p>
<pre><code class="language-javascript"><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">HMAC</span><span class="hl-1"> = </span><span class="hl-3">require</span><span class="hl-1">(</span><span class="hl-4">&#39;hmac-auth-express&#39;</span><span class="hl-1">).</span><span class="hl-6">default</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-6">HMAC</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-4">&#39;hmac-auth-exppress&#39;</span><span class="hl-1">;</span>
<pre><code class="language-javascript"><span class="hl-0">const</span><span class="hl-1"> </span><span class="hl-2">HMAC</span><span class="hl-1"> = </span><span class="hl-3">require</span><span class="hl-1">(</span><span class="hl-4">&#39;hmac-auth-express&#39;</span><span class="hl-1">).</span><span class="hl-6">default</span><span class="hl-1">;</span><br/><span class="hl-5">import</span><span class="hl-1"> </span><span class="hl-6">HMAC</span><span class="hl-1"> </span><span class="hl-5">from</span><span class="hl-1"> </span><span class="hl-4">&#39;hmac-auth-express&#39;</span><span class="hl-1">;</span>
</code></pre>
<p>If you have a suggestion on how to export a default consistently then please <a href="https://github.com/connorjburton/hmac-auth-express/issues/new">open an issue</a>.</p>
<p><em>Why is MD5 used instead of x?</em> We use MD5 to create a hash of the request body (if available) as part of building the digest, which is then hashed in totality with SHA256 (by default), therefore we are not using MD5 to secure any part of this package. MD5 is used as it is faster than the built-in alternatives and adding an external dependency for a faster hashing algorithm such as Murmur is unnecessary.</p>
Expand Down
Loading

0 comments on commit dc3b8f3

Please sign in to comment.