accesscontrollers

package
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 29, 2026 License: MIT Imports: 14 Imported by: 0

Documentation

Overview

Package accesscontrollers decides who may write to a database.

It mirrors src/access-controllers in @orbitdb/core 4. An access controller has an address that goes into the database manifest, so every peer that opens the database enforces the same rules:

  • "ipfs": an immutable write list stored as an IPFS block, /ipfs/<hash> of {type: "ipfs", write: [...]}. "*" lets anyone write.
  • "orbitdb": a mutable list kept in a KeyValue database of its own, whose admins can grant and revoke write access.

Index

Constants

View Source
const (
	CapabilityWrite = "write"
	CapabilityAdmin = "admin"
)

Capabilities of an OrbitDB access controller.

View Source
const IPFSType = "ipfs"

IPFSType is the type of IPFS access controllers.

View Source
const OrbitDBType = "orbitdb"

OrbitDBType is the type of OrbitDB access controllers.

Variables

This section is empty.

Functions

func TypeOf

func TypeOf(address string) string

TypeOf returns the type part of an access controller address, e.g. "ipfs" for "/ipfs/zdpu...".

func UseAccessController

func UseAccessController(typ string, f Factory) error

UseAccessController registers the factory used to load access controllers of type typ from a manifest.

Types

type AccessController

type AccessController interface {
	oplog.AccessController
	// Type is the access controller type, e.g. "ipfs".
	Type() string
	// Address is stored in the database manifest.
	Address() string
}

AccessController is an oplog.AccessController with an address.

type Factory

type Factory func(ctx context.Context, p Params) (AccessController, error)

Factory creates a new access controller, or loads the one at Params.Address.

func GetAccessController

func GetAccessController(typ string) (Factory, error)

GetAccessController returns the factory registered for typ.

func IPFS

func IPFS(opts IPFSOptions) Factory

IPFS returns a factory for IPFS access controllers.

func OrbitDB

func OrbitDB(opts OrbitDBOptions) Factory

OrbitDB returns a factory for OrbitDB access controllers.

type IPFSAccessController

type IPFSAccessController struct {
	// contains filtered or unexported fields
}

IPFSAccessController allows a fixed list of writers.

func (*IPFSAccessController) Address

func (a *IPFSAccessController) Address() string

Address implements AccessController.

func (*IPFSAccessController) CanAppend

func (a *IPFSAccessController) CanAppend(ctx context.Context, entry *oplog.Entry) (bool, error)

CanAppend implements oplog.AccessController.

func (*IPFSAccessController) Type

func (*IPFSAccessController) Type() string

Type implements AccessController.

func (*IPFSAccessController) Write

func (a *IPFSAccessController) Write() []string

Write returns the writers.

type IPFSOptions

type IPFSOptions struct {
	// Write lists the identity ids allowed to write; "*" allows anyone.
	// Defaults to the local identity.
	Write []string
	// Storage holds the access controller block. Defaults to an LRU cache
	// over the IPFS node's block storage.
	Storage storage.Storage
}

IPFSOptions configures IPFS.

type OrbitDBAccessController

type OrbitDBAccessController struct {
	// contains filtered or unexported fields
}

OrbitDBAccessController keeps capabilities (lists of identity ids per capability) in a KeyValue database, so they can change over time. Grants and revocations are writes to that database, so only its writers (the Write list it was created with) can make them.

func (*OrbitDBAccessController) Address

func (a *OrbitDBAccessController) Address() string

Address implements AccessController. It is the address of the capabilities database.

func (*OrbitDBAccessController) CanAppend

func (a *OrbitDBAccessController) CanAppend(ctx context.Context, entry *oplog.Entry) (bool, error)

CanAppend implements oplog.AccessController: writers and admins may write.

func (*OrbitDBAccessController) Capabilities

func (a *OrbitDBAccessController) Capabilities(ctx context.Context) (map[string][]string, error)

Capabilities returns every capability and the ids that have it. The writers of the capabilities database are always admins.

func (*OrbitDBAccessController) Close

func (a *OrbitDBAccessController) Close() error

Close closes the capabilities database.

func (*OrbitDBAccessController) Database

Database returns the KeyValue database holding the capabilities.

func (*OrbitDBAccessController) Drop

Drop drops the capabilities database.

func (*OrbitDBAccessController) Events

Events returns the event emitter of the capabilities database.

func (*OrbitDBAccessController) Get

func (a *OrbitDBAccessController) Get(ctx context.Context, capability string) ([]string, error)

Get returns the ids with capability.

func (*OrbitDBAccessController) Grant

func (a *OrbitDBAccessController) Grant(ctx context.Context, capability, id string) error

Grant gives id capability.

func (*OrbitDBAccessController) HasCapability

func (a *OrbitDBAccessController) HasCapability(ctx context.Context, capability, id string) (bool, error)

HasCapability reports whether id (or "*") has capability.

func (*OrbitDBAccessController) Revoke

func (a *OrbitDBAccessController) Revoke(ctx context.Context, capability, id string) error

Revoke removes capability from id.

func (*OrbitDBAccessController) Type

Type implements AccessController.

type OrbitDBOptions

type OrbitDBOptions struct {
	// Write lists the identity ids that administer the list; they may also
	// write. Defaults to the local identity.
	Write []string
}

OrbitDBOptions configures OrbitDB.

type Params

type Params struct {
	// Identity is the local identity, the default sole writer.
	Identity *identitytypes.Identity
	// Identities resolves and verifies writer identities.
	Identities *identities.Identities
	// IPFS stores access controller blocks.
	IPFS *ipfs.Node
	// Address is set when opening an existing database: the access
	// controller address from its manifest.
	Address string
	// Name is the database name when creating a database.
	Name string
	// OpenKeyValue opens a KeyValue database whose writes are controlled
	// by access. The "orbitdb" access controller stores its list in one.
	OpenKeyValue func(ctx context.Context, address string, access Factory) (*databases.KeyValue, error)
}

Params is what a Factory gets from OrbitDB.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL