OverviewFilesCommitsIssuesDocsReleasesPeers

ANProto commits / 49a3606

add example that works with node.js
49a3606ca5cb9967c2b84ff89c6d6648531c45f8
by Everett Bogue <ev@evbogue.com> · 2025-09-02T19:51:58.000Z

Changed files (3) +37 -2

README.md +1 -1
……@@ -8,7 +8,7 @@ ed25519 keypairs sign timestamp + hash in base64
88
99[anproto.com](https://anproto.com)
1010
11+ [Deno/Browser implementation](https://github.com/evbogue/anproto) [by Evbogue]
11+ [JavaScript implementation](https://github.com/evbogue/anproto) [by Evbogue]
1212+ [Golang implementation](https://github.com/vic/goan) [by Vic]
1313
1414try it at [anproto.com/try](https://anproto.com/try) or use a client such as [wiredove](https://wiredove.net/)
ex.js +1 -1
……@@ -3,7 +3,7 @@ import { an } from "./an.js";
33const m = "Hello World";
44const h = await an.hash(m);
55const k = await an.gen();
6const s = await an.sign(m, k);
6const s = await an.sign(h, k);
77const o = await an.open(s);
88
99console.log(k);
node_ex.js +35 -0
……@@ -0,0 +1,35 @@
1// get an.js working in Node.js -- from https://github.com/vic/goan/blob/main/js_helper.js
2
3import { createRequire } from 'module';
4const require = createRequire(import.meta.url);
5
6globalThis.self = {
7 crypto: {
8 getRandomValues: (buf) => {
9 require('crypto').randomFillSync(buf);
10 return buf;
11 }
12 }
13};
14
15if (typeof globalThis.crypto === 'undefined' || typeof globalThis.crypto.subtle === 'undefined') {
16 globalThis.crypto = globalThis.crypto || {};
17 try {
18 globalThis.crypto.subtle = require('crypto').webcrypto.subtle;
19 } catch (e) {
20 console.log(e)
21 }
22}
23
24const { an } = await import('./an.js');
25
26const m = "Hello World";
27const h = await an.hash(m);
28const k = await an.gen();
29const s = await an.sign(h, k);
30const o = await an.open(s);
31
32console.log(k);
33console.log(h);
34console.log(s);
35console.log(o);