| … | … | @@ -0,0 +1,35 @@ |
| 1 | // get an.js working in Node.js -- from https://github.com/vic/goan/blob/main/js_helper.js |
| 2 | |
| 3 | import { createRequire } from 'module'; |
| 4 | const require = createRequire(import.meta.url); |
| 5 | |
| 6 | globalThis.self = { |
| 7 | crypto: { |
| 8 | getRandomValues: (buf) => { |
| 9 | require('crypto').randomFillSync(buf); |
| 10 | return buf; |
| 11 | } |
| 12 | } |
| 13 | }; |
| 14 | |
| 15 | if (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 | |
| 24 | const { an } = await import('./an.js'); |
| 25 | |
| 26 | const m = "Hello World"; |
| 27 | const h = await an.hash(m); |
| 28 | const k = await an.gen(); |
| 29 | const s = await an.sign(h, k); |
| 30 | const o = await an.open(s); |
| 31 | |
| 32 | console.log(k); |
| 33 | console.log(h); |
| 34 | console.log(s); |
| 35 | console.log(o); |