UNPKG

@atproto/api

Version:

Client library for atproto and Bluesky

35 lines 1.07 kB
export function isAtprotoServiceType(input) { return !input.includes(' ') && !input.includes('#'); } export function isDid(input) { if (!input.startsWith('did:')) return false; if (input.length < 8) return false; if (input.length > 2048) return false; const msidx = input.indexOf(':', 4); return msidx > 4 && msidx < input.length - 1; } export function assertDid(input) { if (!isDid(input)) throw new TypeError(`Invalid DID: ${input}`); } export function asDid(input) { assertDid(input); return input; } export function isAtprotoProxy(input) { const { length, [0]: did, [1]: service } = input.split('#'); return length === 2 && isDid(did) && isAtprotoServiceType(service); } export function assertAtprotoProxy(input) { if (!isAtprotoProxy(input)) { throw new TypeError(`Invalid DID reference: ${input} (must be of the form did:example:alice#service)`); } } export function asAtprotoProxy(input) { assertAtprotoProxy(input); return input; } //# sourceMappingURL=types.js.map