@exodus/ethereum-lib 4.4.0 → 4.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@exodus/ethereum-lib",
3
- "version": "4.4.0",
3
+ "version": "4.5.0",
4
4
  "description": "Ethereum Library",
5
5
  "main": "src/index.js",
6
6
  "files": [
@@ -46,6 +46,7 @@
46
46
  "@exodus/optimism-meta": "^1.2.10",
47
47
  "@exodus/rootstock-meta": "^1.0.5",
48
48
  "@exodus/solidity-contract": "^1.1.3",
49
+ "@metamask/eth-sig-util": "^4.0.1",
49
50
  "base-x": "^3.0.2",
50
51
  "ethjs-util": "0.1.6",
51
52
  "lodash": "^4.17.15",
@@ -59,5 +60,5 @@
59
60
  "@exodus/bnbmainnet-meta": "^1.0.0",
60
61
  "@exodus/elliptic": "^6.5.4-precomputed"
61
62
  },
62
- "gitHead": "952a85ff2ce573b294d53fb411b9858088d15229"
63
+ "gitHead": "539b25e53db7092fab6a1645f6d0e0f3118fe75c"
63
64
  }
@@ -1,5 +1,6 @@
1
1
  import { get } from 'lodash'
2
2
 
3
+ // @deprecated to be removed. Use balances!
3
4
  export const getEthereumBalances = ({ asset, liquidBalance, accountState }) => {
4
5
  // asset = ethereum or ethereumgoerli or ethereumholesky
5
6
  const delegatedBalance = get(
@@ -1,2 +1,3 @@
1
+ // @deprecated to be removed. Use balances!
1
2
  export * from './ethereum-balance'
2
3
  export * from './polygon-balance'
@@ -3,6 +3,7 @@ import assets from '@exodus/ethereum-meta'
3
3
 
4
4
  const polygon = assets.find(({ name: tokenName }) => tokenName === 'polygon')
5
5
 
6
+ // @deprecated to be removed. Use balances!
6
7
  export const getPolygonBalances = ({ liquidBalance, accountState }) => {
7
8
  const delegatedBalance = get(
8
9
  accountState,
@@ -3,7 +3,7 @@ import { asset } from '@exodus/basemainnet-meta'
3
3
 
4
4
  export default new FeeData({
5
5
  config: {
6
- gasPrice: '0.07 Gwei',
6
+ gasPrice: '0.2 Gwei',
7
7
  max: '1 Gwei',
8
8
  min: '0.001 Gwei',
9
9
  fuelThreshold: '750000 Gwei',
@@ -0,0 +1,47 @@
1
+ import assert from 'minimalistic-assert'
2
+ import { SignTypedDataVersion, personalSign, signTypedData } from '@metamask/eth-sig-util'
3
+
4
+ function hex0xStringToBuffer(hex) {
5
+ // Remove the 0x
6
+ const hexWithout0x = hex.startsWith('0x') ? hex.slice(2) : hex
7
+ // Pad the value until even
8
+ const hexWithLeadingZeros = hexWithout0x.length % 2 === 0 ? hexWithout0x : '0' + hexWithout0x
9
+ // Finally return the buffer
10
+ return Buffer.from(hexWithLeadingZeros, 'hex')
11
+ }
12
+
13
+ /**
14
+ * Converts a buffer to the 0xhex encoded value
15
+ * @param {Buffer} buf the buffer to convert to 0xHEXSTRING
16
+ * @returns the hex-encoded value prepended with 0x
17
+ */
18
+ function bufferToHex0xString(buf) {
19
+ if (!Buffer.isBuffer(buf)) {
20
+ throw new TypeError('expected a buffer')
21
+ }
22
+
23
+ const hex = buf.toString('hex')
24
+
25
+ if (typeof hex !== 'string') {
26
+ throw new TypeError('expected hex string')
27
+ }
28
+
29
+ return '0x' + hex
30
+ }
31
+
32
+ export const signMessage = async ({ privateKey, message }) => {
33
+ const { rawMessage, EIP712Message } = message
34
+
35
+ // Exclusive OR (XOR)
36
+ assert(!!rawMessage !== !!EIP712Message, 'Need either rawMessage or EIP712Message')
37
+
38
+ if (rawMessage) {
39
+ return hex0xStringToBuffer(personalSign({ privateKey, data: bufferToHex0xString(rawMessage) }))
40
+ }
41
+
42
+ if (EIP712Message) {
43
+ const version = Array.isArray(EIP712Message) ? SignTypedDataVersion.V1 : SignTypedDataVersion.V4
44
+
45
+ return hex0xStringToBuffer(signTypedData({ privateKey, data: EIP712Message, version }))
46
+ }
47
+ }