Skip to content

Commit

Permalink
hex readme
Browse files Browse the repository at this point in the history
  • Loading branch information
TateB committed Jan 30, 2024
1 parent 2a25538 commit 7653660
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,27 @@ const encodedAddress = btcCoder.encode(decodedAddress);
// 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
```

### Hex String Encoding

If the data you are encoding is a hex string rather than `Uint8Array`, you can use the included `hexToBytes()` to convert it to the correct type.

```ts
import { getCoderByCoinName } from "@ensdomains/address-encoder";
import { hexToBytes } from "@ensdomains/address-encoder/utils";

const btcCoder = getCoderByCoinName("btc");

// Convert hex encoded data to bytes
const dataAsBytes = hexToBytes(
"0x76a91462e907b15cbf27d5425399ebf6f0fb50ebb88f1888ac"
);
// Uint8Array(25) [ 118, 169, 20, 98, 233, 7, 177, 92, 191, 39, 213, 66, 83, 153, 235, 246, 240, 251, 80, 235, 184, 143, 24, 136, 172 ]

// Pass bytes to encoder
const encodedAddress = btcCoder.encode(decodedAddress);
// 1A1zP1eP5QGefi2DMPTfTL5SLmv7DivfNa
```

## Supported Cryptocurrencies

To view all the supported cryptocurrencies of this library, see [here](https://github.com/ensdomains/address-encoder/blob/master/docs/supported-cryptocurrencies.md).
Expand Down
1 change: 1 addition & 0 deletions src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ export {
type BitcoinCoderParameters,
} from "./bitcoin.js";
export { byronDecode, byronEncode } from "./byron.js";
export { bytesToHex, hexToBytes } from "./bytes.js";
export { SimpleValue, TaggedValue, cborDecode, cborEncode } from "./cbor.js";
export { crc32 } from "./crc32.js";
export { createDotAddressDecoder, createDotAddressEncoder } from "./dot.js";
Expand Down

0 comments on commit 7653660

Please sign in to comment.