summaryrefslogtreecommitdiff
path: root/haunt
diff options
context:
space:
mode:
authorJakob L. Kreuze <zerodaysfordays@sdf.org>2022-11-15 18:54:30 -0500
committerJakob L. Kreuze <zerodaysfordays@sdf.org>2022-11-15 18:58:20 -0500
commitb6482d86fa58dee7d55889fa873463274f81d3db (patch)
treeab82cfff0cbc7ed4294975bd526ad0f1a36c8812 /haunt
parent311c083a7786ff83b4810a507fb7af492b20121d (diff)
[dynamic] Cut chalkline
Diffstat (limited to 'haunt')
-rw-r--r--haunt/jakob/builder/blog.scm3
-rw-r--r--haunt/jakob/utils/comments.scm12
-rw-r--r--haunt/static/js/proof-of-work.js34
3 files changed, 37 insertions, 12 deletions
diff --git a/haunt/jakob/builder/blog.scm b/haunt/jakob/builder/blog.scm
index 76782dc..b1e19fa 100644
--- a/haunt/jakob/builder/blog.scm
+++ b/haunt/jakob/builder/blog.scm
@@ -26,8 +26,8 @@
#:use-module (jakob utils pagination)
#:use-module (jakob utils sxml)
#:use-module (jakob utils tags)
- #:use-module (jakob utils webmention)
#:use-module (jakob utils comments)
+ ;; #:use-module (jakob utils webmention)
#:use-module (srfi srfi-1)
#:use-module (srfi srfi-19)
#:use-module (srfi srfi-26)
@@ -86,6 +86,7 @@
(h2 ,(hyperlink "https://indieweb.org/Webmention" "Webmentions")
" for this Page")
(ul (@ (id "webmention-container"))
+ ;; ,@(render-comment-view (fetch-webmentions (post-identifier post))))
,@(render-comment-view (fetch-comments (post-identifier post))))
(form
(@ (action "https://webmention.io/jakob.space/webmention")
diff --git a/haunt/jakob/utils/comments.scm b/haunt/jakob/utils/comments.scm
index 7cb4768..3f55345 100644
--- a/haunt/jakob/utils/comments.scm
+++ b/haunt/jakob/utils/comments.scm
@@ -102,14 +102,4 @@
(define (fetch-comments slug)
"Blocking call to webmention.io to retrieve a vector of all Webmentions for `slug'"
- (get-comments-by-slug slug)
- ;; (list '((id . 1)
- ;; (published . "20220514122120")
- ;; (name . "Jakob")
- ;; (subject . "Test")
- ;; (email . "jakob@memeware.net")
- ;; (comment . "Test")
- ;; (url . "jakob.space")
- ;; (reactions . (("🎖️" . 2)))))
- )
-;; dynamic
+ (get-comments-by-slug slug))
diff --git a/haunt/static/js/proof-of-work.js b/haunt/static/js/proof-of-work.js
new file mode 100644
index 0000000..5207ac6
--- /dev/null
+++ b/haunt/static/js/proof-of-work.js
@@ -0,0 +1,34 @@
+const text = 'An obscure body in the S-K System, your majesty. The inhabitants refer to it as the planet Earth.';
+
+function makeid(length) {
+ var result = '';
+ var characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
+ var charactersLength = characters.length;
+ for ( var i = 0; i < length; i++ ) {
+ result += characters.charAt(Math.floor(Math.random() * charactersLength));
+ }
+ return result;
+}
+
+async function digestMessage(message) {
+ const msgUint8 = new TextEncoder().encode(message); // encode as (utf-8) Uint8Array
+ const hashBuffer = await crypto.subtle.digest('SHA-256', msgUint8); // hash the message
+ const hashArray = Array.from(new Uint8Array(hashBuffer)); // convert buffer to byte array
+ const hashHex = hashArray.map((b) => b.toString(16).padStart(2, '0')).join(''); // convert bytes to hex string
+ return hashHex;
+}
+
+const HARDNESS = 4;
+
+async function findPrefix(challenge) {
+ while (true) {
+ let prefix = makeid(32);
+ let digestHex = await digestMessage(prefix + challenge);
+ if (digestHex.startsWith("0".repeat(HARDNESS))) {
+ return [prefix + challenge, digestHex];
+ }
+ }
+}
+
+const suffix = "p12IyPB2dZsmBHYZyaEMrR5OUxqNc5Z9Cijal+9/iuQ=";
+findPrefix(suffix).then(console.log);