@atproto/did
Version:
DID resolution and verification library
30 lines • 1.06 kB
JavaScript
import { isDid } from './did.js';
import { isFragment } from './lib/uri.js';
export const isDidRefAbsolute = (value) => {
if (typeof value !== 'string')
return false;
const hashIndex = value.indexOf('#');
if (hashIndex === -1)
return false; // no '#'
if (hashIndex === value.length - 1)
return false; // empty fragment
if (value.includes('#', hashIndex + 1))
return false; // more than one '#'
return isFragment(value, hashIndex + 1) && isDid(value.slice(0, hashIndex));
};
export function isDidRefRelative(value, id) {
if (typeof value !== 'string')
return false;
if (value.charCodeAt(0) !== 35 /* '#' */)
return false; // doesn't start with '#'
if (value.length < 2)
return false; // empty fragment
if (value.includes('#', 1))
return false; // more than one '#'
if (!isFragment(value, 1))
return false;
if (id !== undefined && value !== `#${id}`)
return false; // id mismatch
return true;
}
//# sourceMappingURL=did-ref.js.map