@exodus/ethereum-lib 5.0.0 → 5.0.1
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 +2 -2
- package/src/sign-message.js +6 -1
- package/src/utils/ecdsa.js +28 -0
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@exodus/ethereum-lib",
|
|
3
|
-
"version": "5.0.
|
|
3
|
+
"version": "5.0.1",
|
|
4
4
|
"description": "Ethereum Library",
|
|
5
5
|
"main": "src/index.js",
|
|
6
6
|
"files": [
|
|
@@ -49,5 +49,5 @@
|
|
|
49
49
|
"@exodus/ethereumclassic-meta": "^1.0.3",
|
|
50
50
|
"@exodus/fantommainnet-meta": "^1.1.2"
|
|
51
51
|
},
|
|
52
|
-
"gitHead": "
|
|
52
|
+
"gitHead": "6c650d072cc04a4733f99e824a979530d1cd5302"
|
|
53
53
|
}
|
package/src/sign-message.js
CHANGED
|
@@ -8,6 +8,7 @@ import {
|
|
|
8
8
|
concatSig,
|
|
9
9
|
} from '@metamask/eth-sig-util'
|
|
10
10
|
import { hashPersonalMessage, toBuffer } from '@exodus/ethereumjs-util'
|
|
11
|
+
import { normalizeRecoveryParam } from './utils/ecdsa'
|
|
11
12
|
|
|
12
13
|
function hex0xStringToBuffer(hex) {
|
|
13
14
|
// Remove the 0x
|
|
@@ -85,7 +86,11 @@ export async function signMessageWithSigner({ message, signer }) {
|
|
|
85
86
|
})
|
|
86
87
|
|
|
87
88
|
return hex0xStringToBuffer(
|
|
88
|
-
concatSig(
|
|
89
|
+
concatSig(
|
|
90
|
+
toBuffer(normalizeRecoveryParam(sig.recoveryParam, { includeBase: true })),
|
|
91
|
+
sig.r.toBuffer(),
|
|
92
|
+
sig.s.toBuffer()
|
|
93
|
+
)
|
|
89
94
|
)
|
|
90
95
|
}
|
|
91
96
|
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import assert from 'minimalistic-assert'
|
|
2
|
+
|
|
3
|
+
const ECDSA_RECOVERY_ID_BASE = 27
|
|
4
|
+
const ALLOWED_VALUES = new Set([27, 28])
|
|
5
|
+
const ALLOWED_VALUES_WITHOUT_BASE = new Set([0, 1])
|
|
6
|
+
|
|
7
|
+
/*
|
|
8
|
+
@exodus/elliptic returns signatures that have a recoverParam that is either 0 or 1.
|
|
9
|
+
In the literature this is called recovery id. To get the value of v (which is the full recovery param)
|
|
10
|
+
a fixed offset of 27 is added. The value our asset libraries expect is a little all over the place, so we have
|
|
11
|
+
to either remove or add the offset again, depending on where we pass it. This helper can be used to harden our
|
|
12
|
+
methods to transform the recovery param to the format we expect, so consumers don't have to think about that.
|
|
13
|
+
|
|
14
|
+
The recovery param is not strictly necessary to recover the public key,
|
|
15
|
+
so in case we end up with a recovery param that is not 0 or 1, we return undefined
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export const normalizeRecoveryParam = (v, { includeBase = false } = {}) => {
|
|
19
|
+
const { allowedValues, offset } = includeBase
|
|
20
|
+
? { allowedValues: ALLOWED_VALUES, offset: ECDSA_RECOVERY_ID_BASE }
|
|
21
|
+
: { allowedValues: ALLOWED_VALUES_WITHOUT_BASE, offset: -ECDSA_RECOVERY_ID_BASE }
|
|
22
|
+
|
|
23
|
+
if (allowedValues.has(v)) return v
|
|
24
|
+
|
|
25
|
+
const param = v + offset
|
|
26
|
+
assert(allowedValues.has(param), `Failed to normalize unexpected recoveryParam ${v}`)
|
|
27
|
+
return param
|
|
28
|
+
}
|