Skip to content

Instantly share code, notes, and snippets.

View myobie's full-sized avatar

Nathan myobie

View GitHub Profile

Previewing encrypted content on the web

This would be an extension to The Open Graph protocol.

As more and more people are using privacy preserving tools for sharing content on the web, more content embedded into web pages will be end-to-end encrypted and decrypted in-browser by javascript or wasm code.

A current problem with previews of web URLs is they require the server to know the exact contents of the URL and be able to provide a preview as a resource either inside a header or as a URL to an image. If the primary content at the URL were encrypted, no preview could be provided directly by the server.

What the server could provide is an encrypted preview which was encrypted with a symmetric key by the original creator using one of the standard algorithms provided by webcrypto. Then the browser/client could find the decryption key in the URL fragment (or prompt the user for it) to then facilitate the decryption of the preview content safely on device. This would provide a standard

@myobie
myobie / application.ex
Last active May 8, 2023 23:21
Using Finch with ExAws
defmodule Example.Application do
@moduledoc false
use Application
def start(_type, _args) do
children = [
Example.Repo,
ExampleWeb.Telemetry,
{Phoenix.PubSub, name: Example.PubSub},
const worker = new Worker('/tests.js')
worker.onmessage = e => {
if (e.data && e.data._command) {
if (e.data._command === 'console') {
const type = e.data.type || 'log'
const msg = e.data.msg || '<empty>'
switch (type) {
case 'error':
@myobie
myobie / drain.js
Last active January 25, 2021 15:05
Drain an array of potential promises with a max concurrency factor
/** @typedef {() => Promise<unknown>} Task */
/**
* @param {Task[]} pending
* @param {number} max
* @returns {Promise<unknown[]>}
*/
export function drain (pending, max) {
return new Promise((resolve, reject) => {
let nextIndex = 0
@myobie
myobie / build-utils.cjs
Created January 7, 2021 17:05
Using estrella to build tests, serve-handler to serve the results, and playwright to execute the tests and stream the logs back to the node console
const { join, resolve } = require('path')
const { basename, build, file, log, glob, cliopts, stdoutStyle, watch } = require('estrella')
async function serve (cwd, opts = null) {
opts || (opts = {})
let pkgOpts = { devServerPort: null, publicPath: null, rewrites: null, redirects: null }
if (isNodeProject(cwd)) {
const pkg = JSON.parse(await file.read(join(cwd, 'package.json'), { encoding: 'utf8' }))
@myobie
myobie / tests.ts
Created January 7, 2021 17:00
Build tests with esbuild, serve them with vercel's serve-handler, then use playwright to open a browser and stream the console back to the node console
// NOTE: we are just assuming _tests is an alright place to render to
export async function buildAndRunTests (cwd: string): Promise<void> {
const [{ once }] = cliopts.parse(
['o, once', 'run the tests and then exit']
)
await file.mkdirs(join(cwd, '_tests'))
await buildBrowserTests(cwd)
@myobie
myobie / estrella-utils.cjs
Created January 4, 2021 09:20
Build a project with estrella by convention using the settings in package.json
/* eslint-disable @typescript-eslint/no-var-requires */
const { join } = require('path')
const { build, file, cliopts } = require('estrella')
module.exports = {
buildPackage,
buildBrowserAndNodeModule,
buildBrowserModule,
buildNodeModule
@myobie
myobie / tsc-build.cjs
Created January 4, 2021 09:18
Alternative to estrella's tslint; instead use tsc --build so we can choose to produce declaration files (.d.ts)
/* eslint-disable @typescript-eslint/no-var-requires */
const perf = require('perf_hooks')
const { spawn } = require('child_process')
const { cliopts, fmtDuration, findInPATH, log, stdoutStyle } = require('estrella')
module.exports = {
clock,
tscBuild
}
@myobie
myobie / clone.sh
Created November 23, 2020 09:10
Keep things organized with a clone bash function which always puts repos into the correct place
clone() {
org=$(echo $1 | awk -F/ '{ print $1 }')
mkdir -p ~/src/github.com/$org
path=~/src/github.com/$1
git clone $@ $path
cd $path
}
# Examples:
# $ clone myobie/dot-files
@myobie
myobie / application.ex
Last active November 19, 2020 14:48
Gentle request task in elixir
defmodule Gentle.Application do
use Application
def start(_type, _args) do
children = [
{Task.Supervisor, name: Gentle.TaskSupervisor}
]
opts = [strategy: :one_for_one, name: Gentle.Supervisor]
Supervisor.start_link(children, opts)