@exodus/ethereum-lib 4.5.0 → 4.7.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.
|
|
3
|
+
"version": "4.7.0",
|
|
4
4
|
"description": "Ethereum Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -60,5 +60,5 @@
|
|
|
60
60
|
"@exodus/bnbmainnet-meta": "^1.0.0",
|
|
61
61
|
"@exodus/elliptic": "^6.5.4-precomputed"
|
|
62
62
|
},
|
|
63
|
-
"gitHead": "
|
|
63
|
+
"gitHead": "fc95d105fa19691ee2549d2e4ac07ddf20a2b8af"
|
|
64
64
|
}
|
package/src/index.js
CHANGED
|
@@ -5,6 +5,7 @@ export * from './utils'
|
|
|
5
5
|
export * from './constants'
|
|
6
6
|
export * from './fee-monitor'
|
|
7
7
|
export * from './selectors'
|
|
8
|
+
export { signMessage } from './sign-message'
|
|
8
9
|
export { default as createGetKeyIdentifier } from './key-identifier'
|
|
9
10
|
export { default as createEthereumLikeAccountState } from './account-state'
|
|
10
11
|
|
package/src/key-identifier.js
CHANGED
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
2
|
import { createGetKeyIdentifier, unhardenDerivationIndex } from '@exodus/key-utils'
|
|
3
3
|
|
|
4
|
-
const HARDWARE_WALLETS = new Set(['ledger', 'trezor'])
|
|
5
|
-
|
|
6
4
|
const createEthereumGetKeyIdentifier =
|
|
7
5
|
({ bip44, assetName, keyType = 'secp256k1', allowMetaMaskCompat = false } = {}) =>
|
|
8
6
|
(partialParams = {}) => {
|
|
@@ -15,7 +13,6 @@ const createEthereumGetKeyIdentifier =
|
|
|
15
13
|
}
|
|
16
14
|
|
|
17
15
|
const { accountIndex, addressIndex, compatibilityMode } = params
|
|
18
|
-
const isHardwareWallet = HARDWARE_WALLETS.has(compatibilityMode)
|
|
19
16
|
const unhardenedBip44 = unhardenDerivationIndex(bip44)
|
|
20
17
|
const isMetaMask = allowMetaMaskCompat && compatibilityMode === 'metamask'
|
|
21
18
|
|
|
@@ -35,7 +32,7 @@ const createEthereumGetKeyIdentifier =
|
|
|
35
32
|
keyType,
|
|
36
33
|
validationRules: {
|
|
37
34
|
allowMultipleAddresses: true,
|
|
38
|
-
allowXPUB:
|
|
35
|
+
allowXPUB: true,
|
|
39
36
|
},
|
|
40
37
|
})(params)
|
|
41
38
|
}
|
package/src/sign-message.js
CHANGED
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
import assert from 'minimalistic-assert'
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
SignTypedDataVersion,
|
|
4
|
+
typedSignatureHash,
|
|
5
|
+
TypedDataUtils,
|
|
6
|
+
personalSign,
|
|
7
|
+
signTypedData,
|
|
8
|
+
concatSig,
|
|
9
|
+
} from '@metamask/eth-sig-util'
|
|
10
|
+
import { hashPersonalMessage, toBuffer } from '@exodus/ethereumjs-util'
|
|
3
11
|
|
|
4
12
|
function hex0xStringToBuffer(hex) {
|
|
5
13
|
// Remove the 0x
|
|
@@ -45,3 +53,44 @@ export const signMessage = async ({ privateKey, message }) => {
|
|
|
45
53
|
return hex0xStringToBuffer(signTypedData({ privateKey, data: EIP712Message, version }))
|
|
46
54
|
}
|
|
47
55
|
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @typedef {import('bn.js').BN} BN
|
|
59
|
+
* @typedef {{r: BN, s: BN, recoverParam: number}} Signature
|
|
60
|
+
* @typedef {{
|
|
61
|
+
* sign: ({ data: Buffer, ecOptions?: { canonical?: boolean }, enc?: string }) => Promise<Signature | Buffer>
|
|
62
|
+
* getPublicKey: () => Promise<Buffer>
|
|
63
|
+
* }} Signer
|
|
64
|
+
*/
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* @param {object} params
|
|
68
|
+
* @param {{rawMessage: Buffer, EIP712Message: any}} params.message
|
|
69
|
+
* @param {Signer} signer
|
|
70
|
+
* @return {Promise<string>}
|
|
71
|
+
*/
|
|
72
|
+
export async function signMessageWithSigner({ message, signer }) {
|
|
73
|
+
const { rawMessage, EIP712Message } = message
|
|
74
|
+
assert(!!rawMessage !== !!EIP712Message, 'Need either rawMessage or EIP712Message')
|
|
75
|
+
|
|
76
|
+
const msgHash = EIP712Message
|
|
77
|
+
? getEIP712MessageHash(EIP712Message)
|
|
78
|
+
: hashPersonalMessage(rawMessage)
|
|
79
|
+
|
|
80
|
+
const sig = await signer.sign({
|
|
81
|
+
data: msgHash,
|
|
82
|
+
ecOptions: { canonical: true },
|
|
83
|
+
enc: 'raw',
|
|
84
|
+
})
|
|
85
|
+
|
|
86
|
+
return hex0xStringToBuffer(
|
|
87
|
+
concatSig(toBuffer(sig.recoveryParam), sig.r.toBuffer(), sig.s.toBuffer())
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
function getEIP712MessageHash(message) {
|
|
92
|
+
const version = Array.isArray(message) ? SignTypedDataVersion.V1 : SignTypedDataVersion.V4
|
|
93
|
+
return version === SignTypedDataVersion.V1
|
|
94
|
+
? hex0xStringToBuffer(typedSignatureHash(message))
|
|
95
|
+
: TypedDataUtils.eip712Hash(message, version)
|
|
96
|
+
}
|
|
@@ -11,7 +11,10 @@ export async function signUnsignedTxWithSigner(unsignedTx, signer) {
|
|
|
11
11
|
const tx = createEthereumJsTx(unsignedTx)
|
|
12
12
|
|
|
13
13
|
const ethSigner = async (data) => {
|
|
14
|
-
|
|
14
|
+
// temporarily support both function and object
|
|
15
|
+
const sig = await (typeof signer === 'function'
|
|
16
|
+
? signer({ data, ecOptions: { canonical: true }, enc: 'raw' })
|
|
17
|
+
: signer.sign({ data, ecOptions: { canonical: true }, enc: 'raw' }))
|
|
15
18
|
const signature = new Uint8Array(64)
|
|
16
19
|
signature.set(sig.r.toArrayLike(Uint8Array, 'be', 32), 0)
|
|
17
20
|
signature.set(sig.s.toArrayLike(Uint8Array, 'be', 32), 32)
|