Skip to content

Instantly share code, notes, and snippets.

🏏

Saul Shanabrook saulshanabrook

🏏
Block or report user

Report or block saulshanabrook

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@saulshanabrook
saulshanabrook / README.md
Created Oct 19, 2016
Saving Web Crypto Keys using indexedDB
View README.md

This is a working example on how to store CryptoKeys locally in your browser. We are able to save the objects, without serializing them. This means we can keep them not exportable (which might be more secure?? not sure what attack vectors this prevents).

To try out this example, first make sure you are in a browser that has support for async...await and indexedDB (latest chrome canary with chrome://flags "Enable Experimental Javascript" works). Load some page and copy and paste this code into the console. Then call encryptDataSaveKey(). This will create a private/public key pair and encrypted some random data with the private key. Then save both of them. Now reload the page, copy in the code, and run loadKeyDecryptData(). It will load the keys and encrypted data and decrypt it. You should see the same data logged both times.

View parser.ts
export const INVALID = Symbol("INVALID");
/**
* Is able to optionally parse from type T to U
* and then create U from T.
*
* The idea is that these functions are inverses of each other:
*
* parser.create(parser.parse(t)) == t
*
View tmp.vl.json
{
"config": {"view": {"width": 400, "height": 300}, "mark": {"tooltip": null}},
"data": {"name": "data-2ec47c823e6aebe675c9e913a8f3b032"},
"mark": "rect",
"encoding": {
"color": {"type": "quantitative", "aggregate": "count"},
"x": {
"type": "quantitative",
"bin": {"binned": true},
"field": "bin_x",
View example.vl.json
{
"config": {"view": {"width": 400, "height": 300}, "mark": {"tooltip": null}},
"data": {"name": "data-c8d131caa71f8e80b7117ed5b5fdc060"},
"mark": "rect",
"encoding": {
"color": {"type": "quantitative", "aggregate": "count"},
"x": {
"type": "quantitative",
"bin": {"binned": true},
"field": "bin_x",
View tmp.js
const addSubscriber = assign({
subscribers: (context, event) => context.subscribers + 1
});
const removeSubscriber = assign({
subscribers: (context, event) => context.subscribers - 1
});
View Untitled.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View output.json
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"autosize": "pad",
"padding": 5,
"height": 300,
"style": "cell",
"data": [
{
"name": "6132438473295640038",
"transform": [{"type": "queryibis", "name": "6132438473295640038"}]
View input.json
{
"$schema": "https://vega.github.io/schema/vega/v5.json",
"autosize": "pad",
"padding": 5,
"height": 300,
"style": "cell",
"data": [
{
"name": "938224664827150147",
"transform": [{"type": "queryibis", "name": "938224664827150147"}]
View Untitled1.ipynb
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View graph.json
{
"background": null,
"operators": [
{ "id": 0, "type": "operator", "root": true },
{ "id": 1, "type": "operator", "value": 0, "signal": "width" },
{ "id": 2, "type": "operator", "value": 0, "signal": "height" },
{
"id": 3,
"type": "operator",
"value": { "top": 0, "bottom": 0, "left": 0, "right": 0 },
You can’t perform that action at this time.