1
- import * as assert from 'assert'
2
- import * as BN from 'bn.js'
1
+ import assert from 'assert'
2
+ import BN from 'bn.js'
3
3
import * as rlp from 'rlp'
4
4
import { stripHexPrefix } from 'ethjs-util'
5
5
import { KECCAK256_RLP , KECCAK256_NULL } from './constants'
@@ -12,7 +12,7 @@ const {
12
12
privateKeyVerify,
13
13
publicKeyCreate,
14
14
publicKeyVerify,
15
- publicKeyConvert,
15
+ publicKeyConvert
16
16
} = require ( 'ethereum-cryptography/secp256k1' )
17
17
18
18
export interface AccountData {
@@ -35,7 +35,7 @@ export class Account {
35
35
nonce ? new BN ( toBuffer ( nonce ) ) : undefined ,
36
36
balance ? new BN ( toBuffer ( balance ) ) : undefined ,
37
37
stateRoot ? toBuffer ( stateRoot ) : undefined ,
38
- codeHash ? toBuffer ( codeHash ) : undefined ,
38
+ codeHash ? toBuffer ( codeHash ) : undefined
39
39
)
40
40
}
41
41
@@ -52,12 +52,7 @@ export class Account {
52
52
public static fromValuesArray ( values : Buffer [ ] ) {
53
53
const [ nonce , balance , stateRoot , codeHash ] = values
54
54
55
- return new Account (
56
- nonce ? new BN ( nonce ) : undefined ,
57
- balance ? new BN ( balance ) : undefined ,
58
- stateRoot ,
59
- codeHash ,
60
- )
55
+ return new Account ( new BN ( nonce ) , new BN ( balance ) , stateRoot , codeHash )
61
56
}
62
57
63
58
/**
@@ -68,7 +63,7 @@ export class Account {
68
63
nonce = new BN ( 0 ) ,
69
64
balance = new BN ( 0 ) ,
70
65
stateRoot = KECCAK256_RLP ,
71
- codeHash = KECCAK256_NULL ,
66
+ codeHash = KECCAK256_NULL
72
67
) {
73
68
this . nonce = nonce
74
69
this . balance = balance
@@ -169,7 +164,7 @@ export const toChecksumAddress = function(hexAddress: string, eip1191ChainId?: n
169
164
*/
170
165
export const isValidChecksumAddress = function (
171
166
hexAddress : string ,
172
- eip1191ChainId ?: number ,
167
+ eip1191ChainId ?: number
173
168
) : boolean {
174
169
return isValidAddress ( hexAddress ) && toChecksumAddress ( hexAddress , eip1191ChainId ) === hexAddress
175
170
}
@@ -209,7 +204,7 @@ export const generateAddress2 = function(from: Buffer, salt: Buffer, initCode: B
209
204
assert ( salt . length === 32 )
210
205
211
206
const address = keccak256 (
212
- Buffer . concat ( [ Buffer . from ( 'ff' , 'hex' ) , from , salt , keccak256 ( initCode ) ] ) ,
207
+ Buffer . concat ( [ Buffer . from ( 'ff' , 'hex' ) , from , salt , keccak256 ( initCode ) ] )
213
208
)
214
209
215
210
return address . slice ( - 20 )
@@ -259,14 +254,6 @@ export const pubToAddress = function(pubKey: Buffer, sanitize: boolean = false):
259
254
}
260
255
export const publicToAddress = pubToAddress
261
256
262
- /**
263
- * Returns the ethereum address of a given private key.
264
- * @param privateKey A private key must be 256 bits wide
265
- */
266
- export const privateToAddress = function ( privateKey : Buffer ) : Buffer {
267
- return publicToAddress ( privateToPublic ( privateKey ) )
268
- }
269
-
270
257
/**
271
258
* Returns the ethereum public key of a given private key.
272
259
* @param privateKey A private key must be 256 bits wide
@@ -277,6 +264,14 @@ export const privateToPublic = function(privateKey: Buffer): Buffer {
277
264
return Buffer . from ( publicKeyCreate ( privateKey , false ) ) . slice ( 1 )
278
265
}
279
266
267
+ /**
268
+ * Returns the ethereum address of a given private key.
269
+ * @param privateKey A private key must be 256 bits wide
270
+ */
271
+ export const privateToAddress = function ( privateKey : Buffer ) : Buffer {
272
+ return publicToAddress ( privateToPublic ( privateKey ) )
273
+ }
274
+
280
275
/**
281
276
* Converts a public key to the Ethereum format.
282
277
*/
0 commit comments