21 lines
591 B
TypeScript
21 lines
591 B
TypeScript
|
import { ethers } from 'ethers';
|
||
|
import { sha3_256 } from 'js-sha3';
|
||
|
import type { Transaction } from './connectors';
|
||
|
|
||
|
/**
|
||
|
* Creates an ID in the same way that core does on the backend. This way we
|
||
|
* Can match up the newly created order with incoming orders via a subscription
|
||
|
*/
|
||
|
export const determineId = (sig: string) => {
|
||
|
return sha3_256(ethers.utils.arrayify('0x' + sig));
|
||
|
};
|
||
|
|
||
|
/**
|
||
|
* Base64 encode a transaction object
|
||
|
*/
|
||
|
export const encodeTransaction = (tx: Transaction): string => {
|
||
|
return ethers.utils.base64.encode(
|
||
|
ethers.utils.toUtf8Bytes(JSON.stringify(tx))
|
||
|
);
|
||
|
};
|