@@ -3,9 +3,9 @@ const ethUtil = require('ethereumjs-util');
3
3
const erc165 = require ( './ABIs/ERC165' ) ;
4
4
const erc725Core = require ( './ABIs/ERC725Core' ) ;
5
5
6
- const erc725CoreInterfaceID = '0xd202158d' ;
7
- const erc725InterfaceID = '0xdc3d2a7b' ;
8
- const erc725ActionPurpose = 2 ;
6
+ const ERC725_CORE_INTERFACE_ID = '0xd202158d' ;
7
+ const ERC725_INTERFACE_ID = '0xdc3d2a7b' ;
8
+ const ERC725_ACTION_PURPOSE = 2 ;
9
9
10
10
module . exports = class DappAuth {
11
11
constructor ( web3Provider ) {
@@ -18,13 +18,8 @@ module.exports = class DappAuth {
18
18
) ;
19
19
20
20
// Get the address of whoever signed this message
21
- const signatureParams = ethUtil . fromRpcSig ( signature ) ;
22
- const recoveredKey = ethUtil . ecrecover (
23
- challengeHash ,
24
- signatureParams . v ,
25
- signatureParams . r ,
26
- signatureParams . s ,
27
- ) ;
21
+ const { v, r, s } = ethUtil . fromRpcSig ( signature ) ;
22
+ const recoveredKey = ethUtil . ecrecover ( challengeHash , v , r , s ) ;
28
23
const recoveredAddress = ethUtil . publicToAddress ( recoveredKey ) ;
29
24
30
25
// try direct-keyed wallet
@@ -36,44 +31,38 @@ module.exports = class DappAuth {
36
31
}
37
32
38
33
// try smart-contract wallet
39
- const isSupportedContract = await this . isSupportedContract ( address ) ;
34
+ const isSupportedContract = await this . _isSupportedContract ( address ) ;
40
35
if ( ! isSupportedContract ) {
41
36
return false ;
42
37
}
43
-
44
- const keyHasActionPurpose = await this . keyHasActionPurpose (
45
- address ,
46
- recoveredKey ,
47
- ) ;
48
-
49
- return keyHasActionPurpose ;
38
+ return this . _keyHasActionPurpose ( address , recoveredKey ) ;
50
39
}
51
40
52
- async keyHasActionPurpose ( contractAddr , key ) {
41
+ async _keyHasActionPurpose ( contractAddr , key ) {
53
42
const erc725CoreContract = new this . web3 . eth . Contract (
54
43
erc725Core ,
55
44
contractAddr ,
56
45
) ;
57
46
const keyHash = ethUtil . keccak ( key ) ;
58
47
59
48
return erc725CoreContract . methods
60
- . keyHasPurpose ( keyHash , erc725ActionPurpose )
49
+ . keyHasPurpose ( keyHash , ERC725_ACTION_PURPOSE )
61
50
. call ( ) ;
62
51
}
63
52
64
- async isSupportedContract ( contractAddr ) {
53
+ async _isSupportedContract ( contractAddr ) {
65
54
const erc165Contract = new this . web3 . eth . Contract ( erc165 , contractAddr ) ;
66
55
67
56
const isSupportsERC725CoreInterface = await erc165Contract . methods
68
- . supportsInterface ( erc725CoreInterfaceID )
57
+ . supportsInterface ( ERC725_CORE_INTERFACE_ID )
69
58
. call ( ) ;
70
59
71
60
if ( isSupportsERC725CoreInterface ) {
72
61
return true ;
73
62
}
74
63
75
64
const isSupportsERC725Interface = await erc165Contract . methods
76
- . supportsInterface ( erc725InterfaceID )
65
+ . supportsInterface ( ERC725_INTERFACE_ID )
77
66
. call ( ) ;
78
67
79
68
if ( isSupportsERC725Interface ) {
0 commit comments