<?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 Andras Sevcsik-Zajácz on Medium]]></title>
        <description><![CDATA[Stories by Andras Sevcsik-Zajácz on Medium]]></description>
        <link>https://medium.com/@sevcsik?source=rss-3123ea866af2------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*u05H0TAyK9dQEklz.jpeg</url>
            <title>Stories by Andras Sevcsik-Zajácz on Medium</title>
            <link>https://medium.com/@sevcsik?source=rss-3123ea866af2------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 07:00:29 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@sevcsik/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[Writing CSS that scales: Encapsulation]]></title>
            <link>https://medium.com/@sevcsik/writing-css-that-scales-encapsulation-87a6af310624?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/87a6af310624</guid>
            <category><![CDATA[css]]></category>
            <category><![CDATA[code-quality]]></category>
            <category><![CDATA[front-end-development]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Mon, 04 Feb 2019 11:29:28 GMT</pubDate>
            <atom:updated>2019-02-04T11:29:28.549Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post was originally published on </em><a href="https://sevdev.hu/posts/2019-02-03-writing-css-that-scales-encapsulation.html"><em>my blog</em></a><em>.</em></p><p>Usually we don’t take code organisation and architectural discipline seriously when writing stylesheets, because it’s “just CSS”. But over time, when your product grows, things get ugly. Changes in one component break the other, implementing a facelift on a shared component makes the whole product fall apart.</p><p><strong>CSS is code</strong>, and just like any other code, it needs to have a design, be refactored time to time and adhere to set of common principles in order to scale. As any other language, it needs to be learned and it is hard. Don’t be like <a href="https://giphy.com/gifs/frustrated-annoyed-programming-yYSSBtDgbbRzq">this guy</a>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*b7ef9dSP72SXoJ9dsuePlg.jpeg" /></figure><p>If you’re using a somewhat modern front-end framework (like Angular, React, or more recently <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components">Web Components</a>), you’re building your UI out of components. Likely these components are identified by a custom HTML element name, and a fixed, well-defined API for changing it’s inner content (attributes/properties or DOM insertion points).</p><p>Now, you wouldn’t override the inner variables outside the component, would you? That would break the encapsulation: you no longer use the API to customise the behaviour, but your code will rely in the inner workings of the component, making your code break when it’s refactored.</p><p>The same applies to CSS: the inner DOM of a component is private and is a subject to change. Unfortunately CSS doesn’t know these boundaries because they are defined by your UI framework (unless you use <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM">Shadow DOM</a>).</p><p>So it’s up to your diligence to not cross this boundary. Let’s say you have a my-message-bubble element which displays an important message in a coloured box. Like this:</p><pre>&lt;my-message-bubble id=&quot;mybubble&quot; type=&quot;error&quot;&gt;Oh no!&lt;/my-message-bubble&gt;</pre><p>Which gets rendered into:</p><pre>&lt;my-message-bubble id=&quot;mybubble&quot; type=&quot;error&quot;&gt;<br>    &lt;div class=&quot;msg-background error&quot;&gt;<br>        &lt;span class=&quot;msg-text&quot;&gt;Oh no!&lt;/span&gt;<br>    &lt;/div&gt;<br>&lt;/my-message-bubble&gt;</pre><p>This element can accept “error” and “info” messages which paints a red or blue box with a message in it. But in your story, you need a yellow background, because it’s a warning!</p><h3>DON’T write CSS that relies on DOM which is not owned by you</h3><p>It’s an easy thing to do from CSS:</p><pre>#mybubble .msg-background {<br>  background: yellow;<br>}</pre><p>With this solution, you suddenly rely on</p><ul><li>there is an .msg-background element rendered by the component</li><li>the background colour is set by having a background rule on that element</li></ul><p>It’s easy to see that that your code will break if somebody wants to change the inner DOM of my-component, or even if they just decide to use background-color instead of background. It’s not just about refactoring: maybe the author will add an icon, or a border. Then you will have a yellow box with red border and an error icon.</p><p>When your product gets big, there will be hundreds of messages like this. Making the changes above will take a week instead of an hour, because you’ll have to scan every use case of your component if it still works as expected.</p><h3>DO extend components with the needed behaviour</h3><p>Instead of overriding the CSS from the outside, extend the component so it will support a warning value in the type attribute, and add the extra styling to the component’s stylesheet.</p><p>If you work in a large organisation, this will take more time. Likely the component you modify is owned by another team. It looks like an overhead, but actually, it serves you good. It makes you <strong>think twice</strong> before changing an existing UI component.</p><h3>DO think before changing an existing UI component</h3><p>Are you sure you’re using the correct element? Maybe <strong>there’s a reason</strong> for my-message-bubble supports only error and info. Maybe there’s another element for displaying warnings. Maybe there are no warnings in your project at all, you’re just the first to need it. In that case, all the others should need to display a warning, will be able because of you, and all warnings will be displayed the same way in the future.</p><p>Doing this not just helps with code quality and refactoring, but it also helps with maintaining a consistent user experience across the product. When a lot of people work on the same product, a some of them will think differently, and come up with different UX patterns for the same problem.</p><p>This can quickly lead to a cluttered, inconsistent user experience which will be a huge job to untangle afterwards. Honour encapsulation, and the UX people will love you.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87a6af310624" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Failure culture: Beyond blaming]]></title>
            <link>https://medium.com/@sevcsik/failure-culture-beyond-blaming-5f9b70110ccd?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/5f9b70110ccd</guid>
            <category><![CDATA[failure]]></category>
            <category><![CDATA[agile]]></category>
            <category><![CDATA[culture]]></category>
            <category><![CDATA[development]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Mon, 01 Oct 2018 17:43:19 GMT</pubDate>
            <atom:updated>2018-10-01T17:47:04.679Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This article was originally published </em><a href="https://sevdev.hu/posts/2018-09-30-failure-culture-beyond-blaming.html"><em>on my blog</em></a><em>.</em></p><p>It’s inevitable that people make mistakes. Often, the impact of these mistakes are high — sometimes it breaks other team’s code, introduces regressions which can lurk around for a long time. On large projects, especially where a good chunk of legacy is in play, mistakes happen more often and are way more harder to find.</p><p>You can also make a mistake by having the wrong idea; you stick to it, pour more and more of your (and others’) energy into it, and it turns out not being a solution to your problem.</p><p>At the end of the day, you <strong>will</strong> fail as everyone else, and you have to be able to make that failure useful, so it can contribute to your next success.</p><h3>The Blame Game</h3><p>Probably you heard these a plenty times:</p><ul><li>“I’ve told this a thousand times but people are <strong>still doing it</strong>!”</li><li>“Great, another three months of work thrown out the window”</li><li>and my personal favourite: “Who will take the responsibility for this?”</li></ul><p>If the <em>lack of accountability</em> and <em>blame game</em> are recurring themes on your retrospectives, your organisation might have a problem with handling failure. These two issues may seem contradictory, but in fact they go hand in hand and amplify each other.</p><p>If people see that mistakes are left unhandled, they will call each other out on it — probably not the most polite way, out of frustration, doing a lot of collateral damage in the process. When people expect to be blamed and pilloried for making mistakes, they are more likely to avoid admitting their mistakes and thus learn from them.</p><p>Culture won’t change by talking about it. What you can do is start acting on it and believe that others will follow.</p><h3>How <a href="http://agilemanifesto.org/principles.html">Agile Development</a> Helps Dealing with Failure</h3><p>Agile development methods focus on people, adaptability and of course quality. Learning from failures are not just an option, but a core part of the methodology. Every mistake is an opportunity to adapt, and they have to be taken care of in a way to get the most value out of them. If they are handled properly, failure can be just as valuable as success.</p><h4>Trust</h4><p>We trust people to deliver. It doesn’t mean we’re not prepared for someone failing but if it happens, we trust that we will learn from the failure and adapt.</p><h4>Transparency</h4><p>Transparency is a core value of agile development. Responsibilities are clearly defined, progress is clearly communicated and each and every one’s work must be visible for team members and external stakeholders. In a truly agile workflow, “getting away” with a mistake cannot be possible.</p><h4>Continuous Feedback</h4><p>Breaking down the work to bite-size chunks and delivering working software as frequently as possible limits the impact of a failure and allows us to adapt quickly.</p><h4>Retrospective</h4><p>Regularly reflecting on how the team operates gives us the opportunity to learn from our mistakes and adjust our processes to make sure that the mistake won’t happen again.</p><h4><a href="https://www.mikecrunch.com/mvv-is-the-new-mvp/?utm_campaign=Submission&amp;utm_medium=Community&amp;utm_source=GrowthHackers.com">Minimum Viable Value</a></h4><p>When trying out new ideas, it’s essential that we concentrate on delivering the MVV that’s enough to test the validity of the idea. In case of the idea turns out to be invalid or not feasible, we can limit the amount of sunk costs by getting that information as soon as possible.</p><h3>How to Handle Failure in a Constructive Way</h3><h4>If You are the One to Blame</h4><p>You made a mistake. It might be a pretty banal one. Somehow it all the way through, wasting others’ time / went to production / disrupted the work of another team. Shit happens.</p><p>Whether you discovered your own mistake or someone else did, <strong>take ownership</strong>. Open a bug, talk to your boss, and fix it ASAP. <strong>Be honest</strong> about how did the mistake happen. Most importantly, identify what can you do different in the future to avoid making the same mistake again. It’s not just for you: others can learn from your experience as well.</p><p>Be proactive and find ways to catch mistakes like this in the future. Maybe a new tool could help to catch this earlier or the <a href="https://shift.newco.co/2017/07/23/team-working-agreements-the-why-what-and-how">working agreement</a> should be extended. Be sure to bring up the issue on your next retrospective.</p><p>What you should not do is to shift blame to others. Yes, you made the mistake, but it passed the review and testing! <em>They also made a mistake!</em>. Perhaps they did, but it doesn’t make your mistake smaller. Leave the dealing with their part of the responsibility to them, and concentrate on your own.</p><p>On the other hand, if you see someone taking responsibility and you also feel responsible, join the discussion and elaborate how you could do your part better.</p><p>It’s worth it. Admitting your mistakes not just help you and your organisation to learn, but it also helps you to keep your integrity and build your character. No wonder why <a href="https://www.theregister.co.uk/2018/09/17/linus_torvalds_linux_apology_break">great</a> <a href="https://en.wikipedia.org/wiki/Tony_Hoare#Apologies_and_retractions">people</a> <a href="https://www.theverge.com/2013/9/26/4772680/bill-gates-admits-ctrl-alt-del-was-a-mistake">are</a> <a href="https://www.zdnet.com/article/double-slash-in-web-addresses-a-bit-of-a-mistake">doing</a> <a href="https://www.theguardian.com/technology/2018/mar/21/mark-zuckerberg-response-facebook-cambridge-analytica">it</a>.</p><h4>If You are the One Who Blames</h4><p>You found a nasty bug. Turns out to be a rookie mistake, or even worse, blatant ignorance. You can’t imagine making such mistake because you’re one of the <a href="https://en.wikipedia.org/wiki/Illusory_superiority">90% who’s above the average</a>. Your day is ruined because you spent time cleaning up someone’s mess instead of doing something useful.</p><p>First of all, give yourself time to calm down. Then try to reach the person privately: give them the chance to take ownership of their mistake and manage it according to the previous section. If it doesn’t work, talk to their manager or a senior member of their team.</p><p>Don’t start with gathering evidence and writing an essay about what went wrong, you’re not going on a trial. You’re not just wasting your own time with it, but creating an atmosphere where the other will feel like they need to defend themselves instead of taking ownership of their mistake.</p><p>Of course if you have some <strong>constructive</strong> thoughts, it’s ok to publish them on a broader forum, but do it with diligence and only after you tried talking to the “offender” privately first. And <strong>never, ever</strong> do it in a way that the affected person is not involved and cannot participate in the discussion.</p><h3>References</h3><ul><li><a href="https://hbr.org/2010/05/how-to-stop-the-blame-game">How to Stop the Blame Game</a> on Harvard Business Review</li><li><a href="https://www.cornerstoneondemand.com/rework/what-does-it-mean-create-culture-failure">What Does It Mean to Create a ‘Culture of Failure’?</a> on Rework Magazine</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Vh3-TH0XDw7vsH97kqBssA.jpeg" /></figure><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=5f9b70110ccd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Authentication using HTTPS client certificates]]></title>
            <link>https://medium.com/@sevcsik/authentication-using-https-client-certificates-3c9d270e8326?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/3c9d270e8326</guid>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ssl]]></category>
            <category><![CDATA[https]]></category>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[cryptography]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Sat, 22 Jul 2017 21:56:21 GMT</pubDate>
            <atom:updated>2017-07-22T21:56:21.745Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post was originally published </em><a href="https://sevdev.hu/ipfs/QmUm5Vo4HNqgwFPp1jkUtKezwjRYk3g5kFgMANiWnXxWQh/posts/2017-07-22-authentication-using-https-client-certificates.html"><em>on my blog</em></a><em>.</em></p><p>We hear a lot about how passwords are insecure, and should not be used alone for authentication. They are hard to remember, so users are tempted to come up with weak passwords, and reuse them across multiple websites. Even if the password is strong, it’s still just a short string the users <em>know</em>.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fYmkQAgITtz0pdNfSMKWZA.jpeg" /><figcaption>Image from betanews.com</figcaption></figure><p>There are numerous ways to mitigate this, such as <a href="https://en.wikipedia.org/wiki/HMAC-based_One-time_Password_Algorithm">HMAC or</a> <a href="https://en.wikipedia.org/wiki/Time-based_One-time_Password_Algorithm">time-based one-time passwords</a> or more recently <a href="https://en.wikipedia.org/wiki/Universal_2nd_Factor">universal 2nd-factor</a> hardware tokens. They all based on something the user <em>has</em>, rather than something they <em>know</em>. What they <em>have</em> is a secret key, which they can use to generate a password or sign messages.</p><p>What seems to be forgotten in the consumer world is that every browser has had a feature built-in since TLS was introduced, called <a href="https://en.wikipedia.org/wiki/Mutual_authentication">mutual authentication</a>, which allows the user to present a certificate as well as the server. This means the user can authenticate with something they <em>have</em> and — if the certificate is protected by a passphrase — something they <em>know</em>.</p><p>In this post, we implement a simple Node.js example which uses client certificates to authenticate the user.</p><p>We only one need external dependency, express, otherwise, we just depend on the standard Node.js HTTPS server. We also need fs to read the certificates/keys to configure HTTPS.</p><pre>const express = require(&#39;express&#39;)<br>const fs = require(&#39;fs&#39;)<br>const https = require(&#39;https&#39;)</pre><h3>Setting up the private key and the certificate</h3><p>First of all, we need to generate our keys and certificates. We use the openssl command-line tool. On Linux, it’s likely already installed – if not, install the openssl package of your distribution. On Windows it’s a bit trickier, see <a href="https://www.tbs-certificates.co.uk/FAQ/en/openssl-windows.html">this tutorial</a>;</p><p>Like with every regular HTTPS server, we need to generate a server certificate. For the sake of brevity, we use a self-signed certificate here — in real life, you probably want to use a well-known certificate authority, such as <a href="https://letsencrypt.org/">Let’s Encrypt</a>.</p><p>To generate a self-signed certificate (in our case, without encryption):</p><pre>$ openssl req -x509 -newkey rsa:4096 -keyout server_key.pem -out server_cert.pem -nodes -days 365 -subj &quot;/CN=localhost/O=Client\ Certificate\ Demo&quot;</pre><p>This is actually a three-step process combined into one command:</p><ul><li>Create a new 4096bit RSA key and save it to server_key.pem, <em>without</em> DES encryption (-newkey, -keyout and -nodes)</li><li>Create a Certificate Signing Request for a given subject, valid for 365 days (-days, -subj)</li><li>Sign the CSR using the server key, and save it to server_cert.pem as an X.509 certificate (-x509, -out)</li></ul><p>We could have also done this with tree commands, openssl genrsa, openssl req and openssl x509. We used the PEM format (the default setting), which is a base64-encoded text file with a ----- BEGIN/END CERTIFICATE/PRIVATE KEY ----- header and footer. Another option would be the DER format, which uses binary encoding. There is a bit of a confusion what the file extension should refer to: it’s also common to use .key or .crt, referring to the contents of the file rather than the encoding (in which case they can contain both DER- and PEM-encoded data).</p><h3>Configuring the Node.js HTTP server</h3><p>Let’s add our server key and certificate to the options object, which we pass to the HTTPS server later:</p><pre>const opts = { key: fs.readFileSync(&#39;server_key.pem&#39;)<br>             , cert: fs.readFileSync(&#39;server_cert.pem&#39;)</pre><p>Next, we instruct the HTTPS server to request a client certificate from the user</p><pre>, requestCert: true</pre><p>Then we tell it to accept requests with no valid certificate. We need this to handle invalid connections as well (for example to display an error message), otherwise, they would just get a cryptic HTTPS error message from the browser (ERR_BAD_SSL_CLIENT_AUTH_CERT to be precise)</p><pre>, rejectUnauthorized: false</pre><p>Finally, we supply a list of CA certificates that we consider valid. For now, we sign client certificates with our own server key, so it will be the same as our server certificate.</p><pre>, ca: [ fs.readFileSync(&#39;server_cert.pem&#39;) ]<br>             }</pre><p>Then we create our app. We use express only for routeing here — we could use the <a href="http://passportjs.org/">passport middleware</a> as well, with a <a href="https://github.com/ripjar/passport-client-cert">strategy for client certificates</a>, but for now, we keep things simple.</p><pre>const app = express()</pre><p>We add our “landing page” first. This is unprotected, so everyone will see it whether they present a client cert or not.</p><pre>app.get(&#39;/&#39;, (req, res) =&gt; {<br>	res.send(&#39;&lt;a href=&quot;authenticate&quot;&gt;Log in using client certificate&lt;/a&gt;&#39;)<br>})</pre><p>Then we add our protected endpoint: it just displays information about the user and the validity of their certificate. We can get the certificate information from the HTTPS connection handle:</p><pre>app.get(&#39;/authenticate&#39;, (req, res) =&gt; {<br>	const cert = req.connection.getPeerCertificate()</pre><p>The req.client.authorized flag will be true if the certificate is valid and was issued by a CA we white-listed earlier in opts.ca. We display the name of our user (CN = Common Name) and the name of the issuer, which is localhost.</p><pre>if (req.client.authorized) {<br>		res.send(`Hello ${cert.subject.CN}, your certificate was issued by ${cert.issuer.CN}!`)</pre><p>They can still provide a certificate which is not accepted by us. Unfortunately, the cert object will be an empty object instead of null if there is no certificate at all, so we have to check for a known field rather than truthiness.</p><pre>} else if (cert.subject) {<br>		res.status(403)<br>		   .send(`Sorry ${cert.subject.CN}, certificates from ${cert.issuer.CN} are not welcome here.`)</pre><p>And last, they can come to us with no certificate at all:</p><pre>} else {<br>		res.status(401)<br>		   .send(`Sorry, but you need to provide a client certificate to continue.`)<br>	}<br>})</pre><p>Let’s create our HTTPS server and we’re ready to go.</p><pre>https.createServer(opts, app).listen(9999)</pre><p>Then we can start our server with npm i &amp;&amp; node server.js.</p><h3>Setting up client certificates</h3><p>If we try to “log in” to our site now, we get a 401 response, because we don’t have any client certificates yet. To test our setup, we create two certificates for our two users, Alice and Bob. Alice is nice as she has a valid certificate issued by us, while Bob is nasty and tries to log in using a self-signed certificate.</p><p>To create a key and a Certificate Signing Request for Alice and Bob we can use the following command:</p><pre>$ openssl req -newkey rsa:4096 -keyout alice_key.pem -out alice_csr.pem -nodes -days 365 -subj &quot;/CN=Alice&quot;<br>$ openssl req -newkey rsa:4096 -keyout bob_key.pem -out bob_csr.pem -nodes -days 365 -subj &quot;/CN=Bob&quot;</pre><p>We sign Alice’s CSR with our key and save it as a certificate. Here, we act as a Certificate Authority, so we supply our certificate and key via the -CA parameters:</p><pre>$ openssl x509 -req -in alice_csr.pem -CA server_cert.pem -CAkey server_key.pem -out alice_cert.pem -set_serial 01 -days 365</pre><p>Bob doesn’t believe in authority, so he just signs his certificate on his own:</p><pre>$ openssl x509 -req -in bob_csr.pem -signkey bob_key.pem -out bob_cert.pem -days 365</pre><h3>Trying to get in</h3><p>To use these certificates in our browser, we need to bundle them in PKCS#12 format. That will contain both the private key and the certificate, thus the browser can use it for encryption. For Alice, we add the -clcerts option, which excludes the CA certificate from the bundle. Since we issued the certificate, we already have the certificate: we don’t need to include it in Alice’s certificate as well. You can also password-protect the certificate.</p><pre>$ openssl pkcs12 -export -clcerts -in alice_cert.pem -inkey alice_key.pem -out alice.p12<br>$ openssl pkcs12 -export -in bob_cert.pem -inkey bob_key.pem -out bob.p12</pre><p>We can import these private keys to the browser. In Firefox, go to <em>Preferences -&gt; Advanced -&gt; View Certificates -&gt; Import</em>, and choose both files.</p><p>If you open <a href="https://localhost:9999/">https://localhost:9999</a> in the browser now, a dialog will come up to choose a certificate. Note that only Alice’s certificate is in the list: that’s because the browser already knows that only certs issued by us will be accepted (because we advertise it using the opts.ca list). If you continue, you’ll see our success message with the details of Alice.</p><p>This is only a browser limitation, you can still try to get in with Bob’s cert using cURL:</p><pre>$ curl --insecure --cert bob.p12 --cert-type p12 <a href="https://localhost:9999/authenticate">https://localhost:9999/authenticate</a></pre><p>And see that Bob’s not welcome here!</p><p>Of course this solution isn’t practical in real life: we don’t want to genereate keys for our users via the command line and have them installing them into their browsers manually. In the next article, we’ll see how we can generate new client certificates dynamically and install them seamlessly to the users’ browser.</p><p>To try this server, there clone <a href="https://github.com/sevcsik/client-certificate-demo/tree/chapter-1">this post’s github repo</a>, where you can also find the keys and certificates.</p><h3>Sources</h3><ul><li><a href="http://nategood.com/nodejs-ssl-client-cert-auth-api-rest">SSL Client Authentication in Node.js</a></li><li><a href="http://info.ssl.com/article.aspx?id=12149">Q12149 — HOWTO: DER vs. CRT vs. CER vs. PEM Certificates and How To Convert Them</a></li><li><a href="https://gist.github.com/mtigas/952344">Mini tutorial for configuring client-side SSL certificates</a></li><li><a href="https://github.com/tgies/client-certificate-auth/blob/master/lib/clientCertificateAuth.js">client-certificate-auth</a></li><li><a href="https://stackoverflow.com/questions/10175812/how-to-create-a-self-signed-certificate-with-openssl#10176685">diegows’s answer to “How to create a self-signed certificate with openssl?”</a></li></ul><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3c9d270e8326" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Bitcoin HD wallets II: Deriving public keys]]></title>
            <link>https://medium.com/@sevcsik/working-with-bitcoin-hd-wallets-ii-deriving-public-keys-c48341629388?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/c48341629388</guid>
            <category><![CDATA[cryptocurrency]]></category>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[blockchain]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Mon, 16 Jan 2017 00:00:00 GMT</pubDate>
            <atom:updated>2017-02-09T23:53:27.391Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post is the continuation of </em><a href="https://sevdev.hu/ipns/sevdev.hu/posts/2016-11-16-working-with-bitcoin-hd-wallets.html"><em>my previous about key derivation</em></a>.</p><p>So we already know how to create an huge amount of wallets using a recovery seed or an extended private key, the well-known derivation method described in <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki">BIP32</a> and the derivation paths of <a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki">BIP44</a>.</p><p>However, generating keys based on the private key puts limits on the possible use cases. The private key allows to spend the coins sent to its own or its descendants’ addresses, so it must be kept secret. That implies that you have to fully trust the code and the runtime you use to generate your addresses.</p><p>There’s a way to generate addresses in an untrusted environment though: using extended public keys.</p><h3>Extended public keys</h3><p>Extended private keys are regular private keys, extended with a 32-byte chain code. As each private key has a corresponding public key, so extending this its public key with the same chain code gives us — wait for it — the extended public key.</p><p>With an extended public key, it’s possible to derive child public keys using the same method, without knowing the sensitive private key.</p><h3>Security concerns</h3><p>Although extended public keys cannot be used to get access to the private keys (and funds), they are still more sensitive than regular public keys. A leaked extended public key makes it possible to reconstruct every possible derived public key, destroying the privacy gained from using key derivation in the first place.</p><p>Also, due to the <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki#user-content-Security">mathematical properties of the CKD function</a>, given an extended public key and one of the descendants of its corresponding private key, it is possible to recreate the extended private key and all its other descendant private keys. Thus, having a leaked public key can amplify the damage caused by a leaked child private key, which would be limited to its own funds otherwise.</p><h3>Hardened derivation</h3><p>To mitigate this issue, there is a special case of key derivation, called hardened derivation. A quick reminder: the derivation function has two inputs, the extended key and the index, which is a 32-bit integer. We can split this 32-bit space into two halves, above and below 231. You can derive private keys at both halves, but only the lower half can be used to derive public keys, achieved by mixing the <a href="https://bitcoin.org/en/developer-guide#hardened-keys">parent private key into the formula</a> if the index is higher than 231.</p><p>Private keys derived with an index of the upper half are called <em>hardened keys</em>, and in the derivation path (the string of indexes which is used for derivation) are denoted with the <a href="https://en.wikipedia.org/wiki/Prime_%28symbol%29">prime symbol</a> (&#39;), relative to 231.</p><p>To learn more about the cryptographic background of hardened keys and their usefulness, check out the <a href="https://bitcoin.org/en/developer-guide#hardened-keys">Developer Guide on bitcoin.org</a>.</p><h3>Hardened keys in HD wallets</h3><p>Wallet software implementing <a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki">BIP44</a> are using the following derivation scheme:</p><pre>m / 44&#39; / coin_type&#39; / account&#39; / change / address_index</pre><p>The first three levels are hardened, meaning it’s not possible to derive the different accounts’ public keys from the master public key. Using the accounts’ extended public keys though, it is possible to generate every address under that account, making it possible to generate “read-only” addresses without risking the accounts’ funds. If one account’s extended private key or one of its child private keys are exposed, that damage will be limited to that account but the other accounts are kept safe.</p><p>In the next article, we’ll see a real-life scenario of how key derivation and extended public keys can make a life easier for an enterprise running on Bitcoin.</p><p><em>Originally published at </em><a href="https://sevdev.hu/ipns/sevdev.hu/posts/2017-01-16-working-with-bitcoin-hd-wallets-ii.html"><em>sevdev.hu</em></a><em> on January 16, 2017.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c48341629388" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Working with Bitcoin HD wallets: Key derivation]]></title>
            <link>https://medium.com/@sevcsik/working-with-bitcoin-hd-wallets-key-derivation-14cde4f60e11?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/14cde4f60e11</guid>
            <category><![CDATA[bitcoin]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[cryptocurrency]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Wed, 16 Nov 2016 00:00:00 GMT</pubDate>
            <atom:updated>2017-02-09T23:52:28.458Z</atom:updated>
            <content:encoded><![CDATA[<p>If you are using Bitcoin regularly, you may have noticed that modern wallets let you create multiple accounts with the same recovery seed and they create a new address each time you create a payment request. This is important for privacy reasons (if you were reusing the same address, your balance and your transaction history would be publicly visible on the blockchain).</p><p>Key derivation has much more exciting applications though. You can have a cold wallet stored securely, and you derive all your hot wallets from it. If a hot wallet is compromised or lost, the rest of your wallets stay safe, and you can restore the funds from the lost wallet using the cold wallet. Or imagine a large organisation, where there is a top-level wallet managed by the CFO, and each department have there budgets on their sub-wallets, having budget sub-wallets for different spending categories, and so on.</p><h3>Public-key cryptography</h3><p>As you might already know, Bitcoin is based on <a href="https://en.wikipedia.org/wiki/Public-key_cryptography">public-key, AKA asymmetric cryptography</a>. Every Bitcoin address is based on a public key. Knowing an address lets you send transactions to that address, and see every transaction involving that address (giving you the “balance”).</p><p>What you cannot do, is to create new transactions <em>from</em> that address. You need the <em>private key</em> for that. The public key can be generated from the private key, but not the other way around. The private key should always stay secret, as it allows the owner to spend the money from a given address.</p><p>The private key is a long sequence, not meant for human consumption. To store a private key it can be encoded to a QR code and printed. Alternatively it can be deterministically generated from a random seed, which can be represented by a set of natural language words (mnemonics). These words are picked from a <a href="https://github.com/bitcoin/bips/blob/master/bip-0039/bip-0039-wordlists.md">2048-word list</a>, defined by the <a href="https://github.com/bitcoin/bips/blob/master/bip-0039.mediawiki">BIP39</a> standard. BIP39 seeds can optionally be salted with a passphrase. Both QR codes and mnemonics are relatively resilient, making them suitable for long-term storage.</p><h3>Child key derivation (CKD)</h3><p>To have a lot of addresses and to be able to spend the funds arriving to those, we need to keep track of the private key for each address. This is how old wallets work: they generate new keys in batches, so the users have to make regular backups of their wallets, to keep their set of keys up to date. If the wallet is lost and the backup is not up to date, funds received by the new addresses which are not backed up are lost forever.</p><p>Using key derivation, this is no longer necessary: with a predefined algorithm, one can generate child keys based on a master key, use those child keys as master keys to generate new children, and so on. Bitcoin’s algorithm of choice is defined in the <a href="https://github.com/bitcoin/bips/blob/master/bip-0032.mediawiki">BIP32</a> standard.</p><p>The BIP32 CKD function has three parameters: The key itself, a so-called “chain code” and an index. The combination of the key and the chain code is called an extended key. The index is a 32-bit integer, allowing us to derive 232child keys. In case you were wondering, that’s a <em>lot</em> of child keys.</p><h3>HD wallets</h3><p>As I mentioned already, a child key is also an extended key, so we can use it to generate more child keys. That gives us a tree of keys — hence the name hierarchical deterministic wallet (HD wallet for short). The list of indexes used in each step gives us the <em>derivation path</em> of a key, like m/1/2/3, where m denotes the initial key (AKA the <em>master key</em>).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/800/0*k6AjMZgk1q8SCpdD.png" /></figure><p><em>Key derivation paths illustrated in the BIP32 standard</em></p><p>Since there are endless possible variations of these paths, the <a href="https://github.com/bitcoin/bips/blob/master/bip-0044.mediawiki">BIP44</a> standard specifies a limited set to use in HD wallets. If a user imports their private key to a wallet application that implements BIP44 (such as Mycelium), it will automatically keep generating addresses for the first account (m/44&#39;/0&#39;/0&#39;/*/*), as long as it finds transactions for them. If you add a second account, it will do the same.</p><p>To be continued! In the next part, we’ll discover the mysteries of hardened derivation paths and the use of extended public keys.</p><p><em>Originally published at </em><a href="https://sevdev.hu/ipns/sevdev.hu/posts/2016-11-16-working-with-bitcoin-hd-wallets.html"><em>sevdev.hu</em></a><em> on November 16, 2016.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=14cde4f60e11" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Testing ngModel in Angular 2]]></title>
            <link>https://medium.com/@sevcsik/testing-ngmodel-in-angular-2-d9c79923f973?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/d9c79923f973</guid>
            <category><![CDATA[angular2]]></category>
            <category><![CDATA[testing]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-development]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Fri, 14 Oct 2016 10:55:03 GMT</pubDate>
            <atom:updated>2016-10-14T10:55:31.995Z</atom:updated>
            <content:encoded><![CDATA[<p>Originally published <a href="https://sevdev.hu/ipns/sevdev.hu/posts/2016-10-14-testing-ngmodel-in-angular-2.html">on my blog</a>.</p><p>Angular has always put an emphasis on automated testing. Angular 2 continues this tradition — the question of testing is ubiquitous, both the core design and the documentation, which is great.</p><p>Unfortunately, Angular 2 is a much more delicate and complex environment than Angular 1, so are the testing tools. This is a case study of testing a simple component with two-way binding, highlighting the pitfalls to avoid.</p><p><em>If you want to run the code examples, grab the </em><a href="https://bitbucket.org/sevcsik/ng2-ngmodel-testing-demo"><em>example repository</em></a><em> — it has a commit for each section.</em></p><p>Let’s create a simple component to test. I cut the boilerplate, here’s just the essence:</p><pre>export <strong>class</strong> AppComponent {<br>  theValue = &#39;lowercase&#39;;<br>}</pre><pre><strong>&lt;input</strong> <strong>[(ngModel)]</strong>=&quot;theValue&quot;<strong>&gt;</strong><br><strong>&lt;code&gt;</strong>{{ theValue | uppercase }}<strong>&lt;/code&gt;</strong></pre><p>Our requirement is pretty simple: What comes in the &lt;input&gt; should come out in uppercase in the &lt;code&gt;.</p><h3>The naive approach</h3><p>Let’s try (and fail miserably):</p><pre><em>// put our test string to the input element</em><br>fixture.debugElement.query(By.css(&#39;input&#39;)).nativeElement.value = &#39;test&#39;;</pre><pre><em>// expect it to be the uppercase version</em><br>expect(fixture.debugElement<br>              .query(By.css(&#39;code&#39;))<br>              .nativeElement<br>              .textContent<br>      ).toEqual(&#39;TEST&#39;);</pre><p>Result: Expected &#39;&#39; to equal &#39;TEST&#39; :(</p><p>Of course it fails! For a good reason: Angular doesn’t (cannot) update the bindings instantly. This is familiar from Angular 1 — we needed to call the dreaded $scope.apply() to trigger the digest loop, or wait for it to happen by itself.</p><h3>The change detector</h3><p>The Angular2 equivalent of this is <a href="https://angular.io/docs/ts/latest/api/core/index/ChangeDetectorRef-class.html">ChangeDetectorRef#detectChanges()</a>. Int the test environment, it’s exposed onCompnentFixture, and calling it will detect the changes and update the binings. Nice.</p><pre>it( &#39;should put the uppercased version of the input field\&#39;s input into&#39;<br>  + &#39;the code element&#39;, () =&gt; {</pre><pre><em>// put our test string to the input element</em><br>fixture.debugElement.query(By.css(&#39;input&#39;)).nativeElement.value = &#39;test&#39;;<br>fixture.detectChanges();</pre><pre><em>// expect it to be the uppercase version</em><br>expect(fixture.debugElement<br>              .query(By.css(&#39;code&#39;))<br>              .nativeElement<br>              .textContent<br>      ).toEqual(&#39;TEST&#39;);<br>});</pre><p>Result: Expected &#39;LOWERCASE&#39; to equal &#39;TEST&#39;. :(</p><p>A bit better, right? Now at least we have the initial value going through. The reason is that TestBed doesn’t run the change detector at all, unless asked to — so by default, not even the initial bindings are executed. (This behaviour can be changed with <a href="https://angular.io/docs/ts/latest/api/core/testing/index/ComponentFixture-class.html#!#autoDetectChanges-anchor">Fixture#autoDetectChanges</a>.)</p><h3>Triggering NgModel</h3><p>What we want to see, is the new value we put in the input field, not the initial one. The issue is that even though we updated the value property, that doesn’t trigger NgModel’s binding by itself. It listens to the input event, which is dispatched only on actual user input.</p><p>All we need to do is to dispatch an <a href="https://developer.mozilla.org/en-US/docs/Web/Events/input">InputEvent</a> (did you know that’s a thing?) on element and we’re good to go. Right?</p><pre>it( &#39;should put the uppercased version of the input field\&#39;s input into&#39;<br>  + &#39;the code element&#39;, () =&gt; {</pre><pre>  <em>// put our test string to the input element</em><br>  <strong>let</strong> element = fixture.debugElement.query(By.css(&#39;input&#39;)).nativeElement<br>  element.value = &#39;test&#39;;<br>  element.dispatchEvent(<strong>new</strong> Event(&#39;input&#39;));<br>  fixture.detectChanges();</pre><pre>  <em>// expect it to be the uppercase version</em><br>  expect(fixture.debugElement<br>                .query(By.css(&#39;code&#39;))<br>                .nativeElement<br>                .textContent<br>        ).toEqual(&#39;TEST&#39;);<br>});</pre><p>Result: Expected &#39;LOWERCASE&#39; to equal &#39;TEST&#39;. :(</p><h3>NgModel is asynchronous</h3><p>Now this is where it gets funky. After a bit searching, I found a <a href="https://github.com/angular/angular/commit/f444c11d218d26ac817d5f3b12e19c6b4b8d2390">commit to the changelog</a> which explains it: NgModel updates became asynchronous, so fixture.detectChanges() won’t be reflected instantly. We have to use theFixture#whenStable method, which gives us a promise to the stabilised state.</p><pre>it( &#39;should put the uppercased version of the input field\&#39;s input into&#39;<br>  + &#39;the code element&#39;, () =&gt; {<br>  fixture.detectChanges();</pre><pre>  <em>// put our test string to the input element</em><br>  <strong>let</strong> element = fixture.debugElement.query(By.css(&#39;input&#39;)).nativeElement;<br>  element.value = &#39;test&#39;;<br>  element.dispatchEvent(<strong>new</strong> Event(&#39;input&#39;));</pre><pre>  fixture.whenStable().then(() =&gt; {<br>    <em>// expect it to be the uppercase version</em><br>    expect(fixture.debugElement<br>                .query(By.css(&#39;code&#39;))<br>                .nativeElement<br>                .textContent<br>          ).toEqual(&#39;TEST&#39;);<br>  });<br>});</pre><p>Result (wait for it): <em>It works!</em></p><p>Note that I moved the fixture.detectChanges() call to the top, because alhtough we don’t need it anymore <em>after</em> we make changes, we still need an initial call to build the initial state of our component.</p><p>Now we are using promises. You don’t need to have a wild imagination to see this would look like a mess on more complicated test scenarios, if we had to chain every exception after a promise.</p><h3>Making it readable again</h3><p>Thankfully, Angular 2 provides a utility, called <a href="https://angular.io/docs/ts/latest/guide/testing.html#!#the-_fakeasync_-function">fakeAsync</a>, which magically allows us to turn our code sync again, with the help of the tick function. We just have to put the it callback into a fakeAsync wrapper, and we can “suspend” our flow until the async operations are ready.</p><p>Behold:</p><pre>it( &#39;should put the uppercased version of the input field\&#39;s input into&#39;<br>  + &#39;the code element&#39;, fakeAsync(() =&gt; {<br>  fixture.detectChanges();</pre><pre>  <em>// put our test string to the input element</em><br>  <strong>let</strong> element = fixture.debugElement.query(By.css(&#39;input&#39;)).nativeElement;<br>  element.value = &#39;test&#39;;<br>  element.dispatchEvent(<strong>new</strong> Event(&#39;input&#39;));</pre><pre>  tick();<br>  fixture.detectChanges();</pre><pre>  <em>// expect it to be the uppercase version</em><br>  expect(fixture.debugElement<br>              .query(By.css(&#39;code&#39;))<br>              .nativeElement<br>              .textContent<br>        ).toEqual(&#39;TEST&#39;);<br>}));</pre><p>It looks fine now, doesn’t it?</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=d9c79923f973" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[CSS vertical alignment without flexbox]]></title>
            <link>https://medium.com/@sevcsik/css-vertical-alignment-without-flexbox-a83eac44c574?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/a83eac44c574</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[css]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Tue, 20 Sep 2016 23:59:17 GMT</pubDate>
            <atom:updated>2016-09-20T23:59:36.678Z</atom:updated>
            <content:encoded><![CDATA[<p><em>This post was originally published on my </em><a href="http://sevdev.hu/ipns/sevdev.hu/posts/2016-09-19-vertical-alignment-without-flexbox.html"><em>blog</em></a><em>.</em></p><p>If you’re unlucky enough to have to support <a href="http://caniuse.com/#feat=flexbox">non-flexbox-capable browsers</a>, I’m pretty sure you had nightmares about vertical alignment. It’s the most ridiculously complicated thing in CSS. There are urban legends about people, who once aligned a box vertically in the middle of the screen, but they have never been seen again.</p><p>Usually, the solution is the following: use absolute positioning, top: 50%, and use negative margins to set the size of the element. If you can calc(), even better.</p><p>However, this only works if you know the height of the element beforehand. This is not always the case: you might want to have a dialog which grows with the content. And it’s counter-intuitive as well: negative margins just don’t make sense.</p><p>We do have something though that looks like exactly what we need. It’s called vertical-align: middle, the first disappointment in every web developers life. It seems to be the obvious solution — but it just doesn’t work.</p><p>The reason is that vertical-align is for text formatting. It doesn’t set the alignment of the children of the element, like text-align, but aligns the children themselves, relative to each other. This is a very common issue in HTML: It is designed around flowing text, not UI, so it feels unnatural to do things with it which should be obvious in a UI development framework.</p><p>That doesn’t mean we cannot use vertical-align, we just need to be a bit creative. Let’s say we have a .container element, and a .box. As we already know, it should be applied to .box, not .container, but it still doesn’t seem to be doing anything. The reason being, since it is the only child, there’s nobody to align to. We need to add another one as a reference. We can use the ::before pseudoelement. This will be a ruler which we can align our .box against.</p><p>We use an inline-block display for both of our elements, so we can align them nicely. Our ‘ruler’ should have a 100% height, so it’s like we were aligning to the container’s. Width should be 0, to hide it. And voilà, our box is vertically aligned!</p><p><a href="http://jsfiddle.net/hx00epqu/18/">Check out the working example (borders added for demonstration) here.</a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=a83eac44c574" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Publishing to IPFS]]></title>
            <link>https://medium.com/@sevcsik/publishing-to-ipfs-b627b6c8799a?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/b627b6c8799a</guid>
            <category><![CDATA[decentralization]]></category>
            <category><![CDATA[ipfs]]></category>
            <category><![CDATA[web3]]></category>
            <category><![CDATA[blockchain]]></category>
            <category><![CDATA[p2p]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Thu, 30 Jun 2016 16:25:28 GMT</pubDate>
            <atom:updated>2016-06-30T16:27:11.850Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>If you visited this site more than once in the past year, you might notice that it started redirecting to a weird path, like this: /ipns/sevdev.hu.</p><p>The reason being that the site is now hosted on <a href="https://ipfs.io/">IPFS</a>, and the path you are seeing is the IPFS path of the site, served by the HTTP gateway of <a href="https://github.com/ipfs/go-ipfs">go-ipfs</a>. So, what is this, and why it is a big deal?</p><h3>The Interplanetary Filesystem</h3><p>IPFS is a distributed, peer-to-peer, content-addressed filesystem. It’s like the lovechild of BitTorrent and Git. It makes it possible to make a file or directory available on the network, where other nodes can access it knowing only the hash of the content, but unaware of the location of the host. This allows a transparent, infrastructure-agnostic and inherently redundant data storage. The network is trustless, as it’s impossible to change their content without changing their address.</p><p>In this setup, the VPS behind sevdev.hu is just an IPFS node, with a HTTP gateway to serve traditional web browsers. If the page is accessed natively through an IPFS client, it could just be served by any other IPFS node which holds a copy.</p><h3>Publishing files</h3><p>To get started, just install <a href="https://github.com/ipfs/go-ipfs">go-ipfs</a> and initialise your node with ipfs init. This will generate a private key, and a corresponding peer ID, which will identify your node over the peer-to-peer network. After that, the daemon can be started by ipfs daemon.</p><p>Making a file available on IPFS is the easiest part. After installing <a href="https://github.com/ipfs/go-ipfs">go-ipfs</a> , just use ipfs add &lt;path&gt;. That doesn’t transmit anything to the network — it just calculates and stores the hash of the given file. If any node looks for this specific hash in the future, your node will serve it.</p><p>It’s also possible to store trees, just like in Git. A tree’s hash is composed of the hash and path of the leaves, which allows us to publish a whole directory recursively, with ipfs add -r &lt;path&gt;.</p><h3>Addressing</h3><p>The ipfs add command outputs a friendly looking, base-58 hash, starting with Qm for some reason. This file can be referenced by any node on the network, using the path /ipfs/&lt;hash&gt;. As long as your node is up and has a healthy connection, any node can access your content using this path. There is a public gateway at the IPFS home page to try: <a href="http://ipfs.io/ipfs/&lt;hash&gt;.">http://ipfs.io/ipfs/&lt;hash&gt;.</a></p><p>Since paths are immutable, it’s impossible to deliver updates to users. That’s why IPFS has a separate namespace at/ipns/, where mutable names can be resolved. The concept is similar to Git branches — they are mutable pointers, as oppesed to commits, which are content-addressable, immutable objects.</p><p>This namespace can use a number of name services to resolve IPFS resources.</p><h3>IPFS names</h3><p>IPFS provides a built-in method to publish names on the peer-to-peer network. Using your private key, you can publish a name, which points to an IPFS content address. These names are stored in a DHT, and has to be republished regularly (~12h) to stay alive.</p><p>IPFS names can be published by the ipfs name publish &lt;hash&gt; command, which will publish the given hash under the node’s peer ID. The content can be referenced later with the path /ipns/&lt;peer id&gt;. There is also a commandline tool, <a href="https://github.com/whyrusleeping/ipns-pub">ipns-pub</a> to conveniently publish to multiple names, without changing the node configuration.</p><p>This is a self-contained, decentralised way of publishing content, but practically it needs an always-on server with the private key on file, to be able to keep the name alive. According to folks on #ipfs, this will change in the future.</p><h3>DNS</h3><p>Alternatively, the good ol’ DNS can be used to resolve IPFS names. The dnslink= TXT record should point to the IPFS path.</p><p>For example, here’s the TXT record of the <a href="https://ipfs.io/">IPFS website</a>:</p><pre>ipfs.io. 11 IN TXT &quot;dnslink=/ipfs/QmTzQ1JRkWErjk39mryYw2WVaphAZNAREyMchXzYQ7c15n&quot;</pre><p>Because of that TXT record, the website can be accessed by the /ipns/ipfs.io path, instead of an unfriendly peer ID.</p><h3>Using IPFS on today’s web</h3><p>Obviously, there is no native support for the IPFS protocol in web browsers. This site, as well as the IPFS webite provides a HTTP gateway, that conveniently maps IPFS paths to the document root, so they can be loaded in a HTTP client without any modification.</p><p>This practice makes it possible to redirect every HTTP gateway to the local node’s gateway pretty easily, for example using the <a href="https://chrome.google.com/webstore/detail/ipfs-station/kckhgoigikkadogfdiojcblegfhdnjei">IPFS station</a> extension. That provides a seamless way to use IPFS how it’s meant to be used: using the peer-to-peer network, without any knowledge of the original host.</p><p><em>This post was originally published on </em><a href="https://sevdev.hu/ipns/sevdev.hu/posts/2016-06-26-publishing-to-ipfs.html"><em>my blog</em></a><em>.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=b627b6c8799a" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Circumventing required user interaction to play HTML5 media]]></title>
            <link>https://medium.com/@sevcsik/circumventing-required-user-interaction-to-play-html5-media-f405425c1bab?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/f405425c1bab</guid>
            <category><![CDATA[web-development]]></category>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[html5]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Tue, 25 Aug 2015 21:07:30 GMT</pubDate>
            <atom:updated>2015-08-25T21:08:18.222Z</atom:updated>
            <content:encoded><![CDATA[<p>Webkit (and Blink) includes <a href="https://code.google.com/p/chromium/issues/detail?id=178297">a limitation</a> on mobile, that calling HTMLMediaElement#play has no effect unless it was initiated by user interaction. That supposed to make autoplay impossible, thus saving mobile users from unwanted data traffic in their plan by background music and autoplaying videos. Fair enough.</p><p>If you are using something like <a href="https://client.cdn77.com/support/knowledgebase/cdn-resource/how-can-i-enable-disable-secure-token">secure tokens</a> to protect your media URLs, you ask your backend for a fresh token to get the actual video URL to play. Since this operation is asynchronous, you can’t call play soon enough, having your call disarmed. To the end user, this means that they have to tap your play button twice to start the video.</p><p>This “feature” is surprisingly poorly documented. No implementation details, just a few bug reports, all about breaking autoplay. After a few hours of empirical testing, I found out that there can be maximum one second between a click event and your #play call, otherwise you’re just trying to get blood out of a stone.</p><p>There’s a loophole though: once you have “woken” up your &lt;video&gt; tag with a legitimate #play(), every subsequent call will work afterwards. You don’t even have to have an URL loaded to do so.</p><p>So the workaround looks something like this:</p><pre><strong>&lt;video</strong> id=&quot;video&quot; controls<strong>&gt;&lt;/video&gt;</strong><br><strong>&lt;button</strong> onclick=&quot;playAsync()&quot;<strong>&gt;</strong>play<strong>&lt;/button&gt;</strong><br><strong>&lt;script&gt;</strong><br>  <strong>var</strong> v = document.getElementById(&#39;video&#39;);<br>  <strong>function</strong> playAsync() {<br>    v.play();<br>    v.pause();</pre><pre>    setTimeout(<strong>function</strong>() {<br>      v.src = URL;<br>      v.play();<br>    }, 5000);<br>  }<br><strong>&lt;/script&gt;</strong></pre><p>Interestingly, if you remove the v.pause() call, it won’t work. I suspect that the browser would find out that there is no media to play in the next <a href="http://blog.carbonfive.com/2013/10/27/the-javascript-event-loop-explained/">tick</a>, rendering the playback state change invalid.</p><p>Tested on iOS7+ Safari and Chrome for Android.</p><p><a href="https://sevdev.hu/~sevcsik/posts/2015-08-25-circumventing-required-user-interaction-for-html5-media.html"><em>Originally published on my blog.</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=f405425c1bab" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Marrying HTML imports and ES2015 Modules]]></title>
            <link>https://medium.com/@sevcsik/marrying-html-imports-and-es2015-modules-613de889d898?source=rss-3123ea866af2------2</link>
            <guid isPermaLink="false">https://medium.com/p/613de889d898</guid>
            <category><![CDATA[javascript]]></category>
            <category><![CDATA[web-components]]></category>
            <category><![CDATA[es6]]></category>
            <dc:creator><![CDATA[Andras Sevcsik-Zajácz]]></dc:creator>
            <pubDate>Tue, 25 Aug 2015 10:14:34 GMT</pubDate>
            <atom:updated>2015-08-25T21:09:18.491Z</atom:updated>
            <cc:license>http://creativecommons.org/licenses/by/4.0/</cc:license>
            <content:encoded><![CDATA[<p>Web is evolving, which is a good thing. Unsurprisingly, it’s evolving in it’s good ol’ webby way paved with polyfills, transpilers and conflicting standards.</p><p>Having <a href="http://www.2ality.com/2014/09/es6-modules-final.html">modules</a> in Javascript was certainly a long awaited feature, which makes it a much better fit for developing large applications. The same goes for <a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components">Web components</a> in HTML. Finally we can build custom elements without relying on huge frameworks and expensively <a href="https://angularjs.org/">monitoring the DOM</a> or layering a <a href="http://facebook.github.io/react/">less expensive DOM</a> on top of it.</p><p>Of course, HTML imports can be used to load Javascript, and Javascript can import HTML. You can be sure that there will be tools using every possible permutation. And you’ll brain hurt making them work together.</p><h3>The Polymer Way</h3><p>If you look at the <a href="https://elements.polymer-project.org/">Polymer catalog</a>, you’ll see that they envision a world where <em>everything</em> is done by web components. Things like <a href="https://elements.polymer-project.org/elements/iron-ajax">this</a>:</p><pre><strong>&lt;iron-ajax</strong><br>    auto<br>    url=&quot;http://gdata.youtube.com/feeds/api/videos/&quot;<br>    params=&#39;{&quot;alt&quot;:&quot;json&quot;, &quot;q&quot;:&quot;chrome&quot;}&#39;<br>    handle-as=&quot;json&quot;<br>    on-response=&quot;handleResponse&quot;<br>    debounce-duration=&quot;300&quot;<strong>&gt;&lt;/iron-ajax&gt;</strong></pre><p>Call me old fashioned, but I still think that HTML, as a markup languge should be used solely for presentation, not for defining the application logic. And handleResponse would still be implemented in Javascript, so what’s the point?</p><p>This way of thinking ensues that the unit of encapsulation is a component. Each component consists of a&lt;dom-module&gt; definition, and/or a Polymer call. There is no dependency injection, and your dependency graph will be defined how HTML imports are nested in different components. And that gives us the — rather odd — phenomenon that you write your <a href="https://github.com/PolymerElements/iron-ajax/blob/master/iron-ajax.html">script-only components</a> in HTML as well.</p><p>Not to mention that with import, Babel works out of the box, but if you include your ES2015 code with regular&lt;script&gt; tags, it’s tricky to get it working (I didn’t manage at least).</p><h3>A phatetic first try</h3><p>I for one still think that Polymer is the best web component library out there, and if you’re into <a href="https://www.google.com/design/spec/material-design/introduction.html">material design</a> like me, using their paper-* components will save you tons of work. They also have a pretty solid way of “emulating” shadow DOM without sacrificing speed, called the <a href="https://www.polymer-project.org/1.0/articles/shadydom.html">shady DOM</a>. So I’m here to stay.</p><p>First I tried the obvious way: import HTML templates from my ES2015 modules, like this:</p><pre>Polymer.Base.importHref(&#39;template.html&#39;, <strong>function</strong>() {<br>	Polymer({ <em>/* ... */</em> })<br>});</pre><p>This approach works: you can use the import statement to require your components, just like your other modules. Turns out to be terribly bad for performance though, as:</p><ul><li>The initialization of the JS part is delayed by loading the template. If you have multiple levels of dependencies, this pretty much flattens your initialization.</li><li>It breaks <a href="https://github.com/polymer/vulcanize">vulcanize</a> which is essential to deploy your code into production (at least until HTTP/2 gets adopted).</li></ul><h3>Best of Both Worlds</h3><p>I ended up with the following: I use HTML imports to require the HTML definitions for my custom elements, and using ES2015 modules to require the Javascript parts. Unfortunately, this requires me to have an obligatory JS and a HTML part for every element, but usually I end up needing both anyway, so I can live with it.</p><p>This method works nicely with Vulcanize as well: it crunches through every HTML import, while your JS bundler takes care all of your scripts.</p><p>There are a few things to look after though:</p><ul><li>You have to include polymer.html and webcomponents.js explicitly first, <em>then</em> you can load your JS entry point. Otherwise, every JS component declaration will fail because Polymer is not yet defined.</li><li>You have to include your initial HTML import(s) before the JS entry point as well. Turns out the Polymer call can happen <em>after</em> the &lt;dom-module&gt; declaration has been processed by Polymer, but not the other way around (if you see this pointing to window inside your element’s lifecycle callback, that’s the reason).</li><li>If you don’t use Vulcanize, be aware that native HTML imports are sync, but the polyfilled one (webcomponents.js) <em>is async</em>. That means you have to handle both cases.</li></ul><p>In the end it looks something like this (with <a href="https://github.com/systemjs/systemjs">SystemJS</a> for dynamic loading):</p><pre><strong>&lt;script</strong> src=&quot;bower_components/webcomponentsjs/webcomponents.min.js&quot;<strong>&gt;&lt;/script&gt;</strong><br><strong>&lt;link</strong> id=&quot;polymer-import&quot; rel=&quot;import&quot; href=&quot;bower_components/polymer/polymer.html&quot;<strong>&gt;</strong><br><strong>&lt;script</strong> src=&quot;//cdnjs.cloudflare.com/ajax/libs/systemjs/0.18.4/system.js&quot;<strong>&gt;&lt;/script&gt;</strong><br><strong>&lt;script&gt;</strong><br>	System.config({<br>		map: {<br>			babel: &#39;//cdnjs.cloudflare.com/ajax/libs/babel-core/5.6.15/browser.min.js&#39;<br>		},<br>		transpiler: &#39;babel&#39;<br>	});<br>	<strong>var</strong> link = document.querySelector(&#39;#polymer-import&#39;);<br>	<em>// wait for Polymer import</em><br>	if (link &amp;&amp; link.import) {<br>		console.log(&#39;Delaying initial import until polymer is ready&#39;);<br>		document.querySelector(&#39;#polymer-import&#39;).addEventListener(&#39;load&#39;, <br>			<strong>function</strong>() {<br>			System.import(&#39;components/resume.js&#39;);<br>		});<br>	} else {<br>		System.import(&#39;components/resume.js&#39;);<br>	}<br>&lt;/script&gt;</pre><p>And with a pre-compiled JS bundle (using <a href="http://webpack.github.io/">Webpack</a>):</p><pre><strong>&lt;script</strong> src=&quot;https://cdnjs.cloudflare.com/ajax/libs/webcomponentsjs/0.7.12/webcomponents.min.js&quot;<strong>&gt;&lt;/script&gt;</strong><br><strong>&lt;link</strong> id=&quot;polymer-import&quot; rel=&quot;import&quot; href=&quot;bower_components/polymer/polymer.html&quot;<strong>&gt;</strong><br><strong>&lt;link</strong> rel=&quot;import&quot; href=&quot;components/my-main-component.html&quot;<strong>&gt;</strong><br><strong>&lt;script&gt;</strong><br>	(<strong>function</strong>() {<br>		<strong>var</strong> BUNDLE_PATH = &quot;dist/scripts.js&quot;;<br>		<strong>var</strong> script = document.createElement(&#39;SCRIPT&#39;);<br>		script.src = BUNDLE_PATH;<br>		<strong>var</strong> link = document.querySelector(&#39;#polymer-import&#39;);<br>		<em>// wait for Polymer import if necessary</em><br>		if (link &amp;&amp; link.import) {<br>			document.querySelector(&#39;#polymer-import&#39;).addEventListener(&#39;load&#39;, <br>				<strong>function</strong>() {<br>					document.head.appendChild(script);<br>				}	<br>			);<br>		} else {<br>			document.head.appendChild(script);<br>		}<br>	})();<br>&lt;/script&gt;</pre><p>This plays nice with both &lt;link&gt; tags inlined by Vulcanize (that’s why I’m checking for the existence of link). Although it’s a bit painful, it does the job.</p><p>I’m open to suggestions!</p><p><a href="https://sevdev.hu/~sevcsik/posts/2015-08-24-marrying-html-imports-and-es2015-modules.html"><em>Originally published to my blog.</em></a></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=613de889d898" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>