Commit d8d9023b authored by Aral Balkan's avatar Aral Balkan
Browse files

Merge branch 'plain-snowpack-svelte'

This updated version of the spike now works with the new decoupled/simplified version of Place.
parents b86b2071 e5919c37
import sodiumPlus from 'sodium-plus'
const { SodiumPlus, X25519PublicKey } = sodiumPlus
import tweetnaclUtil from 'tweetnacl-util'
const { decodeBase64 } = tweetnaclUtil
// Check every minute and prune sign-in paths that haven’t been used in the last ten seconds.
setInterval(() => {
const now = Date.now()
if (db.privateRoutes) {
db.privateRoutes.forEach((privateRoute, index) => {
if (privateRoute.createdAt === privateRoute.accessedAt && (now - privateRoute.createdAt > 10000)) {
console.log('Pruning unused private path', privateRoute)
db.privateRoutes.splice(index, 1)
}
})
}
console.log('After prune', db.privateRoutes)
}, 1 /* minute */ * 60 * 1000)
let sodium
// In this spike, I’m hard-coding the public encryption key.
// Normally, we would read it in from the place’s configuration.
// (This spike will eventually be integrated into Place itself.)
const publicEncryptionKey = new X25519PublicKey(Buffer.from('101e27f87e7b2529154fbc9828d552b829ae7d0bd9b3d64c4f435b79f4481048', 'hex'))
export default async (request, response) => {
// Initialise Sodium Plus if necessary.
if (!sodium) sodium = await SodiumPlus.auto()
// Generate a new private path fragment. This is the
// hexadecimal representation of a 32-byte random buffer.
const randomBuffer = await sodium.randombytes_buf(32)
const unecryptedPrivateSocketPathFragment = randomBuffer.toString('hex')
console.log('Unencrypted secret path', unecryptedPrivateSocketPathFragment)
// Add the unencrypted secret path, along with the current time, to the routes
// so we can listen for requests on it.
if (!db.privateRoutes) {
db.privateRoutes = []
}
db.privateRoutes.push({ createdAt: Date.now(), accessedAt: Date.now(), route: unecryptedPrivateSocketPathFragment })
console.log('Private routes', db.privateRoutes)
// Next, we encrypt it using the person’s public encryption key.
// Since this is over a TLS connection, we don’t need to prove our
// identity so a sealed box will suffice.
const encryptedPrivateSocketPathFragment = (await sodium.crypto_box_seal(unecryptedPrivateSocketPathFragment, publicEncryptionKey)).toString('hex')
console.log('Encrypted secret path', encryptedPrivateSocketPathFragment)
response.json({
encryptedPrivateSocketPathFragment
})
}
export default function (socket, request) {
console.log('Private socket connection request. Token = ', request.params.token)
if (!db.privateRoutes) {
db.privateRoutes = []
}
let authorised = false
db.privateRoutes.forEach(route => {
if (route.route === request.params.token) {
authorised = true
route.accessedAt = Date.now()
}
})
if (!authorised) {
socket.close()
} else {
// TODO: add client to room, etc., etc.
socket.send('Hello from the server :) Welcome to the private area! Oooh!!!!')
}
}
......@@ -4,3 +4,4 @@ node_modules
.db
build
out
sign-in.small-web.org
<script>
import Navigation from './Navigation.interface'
import HomeSection from './sections/Home.interface'
import AboutSection from './sections/About.interface'
import SlidingSection from './sections/Sliding.interface'
import SwitchSection from './sections/Switch.interface'
import PrivateSection from './sections/Private.interface'
import SignInSection from './sections/SignIn.interface'
import SignOutSection from './sections/SignOut.interface'
import NotFound from './sections/NotFound.interface'
import Navigation from './Navigation.svelte'
import HomeSection from './sections/Home.svelte'
import AboutSection from './sections/About.svelte'
import SlidingSection from './sections/Sliding.svelte'
import SwitchSection from './sections/Switch.svelte'
import PrivateSection from './sections/Private.svelte'
import SignInSection from './sections/SignIn.svelte'
import SignOutSection from './sections/SignOut.svelte'
import NotFound from './sections/NotFound.svelte'
import { initialise } from './state.js'
initialise()
......
import './index.css'
import Index from './Index.interface'
import Index from './Index.svelte'
new Index({
target: document.getElementById('svelte')
......
......@@ -4,16 +4,39 @@
"lockfileVersion": 1,
"requires": true,
"dependencies": {
"@snowpack/plugin-svelte": {
"version": "3.5.2",
"resolved": "https://registry.npmjs.org/@snowpack/plugin-svelte/-/plugin-svelte-3.5.2.tgz",
"integrity": "sha512-i7OhkIRNt1uJ/y3qpowlU7icjtSgFPIl/GjMmBxhtwoIqHAnowFLh1Ur5G6S36GCFo65ymClnYfEIM/2x1+wPQ==",
"requires": {
"rollup-plugin-svelte": "^7.0.0",
"svelte-hmr": "^0.12.1",
"svelte-preprocess": "^4.6.0"
}
},
"@types/node": {
"version": "14.14.28",
"resolved": "https://registry.npmjs.org/@types/node/-/node-14.14.28.tgz",
"integrity": "sha512-lg55ArB+ZiHHbBBttLpzD07akz0QPrZgUODNakeC09i62dnrywr9mFErHuaPlB6I7z+sEbK+IYmplahvplCj2g=="
},
"@types/pug": {
"version": "2.0.4",
"resolved": "https://registry.npmjs.org/@types/pug/-/pug-2.0.4.tgz",
"integrity": "sha1-h3L80EGOPNLMFxVV1zAHQVBR9LI="
},
"@types/sass": {
"version": "1.16.0",
"resolved": "https://registry.npmjs.org/@types/sass/-/sass-1.16.0.tgz",
"integrity": "sha512-2XZovu4NwcqmtZtsBR5XYLw18T8cBCnU2USFHTnYLLHz9fkhnoEMoDsqShJIOFsFhn5aJHjweiUUdTrDGujegA==",
"requires": {
"@types/node": "*"
}
},
"base64-js": {
"version": "1.5.1",
"resolved": "https://registry.npmjs.org/base64-js/-/base64-js-1.5.1.tgz",
"integrity": "sha512-AKpaYlHn8t4SVbOHCy+b5+KKgvR4vrsD8vbvrbiQJps7fKDTkjkDry6ji0rUJjC0kzbNePLwzxq8iypo41qeWA=="
},
"big-integer": {
"version": "1.6.48",
"resolved": "https://registry.npmjs.org/big-integer/-/big-integer-1.6.48.tgz",
"integrity": "sha512-j51egjPa7/i+RdiRuJbPdJ2FIUYYPhvYLjzoYbcMMm62ooO6F94fETG4MTs46zPAF9Brs04OajboA/qTGuz78w=="
},
"blake2s-js": {
"version": "1.3.0",
"resolved": "https://registry.npmjs.org/blake2s-js/-/blake2s-js-1.3.0.tgz",
......@@ -24,44 +47,88 @@
"resolved": "https://registry.npmjs.org/blakejs/-/blakejs-1.1.0.tgz",
"integrity": "sha1-ad+S75U6qIylGjLfarHFShVfx6U="
},
"buffer": {
"version": "5.7.1",
"resolved": "https://registry.npmjs.org/buffer/-/buffer-5.7.1.tgz",
"integrity": "sha512-EHcyIPBQ4BSGlvjB16k5KgAJ27CIsHY/2JBmCRReo48y9rQ3MaUzWX3KVlBa4U7MyX02HdVj0K7C3WaB3ju7FQ==",
"detect-indent": {
"version": "6.0.0",
"resolved": "https://registry.npmjs.org/detect-indent/-/detect-indent-6.0.0.tgz",
"integrity": "sha512-oSyFlqaTHCItVRGK5RmrmjB+CmaMOW7IaNA/kdxqhoa6d17j/5ce9O9eWXmV/KEdRwqpQA+Vqe8a8Bsybu4YnA=="
},
"esbuild": {
"version": "0.8.46",
"resolved": "https://registry.npmjs.org/esbuild/-/esbuild-0.8.46.tgz",
"integrity": "sha512-xck9sXNCNmjDHCCfxTCyhKTiFuEBweh+IDAhMLOJI990v1Fzii6MyIkT1LbkvjgoVgPX2SK1kpi5eZVGNrl8yg==",
"dev": true
},
"estree-walker": {
"version": "0.6.1",
"resolved": "https://registry.npmjs.org/estree-walker/-/estree-walker-0.6.1.tgz",
"integrity": "sha512-SqmZANLWS0mnatqbSfRP5g8OXZC12Fgg1IwNtLsyHDzJizORW4khDfjPqJZsemPWBB2uqykUah5YpQ6epsqC/w=="
},
"fsevents": {
"version": "2.3.2",
"resolved": "https://registry.npmjs.org/fsevents/-/fsevents-2.3.2.tgz",
"integrity": "sha512-xiqMQR4xAeHTuB9uWm+fFRcIOgKBMiOBP+eXiyT7jsgVCq1bkVygt00oASowB7EdtpOHaaPgKt812P9ab+DDKA==",
"dev": true,
"optional": true
},
"is-docker": {
"version": "2.1.1",
"resolved": "https://registry.npmjs.org/is-docker/-/is-docker-2.1.1.tgz",
"integrity": "sha512-ZOoqiXfEwtGknTiuDEy8pN2CfE3TxMHprvNer1mXiqwkOT77Rw3YVrUQ52EqAOU3QAWDQ+bQdx7HJzrv7LS2Hw==",
"dev": true
},
"is-wsl": {
"version": "2.2.0",
"resolved": "https://registry.npmjs.org/is-wsl/-/is-wsl-2.2.0.tgz",
"integrity": "sha512-fKzAra0rGJUUBwGBgNkHZuToZcn+TtXHpeCgmkMJMMYx1sQDYaCSyjJBSCa2nH1DGm7s3n1oBnohoVTBaN7Lww==",
"dev": true,
"requires": {
"is-docker": "^2.0.0"
}
},
"min-indent": {
"version": "1.0.1",
"resolved": "https://registry.npmjs.org/min-indent/-/min-indent-1.0.1.tgz",
"integrity": "sha512-I9jwMn07Sy/IwOj3zVkVik2JTvgpaykDZEigL6Rx6N9LbMywwUSMtxET+7lVoDLLd3O3IXwJwvuuns8UB/HeAg=="
},
"open": {
"version": "7.4.2",
"resolved": "https://registry.npmjs.org/open/-/open-7.4.2.tgz",
"integrity": "sha512-MVHddDVweXZF3awtlAS+6pgKLlm/JgxZ90+/NBurBoQctVOOB/zDdVjcyPzQ+0laDGbsWgrRkflI65sQeOgT9Q==",
"dev": true,
"requires": {
"base64-js": "^1.3.1",
"ieee754": "^1.1.13"
"is-docker": "^2.0.0",
"is-wsl": "^2.1.1"
}
},
"ieee754": {
"version": "1.2.1",
"resolved": "https://registry.npmjs.org/ieee754/-/ieee754-1.2.1.tgz",
"integrity": "sha512-dcyqhDvX1C46lXZcVqCpK+FtMRQVdIMN6/Df5js2zouUsqG7I6sFxitIC+7KYK29KdXOLHdu9zL4sFnoVQnqaA=="
},
"is-typedarray": {
"version": "1.0.0",
"resolved": "https://registry.npmjs.org/is-typedarray/-/is-typedarray-1.0.0.tgz",
"integrity": "sha1-5HnICFjfDBsR3dppQPlgEfzaSpo="
},
"libsodium": {
"version": "0.7.8",
"resolved": "https://registry.npmjs.org/libsodium/-/libsodium-0.7.8.tgz",
"integrity": "sha512-/Qc+APf0jbeWSaeEruH0L1/tbbT+sbf884ZL0/zV/0JXaDPBzYkKbyb/wmxMHgAHzm3t6gqe7bOOXAVwfqVikQ=="
},
"libsodium-wrappers": {
"version": "0.7.8",
"resolved": "https://registry.npmjs.org/libsodium-wrappers/-/libsodium-wrappers-0.7.8.tgz",
"integrity": "sha512-PDhPWXBqd/SaqAFUBgH2Ux7b3VEEJgyD6BQB+VdNFJb9PbExGr/T/myc/MBoSvl8qLzfm0W0IVByOQS5L1MrCg==",
"require-relative": {
"version": "0.8.7",
"resolved": "https://registry.npmjs.org/require-relative/-/require-relative-0.8.7.tgz",
"integrity": "sha1-eZlTn8ngR6N5KPoZb44VY9q9Nt4="
},
"rollup": {
"version": "2.39.0",
"resolved": "https://registry.npmjs.org/rollup/-/rollup-2.39.0.tgz",
"integrity": "sha512-+WR3bttcq7zE+BntH09UxaW3bQo3vItuYeLsyk4dL2tuwbeSKJuvwiawyhEnvRdRgrII0Uzk00FpctHO/zB1kw==",
"dev": true,
"requires": {
"libsodium": "0.7.8"
"fsevents": "~2.3.1"
}
},
"poly1305-js": {
"version": "0.4.3",
"resolved": "https://registry.npmjs.org/poly1305-js/-/poly1305-js-0.4.3.tgz",
"integrity": "sha512-PZ/bfUvUoIPZ7DwfiEVq0WLZ7scYORkVyUeIFcM6MpeNyE9s6SMz9TUKbYma6k4HOuXZumvu1zvLBdEnku0/UA==",
"rollup-plugin-svelte": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/rollup-plugin-svelte/-/rollup-plugin-svelte-7.1.0.tgz",
"integrity": "sha512-vopCUq3G+25sKjwF5VilIbiY6KCuMNHP1PFvx2Vr3REBNMDllKHFZN2B9jwwC+MqNc3UPKkjXnceLPEjTjXGXg==",
"requires": {
"big-integer": "^1.6.48"
"require-relative": "^0.8.7",
"rollup-pluginutils": "^2.8.2"
}
},
"rollup-pluginutils": {
"version": "2.8.2",
"resolved": "https://registry.npmjs.org/rollup-pluginutils/-/rollup-pluginutils-2.8.2.tgz",
"integrity": "sha512-EEp9NhnUkwY8aif6bxgovPHMoMoNr2FulJziTndpt5H9RdwC47GSGuII9XxpSdzVGM0GWrNPHV6ie1LTNJPaLQ==",
"requires": {
"estree-walker": "^0.6.1"
}
},
"scrypt-async": {
......@@ -87,28 +154,56 @@
}
}
},
"sodium-plus": {
"version": "0.9.0",
"resolved": "https://registry.npmjs.org/sodium-plus/-/sodium-plus-0.9.0.tgz",
"integrity": "sha512-WWKxrd81qDL7C1A10yxNmZ135yovEZuIRnZ/BIf/FcajYBupbKbPdgzwlusPHLVxkMDDamcarq9PxxRBUSqpCw==",
"snowpack": {
"version": "3.0.11",
"resolved": "https://registry.npmjs.org/snowpack/-/snowpack-3.0.11.tgz",
"integrity": "sha512-lBxgkvWTgdg0szE31JUt01wQkA9Lnmm+6lxqeV9rxDfflpx7ASnldVHFvu7Se70QJmPTQB0UJjfKI+xmYGwiiQ==",
"dev": true,
"requires": {
"buffer": "^5.6.0",
"libsodium-wrappers": "^0.7.6",
"poly1305-js": "^0.4.2",
"typedarray-to-buffer": "^3.1.5",
"xsalsa20": "^1.1.0"
"esbuild": "^0.8.7",
"fsevents": "^2.2.0",
"open": "^7.0.4",
"rollup": "^2.34.0"
}
},
"strip-indent": {
"version": "3.0.0",
"resolved": "https://registry.npmjs.org/strip-indent/-/strip-indent-3.0.0.tgz",
"integrity": "sha512-laJTa3Jb+VQpaC6DseHhF7dXVqHTfJPCRDaEbid/drOhgitgYku/letMUqOXFoWV0zIIUbjpdH2t+tYj4bQMRQ==",
"requires": {
"min-indent": "^1.0.0"
}
},
"svelte": {
"version": "3.32.3",
"resolved": "https://registry.npmjs.org/svelte/-/svelte-3.32.3.tgz",
"integrity": "sha512-5etu/wDwtewhnYO/631KKTjSmFrKohFLWNm1sWErVHXqGZ8eJLqrW0qivDSyYTcN8GbUqsR4LkIhftNFsjNehg=="
},
"svelte-hmr": {
"version": "0.12.6",
"resolved": "https://registry.npmjs.org/svelte-hmr/-/svelte-hmr-0.12.6.tgz",
"integrity": "sha512-q08BjoUSbwXpKo9ij6aym93jBrt7K8eutLwix5Y9cuSFLS5djxumOoUVsSzDkdKssLlg5X//Kg/0MWHHBeQRTg=="
},
"svelte-loading-spinners": {
"version": "0.1.4",
"resolved": "https://registry.npmjs.org/svelte-loading-spinners/-/svelte-loading-spinners-0.1.4.tgz",
"integrity": "sha512-r/0Hs9cxtRLh2RwBwwEat1V1M1kypaGFPllM7XdZSH299JTed994B6zMHJ1Z5Ug8B9Tl2bs+VOy8Vz5EFWy5Ww=="
},
"svelte-preprocess": {
"version": "4.6.9",
"resolved": "https://registry.npmjs.org/svelte-preprocess/-/svelte-preprocess-4.6.9.tgz",
"integrity": "sha512-SROWH0rB0DJ+0Ii264cprmNu/NJyZacs5wFD71ya93Cg/oA2lKHgQm4F6j0EWA4ktFMzeuJJm/eX6fka39hEHA==",
"requires": {
"@types/pug": "^2.0.4",
"@types/sass": "^1.16.0",
"detect-indent": "^6.0.0",
"strip-indent": "^3.0.0"
}
},
"svelte-switch": {
"version": "0.0.4",
"resolved": "https://registry.npmjs.org/svelte-switch/-/svelte-switch-0.0.4.tgz",
"integrity": "sha512-Qb/S1CmO6XIaHbwwis5v1aJygna8DvKbnaiCpIUlDdIvZz35s6xQNnb88F2TtEsMUqmlGSm7DQYYBLIj3HwizA==",
"dev": true
"integrity": "sha512-Qb/S1CmO6XIaHbwwis5v1aJygna8DvKbnaiCpIUlDdIvZz35s6xQNnb88F2TtEsMUqmlGSm7DQYYBLIj3HwizA=="
},
"tweetnacl": {
"version": "1.0.3",
......@@ -140,19 +235,6 @@
"version": "0.15.1",
"resolved": "https://registry.npmjs.org/tweetnacl-util/-/tweetnacl-util-0.15.1.tgz",
"integrity": "sha512-RKJBIj8lySrShN4w6i/BonWp2Z/uxwC3h4y7xsRrpP59ZboCd0GpEVsOnMDYLMmKBpYhb5TgHzZXy7wTfYFBRw=="
},
"typedarray-to-buffer": {
"version": "3.1.5",
"resolved": "https://registry.npmjs.org/typedarray-to-buffer/-/typedarray-to-buffer-3.1.5.tgz",
"integrity": "sha512-zdu8XMNEDepKKR+XYOXAVPtWui0ly0NtohUscw+UmaHiAWT8hrV1rr//H6V+0DvJ3OQ19S979M0laLfX8rm82Q==",
"requires": {
"is-typedarray": "^1.0.0"
}
},
"xsalsa20": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/xsalsa20/-/xsalsa20-1.1.0.tgz",
"integrity": "sha512-zd3ytX2cm+tcSndRU+krm0eL4TMMpZE7evs5hLRAoOy6gviqLfe3qOlkjF3i5SeAkQUCeJk0lJZrEU56kHRfWw=="
}
}
}
......@@ -11,15 +11,18 @@
"author": "",
"license": "ISC",
"dependencies": {
"@snowpack/plugin-svelte": "^3.5.2",
"blakejs": "^1.1.0",
"session25519": "^1.1.0",
"sodium-plus": "^0.9.0",
"svelte": "^3.32.3",
"svelte-hmr": "^0.12.6",
"svelte-loading-spinners": "^0.1.4",
"svelte-switch": "0.0.4",
"tweetnacl": "^1.0.3",
"tweetnacl-sealedbox-js": "^1.2.0",
"tweetnacl-util": "^0.15.1"
},
"devDependencies": {
"svelte-switch": "0.0.4"
"snowpack": "^3.0.11"
}
}
<script>
import Section from './Section.interface'
import Section from './Section.svelte'
</script>
<Section path='/about' title='About'>
......
<script>
import Section from './Section.interface'
import Section from './Section.svelte'
</script>
<Section path='/' title='Home'>
......
<script>
import Section from './Section.interface'
import Section from './Section.svelte'
let requestedSection = location.hash.replace('#', '')
......
<script>
import Section from './Section.interface'
import Section from './Section.svelte'
import { getContext } from 'svelte'
import { get } from 'svelte/store'
......
<script>
import { getContext } from 'svelte'
import { state } from '../state.js'
import Section from './Section.interface'
import Section from './Section.svelte'
import { authenticate } from '../authentication.js'
import { BarLoader } from 'svelte-loading-spinners'
......
<script>
import { getContext, tick } from 'svelte'
import { state } from '../state.js'
import Section from './Section.interface'
import Section from './Section.svelte'
let { signedIn, privatePath, currentSection } = getContext(state)
......
<script>
import Section from './Section.interface'
import Section from './Section.svelte'
import { slide } from 'svelte/transition'
let show = true
......
<script>
// @hmr:reset
import Section from './Section.interface'
import Section from './Section.svelte'
import Switch from 'svelte-switch'
let checkedValue = true;
......
/** @type {import("snowpack").SnowpackUserConfig } */
module.exports = {
mount: {
/* ... */
},
exclude: ['.git/**'],
plugins: [
['@snowpack/plugin-svelte'],
],
packageOptions: {
polyfillNode: true
},
devOptions: {
// output: 'stream', // Don’t clear terminal.
open: 'none',
secure: true,
port: 444,
},
buildOptions: {
out: 'sign-in.small-web.org'
},
optimize: {
bundle: true,
minify: true,
target: 'es2020',
},
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment