feat: add publish_https & resolve_https

Adds publish_https & resolve_https methods.
Updates examples in README.md.
Bump package version to 0.5.0.
This commit is contained in:
coreyphillips
2024-09-27 10:48:27 -04:00
parent f347ee9ad4
commit f047526748
22 changed files with 469 additions and 49 deletions

View File

@@ -82,11 +82,13 @@ interface ITxt {
ttl: number;
}
interface IDNSPacket {
dns_packet: string;
signed_packet: string;
public_key: string;
records: ITxt[];
signature: string;
timestamp: number;
last_seen: number;
dns_packet: string;
records: ITxt[];
}
export async function resolve(publicKey: string): Promise<Result<IDNSPacket>> {
try {
@@ -165,3 +167,48 @@ export async function put(
return err(JSON.stringify(e));
}
}
export async function publishHttps(
recordName: string,
target: string,
secretKey: string
): Promise<Result<string[]>> {
try {
const res = await Pubky.publishHttps(recordName, target, secretKey);
if (res[0] === 'error') {
return err(res[1]);
}
return ok(res[1]);
} catch (e) {
return err(JSON.stringify(e));
}
}
interface IHttpsRecord {
name: string;
class: string;
ttl: number;
priority: number;
target: string;
port?: number;
alpn?: string[];
}
interface IHttpsResolveResult {
public_key: string;
https_records: IHttpsRecord[];
}
export async function resolveHttps(
publicKey: string
): Promise<Result<IHttpsResolveResult>> {
try {
const res = await Pubky.resolveHttps(publicKey);
if (res[0] === 'error') {
return err(res[1]);
}
return ok(JSON.parse(res[1]));
} catch (e) {
return err(JSON.stringify(e));
}
}