OverviewFilesCommitsIssuesDocsReleasesPeers

ANProto commits / 1696f64

rebrand as anproto
1696f6409aca040877faf6e9ea831c23cbc4d6e9
by Everett Bogue <ev@evbogue.com> · 2025-08-26T15:40:34.000Z

Changed files (6) +61 -61

README.md +7 -7
……@@ -1,25 +1,25 @@
1# AProto
1# ANProto
22
3ed25519 keypairs sign ts + hash in base64
3ed25519 keypairs sign timestamp + hash in base64
44
55### code
66
77use Deno or your browser
88
99```
10import { a } from './a.js'
10import { an } from './an.js'
1111
12console.log(await a.gen())
12console.log(await an.gen())
1313
1414// BSY7/er4VJIu08o39NaRAiPY/MAvd7oQhlGCRDABjYU=tQa03kqUWG3VtHZ98++lHFBeQ4JKZwuTH2CjC/K6P8EFJjv96vhUki7Tyjf01pECI9j8wC93uhCGUYJEMAGNhQ==
1515
16console.log(await a.hash('Hello World'))
16console.log(await an.hash('Hello World'))
1717// pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4=
1818
19console.log(await a.sig('Hello World', await a.gen()))
19console.log(await an.sign('Hello World', await a.gen()))
2020// BSY7/er4VJIu08o39NaRAiPY/MAvd7oQhlGCRDABjYU=yVpD8i7d3d4dls3YThEg1x1vSdmqeEweV4e4Ejl/8yPoVG7JR0YAKDPagQOgxXMrlCVLNNqvlNvj4xRDOYDLBjE3NTUxOTc4NDEzMTlwWkdtMUF2MElFQktBUmN6ejdleGtOWXNaYjhMemFNclY3SjMyYTJmRkc0PQ==
2121
22console.log(await a.open('BSY7/er4VJIu08o39NaRAiPY/MAvd7oQhlGCRDABjYU=yVpD8i7d3d4dls3YThEg1x1vSdmqeEweV4e4Ejl/8yPoVG7JR0YAKDPagQOgxXMrlCVLNNqvlNvj4xRDOYDLBjE3NTUxOTc4NDEzMTlwWkdtMUF2MElFQktBUmN6ejdleGtOWXNaYjhMemFNclY3SjMyYTJmRkc0PQ=='))
22console.log(await an.open('BSY7/er4VJIu08o39NaRAiPY/MAvd7oQhlGCRDABjYU=yVpD8i7d3d4dls3YThEg1x1vSdmqeEweV4e4Ejl/8yPoVG7JR0YAKDPagQOgxXMrlCVLNNqvlNvj4xRDOYDLBjE3NTUxOTc4NDEzMTlwWkdtMUF2MElFQktBUmN6ejdleGtOWXNaYjhMemFNclY3SjMyYTJmRkc0PQ=='))
2323
2424//1755197841319pZGm1Av0IEBKARczz7exkNYsZb8LzaMrV7J32a2fFG4=
2525```
a.js +0 -37
……@@ -1,37 +0,0 @@
1import nacl from "./lib/nacl-fast-es.js";
2import { decode, encode } from "./lib/base64.js";
3
4export const a = {};
5
6a.gen = async () => {
7 const g = await nacl.sign.keyPair();
8 const k = await encode(g.publicKey) + encode(g.secretKey);
9 return k;
10};
11
12a.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
22a.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
31a.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};
an.js +37 -0
……@@ -0,0 +1,37 @@
1import nacl from "./lib/nacl-fast-es.js";
2import { decode, encode } from "./lib/base64.js";
3
4export const an = {};
5
6an.gen = async () => {
7 const g = await nacl.sign.keyPair();
8 const k = await encode(g.publicKey) + encode(g.secretKey);
9 return k;
10};
11
12an.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
22an.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
31an.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};
ex.js +5 -5
……@@ -1,10 +1,10 @@
1import { a } from "./a.js";
1import { an } from "./an.js";
22
33const m = "Hello World";
4const h = await a.hash(m);
5const k = await a.gen();
6const s = await a.sign(m, k);
7const o = await a.open(s);
4const h = await an.hash(m);
5const k = await an.gen();
6const s = await an.sign(m, k);
7const o = await an.open(s);
88
99console.log(k);
1010console.log(h);
example.js +10 -10
……@@ -9,8 +9,8 @@ app.get('/', async (c) => {
99 const content = `
1010 <div id="scroller">
1111 <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>
1414 <p><a href="https://wiredove.net/">Wiredove</a></p>
1515 </div>
1616 </div>
……@@ -25,7 +25,7 @@ app.get('/try', async (c) => {
2525 const body = `<body>
2626 <div id='scroller'>
2727 <div class='message'>
28 <h1>Try AProto</h1>
28 <h1>Try ANProto</h1>
2929
3030 <p><em>An Interactive Demonstration</em></p>
3131
……@@ -55,7 +55,7 @@ app.get('/try', async (c) => {
5555
5656 <div class='message'>
5757
58 <p><strong>Step 3.</strong> Sign an AProto message</p>
58 <p><strong>Step 3.</strong> Sign the ANProto message</p>
5959
6060 <code>const sig = await a.sign(hash, keypair)</code>
6161
……@@ -66,7 +66,7 @@ app.get('/try', async (c) => {
6666 </div>
6767 <div class="message">
6868
69 <p><strong>Step 4.</strong> Open the AProto message</p>
69 <p><strong>Step 4.</strong> Open the ANProto message</p>
7070
7171 <code>const opened = await a.open(msg)</code>
7272
……@@ -88,13 +88,13 @@ app.get('/try', async (c) => {
8888</body>
8989
9090<script type='module'>
91import { a } from './a.js'
91import { an } from './an.js'
9292
9393const key = document.getElementById('key')
9494const button = document.getElementById('but')
9595
9696button.onclick = async () => {
97 key.value = await a.gen()
97 key.value = await an.gen()
9898}
9999
100100const content = document.getElementById('content')
……@@ -104,7 +104,7 @@ const sha = document.getElementById('sha256')
104104let blobs = []
105105
106106hashbutton.onclick = async () => {
107 sha.textContent = await a.hash(content.value)
107 sha.textContent = await an.hash(content.value)
108108 blobs[sha.textContent] = content.value
109109}
110110
……@@ -112,7 +112,7 @@ const siginput = document.getElementById('sig')
112112const signbutton = document.getElementById('sign')
113113
114114signbutton.onclick = async () => {
115 siginput.value = await a.sign(sha.textContent, key.value)
115 siginput.value = await an.sign(sha.textContent, key.value)
116116}
117117
118118const openbutton = document.getElementById('open')
……@@ -120,7 +120,7 @@ const openbutton = document.getElementById('open')
120120const openen = document.getElementById('openen')
121121
122122openbutton.onclick = async () => {
123 openen.value = await a.open(siginput.value)
123 openen.value = await an.open(siginput.value)
124124}
125125
126126const msgspan = document.getElementById('msg')
template.js +2 -2
……@@ -3,7 +3,7 @@ export const head = async (title) => {
33<!doctype html>
44<html>
55 <head>
6 <title>A Protocol | ${title}</title>
6 <title>ANProto | ${title}</title>
77 <link rel='stylesheet' href='./style.css' type='text/css' />
88 <meta name='viewport' content='width=device-width initial-scale=1' />
99 <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
……@@ -16,7 +16,7 @@ export const head = async (title) => {
1616 <body>
1717 <div id='navbar'>
1818 <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>
2020 </div>
2121`;
2222};