open source is social v-it.org
0
fork

Configure Feed

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

Add verbose output flag to plc-register

- Add -v/--verbose flag to show detailed operation info
- Display compressed pubkey in hex during key generation
- Show unsigned operation structure as pretty JSON
- Print CBOR encoding size and signature
- Display SHA256 hash used for DID derivation
- List files written with sizes
- Show HTTP request body when posting to PLC directory

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>

+33 -2
+33 -2
plc_register.py
··· 112 112 signing_key_bytes: bytes # compressed point (33 bytes) 113 113 114 114 115 - def generate_rotation_key(outdir: pathlib.Path, curve: str) -> KeyBundle: 115 + def generate_rotation_key(outdir: pathlib.Path, curve: str, verbose: bool = False) -> KeyBundle: 116 116 ensure_dir(outdir) 117 117 if curve == "k256": 118 118 priv = ec.generate_private_key(ec.SECP256K1(), backend=default_backend()) ··· 142 142 # did:key for rotation key is allowed; PLC only requires rotationKeys to be did:key of k256 or p256 143 143 compressed = compress_pubkey_bytes(pub) 144 144 didk = did_key_for_pub(curve, compressed) 145 + 146 + if verbose: 147 + print(f"[verbose] Generated {curve.upper()} keypair") 148 + print(f"[verbose] Compressed pubkey: {compressed.hex()}") 145 149 146 150 return KeyBundle( 147 151 curve=curve, ··· 188 192 ap.add_argument("--aka", action="append", default=[], help="alsoKnownAs entry (e.g., at://alice.example). May repeat.") 189 193 ap.add_argument("--pds", default=None, help="PDS endpoint URL (e.g., https://pds.example.com)") 190 194 ap.add_argument("--dry-run", action="store_true", help="Build & print but do not POST to PLC") 195 + ap.add_argument("-v", "--verbose", action="store_true", help="Show verbose output") 191 196 args = ap.parse_args() 192 197 193 198 outdir = pathlib.Path(args.out) 194 - kb = generate_rotation_key(outdir, args.curve) 199 + kb = generate_rotation_key(outdir, args.curve, args.verbose) 195 200 196 201 unsigned = build_unsigned_op([kb.did_key], args.aka, args.pds) 197 202 203 + if args.verbose: 204 + print("[verbose] Unsigned operation:") 205 + print(json.dumps(unsigned, indent=2)) 206 + 198 207 # Sign DAG-CBOR bytes of unsigned op (without 'sig') 199 208 unsigned_cbor = dag_cbor.encode(unsigned) 209 + if args.verbose: 210 + print(f"[verbose] Encoded CBOR size: {len(unsigned_cbor)} bytes") 211 + 200 212 # cryptography ECDSA expects the message; spec requires ECDSA-SHA256; library will hash internally. 201 213 # If you'd rather sign the SHA256 digest explicitly, replace message with hashlib.sha256(unsigned_cbor).digest() 202 214 # and switch to ec.Prehashed(hashes.SHA256()). ··· 205 217 raw_sig = sign_low_s_raw(args.curve, priv, unsigned_cbor) 206 218 sig_b64u = b64url_nopad(raw_sig) 207 219 220 + if args.verbose: 221 + print(f"[verbose] Signature (base64url): {sig_b64u}") 222 + 208 223 signed = dict(unsigned) 209 224 signed["sig"] = sig_b64u 210 225 211 226 did = derive_plc_did(signed) 212 227 228 + if args.verbose: 229 + signed_cbor = dag_cbor.encode(signed) 230 + digest = hashlib.sha256(signed_cbor).digest() 231 + print(f"[verbose] SHA256 of signed op: {digest.hex()}") 232 + 213 233 # Save artifacts 214 234 (outdir / "genesis_unsigned.dag-cbor").write_bytes(unsigned_cbor) 215 235 (outdir / "genesis_signed.json").write_text(json.dumps(signed, separators=(",", ":"), ensure_ascii=False) + "\n") 216 236 (outdir / "did.txt").write_text(did + "\n") 217 237 (outdir / "rotation_did_key.txt").write_text(kb.did_key + "\n") 218 238 239 + if args.verbose: 240 + print(f"[verbose] Wrote genesis_unsigned.dag-cbor ({len(unsigned_cbor)} bytes)") 241 + print(f"[verbose] Wrote genesis_signed.json") 242 + print(f"[verbose] Wrote did.txt") 243 + print(f"[verbose] Wrote rotation_did_key.txt") 244 + 219 245 print(f"Rotation key (did:key): {kb.did_key}") 220 246 print(f"DID (derived): {did}") 221 247 print(f"Wrote keys & artifacts to: {outdir.resolve()}") ··· 226 252 227 253 # Submit to PLC directory (HTTP POST JSON to .../{did}) 228 254 url = f"https://plc.directory/{did}" 255 + if args.verbose: 256 + print(f"[verbose] POSTing to {url}") 257 + print("[verbose] Request body:") 258 + print(json.dumps(signed, indent=2)) 259 + 229 260 try: 230 261 resp = requests.post(url, json=signed, timeout=10) 231 262 print(f"POST {url} -> {resp.status_code}")