-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
36 changed files
with
1,007 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
description: Asserts that the given value is a valid address | ||
--- | ||
|
||
# Address.assert | ||
|
||
**Alias:** `assertAddress` | ||
|
||
Asserts that the given value is a valid address. | ||
|
||
## Imports | ||
|
||
```ts twoslash | ||
// @noErrors | ||
// Named Module Import | ||
import { Address } from 'ox' | ||
|
||
// Module Imports | ||
import * as Address from 'ox/Address' | ||
import { assertAddress } from 'ox/Address' | ||
``` | ||
|
||
## Usage | ||
|
||
```ts twoslash | ||
// @noErrors | ||
import { Address } from 'ox'; | ||
|
||
Address.assert('0xa0cf798816d4b9b9866b5330eea46a18382f251e') | ||
|
||
Address.assert('0xa5cc3c03994db5b0d9a5eEdD10Cabab0813678ac') | ||
// Address "0xa5cc3c03994db5b0d9a5eEdD10Cabab0813678ac" is invalid. | ||
// | ||
// Details: Address does not match its checksum counterpart. | ||
|
||
Address.assert('0xa') | ||
// Address "0xa" is invalid. | ||
// | ||
// Details: Address is not a 20 byte hexadecimal value. | ||
``` | ||
|
||
## Returns | ||
|
||
`void` | ||
|
||
## Parameters | ||
|
||
### value | ||
|
||
- **Type:** `string` | ||
|
||
Value to assert if it is a valid address. | ||
|
||
```ts twoslash | ||
import { Address } from 'ox'; | ||
|
||
Address.assert( | ||
'0xa0cf798816d4b9b9866b5330eea46a18382f251e' // [!code focus] | ||
); | ||
``` | ||
|
||
## Parameters | ||
|
||
### options | ||
|
||
#### options.strict | ||
|
||
- **Type:** `boolean` | ||
- **Default:** `true` | ||
|
||
Enables strict mode. Whether or not to compare the address against its checksum. | ||
|
||
```ts twoslash | ||
import { Address } from 'ox'; | ||
|
||
Address.assert( | ||
'0xa0cf798816d4b9b9866b5330eea46a18382f251e', | ||
{ strict: false } // [!code focus] | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
--- | ||
description: Computes the checksum address for the given address | ||
--- | ||
|
||
# Address.checksum | ||
|
||
**Alias:** `checksumAddress` | ||
|
||
Computes the checksum address for the given address. | ||
|
||
## Imports | ||
|
||
```ts twoslash | ||
// @noErrors | ||
// Named Module Import | ||
import { Address } from 'ox' | ||
|
||
// Module Imports | ||
import * as Address from 'ox/Address' | ||
import { checksumAddress } from 'ox/Address' | ||
``` | ||
|
||
## Usage | ||
|
||
```ts twoslash | ||
// @noErrors | ||
import { Address } from 'ox'; | ||
|
||
Address.checksum('0xa0cf798816d4b9b9866b5330eea46a18382f251e') | ||
// '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e' | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
--- | ||
description: Converts an address string to a typed Address | ||
--- | ||
|
||
# Address.from | ||
|
||
**Alias:** `toAddress` | ||
|
||
Converts an address string to a typed (checksummed) Address. | ||
|
||
## Imports | ||
|
||
```ts twoslash | ||
// @noErrors | ||
// Named Module Import | ||
import { Address } from 'ox' | ||
|
||
// Module Imports | ||
import * as Address from 'ox/Address' | ||
import { toAddress } from 'ox/Address' | ||
``` | ||
|
||
## Usage | ||
|
||
```ts twoslash | ||
// @noErrors | ||
import { Address } from 'ox'; | ||
|
||
const address = Address.from('0xa0cf798816d4b9b9866b5330eea46a18382f251e') | ||
// '0xA0Cf798816D4b9b9866b5330EEa46a18382f251e' | ||
|
||
const address = Address.from( | ||
'0xa0cf798816d4b9b9866b5330eea46a18382f251e', | ||
{ checksum: false } | ||
) | ||
// '0xa0cf798816d4b9b9866b5330eea46a18382f251e' | ||
|
||
const address = Address.from('hello') | ||
// InvalidAddressError: Address "0xa" is invalid. | ||
``` | ||
|
||
## Return Type | ||
|
||
`Address` | ||
|
||
The checksummed Address. | ||
|
||
## Parameters | ||
|
||
### address | ||
|
||
- **Type:** `string` | ||
|
||
An address string to convert to a typed Address. | ||
|
||
```ts twoslash | ||
import { Address } from 'ox'; | ||
|
||
const address = Address.from( | ||
'0xa0cf798816d4b9b9866b5330eea46a18382f251e' // [!code focus] | ||
); | ||
``` | ||
|
||
### options | ||
|
||
#### options.checksum | ||
|
||
- **Type:** `boolean` | ||
|
||
Whether to checksum the address. | ||
|
||
```ts twoslash | ||
import { Address } from 'ox'; | ||
|
||
const address = Address.from( | ||
'0xa0cf798816d4b9b9866b5330eea46a18382f251e', | ||
{ checksum: false } // [!code focus] | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,19 @@ | ||
# Address | ||
|
||
TODO | ||
The **Address** Module provides a set of utility functions for working with Ethereum addresses. | ||
|
||
## Type | ||
|
||
**Address** can be represented via the `Address` type. It is a JavaScript `string` primitive with a `"0x"` prefix. | ||
|
||
```ts twoslash | ||
// @noErrors | ||
import { Address } from 'ox' | ||
|
||
const address = Address.from('0xa0cf798816d4b9b9866b5330eea46a18382f251e') | ||
satisfies Address.Address | ||
// ^? | ||
|
||
|
||
|
||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
--- | ||
description: Checks if the given address is a valid address | ||
--- | ||
|
||
# Address.isAddress | ||
|
||
Checks if the given address is a valid address. | ||
|
||
## Imports | ||
|
||
```ts twoslash | ||
// @noErrors | ||
// Named Module Import | ||
import { Address } from 'ox' | ||
|
||
// Module Imports | ||
import * as Address from 'ox/Address' | ||
import { isAddress } from 'ox/Address' | ||
``` | ||
|
||
## Usage | ||
|
||
```ts twoslash | ||
// @noErrors | ||
import { Address } from 'ox'; | ||
|
||
const isAddress = Address.isAddress('0xA0Cf798816D4b9b9866b5330EEa46a18382f251e') | ||
// true | ||
|
||
const isAddress = Address.isAddress('0xdeadbeef') | ||
// false | ||
``` | ||
|
||
## Return Type | ||
|
||
`boolean` | ||
|
||
Whether the address is a valid address. | ||
|
||
## Parameters | ||
|
||
### value | ||
|
||
- **Type:** `string` | ||
|
||
Value to check if it is a valid address. | ||
|
||
```ts twoslash | ||
import { Address } from 'ox'; | ||
|
||
const isAddress = Address.isAddress( | ||
'0xa0cf798816d4b9b9866b5330eea46a18382f251e' // [!code focus] | ||
); | ||
``` | ||
|
||
### options | ||
|
||
#### options.strict | ||
|
||
- **Type:** `boolean` | ||
- **Default:** `true` | ||
|
||
Enables strict mode. Whether or not to compare the address against its checksum. | ||
|
||
```ts twoslash | ||
import { Address } from 'ox'; | ||
|
||
const address = Address.isAddress( | ||
'0xa0cf798816d4b9b9866b5330eea46a18382f251e', | ||
{ strict: false } // [!code focus] | ||
); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
--- | ||
description: Checks if two addresses are equal | ||
--- | ||
|
||
# Address.isEqual | ||
|
||
**Alias:** `isAddressEqual` | ||
|
||
Checks if two addresses are equal. | ||
|
||
## Imports | ||
|
||
```ts twoslash | ||
// @noErrors | ||
// Named Module Import | ||
import { Address } from 'ox' | ||
|
||
// Module Imports | ||
import * as Address from 'ox/Address' | ||
import { isAddressEqual } from 'ox/Address' | ||
``` | ||
|
||
## Usage | ||
|
||
```ts twoslash | ||
// @noErrors | ||
import { Address } from 'ox'; | ||
|
||
const isEqual = Address.isEqual( | ||
'0xa0cf798816d4b9b9866b5330eea46a18382f251e', | ||
'0xA0Cf798816D4b9b9866b5330EEa46a18382f251e' | ||
) | ||
// true | ||
|
||
const isEqual = Address.isEqual( | ||
'0xa0cf798816d4b9b9866b5330eea46a18382f251e', | ||
'0xA0Cf798816D4b9b9866b5330EEa46a18382f251f' | ||
) | ||
// false | ||
``` | ||
|
||
## Return Type | ||
|
||
`boolean` | ||
|
||
Whether the addresses are equal. |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.