Pen Settings

HTML

CSS

CSS Base

Vendor Prefixing

Add External Stylesheets/Pens

Any URLs added here will be added as <link>s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.

+ add another resource

JavaScript

Babel includes JSX processing.

Add External Scripts/Pens

Any URL's added here will be added as <script>s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.

+ add another resource

Packages

Add Packages

Search for and use JavaScript packages from npm here. By selecting a package, an import statement will be added to the top of the JavaScript editor for this package.

Behavior

Auto Save

If active, Pens will autosave every 30 seconds after being saved once.

Auto-Updating Preview

If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.

Format on Save

If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.

Editor Settings

Code Indentation

Want to change your Syntax Highlighting theme, Fonts and more?

Visit your global Editor Settings.

HTML

              
                <label for="file-private-key">Private Key File</label>
<input id="file-private-key" type="file" /><br>
<input id="button-generate" type="button" value="Generate"></input>

<div id="output" style="display: none">
  <h3>Download</h3>
  <ul>
    <li>
      <a id="download-public">Public Key</a>
    </li>
    <li>
      <a id="download-private">Private Key</a>
    </li>
  </ul>
</div>
              
            
!

CSS

              
                
              
            
!

JS

              
                document
  .querySelector("#button-generate")
  .addEventListener("click", generate, false);

async function generate() {
  const parentPrivateKeyRaw = await readFile(
    document.querySelector("#file-private-key")
  );
  if (!parentPrivateKeyRaw) {
    return;
  }
  const parentPrivateKey = await crypto.subtle.importKey(
    "jwk",
    JSON.parse(parentPrivateKeyRaw),
    {
      name: "ECDSA",
      namedCurve: "P-521"
    },
    true,
    ["sign"]
  );
  // https://developer.mozilla.org/en-US/docs/Web/API/SubtleCrypto/generateKey
  const keyPair = await crypto.subtle.generateKey(
    // https://developer.mozilla.org/en-US/docs/Web/API/EcKeyGenParams
    {
      name: "ECDSA",
      namedCurve: "P-521"
    },
    true,
    ["sign", "verify"]
  );

  // jwk == JSON Web Key
  const publicKey = await crypto.subtle.exportKey("jwk", keyPair.publicKey);
  const privateKey = await crypto.subtle.exportKey("jwk", keyPair.privateKey);
  const salt = createSalt();
  const publicKeySignature = arrayBufferToBase64(
    await crypto.subtle.sign(
      {
        name: "ECDSA",
        hash: { name: "SHA-512" }
      },
      parentPrivateKey,
      new TextEncoder().encode(salt + JSON.stringify(publicKey)).buffer
    )
  );

  setupDownload(
    document.querySelector("#download-public"),
    {
      publicKey,
      signature: salt + "." + publicKeySignature
    },
    "user-public-key-and-sig.json"
  );
  setupDownload(
    document.querySelector("#download-private"),
    privateKey,
    "user-private-key.json"
  );
  document.querySelector("#output").style.display = "";
}

function setupDownload(a, data, name) {
  if (a.href) {
    URL.revokeObjectURL(a.href);
  }
  a.download = decodeURI(name);
  const blob = new Blob([JSON.stringify(data)], { type: "text/json" });
  a.href = URL.createObjectURL(blob);
  a.type = "text/json";
}

async function readFile(file) {
  if (file.files.length === 0) {
    return;
  }
  return await new Promise((resolve, reject) => {
    const fileReader = new FileReader();
    fileReader.onload = (e) => {
      if (!e.target) {
        reject();
        return;
      }
      resolve(e.target.result);
    };
    fileReader.readAsText(file.files[0]);
  });
}
function createSalt() {
  const salt = new Uint8Array(4);
  crypto.getRandomValues(salt);
  return uint8ArrayToBase64(salt);
}
function uint8ArrayToBase64(data) {
  return btoa(String.fromCharCode.apply(null, [...data]));
}
function arrayBufferToBase64(data) {
  return uint8ArrayToBase64(new Uint8Array(data));
}
function base64ToArrayBuffer(str) {
  return Uint8Array.from(atob(str), (c) => c.charCodeAt(0));
}

              
            
!
999px

Console