<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by John Quiwa on Medium]]></title>
        <description><![CDATA[Stories by John Quiwa on Medium]]></description>
        <link>https://medium.com/@johnquiwacode?source=rss-13ce09d8386d------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tGkQ4BgyzLAZzMrb0WVcJA.jpeg</url>
            <title>Stories by John Quiwa on Medium</title>
            <link>https://medium.com/@johnquiwacode?source=rss-13ce09d8386d------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 14:36:39 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@johnquiwacode/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Utilizing Cryptography Libraries to Derive Ethereum Addresses from Private Keys]]></title>
            <link>https://medium.com/hackernoon/utilizing-cryptography-libraries-to-derive-ethereum-addresses-from-private-keys-1bedd1a85bd?source=rss-13ce09d8386d------2</link>
            <guid isPermaLink="false">https://medium.com/p/1bedd1a85bd</guid>
            <category><![CDATA[ethereum]]></category>
            <category><![CDATA[solidity]]></category>
            <category><![CDATA[software-development]]></category>
            <category><![CDATA[cryptography]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[John Quiwa]]></dc:creator>
            <pubDate>Wed, 30 May 2018 16:36:02 GMT</pubDate>
            <atom:updated>2019-04-23T07:08:33.224Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/946/1*HSdhaTJV0zzq88OAX095JA.jpeg" /></figure><h4>For the non-math inclined developer</h4><p><a href="https://hackernoon.com/tagged/cryptocurrency">Cryptography</a> is central to everything in the world of <a href="https://hackernoon.com/tagged/blockchain">blockchain</a> and cryptocurrencies. It’s used to create hash pointers that make blockchains possible and to create key pairs for wallets!</p><p>In this tutorial, we will be using the ‘<strong>elliptic</strong>’ and ‘<strong>js-sha3</strong>’ javascript libraries in order to leverage principles of Elliptic Curve Cryptography (ECC) to derive a public key from a private key, and then convert the public key into it’s corresponding Ethereum address.</p><p>Many online resources cover Elliptic Curve Cryptography from a mathematical perspective, but don’t offer applicable code examples. As a programmer, I find that seeing equations broken down into digestible code snippets can cement the principles into my mind. Before we dive into the code, let’s build a general foundation regarding what Elliptic Curve Cryptography is, why it is considered safe within the Ethereum ecosystem, and how it is used to generate key pairs.</p><h3><strong>What is Elliptic Curve Cryptography?</strong></h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/409/1*KKdvscN4y-NcGZ8Nnx1ZYQ.png" /><figcaption>Elliptic Curve Example</figcaption></figure><p>Elliptic Curve Cryptography is a form of asymmetric cryptography that leverages the discrete logarithm problem of elliptic curves (ECDSA) to create public and private key pairs. Essentially, it is easy to perform operations in one direction, but is very computationally expensive to go in the other direction.</p><p><strong>Is it possible to find a private key from a public key?</strong></p><p>Public Keys are generated as a result of using elliptic curve multiplication to multiply <strong>private key (k) </strong>by <strong>generator point (G)</strong> in order to get <strong>public key (K).</strong></p><pre><strong>K = k * G</strong></pre><p>In <em>normal integer arithmetic</em>, if we knew both <strong>K</strong> and <strong>g,</strong> we could simply divide <strong>K</strong> by <strong>g</strong> in order to get <strong>k</strong>.<strong> </strong>In other words, dividing the public key by the generator point would easily give us the private key.</p><pre><strong>k = K / G</strong></pre><p>Elliptic Curve arithmetic <strong>does not</strong> <strong>have division</strong> and is therefore considered a one-way mathematical function. It is technically possible to find the private key<strong> </strong>by multiplying all of the possible factors that result in <strong>K,</strong> however, the larger the numbers involved, the longer it would take to compute. For more information, I recommend reading checking out this section from Andreas M. Antonopoulos and Gavin Wood’s book <a href="https://github.com/ethereumbook/ethereumbook/blob/develop/keys-addresses.asciidoc#elliptic_curve.">Mastering Ethereum</a>.</p><h3><strong>Overview</strong></h3><p>As previously discussed, <strong>K = k * G</strong> is actually another point on the elliptic curve. Therefore, <strong>K = (x, y)</strong> where x and y are it’s coordinates<strong>.</strong></p><p>To convert the resulting public key (<strong>K)</strong> into it’s corresponding Ethereum address, we must run it through the <strong>Keccak-256</strong> cryptographic hash function. The last 20 bytes of the resulting hash compose our Ethereum address.</p><h3><strong>Let’s jump into the code!</strong></h3><p>First, let’s setup our project. (You can skip to the next part if you’re already comfortable setting up node projects.)</p><p>Open up our terminal and create a directory for our code.</p><pre>mkdir deriveEthAddress</pre><p>Then, go into that directory using:</p><pre>cd deriveEthAddress</pre><p>To be able to npm install the modules we’ll be using, run</p><pre>npm init</pre><p>and fill in the prompts if you wish to.</p><p>Next, let’s npm install the ‘elliptic’ and ‘js-sha3’ libraries. <strong>Elliptic</strong> is a javascript library with various elliptic curve cryptography functions and <strong>js-sha3</strong> provides us with a hash function we will be using.</p><pre>npm install elliptic --save &amp;&amp; npm install js-sha3 --save</pre><p>Lastly, we create our project file.</p><pre>touch deriveEthAddress.js</pre><h4><strong>Now that our project is set up, open up deriveEthAddress.js in a text editor.</strong></h4><p>In deriveEthAddress.js we’ll require the modules we installed. Below, we create a new instance of an elliptic curve with the <strong>secp256k1</strong> (a specific elliptic curve that both Ethereum and Bitcoin use) preset. We also require the <strong>keccak256</strong> hash function from <strong>js-sha3.</strong></p><pre>// Required Modules<br><strong>const </strong>EC = require(&#39;elliptic&#39;).ec;<br><strong>const </strong>ec = <strong>new </strong>EC(&#39;secp256k1&#39;);<br><strong>const </strong>keccak256 = require(&#39;js-sha3&#39;).keccak256;</pre><p>We’ll then create variables for our private key and ethereum address. (This key pair is only for testing and shouldn’t be used to store actual funds. It was taken from the Ganache CLI - see the <a href="https://github.com/trufflesuite/ganache-cli">github repo</a> for more information.)</p><pre>// Private Key and Public Ethereum address (from Ganache)<br><strong>const </strong>givenPrivateKey = &#39;c87509a1c067bbde78beb793e6fa76530b6382a4c0241e5e4a9ec0a0f44dc0d3&#39;;<br><strong>const </strong>givenEthAddress = &#39;0x627306090abab3a6e1400e9345bc60c78a8bef57&#39;;</pre><p>Next, we’ll utilize the equation <strong>K = k * G. </strong>We get our generator point (<strong>G)</strong> from the secp256k1 elliptic curve instance. generatorPoint is then multiplied by privateKey (<strong>k</strong>). This results in pubKeyCoordinates (<strong>K</strong>). As we discussed earlier, <strong>K = (x,y), </strong>so we extract coordinates x and y and convert them to hexadecimal strings to be concatenated.</p><pre>// Get secp256k1 generator point<br><strong>const </strong>generatorPoint = ec.g;<br><br>// Public Key Coordinates calculated via Elliptic Curve Multiplication<br>// PublicKeyCoordinates = privateKey * generatorPoint<br><strong>const </strong>pubKeyCoordinates = generatorPoint.mul(givenPrivateKey);<br><br><strong>const </strong>x = pubKeyCoordinates.getX().toString(&#39;hex&#39;);<br><strong>const </strong>y = pubKeyCoordinates.getY().toString(&#39;hex&#39;);<br><br>// Public Key = X and Y concatenated<br><strong>const </strong>publicKey = x + y;</pre><pre>console.log(publicKey);<br>//af80b90d25145da28c583359beb47b21796b2fe1a23c1511e443e7a64dfdb27d7434c380f0aa4c500e220aa1a9d068514b1ff4d5019e624e7ba1efe82b340a59</pre><p>We must then run our public key through the <strong>keccak256</strong> hash function.</p><pre>// Use Keccak-256 hash function to get public key hash<br><strong>const </strong>hashOfPublicKey = keccak256(<strong>new </strong>Buffer(publicKey, &#39;hex&#39;));</pre><pre>console.log(hashOfPublicKey);<br>// 3f704e8b0ee605967f55081f627306090abab3a6e1400e9345bc60c78a8bef57</pre><p>If we look at our hash, the last 20 bytes (which would be the last 40 bits) compose our Ethereum address! Let’s convert this to a buffer so we can slice out the bytes we want to use and convert it to a hexadecimal string. We can then add the hexadecimal prefix 0x to this.</p><pre>// Convert hash to buffer<br><strong>const </strong>ethAddressBuffer = <strong>new </strong>Buffer(hashOfPublicKey, &#39;hex&#39;);<br><br>// Ethereum Address is &#39;0x&#39; concatenated with last 20 bytes<br>// of the public key hash<br><strong>const </strong>ethAddress = ethAddressBuffer.slice(-20).toString(&#39;hex&#39;);<br><strong>const </strong>ethAddressWithPrefix = `0x${ethAddress}`;</pre><p>Lastly, let’s compare our derived address to the address we were told our private key corresponded to.</p><pre>// Ethereum Address derived from private key<br>// is equal to the given address<br>console.log(ethAddressWithPrefix === givenEthAddress);</pre><pre>// true</pre><p>It’s a match! Here’s the full example -</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/90efba4b57ec1701fbe700e80cf45af0/href">https://medium.com/media/90efba4b57ec1701fbe700e80cf45af0/href</a></iframe><h3><strong>Closing</strong></h3><p>We’ve only covered the basic principles of Elliptic Curve Cryptography. That being said, the mathematical concepts applied to the Ethereum network are pretty straightforward, and there are many libraries out there to help us!</p><p><em>Thanks for reading! If you found this useful, give a </em><strong><em>clap</em></strong><em> below and </em><strong><em>follow</em></strong><em> me for more Javascript and Blockchain related articles.</em></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fupscri.be%2Fdde502%3Fas_embed%3Dtrue&amp;dntp=1&amp;url=https%3A%2F%2Fupscri.be%2Fhackernoon%2F&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=upscri" width="800" height="400" frameborder="0" scrolling="no"><a href="https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href">https://medium.com/media/3c851dac986ab6dbb2d1aaa91205a8eb/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1bedd1a85bd" width="1" height="1" alt=""><hr><p><a href="https://medium.com/hackernoon/utilizing-cryptography-libraries-to-derive-ethereum-addresses-from-private-keys-1bedd1a85bd">Utilizing Cryptography Libraries to Derive Ethereum Addresses from Private Keys</a> was originally published in <a href="https://medium.com/hackernoon">HackerNoon.com</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Developing Dotdash’s CMS Permissions]]></title>
            <link>https://techblog.people.inc/developing-dotdashs-cms-permissions-a0e63f2cd6bf?source=rss-13ce09d8386d------2</link>
            <guid isPermaLink="false">https://medium.com/p/a0e63f2cd6bf</guid>
            <category><![CDATA[mongodb]]></category>
            <category><![CDATA[permission]]></category>
            <category><![CDATA[mongo]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[technology]]></category>
            <dc:creator><![CDATA[John Quiwa]]></dc:creator>
            <pubDate>Fri, 13 Apr 2018 16:56:53 GMT</pubDate>
            <atom:updated>2018-04-13T16:56:53.673Z</atom:updated>
            <content:encoded><![CDATA[<h4>Building a Flexible System</h4><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xnORJc2dqj0f6lbzMUDEew.jpeg" /></figure><p><em>This article is part one of a two part series that details the current state of Dotdash’s CMS permissions system.</em></p><p>All web application permissions systems seem to have the same purpose, but each system must solve problems unique to an application itself. In order to ensure that users are only able interact with an application in ways they are intended to, a Permissions Management tool must be designed with the intention of being intuitive to prevent confusion that could potentially be costly if the wrong permissions are given to the wrong person (this will be discussed in part two of this series).</p><p>After the rebranding of About.com to Dotdash, maintaining a flexible permissions system that fit Content Managers’ needs began to become more cumbersome. This article will explore how certain challenges were overcome and the various variables taken into consideration.</p><h4>One Permission Doesn’t Fit All</h4><p>At Dotdash, Experts write articles and create content about particular topics through our in-house Content Management System. Once a draft is created, it can be submitted for approval by a Content Manager. If it’s decided that the content isn’t quite up to snuff, additional revisions may be made by another Expert or a Site Contributor. This is a simple case in which at least 3 different users would need access to a single document.</p><p>This example assumes that all 3 users are free to do as they please with the aforementioned document. However, not all permissions are as simple as a binary true or false.</p><h4>Resources</h4><p>Resources and Permissions seem to be standard to all permissions systems. At Dotdash, users may be given any combination of author, vertical, or document resources, as well as different combinations of CREATE, VIEW, EDIT, and DELETE permissions for each role. To take this one step further, certain resources override aspects of other resources, thus adding an additional layer of complexity.</p><h4>Bases — Keeping things Simple To Manage and Flexible To Develop</h4><p>We utilize an architecture based on prototypal inheritance where we defer to the most specific “resource.” Similar to prototypal inheritance in Javascript - where an object inherits properties from other objects - “bases” (as we call them) serve as the foundational resource sets given to a user that belongs to a particular group. This makes it simple to change the permissions of an entire group.</p><p>For example, users given a base of base.STAFF may have CREATE, VIEW, EDIT, and DELETE permissions for all verticals. If one day it is decided that staff should no longer have access to any vertical documents, the vertical resource and it’s permissions could be removed from the configuration for base.STAFF.</p><h4>Cerberus &amp; Pandora — Permission Handlers</h4><p>Bases are treated as a separate entity and are different than resources. They are processed by Pandora, a module we created for querying our permissions database. Pandora retrieves bases that are attached to a user and resolves them into all of the resources they represent.</p><p>Then, using a module we have named Cerberus (after the three-headed dog and gatekeeper of Greek Mythology), we are able to parse through these resources and their corresponding permissions to decide what a user can or cannot do.</p><p>Cerberus makes it possible for resources to be more specific if desired. For example, what if a Content Manager only wanted a user to be able to view specific documents? If granted view permissions under the vertical role, a user would be able to view all documents in all verticals. However, by appending a specific enum of a vertical to the vertical role (ex. vertical.HEALTH), Cerberus restricts a user to only be able to view<strong><em> </em></strong>documents under the specified vertical (in this case, Verywell.com).</p><h4>Follow The Rules</h4><p>The rules of this hierarchical structure also allow exceptions to be made easily. For instance, a user can be given the role vertical with the permission VIEW, as well as the role vertical.HEALTH, but with an <strong><em>empty</em></strong> permissions array. This would result in the user having the ability to view <strong><em>all</em></strong> documents under all other verticals <strong><em>except </em></strong>those under<strong><em> </em></strong>vertical.HEALTH.</p><h4>Conclusion</h4><p>There are many things to consider when developing a permissions system. As previously stated, every application will vary in the problems they must solve when it comes to permissions and developing a system using inheritance may be overkill. However, as we have seen at Dotdash, keeping a system as flexible as possible may make implementing changes based on future business decisions both quicker and easier.</p><p><em>In part two of this series, we will explore the challenges of designing and developing a UI and the factors one must consider when creating internal facing applications.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a0e63f2cd6bf" width="1" height="1" alt=""><hr><p><a href="https://techblog.people.inc/developing-dotdashs-cms-permissions-a0e63f2cd6bf">Developing Dotdash’s CMS Permissions</a> was originally published in <a href="https://techblog.people.inc/">People Inc. Tech Blog</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
    </channel>
</rss>