Skip to content

Commit

Permalink
Remove ethers
Browse files Browse the repository at this point in the history
  • Loading branch information
yagopv committed Aug 31, 2023
1 parent 9c85909 commit 2c04c3f
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
7 changes: 5 additions & 2 deletions packages/onramp-kit/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,16 @@
"access": "public"
},
"dependencies": {
"@ethersproject/abi": "^5.7.0",
"@ethersproject/address": "^5.7.0",
"@ethersproject/bytes": "^5.7.0",
"@ethersproject/hash": "^5.7.0",
"@monerium/sdk": "^2.3.0",
"@safe-global/api-kit": "^1.3.0",
"@safe-global/protocol-kit": "^1.2.0",
"@safe-global/safe-core-sdk-types": "^2.2.0",
"@stripe/crypto": "^0.0.4",
"@stripe/stripe-js": "^1.52.0",
"ethers": "^5.7.0"
"@stripe/stripe-js": "^1.52.0"
},
"devDependencies": {
"events": "^3.3.0",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ethers } from 'ethers'
import { hashMessage } from '@ethersproject/hash'
import { Currency, PaymentStandard } from '@monerium/sdk'
import Safe, * as protocolKit from '@safe-global/protocol-kit'
import { OperationType } from '@safe-global/safe-core-sdk-types'
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('SafeMoneriumClient', () => {
// @ts-expect-error - dataDecoded should have the method property
dataDecoded: {
method: 'signMessage',
parameters: [{ value: ethers.utils.hashMessage('message to sign') }]
parameters: [{ value: hashMessage('message to sign') }]
}
}
]
Expand Down
11 changes: 6 additions & 5 deletions packages/onramp-kit/src/packs/monerium/SafeMoneriumClient.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { ethers } from 'ethers'
import { hashMessage } from '@ethersproject/hash'
import { arrayify } from '@ethersproject/bytes'
import { Chain, IBAN, MoneriumClient, Networks, NewOrder, OrderKind } from '@monerium/sdk'
import Safe, { getSignMessageLibContract } from '@safe-global/protocol-kit'
import SafeApiKit from '@safe-global/api-kit'
Expand Down Expand Up @@ -68,7 +69,7 @@ export class SafeMoneriumClient extends MoneriumClient {
* @returns A boolean indicating if the message is signed
*/
async isMessageSigned(safeAddress: string, message: string): Promise<boolean> {
const messageHash = ethers.utils.hashMessage(message)
const messageHash = hashMessage(message)
const messageHashSigned = await this.#isValidSignature(safeAddress, messageHash)
return messageHashSigned
}
Expand All @@ -92,7 +93,7 @@ export class SafeMoneriumClient extends MoneriumClient {
// @ts-expect-error - dataDecoded should have the method property
tx?.dataDecoded?.method === 'signMessage' &&
// @ts-expect-error - dataDecoded should have the parameters array
tx?.dataDecoded?.parameters[0]?.value === ethers.utils.hashMessage(message)
tx?.dataDecoded?.parameters[0]?.value === hashMessage(message)
)
})
}
Expand All @@ -114,7 +115,7 @@ export class SafeMoneriumClient extends MoneriumClient {
safeVersion
})

const txData = signMessageContract.encode('signMessage', [ethers.utils.hashMessage(message)])
const txData = signMessageContract.encode('signMessage', [hashMessage(message)])

const safeTransaction = await this.#safeSdk.createTransaction({
safeTransactionData: {
Expand Down Expand Up @@ -228,7 +229,7 @@ export class SafeMoneriumClient extends MoneriumClient {
messageHash,
'0x'
])
const msgBytes = ethers.utils.arrayify(messageHash)
const msgBytes = arrayify(messageHash)

const eip1271BytesData = EIP_1271_BYTES_INTERFACE.encodeFunctionData('isValidSignature', [
msgBytes,
Expand Down
7 changes: 4 additions & 3 deletions packages/onramp-kit/src/packs/monerium/signatures.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,19 @@
import { ethers } from 'ethers'
import { Interface } from '@ethersproject/abi'

// EIP-1271 magic values (https://eips.ethereum.org/EIPS/eip-1271)
// The four-byte code is defined as follows:
// - 0x00000000 if the signature is invalid.
// - 0x20c13b0b if the signature is valid and was produced using the eth_sign method.
// - 0x1626ba7e if the signature is valid and was produced using the personal_sign method.

// More info: https://docs.safe.global/safe-core-protocol/signatures/eip-1271
const MAGIC_VALUE = '0x1626ba7e'
const MAGIC_VALUE_BYTES = '0x20c13b0b'

const EIP_1271_INTERFACE = new ethers.utils.Interface([
const EIP_1271_INTERFACE = new Interface([
'function isValidSignature(bytes32 _dataHash, bytes calldata _signature) external view'
])
const EIP_1271_BYTES_INTERFACE = new ethers.utils.Interface([
const EIP_1271_BYTES_INTERFACE = new Interface([
'function isValidSignature(bytes calldata _data, bytes calldata _signature) public view'
])

Expand Down
2 changes: 1 addition & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7049,7 +7049,7 @@ ethereumjs-wallet@^1.0.1:
utf8 "^3.0.0"
uuid "^8.3.2"

ethers@5.7.2, ethers@^5.5.3, ethers@^5.5.4, ethers@^5.7.0, ethers@^5.7.1, ethers@^5.7.2:
ethers@5.7.2, ethers@^5.5.3, ethers@^5.5.4, ethers@^5.7.1, ethers@^5.7.2:
version "5.7.2"
resolved "https://registry.yarnpkg.com/ethers/-/ethers-5.7.2.tgz#3a7deeabbb8c030d4126b24f84e525466145872e"
integrity sha512-wswUsmWo1aOK8rR7DIKiWSw9DbLWe6x98Jrn8wcTflTVvaXhAMaB5zGAXy0GYQEQp9iO1iSHWVyARQm11zUtyg==
Expand Down

0 comments on commit 2c04c3f

Please sign in to comment.