Skip to content

Commit

Permalink
Make it compatible with ethers-v5
Browse files Browse the repository at this point in the history
  • Loading branch information
anxolin committed Jul 17, 2023
1 parent 17ee014 commit f09039f
Show file tree
Hide file tree
Showing 4 changed files with 459 additions and 49 deletions.
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@cowprotocol/app-data",
"version": "1.0.0-rc.2",
"version": "1.0.0-rc.3",
"description": "CowProtocol AppData schema definitions",
"type": "module",
"source": "src/index.ts",
Expand Down Expand Up @@ -33,7 +33,7 @@
},
"homepage": "https://github.com/cowprotocol/app-data#readme",
"devDependencies": {
"ethers": "^6.6.4",
"ethers": "^5.0.26",
"@babel/core": "^7.18.9",
"@babel/preset-env": "^7.18.9",
"@babel/preset-typescript": "^7.18.6",
Expand All @@ -59,7 +59,7 @@
},
"peerDependencies": {
"cross-fetch": "^3.x",
"ethers": "^6.6.4",
"ethers": "^5.0.0",
"ipfs-only-hash": "^4.x",
"multiformats": "^9.x"
},
Expand Down
4 changes: 2 additions & 2 deletions src/api/appDataHexToCid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ async function _appDataHexToCid(appDataHex: string): Promise<string> {
cidPrefix[2] = 0x1b // keccak hash algorithm
cidPrefix[3] = 32 // keccak hash length (0x20 = 32)

const { getBytes } = await import('ethers')
const hashBytes = getBytes(appDataHex) // 32 bytes of the keccak256 hash
const { utils } = await import('ethers')
const hashBytes = utils.arrayify(appDataHex) // 32 bytes of the keccak256 hash

// Concat prefix and multihash
var cidBytes = new Uint8Array(cidPrefix.length + hashBytes.length)
Expand Down
4 changes: 2 additions & 2 deletions src/api/appDataToCid.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,9 +98,9 @@ export async function _appDataToCidAux(
* @returns the IPFS CID v0 of the content
*/
async function _appDataToCid(fullAppDataJson: string): Promise<string> {
const { keccak256, toUtf8Bytes } = await import('ethers')
const { utils } = await import('ethers')

const appDataHex = await keccak256(toUtf8Bytes(fullAppDataJson))
const appDataHex = await utils.keccak256(utils.toUtf8Bytes(fullAppDataJson))
return appDataHexToCid(appDataHex)
}

Expand Down
Loading

0 comments on commit f09039f

Please sign in to comment.