@cowprotocol/sdk-order-signing

中文文档
1.1.25发布于 2026/11/04MITTypeScriptESM + CJS构建来源已验证近 30 天下载 8.5万

COW 协议 SDK 命令签名

中文使用文档
文档目录9 节
  1. 测试覆盖率
  2. 安装
  3. 使用量
  4. 使用 CoW SDK 软件
  5. 签名计划
  6. EIP-712(过失)
  7. 智能合同钱包( 预签名)
  8. EIP-1271 (中文(简体) )
  9. 与顺序书合并

SDK 命令签名

测试覆盖率

发言分支职能行数
StatementsBranchesFunctionsLines

这个软件包为CoW协议提供EIP-712订单签名和取消功能. 它负责所有根据CoW协议的规格签署订单和注销所需的密码操作.

安装

npm install @cowprotocol/sdk-order-signing
or
pnpm add @cowprotocol/sdk-order-signing
or
yarn add @cowprotocol/sdk-order-signing

使用量

import { OrderSigningUtils, SupportedChainId, UnsignedOrder, SigningResult } from '@cowprotocol/sdk-order-signing'
import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
import { JsonRpcProvider, Wallet } from 'ethers'

// Configure the adapter
const provider = new JsonRpcProvider('YOUR_RPC_URL')
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
const adapter = new EthersV6Adapter({ provider, signer: wallet })

// Configure the global adapter
setGlobalAdapter(adapter)

// Sign an order using static methods
const orderToSign: UnsignedOrder = {
  sellToken: '0xA0b86a33E6417b528874E10EB3a95beb4F25A0E3',
  buyToken: '0xC02aaA39b223FE8D0A0e5C4F27eAD9083C756Cc2',
  sellAmount: '1000000000000000000',
  buyAmount: '1000000000000000000',
  validTo: Math.floor(Date.now() / 1000) + 3600,
  appData: '0x0000000000000000000000000000000000000000000000000000000000000000',
  feeAmount: '0',
  kind: 'sell',
  partiallyFillable: false,
  sellTokenBalance: 'erc20',
  buyTokenBalance: 'erc20',
  receiver: '0x0000000000000000000000000000000000000000',
}

const signingResult: SigningResult = await OrderSigningUtils.signOrder(
  orderToSign,
  SupportedChainId.MAINNET,
  adapter.signer,
)

// Sign order cancellation
const orderId = 'ORDER_UID_TO_CANCEL'
const cancellationResult = await OrderSigningUtils.signOrderCancellation(
  orderId,
  SupportedChainId.MAINNET,
  adapter.signer,
)

// Generate order ID
const { orderId: generatedId, orderDigest } = await OrderSigningUtils.generateOrderId(
  SupportedChainId.MAINNET,
  orderToSign as any,
  { owner: await adapter.signer.getAddress() },
)

使用 CoW SDK 软件

import { CowSdk, OrderSigningUtils, SupportedChainId, UnsignedOrder } from '@cowprotocol/cow-sdk'
import { EthersV6Adapter } from '@cowprotocol/sdk-ethers-v6-adapter'
import { JsonRpcProvider, Wallet } from 'ethers'

// Configure the adapter
const provider = new JsonRpcProvider('YOUR_RPC_URL')
const wallet = new Wallet('YOUR_PRIVATE_KEY', provider)
const adapter = new EthersV6Adapter({ provider, signer: wallet })

// Initialize the unified SDK
const sdk = new CowSdk({
  chainId: SupportedChainId.MAINNET,
  adapter,
})

// Use static methods through sdk.orderSigning
const signingResult = await sdk.orderSigning.signOrder(orderToSign, SupportedChainId.MAINNET, adapter.signer)

// Sign cancellation
const cancellationResult = await sdk.orderSigning.signOrderCancellation(
  orderId,
  SupportedChainId.MAINNET,
  adapter.signer,
)

签名计划

SDK支持多个签名方案:

EIP-712(过失)

使用 EIP-712 输入数据的标准钱包签名 :

// Automatically uses EIP-712 for wallet signers
const result = await OrderSigningUtils.signOrder(order, chainId, signer)

智能合同钱包( 预签名)

对于Safe这样的智能合同钱包:

import { SigningScheme } from '@cowprotocol/sdk-order-signing'

// For smart contract wallets, specify the signing scheme
// Then execute the pre-sign transaction on-chain

EIP-1271 (中文(简体) )

对于执行EIP-1271的合同:

// Used for contracts that can validate signatures
// The SDK automatically detects and handles this

与顺序书合并

本套件与"秩序书"API无缝:

// 1. Sign the order
const signingResult = await OrderSigningUtils.signOrder(order, chainId, signer)

// 2. Submit to order book
const orderId = await orderBookApi.sendOrder({ ...order, ...signingResult })

// 3. Cancel if needed
const cancellation = await OrderSigningUtils.signOrderCancellation(orderId, chainId, signer)
await orderBookApi.sendSignedOrderCancellations({ ...cancellation, orderUids: [orderId] })

说明: 这个软件包处理 CoW 协议订单的密码方面. 它通常与Trading SDK或Order Book API一起用于完整的订单管理工作流程.

版本与发布记录

@cowprotocol/sdk-order-signing 共发布 89 个版本,首次发布于 2025/08/02;过去 12 个月发布了 65 个版本。最新版本附带 npm provenance 构建来源证明,可追溯到公开的 CI 构建记录。

版本发布日期距今
1.1.25latest2026/11/046 天前
1.1.242026/11/046 天前
1.1.232026/11/037 天前
1.1.222026/10/2615 天前
1.1.212026/10/2318 天前
1.1.202026/10/1328 天前

其他发布通道:next → 0.2.0-beta.0。

关于 @cowprotocol/sdk-order-signing 的常见问题

@cowprotocol/sdk-order-signing 是什么?

COW 协议 SDK 命令签名

如何安装 @cowprotocol/sdk-order-signing?

在项目目录运行 npm install @cowprotocol/sdk-order-signing,或使用 pnpm add / yarn add / bun add。

@cowprotocol/sdk-order-signing 支持 TypeScript 吗?

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

@cowprotocol/sdk-order-signing 支持 ESM 还是 CommonJS?

同时提供 ES Module 与 CommonJS 入口,import 和 require() 都可以使用,打包工具会自动选择合适的版本。

@cowprotocol/sdk-order-signing 可以商用吗?

@cowprotocol/sdk-order-signing 使用 MIT 许可。宽松许可:允许商业使用、修改和再分发,通常只需在分发时保留原版权与许可声明。以上为概括,不构成法律意见,请以许可原文为准。

@cowprotocol/sdk-order-signing 的下载量有多少?

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

@cowprotocol/sdk-order-signing 还在维护吗?

最新版本 1.1.25 发布于 2026/11/04(6 天前);至今共发布 89 个版本,其中过去 12 个月发布了 65 个;首次发布于 2025/08/02。发布频率只是参考信号:功能稳定的工具可能很少需要更新,建议结合源码仓库的 issue 和提交记录判断。