@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 Signature = {
publicKey: string
signature: Uint8Array
cid: CID
}
Signers
import type { Signature } from "./Signature.js"
export interface Signer<T = any> {
sign(value: T): Signature
}
Messages
export type Message<Payload = unknown> = {
topic: string
clock: number
parents: string[]
payload: Payload
}
Actions
export type Action = {
type: "action"
address: string
name: string
args: any
context: {
timestamp: number
blockhash?: string
}
}
Sessions
export type Session<AuthorizationData = any> = {
type: "session"
address: string
publicKey: string
authorizationData: AuthorizationData
context: {
blockhash?: string
duration?: number
timestamp: number
}
}
Session signers
import type { Signer } from "./Signer.js"
import type { Message } from "./Message.js"
import type { Session } from "./Session.js"
import type { Action } from "./Action.js"
import type { Awaitable } from "./Awaitable.js"
export interface SessionSigner extends Signer<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>