ethers.js/docs.wrm/api/utils/encoding.wrm
2021-06-10 17:38:38 -04:00

128 lines
2.8 KiB
Plaintext

_section: Encoding Utilities @<encoding>
_subsection: Base58 @<Bse58> @SRC<basex:Base58>
_property: ethers.utils.base58.decode(textData) => Uint8Array
Return a typed Uint8Array representation of //textData// decoded using
base-58 encoding.
_code: @lang<javascript>
//_hide: const base58 = ethers.utils.base58;
//_result:
base58.decode("TzMhH");
//_log:
_property: ethers.utils.base58.encode(aBytesLike) => string
Return //aBytesLike// encoded as a string using the base-58 encoding.
_code: @lang<javascript>
//_hide: const base58 = ethers.utils.base58;
//_result:
base58.encode("0x12345678");
//_log:
//_result:
base58.encode([ 0x12, 0x34, 0x56, 0x78 ]);
//_log:
_subsection: Base64 @<Base64>
_property: ethers.utils.base64.decode(textData) => Uint8Array @SRC<base64>
Return a typed Uint8Array representation of //textData// decoded using
base-64 encoding.
_code: @lang<javascript>
//_hide: const base64 = ethers.utils.base64;
//_result:
base64.decode("EjQ=");
//_log:
_property: ethers.utils.base64.encode(aBytesLike) => string @SRC<base64>
Return //aBytesLike// encoded as a string using the base-64 encoding.
_code: @lang<javascript>
//_hide: const base64 = ethers.utils.base64;
//_result:
base64.encode("0x1234");
//_log:
//_result:
base64.encode([ 0x12, 0x34 ]);
//_log:
_subsection: Recursive-Length Prefix @<rlp--methods>
The [[link-rlp]] encoding is used throughout Ethereum to serialize nested
structures of Arrays and data.
_property: ethers.utils.RLP.encode(dataObject) => string<[[DataHexString]]> @<utils-rlpEncode> @SRC<rlp>
Encode a structured [Data Object](rlp--dataobject) into its RLP-encoded representation.
_code: @lang<javascript>
//_hide: const RLP = ethers.utils.RLP;
//_result:
RLP.encode("0x12345678");
//_log:
//_result:
RLP.encode([ "0x12345678" ]);
//_log:
//_result:
RLP.encode([ new Uint8Array([ 0x12, 0x34, 0x56, 0x78 ]) ]);
//_log:
//_result:
RLP.encode([ [ "0x42", [ "0x43" ] ], "0x12345678", [ ] ]);
//_log:
//_result:
RLP.encode([ ]);
//_log:
_property: ethers.utils.RLP.decode(aBytesLike) => [DataObject](rlp--dataobject) @<utils.rlpDecode> @SRC<rlp>
Decode an RLP-encoded //aBytesLike// into its structured [Data Object](rlp--dataobject).
All Data components will be returned as a [[DataHexString]].
_code: @lang<javascript>
//_hide: const RLP = ethers.utils.RLP;
//_result:
RLP.decode("0x8412345678");
//_log:
//_result:
RLP.decode("0xcac342c1438412345678c0");
//_log:
//_result:
RLP.decode("0xc0");
//_log:
_heading: Data Object @<rlp--dataobject>
A **Data Object** is a recursive structure which is used to serialize many
internal structures in Ethereum. Each **Data Object** can either be:
- Binary Data
- An Array of **Data Objects** (i.e. this recursively includes Nesting)
_definition: **Examples**
- ``"0x1234"``
- ``[ "0x1234", [ "0xdead", "0xbeef" ], [ ] ]``