<?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 Nakul Sharma on Medium]]></title>
        <description><![CDATA[Stories by Nakul Sharma on Medium]]></description>
        <link>https://medium.com/@nakul5harma?source=rss-56bc05049a5------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*KsDQ1ertG0q9Dp1bcmy3Iw.png</url>
            <title>Stories by Nakul Sharma on Medium</title>
            <link>https://medium.com/@nakul5harma?source=rss-56bc05049a5------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Tue, 17 Nov 2026 23:15:38 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@nakul5harma/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[Is Monorepo Architecture right for your team?]]></title>
            <link>https://medium.com/@nakul5harma/is-monorepo-architecture-right-for-your-team-95ef673222f0?source=rss-56bc05049a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/95ef673222f0</guid>
            <category><![CDATA[nx-monorepo]]></category>
            <category><![CDATA[rushjs]]></category>
            <category><![CDATA[bazel]]></category>
            <category><![CDATA[software-architecture]]></category>
            <category><![CDATA[monorepo]]></category>
            <dc:creator><![CDATA[Nakul Sharma]]></dc:creator>
            <pubDate>Sat, 30 Nov 2024 14:58:49 GMT</pubDate>
            <atom:updated>2024-11-30T14:58:49.329Z</atom:updated>
            <content:encoded><![CDATA[<p>In today’s world, even small organizations have to manage a significant amount of code in the form of various applications, libraries, and services. Typically, an organization may have a web application, a mobile application, a few microservices, and some libraries that are shared between these applications. In most codebases, each project is stored in its own repository i.e. a poly-repo setup, and shared code is usually managed through a private npm registry or Maven repository. This is a good setup and works well for many organizations.</p><p>As the organization grows, managing multiple repositories can become challenging. Even a small application requires dealing with several components such as project builders, bundlers, test suites, CI/CD scripts, docker configurations, and whatnot. It is not hard to see that managing a codebase for a medium or a large enterprise can become overwhelming. Thus, it becomes extremely important to separate concerns and avoid code duplication to make the process more efficient.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eCTvYCXLkQ9ieAXL" /><figcaption>Poly-repo vs Monorepo</figcaption></figure><p>The concept of monorepo architecture has been around for about two decades, but it has gained significant attention in the last few years. This is largely due to the growing size of codebases and an increase in the number of applications managed by organizations. In a monorepo setup, the entire codebase, including all applications, libraries, and services, is stored in a single repository. You get many benefits when using monorepos, some of them are:</p><ul><li><strong>Shared code and visibility:</strong> This eliminates the need to copy and paste code between repositories, enabling developers to keep their code DRY across the organization.</li><li><strong>One place for your toolchain setup and configurations: </strong>You don’t need to repeatedly copy your CI/CD scripts, Docker configurations, and other settings whenever you create a new repository.</li><li><strong>Atomic changes:</strong> Making related changes to multiple applications and libraries in a single commit can simplify the process of maintaining code consistency and improve code review. For instance, you can make changes in the server API and also modify the frontend code that uses this API, all in a single commit. This way, you won’t need to create and manage multiple pull requests for related changes.</li><li><strong>Codebase modernization is easier:</strong> Updating dependencies and refactoring the codebase is easier due to full codebase visibility.</li><li><strong>Single-version dependency rule:</strong> It helps in avoiding the <a href="https://opensource.google/documentation/reference/thirdparty/oneversion#diamond_dependencies">diamond dependency problem</a> and <a href="https://en.wikipedia.org/wiki/Dependency_hell">dependency hell</a>.</li></ul><p>Many developers may have reservations about implementing monorepos, especially those who have not worked with them before. In this article, I will discuss these and attempt to clarify some misunderstandings.</p><h3><strong><em>We have multiple projects that don’t share much code, do I need to bring everything into the same repository?</em></strong></h3><p>When using a poly-repo architecture, managing multiple repositories can be a challenge as each repository requires its own CI/CD pipeline, Docker configurations, and other settings. This can become especially difficult when dealing with a large number of repositories. In contrast, by using a monorepo architecture, you will benefit from a single CI process, even if your projects are unrelated or don’t share much code. Also, you won’t need to create or copy configurations every time you create a new application, service, or library.</p><p>One other challenge in poly-repo architecture is testing changes. For example, in a JavaScript project with internal npm packages, you may need to link and unlink several repository folders via <a href="https://docs.npmjs.com/cli/v9/commands/npm-link">npm link</a> in order to test changes. However, this process can be time-consuming and prone to errors. In contrast, in a monorepo setup, you can easily test your changes without having to worry about linking and unlinking multiple folders. This approach ensures that everything works as intended and saves you time.</p><h3><strong><em>We have multiple teams working on the project, isn’t it going to be chaotic working in a monorepo?</em></strong></h3><p>It’s a common misconception that when multiple teams work on the same repository, it’s going to turn into a disorganized mess without any clear boundaries in modules and applications. However, this is not the case. In a monorepo setup, you can clearly define module boundaries with private and public APIs, you can not import any file from any other module unless it’s explicitly exported out of the module.</p><p>Then there are tools like <a href="https://docs.github.com/en/repositories/managing-your-repositorys-settings-and-features/customizing-your-repository/about-code-owners">GitHub CODEOWNERS</a> that let you define folder-level permissions in the repository, this can add another layer of structure and control to the repository when you are working with a large team.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*TRseRA73js9XNq3v" /><figcaption>A sample GitHub CODEOWNERS file</figcaption></figure><p>You can create a CODEOWNERS file in the repository and respective code owners will be notified of the changes automatically.</p><h3><strong><em>Am I going to spend a lot of time building and testing everything when I make a change?</em></strong></h3><p>There is a common misconception that when making changes, you have to build and test everything, which can waste a lot of time but this is not true. Only the part that is affected by the change needs to be rebuilt and retested. This is one of the core principles of the monorepo architecture and all popular monorepo management tools like <a href="https://rushjs.io/">Rush</a>, <a href="https://bazel.build/">Bazel</a>, and <a href="https://nx.dev/">Nx</a> have built-in support for this.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*pdxXjkKqdPzWinPA" /><figcaption>Example of a project’s dependency graph</figcaption></figure><p>In the above illustration, if you make changes in lib-d then only lib-b2 and app-B need to be rebuilt and retested along with lib-d to verify if your changes are working, basically everything above lib-d in the dependency graph.</p><p>If two projects do not depend on each other, they cannot affect each other. This gives teams the freedom to work independently and make changes more confidently.</p><h3><strong><em>Can I keep part of the code in a monorepo and part of the code in a poly-repo?</em></strong></h3><p>There is no particular issue if you want to manage multiple repositories for some of the applications, you can even choose to create multiple monorepos or a mix of monorepos and poly-repos based on your organization’s needs.</p><p>Some organizations may want to keep some of the code hidden between smaller groups of people. In such cases, it’s not a good idea to bring that project into the monorepo, since popular tools like GitHub do not have the functionality to restrict access to specific parts of the repository. It’s probably best to create a separate repository for those projects.</p><p>Another model that is gaining popularity is where the code for different products or platforms is kept in separate monorepos. All the backend services, frontend applications, and utility libraries related to a specific product or platform are grouped in a single monorepo. This approach allows developers to keep the codebase small and manageable while still enjoying the benefits of a monorepo.</p><p>You get a lot of benefits when using a monorepo architecture, but there are a few real challenges as well:</p><ul><li><strong>Requires a more sophisticated CI setup:</strong> You’re not building a single app, but rather multiple apps from a single repository.</li><li><strong>Single-version dependency rule:</strong> While using a single version of dependency can help avoid issues and inconsistencies that are hard to debug, it also has a downside. When multiple teams and apps utilize a dependency, all of the teams must collaborate on version updates. In large organizations, this is handled by a dedicated platform team.</li><li><strong>Long-lived branches do not work well with monorepos:</strong> Large teams often face merge conflicts when using monorepos and long-lived branches. To overcome this challenge, teams can adopt new practices like trunk-based development and feature toggles. Feature toggles can help manage breaking changes and cases where teams have to manage two versions of a method or class.</li><li><strong>Controlling access to specific parts of the codebase:</strong> This model is ineffective when a large portion of the code is hidden between groups.</li></ul><h3>Final Thoughts</h3><p>When considering a shift to monorepos, it is important to evaluate the tools and processes required to ensure a successful transition. Despite the challenges that may arise, many organizations, regardless of their size, find that the benefits of adopting a monorepo architecture outweigh the difficulties. It is a good idea to start with a small portion of your codebase and gradually transition to a monorepo architecture to evaluate its effectiveness for your organization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=95ef673222f0" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[The Effectiveness of the “Debt” Metaphor in Describing Technical Debt]]></title>
            <link>https://medium.com/@nakul5harma/the-effectiveness-of-the-debt-metaphor-in-describing-technical-debt-5ace9e418f1c?source=rss-56bc05049a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/5ace9e418f1c</guid>
            <category><![CDATA[technical-debt]]></category>
            <category><![CDATA[metaphor]]></category>
            <category><![CDATA[ward-cunningham]]></category>
            <category><![CDATA[technical-debt-quadrant]]></category>
            <dc:creator><![CDATA[Nakul Sharma]]></dc:creator>
            <pubDate>Sun, 21 Jan 2024 09:37:51 GMT</pubDate>
            <atom:updated>2024-01-21T09:37:51.519Z</atom:updated>
            <content:encoded><![CDATA[<blockquote><strong><em>“Metaphors are a way of thinking and a way of seeing” </em></strong><em>— </em><a href="https://wiki.c2.com/?MetaphorsWeLiveBy"><em>Gareth Morgan, 1986</em></a></blockquote><p>Metaphors play a crucial role in communication and understanding by providing a way to convey complex ideas, emotions, and concepts in a more relatable and vivid manner. When information is presented in a metaphorical context, it becomes easier for individuals to recall and retain, as the association with a vivid image or concept enhances memory. Metaphors are tools for abstract thinking and problem-solving. They allow individuals to approach challenges by drawing parallels with more familiar situations, facilitating creative problem-solving.</p><h3>The “Technical Debt” Metaphor</h3><blockquote><strong><em>“An important idea is that we reason by analogy with the metaphors that have entered our language” </em></strong><em>— </em><a href="https://wiki.c2.com/?WardExplainsDebtMetaphor"><em>Ward Cunningham</em></a></blockquote><p>The term “Technical Debt” was coined by Ward Cunningham, the “debt” metaphor frames how to think about and deal with this issue. Ward Cunningham’s original idea behind “Technical Debt” was to describe a “deliberate” decision made to release a feature early, understanding that there would be a cost in terms of future maintenance. This term has taken on a broader meaning now, technical debt is now used to describe anything that slows us down and makes future maintenance harder, even in cases where we did not realise that we were, in fact, incurring technical debt.</p><p>Martin Fowler’s <a href="https://martinfowler.com/bliki/TechnicalDebtQuadrant.html">Technical Debt Quadrant</a> helps us categorize and understand the different types of technical debt we may encounter -</p><ol><li><strong>Deliberate and Prudent:</strong> This type of technical debt is taken on intentionally to expedite product delivery. It involves thoughtful consideration of the trade-offs and a clear plan for future repayment through refactoring.</li><li><strong>Deliberate and Reckless:</strong> In this case, technical debt arises from carelessness or neglecting essential aspects like design and refactoring. While it may offer short-term benefits, it can lead to severe long-term consequences.</li><li><strong>Inadvertent and Reckless:</strong> When we lack a complete understanding of the application’s architecture or crucial aspects, we may unknowingly incur this type of technical debt. It results from unintentional mistakes that hinder progress and demand resolution.</li><li><strong>Inadvertent and Prudent:</strong> Starting with less-than-ideal design due to limited knowledge of future development or resources leads to this type of technical debt. While it is not intentional, it still requires future investment for improvement.</li></ol><figure><img alt="" src="https://cdn-images-1.medium.com/max/512/0*-a_kxR0Aa8LHpX-V" /><figcaption>Martin Fowler’s <a href="https://martinfowler.com/bliki/TechnicalDebtQuadrant.html">Technical Debt Quadrant</a></figcaption></figure><h3>Understanding “Technical Debt” in comparison with the “Financial Debt”?</h3><p>Much like financial debt, technical debt involves making conscious trade-offs to achieve short-term gains, with an awareness that these decisions will incur interest and require future repayment. Just as we might borrow money to accomplish something quickly, knowing that we must pay interest until we repay the principal, we incur technical debt to expedite the release of a product. We can choose to push software out to get some early feedback or to get the feature in the market with quick shortcuts, this incurs a figurative “interest” in terms of reduced development speed, decreased efficiency and increased complexity.</p><blockquote><strong><em>“When the whole project caves in under the mess, is that like when the big guys come round and slam your hands in the car door for not paying up?” </em></strong><em>— </em><a href="https://wiki.c2.com/?ComplexityAsDebt"><em>Ward Cunningham</em></a></blockquote><p>The development gets slower when we keep pushing new features one after the other and do not deal with technical debt in time, it is like borrowing money and not thinking about paying it back. When we do this long enough, eventually our purchasing power is decreased to zero, that is when the team will spend all their efforts tiptoeing around the “temporary solution” and we make zero real progress.</p><blockquote><strong><em>“Refactoring is like repaying principal” </em></strong><em>— </em><a href="https://wiki.c2.com/?ComplexityAsDebt"><em>Ward Cunningham</em></a></blockquote><p>We can claim back the development speed and agility by putting our learning back in the code once our goal is achieved. Regular code refactoring is an essential part of many software development practices nowadays.</p><h3>Final Thoughts</h3><p>We can draw parallels with financial debt to better understand the “Technical Debt” metaphor. When we introduce technical debt in our software, it is like borrowing money we need to pay back. When we do not put our understanding back into the software once we have achieved our goal, it becomes challenging to develop new features and development gets slower and slower until we cannot push new features out in the market in time.</p><p>Refactoring the code is like paying the principal, doing so we can get rid of the interest that we are incurring because of the technical debt in terms of slower development and decreased efficiency.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5ace9e418f1c" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[How to integrate a fingerprint scanner device in a windows machine for EKYC verification]]></title>
            <link>https://medium.com/@nakul5harma/how-to-integrate-a-fingerprint-scanner-device-in-a-windows-machine-for-ekyc-verification-33f5b095ef4d?source=rss-56bc05049a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/33f5b095ef4d</guid>
            <category><![CDATA[aadhar-card]]></category>
            <category><![CDATA[biometric-authentication]]></category>
            <category><![CDATA[ekyc]]></category>
            <category><![CDATA[electronjs]]></category>
            <category><![CDATA[aadhar]]></category>
            <dc:creator><![CDATA[Nakul Sharma]]></dc:creator>
            <pubDate>Thu, 27 Oct 2022 08:54:14 GMT</pubDate>
            <atom:updated>2022-10-27T08:54:14.851Z</atom:updated>
            <content:encoded><![CDATA[<p>We recently had a requirement where we had to perform customer EKYC using a fingerprint scanner device in an <a href="https://www.electronjs.org/">ElectronJS</a>-based Windows application. If you want to perform EKYC verification with a fingerprint scanner, it can’t be done with just any fingerprint scanner, you will need an AVDM for that. You must be wondering what’s an AVDM. AVDM is short for “Aadhar Verification Device Manager”, it is nothing but a simple fingerprint scanning device that is manufactured by a UIDAI-authorized vendor, the device vendor must get UIDAI’s permission and should comply with certain security practices.</p><p>The device we went with was Mantra’s MFS100. Device usages are well documented and the device is straightforward to use as it can be easily plugged in using a USB connection and exposes REST APIs to make it platform-independent and language-independent. The device itself is not that important here because any vendor which is authorized by UIDAI exposes similar APIs for using it.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/360/1*0lsz4qLGeQMt5gfOJ2KsSw.png" /><figcaption>Mantra MFS100</figcaption></figure><p>Easy to use and well-documented!? Then why am I writing one more article and adding to the list of documentation which is already available? I’ll tell you. While the device usages are pretty straightforward, using it for generating fingerprint data that can be used for EKYC verification? Well, I will not say that finding the right solution was easy. The problem I faced is that there is no single place where you’ll find everything you need, the documentation is scattered in many places. I had to go through tons of resources including UIDAI’s EKYC API documentation and had to connect with many people to get to the right solution. The trickiest part is that you’ll never know if the generated data is correct until you perform an EKYC verification check, as we’ll get the data even if we are missing a thing or two but the EKYC verification will fail eventually. I’ll explain my experience integrating the AVDM device and I hope it makes your life easier.</p><p>As I said we need an AVDM to capture the biometric data but that’s not all. AVDM is incomplete without an RD service, RD service registers the fingerprint device as an AVDM on the vendor’s management servers, hence the name “Register Device” service. RD service is also responsible for interacting with the vendor’s management servers for encrypting the biometric data.</p><p>Let’s move on and install the device driver and RD service together.</p><h4>How to install the Mantra device driver and Mantra RD service in windows?</h4><p>Easy, go to Mantra’s <a href="http://download.mantratecapp.com/Forms/DownLoadFiles">download page</a>, enter the captcha and you’ll land on the page with all the drivers. Download the device driver for MFS100 and its RD service from the page.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*HRd16fdpjP7v_BQ8bZMLng.png" /><figcaption>Mantra download page</figcaption></figure><p>Once the driver and RD service are downloaded, install them in administrator mode (right-click on the .exe file and choose “Run as administrator” from the options menu).</p><blockquote>It’s important to note that the RD service will not work if the installation is done without admin access because the setup requires access to the “system32” folder in the Windows directory. Driver and RD service installation is a one-time task, the service is bound to Windows boot and restarted when the system restarts.</blockquote><p>Voila!! It’s done. We have the system ready for some serious action!</p><h4>How to check the device status?</h4><p>When installed, RD service takes up one of the ports from 11100 to 11105, check the port on which the RD service is running beforehand, in most cases, it’s going to be 11100 unless some other service is already running on the port.</p><p>RD service exposes a few simple REST APIs, which accept and send XML payloads. An interesting point to note here is that none of the RD service REST APIs uses standard HTTP methods like GET, POST, PUT etc.</p><p>The first one is the “Discover AVDM” API, cURL request for the API looks like this -</p><pre>curl — location — request RDSERVICE ‘http://127.0.0.1:11100&#39;</pre><p>Status response -</p><pre>&lt;?xml version=”1.0&quot;?&gt;<br>&lt;RDService status=”READY” info=”Mantra Authentication Vendor Device Manager”&gt;<br>  &lt;Interface id=”DEVICEINFO” path=”/rd/info” /&gt;<br>  &lt;Interface id=”CAPTURE” path=”/rd/capture” /&gt;<br>&lt;/RDService&gt;</pre><p>Did you notice the “status” field in the response? Anything but “READY” is an error. Please ensure that the device is properly connected to the machine if you are getting an error.</p><p>Two important data points are also present in the response here — API URIs and corresponding HTTP methods for getting device information and for capturing biometric data.</p><h4>How to get the device information?</h4><p>To get the endpoint for the “Device Info” API, we need to concatenate the base URL with the path received in the “Discover AVDM” API response.</p><p>cURL request for the API looks like this -</p><pre>curl — location — request DEVICEINFO ‘http://127.0.0.1:11100/rd/info&#39;</pre><p>Device info response -</p><pre>&lt;?xml version=”1.0&quot;?&gt;<br>&lt;DeviceInfo dpId=”MANTRA.MSIPL” rdsId=”MANTRA.WIN.001&quot; rdsVer=”1.0.3&quot; mi=”MFS100&quot; mc=”MgTWFudHJhIFNvZn…w=” dc=”c4148a54-a544–4c41–8b31–85e4c4148b31&quot;&gt;<br>  &lt;additional_info&gt;<br>    &lt;Param name=”srno” value=”98712312&quot; /&gt;<br>    &lt;Param name=”sysid” value=”DBQBQWB80NVP90L793JG” /&gt;<br>    &lt;Param name=”ts” value=”2022–01–13T19:00:00+05:30&quot; /<br>  &lt;/additional_info&gt;<br>&lt;/DeviceInfo&gt;</pre><p>We received device information and RD service details in the response. Let’s have a look at some of the important values and what these values mean -</p><ul><li>“dpId” is a unique device provider ID assigned to the vendor by UIDAI.</li><li>“rdsId” is a unique RD service ID assigned to the vendor’s RD service by UIDAI.</li><li>“rdsVer” is the RD service version installed in the system.</li><li>“mi” is the model ID for the device.</li><li>“mc” is a public key assigned to the device when it’s registered in the vendor’s management server.</li><li>“dc” is a unique code assigned to the device.</li></ul><h4>How to capture fingerprint data for EKYC purposes?</h4><p>Let’s start with how biometric EKYC verification works. As the first step, our application sends a capture request to the RD service, which in turn triggers the device to start scanning. Once the biometric data is collected, the RD service processes the data and encrypts it. Finally, the RD service prepares the PID data block and sends it back to our application, this PID data can be verified by requesting “KUA” (Aadhar User Agency or “AUA” with KYC permission, it’s a separate entity from the device vendor) for EKYC verification.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*KVK5ZmdNFzklEsbdv-M3Og.png" /><figcaption>Biometric aadhar verification flow</figcaption></figure><p>Below is the cURL request for the “Capture” API. For the “Capture” request too, we need to concatenate the base URL with the path received in the “Discover AVDM” API response -</p><pre>curl — location — request CAPTURE ‘http://127.0.0.1:11100/rd/capture&#39; \<br>— header ‘Content-Type: application/xml’ \<br>— data-raw ‘&lt;?xml version=”1.0&quot;?&gt;<br>&lt;PidOptions ver=”1.0&quot;&gt;<br>&lt;Opts fCount=”1&quot; fType=”0&quot; iCount=”0&quot; pCount=”0&quot; format=”0&quot; pidVer=”2.0&quot; timeout=”10000&quot; posh=”UNKNOWN” env=”P” wadh=”E0jzJ/P8UopUHAieZn8CKqS4WPMi5ZSYXgfnlfkWjrc=”/&gt;<br>&lt;CustOpts&gt;<br>&lt;Param name=”mantrakey” value=”undefined” &gt;&lt;/Param&gt;<br>&lt;/CustOpts&gt;<br>&lt;/PidOptions&gt;’</pre><p>We need to specify a few options in the request body. These must be correct to get the right kind of data, as I had mentioned earlier, we will get the data anyway even if we miss a few things, but that does not mean all the parameters are correct. Let’s go through the options we have sent in the request -</p><ul><li>“fCount” is the number of fingers we are capturing in the request. “fCount” varies between “0” and “10”. The device we are using, MFS100, is used for capturing only one finger at a time.</li><li>“fType” can have two possible values “0” for “FMR” (Fingerprint Minutiae Records) or “1” for “FIR” (Fingerprint Image Records), FMR is the recommended method for fingerprint capture so we’ll go with value “0” here.</li><li>“iCount” is the number of iris, this value is “0” for us because we are not scanning iris here. iCount can vary between 0 and 2.</li><li>“pCount” specifies face count for scanning. Use “0” when not scanning the face, “1” while scanning the face.</li><li>“format” specifies the type of data format we need in the response. “0” is for XML and “1” is for ProtoBuf. ProtoBuf is a <a href="https://developers.google.com/protocol-buffers">new mechanism designed by Google for serializing structured data</a>.</li><li>“pidVer” is the version for the PID data type that we’ll receive in the response. “2.0” is the latest one and will work with new Aadhaar APIs.</li><li>“timeout” specifies the number of milliseconds after which the capture request times out if no fingerprint is detected.</li><li>“posh” specifies the finger/ iris type to be captured. The “UNKNOWN” value means that any finger/ iris can be scanned.</li><li>“env” can have three possible values — “S” for staging, “PP” for pre-production and “P” for production.</li><li>“wadh” has EKYC API options. We get this value by concatenating EKYC options, then encrypting the resultant string using the SHA256 algorithm and then finally encoding it in BASE64 format. EKYC options are -<br> — “ver” is the EKYC API version, here I’m using the latest version available i.e. “2.5”.<br> — “ra” is the resident authentication type, meaning what kind of verification we perform. “F” is for the finger, “I” is for the iris, “O” is for OTP and “P” is for the face. These values can be combined as well, like “FO” for fingerprint and OTP verification. This option must match with the options specified for “fCount”/ “iCount”/ “pCount”, otherwise, the EKYC verification will fail.<br> — “rc” represents the explicit consent of the customer for biometric verification. The only possible value is “Y”, any other value results in an error response.<br> — “lr” value should be “Y” if local language data is required in the response in addition to English, and “N” is for English only.<br> — “de” specifies who decrypts the biometric data when the data is forwarded for EKYC verification. If this is set to “N” then “KUA” will decrypt the data, otherwise, their parent entity “ASA” will decrypt the data.<br> — “pfr” specifies the print format request option. If it is set to “Y” then PDF print format is attached in the response, only XML is returned if the value is set to “N”.<br> — Finally, “wadh” can be calculated with these values. “wadh” = BASE64(SHA256(“ver” + “ra” + “rc” + “lr” + “de” + “pfr”))</li></ul><p>Phewww!! That was a lot. Now that the request options are out of the way, let’s take a look at the capture response -</p><pre>&lt;?xml version=”1.0&quot;?&gt;<br>&lt;PidData&gt;<br>  &lt;Resp errCode=”0&quot; errInfo=”Success” fCount=”1&quot; fType=”0&quot; nmPoints=”46&quot; qScore=”71&quot; /&gt;<br>  &lt;DeviceInfo dpId=”MANTRA.MSIPL” rdsId=”MANTRA.WIN.001&quot; rdsVer=”1.0.3&quot; mi=”MFS100&quot; mc=”MgTWFudHJhIFNvZn…w=” dc=”c4148a54-a544–4c41–8b31–85e4c4148b31&quot;&gt;<br>    &lt;additional_info&gt;<br>      &lt;Param name=”srno” value=”98712312&quot; /&gt;<br>      &lt;Param name=”sysid” value=”DBQBQWB80NVP90L793JG” /&gt;<br>      &lt;Param name=”ts” value=”2022–01–13T19:00:00+05:30&quot; /<br>    &lt;/additional_info&gt;<br>  &lt;/DeviceInfo&gt;<br>  &lt;Skey ci=”20220113&quot;&gt;rW1yvtbOFKISFANC…g==&lt;/Skey<br>  &lt;Hmac&gt;ib9Amw/J6TQ78aVTt…ZZh&lt;/Hmac&gt;<br>  &lt;Data type=”X”&gt;MgTWFudHJhIFNvZn…wg==&lt;/Data&gt;<br>&lt;/PidData&gt;</pre><p>We received device information and captured fingerprint data (“SKey”, “Hmac” and “Data”) in the response. Here -</p><ul><li>“errCode” value “0” indicates that the capture was successful, in case of an error we get a helpful error message in `errInfo`.</li><li>“nmPoints” in the response is for the number of captured minutiae points. Minutiae points are the points where lines in the fingerprint end or fork out. Values between 25 and 80 are considered good.</li><li>“qScore” indicates the normalized quality score for the captured data. This varies from “0” to “100”.</li></ul><p>Easier than you thought in the beginning, isn’t it?</p><h4>Debugging Common Issues</h4><p>API requests to the RD service in the user’s machine (user’s localhost) may fail with the error “blocked:other” if an ad-blocker is active, please turn off the ad-blocker to proceed.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*XMFSS3SEpveJ4u33gnDLdg.png" /><figcaption>Ad-blocker error</figcaption></figure><h4>Final Thoughts</h4><p>As you may have understood from the above explanation, these APIs can be used for any Aadhaar-based biometric verification (fingerprint/ iris/ face verification), we just need to tweak the request body a little and that’s about it.</p><p>I have implemented fingerprint flow in a React application, the code is hosted in a Git repo <a href="https://github.com/nakul5harma/mantra-avdm-react">here</a>. Also, this application is deployed in <a href="https://nakul5harma-mantra-avdm-react.herokuapp.com/">Heroku</a>.</p><p>Hope this helps.</p><h4>References</h4><ul><li><a href="http://download.mantratecapp.com/StaticDownload/Mantra_RD_Service_Manual_Windows.pdf">Mantra RD Service Manual</a></li><li><a href="https://uidai.gov.in/images/resource/aadhaar_registered_devices_2_0_09112016.pdf">Aadhaar Registered Devices Specification</a></li><li><a href="https://uidai.gov.in/images/resource/aadhaar_ekyc_api_2_1.pdf">AADHAAR E-KYC API SPECIFICATION — VERSION 2.1</a></li><li><a href="https://nulm.gov.in/PDF/UIDAI-APIerrorcode.pdf">EKYC API 2.0 Error Handling document</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=33f5b095ef4d" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Find the distance between two coordinates using the haversine formula (Typescript/ JavaScript)]]></title>
            <link>https://medium.com/@nakul5harma/distance-between-two-coordinates-using-haversine-formula-272325ec8e9a?source=rss-56bc05049a5------2</link>
            <guid isPermaLink="false">https://medium.com/p/272325ec8e9a</guid>
            <category><![CDATA[radial-distance]]></category>
            <category><![CDATA[haversine]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[typescript]]></category>
            <category><![CDATA[haversinedistance]]></category>
            <dc:creator><![CDATA[Nakul Sharma]]></dc:creator>
            <pubDate>Thu, 27 Oct 2022 08:24:25 GMT</pubDate>
            <atom:updated>2023-02-02T08:17:22.794Z</atom:updated>
            <content:encoded><![CDATA[<p>Have you come across a situation where you needed to check the distance between two points on a map, not the distance by roads and rail networks but the direct distance between both points? Maybe…or maybe not, but are you curious now about how can we do it?</p><p>Think of a food delivery app, a customer opens the app and orders the food, and a delivery partner picks up the order from the restaurant and delivers it to the customer. Now, the delivery partner could be 100 meters or a kilometre away from the customer’s location and could simply press the button in the app that he has reached the location, wouldn’t that confuse customers about the whereabouts of their order? This problem could also appear in other location-based services, like a cab-hailing service or a parcel delivery service.</p><p>How do we go about solving the problem? Here’s a simple trick on how you can do that. It’s quick, easy and free!</p><p>A simple solution could be calculating the radial distance between both locations and enforcing distance checks on these actions.</p><p>Now, what do I mean by radial distance? Is it a regular distance between two points by road? No, it’s not. It is a distance measured by a straight line drawn between both locations, ignoring all the roads and trails. I’m sure in a sci-fi or a war movie you would have seen a screen with warplanes appearing on the radar and closing in on the location, the distance shown on that screen is measured by drawing a straight line from the warplane to the radar location, this distance is called the radial distance between these points.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/500/1*MhkL-87z51cR20h_w42lRQ.gif" /><figcaption>Objects on RADAR</figcaption></figure><h4>What is the haversine formula and how can we use it for calculating distances between two coordinates?</h4><p>We can calculate the radial distance between any two points on a sphere using the <a href="https://en.wikipedia.org/wiki/Haversine_formula">haversine formula</a>. But wait, the earth is not a perfect sphere…right? Yup, it is not, in fact, it is an oblate spheroid.</p><p>How are we supposed to get accurate results with this formula then?</p><p>The haversine formula works perfectly in practical cases with relatively short distances, and by short distances, I mean a few hundred kilometres. The Haversine formula is an old equation used by navigators before the invention of modern-day navigation systems. However, as I said you could use it to calculate distances on land as well.</p><p>Let’s have a look at the haversine formula -</p><blockquote>a = sin²(Δφ/2) + cos φ1 ⋅ cos φ2 ⋅ sin²(Δλ/2)</blockquote><blockquote>c = 2 ⋅ atan2( √a, √(1−a) )</blockquote><blockquote>Distance = R ⋅ c</blockquote><blockquote>here φ is latitude, λ is longitude, R is earth’s radius (mean radius = 6,371km).</blockquote><p>Please visit <a href="https://www.movable-type.co.uk/scripts/latlong.html">this</a> page for technical definitions. I have implemented the haversine formula in TypeScript below.</p><pre>export interface Coordinates {<br>  latitude: number;<br>  longitude: number;<br>}</pre><pre>const getRadiansFromDegrees = (degrees: number) =&gt; {<br>  return (degrees * Math.PI) / 180;<br>};</pre><pre>export const calculateRadialDistanceBetweenCoordinates = (<br>  sourceCoordinates: Coordinates,<br>  destinationCoordinates: Coordinates<br>) =&gt; {<br>const EARTH_RADIUS_IN_METERS = 6371e3;</pre><pre>const sourceLatitudeInRadians = getRadiansFromDegrees(<br>  sourceCoordinates.latitude<br>);<br>const destinationLatitudeInRadians = getRadiansFromDegrees(<br>  destinationCoordinates.latitude<br>);<br>const latitudeDifference = getRadiansFromDegrees(<br>  destinationCoordinates.latitude — sourceCoordinates.latitude<br>);<br>const longitudeDifference = getRadiansFromDegrees(<br>  destinationCoordinates.longitude — sourceCoordinates.longitude<br>);</pre><pre>const haversineOfCentralAngle =<br>  Math.pow(Math.sin(latitudeDifference / 2), 2) +<br>  Math.cos(sourceLatitudeInRadians) *<br>  Math.cos(destinationLatitudeInRadians) *<br>  Math.pow(Math.sin(longitudeDifference / 2), 2);</pre><pre>const centralAngle = 2 * Math.atan2(<br>  Math.sqrt(haversineOfCentralAngle),<br>  Math.sqrt(1 — haversineOfCentralAngle)<br>);</pre><pre>const distanceInMeters = EARTH_RADIUS_IN_METERS * centralAngle;</pre><pre>return Number(distanceInMeters.toFixed(3));<br>};</pre><p>You could add a simple method to check if the delivery partner is within the allowed distance or not, like the one below.</p><pre>export const isDeliveryPartnerInAllowedRange = (<br>  sourceCoordinates: Coordinates,<br>  destinationCoordinates: Coordinates,<br>  allowedMaxDistanceInMeters: number<br>) =&gt; {<br>const radialDistanceInMeters = calculateRadialDistanceBetweenCoordinates(<br>  sourceCoordinates,<br>  destinationCoordinates<br>);</pre><pre>if (radialDistanceInMeters &gt; allowedMaxDistanceInMeters) {<br>  return false;<br>}</pre><pre>return true;<br>};</pre><p>Add about a <a href="https://gis.stackexchange.com/questions/25494">0.3% error margin</a> in the total allowed distance so you don’t get false negatives.</p><h4>Final thoughts</h4><p>This is a very simple and cost-effective way to get the distance between any two points. Now you can calculate direct distances between any two points completely free and that too without the internet!</p><p>I have hosted the above snippet in <a href="https://gist.github.com/nakul5harma/3f459045a45be0921f9abef3207adeb2">this</a> GitHub gist.</p><p>I hope this helps, till then happy coding!!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=272325ec8e9a" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>