<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Francesco Ceccon</title>
    <description>The latest articles on DEV Community by Francesco Ceccon (@fracek).</description>
    <link>https://dev.to/fracek</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F551307%2F4b9bdd78-ea13-4f02-803d-ab04c5c880e2.png</url>
      <title>DEV Community: Francesco Ceccon</title>
      <link>https://dev.to/fracek</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/fracek"/>
    <language>en</language>
    <item>
      <title>How to generate Stellar keys</title>
      <dc:creator>Francesco Ceccon</dc:creator>
      <pubDate>Thu, 14 Jan 2021 17:41:55 +0000</pubDate>
      <link>https://dev.to/fracek/how-to-generate-stellar-keys-586o</link>
      <guid>https://dev.to/fracek/how-to-generate-stellar-keys-586o</guid>
      <description>&lt;h1&gt;
  
  
  What is a key pair?
&lt;/h1&gt;

&lt;p&gt;Stellar keys are used to authenticate and identify users on the network. Stellar accounts are uniquely identified by their &lt;em&gt;public key&lt;/em&gt;, also known as &lt;em&gt;account id&lt;/em&gt;. A Stellar account id is a string that starts with the letter &lt;code&gt;G&lt;/code&gt;, this key is safe to share with others. Accounts are controlled using a &lt;em&gt;secret key seed&lt;/em&gt;, a string starting with &lt;code&gt;S&lt;/code&gt;, and they should never be shared with other people or applications. The secret key seed is used to derive the private key. A private key and a public key together are known as a &lt;em&gt;key pair&lt;/em&gt;. The private key is used to sign operations that modify the Stellar account state on the ledger.&lt;/p&gt;

&lt;h1&gt;
  
  
  Generate key pairs with one of the SDKs
&lt;/h1&gt;

&lt;p&gt;Now that we know what is a key pair and what it is used for, we can see how to generate it using four different SDKs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Javascript
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;stellar-base&lt;/code&gt; package is officially maintained by the Stellar Development Foundation and &lt;a href="https://www.npmjs.com/package/stellar-base"&gt;is available on npm&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Keypair&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;stellar-base&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Generate random key pair&lt;/span&gt;
&lt;span class="nx"&gt;Keypair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Generate key pair from secret&lt;/span&gt;
&lt;span class="nx"&gt;Keypair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fromSecret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;SA6KO...PRET&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Generate key pair from account id&lt;/span&gt;
&lt;span class="nx"&gt;Keypair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;fromPublicKey&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;GBMZ...ZPJK&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Rust
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;stellar-base&lt;/code&gt; crate provides low-level Stellar types, including key pairs. You can fetch it directly from &lt;a href="https://crates.io/crates/stellar-base"&gt;crates.io&lt;/a&gt;. The Rust SDK provides a &lt;code&gt;KeyPair&lt;/code&gt; type that contains both the private and public keys, and a &lt;code&gt;PublicKey&lt;/code&gt; type that contains only the public key. With this API design, it’s impossible to accidentally sign a transaction with a key pair that was constructed from the public key only.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="k"&gt;use&lt;/span&gt; &lt;span class="nn"&gt;stellar_base&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nn"&gt;crypto&lt;/span&gt;&lt;span class="p"&gt;::{&lt;/span&gt;&lt;span class="n"&gt;KeyPair&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;};&lt;/span&gt;

&lt;span class="c"&gt;// Generate random key pair&lt;/span&gt;
&lt;span class="nn"&gt;KeyPair&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;random&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c"&gt;// Generate key pair from secret&lt;/span&gt;
&lt;span class="n"&gt;KeyPair&lt;/span&gt;&lt;span class="nf"&gt;.from_secret_seed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SA6KO...PRET"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c"&gt;// Generate public key from account id&lt;/span&gt;
&lt;span class="nn"&gt;PublicKey&lt;/span&gt;&lt;span class="p"&gt;::&lt;/span&gt;&lt;span class="nf"&gt;from_account_id&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"GBMZ...ZPJK"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;?&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  C
&lt;/h2&gt;

&lt;p&gt;The &lt;code&gt;dotnet-stellar-sdk&lt;/code&gt; is a C# library to interact witth the Stellar ecosystem. It can be used in any language that targets .NET Standard 2.0 or above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="k"&gt;using&lt;/span&gt; &lt;span class="nn"&gt;stellar_dotnet_sdk&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="c1"&gt;// Generate random key pair&lt;/span&gt;
&lt;span class="n"&gt;KeyPair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;Random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;// Generate key pair from secret&lt;/span&gt;
&lt;span class="n"&gt;KeyPair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromSecretSeed&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SA6KO...PRET"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;// Generate key pair from account id&lt;/span&gt;
&lt;span class="n"&gt;KeyPair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;FromAccountId&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"GBMZ...ZPJK"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Python
&lt;/h2&gt;

&lt;p&gt;The Python &lt;code&gt;stellar-sdk&lt;/code&gt; is available on &lt;a href="https://pypi.org/project/stellar-sdk/"&gt;PyPi&lt;/a&gt; and can be installed with &lt;code&gt;pip&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;stellar_sdk&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;Keypair&lt;/span&gt;

&lt;span class="c1"&gt;# Generate random key pair
&lt;/span&gt;&lt;span class="n"&gt;Keypair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;random&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;

