this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Don't accept user-provided p256 private key

futurGH b54efd85 fed54890

+8 -16
+8 -16
src/scripts/plc.ts
··· 1 1 import { AtpAgent, ComAtprotoIdentitySignPlcOperation } from "@atproto/api"; 2 - import { P256Keypair, Secp256k1Keypair } from "@atproto/crypto"; 2 + import { Secp256k1Keypair } from "@atproto/crypto"; 3 3 import * as ui8 from "uint8arrays"; 4 4 import { loginAgentOrCredentials } from "./util.js"; 5 5 ··· 23 23 /** An agent logged into the labeler account. You must provide either `password` or `agent`. */ 24 24 agent?: AtpAgent; 25 25 26 - /** You may choose to provide your own signing key to use for the labeler. */ 26 + /** 27 + * You may choose to provide your own hex-encoded secp256k1 signing key to use for the labeler. 28 + * Leave this empty to generate a new keypair. 29 + */ 27 30 privateKey?: string | Uint8Array; 28 - /** The algorithm of the provided private key. */ 29 - privateKeyAlgorithm?: "secp256k1" | "secp256r1"; 30 31 /** Whether to overwrite the existing label signing key if one is already set. */ 31 32 overwriteExistingKey?: boolean; 32 33 } ··· 53 54 await agent.login({ identifier: options.did, password: options.password }); 54 55 } 55 56 56 - let keypair: Secp256k1Keypair | P256Keypair; 57 - if (options.privateKey) { 58 - if (options.privateKeyAlgorithm === "secp256r1") { 59 - keypair = await P256Keypair.import(options.privateKey); 60 - } else if (options.privateKeyAlgorithm === "secp256k1") { 61 - keypair = await Secp256k1Keypair.import(options.privateKey); 62 - } else { 63 - throw new Error("Invalid private key algorithm."); 64 - } 65 - } else { 66 - keypair = await Secp256k1Keypair.create({ exportable: true }); 67 - } 57 + const keypair = options.privateKey 58 + ? await Secp256k1Keypair.import(options.privateKey) 59 + : await Secp256k1Keypair.create({ exportable: true }); 68 60 69 61 const keyDid = keypair.did(); 70 62