bundle shedding: drop atcute/identity-resolver hard dep
we still dynamically import the web did doc resolver if we need to resolve a did:web: but since it's an async import it should get codesplit on the client side
This commit is contained in:
parent
dbf653e7cd
commit
deb0e7302c
3 changed files with 28 additions and 22 deletions
|
|
@ -21,7 +21,7 @@ const fetchVideoRecord = async (
|
||||||
|
|
||||||
const xrpc = new XRPC<ATProtoUniverse>(pds);
|
const xrpc = new XRPC<ATProtoUniverse>(pds);
|
||||||
const record = await xrpc.get("com.atproto.repo.getRecord", {
|
const record = await xrpc.get("com.atproto.repo.getRecord", {
|
||||||
parameters: {
|
params: {
|
||||||
collection: "blue.cerulea.video.video",
|
collection: "blue.cerulea.video.video",
|
||||||
repo: did,
|
repo: did,
|
||||||
rkey,
|
rkey,
|
||||||
|
|
|
||||||
|
|
@ -1,26 +1,32 @@
|
||||||
import type { DidDocument } from "@atcute/identity";
|
import type { DidDocument } from "@atcute/identity";
|
||||||
import {
|
import type { WebDidDocumentResolver } from "@atcute/identity-resolver";
|
||||||
CompositeDidDocumentResolver,
|
import type { ATProtoUniverse } from "@char/lexicon.ts/atproto";
|
||||||
PlcDidDocumentResolver,
|
import { XRPC } from "@char/lexicon.ts/rpc";
|
||||||
WebDidDocumentResolver,
|
|
||||||
XrpcHandleResolver,
|
|
||||||
} from "@atcute/identity-resolver";
|
|
||||||
|
|
||||||
const handleResolver = new XrpcHandleResolver({
|
const bskyPublic = new XRPC<ATProtoUniverse>("https://public.api.bsky.app");
|
||||||
serviceUrl: "https://public.api.bsky.app",
|
|
||||||
});
|
|
||||||
|
|
||||||
const didResolver = new CompositeDidDocumentResolver({
|
export async function resolveHandle(handle: string): Promise<`did:${string}`> {
|
||||||
methods: {
|
const { did } = await bskyPublic.get("com.atproto.identity.resolveHandle", {
|
||||||
plc: new PlcDidDocumentResolver(),
|
params: { handle },
|
||||||
web: new WebDidDocumentResolver(),
|
});
|
||||||
},
|
return did;
|
||||||
});
|
|
||||||
|
|
||||||
export function resolveHandle(handle: string): Promise<`did:${string}`> {
|
|
||||||
return handleResolver.resolve(handle as `${string}.${string}`);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function resolveDid(did: string): Promise<DidDocument> {
|
export async function resolveDid(did: string): Promise<DidDocument> {
|
||||||
return didResolver.resolve(did as `did:${"plc" | "web"}:${string}`);
|
if (did.startsWith("did:plc:")) {
|
||||||
|
const doc = await fetch("https://plc.directory/" + did).then((r) =>
|
||||||
|
r.json()
|
||||||
|
);
|
||||||
|
return doc;
|
||||||
|
} else if (did.startsWith("did:web:")) {
|
||||||
|
// TODO: write our own did:web resolver (maybe use a CORS proxy on clientside)
|
||||||
|
const resolver: WebDidDocumentResolver = await import(
|
||||||
|
"@atcute/identity-resolver"
|
||||||
|
)
|
||||||
|
.then((m) => m.WebDidDocumentResolver)
|
||||||
|
.then((r) => new r());
|
||||||
|
return resolver.resolve(did as `did:web:${string}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
throw new Error("unsupported did type: " + did);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
2
vendor/lexicon.ts
vendored
2
vendor/lexicon.ts
vendored
|
|
@ -1 +1 @@
|
||||||
Subproject commit 1edb68e5eac3ddfabdd77674ed8193ef9af05649
|
Subproject commit 4b3c48591c21d976ab94d0ae6cf2160a2115471c
|
||||||
Loading…
Reference in a new issue