@canvas-js/interfaces

中文文档
0.16.1发布于 2025/07/30TypeScriptES Module零依赖近 30 天下载 3733

此套件会导出 Canvas 信件和其他接口的 TypeScript 类型 .

中文使用文档
文档目录10 节
  1. 目录
  2. 安装
  3. API 密码
  4. 签署
  5. 签名人
  6. 信件
  7. 行动
  8. 会议
  9. 会话签名符
  10. 工具类型

@ canvas- js/ 接口

此套件会导出 Canvas 信件和其他接口的 TypeScript 类型 .

目录

安装

npm i @canvas-js/interfaces

API 密码

签署

import type { CID } from "multiformats"

export type Signature = {
  publicKey: string
  signature: Uint8Array
  cid: CID
}

签名人

import type { Signature } from "./Signature.js"

export interface Signer<T = any> {
  sign(value: T): Signature
}

信件

export type Message<Payload = unknown> = {
  topic: string
  clock: number
  parents: string[]
  payload: Payload
}

行动

export type Action = {
  type: "action"

  /** DID of the user that authorized the session (e.g. "did:pkh:eip155:1:0xb94d27...") */
  address: string

  name: string
  args: any

  context: {
    timestamp: number
    blockhash?: string
  }
}

会议

export type Session<AuthorizationData = any> = {
  type: "session"

  /** DID of the user that authorized the session (e.g. "did:pkh:eip155:1:0xb94d27...") */
  address: string

  /** did:key URI of the ephemeral session key used to sign subsequent actions */
  publicKey: string

  /** signer-specific session payload, e.g. a SIWE message & signature */
  authorizationData: AuthorizationData

  context: {
    blockhash?: string
    duration?: number
    timestamp: number
  }
}

会话签名符

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

  /**
   * Produce an signed Session object, which authorizes `session.publicKey`
   * to represent the user `${session.chain}:${session.address}`.
   *
   * The signature is stored in `session.data`, and the entire Session
   * object is then signed using the session-key, and appended to our message log.
   */
  getSession: (topic: string, options?: { chain?: string; timestamp?: number }) => Awaitable<Session>

  /**
   * Verify that `session.data` authorizes `session.publicKey`
   * to take actions on behalf of the user `${session.chain}:${session.address}`
   */
  verifySession: (session: Session) => Awaitable<void>
}

工具类型

Awaitable

export type Awaitable<T> = T | Promise<T>

版本与发布记录

@canvas-js/interfaces 共发布 262 个版本,首次发布于 2022/06/10;过去 12 个月发布了 0 个版本。

版本发布日期距今
0.16.1latest2025/07/301.3 年前
0.16.0-next.9next2025/07/141.3 年前
0.16.02025/07/081.3 年前
0.16.0-next.82025/06/271.4 年前
0.16.0-next.72025/06/251.4 年前
0.16.0-next.62025/06/251.4 年前

其他发布通道:main → 0.8.26-main-488c798d,alpha → 0.10.0-alpha.1,beta → 0.10.0-beta.3,next → 0.16.0-next.9。

关于 @canvas-js/interfaces 的常见问题

@canvas-js/interfaces 是什么?

此套件会导出 Canvas 信件和其他接口的 TypeScript 类型 .

如何安装 @canvas-js/interfaces?

在项目目录运行 npm install @canvas-js/interfaces,或使用 pnpm add / yarn add / bun add。

@canvas-js/interfaces 支持 TypeScript 吗?

支持。包内自带 TypeScript 类型声明(package.json 声明了 types 入口),安装后即可获得类型提示,无需再安装 @types 包。

@canvas-js/interfaces 支持 ESM 还是 CommonJS?

以 ES Module 形式发布,推荐使用 import 引入。在 CommonJS 项目中,Node.js 20.19+ / 22.12+ 可以直接 require() 不含顶层 await 的 ES Module,更早的版本需要改用动态 import()。

@canvas-js/interfaces 可以商用吗?

@canvas-js/interfaces 使用 未声明 许可。package.json 没有声明许可证。没有许可证的代码默认保留全部权利,商用前请联系作者或查看仓库中的 LICENSE 文件。以上为概括,不构成法律意见,请以许可原文为准。

@canvas-js/interfaces 的下载量有多少?

根据 npm 官方下载统计,@canvas-js/interfaces 在 2026/10/09 – 2026/11/07 这 30 天内被下载 3,733 次,日均约 124 次。下载量会把 CI 构建、镜像同步和作为其他包依赖的安装一并计入,适合横向比较热度,不能直接等同于使用人数。

@canvas-js/interfaces 还在维护吗?

最新版本 0.16.1 发布于 2025/07/30(1.3 年前);至今共发布 262 个版本,其中过去 12 个月发布了 0 个;首次发布于 2022/06/10。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。