<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: prabhaav</title>
    <description>The latest articles on DEV Community by prabhaav (@prabhaav).</description>
    <link>https://dev.to/prabhaav</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F120427%2F76c7f4d7-96c6-4751-9ebb-1a3107172875.png</url>
      <title>DEV Community: prabhaav</title>
      <link>https://dev.to/prabhaav</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/prabhaav"/>
    <language>en</language>
    <item>
      <title>One Thing Stood Between us and a $100,000 Prize …</title>
      <dc:creator>prabhaav</dc:creator>
      <pubDate>Fri, 07 Dec 2018 19:18:38 +0000</pubDate>
      <link>https://dev.to/prabhaav/one-thing-stood-between-us-and-a-100000-prize--3e6p</link>
      <guid>https://dev.to/prabhaav/one-thing-stood-between-us-and-a-100000-prize--3e6p</guid>
      <description>&lt;p&gt;&lt;a href="https://www.stealthy.im" rel="noopener noreferrer"&gt;Stealthy.IM&lt;/a&gt; is built atop Blockstack — a decentralized platform providing identity on the Bitcoin blockchain, elliptic curve cryptography, and GAIA, a decentralized storage system.&lt;/p&gt;

&lt;p&gt;In April of 2018, Blockstack released mobile APIs for Android and iOS, enabling us to build Stealthy IM for phones. Naively, we assumed everything would work out of the box, but quickly realized there was at least one major issue. The elliptic curve cryptography features were not yet supported on Blockstack’s iOS API, and without them Stealthy IM on a phone was dead in the water. This is because all of Stealthy’s personal messaging is encrypted, as shown below in Figure 1.0.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2ATblhpoVF7QawM27oZm1YUA.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2ATblhpoVF7QawM27oZm1YUA.png" alt="Figure 1.0: A message in Stealthy and the resulting encrypted ECIES data."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Blockstack’s iOS platform API was developed in Swift and there weren’t any Swift libraries providing directly compatible Elliptic Curve Integrated Encryption System (ECIES) cryptography at the time. A temporary workaround using Blockstack’s Javascript Web platform was not possible either because the Node Crypto library components it utilized did not work in the iOS Javascript environment of Blockstack’s iOS API.&lt;/p&gt;

&lt;p&gt;Should we wait until the Blockstack team were able to address the situation? We grappled with this decision for a while, but ultimately being chosen to compete in &lt;a href="https://techcrunch.com/2018/09/05/stealthy-wants-to-become-the-wechat-of-blockchain-apps" rel="noopener noreferrer"&gt;Techcrunch Disrupt 2018&lt;/a&gt; made the decision for us. We now had until early September to finish developing our mobile product, where it would gain significant media exposure and give us the chance of winning $100,000. We couldn’t afford to wait on a solution that was beyond our control.&lt;/p&gt;

&lt;p&gt;There was little time to spare for the September Techcrunch deadline. Studying the Blockstack ECIES Javascript implementation was encouraging — it was clear and relatively uncomplicated.&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/hirosystems" rel="noopener noreferrer"&gt;
        hirosystems
      &lt;/a&gt; / &lt;a href="https://github.com/hirosystems/stacks.js" rel="noopener noreferrer"&gt;
        stacks.js
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      JavaScript libraries for identity, auth, storage and transactions on the Stacks blockchain.
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;Stacks.js &lt;a href="https://github.com/hirosystems/stacks.js/actions/workflows/tests.yml" rel="noopener noreferrer"&gt;&lt;img src="https://github.com/hirosystems/stacks.js/actions/workflows/tests.yml/badge.svg" alt="Test Action Badge"&gt;&lt;/a&gt; &lt;a href="https://github.com/hirosystems/stacks.js/tree/main/packages" rel="noopener noreferrer"&gt;&lt;img src="https://camo.githubusercontent.com/6102f40b9792756765c411eadeedaf07faef1b230319b853cfcfdab03df87abf/68747470733a2f2f696d672e736869656c64732e696f2f6769746875622f6c65726e612d6a736f6e2f762f6869726f73797374656d732f737461636b732e6a733f6c6162656c3d6d6f6e6f7265706f" alt="Monorepo Version Label"&gt;&lt;/a&gt;
&lt;/h1&gt;
&lt;/div&gt;
&lt;div class="markdown-alert markdown-alert-important"&gt;
&lt;p class="markdown-alert-title"&gt;Important&lt;/p&gt;
&lt;p&gt;Looking for Nakamoto updates
Use version &lt;code&gt;6.16.0&lt;/code&gt; or later to test the latest nakamoto changes
e.g., &lt;code&gt;npm install @stacks/stacking@6.16.0&lt;/code&gt;&lt;/p&gt;
&lt;/div&gt;
&lt;p&gt;Welcome to the Stacks.js repository, your one-stop solution for working with the Stacks blockchain using JavaScript/TypeScript. This repository nests a collection of packages designed to provide you with the essential building blocks to work with the &lt;a href="https://www.stacks.co/what-is-stacks" rel="nofollow noopener noreferrer"&gt;Stacks blockchain&lt;/a&gt; from JavaScript/TypeScript.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h2 class="heading-element"&gt;Packages&lt;/h2&gt;

