5
5
privateKeyVerify ,
6
6
publicKeyCreate ,
7
7
publicKeyVerify ,
8
- publicKeyConvert
8
+ publicKeyConvert ,
9
9
} from 'ethereum-cryptography/secp256k1'
10
10
import { stripHexPrefix } from 'ethjs-util'
11
11
import { KECCAK256_RLP , KECCAK256_NULL } from './constants'
@@ -121,7 +121,7 @@ export class Account {
121
121
/**
122
122
* Checks if the address is a valid. Accepts checksummed addresses too.
123
123
*/
124
- export const isValidAddress = function ( hexAddress : string ) : boolean {
124
+ export const isValidAddress = function ( hexAddress : string ) : boolean {
125
125
assertIsHexString ( hexAddress )
126
126
return / ^ 0 x [ 0 - 9 a - f A - F ] { 40 } $ / . test ( hexAddress )
127
127
}
@@ -136,7 +136,7 @@ export const isValidAddress = function(hexAddress: string): boolean {
136
136
* WARNING: Checksums with and without the chainId will differ. As of 2019-06-26, the most commonly
137
137
* used variation in Ethereum was without the chainId. This may change in the future.
138
138
*/
139
- export const toChecksumAddress = function ( hexAddress : string , eip1191ChainId ?: BNLike ) : string {
139
+ export const toChecksumAddress = function ( hexAddress : string , eip1191ChainId ?: BNLike ) : string {
140
140
assertIsHexString ( hexAddress )
141
141
const address = stripHexPrefix ( hexAddress ) . toLowerCase ( )
142
142
@@ -165,7 +165,7 @@ export const toChecksumAddress = function(hexAddress: string, eip1191ChainId?: B
165
165
*
166
166
* See toChecksumAddress' documentation for details about the eip1191ChainId parameter.
167
167
*/
168
- export const isValidChecksumAddress = function (
168
+ export const isValidChecksumAddress = function (
169
169
hexAddress : string ,
170
170
eip1191ChainId ?: BNLike
171
171
) : boolean {
@@ -177,7 +177,7 @@ export const isValidChecksumAddress = function(
177
177
* @param from The address which is creating this new address
178
178
* @param nonce The nonce of the from account
179
179
*/
180
- export const generateAddress = function ( from : Buffer , nonce : Buffer ) : Buffer {
180
+ export const generateAddress = function ( from : Buffer , nonce : Buffer ) : Buffer {
181
181
assertIsBuffer ( from )
182
182
assertIsBuffer ( nonce )
183
183
const nonceBN = new BN ( nonce )
@@ -198,7 +198,7 @@ export const generateAddress = function(from: Buffer, nonce: Buffer): Buffer {
198
198
* @param salt A salt
199
199
* @param initCode The init code of the contract being created
200
200
*/
201
- export const generateAddress2 = function ( from : Buffer , salt : Buffer , initCode : Buffer ) : Buffer {
201
+ export const generateAddress2 = function ( from : Buffer , salt : Buffer , initCode : Buffer ) : Buffer {
202
202
assertIsBuffer ( from )
203
203
assertIsBuffer ( salt )
204
204
assertIsBuffer ( initCode )
@@ -216,7 +216,7 @@ export const generateAddress2 = function(from: Buffer, salt: Buffer, initCode: B
216
216
/**
217
217
* Checks if the private key satisfies the rules of the curve secp256k1.
218
218
*/
219
- export const isValidPrivate = function ( privateKey : Buffer ) : boolean {
219
+ export const isValidPrivate = function ( privateKey : Buffer ) : boolean {
220
220
return privateKeyVerify ( privateKey )
221
221
}
222
222
@@ -226,7 +226,7 @@ export const isValidPrivate = function(privateKey: Buffer): boolean {
226
226
* @param publicKey The two points of an uncompressed key, unless sanitize is enabled
227
227
* @param sanitize Accept public keys in other formats
228
228
*/
229
- export const isValidPublic = function ( publicKey : Buffer , sanitize : boolean = false ) : boolean {
229
+ export const isValidPublic = function ( publicKey : Buffer , sanitize : boolean = false ) : boolean {
230
230
assertIsBuffer ( publicKey )
231
231
if ( publicKey . length === 64 ) {
232
232
// Convert to SEC1 for secp256k1
@@ -246,7 +246,7 @@ export const isValidPublic = function(publicKey: Buffer, sanitize: boolean = fal
246
246
* @param pubKey The two points of an uncompressed key, unless sanitize is enabled
247
247
* @param sanitize Accept public keys in other formats
248
248
*/
249
- export const pubToAddress = function ( pubKey : Buffer , sanitize : boolean = false ) : Buffer {
249
+ export const pubToAddress = function ( pubKey : Buffer , sanitize : boolean = false ) : Buffer {
250
250
assertIsBuffer ( pubKey )
251
251
if ( sanitize && pubKey . length !== 64 ) {
252
252
pubKey = Buffer . from ( publicKeyConvert ( pubKey , false ) . slice ( 1 ) )
@@ -261,7 +261,7 @@ export const publicToAddress = pubToAddress
261
261
* Returns the ethereum public key of a given private key.
262
262
* @param privateKey A private key must be 256 bits wide
263
263
*/
264
- export const privateToPublic = function ( privateKey : Buffer ) : Buffer {
264
+ export const privateToPublic = function ( privateKey : Buffer ) : Buffer {
265
265
assertIsBuffer ( privateKey )
266
266
// skip the type flag and use the X, Y points
267
267
return Buffer . from ( publicKeyCreate ( privateKey , false ) ) . slice ( 1 )
@@ -271,14 +271,14 @@ export const privateToPublic = function(privateKey: Buffer): Buffer {
271
271
* Returns the ethereum address of a given private key.
272
272
* @param privateKey A private key must be 256 bits wide
273
273
*/
274
- export const privateToAddress = function ( privateKey : Buffer ) : Buffer {
274
+ export const privateToAddress = function ( privateKey : Buffer ) : Buffer {
275
275
return publicToAddress ( privateToPublic ( privateKey ) )
276
276
}
277
277
278
278
/**
279
279
* Converts a public key to the Ethereum format.
280
280
*/
281
- export const importPublic = function ( publicKey : Buffer ) : Buffer {
281
+ export const importPublic = function ( publicKey : Buffer ) : Buffer {
282
282
assertIsBuffer ( publicKey )
283
283
if ( publicKey . length !== 64 ) {
284
284
publicKey = Buffer . from ( publicKeyConvert ( publicKey , false ) . slice ( 1 ) )
@@ -289,7 +289,7 @@ export const importPublic = function(publicKey: Buffer): Buffer {
289
289
/**
290
290
* Returns the zero address.
291
291
*/
292
- export const zeroAddress = function ( ) : string {
292
+ export const zeroAddress = function ( ) : string {
293
293
const addressLength = 20
294
294
const addr = zeros ( addressLength )
295
295
return bufferToHex ( addr )
@@ -298,7 +298,7 @@ export const zeroAddress = function(): string {
298
298
/**
299
299
* Checks if a given address is the zero address.
300
300
*/
301
- export const isZeroAddress = function ( hexAddress : string ) : boolean {
301
+ export const isZeroAddress = function ( hexAddress : string ) : boolean {
302
302
assertIsHexString ( hexAddress )
303
303
const zeroAddr = zeroAddress ( )
304
304
return zeroAddr === hexAddress
0 commit comments