# dog_and_duck/scratch/scratch.clj

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-pgp.core :as pgp]
006 [clj-pgp.keyring :as keyring]
007 [clj-pgp.generate :as pgp-gen]
008 [clojure.walk :refer [keywordize-keys]]
009 [clojure.pprint :refer [pprint]]))
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 "Fetch my account to mess with"
039 (let [handle (activitypub/parse-account account-handle)]
040 (keywordize-keys
041 (activitypub/fetch-user
042 (apply webfinger/fetch-user-id (map handle [:domain :username]))))))
043
044 ;;; examine what you got back!
045 (:inbox account)
046
047
048 (def rsa (pgp-gen/rsa-keypair-generator 2048))
049 (def kp (pgp-gen/generate-keypair rsa :rsa-general))
050
051 ;; how we make a public/private key pair. But this key pair is not the one
052 ;; known to mastodon.scot as my key pair, so that doesn't get us very far...
053 ;; I think.
054 (let [rsa (pgp-gen/rsa-keypair-generator 2048)
055 kp (pgp-gen/generate-keypair rsa :rsa-general)
056 public (-> kp .getPublicKey .getEncoded)
057 private (-> kp .getPrivateKey .getPrivateKeyDataPacket .getEncoded)]
058 (println (str "Public key: " public))
059 (println (str "Private key: " private))
060 )
061