Options
All
  • Public
  • Public/Protected
  • All
Menu

Module @ceramicnetwork/core

Ceramic Core

This package contains the implementation of the core Ceramic protocol. It's exposed using a simple JavaScript API.

Getting started

Installation

$ npm install @ceramicnetwork/core

Usage

import Ceramic from '@ceramicnetwork/core'
import TileDocument from '@ceramicnetwork/stream-tile'

import IPFS from 'ipfs-core'
import dagJose from 'dag-jose'
import { convert } from 'blockcodec-to-ipld-format'

const format = convert(dagJose)

const ipfs = Ipfs.create({
    ipld: { formats: [format] },
})

const config: CeramicConfig = {}
const ceramic = await Ceramic.create(ipfs, config)

// create document example
const tileDocument = await TileDocument.create(ceramic, { test: 123 })

Ceramic API

Complete Ceramic core API is available on Ceramic API.

Development

Run tests:

$ npm test

Run linter:

npm run lint

Contributing

We are happy to accept small and large contributions. Make sure to check out the Ceramic specifications for details of how the protocol works.

License

Index

References

Enumerations

Classes

Interfaces

Type aliases

Variables

Functions

Object literals

References

Ceramic

Re-exports Ceramic

CeramicConfig

Re-exports CeramicConfig

CeramicModules

Re-exports CeramicModules

CeramicParameters

Re-exports CeramicParameters

StateStore

Re-exports StateStore

Type aliases

IPFSPubsubMessage

IPFSPubsubMessage: { data: Uint8Array; from: string; key: Uint8Array; seqno: Uint8Array; signature: Uint8Array; topicIDs: string[] }

Type declaration

  • data: Uint8Array
  • from: string
  • key: Uint8Array
  • seqno: Uint8Array
  • signature: Uint8Array
  • topicIDs: string[]

KeepaliveMessage

KeepaliveMessage: { ts: number; typ: KEEPALIVE }

Type declaration

LoadDocumentFunc

LoadDocumentFunc: <T>(streamId: CommitID) => Promise<T>

Type declaration

    • <T>(streamId: CommitID): Promise<T>
    • Type parameters

      • T: Stream

      Parameters

      • streamId: CommitID

      Returns Promise<T>

ObservableWithNext

ObservableWithNext<T>: Observable<T> & { next: (m: T) => Subscription }

An extension of Observable that also has a 'next' method which can be used to publish new events into the Observable stream.

Type parameters

  • T

Props

Props: { networkName?: string; pinningBackends?: PinningBackendStatic[]; pinningEndpoints?: string[]; stateStoreDirectory?: string }

Type declaration

  • Optional networkName?: string
  • Optional pinningBackends?: PinningBackendStatic[]
  • Optional pinningEndpoints?: string[]
  • Optional stateStoreDirectory?: string

PubsubMessage

QueryMessage

QueryMessage: { id: string; stream: StreamID; typ: QUERY }

Type declaration

  • id: string
  • stream: StreamID
  • typ: QUERY

Registry

Registry: Map<number, StreamHandler<Stream>>

RepositoryDependencies

RepositoryDependencies: { anchorService: AnchorService; conflictResolution: ConflictResolution; context: Context; dispatcher: Dispatcher; handlers: HandlersMap; pinStore: PinStore; stateValidation: StateValidation }

Type declaration

ResponseMessage

ResponseMessage: { id: string; tips: Map<string, CID>; typ: RESPONSE }

Type declaration

  • id: string
  • tips: Map<string, CID>
  • typ: RESPONSE

Task

Task<TaskResultType>: () => Promise<TaskResultType>

Type parameters

  • TaskResultType

Type declaration

    • (): Promise<TaskResultType>
    • Returns Promise<TaskResultType>

UpdateMessage

UpdateMessage: { stream: StreamID; tip: CID; typ: UPDATE }

Type declaration

  • stream: StreamID
  • tip: CID
  • typ: UPDATE

Variables