&lt;span class="c1"&gt;# Generate key pair from secret
&lt;/span&gt;&lt;span class="n"&gt;Keypair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;from_secret&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"SA6KO...PRET"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="c1"&gt;# Generate key pair from account id
&lt;/span&gt;&lt;span class="n"&gt;Keypair&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;from_public_key&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;"GBMZ...ZPJK"&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h1&gt;
  
  
  What’s happening behind the scenes?
&lt;/h1&gt;

&lt;p&gt;Stellar uses the &lt;a href="https://tools.ietf.org/html/rfc8032"&gt;EdDSA&lt;/a&gt; signature scheme for its transactions. A private key starts its life as a 32 bytes seed that is then used to generate the private key itself. The public key can be derived from the private key or created directly from a buffer of 32 bytes. I’m not going into too much detail how the private and public keys are derived, if you’re interested you can find more in &lt;a href="https://blog.mozilla.org/warner/2011/11/29/ed25519-keys/"&gt;this excellent blog post by Brian Warner&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Going from a Stellar account id to a public key is very simple, you start by decoding the account id (a string starting with &lt;code&gt;G&lt;/code&gt;) as &lt;em&gt;base32&lt;/em&gt; and obtaining a buffer of 35 bytes. The first byte contains information about the type of key (secret seed, account id, pre-authorized transaction, or &lt;code&gt;hash(x)&lt;/code&gt;), the next 32 bytes contain the key itself (or the secret key seed), finally the last 2 bytes contain the key checksum. Stellar uses &lt;a href="http://mdfs.net/Info/Comp/Comms/CRC16.htm"&gt;CRC-16 XMODEM&lt;/a&gt; for the checksum of bytes 1 to 32.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--eI3KcefK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.ceccon.me/images/strkey-to-key.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--eI3KcefK--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://www.ceccon.me/images/strkey-to-key.png" alt="strkey-to-key"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The process to compute a Stellar account id from a public key is similar, we concatenate the version byte with the public key bytes to obtain a 33 byte long payload. We then compute the 16 bit CRC of the payload. Finally, we concatenate the payload and its checksum and encode it using base32.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Pulumi first impression</title>
      <dc:creator>Francesco Ceccon</dc:creator>
      <pubDate>Fri, 01 Jan 2021 15:41:42 +0000</pubDate>
      <link>https://dev.to/fracek/pulumi-first-impression-bo4</link>
      <guid>https://dev.to/fracek/pulumi-first-impression-bo4</guid>
      <description>&lt;p&gt;Pulumi changed how I approach infrastructure and how I build web applications.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://www.pulumi.com/"&gt;Pulumi&lt;/a&gt; is a tool for Infrastructure as Code,  its selling point is that it uses a real programming language to  describe infrastructure.&lt;/p&gt;

&lt;p&gt;With Pulumi, you build cloud environments by specifying the resources  you need and combining them together.  Because Pulumi uses Typescript  (or Python or any .NET language), you can create your own abstractions  and use that to reduce the amount of code needed to describe your  infrastructure.&lt;br&gt;
Pulumi is not limited to cloud resources, you can use  it to describe Kubernetes resources. This means that you can use the  same language to describe the resources outside the control of  Kubernetes (the Kubernetes cluster itself, but also managed databases,  and pub/sub queues) and the Kubernetes resources such as deployments,  services, and even custom resources.&lt;br&gt;
Once you described what you need, the Pulumi engine will process your  requirements and present you with a change plan, which you can accept  and apply to your project. By default, Pulumi stores its state on  the Pulumi Service backend. However, this behavior can be changed  and you can store the state on the usual suspects (Amazon S3, Google  Cloud Storage, Azure Blob Storage) or your local file system.&lt;/p&gt;

&lt;p&gt;Infrastructure as Code is a way to encode your knowledge about  infrastructure in code. This means that when you come back to a project months later, you can see at a glance what resources it uses and any non  default settings.&lt;br&gt;
Because resources are linked to each other by their inputs and outputs, you can also see which resources are dependent on other resources. Pulumi even provides a web interface where you can visually see this dependency graph between resources.&lt;/p&gt;

&lt;p&gt;Pulumi is not the only project that aims to describe infrastructure as code, the most prominent project is HashiCorp Terraform.  There are some (many) differences between Terraform and Pulumi, and depending on your preferences you may like one or the other more (or none, IaC is not everyone's thing!).&lt;br&gt;
The most noticeable difference is that Terraform uses its own Domain Specific Language (DSL) to describe resources, while Pulumi uses Typescript. The trade-off in using a general purpose language is that, while you gain in expressiveness, you introduce the ability to generate non-deterministic resource graphs, which will result in broken deployments. This is solved by using Pulumi provided libraries to generate, for example, pseudo random data.&lt;/p&gt;

&lt;p&gt;Pulumi real killer feature is, however, being able to generate Kubernetes configuration directly together with the rest of infrastructure. This is a much superior approach than what is available for Terraform, which is using a separate tool to generate Kubernetes templates and deploying them.&lt;/p&gt;

&lt;p&gt;Since discovering Pulumi I changed how I build applications completely, before that I was not sold on serverless since deploying the functions and managing the API gateway requires a lot of configuration. Pulumi makes this completely manageable, to make it even simpler they provide packages containing common abstractions used when building serverless applications.&lt;/p&gt;

&lt;p&gt;After using Pulumi for just over one year it already changed how I approach building applications: I'm no longer reluctant to introduce dependencies on cloud resources since I know I can spin them up with a single command, and serverless has become my go-to tool when I need to create simple web services.&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
