OrbisDB utilizes DIDs (link) for its account management. We managed to abstract all the complexities away and bundle it into a single method call.

Before using the methods, make sure to initialize (link) your OrbisDB SDK.

Authenticating users

Authentication is handled by OrbisAuthenticators which generate the DID session in did:pkh (OrbisEVMAuthOrbisSolanaAuthOrbisTezosAuth) and did:key (OrbisKeyDidAuth) formats.

EVM

import { OrbisDB } from "@useorbis/db-sdk"
import { OrbisEVMAuth } from "@useorbis/db-sdk/auth"

// Browser provider (ie. Metamask)
const provider = window.ethereum

// Orbis Authenticator
const auth = new OrbisEVMAuth(provider)

// Authenticate the user and persist the session in localStorage
const authResult: OrbisConnectResult = await orbis.connectUser({ auth })

// Log the result
console.log({ authResult })

Solana

import { OrbisDB } from "@useorbis/db-sdk"
import { OrbisSolanaAuth } from "@useorbis/db-sdk/auth"

// Browser provider (ie. Phantom)
const provider = window.solana

// Orbis Authenticator
const auth = new OrbisSolanaAuth(provider)

// Authenticate the user and persist the session in localStorage
const authResult: OrbisConnectResult = await orbis.connectUser({ auth })

// Log the result
console.log({ authResult })

KeyDID


import { OrbisDB } from "@useorbis/db-sdk"
import { OrbisKeyDidAuth } from "@useorbis/db-sdk/auth"

// Generate the seed or provide an existing one
const seed = await OrbisKeyDidAuth.generateSeed()

// Initiate the authenticator using the generated (or persisted) seed
const auth = await OrbisKeyDidAuth.fromSeed(seed)

// Authenticate the user and persist the session in localStorage
const authResult: OrbisConnectResult = await orbis.connectUser({ auth })

// Log the result
console.log({ authResult })

Sessions

OrbisDB Sessions are stored in localStorage and valid for up to 3 months. To bypass this behavior, you can pass an optional saveSession argument to connectUser.

Sessions are serializable and stored as a base64 encoded string.

Don’t persist the session

// ...
const authResult = await orbis.connectUser({ auth, saveSession: false })
// ...

Check if a user is connected

In case no active session is found, the method will check the localStorage for any persisted sessions

// Check if any user is connected
const connected: boolean = await orbis.isUserConnected()

// Check if a user with the specified wallet address is connected
const connected = await orbis.isUserConnected("0x00...")

Get the currently connected user

In case no active session is found, the method will check the localStorage for any persisted sessions