Const APPLY_ANCHOR_COMMIT_ATTEMPTS

APPLY_ANCHOR_COMMIT_ATTEMPTS: 3 = 3

Const BASE_CHAIN_ID

BASE_CHAIN_ID: "eip155" = "eip155"

Const CHAIN_ID

CHAIN_ID: "inmemory:12345" = "inmemory:12345"

Const DEFAULT_CACHE_LIMIT

DEFAULT_CACHE_LIMIT: 500 = 500

Const DEFAULT_LOCAL_ETHEREUM_RPC

DEFAULT_LOCAL_ETHEREUM_RPC: "http://localhost:7545" = "http://localhost:7545"

Const DEFAULT_NETWORK

DEFAULT_NETWORK: INMEMORY = Networks.INMEMORY

Const DEFAULT_STATE_STORE_DIRECTORY

DEFAULT_STATE_STORE_DIRECTORY: string = path.join(os.homedir(), '.ceramic', 'statestore')

Const DID_MATCHER

DID_MATCHER: "^(did:([a-zA-Z0-9_]+):([a-zA-Z0-9_.-]+(:[a-zA-Z0-9_.-]+)*)((;[a-zA-Z0-9_.:%-]+=[a-zA-Z0-9_.:%-]*)*)(/[^#?]*)?)([?][^#]*)?(#.*)?" = "^(did:([a-zA-Z0-9_]+):([a-zA-Z0-9_.-]+(:[a-zA-Z0-9_.-]+)*)((;[a-zA-Z0-9_.:%-]+=[a-zA-Z0-9_.:%-]*)*)(/[^#?]*)?)([?][^#]*)?(#.*)?"

Const IPFS_CACHE_SIZE

IPFS_CACHE_SIZE: 1024 = 1024

Const IPFS_GET_RETRIES

IPFS_GET_RETRIES: 3 = 3

Const IPFS_GET_TIMEOUT

IPFS_GET_TIMEOUT: 30000 = 30000

Const IPFS_GET_TIMEOUT

IPFS_GET_TIMEOUT: 60000 = 60000

Const IPFS_GET_TIMEOUT

IPFS_GET_TIMEOUT: 60000 = 60000

Const IPFS_MAX_COMMIT_SIZE

IPFS_MAX_COMMIT_SIZE: 256000 = 256000

Const IPFS_RESUBSCRIBE_INTERVAL_DELAY

IPFS_RESUBSCRIBE_INTERVAL_DELAY: number = 1000 * 15

Const MAX_POLL_TIME

MAX_POLL_TIME: 86400000 = 86400000

Const MAX_PROVIDERS_COUNT

MAX_PROVIDERS_COUNT: 100 = 100

Const MAX_PUBSUB_PUBLISH_INTERVAL

MAX_PUBSUB_PUBLISH_INTERVAL: number = 60 * 1000

Const MAX_QUERIES_PER_SECOND

MAX_QUERIES_PER_SECOND: 10 = 10

Const MAX_QUEUED_QUERIES

MAX_QUEUED_QUERIES: 100 = 100

Const MAX_RESPONSE_INTERVAL

MAX_RESPONSE_INTERVAL: 300 = 300

Const POLL_INTERVAL

POLL_INTERVAL: 60000 = 60000

Const SAMPLE_ETH_TX_HASH

SAMPLE_ETH_TX_HASH: "bagjqcgzaday6dzalvmy5ady2m5a5legq5zrbsnlxfc2bfxej532ds7htpova" = "bagjqcgzaday6dzalvmy5ady2m5a5legq5zrbsnlxfc2bfxej532ds7htpova"

Const TESTING

TESTING: boolean = process.env.NODE_ENV == 'test'

Const TRAILING_SLASH

TRAILING_SLASH: RegExp = /\/$/

Const textDecoder

textDecoder: TextDecoder = new TextDecoder('utf-8')

Const textDecoder

textDecoder: TextDecoder = new TextDecoder('utf-8')

Const textEncoder

