Skip to main content

Class: OrderSigningUtils

Utility class for signing order intents and cancellations.

Remarks

This class only supports eth_sign and wallet-native EIP-712 signing. For use of presign and eip1271 see the docs.

Example

import { OrderSigningUtils, SupportedChainId } from '@cowprotocol/cow-sdk'
import { Web3Provider } from '@ethersproject/providers'

const account = 'YOUR_WALLET_ADDRESS'
const chainId = 100 // Gnosis chain
const provider = new Web3Provider(window.ethereum)
const signer = provider.getSigner()

async function main() {
const { order: Order } = { ... }
const orderSigningResult = await OrderSigningUtils.signOrder(quote, chainId, signer)

const orderId = await orderBookApi.sendOrder({ ...quote, ...orderSigningResult })

const order = await orderBookApi.getOrder(orderId)

const trades = await orderBookApi.getTrades({ orderId })

const orderCancellationSigningResult = await OrderSigningUtils.signOrderCancellations([orderId], chainId, signer)

const cancellationResult = await orderBookApi.sendSignedOrderCancellations({...orderCancellationSigningResult, orderUids: [orderId] })

console.log('Results: ', { orderId, order, trades, orderCancellationSigningResult, cancellationResult })
}

Constructors

constructor

new OrderSigningUtils(): OrderSigningUtils

Returns

OrderSigningUtils

Methods

getDomain

getDomain(chainId): Promise<TypedDataDomain>

Get the EIP-712 typed domain data being used for signing.

Parameters

NameTypeDescription
chainIdSupportedChainIdThe CoW Protocol protocol chainId context that's being used.

Returns

Promise<TypedDataDomain>

The EIP-712 typed domain data.

See

https://eips.ethereum.org/EIPS/eip-712

Defined in

external/cow-sdk/src/order-signing/orderSigningUtils.ts:98


getDomainSeparator

getDomainSeparator(chainId): Promise<string>

Get the domain separator hash for the EIP-712 typed domain data being used for signing.

Parameters

NameTypeDescription
chainIdSupportedChainId{SupportedChainId} chainId The CoW Protocol protocol chainId context that's being used.

Returns

Promise<string>

A string representation of the EIP-712 typed domain data hash.

Defined in

external/cow-sdk/src/order-signing/orderSigningUtils.ts:108


getEIP712Types

getEIP712Types(): Record<string, any>

Get the EIP-712 types used for signing a GPv2Order.Data struct. This is useful for when signing orders using smart contracts, whereby this SDK cannot do the EIP-1271 signing for you.

Returns

Record<string, any>

The EIP-712 types used for signing.

Defined in

external/cow-sdk/src/order-signing/orderSigningUtils.ts:119


signOrder

signOrder(order, chainId, signer): Promise<SigningResult>

Sign the order intent with the specified signer.

Parameters

NameTypeDescription
orderUnsignedOrderThe unsigned order intent to be placed.
chainIdSupportedChainIdThe CoW Protocol chainId context that's being used.
signerSignerThe signer who is placing the order intent.

Returns

Promise<SigningResult>

Encoded signature including signing scheme for the order.

Remarks

If the API reports an error with the signature, it is likely to be due to an incorrectly specified chainId. Please ensure that the chainId is correct for the network you are using.

Defined in

external/cow-sdk/src/order-signing/orderSigningUtils.ts:55


signOrderCancellation

signOrderCancellation(orderUid, chainId, signer): Promise<SigningResult>

Sign a cancellation message of an order intent with the specified signer.

Parameters

NameTypeDescription
orderUidstringThe unique identifier of the order to cancel.
chainIdSupportedChainIdThe CoW Protocol chainid context that's being used.
signerSignerThe signer who initially placed the order intent.

Returns

Promise<SigningResult>

Encoded signature including signing scheme for the cancellation.

Defined in

external/cow-sdk/src/order-signing/orderSigningUtils.ts:67


signOrderCancellations

signOrderCancellations(orderUids, chainId, signer): Promise<SigningResult>

Sign a cancellation message of multiple order intents with the specified signer.

Parameters

NameTypeDescription
orderUidsstring[]An array of orderUid to cancel.
chainIdSupportedChainIdThe CoW Protocol protocol chainId context that's being used.
signerSignerThe signer who initially placed the order intents.

Returns

Promise<SigningResult>

Encoded signature including signing scheme for the cancellation.

Defined in

external/cow-sdk/src/order-signing/orderSigningUtils.ts:83