@@ -73,6 +73,13 @@ const FUTURE_SEGWIT_VERSION_WARNING =
7373 'End users MUST be warned carefully in the GUI and asked if they wish to proceed ' +
7474 'with caution. Wallets should verify the segwit version from the output of fromBech32, ' +
7575 'then decide when it is safe to use which version of segwit.' ;
76+ /**
77+ * Converts an output buffer to a future segwit address.
78+ * @param output - The output buffer.
79+ * @param network - The network object.
80+ * @returns The future segwit address.
81+ * @throws {TypeError } If the program length or version is invalid for segwit address.
82+ */
7683function _toFutureSegwitAddress ( output , network ) {
7784 const data = output . slice ( 2 ) ;
7885 if (
@@ -92,7 +99,11 @@ function _toFutureSegwitAddress(output, network) {
9299 return toBech32 ( data , version , network . bech32 ) ;
93100}
94101/**
95- * decode address with base58 specification, return address version and address hash if valid
102+ * Decodes a base58check encoded Bitcoin address and returns the version and hash.
103+ *
104+ * @param address - The base58check encoded Bitcoin address to decode.
105+ * @returns An object containing the version and hash of the decoded address.
106+ * @throws {TypeError } If the address is too short or too long.
96107 */
97108function fromBase58Check ( address ) {
98109 const payload = bs58check_1 . default . decode ( address ) ;
@@ -104,7 +115,10 @@ function fromBase58Check(address) {
104115 return { version, hash } ;
105116}
106117/**
107- * decode address with bech32 specification, return address version、address prefix and address data if valid
118+ * Converts a Bech32 or Bech32m encoded address to its corresponding data representation.
119+ * @param address - The Bech32 or Bech32m encoded address.
120+ * @returns An object containing the version, prefix, and data of the address.
121+ * @throws {TypeError } If the address uses the wrong encoding.
108122 */
109123function fromBech32 ( address ) {
110124 let result ;
@@ -128,7 +142,10 @@ function fromBech32(address) {
128142 } ;
129143}
130144/**
131- * encode address hash to base58 address with version
145+ * Converts a hash to a Base58Check-encoded string.
146+ * @param hash - The hash to be encoded.
147+ * @param version - The version byte to be prepended to the encoded string.
148+ * @returns The Base58Check-encoded string.
132149 */
133150function toBase58Check ( hash , version ) {
134151 v . parse ( v . tuple ( [ types_js_1 . Hash160bitSchema , types_js_1 . UInt8Schema ] ) , [
@@ -141,7 +158,11 @@ function toBase58Check(hash, version) {
141158 return bs58check_1 . default . encode ( payload ) ;
142159}
143160/**
144- * encode address hash to bech32 address with version and prefix
161+ * Converts a buffer to a Bech32 or Bech32m encoded string.
162+ * @param data - The buffer to be encoded.
163+ * @param version - The version number to be used in the encoding.
164+ * @param prefix - The prefix string to be used in the encoding.
165+ * @returns The Bech32 or Bech32m encoded string.
145166 */
146167function toBech32 ( data , version , prefix ) {
147168 const words = bech32_1 . bech32 . toWords ( data ) ;
@@ -151,7 +172,11 @@ function toBech32(data, version, prefix) {
151172 : bech32_1 . bech32m . encode ( prefix , words ) ;
152173}
153174/**
154- * decode address from output script with network, return address if matched
175+ * Converts an output script to a Bitcoin address.
176+ * @param output - The output script as a Buffer.
177+ * @param network - The Bitcoin network (optional).
178+ * @returns The Bitcoin address corresponding to the output script.
179+ * @throws If the output script has no matching address.
155180 */
156181function fromOutputScript ( output , network ) {
157182 // TODO: Network
@@ -177,7 +202,11 @@ function fromOutputScript(output, network) {
177202 throw new Error ( bscript . toASM ( output ) + ' has no matching Address' ) ;
178203}
179204/**
180- * encodes address to output script with network, return output script if address matched
205+ * Converts a Bitcoin address to its corresponding output script.
206+ * @param address - The Bitcoin address to convert.
207+ * @param network - The Bitcoin network to use. Defaults to the Bitcoin network.
208+ * @returns The corresponding output script as a Buffer.
209+ * @throws If the address has an invalid prefix or no matching script.
181210 */
182211function toOutputScript ( address , network ) {
183212 network = network || networks . bitcoin ;
0 commit comments