Encrypted, ephemeral, private memos on atproto

feat(producer): allow switching public keys

graham.systems be2f6f40 0c575e72

verified
Changed files
+12 -15
packages
producer
+11 -8
packages/producer/mod.ts
··· 1 1 import { produceRequirements } from "@cistern/shared"; 2 2 import { encryptText } from "@cistern/crypto"; 3 3 import type { 4 - LocalPublicKey, 5 4 ProducerOptions, 6 5 ProducerParams, 7 6 PublicKeyOption, ··· 21 20 ): Promise<Producer> { 22 21 const reqs = await produceRequirements(opts); 23 22 24 - let publicKey: LocalPublicKey | undefined; 23 + let publicKey: PublicKeyOption | undefined; 25 24 if (rkey) { 26 - // Fetch record contents from PDS 27 25 const res = await reqs.rpc.get("com.atproto.repo.getRecord", { 28 26 params: { 29 27 repo: reqs.miniDoc.did, ··· 40 38 41 39 const record = parse(AppCisternLexiconPubkey.mainSchema, res.data.value); 42 40 43 - publicKey = { uri: res.data.uri, record }; 41 + publicKey = { 42 + uri: res.data.uri, 43 + name: record.name, 44 + content: record.content, 45 + }; 44 46 } 45 47 46 48 return new Producer({ ··· 53 55 did: Did; 54 56 rpc: Client; 55 57 manager: CredentialManager; 56 - publicKey?: LocalPublicKey; 58 + publicKey?: PublicKeyOption; 57 59 58 60 constructor(params: ProducerParams) { 59 61 this.did = params.miniDoc.did; ··· 73 75 } 74 76 75 77 const payload = encryptText( 76 - Uint8Array.fromBase64(this.publicKey.record.content), 78 + Uint8Array.fromBase64(this.publicKey.content), 77 79 text, 78 80 ); 79 81 const record: AppCisternLexiconItem.Main = { ··· 148 150 149 151 /** 150 152 * Sets a public key as the main encryption key 151 - * @todo Replace local key with provided key 152 153 */ 153 - selectPublicKey() {} 154 + selectPublicKey(key: PublicKeyOption) { 155 + this.publicKey = key; 156 + } 154 157 }
+1 -7
packages/producer/types.ts
··· 1 1 import type { BaseClientOptions, ClientRequirements } from "@cistern/shared"; 2 - import type { AppCisternLexiconPubkey } from "@cistern/lexicon"; 3 2 import type { RecordKey, ResourceUri } from "@atcute/lexicons"; 4 3 5 4 export interface ProducerOptions extends BaseClientOptions { ··· 7 6 } 8 7 9 8 export type ProducerParams = ClientRequirements<ProducerOptions> & { 10 - publicKey?: LocalPublicKey; 9 + publicKey?: PublicKeyOption; 11 10 }; 12 - 13 - export interface LocalPublicKey { 14 - uri: ResourceUri; 15 - record: AppCisternLexiconPubkey.Main; 16 - } 17 11 18 12 export interface PublicKeyOption { 19 13 uri: ResourceUri;