@@ -23,6 +23,13 @@ const FUTURE_SEGWIT_VERSION_WARNING =
2323 'End users MUST be warned carefully in the GUI and asked if they wish to proceed ' +
2424 'with caution. Wallets should verify the segwit version from the output of fromBech32, ' +
2525 'then decide when it is safe to use which version of segwit.' ;
26+ /**
27+ * Converts an output buffer to a future segwit address.
28+ * @param output - The output buffer.
29+ * @param network - The network object.
30+ * @returns The future segwit address.
31+ * @throws {TypeError } If the program length or version is invalid for segwit address.
32+ */
2633function _toFutureSegwitAddress ( output , network ) {
2734 const data = output . slice ( 2 ) ;
2835 if (
@@ -42,7 +49,11 @@ function _toFutureSegwitAddress(output, network) {
4249 return toBech32 ( data , version , network . bech32 ) ;
4350}
4451/**
45- * decode address with base58 specification, return address version and address hash if valid
52+ * Decodes a base58check encoded Bitcoin address and returns the version and hash.
53+ *
54+ * @param address - The base58check encoded Bitcoin address to decode.
55+ * @returns An object containing the version and hash of the decoded address.
56+ * @throws {TypeError } If the address is too short or too long.
4657 */
4758function fromBase58Check ( address ) {
4859 const payload = Buffer . from ( bs58check . decode ( address ) ) ;
@@ -55,7 +66,10 @@ function fromBase58Check(address) {
5566}
5667exports . fromBase58Check = fromBase58Check ;
5768/**
58- * decode address with bech32 specification, return address version、address prefix and address data if valid
69+ * Converts a Bech32 or Bech32m encoded address to its corresponding data representation.
70+ * @param address - The Bech32 or Bech32m encoded address.
71+ * @returns An object containing the version, prefix, and data of the address.
72+ * @throws {TypeError } If the address uses the wrong encoding.
5973 */
6074function fromBech32 ( address ) {
6175 let result ;
@@ -80,7 +94,10 @@ function fromBech32(address) {
8094}
8195exports . fromBech32 = fromBech32 ;
8296/**
83- * encode address hash to base58 address with version
97+ * Converts a hash to a Base58Check-encoded string.
98+ * @param hash - The hash to be encoded.
99+ * @param version - The version byte to be prepended to the encoded string.
100+ * @returns The Base58Check-encoded string.
84101 */
85102function toBase58Check ( hash , version ) {
86103 ( 0 , types_1 . typeforce ) (
@@ -94,7 +111,11 @@ function toBase58Check(hash, version) {
94111}
95112exports . toBase58Check = toBase58Check ;
96113/**
97- * encode address hash to bech32 address with version and prefix
114+ * Converts a buffer to a Bech32 or Bech32m encoded string.
115+ * @param data - The buffer to be encoded.
116+ * @param version - The version number to be used in the encoding.
117+ * @param prefix - The prefix string to be used in the encoding.
118+ * @returns The Bech32 or Bech32m encoded string.
98119 */
99120function toBech32 ( data , version , prefix ) {
100121 const words = bech32_1 . bech32 . toWords ( data ) ;
@@ -105,7 +126,11 @@ function toBech32(data, version, prefix) {
105126}
106127exports . toBech32 = toBech32 ;
107128/**
108- * decode address from output script with network, return address if matched
129+ * Converts an output script to a Bitcoin address.
130+ * @param output - The output script as a Buffer.
131+ * @param network - The Bitcoin network (optional).
132+ * @returns The Bitcoin address corresponding to the output script.
133+ * @throws If the output script has no matching address.
109134 */
110135function fromOutputScript ( output , network ) {
111136 // TODO: Network
@@ -132,7 +157,11 @@ function fromOutputScript(output, network) {
132157}
133158exports . fromOutputScript = fromOutputScript ;
134159/**
135- * encodes address to output script with network, return output script if address matched
160+ * Converts a Bitcoin address to its corresponding output script.
161+ * @param address - The Bitcoin address to convert.
162+ * @param network - The Bitcoin network to use. Defaults to the Bitcoin network.
163+ * @returns The corresponding output script as a Buffer.
164+ * @throws If the address has an invalid prefix or no matching script.
136165 */
137166function toOutputScript ( address , network ) {
138167 network = network || networks . bitcoin ;
0 commit comments