diff --git a/package.json b/package.json index 1975ac2..ef754fe 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,7 @@ "@atcute/lexicon-doc": "^2.0.4", "@atcute/lexicon-resolver": "^0.1.5", "@atcute/lexicons": "^1.2.5", + "@atcute/multibase": "^1.1.6", "@atcute/oauth-browser-client": "^2.0.1", "@atcute/repo": "^0.1.0", "@atcute/tangled": "^1.0.12", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 0a25433..cdeddc1 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -41,6 +41,9 @@ importers: '@atcute/lexicons': specifier: ^1.2.5 version: 1.2.5 + '@atcute/multibase': + specifier: ^1.1.6 + version: 1.1.6 '@atcute/oauth-browser-client': specifier: ^2.0.1 version: 2.0.1 diff --git a/src/utils/key.ts b/src/utils/key.ts new file mode 100644 index 0000000..edc37bb --- /dev/null +++ b/src/utils/key.ts @@ -0,0 +1,30 @@ +import { parseDidKey, parsePublicMultikey } from "@atcute/crypto"; +import { fromBase58Btc } from "@atcute/multibase"; + +export const detectKeyType = (key: string): string => { + try { + return parsePublicMultikey(key).type; + } catch (e) { + try { + const bytes = fromBase58Btc(key.startsWith("z") ? key.slice(1) : key); + if (bytes.length >= 2) { + const type = (bytes[0] << 8) | bytes[1]; + if (type === 0xed01) { + return "ed25519"; + } + } + } catch {} + return "unknown"; + } +}; + +export const detectDidKeyType = (key: string): string => { + try { + return parseDidKey(key).type; + } catch (e) { + if (key.startsWith("did:key:")) { + return detectKeyType(key.slice(8)); + } + return "unknown"; + } +}; diff --git a/src/views/repo.tsx b/src/views/repo.tsx index 48455ee..7f5ca5c 100644 --- a/src/views/repo.tsx +++ b/src/views/repo.tsx @@ -1,5 +1,4 @@ import { Client, CredentialManager } from "@atcute/client"; -import { parseDidKey, parsePublicMultikey } from "@atcute/crypto"; import { DidDocument } from "@atcute/identity"; import { ActorIdentifier, Did, Handle, Nsid } from "@atcute/lexicons"; import { A, useLocation, useNavigate, useParams } from "@solidjs/router"; @@ -39,6 +38,7 @@ import { resolvePDS, validateHandle, } from "../utils/api.js"; +import { detectDidKeyType, detectKeyType } from "../utils/key.js"; import { BlobView } from "./blob.jsx"; import { PlcLogView } from "./logs.jsx"; @@ -566,9 +566,7 @@ export const RepoView = () => { #{verif.id.split("#")[1]} - unknown}> - {parsePublicMultikey(key()).type} - + {detectKeyType(key())}
{key()}
@@ -592,7 +590,7 @@ export const RepoView = () => { {(key) => (
- {parseDidKey(key).type} + {detectDidKeyType(key)}
{key.replace("did:key:", "")}