@exodus/ethereum-lib 4.1.3 → 4.2.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/LICENSE.md
ADDED
|
File without changes
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-lib",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.2.0",
|
|
4
4
|
"description": "Ethereum Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -42,5 +42,6 @@
|
|
|
42
42
|
"lodash": "^4.17.15",
|
|
43
43
|
"ms": "^2.1.1",
|
|
44
44
|
"reselect": "~3.0.1"
|
|
45
|
-
}
|
|
45
|
+
},
|
|
46
|
+
"gitHead": "c5aba08d687ed0470b9fea821879d41149156897"
|
|
46
47
|
}
|
package/src/unsigned-tx/index.js
CHANGED
|
@@ -3,3 +3,4 @@ export { default as parseUnsignedTx } from './parse-unsigned-tx'
|
|
|
3
3
|
export { default as signUnsignedTx } from './sign-unsigned-tx'
|
|
4
4
|
export { default as createAndSignTx } from './create-and-sign-tx'
|
|
5
5
|
export { default as createEthereumJsTx } from './create-ethereumjs-tx'
|
|
6
|
+
export { signHardwareFactory } from './sign-hardware'
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
import createEthereumJsTx from './create-ethereumjs-tx'
|
|
2
|
+
|
|
3
|
+
export const signHardwareFactory = ({ baseAssetName }) => async ({
|
|
4
|
+
unsignedTx,
|
|
5
|
+
hardwareDevice,
|
|
6
|
+
accountIndex,
|
|
7
|
+
}) => {
|
|
8
|
+
const tx = createEthereumJsTx(unsignedTx)
|
|
9
|
+
|
|
10
|
+
const signedTx = await signWithHardwareWallet({
|
|
11
|
+
baseAssetName,
|
|
12
|
+
tx,
|
|
13
|
+
hardwareDevice,
|
|
14
|
+
accountIndex,
|
|
15
|
+
})
|
|
16
|
+
|
|
17
|
+
// serialize and get txId
|
|
18
|
+
const rawTx = signedTx.serialize()
|
|
19
|
+
const txId = signedTx.hash().toString('hex')
|
|
20
|
+
return { rawTx, txId }
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
async function signWithHardwareWallet({ baseAssetName, tx, hardwareDevice, accountIndex }) {
|
|
24
|
+
const rlpEncodedTx = tx.serialize()
|
|
25
|
+
const signatures = await hardwareDevice.signTransaction({
|
|
26
|
+
assetName: baseAssetName,
|
|
27
|
+
signableTransaction: rlpEncodedTx,
|
|
28
|
+
derivationPaths: [`m/44'/60'/${accountIndex}'/0/0`],
|
|
29
|
+
})
|
|
30
|
+
|
|
31
|
+
const { signature } = signatures[0]
|
|
32
|
+
|
|
33
|
+
let v = signature.slice(0, 1)[0]
|
|
34
|
+
if (v === 0 || v === 1) {
|
|
35
|
+
// Undo the parity
|
|
36
|
+
v = v + 27
|
|
37
|
+
}
|
|
38
|
+
const r = signature.slice(1, 1 + 32)
|
|
39
|
+
const s = signature.slice(1 + 32, 1 + 32 + 32)
|
|
40
|
+
|
|
41
|
+
return tx._processSignature(v, r, s)
|
|
42
|
+
}
|
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
/* @flow */
|
|
2
|
-
import type { UnsignedTransaction, SignedTransaction } from '@exodus/models/lib/types'
|
|
3
1
|
import createEthereumJsTx from './create-ethereumjs-tx'
|
|
4
2
|
|
|
5
|
-
export default function signUnsignedTx(
|
|
6
|
-
unsignedTx: UnsignedTransaction,
|
|
7
|
-
privateKey: Buffer
|
|
8
|
-
): SignedTransaction {
|
|
3
|
+
export default function signUnsignedTx(unsignedTx, privateKey) {
|
|
9
4
|
const tx = createEthereumJsTx(unsignedTx)
|
|
5
|
+
|
|
10
6
|
const signedTx = tx.sign(privateKey)
|
|
11
7
|
|
|
12
8
|
// serialize and get txId
|