Resolver
@twine-protocol/twine-core v0.1.0 • Docs
twine-js / @twine-protocol/twine-core / Resolver
Interface: Resolver
Resolves a query into a chain or pulse
Resolvers are the primary way to fetch twines from somewhere. This specifies a general interface for all resolvers.
Resolvers are expected to verify the signature of the resolved twine.
See
Example
import { collect } from '@twine-protocol/twine-core'
const resolver = new MyResolver()
const chains = await collect(resolver.chains())
// resolve the latest pulse of the first chain
const resolution = await resolver.resolveLatest({ chain: chains[0] })
if (resolution.pulse) {
// a verified pulse that is the latest this resolver knows of
console.log('pulse', resolution.pulse)
}Extended by
Methods
resolve()
resolve(query, options)
resolve(
query,options?):Promise<ChainResolution>
Resolve a chain from a query
This is the main way to get a pulse or chain from somewhere and have it automatically verified.
If the input is already a successful resolution, it will be returned as is.
If the input is a chain or pulse, it will be resolved as a chain or pulse resolution.
Parameters
Returns
Promise<ChainResolution>
A chain or pulse resolution
Examples
const { chain } = await resolver.resolve({ chain: 'bafybeib3...' })
if (chain) {
console.log('chain', chain)
} else {
console.log('no chain')
}const { chain, pulse } = await resolver.resolve({
chain: 'bafybeib3...',
pulse: 'bafybeib3...'
})
if (pulse) {
console.log('pulse', pulse)
} else {
console.log('no pulse')
}Defined in
packages/twine-core/src/resolver/types.ts:233
resolve(query, options)
resolve(
query,options?):Promise<PulseResolution>
Resolve a pulse (with its chain) from a query
Parameters
options?
Returns
Promise<PulseResolution>
Defined in
packages/twine-core/src/resolver/types.ts:237
resolveLatest()
resolveLatest(
chain,options?):Promise<PulseResolution>
Resolve the latest pulse of a chain
Parameters
Returns
Promise<PulseResolution>
A pulse resolution
Examples
const resolution = await resolver.resolveLatest('bafybeib3...')
if (resolution.pulse) {
console.log('pulse', resolution.pulse)
}const { chain } = await resolver.resolve({ chain: 'bafybeib3...' })
const resolution = await resolver.resolveLatest(chain)Defined in
packages/twine-core/src/resolver/types.ts:260
resolveIndex()
resolveIndex(
chain,index,options?):Promise<PulseResolution>
Resolve a pulse by index
Parameters
index
number
The index of the pulse to resolve
Returns
Promise<PulseResolution>
A pulse resolution
Example
const resolution = await resolver.resolveIndex('bafybeib3...', 42)
if (resolution.pulse) {
console.log('pulse', resolution.pulse)
}Defined in
packages/twine-core/src/resolver/types.ts:278
has()
has(
cid):Awaitable<boolean>
Check if a cid can be resolved
Parameters
Returns
Awaitable<boolean>
True if the CID can be resolved, false otherwise
Example
const exists = await resolver.has('bafybeib3...')
if (exists) {
console.log('chain exists')
} else {
console.log('chain does not exist')
}Defined in
packages/twine-core/src/resolver/types.ts:295
pulses()
pulses(
chain,start?,options?):AsyncGenerator<Pulse,any,any> |Generator<Pulse,any,any> |AnyIterable<Pulse>
Get the pulses of a chain
Parameters
Returns
AsyncGenerator<Pulse, any, any> | Generator<Pulse, any, any> | AnyIterable<Pulse>
An sync/async iterable of pulses
Example
// loop through pulses and print indices
for await (const pulse of resolver.pulses('bafybeib3...')) {
console.log('pulse', pulse.value.content.index)
}Defined in
packages/twine-core/src/resolver/types.ts:313
chains()
chains():
AsyncGenerator<Chain,any,any> |Generator<Chain,any,any> |AnyIterable<Chain>
Get the chains that are known to the resolver
Returns
AsyncGenerator<Chain, any, any> | Generator<Chain, any, any> | AnyIterable<Chain>
An sync/async iterable of chains
Example
const chains = await collect(resolver.chains())Defined in
Last updated