&lt;/div&gt;
&lt;p&gt;For installation instructions and usage guidelines, refer to the respective &lt;code&gt;README&lt;/code&gt; in each package directory.&lt;/p&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Connecting Wallets&lt;/h3&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/hirosystems/connect" rel="noopener noreferrer"&gt;&lt;code&gt;@stacks/connect&lt;/code&gt;&lt;/a&gt; Connect web application to Stacks wallet browser extensions &lt;em&gt;(separate repo)&lt;/em&gt;.&lt;/li&gt;
&lt;/ul&gt;
&lt;div class="markdown-heading"&gt;
&lt;h3 class="heading-element"&gt;Stacks Primitives&lt;/h3&gt;

&lt;/div&gt;
&lt;ul&gt;
&lt;li&gt;
&lt;a href="https://github.com/hirosystems/stacks.js/tree/main/packages/transactions" rel="noopener noreferrer"&gt;&lt;code&gt;@stacks/transactions&lt;/code&gt;&lt;/a&gt; Construct, decode transactions, and work with Clarity smart contracts on the Stacks blockchain.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/hirosystems/stacks.js/tree/main/packages/wallet-sdk" rel="noopener noreferrer"&gt;&lt;code&gt;@stacks/wallet-sdk&lt;/code&gt;&lt;/a&gt; Library for building wallets, managing accounts, and handling keys for the Stacks blockchain.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/hirosystems/stacks.js/tree/main/packages/storage" rel="noopener noreferrer"&gt;&lt;code&gt;@stacks/storage&lt;/code&gt;&lt;/a&gt; Store and fetch files with Gaia, the decentralized storage system.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/hirosystems/stacks.js/tree/main/packages/encryption" rel="noopener noreferrer"&gt;&lt;code&gt;@stacks/encryption&lt;/code&gt;&lt;/a&gt; Encryption functions used by stacks.js packages.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/hirosystems/stacks.js/tree/main/packages/auth" rel="noopener noreferrer"&gt;&lt;code&gt;@stacks/auth&lt;/code&gt;&lt;/a&gt; Construct and decode authentication requests for Stacks apps.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/hirosystems/stacks.js/tree/main/packages/profile" rel="noopener noreferrer"&gt;&lt;code&gt;@stacks/profile&lt;/code&gt;&lt;/a&gt; Functions…&lt;/li&gt;
&lt;/ul&gt;
&lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/hirosystems/stacks.js" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;/div&gt;


&lt;p&gt;It’s important to mention that neither of Stealthy’s founders are experts in cryptography — it was in fact relatively new to both of us. Initially it seemed it might be possible to use Apple’s own cryptographic functions for iOS. Blockstack’s ECIES cryptography centers around the SECP256K1 curve made popular by Bitcoin and Apple’s libraries support both this curve and some aspects of &lt;a href="https://en.bitcoin.it/wiki/Secp256k1" rel="noopener noreferrer"&gt;elliptic curve cryptography&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;However, much time was spent just trying to get a user’s Blockstack public and private keys into the correct data structure to work with Apple’s libraries. The process involved iterations of trial and error and reading Apple’s Developer Forum and Stack Overflow — largely because of some catch-all error messaging that didn’t give much of an indication about what was going wrong. Eventually after reading several posts from Quinn “The Eskimo”, a resident expert in Apple’s Developer Forum, we elected to ask him for help. To summarize he essentially said &lt;a href="https://forums.developer.apple.com/message/316794#316794" rel="noopener noreferrer"&gt;“read Apple’s code” — not bad advice&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;After making little progress over a couple of days, defeating a small portion of the cryptography learning curve and getting the public key into the right Apple data structure, it was time to try something else. Further comparison of Apple’s system and the Blockstack one seemed to confirm this, as it appeared there would be many more challenges.&lt;/p&gt;

