atmosphere explorer

add ed25519 key detection

handle.invalid a5a8a76e d813d590

verified
+37 -5
+1
package.json
··· 32 32 "@atcute/lexicon-doc": "^2.0.4", 33 33 "@atcute/lexicon-resolver": "^0.1.5", 34 34 "@atcute/lexicons": "^1.2.5", 35 + "@atcute/multibase": "^1.1.6", 35 36 "@atcute/oauth-browser-client": "^2.0.1", 36 37 "@atcute/repo": "^0.1.0", 37 38 "@atcute/tangled": "^1.0.12",
+3
pnpm-lock.yaml
··· 41 41 '@atcute/lexicons': 42 42 specifier: ^1.2.5 43 43 version: 1.2.5 44 + '@atcute/multibase': 45 + specifier: ^1.1.6 46 + version: 1.1.6 44 47 '@atcute/oauth-browser-client': 45 48 specifier: ^2.0.1 46 49 version: 2.0.1
+30
src/utils/key.ts
··· 1 + import { parseDidKey, parsePublicMultikey } from "@atcute/crypto"; 2 + import { fromBase58Btc } from "@atcute/multibase"; 3 + 4 + export const detectKeyType = (key: string): string => { 5 + try { 6 + return parsePublicMultikey(key).type; 7 + } catch (e) { 8 + try { 9 + const bytes = fromBase58Btc(key.startsWith("z") ? key.slice(1) : key); 10 + if (bytes.length >= 2) { 11 + const type = (bytes[0] << 8) | bytes[1]; 12 + if (type === 0xed01) { 13 + return "ed25519"; 14 + } 15 + } 16 + } catch {} 17 + return "unknown"; 18 + } 19 + }; 20 + 21 + export const detectDidKeyType = (key: string): string => { 22 + try { 23 + return parseDidKey(key).type; 24 + } catch (e) { 25 + if (key.startsWith("did:key:")) { 26 + return detectKeyType(key.slice(8)); 27 + } 28 + return "unknown"; 29 + } 30 + };
+3 -5
src/views/repo.tsx
··· 1 1 import { Client, CredentialManager } from "@atcute/client"; 2 - import { parseDidKey, parsePublicMultikey } from "@atcute/crypto"; 3 2 import { DidDocument } from "@atcute/identity"; 4 3 import { ActorIdentifier, Did, Handle, Nsid } from "@atcute/lexicons"; 5 4 import { A, useLocation, useNavigate, useParams } from "@solidjs/router"; ··· 39 38 resolvePDS, 40 39 validateHandle, 41 40 } from "../utils/api.js"; 41 + import { detectDidKeyType, detectKeyType } from "../utils/key.js"; 42 42 import { BlobView } from "./blob.jsx"; 43 43 import { PlcLogView } from "./logs.jsx"; 44 44 ··· 566 566 #{verif.id.split("#")[1]} 567 567 </span> 568 568 <span class="rounded bg-neutral-200 px-1 py-0.5 text-xs text-neutral-800 dark:bg-neutral-700 dark:text-neutral-300"> 569 - <ErrorBoundary fallback={<>unknown</>}> 570 - {parsePublicMultikey(key()).type} 571 - </ErrorBoundary> 569 + {detectKeyType(key())} 572 570 </span> 573 571 </div> 574 572 <div class="font-mono break-all">{key()}</div> ··· 592 590 {(key) => ( 593 591 <div class="text-sm"> 594 592 <span class="rounded bg-neutral-200 px-1 py-0.5 text-xs text-neutral-800 dark:bg-neutral-700 dark:text-neutral-300"> 595 - {parseDidKey(key).type} 593 + {detectDidKeyType(key)} 596 594 </span> 597 595 <div class="font-mono break-all">{key.replace("did:key:", "")}</div> 598 596 </div>