Skip to content
This repository was archived by the owner on Jun 17, 2021. It is now read-only.

Commit beecf2d

Browse files
committed
Update EIP1191 doc
1 parent a91eaf3 commit beecf2d

File tree

2 files changed

+31
-26
lines changed

2 files changed

+31
-26
lines changed

docs/README.md

Lines changed: 20 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ ___
165165

166166
**● publicToAddress**: *[pubToAddress]()* = pubToAddress
167167

168-
*Defined in [account.ts:160](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L160)*
168+
*Defined in [account.ts:163](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L163)*
169169

170170
___
171171
<a id="setlength"></a>
@@ -376,7 +376,7 @@ ___
376376

377377
**generateAddress**(from: *`Buffer`*, nonce: *`Buffer`*): `Buffer`
378378

379-
*Defined in [account.ts:72](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L72)*
379+
*Defined in [account.ts:75](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L75)*
380380

381381
Generates an address of a newly created contract.
382382

@@ -396,7 +396,7 @@ ___
396396

397397
**generateAddress2**(from: *`Buffer` \| `string`*, salt: *`Buffer` \| `string`*, initCode: *`Buffer` \| `string`*): `Buffer`
398398

399-
*Defined in [account.ts:92](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L92)*
399+
*Defined in [account.ts:95](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L95)*
400400

401401
Generates an address for a contract created using CREATE2.
402402

@@ -436,7 +436,7 @@ ___
436436

437437
**importPublic**(publicKey: *`Buffer`*): `Buffer`
438438

439-
*Defined in [account.ts:183](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L183)*
439+
*Defined in [account.ts:186](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L186)*
440440

441441
Converts a public key to the Ethereum format.
442442

@@ -455,7 +455,7 @@ ___
455455

456456
**isPrecompiled**(address: *`Buffer` \| `string`*): `boolean`
457457

458-
*Defined in [account.ts:114](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L114)*
458+
*Defined in [account.ts:117](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L117)*
459459

460460
Returns true if the supplied address belongs to a precompiled account (Byzantium).
461461

@@ -491,20 +491,20 @@ ___
491491

492492
### `<Const>` isValidChecksumAddress
493493

494-
**isValidChecksumAddress**(address: *`string`*, chainId?: *`undefined` \| `number`*): `boolean`
494+
**isValidChecksumAddress**(address: *`string`*, eip1191ChainId?: *`undefined` \| `number`*): `boolean`
495495

496-
*Defined in [account.ts:63](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L63)*
496+
*Defined in [account.ts:66](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L66)*
497497

498498
Checks if the address is a valid checksummed address.
499499

500-
If a chainId is provided, the address is compared to an EIP-1191 checksum. Otherwise, it will be compared to an EIP-55 checksum.
500+
See toChecksumAddress' documentation for details about the eip1191ChainId parameter.
501501

502502
**Parameters:**
503503

504504
| Name | Type |
505505
| ------ | ------ |
506506
| address | `string` |
507-
| `Optional` chainId | `undefined` \| `number` |
507+
| `Optional` eip1191ChainId | `undefined` \| `number` |
508508

509509
**Returns:** `boolean`
510510

@@ -515,7 +515,7 @@ ___
515515

516516
**isValidPrivate**(privateKey: *`Buffer`*): `boolean`
517517

518-
*Defined in [account.ts:122](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L122)*
518+
*Defined in [account.ts:125](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L125)*
519519

520520
Checks if the private key satisfies the rules of the curve secp256k1.
521521

@@ -534,7 +534,7 @@ ___
534534

535535
**isValidPublic**(publicKey: *`Buffer`*, sanitize?: *`boolean`*): `boolean`
536536

537-
*Defined in [account.ts:132](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L132)*
537+
*Defined in [account.ts:135](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L135)*
538538

539539
Checks if the public key satisfies the rules of the curve secp256k1 and the requirements of Ethereum.
540540

@@ -635,7 +635,7 @@ ___
635635

636636
**privateToAddress**(privateKey: *`Buffer`*): `Buffer`
637637

638-
*Defined in [account.ts:166](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L166)*
638+
*Defined in [account.ts:169](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L169)*
639639

640640
Returns the ethereum address of a given private key.
641641

