001  (ns dog-and-duck.scratch.scratch
002    "Scratchpad where I try to understand how to do this stuff."
003    (:require [clj-activitypub.core :as activitypub]
004              [clj-activitypub.webfinger :as webfinger]
005              [clj-activitypub.net :as activitypub-net]
006              [clj-pgp.generate :as pgp-gen]
007              [clojure.walk :refer [keywordize-keys]]
008              [clojure.pprint :refer [pprint]]
009              [clojure.data.json :as json]))
010  
011  ;;;     Copyright (C) Simon Brooke, 2022
012  
013  ;;;     This program is free software; you can redistribute it and/or
014  ;;;     modify it under the terms of the GNU General Public License
015  ;;;     as published by the Free Software Foundation; either version 2
016  ;;;     of the License, or (at your option) any later version.
017      
018  ;;;     This program is distributed in the hope that it will be useful,
019  ;;;     but WITHOUT ANY WARRANTY; without even the implied warranty of
020  ;;;     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
021  ;;;     GNU General Public License for more details.
022      
023  ;;;     You should have received a copy of the GNU General Public License
024  ;;;     along with this program; if not, write to the Free Software
025  ;;;     Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
026  
027  ;;; Use any ActivityPub account handle you like - for example, your own
028  (def account-handle "@simon_brooke@mastodon.scot")
029  
030  ;;(def handle (activitypub/parse-account account-handle))
031  ;;(webfinger/fetch-user-id "mastodon.scot" "simon_brooke")
032  ;;(apply webfinger/fetch-user-id (map handle [:domain :username]))
033  
034  ;;; Retrieve the account details from its home server
035  ;;; (`keywordize-keys` is not necessary here but produces a more idiomatic clojure
036  ;;; data structure)
037  ;; (def account
038  ;;   (-> account-handle
039  ;;       (webfinger/parse-handle)
040  ;;       (webfinger/fetch-user-id!)
041  ;;       (activitypub-net/fetch-user!)
042  ;;       (select-keys [:name :preferredUsername :inbox :summary])))
043  
044  ;; ;;; examine what you got back!
045  ;; (:inbox account)
046  
047  ;; (-> account
048  ;;     :inbox
049  ;;     slurp
050  ;;     json/read-str
051  ;;     pprint) ;; => 80
052  
053  ;; (def rsa (pgp-gen/rsa-keypair-generator 2048))
054  ;; (def kp (pgp-gen/generate-keypair rsa :rsa-general))
055  
056  ;; how we make a public/private key pair. But this key pair is not the one 
057  ;; known to mastodon.scot as my key pair, so that doesn't get us very far...
058  ;; I think.
059  ;; (let [rsa (pgp-gen/rsa-keypair-generator 2048)
060  ;;       kp (pgp-gen/generate-keypair rsa :rsa-general)
061  ;;       public (-> kp .getPublicKey .getEncoded)
062  ;;       private (-> kp .getPrivateKey .getPrivateKeyDataPacket .getEncoded)]
063  ;;   (println (str "Public key:  " public))
064  ;;   (println (str "Private key: " private))
065  ;;   )
066