&lt;p&gt;This is when we broke one of our cardinal start-up rules. For years we told friends never to join a startup working in C++. Nothing against the language, it just requires a high degree of skill and takes longer to develop solutions with. Yet here was a good reason to work in C++: the &lt;a href="https://www.cryptopp.com" rel="noopener noreferrer"&gt;Crypto++ library&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Crypto++ is a free C++ cryptography library with lots of documentation and examples. It is well maintained and there is even a forum where you can reach out for support. However, what’s really interesting about Crypto++ is the original author:&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Wei Dai … is a computer engineer best known as the creator of the Bitcoin predecessor “b-money” and as the developer of the Crypto++ library.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;His &lt;a href="http://www.weidai.com/bmoney.txt" rel="noopener noreferrer"&gt;b-money&lt;/a&gt; paper sets the groundwork for Bitcoin — &lt;strong&gt;in 1998&lt;/strong&gt;! Proof of work, collective bookkeeping, and authentication with cryptographic hashes are all described. The paper is referenced in Satoshi Nakamoto’s original Bitcoin whitepaper.&lt;/p&gt;

&lt;p&gt;With clearer documentation and some useful example code, we created a testbench using data from the desktop version of Stealthy and a prototype ECIES solution using Crypto++. Much of the learning curve was in getting familiar with the data types and basic cryptographic principles (i.e. uncompressing a compressed key, deriving a shared secret, and mapping what we understood from the Blockstack ECIES implementation to the examples found in the Crypto++ forums and documentation).&lt;/p&gt;

&lt;p&gt;It took about four days, but now we had a prototype that could encrypt and decrypt data interoperably with our desktop Stealthy release. The remaining challenge was plumbing these cryptography methods into the Stealthy iOS product.&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/fzOg9siQhps"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;This was a bit of a mess because Swift and Objective C do not directly allow you to import C++ code. You have to wrap the C++ with Objective C++. The Objective C++ is then callable from Objective C. Then from Objective C, it can be exported to React Native JSX / Javascript callable functions used in Stealthy. Figure 2.0 below illustrates the situation:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2AwrwMKkEknMlAoOu4Mk1adw.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fcdn-images-1.medium.com%2Fmax%2F1600%2F1%2AwrwMKkEknMlAoOu4Mk1adw.png" alt="Figure 2.0: Calling C++ from React Native on iOS."&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;A Github repository of our Blockstack compatible Crypto++ ECIES implementation can be found here:&lt;/p&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev.to%2Fassets%2Fgithub-logo-5a155e1f9a670af7944dd5e12375bc76ed542ea80224905ecaf878b9157cdefc.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/stealthyinc" rel="noopener noreferrer"&gt;
        stealthyinc
      &lt;/a&gt; / &lt;a href="https://github.com/stealthyinc/ECIES-Encryption" rel="noopener noreferrer"&gt;
        ECIES-Encryption
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Crypto++ Implementation of ECIES Cryptography on the SECP1256K1 Curve
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;div class="markdown-heading"&gt;
&lt;h1 class="heading-element"&gt;ECIES-Encryption&lt;/h1&gt;

&lt;/div&gt;
&lt;p&gt;Crypto++ Implementation of ECIES Cryptography on the SECP1256K1 Curve&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/stealthyinc/ECIES-Encryption" rel="noopener noreferrer"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;p&gt;While there are many things we might do differently now that we have more experience, this work got us on stage at Techcrunch Disrupt 2018 to release our mobile product. It allowed our users to send and receive messages between our iOS, Android, and desktop versions of Stealthy seamlessly and securely.&lt;/p&gt;

&lt;p&gt;Going forward we hope to get feedback from the Crypto++ maintainers on our implementation, possibly providing it as a complete ECIES implementation example.&lt;/p&gt;

&lt;p&gt;Special thanks to the fine folks maintaining and documenting Crypto++. It’s a wonderful project that we found immensely useful.&lt;/p&gt;

</description>
      <category>discuss</category>
      <category>javascript</category>
      <category>ios</category>
      <category>blockchain</category>
    </item>
  </channel>
</rss>
