| … | … | @@ -1,25 +1,25 @@ |
| 1 | # AProto | |
| 1 | # ANProto | |
| 2 | 2 | |
| 3 | ed25519 keypairs sign ts + hash in base64 | |
| 3 | ed25519 keypairs sign timestamp + hash in base64 | |
| 4 | 4 | |
| 5 | 5 | ### code |
| 6 | 6 | |
| 7 | 7 | use Deno or your browser |
| 8 | 8 | |
| 9 | 9 | ``` |
| 10 | import { a } from './a.js' | |
| 10 | import { an } from './an.js' | |
| 11 | 11 | |
| 12 | console.log(await a.gen()) | |
| 12 | console.log(await an.gen()) | |
| 13 | 13 | |
| 14 | 14 | // BSY7/er4VJIu08o39NaRAiPY/MAvd7oQhlGCRDABjYU=tQa03kqUWG3VtHZ98++lHFBeQ4JKZwuTH2CjC/K6P8EFJjv96vhUki7Tyjf01pECI9j8wC93uhCGUYJEMAGNhQ== |
| 15 | 15 | |
| 16 | console.log(await a.hash('Hello World')) | |
| 16 | console.log(await an.hash('Hello World')) | |
| 17 | 17 | // pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4= |
| 18 | 18 | |
| 19 | console.log(await a.sig('Hello World', await a.gen())) | |
| 19 | console.log(await an.sign('Hello World', await a.gen())) | |
| 20 | 20 | // BSY7/er4VJIu08o39NaRAiPY/MAvd7oQhlGCRDABjYU=yVpD8i7d3d4dls3YThEg1x1vSdmqeEweV4e4Ejl/8yPoVG7JR0YAKDPagQOgxXMrlCVLNNqvlNvj4xRDOYDLBjE3NTUxOTc4NDEzMTlwWkdtMUF2MElFQktBUmN6ejdleGtOWXNaYjhMemFNclY3SjMyYTJmRkc0PQ== |
| 21 | 21 | |
| 22 | console.log(await a.open('BSY7/er4VJIu08o39NaRAiPY/MAvd7oQhlGCRDABjYU=yVpD8i7d3d4dls3YThEg1x1vSdmqeEweV4e4Ejl/8yPoVG7JR0YAKDPagQOgxXMrlCVLNNqvlNvj4xRDOYDLBjE3NTUxOTc4NDEzMTlwWkdtMUF2MElFQktBUmN6ejdleGtOWXNaYjhMemFNclY3SjMyYTJmRkc0PQ==')) | |
| 22 | console.log(await an.open('BSY7/er4VJIu08o39NaRAiPY/MAvd7oQhlGCRDABjYU=yVpD8i7d3d4dls3YThEg1x1vSdmqeEweV4e4Ejl/8yPoVG7JR0YAKDPagQOgxXMrlCVLNNqvlNvj4xRDOYDLBjE3NTUxOTc4NDEzMTlwWkdtMUF2MElFQktBUmN6ejdleGtOWXNaYjhMemFNclY3SjMyYTJmRkc0PQ==')) | |
| 23 | 23 | |
| 24 | 24 | //1755197841319pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4= |
| 25 | 25 | ``` |
| … | … | @@ -1,37 +0,0 @@ |
| 1 | import nacl from "./lib/nacl-fast-es.js"; | |
| 2 | import { decode, encode } from "./lib/base64.js"; | |
| 3 | ||
| 4 | export const a = {}; | |
| 5 | ||
| 6 | a.gen = async () => { | |
| 7 | const g = await nacl.sign.keyPair(); | |
| 8 | const k = await encode(g.publicKey) + encode(g.secretKey); | |
| 9 | return k; | |
| 10 | }; | |
| 11 | ||
| 12 | a.hash = async (d) => { | |
| 13 | return encode( | |
| 14 | Array.from( | |
| 15 | new Uint8Array( | |
| 16 | await crypto.subtle.digest("SHA-256", new TextEncoder().encode(d)), | |
| 17 | ), | |
| 18 | ), | |
| 19 | ); | |
| 20 | }; | |
| 21 | ||
| 22 | a.sign = async (h, k) => { | |
| 23 | const ts = Date.now(); | |
| 24 | const s = encode( | |
| 25 | nacl.sign(new TextEncoder().encode(ts + h), decode(k.substring(44))), | |
| 26 | ); | |
| 27 | ||
| 28 | return k.substring(0, 44) + s; | |
| 29 | }; | |
| 30 | ||
| 31 | a.open = async (m) => { | |
| 32 | const o = new TextDecoder().decode( | |
| 33 | nacl.sign.open(decode(m.substring(44)), decode(m.substring(0, 44))), | |
| 34 | ); | |
| 35 | ||
| 36 | return o; | |
| 37 | }; |
| … | … | @@ -0,0 +1,37 @@ |
| 1 | import nacl from "./lib/nacl-fast-es.js"; | |
| 2 | import { decode, encode } from "./lib/base64.js"; | |
| 3 | ||
| 4 | export const an = {}; | |
| 5 | ||
| 6 | an.gen = async () => { | |
| 7 | const g = await nacl.sign.keyPair(); | |
| 8 | const k = await encode(g.publicKey) + encode(g.secretKey); | |
| 9 | return k; | |
| 10 | }; | |
| 11 | ||
| 12 | an.hash = async (d) => { | |
| 13 | return encode( | |
| 14 | Array.from( | |
| 15 | new Uint8Array( | |
| 16 | await crypto.subtle.digest("SHA-256", new TextEncoder().encode(d)), | |
| 17 | ), | |
| 18 | ), | |
| 19 | ); | |
| 20 | }; | |
| 21 | ||
| 22 | an.sign = async (h, k) => { | |
| 23 | const ts = Date.now(); | |
| 24 | const s = encode( | |
| 25 | nacl.sign(new TextEncoder().encode(ts + h), decode(k.substring(44))), | |
| 26 | ); | |
| 27 | ||
| 28 | return k.substring(0, 44) + s; | |
| 29 | }; | |
| 30 | ||
| 31 | an.open = async (m) => { | |
| 32 | const o = new TextDecoder().decode( | |
| 33 | nacl.sign.open(decode(m.substring(44)), decode(m.substring(0, 44))), | |
| 34 | ); | |
| 35 | ||
| 36 | return o; | |
| 37 | }; |
| … | … | @@ -1,10 +1,10 @@ |
| 1 | import { a } from "./a.js"; | |
| 1 | import { an } from "./an.js"; | |
| 2 | 2 | |
| 3 | 3 | const m = "Hello World"; |
| 4 | const h = await a.hash(m); | |
| 5 | const k = await a.gen(); | |
| 6 | const s = await a.sign(m, k); | |
| 7 | const o = await a.open(s); | |
| 4 | const h = await an.hash(m); | |
| 5 | const k = await an.gen(); | |
| 6 | const s = await an.sign(m, k); | |
| 7 | const o = await an.open(s); | |
| 8 | 8 | |
| 9 | 9 | console.log(k); |
| 10 | 10 | console.log(h); |
| … | … | @@ -9,8 +9,8 @@ app.get('/', async (c) => { |
| 9 | 9 | const content = ` |
| 10 | 10 | <div id="scroller"> |
| 11 | 11 | <div class='message'> |
| 12 | <h1>AProto</h1> | |
| 13 | <p><a href="./try">Try AProto</a></p> | |
| 12 | <h1>ANProto</h1> | |
| 13 | <p><a href="./try">Try ANProto</a></p> | |
| 14 | 14 | <p><a href="https://wiredove.net/">Wiredove</a></p> |
| 15 | 15 | </div> |
| 16 | 16 | </div> |
| … | … | @@ -25,7 +25,7 @@ app.get('/try', async (c) => { |
| 25 | 25 | const body = `<body> |
| 26 | 26 | <div id='scroller'> |
| 27 | 27 | <div class='message'> |
| 28 | <h1>Try AProto</h1> | |
| 28 | <h1>Try ANProto</h1> | |
| 29 | 29 | |
| 30 | 30 | <p><em>An Interactive Demonstration</em></p> |
| 31 | 31 | |
| … | … | @@ -55,7 +55,7 @@ app.get('/try', async (c) => { |
| 55 | 55 | |
| 56 | 56 | <div class='message'> |
| 57 | 57 | |
| 58 | <p><strong>Step 3.</strong> Sign an AProto message</p> | |
| 58 | <p><strong>Step 3.</strong> Sign the ANProto message</p> | |
| 59 | 59 | |
| 60 | 60 | <code>const sig = await a.sign(hash, keypair)</code> |
| 61 | 61 | |
| … | … | @@ -66,7 +66,7 @@ app.get('/try', async (c) => { |
| 66 | 66 | </div> |
| 67 | 67 | <div class="message"> |
| 68 | 68 | |
| 69 | <p><strong>Step 4.</strong> Open the AProto message</p> | |
| 69 | <p><strong>Step 4.</strong> Open the ANProto message</p> | |
| 70 | 70 | |
| 71 | 71 | <code>const opened = await a.open(msg)</code> |
| 72 | 72 | |
| … | … | @@ -88,13 +88,13 @@ app.get('/try', async (c) => { |
| 88 | 88 | </body> |
| 89 | 89 | |
| 90 | 90 | <script type='module'> |
| 91 | import { a } from './a.js' | |
| 91 | import { an } from './an.js' | |
| 92 | 92 | |
| 93 | 93 | const key = document.getElementById('key') |
| 94 | 94 | const button = document.getElementById('but') |
| 95 | 95 | |
| 96 | 96 | button.onclick = async () => { |
| 97 | key.value = await a.gen() | |
| 97 | key.value = await an.gen() | |
| 98 | 98 | } |
| 99 | 99 | |
| 100 | 100 | const content = document.getElementById('content') |
| … | … | @@ -104,7 +104,7 @@ const sha = document.getElementById('sha256') |
| 104 | 104 | let blobs = [] |
| 105 | 105 | |
| 106 | 106 | hashbutton.onclick = async () => { |
| 107 | sha.textContent = await a.hash(content.value) | |
| 107 | sha.textContent = await an.hash(content.value) | |
| 108 | 108 | blobs[sha.textContent] = content.value |
| 109 | 109 | } |
| 110 | 110 | |
| … | … | @@ -112,7 +112,7 @@ const siginput = document.getElementById('sig') |
| 112 | 112 | const signbutton = document.getElementById('sign') |
| 113 | 113 | |
| 114 | 114 | signbutton.onclick = async () => { |
| 115 | siginput.value = await a.sign(sha.textContent, key.value) | |
| 115 | siginput.value = await an.sign(sha.textContent, key.value) | |
| 116 | 116 | } |
| 117 | 117 | |
| 118 | 118 | const openbutton = document.getElementById('open') |
| … | … | @@ -120,7 +120,7 @@ const openbutton = document.getElementById('open') |
| 120 | 120 | const openen = document.getElementById('openen') |
| 121 | 121 | |
| 122 | 122 | openbutton.onclick = async () => { |
| 123 | openen.value = await a.open(siginput.value) | |
| 123 | openen.value = await an.open(siginput.value) | |
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | const msgspan = document.getElementById('msg') |
| … | … | @@ -3,7 +3,7 @@ export const head = async (title) => { |
| 3 | 3 | <!doctype html> |
| 4 | 4 | <html> |
| 5 | 5 | <head> |
| 6 | <title>A Protocol | ${title}</title> | |
| 6 | <title>ANProto | ${title}</title> | |
| 7 | 7 | <link rel='stylesheet' href='./style.css' type='text/css' /> |
| 8 | 8 | <meta name='viewport' content='width=device-width initial-scale=1' /> |
| 9 | 9 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/> |
| … | … | @@ -16,7 +16,7 @@ export const head = async (title) => { |
| 16 | 16 | <body> |
| 17 | 17 | <div id='navbar'> |
| 18 | 18 | <img src='https://wiredove.net/doveorange_sm.png' class='avatar_small' style='vertical-align: middle;'></strong> |
| 19 | <strong><span style="color: #fe7a00;">A</span>Proto</strong> | |
| 19 | <strong><span style="color: #fe7a00;">AN</span>Proto</strong> | |
| 20 | 20 | </div> |
| 21 | 21 | `; |
| 22 | 22 | }; |