textEncoder: TextEncoder = new TextEncoder()

Functions

anchorUpdate

  • anchorUpdate(ceramic: Ceramic, stream: Stream): Promise<void>

asIpfsMessage

betweenTimeout

  • betweenTimeout<T>(betweenMs: number): UnaryFunction<Observable<T>, Observable<T>>
  • Stop emitting if +betweenMs+ passed since the last emitted value.

    Type parameters

    • T

    Parameters

    • betweenMs: number

      max interval between the sequential values.

    Returns UnaryFunction<Observable<T>, Observable<T>>

buildQueryMessage

buildResubscribeQueue

  • buildResubscribeQueue(logger: DiagnosticsLogger): TaskQueue

commitAtTime

  • commitAtTime(stateHolder: StreamStateHolder, timestamp: number): CommitID

createCeramic

createIPFS

  • createIPFS(overrideConfig?: Record<string, unknown>): Promise<IpfsApi>

defaultHandlers

delay

  • delay(ms: number): Promise<void>

deserialize

filterExternal

  • filterExternal(ownPeerId$: Observable<string>): MonoTypeOperatorFunction<IPFSPubsubMessage>

fleet

  • fleet(n: number, overrideConfig?: Record<string, unknown>): Promise<IpfsApi[]>
  • Instantiate a number of IPFS instances

    Parameters

    • n: number

      number of ipfs instances

    • Default value overrideConfig: Record<string, unknown> = {}

      IPFS config for override

    Returns Promise<IpfsApi[]>

ipfsToPubsub

  • ipfsToPubsub(peerId$: Observable<string>, pubsubLogger: ServiceLogger, topic: string): UnaryFunction<Observable<IPFSPubsubMessage>, Observable<PubsubMessage>>
  • Deserialize incoming message in an internal observable that does not emit if error happens. Log a successfully deserialized message.

    Parameters

    • peerId$: Observable<string>

      own IPFS node peer id

    • pubsubLogger: ServiceLogger

      logger that dumps a successfully deserialized message

    • topic: string

      IPFS pubsub topic we listen

    Returns UnaryFunction<Observable<IPFSPubsubMessage>, Observable<PubsubMessage>>

messageHash

  • messageHash(message: any): string

messageTypeToString

  • messageTypeToString(type: MsgType): string

Const noop

  • noop(): void

Const normalizeStreamID

  • normalizeStreamID(streamId: StreamID | string): StreamID

pickLogToAccept

  • pickLogToAccept(state1: StreamState, state2: StreamState): Promise<StreamState>
  • Given two different StreamStates representing two different conflicting histories of the same stream, pick which commit to accept, in accordance with our conflict resolution strategy

    Parameters

    • state1: StreamState

      first log's state

    • state2: StreamState

      second log's state

    Returns Promise<StreamState>

    the StreamState containing the log that is selected

Const promiseTimeout

  • promiseTimeout(ms: number, promise: Promise<any>): Promise<any>

serialize

streamFromState

  • streamFromState<T>(context: Context, handlersMap: HandlersMap, state: StreamState, update$?: (init: StreamState) => Observable<StreamState>): T
  • Build Stream from the current state and update feed.

    Type parameters

    • T: Stream

    Parameters

    • context: Context

      Ceramic context

    • handlersMap: HandlersMap

      available stream handlers

    • state: StreamState

      current state of the stream

    • Optional update$: (init: StreamState) => Observable<StreamState>

      On-demand feed of updates for the stream. If not provided then the returned Stream object is marked read-only and cannot be used to update the stream.

        • (init: StreamState): Observable<StreamState>
        • Parameters

          • init: StreamState

          Returns Observable<StreamState>

    Returns T

swarmConnect

Const tryStreamId

  • tryStreamId(id: string): StreamID | null

