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