Skip to content
This repository has been archived by the owner on Sep 11, 2024. It is now read-only.

Commit

Permalink
chore(core): update decoding of eth (LE to BE) (#169)
Browse files Browse the repository at this point in the history
* chore(core): update decoding of eth (LE to BE)

* fix lint

* fix lint

* fix lint

* chore(ops): update latest standard

* override eslint to use 8.5.0

* chore(ops): bump jellyfish

* fix
  • Loading branch information
pierregee authored Sep 26, 2023
1 parent 770c3a4 commit 959eeb1
Show file tree
Hide file tree
Showing 6 changed files with 497 additions and 539 deletions.
15 changes: 10 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,19 @@
"check-file/filename-naming-convention": "off"
}
},
"pnpm": {
"overrides": {
"eslint": "^8.50.0"
}
},
"devDependencies": {
"@stickyjs/eslint-config": "^1.3.2",
"@stickyjs/turbo": "^1.3.2",
"@types/react": "18.2.21",
"@waveshq/standard-defichain-jellyfishsdk": "^2.4.1",
"@waveshq/standard-prettier": "^2.4.1",
"@waveshq/standard-web": "^2.4.1",
"@waveshq/standard-web-linter": "^2.4.1",
"@types/react": "18.2.22",
"@waveshq/standard-defichain-jellyfishsdk": "^2.11.3",
"@waveshq/standard-prettier": "^2.11.3",
"@waveshq/standard-web": "^2.11.3",
"@waveshq/standard-web-linter": "^2.11.3",
"@waveshq/walletkit-core": "workspace:*",
"testcontainers": "^9.12.0"
},
Expand Down
5 changes: 3 additions & 2 deletions packages/walletkit-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
"build": "tsc -b ./tsconfig.build.json",
"test": "jest --maxWorkers=100%",
"lint": "eslint .",
"clean": "rm -rf dist"
"clean": "rm -rf dist",
"format": "prettier --write ."
},
"jest": {
"preset": "@stickyjs/jest"
Expand All @@ -22,6 +23,6 @@
},
"devDependencies": {
"@stickyjs/jest": "^1.3.2",
"@types/react": "18.2.21"
"@types/react": "18.2.22"
}
}
22 changes: 12 additions & 10 deletions packages/walletkit-core/src/api/address.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { fromAddress, fromScript } from "@defichain/jellyfish-address";
import { Eth, fromAddress, fromScript } from "@defichain/jellyfish-address";
import { NetworkName } from "@defichain/jellyfish-network";
import { OP_PUSHDATA, Script } from "@defichain/jellyfish-transaction";
import { Script } from "@defichain/jellyfish-transaction";
import { ethers } from "ethers";

/**
Expand Down Expand Up @@ -67,15 +67,17 @@ export function getDecodedAddress(
*/

// extract script OPCodes and Hex
const hash = script.stack[1] as OP_PUSHDATA;
const address = ethers.utils.getAddress(hash.hex);
const decodedEthAddress = Eth.fromScript(script);
if (decodedEthAddress !== undefined) {
return {
type: AddressType.ETH,
address: `0x${decodedEthAddress}`,
script,
network,
};
}

return {
type: AddressType.ETH,
address,
script,
network,
};
return undefined;
} catch (e) {
return undefined;
}
Expand Down
4 changes: 2 additions & 2 deletions packages/walletkit-core/src/api/address.unit.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ describe("Address Decoder", () => {
const script: Script = {
stack: [
OP_CODES.OP_16,
OP_CODES.OP_PUSHDATA_HEX_LE("98bd4c07f8eddf293f81e511921106d0c7f2839d"),
OP_CODES.OP_PUSHDATA_HEX_BE("98bd4c07f8eddf293f81e511921106d0c7f2839d"),
],
};

const expected: EthDecodedAddress = {
type: AddressType.ETH,
address: "0x98bd4c07F8eddf293f81E511921106d0C7f2839D",
address: "0x98bd4c07f8eddf293f81e511921106d0c7f2839d",
script,
network: "testnet",
};
Expand Down
8 changes: 4 additions & 4 deletions packages/walletkit-ui/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
],
"dependencies": {
"@stickyjs/jest": "^1.3.2",
"@waveshq/standard-defichain-jellyfishsdk": "^2.4.1",
"@waveshq/standard-web": "^2.4.1",
"@waveshq/standard-web-linter": "^2.4.1",
"@waveshq/standard-defichain-jellyfishsdk": "^2.11.2",
"@waveshq/standard-web": "^2.11.2",
"@waveshq/standard-web-linter": "^2.11.2",
"@waveshq/walletkit-core": "workspace:*",
"bignumber.js": "^9.1.1",
"dayjs": "^1.11.9",
Expand All @@ -23,7 +23,7 @@
"@testing-library/jest-dom": "^5.17.0",
"@testing-library/react": "^14.0.0",
"@testing-library/react-hooks": "^8.0.1",
"@types/react": "18.2.21",
"@types/react": "18.2.22",
"jest-environment-jsdom": "^29.6.4"
},
"scripts": {
Expand Down
Loading

0 comments on commit 959eeb1

Please sign in to comment.