verifyAnchorCommit

  • verifyAnchorCommit(dispatcher: Dispatcher, anchorValidator: AnchorValidator, commitData: CommitData): Promise<AnchorProof>
  • Verifies anchor commit structure

    Parameters

    • dispatcher: Dispatcher

      To get raw blob from IPFS

    • anchorValidator: AnchorValidator

      AnchorValidator to verify chain inclusion

    • commitData: CommitData

      Anchor commit data

    Returns Promise<AnchorProof>

withFleet

  • withFleet(n: number, task: (instances: IpfsApi[]) => Promise<void>): Promise<void>
  • Start n IPFS instances, and stop them after task is done.

    Parameters

    • n: number

      Number of IPFS instances to create.

    • task: (instances: IpfsApi[]) => Promise<void>

      Function that uses the IPFS instances.

        • (instances: IpfsApi[]): Promise<void>
        • Parameters

          Returns Promise<void>

    Returns Promise<void>

Object literals

Const DEFAULT_ANCHOR_SERVICE_URLS

DEFAULT_ANCHOR_SERVICE_URLS: object

[Networks.DEV_UNSTABLE]

[Networks.DEV_UNSTABLE]: string = "https://cas-dev.3boxlabs.com"

[Networks.ELP]

[Networks.ELP]: string = "https://cas.3boxlabs.com"

[Networks.LOCAL]

[Networks.LOCAL]: string = "http://localhost:8081"

[Networks.MAINNET]

[Networks.MAINNET]: string = "https://cas.3boxlabs.com"

[Networks.TESTNET_CLAY]

[Networks.TESTNET_CLAY]: string = "https://cas-clay.3boxlabs.com"

Const DEFAULT_APPLY_COMMIT_OPTS

DEFAULT_APPLY_COMMIT_OPTS: object

anchor

anchor: boolean = true

publish

publish: boolean = true

sync

sync: SyncOptions = SyncOptions.PREFER_CACHE

Const DEFAULT_CREATE_FROM_GENESIS_OPTS

DEFAULT_CREATE_FROM_GENESIS_OPTS: object

anchor

anchor: boolean = true

publish

publish: boolean = true

sync

sync: SyncOptions = SyncOptions.PREFER_CACHE

Const DEFAULT_LOAD_OPTS

DEFAULT_LOAD_OPTS: object

sync

sync: SyncOptions = SyncOptions.PREFER_CACHE

syncTimeoutSeconds

syncTimeoutSeconds: number = 3

Const DEFAULT_LOAD_OPTS

DEFAULT_LOAD_OPTS: object

sync

sync: SyncOptions = SyncOptions.PREFER_CACHE

Const ETH_CHAIN_ID_MAPPINGS

ETH_CHAIN_ID_MAPPINGS: object

Maps some of Ethereum chain IDs to network configuration

eip155:1

eip155:1: object

chain

chain: string = "ETH"

chainId

chainId: number = 1

network

network: string = "mainnet"

networkId

networkId: number = 1

type

type: string = "Production"

eip155:3

eip155:3: object

chain

chain: string = "ETH"

chainId

chainId: number = 3

network

network: string = "ropsten"

networkId

networkId: number = 3

type

type: string = "Test"

eip155:4

eip155:4: object

chain

chain: string = "ETH"

chainId

chainId: number = 4

network

network: string = "rinkeby"

networkId

networkId: number = 4

type

type: string = "Test"

Const SUPPORTED_CHAINS_BY_NETWORK

SUPPORTED_CHAINS_BY_NETWORK: object

[Networks.DEV_UNSTABLE]

[Networks.DEV_UNSTABLE]: string[] = ['eip155:3', 'eip155:4']

[Networks.ELP]

[Networks.ELP]: string[] = ['eip155:1']

[Networks.INMEMORY]

[Networks.INMEMORY]: string[] = ['inmemory:12345']

[Networks.LOCAL]

[Networks.LOCAL]: string[] = ['eip155:1337']

[Networks.MAINNET]

[Networks.MAINNET]: string[] = ['eip155:1']

[Networks.TESTNET_CLAY]

[Networks.TESTNET_CLAY]: string[] = ['eip155:3', 'eip155:4']