feat: implement parseAuthUrl

Adds & Implements parseAuthUrl.
Updates README.md.
Bumps version to 0.2.0.
This commit is contained in:
coreyphillips
2024-09-15 21:17:10 -04:00
parent b5185fe7ba
commit c2a699d2d2
19 changed files with 221 additions and 41 deletions

View File

@@ -28,3 +28,29 @@ export async function auth(
}
return ok(res[1]);
}
type Capability = {
path: string;
permission: string;
};
type PubkyAuthDetails = {
relay: string;
capabilities: Capability[];
secret: string;
};
export async function parseAuthUrl(
url: string
): Promise<Result<PubkyAuthDetails>> {
try {
const res = await Pubky.parseAuthUrl(url);
if (res[0] === 'error') {
return err(res[1]);
}
const parsed = JSON.parse(res[1]);
return ok(parsed);
} catch (e) {
return err(JSON.stringify(e));
}
}