Skip to content

Commit

Permalink
chore: migrate sign typed data to ethers
Browse files Browse the repository at this point in the history
  • Loading branch information
krboktv committed May 2, 2024
1 parent 90d5255 commit bfb9865
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 15 deletions.
4 changes: 1 addition & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "@1inch/fusion-sdk",
"version": "2.0.1",
"description": "1inch Fusion Mode SDK",
"description": "1inch Fusion SDK",
"author": "@1inch",
"private": false,
"main": "dist/index.js",
Expand Down Expand Up @@ -29,8 +29,6 @@
"dependencies": {
"@1inch/byte-utils": "2.2.1",
"@1inch/limit-order-sdk": "^4.8.7",
"@metamask/eth-sig-util": "^5.1.0",
"bn.js": "^5.2.1",
"ethers": "6.11.0",
"tslib": "^2.6.2",
"ws": "^8.16.0"
Expand Down
22 changes: 11 additions & 11 deletions src/connector/blockchain/private-key-provider.connector.ts
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
import {signTypedData, SignTypedDataVersion} from '@metamask/eth-sig-util'
import {EIP712TypedData} from '@1inch/limit-order-sdk'
import {Wallet} from 'ethers'
import {BlockchainProviderConnector} from './blockchain-provider.connector'
import {Web3Like} from './web3-provider-connector'
import {add0x} from '../../utils'

export class PrivateKeyProviderConnector
implements BlockchainProviderConnector
{
private readonly privateKeyBuffer: Buffer
private readonly wallet: Wallet

constructor(
readonly privateKey: string,
protected readonly web3Provider: Web3Like
) {
this.privateKeyBuffer = Buffer.from(privateKey.replace('0x', ''), 'hex')
this.wallet = new Wallet(add0x(privateKey))
}

signTypedData(
_walletAddress: string,
typedData: EIP712TypedData
): Promise<string> {
const result = signTypedData({
privateKey: this.privateKeyBuffer,
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
// @ts-ignore
data: typedData,
version: SignTypedDataVersion.V4
})
const primaryTypes = {...typedData.types}
delete primaryTypes['EIP712Domain']

return Promise.resolve(result)
return this.wallet.signTypedData(
typedData.domain,
primaryTypes,
typedData.message
)
}

ethCall(contractAddress: string, callData: string): Promise<string> {
Expand Down
4 changes: 3 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,5 +28,7 @@ export {
QuoterCustomPresetRequest,
PresetEnum,
Preset,
Quote
Quote,
OrderStatusResponse,
OrderStatus
} from './api'

0 comments on commit bfb9865

Please sign in to comment.