* lexicon: doc validation compatibility with published lexicons * lexicon-resolver: setup new package * lexicon-resolver: implement record resolution * lexicon-resolver: implement lexicon resolution * lexicon-resolver: test record resolution * repo: add option to verify CIDs found in CARs. tidy. * lexicon-resolution: verify CIDs in proof CAR * lexicon-resolution: tests and fixes * tidy * lexicon-resolution: add entrypoint * lexicon-resolver: tidy errors * lexicon-resolver: readme * lexicon-resolver: changeset * prettier * eslint * tidy * tidy * tidy * enable CID-to-content verification within CARs by default * lexicon-resolver: tidy types, application of defaults, gitattributes * lexicon-resolver: add interface and builder fn for lexicon and record resolvers * lexicon-resolver: update readme * tidy * lexicon-resolver: cover error cases in record resolution --------- Co-authored-by: Matthieu Sieben <matthieu.sieben@gmail.com>
3.1 KiB
@atproto/lexicon-resolver
ATProto Lexicon resolution
Usage
This package may be used to determine the DID authority for a Lexicon based on its NSID, and to resolve a Lexicon from its NSID based on Lexicon Resolution from the network. Resolutions always verify the inclusion proof for the Lexicon schema document published to the ATProto network.
import {
resolveLexicon,
resolveLexiconDidAuthority,
} from '@atproto/lexicon-resolver'
// Which DID is the authority over this Lexicon?
const didAuthority = await resolveLexiconDidAuthority('app.bsky.feed.post')
// Resolve the Lexicon document with resolution details
const resolved = await resolveLexicon('app.bsky.feed.post')
/**
* {
* commit: {
* did: 'did:plc:4v4y5r3lwsbtmsxhile2ljac',
* rev: '3lnlpukgipj2c',
* sig: Uint8Array(64),
* ...
* },
* uri: AtUri(at://did:plc:4v4y5r3lwsbtmsxhile2ljac/com.atproto.lexicon.schema/app.bsky.feed.post),
* cid: CID(bafyreidgbehqwweghrrddfu6jgj7lyr6fwhzgazhirnszdb5lvr7iynkiy),
* nsid: NSID('app.bsky.feed.post'),
* lexicon: {
* '$type': 'com.atproto.lexicon.schema',
* lexicon: 1
* id: 'app.bsky.feed.post',
* defs: { main: [Object], ... },
* }
* }
*/
With identity caching
Identity data is used in order to fetch and verify record contents. The @atproto/identity package can be used to offer more control over caching and other behaviors of identity lookups.
import { IdResolver, MemoryCache } from '@atproto/identity'
import { buildLexiconResolver } from '@atproto/lexicon-resolver'
const resolveLexicon = buildLexiconResolver({
idResolver: new IdResolver({
didCache: new MemoryCache(),
}),
})
const resolved = await resolveLexicon('app.bsky.feed.post')
With DID authority override
You may specify a specific DID authority you'd like to use to perform a Lexicon resolution, overriding ATProto's DNS-based authority over Lexicons. This is described in some more detail in Authority and Control.
import { resolveLexicon } from '@atproto/lexicon-resolver'
const resolved = await resolveLexicon('app.bsky.feed.post', {
didAuthority: 'did:plc:...',
})
License
This project is dual-licensed under MIT and Apache 2.0 terms:
- MIT license (LICENSE-MIT.txt or http://opensource.org/licenses/MIT)
- Apache License, Version 2.0, (LICENSE-APACHE.txt or http://www.apache.org/licenses/LICENSE-2.0)
Downstream projects and end users may chose either license individually, or both together, at their discretion. The motivation for this dual-licensing is the additional software patent assurance provided by Apache 2.0.