Skip to content

Commit

Permalink
Merge pull request #1379 from Conflux-Chain/dev
Browse files Browse the repository at this point in the history
release: v2.6.2
  • Loading branch information
AngeliaQ authored Mar 23, 2023
2 parents 1093955 + 381d49e commit dca3195
Show file tree
Hide file tree
Showing 8 changed files with 212 additions and 23 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# shared basic environment variable
# the build tool will load this file with any NODE_ENV
SNOWPACK_PUBLIC_FLUENT_VERSION=2.6.1
SNOWPACK_PUBLIC_FLUENT_VERSION=2.6.2

9 changes: 6 additions & 3 deletions packages/estimate-tx/eth.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ export const ethEstimate = async (
},
{balance: balances['0x0']},
)
if (toAddressType === 'user')
if (toAddressType !== 'contract')
return {
...ethFeeData,
gasPrice,
Expand Down Expand Up @@ -233,8 +233,11 @@ export const ethEstimate = async (
const clcMaxFeePerGas = customMaxFeePerGas || maxFeePerGas
const clcGasLimit =
customGasLimit ||
pre0x(bn16(gasLimit).muln(chainIdToGasBuffer[chainId] || defaultGasBuffer))

pre0x(
bn16(gasLimit)
.muln(chainIdToGasBuffer[chainId] || defaultGasBuffer)
.toString(16),
)
rst = {
...rst,
}
Expand Down
2 changes: 1 addition & 1 deletion packages/estimate-tx/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"type": "module",
"main": "index.js",
"packageManager": "yarn@3.0.1",
"version": "0.2.2",
"version": "0.2.3",
"dependencies": {
"@fluent-wallet/consts": "workspace:*",
"@fluent-wallet/detect-address-type": "workspace:packages/detect-address-type",
Expand Down
4 changes: 4 additions & 0 deletions packages/popup/src/hooks/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
useDataForPopup,
useCurrentAddress,
useAddress,
useBalance,
useNetworkTypeIsCfx,
useAddressType,
useValid20Token,
Expand Down Expand Up @@ -141,6 +142,8 @@ export const useEstimateTx = (tx = {}, tokensAmount = {}) => {
gas,
storageLimit,
} = tx
const nativeBalance =
useBalance(from, network?.eid, '0x0')?.[from]?.['0x0'] || '0x0'
const {
value: rst,
loading,
Expand Down Expand Up @@ -177,6 +180,7 @@ export const useEstimateTx = (tx = {}, tokensAmount = {}) => {
// currentNetwork.netId,
Boolean(provider),
Object.keys(tokensAmount)?.[0],
nativeBalance,
type,
])

Expand Down
39 changes: 25 additions & 14 deletions packages/rpcs/eth_signTxWithLedgerNanoS/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
import {map, dbid, mapp} from '@fluent-wallet/spec'
import {decrypt} from 'browser-passworder'
import {Ethereum as LedgerEthereum} from '@fluent-wallet/ledger'
import {
ethEncodeTx,
ethRecoverTransactionToAddress,
ethJoinTransactionAndSignature,
} from '@fluent-wallet/signature'
import {TransactionFactory} from '@ethereumjs/tx'
import {RLP} from '@ethereumjs/rlp'
import {bufArrToArr} from '@ethereumjs/util'
import {Common} from '@ethereumjs/common'
import {addHexPrefix} from '@fluent-wallet/utils'

export const NAME = 'eth_signTxWithLedgerNanoS'

Expand Down Expand Up @@ -34,7 +34,7 @@ export const main = async ({
db: {findAddress, getPassword},
params: {tx, addressId, accountId},
}) => {
const newTx = {...tx}
let newTx = {...tx}
const addr = findAddress({
addressId,
accountId,
Expand All @@ -60,23 +60,34 @@ export const main = async ({
if (!hdPath) throw InvalidParams(`Invalid address id ${addressId}`)

try {
const common = Common.custom({chainId: tx.chainId})
const txData = TransactionFactory.fromTxData(newTx, {common})

let messageToSign = txData.getMessageToSign(false)
const rawTxHex = Buffer.isBuffer(messageToSign)
? messageToSign.toString('hex')
: Buffer.from(RLP.encode(bufArrToArr(messageToSign)))

const {r, s, v} = await new LedgerEthereum().signTransaction(
hdPath,
ethEncodeTx(newTx, true),
rawTxHex,
)
const recoveredAddr = ethRecoverTransactionToAddress(tx, {r, s, v})

const allTxData = {
...newTx,
v: addHexPrefix(v),
r: addHexPrefix(r),
s: addHexPrefix(s),
}
const signedTx = TransactionFactory.fromTxData(allTxData, {common})
const recoveredAddr = signedTx.getSenderAddress().toString()
if (recoveredAddr.toLowerCase() !== addr.value)
throw InvalidParams(
`The address in LedgerNanoS (${recoveredAddr}) doesn't match the address in fluent (${addr.value})`,
)

const rawTx = ethJoinTransactionAndSignature({
tx: newTx,
signature: [r, s, v],
})

return rawTx
const rawTx = signedTx.serialize().toString('hex')
return addHexPrefix(rawTx)
} catch (err) {
const newError = UserRejected(
'error while signing transaction with Ledger Nano S',
Expand Down
7 changes: 5 additions & 2 deletions packages/rpcs/eth_signTxWithLedgerNanoS/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
"type": "module",
"main": "index.js",
"packageManager": "yarn@3.1.0",
"version": "0.0.3",
"version": "0.0.4",
"dependencies": {
"@ethereumjs/rlp": "4.0.1",
"@ethereumjs/tx": "4.1.1",
"@ethereumjs/util": "8.0.5",
"@fluent-wallet/ledger": "workspace:*",
"@fluent-wallet/signature": "workspace:*",
"@fluent-wallet/spec": "workspace:*",
"@fluent-wallet/utils": "workspace:packages/utils",
"browser-passworder": "2.0.3"
}
}
2 changes: 1 addition & 1 deletion scripts/before_all.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ style-src 'self' data: chrome-extension-resource: 'unsafe-inline';
frame-src 'self' http://localhost:* data: chrome-extension-resource:;
font-src 'self' data: chrome-extension-resource:;
media-src * data: blob: filesystem:;",`.replaceAll('\n', ' ')
: '',
: `"content_security_policy": "script-src 'self' 'wasm-unsafe-eval'; object-src 'self'",`,
name: isDev() ? 'AFluent' : '__MSG_extensionNAME__',
backgroundScripts: isDev()
? '"reload.js","background.dev.js"'
Expand Down
170 changes: 169 additions & 1 deletion yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1830,6 +1830,33 @@ __metadata:
languageName: node
linkType: hard

"@chainsafe/as-sha256@npm:^0.3.1":
version: 0.3.1
resolution: "@chainsafe/as-sha256@npm:0.3.1"
checksum: 58ea733be1657b0e31dbf48b0dba862da0833df34a81c1460c7352f04ce90874f70003cbf34d0afb9e5e53a33ee2d63a261a8b12462be85b2ba0a6f7f13d6150
languageName: node
linkType: hard

"@chainsafe/persistent-merkle-tree@npm:^0.4.2":
version: 0.4.2
resolution: "@chainsafe/persistent-merkle-tree@npm:0.4.2"
dependencies:
"@chainsafe/as-sha256": ^0.3.1
checksum: f9cfcb2132a243992709715dbd28186ab48c7c0c696f29d30857693cca5526bf753974a505ef68ffd5623bbdbcaa10f9083f4dd40bf99eb6408e451cc26a1a9e
languageName: node
linkType: hard

"@chainsafe/ssz@npm:0.9.4":
version: 0.9.4
resolution: "@chainsafe/ssz@npm:0.9.4"
dependencies:
"@chainsafe/as-sha256": ^0.3.1
"@chainsafe/persistent-merkle-tree": ^0.4.2
case: ^1.6.3
checksum: c6eaedeae9e5618b3c666ff4507a27647f665a8dcf17d5ca86da4ed4788c5a93868f256d0005467d184fdf35ec03f323517ec2e55ec42492d769540a2ec396bc
languageName: node
linkType: hard

"@conflux-dev/conflux-address-js@npm:1.3.13":
version: 1.3.13
resolution: "@conflux-dev/conflux-address-js@npm:1.3.13"
Expand Down Expand Up @@ -2405,6 +2432,55 @@ __metadata:
languageName: node
linkType: hard

"@ethereumjs/common@npm:^3.1.1":
version: 3.1.1
resolution: "@ethereumjs/common@npm:3.1.1"
dependencies:
"@ethereumjs/util": ^8.0.5
crc-32: ^1.2.0
checksum: 58602dee9fbcf691dca111b4fd7fd5770f5e86d68012ce48fba396c7038afdca4fca273a9cf39f88cf6ea7b256603a4bd214e94e9d01361efbcd060460b78952
languageName: node
linkType: hard

"@ethereumjs/rlp@npm:4.0.1, @ethereumjs/rlp@npm:^4.0.1":
version: 4.0.1
resolution: "@ethereumjs/rlp@npm:4.0.1"
bin:
rlp: bin/rlp
checksum: 30db19c78faa2b6ff27275ab767646929207bb207f903f09eb3e4c273ce2738b45f3c82169ddacd67468b4f063d8d96035f2bf36f02b6b7e4d928eefe2e3ecbc
languageName: node
linkType: hard

"@ethereumjs/tx@npm:4.1.1":
version: 4.1.1
resolution: "@ethereumjs/tx@npm:4.1.1"
dependencies:
"@chainsafe/ssz": 0.9.4
"@ethereumjs/common": ^3.1.1
"@ethereumjs/rlp": ^4.0.1
"@ethereumjs/util": ^8.0.5
"@ethersproject/providers": ^5.7.2
ethereum-cryptography: ^1.1.2
peerDependencies:
c-kzg: ^1.0.8
peerDependenciesMeta:
c-kzg:
optional: true
checksum: 98897e79adf03ee90ed98c6a543e15e0b4e127bc5bc381d70cdcc76b111574205b94869c29d925ea9e30a98e5ef8b0f5597914359deb9db552017b2e78ef17a8
languageName: node
linkType: hard

"@ethereumjs/util@npm:8.0.5, @ethereumjs/util@npm:^8.0.5":
version: 8.0.5
resolution: "@ethereumjs/util@npm:8.0.5"
dependencies:
"@chainsafe/ssz": 0.9.4
"@ethereumjs/rlp": ^4.0.1
ethereum-cryptography: ^1.1.2
checksum: 318386785295b4584289b1aa576d2621392b3a918d127890db62d3f74184f3377694dd9e951e19bfb9ab80e8dc9e38e180236cac2651dead26097d10963731f9
languageName: node
linkType: hard

"@ethersproject/abi@npm:^5.7.0":
version: 5.7.0
resolution: "@ethersproject/abi@npm:5.7.0"
Expand Down Expand Up @@ -2767,6 +2843,34 @@ __metadata:
languageName: node
linkType: hard

"@ethersproject/providers@npm:^5.7.2":
version: 5.7.2
resolution: "@ethersproject/providers@npm:5.7.2"
dependencies:
"@ethersproject/abstract-provider": ^5.7.0
"@ethersproject/abstract-signer": ^5.7.0
"@ethersproject/address": ^5.7.0
"@ethersproject/base64": ^5.7.0
"@ethersproject/basex": ^5.7.0
"@ethersproject/bignumber": ^5.7.0
"@ethersproject/bytes": ^5.7.0
"@ethersproject/constants": ^5.7.0
"@ethersproject/hash": ^5.7.0
"@ethersproject/logger": ^5.7.0
"@ethersproject/networks": ^5.7.0
"@ethersproject/properties": ^5.7.0
"@ethersproject/random": ^5.7.0
"@ethersproject/rlp": ^5.7.0
"@ethersproject/sha2": ^5.7.0
"@ethersproject/strings": ^5.7.0
"@ethersproject/transactions": ^5.7.0
"@ethersproject/web": ^5.7.0
bech32: 1.1.4
ws: 7.4.6
checksum: 1754c731a5ca6782ae9677f4a9cd8b6246c4ef21a966c9a01b133750f3c578431ec43ec254e699969c4a0f87e84463ded50f96b415600aabd37d2056aee58c19
languageName: node
linkType: hard

"@ethersproject/random@npm:5.6.1":
version: 5.6.1
resolution: "@ethersproject/random@npm:5.6.1"
Expand Down Expand Up @@ -4034,9 +4138,12 @@ __metadata:
version: 0.0.0-use.local
resolution: "@fluent-wallet/eth_sign-tx-with-ledger-nano-s@workspace:packages/rpcs/eth_signTxWithLedgerNanoS"
dependencies:
"@ethereumjs/rlp": 4.0.1
"@ethereumjs/tx": 4.1.1
"@ethereumjs/util": 8.0.5
"@fluent-wallet/ledger": "workspace:*"
"@fluent-wallet/signature": "workspace:*"
"@fluent-wallet/spec": "workspace:*"
"@fluent-wallet/utils": "workspace:packages/utils"
browser-passworder: 2.0.3
languageName: unknown
linkType: soft
Expand Down Expand Up @@ -5814,6 +5921,20 @@ __metadata:
languageName: node
linkType: hard

"@noble/hashes@npm:1.2.0, @noble/hashes@npm:~1.2.0":
version: 1.2.0
resolution: "@noble/hashes@npm:1.2.0"
checksum: 8ca080ce557b8f40fb2f78d3aedffd95825a415ac8e13d7ffe3643f8626a8c2d99a3e5975b555027ac24316d8b3c02a35b8358567c0c23af681e6573602aa434
languageName: node
linkType: hard

"@noble/secp256k1@npm:1.7.1, @noble/secp256k1@npm:~1.7.0":
version: 1.7.1
resolution: "@noble/secp256k1@npm:1.7.1"
checksum: d2301f1f7690368d8409a3152450458f27e54df47e3f917292de3de82c298770890c2de7c967d237eff9c95b70af485389a9695f73eb05a43e2bd562d18b18cb
languageName: node
linkType: hard

"@nodelib/fs.scandir@npm:2.1.5":
version: 2.1.5
resolution: "@nodelib/fs.scandir@npm:2.1.5"
Expand Down Expand Up @@ -6107,6 +6228,34 @@ __metadata:
languageName: node
linkType: hard

"@scure/base@npm:~1.1.0":
version: 1.1.1
resolution: "@scure/base@npm:1.1.1"
checksum: b4fc810b492693e7e8d0107313ac74c3646970c198bbe26d7332820886fa4f09441991023ec9aa3a2a51246b74409ab5ebae2e8ef148bbc253da79ac49130309
languageName: node
linkType: hard

"@scure/bip32@npm:1.1.5":
version: 1.1.5
resolution: "@scure/bip32@npm:1.1.5"
dependencies:
"@noble/hashes": ~1.2.0
"@noble/secp256k1": ~1.7.0
"@scure/base": ~1.1.0
checksum: b08494ab0d2b1efee7226d1b5100db5157ebea22a78bb87126982a76a186cb3048413e8be0ba2622d00d048a20acbba527af730de86c132a77de616eb9907a3b
languageName: node
linkType: hard

"@scure/bip39@npm:1.1.1":
version: 1.1.1
resolution: "@scure/bip39@npm:1.1.1"
dependencies:
"@noble/hashes": ~1.2.0
"@scure/base": ~1.1.0
checksum: fbb594c50696fa9c14e891d872f382e50a3f919b6c96c55ef2fb10c7102c546dafb8f099a62bd114c12a00525b595dcf7381846f383f0ddcedeaa6e210747d2f
languageName: node
linkType: hard

"@sentry/browser@npm:7.4.1":
version: 7.4.1
resolution: "@sentry/browser@npm:7.4.1"
Expand Down Expand Up @@ -11021,6 +11170,13 @@ __metadata:
languageName: node
linkType: hard

"case@npm:^1.6.3":
version: 1.6.3
resolution: "case@npm:1.6.3"
checksum: febe73278f910b0d28aab7efd6f51c235f9aa9e296148edb56dfb83fd58faa88308c30ce9a0122b6e53e0362c44f4407105bd5ef89c46860fc2b184e540fd68d
languageName: node
linkType: hard

"caseless@npm:~0.12.0":
version: 0.12.0
resolution: "caseless@npm:0.12.0"
Expand Down Expand Up @@ -14972,6 +15128,18 @@ __metadata:
languageName: node
linkType: hard

"ethereum-cryptography@npm:^1.1.2":
version: 1.2.0
resolution: "ethereum-cryptography@npm:1.2.0"
dependencies:
"@noble/hashes": 1.2.0
"@noble/secp256k1": 1.7.1
"@scure/bip32": 1.1.5
"@scure/bip39": 1.1.1
checksum: 97e8e8253cb9f5a9271bd0201c37609c451c890eb85883b9c564f14743c3d7c673287406c93bf5604307593ee298ad9a03983388b85c11ca61461b9fc1a4f2c7
languageName: node
linkType: hard

"ethereumjs-abi@git+https://github.com/ethereumjs/ethereumjs-abi.git":
version: 0.6.8
resolution: "ethereumjs-abi@https://github.com/ethereumjs/ethereumjs-abi.git#commit=ee3994657fa7a427238e6ba92a84d0b529bbcde0"
Expand Down

0 comments on commit dca3195

Please sign in to comment.