@canvas-js/interfaces
This package exports TypeScript types for Canvas messages and other interfaces.
Table of Contents
Installation
npm i @canvas-js/chain-interfaces
API
Signatures
import type { CID } from "multiformats"
export type SignatureType = "ed25519" | "secp256k1"
export type Signature = {
type: SignatureType
publicKey: Uint8Array
signature: Uint8Array
cid: CID
}
Messages
export type Message<Payload = unknown> = {
topic: string
clock: number
parents: string[]
payload: Payload
}
Actions
export type Action = {
type: "action"
chain: string
address: string
name: string
args: any
timestamp: number
blockhash: string | null
}
Sessions
import type { SignatureType } from "./Signature.js"
export type Session<Data = any> = {
type: "session"
chain: string
address: string
publicKeyType: SignatureType
publicKey: Uint8Array
data: Data
timestamp: number
blockhash: string | null
duration: number | null
}
Message signers
export interface MessageSigner<Payload = unknown> {
sign: (message: Message<Payload>) => Signature
}
Session signers
import type { MessageSigner } from "./MessageSigner.js"
import type { Session } from "./Session.js"
import type { Action } from "./Action.js"
import type { Awaitable } from "./Awaitable.js"
export interface SessionSigner extends MessageSigner<Action | Session> {
match: (chain: string) => boolean
getSession: (topic: string, options?: { chain?: string; timestamp?: number }) => Awaitable<Session>
verifySession: (session: Session) => Awaitable<void>
}
Utility types
Awaitable
export type Awaitable<T> = T | Promise<T>