@@ -654,7 +654,7 @@ ___
654654

655655
**privateToPublic**(privateKey: *`Buffer`*): `Buffer`
656656

657-
*Defined in [account.ts:174](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L174)*
657+
*Defined in [account.ts:177](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L177)*
658658

659659
Returns the ethereum public key of a given private key.
660660

@@ -673,7 +673,7 @@ ___
673673

674674
**pubToAddress**(pubKey: *`Buffer`*, sanitize?: *`boolean`*): `Buffer`
675675

676-
*Defined in [account.ts:151](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L151)*
676+
*Defined in [account.ts:154](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L154)*
677677

678678
Returns the ethereum address of a given public key. Accepts "Ethereum public keys" and SEC1 encoded keys.
679679

@@ -811,20 +811,22 @@ ___
811811

812812
### `<Const>` toChecksumAddress
813813

814-
**toChecksumAddress**(address: *`string`*, chainId?: *`undefined` \| `number`*): `string`
814+
**toChecksumAddress**(address: *`string`*, eip1191ChainId?: *`undefined` \| `number`*): `string`
815815

816-
*Defined in [account.ts:38](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L38)*
816+
*Defined in [account.ts:42](https://github.com/ethereumjs/ethereumjs-util/blob/master/src/account.ts#L42)*
817817

818818
Returns a checksummed address.
819819

820-
If a chainId is provided, the result will be an EIP-1191 checksum. Otherwise, it will be an EIP-55 checksum.
820+
If a eip1191ChainId is provided, the chainId will be included in the checksum calculation. This has the effect of checksummed addresses for one chain having invalid checksums for others. For more details, consult EIP-1191.
821+
822+
WARNING: Checksums with and without the chainId will differ. As of 2019-06-26, the most commonly used variation in Ethereum was without the chainId. This may change in the future.
821823

822824
**Parameters:**
823825

824826
| Name | Type |
825827
| ------ | ------ |
826828
| address | `string` |
827-
| `Optional` chainId | `undefined` \| `number` |
829+
| `Optional` eip1191ChainId | `undefined` \| `number` |
828830

829831
**Returns:** `string`
830832

src/account.ts

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,13 +32,17 @@ export const isZeroAddress = function(address: string): boolean {
3232
/**
3333
* Returns a checksummed address.
3434
*
35-
* If a chainId is provided, the result will be an EIP-1191 checksum. Otherwise, it will be an
36-
* EIP-55 checksum.
35+
* If a eip1191ChainId is provided, the chainId will be included in the checksum calculation. This
36+
* has the effect of checksummed addresses for one chain having invalid checksums for others.
37+
* For more details, consult EIP-1191.
38+
*
39+
* WARNING: Checksums with and without the chainId will differ. As of 2019-06-26, the most commonly
40+
* used variation in Ethereum was without the chainId. This may change in the future.
3741
*/
38-
export const toChecksumAddress = function(address: string, chainId?: number): string {
42+
export const toChecksumAddress = function(address: string, eip1191ChainId?: number): string {
3943
address = ethjsUtil.stripHexPrefix(address).toLowerCase()
4044

41-
const prefix = chainId !== undefined ? chainId.toString() + '0x' : ''
45+
const prefix = eip1191ChainId !== undefined ? eip1191ChainId.toString() + '0x' : ''
4246

4347
const hash = keccak(prefix + address).toString('hex')
4448
let ret = '0x'
@@ -57,11 +61,10 @@ export const toChecksumAddress = function(address: string, chainId?: number): st
5761
/**
5862
* Checks if the address is a valid checksummed address.
5963
*
60-
* If a chainId is provided, the address is compared to an EIP-1191 checksum. Otherwise, it will be
61-
* compared to an EIP-55 checksum.
64+
* See toChecksumAddress' documentation for details about the eip1191ChainId parameter.
6265
*/
63-
export const isValidChecksumAddress = function(address: string, chainId?: number): boolean {
64-
return isValidAddress(address) && toChecksumAddress(address, chainId) === address
66+
export const isValidChecksumAddress = function(address: string, eip1191ChainId?: number): boolean {
67+
return isValidAddress(address) && toChecksumAddress(address, eip1191ChainId) === address
6568
}
6669

6770
/**

0 commit comments

Comments
 (0)