From 16efbde9868183edc44034bc9437da075f3bd8c3 Mon Sep 17 00:00:00 2001 From: Chris Gianelloni Date: Thu, 23 Jan 2025 16:46:47 -0500 Subject: [PATCH] chore(deps): use btcutil for base58/bech32 Signed-off-by: Chris Gianelloni --- base58/LICENSE | 14 -- base58/alphabet.go | 52 ----- base58/base58.go | 147 ------------- base58/base58check.go | 57 ----- base58/doc.go | 32 --- base58/genalphabet.go | 85 -------- bech32/LICENSE | 14 -- bech32/bech32.go | 450 --------------------------------------- bech32/doc.go | 18 -- bech32/error.go | 90 -------- bech32/version.go | 46 ---- go.mod | 1 + go.sum | 94 ++++++++ ledger/common/address.go | 5 +- ledger/common/common.go | 6 +- 15 files changed, 101 insertions(+), 1010 deletions(-) delete mode 100644 base58/LICENSE delete mode 100644 base58/alphabet.go delete mode 100644 base58/base58.go delete mode 100644 base58/base58check.go delete mode 100644 base58/doc.go delete mode 100644 base58/genalphabet.go delete mode 100644 bech32/LICENSE delete mode 100644 bech32/bech32.go delete mode 100644 bech32/doc.go delete mode 100644 bech32/error.go delete mode 100644 bech32/version.go diff --git a/base58/LICENSE b/base58/LICENSE deleted file mode 100644 index 43fe51a7..00000000 --- a/base58/LICENSE +++ /dev/null @@ -1,14 +0,0 @@ -Copyright © 2004-2011 by Internet Systems Consortium, Inc. ("ISC") -Copyright © 1995-2003 by Internet Software Consortium - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD -TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS -ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. diff --git a/base58/alphabet.go b/base58/alphabet.go deleted file mode 100644 index f228b155..00000000 --- a/base58/alphabet.go +++ /dev/null @@ -1,52 +0,0 @@ -// Copyright (c) 2015 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// NOTE: this file was copied from: -// https://github.com/btcsuite/btcd/tree/v0.23.4/btcutil/base58 - -// AUTOGENERATED by genalphabet.go; do not edit. - -package base58 - -const ( - // alphabet is the modified base58 alphabet used by Bitcoin. - alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" - - alphabetIdx0 = '1' -) - -var b58 = [256]byte{ - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 0, 1, 2, 3, 4, 5, 6, - 7, 8, 255, 255, 255, 255, 255, 255, - 255, 9, 10, 11, 12, 13, 14, 15, - 16, 255, 17, 18, 19, 20, 21, 255, - 22, 23, 24, 25, 26, 27, 28, 29, - 30, 31, 32, 255, 255, 255, 255, 255, - 255, 33, 34, 35, 36, 37, 38, 39, - 40, 41, 42, 43, 255, 44, 45, 46, - 47, 48, 49, 50, 51, 52, 53, 54, - 55, 56, 57, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, - 255, 255, 255, 255, 255, 255, 255, 255, -} diff --git a/base58/base58.go b/base58/base58.go deleted file mode 100644 index 3d785e7b..00000000 --- a/base58/base58.go +++ /dev/null @@ -1,147 +0,0 @@ -// Copyright (c) 2013-2015 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// NOTE: this file was copied from: -// https://github.com/btcsuite/btcd/tree/v0.23.4/btcutil/base58 - -package base58 - -import ( - "math/big" -) - -//go:generate go run genalphabet.go - -var bigRadix = [...]*big.Int{ - big.NewInt(0), - big.NewInt(58), - big.NewInt(58 * 58), - big.NewInt(58 * 58 * 58), - big.NewInt(58 * 58 * 58 * 58), - big.NewInt(58 * 58 * 58 * 58 * 58), - big.NewInt(58 * 58 * 58 * 58 * 58 * 58), - big.NewInt(58 * 58 * 58 * 58 * 58 * 58 * 58), - big.NewInt(58 * 58 * 58 * 58 * 58 * 58 * 58 * 58), - big.NewInt(58 * 58 * 58 * 58 * 58 * 58 * 58 * 58 * 58), - bigRadix10, -} - -var bigRadix10 = big.NewInt( - 58 * 58 * 58 * 58 * 58 * 58 * 58 * 58 * 58 * 58, -) // 58^10 - -// Decode decodes a modified base58 string to a byte slice. -func Decode(b string) []byte { - answer := big.NewInt(0) - scratch := new(big.Int) - - // Calculating with big.Int is slow for each iteration. - // x += b58[b[i]] * j - // j *= 58 - // - // Instead we can try to do as much calculations on int64. - // We can represent a 10 digit base58 number using an int64. - // - // Hence we'll try to convert 10, base58 digits at a time. - // The rough idea is to calculate `t`, such that: - // - // t := b58[b[i+9]] * 58^9 ... + b58[b[i+1]] * 58^1 + b58[b[i]] * 58^0 - // x *= 58^10 - // x += t - // - // Of course, in addition, we'll need to handle boundary condition when `b` is not multiple of 58^10. - // In that case we'll use the bigRadix[n] lookup for the appropriate power. - for t := b; len(t) > 0; { - n := len(t) - if n > 10 { - n = 10 - } - - total := uint64(0) - for _, v := range t[:n] { - if v > 255 { - return []byte("") - } - - tmp := b58[v] - if tmp == 255 { - return []byte("") - } - total = total*58 + uint64(tmp) - } - - answer.Mul(answer, bigRadix[n]) - scratch.SetUint64(total) - answer.Add(answer, scratch) - - t = t[n:] - } - - tmpval := answer.Bytes() - - var numZeros int - for numZeros = 0; numZeros < len(b); numZeros++ { - if b[numZeros] != alphabetIdx0 { - break - } - } - flen := numZeros + len(tmpval) - val := make([]byte, flen) - copy(val[numZeros:], tmpval) - - return val -} - -// Encode encodes a byte slice to a modified base58 string. -func Encode(b []byte) string { - x := new(big.Int) - x.SetBytes(b) - - // maximum length of output is log58(2^(8*len(b))) == len(b) * 8 / log(58) - maxlen := int(float64(len(b))*1.365658237309761) + 1 - answer := make([]byte, 0, maxlen) - mod := new(big.Int) - for x.Sign() > 0 { - // Calculating with big.Int is slow for each iteration. - // x, mod = x / 58, x % 58 - // - // Instead we can try to do as much calculations on int64. - // x, mod = x / 58^10, x % 58^10 - // - // Which will give us mod, which is 10 digit base58 number. - // We'll loop that 10 times to convert to the answer. - - x.DivMod(x, bigRadix10, mod) - if x.Sign() == 0 { - // When x = 0, we need to ensure we don't add any extra zeros. - m := mod.Int64() - for m > 0 { - answer = append(answer, alphabet[m%58]) - m /= 58 - } - } else { - m := mod.Int64() - for i := 0; i < 10; i++ { - answer = append(answer, alphabet[m%58]) - m /= 58 - } - } - } - - // leading zero bytes - for _, i := range b { - if i != 0 { - break - } - answer = append(answer, alphabetIdx0) - } - - // reverse - alen := len(answer) - for i := 0; i < alen/2; i++ { - answer[i], answer[alen-1-i] = answer[alen-1-i], answer[i] - } - - return string(answer) -} diff --git a/base58/base58check.go b/base58/base58check.go deleted file mode 100644 index 5cc51a65..00000000 --- a/base58/base58check.go +++ /dev/null @@ -1,57 +0,0 @@ -// Copyright (c) 2013-2014 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// NOTE: this file was copied from: -// https://github.com/btcsuite/btcd/tree/v0.23.4/btcutil/base58 - -package base58 - -import ( - "crypto/sha256" - "errors" -) - -// ErrChecksum indicates that the checksum of a check-encoded string does not verify against -// the checksum. -var ErrChecksum = errors.New("checksum error") - -// ErrInvalidFormat indicates that the check-encoded string has an invalid format. -var ErrInvalidFormat = errors.New( - "invalid format: version and/or checksum bytes missing", -) - -// checksum: first four bytes of sha256^2 -func checksum(input []byte) (cksum [4]byte) { - h := sha256.Sum256(input) - h2 := sha256.Sum256(h[:]) - copy(cksum[:], h2[:4]) - return -} - -// CheckEncode prepends a version byte and appends a four byte checksum. -func CheckEncode(input []byte, version byte) string { - b := make([]byte, 0, 1+len(input)+4) - b = append(b, version) - b = append(b, input...) - cksum := checksum(b) - b = append(b, cksum[:]...) - return Encode(b) -} - -// CheckDecode decodes a string that was encoded with CheckEncode and verifies the checksum. -func CheckDecode(input string) (result []byte, version byte, err error) { - decoded := Decode(input) - if len(decoded) < 5 { - return nil, 0, ErrInvalidFormat - } - version = decoded[0] - var cksum [4]byte - copy(cksum[:], decoded[len(decoded)-4:]) - if checksum(decoded[:len(decoded)-4]) != cksum { - return nil, 0, ErrChecksum - } - payload := decoded[1 : len(decoded)-4] - result = append(result, payload...) - return -} diff --git a/base58/doc.go b/base58/doc.go deleted file mode 100644 index 139dbfac..00000000 --- a/base58/doc.go +++ /dev/null @@ -1,32 +0,0 @@ -// Copyright (c) 2014 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// NOTE: this file was copied from: -// https://github.com/btcsuite/btcd/tree/v0.23.4/btcutil/base58 - -/* -Package base58 provides an API for working with modified base58 and Base58Check -encodings. - -# Modified Base58 Encoding - -Standard base58 encoding is similar to standard base64 encoding except, as the -name implies, it uses a 58 character alphabet which results in an alphanumeric -string and allows some characters which are problematic for humans to be -excluded. Due to this, there can be various base58 alphabets. - -The modified base58 alphabet used by Bitcoin, and hence this package, omits the -0, O, I, and l characters that look the same in many fonts and are therefore -hard to humans to distinguish. - -# Base58Check Encoding Scheme - -The Base58Check encoding scheme is primarily used for Bitcoin addresses at the -time of this writing, however it can be used to generically encode arbitrary -byte arrays into human-readable strings along with a version byte that can be -used to differentiate the same payload. For Bitcoin addresses, the extra -version is used to differentiate the network of otherwise identical public keys -which helps prevent using an address intended for one network on another. -*/ -package base58 diff --git a/base58/genalphabet.go b/base58/genalphabet.go deleted file mode 100644 index ac14214a..00000000 --- a/base58/genalphabet.go +++ /dev/null @@ -1,85 +0,0 @@ -// Copyright (c) 2015 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// NOTE: this file was copied from: -// https://github.com/btcsuite/btcd/tree/v0.23.4/btcutil/base58 - -//go:build ignore -// +build ignore - -package main - -import ( - "bytes" - "io" - "log" - "os" - "strconv" -) - -var ( - start = []byte(`// Copyright (c) 2015 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// AUTOGENERATED by genalphabet.go; do not edit. - -package base58 - -const ( - // alphabet is the modified base58 alphabet used by Bitcoin. - alphabet = "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz" - - alphabetIdx0 = '1' -) - -var b58 = [256]byte{`) - - end = []byte(`}`) - - alphabet = []byte( - "123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz", - ) - tab = []byte("\t") - invalid = []byte("255") - comma = []byte(",") - space = []byte(" ") - nl = []byte("\n") -) - -func write(w io.Writer, b []byte) { - _, err := w.Write(b) - if err != nil { - log.Fatal(err) - } -} - -func main() { - fi, err := os.Create("alphabet.go") - if err != nil { - log.Fatal(err) - } - defer fi.Close() - - write(fi, start) - write(fi, nl) - for i := byte(0); i < 32; i++ { - write(fi, tab) - for j := byte(0); j < 8; j++ { - idx := bytes.IndexByte(alphabet, i*8+j) - if idx == -1 { - write(fi, invalid) - } else { - write(fi, strconv.AppendInt(nil, int64(idx), 10)) - } - write(fi, comma) - if j != 7 { - write(fi, space) - } - } - write(fi, nl) - } - write(fi, end) - write(fi, nl) -} diff --git a/bech32/LICENSE b/bech32/LICENSE deleted file mode 100644 index 43fe51a7..00000000 --- a/bech32/LICENSE +++ /dev/null @@ -1,14 +0,0 @@ -Copyright © 2004-2011 by Internet Systems Consortium, Inc. ("ISC") -Copyright © 1995-2003 by Internet Software Consortium - -Permission to use, copy, modify, and/or distribute this software for any -purpose with or without fee is hereby granted, provided that the above -copyright notice and this permission notice appear in all copies. - -THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH REGARD -TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND -FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR -CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, -DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS -ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS -SOFTWARE. diff --git a/bech32/bech32.go b/bech32/bech32.go deleted file mode 100644 index 5fe068cd..00000000 --- a/bech32/bech32.go +++ /dev/null @@ -1,450 +0,0 @@ -// Copyright (c) 2017 The btcsuite developers -// Copyright (c) 2019 The Decred developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// NOTE: this file was copied from: -// https://github.com/btcsuite/btcd/tree/v0.23.4/btcutil/bech32 - -package bech32 - -import ( - "strings" -) - -// charset is the set of characters used in the data section of bech32 strings. -// Note that this is ordered, such that for a given charset[i], i is the binary -// value of the character. -const charset = "qpzry9x8gf2tvdw0s3jn54khce6mua7l" - -// gen encodes the generator polynomial for the bech32 BCH checksum. -var gen = []int{0x3b6a57b2, 0x26508e6d, 0x1ea119fa, 0x3d4233dd, 0x2a1462b3} - -// toBytes converts each character in the string 'chars' to the value of the -// index of the correspoding character in 'charset'. -func toBytes(chars string) ([]byte, error) { - decoded := make([]byte, 0, len(chars)) - for i := 0; i < len(chars); i++ { - index := strings.IndexByte(charset, chars[i]) - if index < 0 { - // In the original code, this returns nil instead - return []byte{}, ErrNonCharsetChar(chars[i]) - } - decoded = append(decoded, byte(index)) - } - return decoded, nil -} - -// bech32Polymod calculates the BCH checksum for a given hrp, values and -// checksum data. Checksum is optional, and if nil a 0 checksum is assumed. -// -// Values and checksum (if provided) MUST be encoded as 5 bits per element (base -// 32), otherwise the results are undefined. -// -// For more details on the polymod calculation, please refer to BIP 173. -func bech32Polymod(hrp string, values, checksum []byte) int { - chk := 1 - - // Account for the high bits of the HRP in the checksum. - for i := 0; i < len(hrp); i++ { - b := chk >> 25 - hiBits := int(hrp[i]) >> 5 - chk = (chk&0x1ffffff)<<5 ^ hiBits - for i := 0; i < 5; i++ { - if (b>>uint(i))&1 == 1 { - chk ^= gen[i] - } - } - } - - // Account for the separator (0) between high and low bits of the HRP. - // x^0 == x, so we eliminate the redundant xor used in the other rounds. - b := chk >> 25 - chk = (chk & 0x1ffffff) << 5 - for i := 0; i < 5; i++ { - if (b>>uint(i))&1 == 1 { - chk ^= gen[i] - } - } - - // Account for the low bits of the HRP. - for i := 0; i < len(hrp); i++ { - b := chk >> 25 - loBits := int(hrp[i]) & 31 - chk = (chk&0x1ffffff)<<5 ^ loBits - for i := 0; i < 5; i++ { - if (b>>uint(i))&1 == 1 { - chk ^= gen[i] - } - } - } - - // Account for the values. - for _, v := range values { - b := chk >> 25 - chk = (chk&0x1ffffff)<<5 ^ int(v) - for i := 0; i < 5; i++ { - if (b>>uint(i))&1 == 1 { - chk ^= gen[i] - } - } - } - - if checksum == nil { - // A nil checksum is used during encoding, so assume all bytes are zero. - // x^0 == x, so we eliminate the redundant xor used in the other rounds. - for v := 0; v < 6; v++ { - b := chk >> 25 - chk = (chk & 0x1ffffff) << 5 - for i := 0; i < 5; i++ { - if (b>>uint(i))&1 == 1 { - chk ^= gen[i] - } - } - } - } else { - // Checksum is provided during decoding, so use it. - for _, v := range checksum { - b := chk >> 25 - chk = (chk&0x1ffffff)<<5 ^ int(v) - for i := 0; i < 5; i++ { - if (b>>uint(i))&1 == 1 { - chk ^= gen[i] - } - } - } - } - - return chk -} - -// writeBech32Checksum calculates the checksum data expected for a string that -// will have the given hrp and payload data and writes it to the provided string -// builder. -// -// The payload data MUST be encoded as a base 32 (5 bits per element) byte slice -// and the hrp MUST only use the allowed character set (ascii chars between 33 -// and 126), otherwise the results are undefined. -// -// For more details on the checksum calculation, please refer to BIP 173. -func writeBech32Checksum(hrp string, data []byte, bldr *strings.Builder, - version Version) { - - bech32Const := int(VersionToConsts[version]) - polymod := bech32Polymod(hrp, data, nil) ^ bech32Const - for i := 0; i < 6; i++ { - b := byte((polymod >> uint(5*(5-i))) & 31) - - // This can't fail, given we explicitly cap the previous b byte by the - // first 31 bits. - c := charset[b] - bldr.WriteByte(c) - } -} - -// bech32VerifyChecksum verifies whether the bech32 string specified by the -// provided hrp and payload data (encoded as 5 bits per element byte slice) has -// the correct checksum suffix. The version of bech32 used (bech32 OG, or -// bech32m) is also returned to allow the caller to perform proper address -// validation (segwitv0 should use bech32, v1+ should use bech32m). -// -// Data MUST have more than 6 elements, otherwise this function panics. -// -// For more details on the checksum verification, please refer to BIP 173. -func bech32VerifyChecksum(hrp string, data []byte) (Version, bool) { - checksum := data[len(data)-6:] - values := data[:len(data)-6] - polymod := bech32Polymod(hrp, values, checksum) - - // Before BIP-350, we'd always check this against a static constant of - // 1 to know if the checksum was computed properly. As we want to - // generically support decoding for bech32m as well as bech32, we'll - // look up the returned value and compare it to the set of defined - // constants. - bech32Version, ok := ConstsToVersion[ChecksumConst(polymod)] - if ok { - return bech32Version, true - } - - return VersionUnknown, false -} - -// DecodeNoLimit is a bech32 checksum version aware arbitrary string length -// decoder. This function will return the version of the decoded checksum -// constant so higher level validation can be performed to ensure the correct -// version of bech32 was used when encoding. -func decodeNoLimit(bech string) (string, []byte, Version, error) { - // The minimum allowed size of a bech32 string is 8 characters, since it - // needs a non-empty HRP, a separator, and a 6 character checksum. - if len(bech) < 8 { - return "", nil, VersionUnknown, ErrInvalidLength(len(bech)) - } - - // Only ASCII characters between 33 and 126 are allowed. - var hasLower, hasUpper bool - for i := 0; i < len(bech); i++ { - if bech[i] < 33 || bech[i] > 126 { - return "", nil, VersionUnknown, ErrInvalidCharacter(bech[i]) - } - - // The characters must be either all lowercase or all uppercase. Testing - // directly with ascii codes is safe here, given the previous test. - hasLower = hasLower || (bech[i] >= 97 && bech[i] <= 122) - hasUpper = hasUpper || (bech[i] >= 65 && bech[i] <= 90) - if hasLower && hasUpper { - return "", nil, VersionUnknown, ErrMixedCase{} - } - } - - // Bech32 standard uses only the lowercase for of strings for checksum - // calculation. - if hasUpper { - bech = strings.ToLower(bech) - } - - // The string is invalid if the last '1' is non-existent, it is the - // first character of the string (no human-readable part) or one of the - // last 6 characters of the string (since checksum cannot contain '1'). - one := strings.LastIndexByte(bech, '1') - if one < 1 || one+7 > len(bech) { - return "", nil, VersionUnknown, ErrInvalidSeparatorIndex(one) - } - - // The human-readable part is everything before the last '1'. - hrp := bech[:one] - data := bech[one+1:] - - // Each character corresponds to the byte with value of the index in - // 'charset'. - decoded, err := toBytes(data) - if err != nil { - return "", nil, VersionUnknown, err - } - - // Verify if the checksum (stored inside decoded[:]) is valid, given the - // previously decoded hrp. - bech32Version, ok := bech32VerifyChecksum(hrp, decoded) - if !ok { - // Invalid checksum. Calculate what it should have been, so that the - // error contains this information. - - // Extract the payload bytes and actual checksum in the string. - actual := bech[len(bech)-6:] - payload := decoded[:len(decoded)-6] - - // Calculate the expected checksum, given the hrp and payload - // data. We'll actually compute _both_ possibly valid checksum - // to further aide in debugging. - var expectedBldr strings.Builder - expectedBldr.Grow(6) - writeBech32Checksum(hrp, payload, &expectedBldr, Version0) - expectedVersion0 := expectedBldr.String() - - var b strings.Builder - b.Grow(6) - writeBech32Checksum(hrp, payload, &expectedBldr, VersionM) - expectedVersionM := expectedBldr.String() - - err = ErrInvalidChecksum{ - Expected: expectedVersion0, - ExpectedM: expectedVersionM, - Actual: actual, - } - return "", nil, VersionUnknown, err - } - - // We exclude the last 6 bytes, which is the checksum. - return hrp, decoded[:len(decoded)-6], bech32Version, nil -} - -// DecodeNoLimit decodes a bech32 encoded string, returning the human-readable -// part and the data part excluding the checksum. This function does NOT -// validate against the BIP-173 maximum length allowed for bech32 strings and -// is meant for use in custom applications (such as lightning network payment -// requests), NOT on-chain addresses. -// -// Note that the returned data is 5-bit (base32) encoded and the human-readable -// part will be lowercase. -func DecodeNoLimit(bech string) (string, []byte, error) { - hrp, data, _, err := decodeNoLimit(bech) - return hrp, data, err -} - -// Decode decodes a bech32 encoded string, returning the human-readable part and -// the data part excluding the checksum. -// -// Note that the returned data is 5-bit (base32) encoded and the human-readable -// part will be lowercase. -func Decode(bech string) (string, []byte, error) { - // The maximum allowed length for a bech32 string is 90. - if len(bech) > 90 { - return "", nil, ErrInvalidLength(len(bech)) - } - - hrp, data, _, err := decodeNoLimit(bech) - return hrp, data, err -} - -// DecodeGeneric is identical to the existing Decode method, but will also -// return bech32 version that matches the decoded checksum. This method should -// be used when decoding segwit addresses, as it enables additional -// verification to ensure the proper checksum is used. -func DecodeGeneric(bech string) (string, []byte, Version, error) { - // The maximum allowed length for a bech32 string is 90. - if len(bech) > 90 { - return "", nil, VersionUnknown, ErrInvalidLength(len(bech)) - } - - return decodeNoLimit(bech) -} - -// encodeGeneric is the base bech32 encoding function that is aware of the -// existence of the checksum versions. This method is private, as the Encode -// and EncodeM methods are intended to be used instead. -func encodeGeneric(hrp string, data []byte, - version Version) (string, error) { - - // The resulting bech32 string is the concatenation of the lowercase - // hrp, the separator 1, data and the 6-byte checksum. - hrp = strings.ToLower(hrp) - var bldr strings.Builder - bldr.Grow(len(hrp) + 1 + len(data) + 6) - bldr.WriteString(hrp) - bldr.WriteString("1") - - // Write the data part, using the bech32 charset. - for _, b := range data { - if int(b) >= len(charset) { - return "", ErrInvalidDataByte(b) - } - bldr.WriteByte(charset[b]) - } - - // Calculate and write the checksum of the data. - writeBech32Checksum(hrp, data, &bldr, version) - - return bldr.String(), nil -} - -// Encode encodes a byte slice into a bech32 string with the given -// human-readable part (HRP). The HRP will be converted to lowercase if needed -// since mixed cased encodings are not permitted and lowercase is used for -// checksum purposes. Note that the bytes must each encode 5 bits (base32). -func Encode(hrp string, data []byte) (string, error) { - return encodeGeneric(hrp, data, Version0) -} - -// EncodeM is the exactly same as the Encode method, but it uses the new -// bech32m constant instead of the original one. It should be used whenever one -// attempts to encode a segwit address of v1 and beyond. -func EncodeM(hrp string, data []byte) (string, error) { - return encodeGeneric(hrp, data, VersionM) -} - -// ConvertBits converts a byte slice where each byte is encoding fromBits bits, -// to a byte slice where each byte is encoding toBits bits. -func ConvertBits( - data []byte, - fromBits, toBits uint8, - pad bool, -) ([]byte, error) { - if fromBits < 1 || fromBits > 8 || toBits < 1 || toBits > 8 { - return nil, ErrInvalidBitGroups{} - } - - // Determine the maximum size the resulting array can have after base - // conversion, so that we can size it a single time. This might be off - // by a byte depending on whether padding is used or not and if the input - // data is a multiple of both fromBits and toBits, but we ignore that and - // just size it to the maximum possible. - maxSize := len(data)*int(fromBits)/int(toBits) + 1 - - // The final bytes, each byte encoding toBits bits. - regrouped := make([]byte, 0, maxSize) - - // Keep track of the next byte we create and how many bits we have - // added to it out of the toBits goal. - nextByte := byte(0) - filledBits := uint8(0) - - for _, b := range data { - - // Discard unused bits. - b <<= 8 - fromBits - - // How many bits remaining to extract from the input data. - remFromBits := fromBits - for remFromBits > 0 { - // How many bits remaining to be added to the next byte. - remToBits := toBits - filledBits - - // The number of bytes to next extract is the minimum of - // remFromBits and remToBits. - toExtract := remFromBits - if remToBits < toExtract { - toExtract = remToBits - } - - // Add the next bits to nextByte, shifting the already - // added bits to the left. - nextByte = (nextByte << toExtract) | (b >> (8 - toExtract)) - - // Discard the bits we just extracted and get ready for - // next iteration. - b <<= toExtract - remFromBits -= toExtract - filledBits += toExtract - - // If the nextByte is completely filled, we add it to - // our regrouped bytes and start on the next byte. - if filledBits == toBits { - regrouped = append(regrouped, nextByte) - filledBits = 0 - nextByte = 0 - } - } - } - - // We pad any unfinished group if specified. - if pad && filledBits > 0 { - nextByte <<= toBits - filledBits - regrouped = append(regrouped, nextByte) - filledBits = 0 - nextByte = 0 - } - - // Any incomplete group must be <= 4 bits, and all zeroes. - if filledBits > 0 && (filledBits > 4 || nextByte != 0) { - return nil, ErrInvalidIncompleteGroup{} - } - - return regrouped, nil -} - -// EncodeFromBase256 converts a base256-encoded byte slice into a base32-encoded -// byte slice and then encodes it into a bech32 string with the given -// human-readable part (HRP). The HRP will be converted to lowercase if needed -// since mixed cased encodings are not permitted and lowercase is used for -// checksum purposes. -func EncodeFromBase256(hrp string, data []byte) (string, error) { - converted, err := ConvertBits(data, 8, 5, true) - if err != nil { - return "", err - } - return Encode(hrp, converted) -} - -// DecodeToBase256 decodes a bech32-encoded string into its associated -// human-readable part (HRP) and base32-encoded data, converts that data to a -// base256-encoded byte slice and returns it along with the lowercase HRP. -func DecodeToBase256(bech string) (string, []byte, error) { - hrp, data, err := Decode(bech) - if err != nil { - return "", nil, err - } - converted, err := ConvertBits(data, 5, 8, false) - if err != nil { - return "", nil, err - } - return hrp, converted, nil -} diff --git a/bech32/doc.go b/bech32/doc.go deleted file mode 100644 index 1c330aa0..00000000 --- a/bech32/doc.go +++ /dev/null @@ -1,18 +0,0 @@ -// Copyright (c) 2017 The btcsuite developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// NOTE: this file was copied from: -// https://github.com/btcsuite/btcd/tree/v0.23.4/btcutil/bech32 - -/* -Package bech32 provides a Go implementation of the bech32 format specified in -BIP 173. - -Bech32 strings consist of a human-readable part (hrp), followed by the -separator 1, then a checksummed data part encoded using the 32 characters -"qpzry9x8gf2tvdw0s3jn54khce6mua7l". - -More info: https://github.com/bitcoin/bips/blob/master/bip-0173.mediawiki -*/ -package bech32 diff --git a/bech32/error.go b/bech32/error.go deleted file mode 100644 index 033e9801..00000000 --- a/bech32/error.go +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) 2019 The Decred developers -// Use of this source code is governed by an ISC -// license that can be found in the LICENSE file. - -// NOTE: this file was copied from: -// https://github.com/btcsuite/btcd/tree/v0.23.4/btcutil/bech32 - -package bech32 - -import ( - "fmt" -) - -// ErrMixedCase is returned when the bech32 string has both lower and uppercase -// characters. -type ErrMixedCase struct{} - -func (e ErrMixedCase) Error() string { - return "string not all lowercase or all uppercase" -} - -// ErrInvalidBitGroups is returned when conversion is attempted between byte -// slices using bit-per-element of unsupported value. -type ErrInvalidBitGroups struct{} - -func (e ErrInvalidBitGroups) Error() string { - return "only bit groups between 1 and 8 allowed" -} - -// ErrInvalidIncompleteGroup is returned when then byte slice used as input has -// data of wrong length. -type ErrInvalidIncompleteGroup struct{} - -func (e ErrInvalidIncompleteGroup) Error() string { - return "invalid incomplete group" -} - -// ErrInvalidLength is returned when the bech32 string has an invalid length -// given the BIP-173 defined restrictions. -type ErrInvalidLength int - -func (e ErrInvalidLength) Error() string { - return fmt.Sprintf("invalid bech32 string length %d", int(e)) -} - -// ErrInvalidCharacter is returned when the bech32 string has a character -// outside the range of the supported charset. -type ErrInvalidCharacter rune - -func (e ErrInvalidCharacter) Error() string { - return fmt.Sprintf("invalid character in string: '%c'", rune(e)) -} - -// ErrInvalidSeparatorIndex is returned when the separator character '1' is -// in an invalid position in the bech32 string. -type ErrInvalidSeparatorIndex int - -func (e ErrInvalidSeparatorIndex) Error() string { - return fmt.Sprintf("invalid separator index %d", int(e)) -} - -// ErrNonCharsetChar is returned when a character outside of the specific -// bech32 charset is used in the string. -type ErrNonCharsetChar rune - -func (e ErrNonCharsetChar) Error() string { - return fmt.Sprintf("invalid character not part of charset: %v", int(e)) -} - -// ErrInvalidChecksum is returned when the extracted checksum of the string -// is different than what was expected. Both the original version, as well as -// the new bech32m checksum may be specified. -type ErrInvalidChecksum struct { - Expected string - ExpectedM string - Actual string -} - -func (e ErrInvalidChecksum) Error() string { - return fmt.Sprintf("invalid checksum (expected (bech32=%v, "+ - "bech32m=%v), got %v)", e.Expected, e.ExpectedM, e.Actual) -} - -// ErrInvalidDataByte is returned when a byte outside the range required for -// conversion into a string was found. -type ErrInvalidDataByte byte - -func (e ErrInvalidDataByte) Error() string { - return fmt.Sprintf("invalid data byte: %v", byte(e)) -} diff --git a/bech32/version.go b/bech32/version.go deleted file mode 100644 index f44fd028..00000000 --- a/bech32/version.go +++ /dev/null @@ -1,46 +0,0 @@ -// NOTE: this file was copied from: -// https://github.com/btcsuite/btcd/tree/v0.23.4/btcutil/bech32 - -package bech32 - -// ChecksumConst is a type that represents the currently defined bech32 -// checksum constants. -type ChecksumConst int - -const ( - // Version0Const is the original constant used in the checksum - // verification for bech32. - Version0Const ChecksumConst = 1 - - // VersionMConst is the new constant used for bech32m checksum - // verification. - VersionMConst ChecksumConst = 0x2bc830a3 -) - -// Version defines the current set of bech32 versions. -type Version uint8 - -const ( - // Version0 defines the original bech version. - Version0 Version = iota - - // VersionM is the new bech32 version defined in BIP-350, also known as - // bech32m. - VersionM - - // VersionUnknown denotes an unknown bech version. - VersionUnknown -) - -// VersionToConsts maps bech32 versions to the checksum constant to be used -// when encoding, and asserting a particular version when decoding. -var VersionToConsts = map[Version]ChecksumConst{ - Version0: Version0Const, - VersionM: VersionMConst, -} - -// ConstsToVersion maps a bech32 constant to the version it's associated with. -var ConstsToVersion = map[ChecksumConst]Version{ - Version0Const: Version0, - VersionMConst: VersionM, -} diff --git a/go.mod b/go.mod index 395eff66..8d66d500 100644 --- a/go.mod +++ b/go.mod @@ -5,6 +5,7 @@ go 1.22.11 require ( filippo.io/edwards25519 v1.1.0 github.com/blinklabs-io/ouroboros-mock v0.3.6 + github.com/btcsuite/btcd/btcutil v1.1.3 github.com/fxamacker/cbor/v2 v2.7.0 github.com/jinzhu/copier v0.4.0 github.com/stretchr/testify v1.10.0 diff --git a/go.sum b/go.sum index ba6f5df8..b93e6251 100644 --- a/go.sum +++ b/go.sum @@ -1,38 +1,132 @@ filippo.io/edwards25519 v1.1.0 h1:FNf4tywRC1HmFuKW5xopWpigGjJKiJSV0Cqo0cJWDaA= filippo.io/edwards25519 v1.1.0/go.mod h1:BxyFTGdWcka3PhytdK4V28tE5sGfRvvvRV7EaN4VDT4= +github.com/aead/siphash v1.0.1/go.mod h1:Nywa3cDsYNNK3gaciGTWPwHt0wlpNV15vwmswBAUSII= github.com/blinklabs-io/ouroboros-mock v0.3.6 h1:m/iK4l1EJbiz9kU0u5uzWNEwlskazWuwbJHysr2hhP4= github.com/blinklabs-io/ouroboros-mock v0.3.6/go.mod h1:S++j/dBxNYG3AlcRaeZvok4X2ih7GrK+VWV1s0SLN3M= +github.com/btcsuite/btcd v0.20.1-beta/go.mod h1:wVuoA8VJLEcwgqHBwHmzLRazpKxTv13Px/pDuV7OomQ= +github.com/btcsuite/btcd v0.22.0-beta.0.20220111032746-97732e52810c/go.mod h1:tjmYdS6MLJ5/s0Fj4DbLgSbDHbEqLJrtnHecBFkdz5M= +github.com/btcsuite/btcd v0.23.0/go.mod h1:0QJIIN1wwIXF/3G/m87gIwGniDMDQqjVn4SZgnFpsYY= +github.com/btcsuite/btcd/btcec/v2 v2.1.0/go.mod h1:2VzYrv4Gm4apmbVVsSq5bqf1Ec8v56E48Vt0Y/umPgA= +github.com/btcsuite/btcd/btcec/v2 v2.1.3/go.mod h1:ctjw4H1kknNJmRN4iP1R7bTQ+v3GJkZBd6mui8ZsAZE= +github.com/btcsuite/btcd/btcutil v1.0.0/go.mod h1:Uoxwv0pqYWhD//tfTiipkxNfdhG9UrLwaeswfjfdF0A= +github.com/btcsuite/btcd/btcutil v1.1.0/go.mod h1:5OapHB7A2hBBWLm48mmw4MOHNJCcUBTwmWH/0Jn8VHE= +github.com/btcsuite/btcd/btcutil v1.1.3 h1:xfbtw8lwpp0G6NwSHb+UE67ryTFHJAiNuipusjXSohQ= +github.com/btcsuite/btcd/btcutil v1.1.3/go.mod h1:UR7dsSJzJUfMmFiiLlIrMq1lS9jh9EdCV7FStZSnpi0= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.0/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1/go.mod h1:7SFka0XMvUgj3hfZtydOrQY2mwhPclbT2snogU7SQQc= +github.com/btcsuite/btclog v0.0.0-20170628155309-84c8d2346e9f/go.mod h1:TdznJufoqS23FtqVCzL0ZqgP5MqXbb4fg/WgDys70nA= +github.com/btcsuite/btcutil v0.0.0-20190425235716-9e5f4b9a998d/go.mod h1:+5NJ2+qvTyV9exUAL/rxXi3DcLg2Ts+ymUAY5y4NvMg= +github.com/btcsuite/go-socks v0.0.0-20170105172521-4720035b7bfd/go.mod h1:HHNXQzUsZCxOoE+CPiyCTO6x34Zs86zZUiwtpXoGdtg= +github.com/btcsuite/goleveldb v0.0.0-20160330041536-7834afc9e8cd/go.mod h1:F+uVaaLLH7j4eDXPRvw78tMflu7Ie2bzYOH4Y8rRKBY= +github.com/btcsuite/goleveldb v1.0.0/go.mod h1:QiK9vBlgftBg6rWQIj6wFzbPfRjiykIEhBH4obrXJ/I= +github.com/btcsuite/snappy-go v0.0.0-20151229074030-0bdef8d06723/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/snappy-go v1.0.0/go.mod h1:8woku9dyThutzjeg+3xrA5iCpBRH8XEEg3lh6TiUghc= +github.com/btcsuite/websocket v0.0.0-20150119174127-31079b680792/go.mod h1:ghJtEyQwv5/p4Mg4C0fgbePVuGr935/5ddU9Z3TmDRY= +github.com/btcsuite/winsvc v1.0.0/go.mod h1:jsenWakMcC0zFBFurPLEAyrnc/teJEM1O46fmI40EZs= github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ33E= +github.com/davecgh/go-spew v0.0.0-20171005155431-ecdeabc65495/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM= github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= +github.com/decred/dcrd/crypto/blake256 v1.0.0/go.mod h1:sQl2p6Y26YV+ZOcSTP6thNdn47hh8kt6rqSlvmrXFAc= +github.com/decred/dcrd/dcrec/secp256k1/v4 v4.0.1/go.mod h1:hyedUtir6IdtD/7lIxGeCxkaw7y45JueMRL4DIyJDKs= +github.com/decred/dcrd/lru v1.0.0/go.mod h1:mxKOwFd7lFjN2GZYsiz/ecgqR6kkYAl+0pz0tEMk218= +github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo= +github.com/fsnotify/fsnotify v1.4.9/go.mod h1:znqG4EE+3YCdAaPaxE2ZRY/06pZUdp0tY4IgpuI1SZQ= github.com/fxamacker/cbor/v2 v2.7.0 h1:iM5WgngdRBanHcxugY4JySA0nk1wZorNOpTgCMedv5E= github.com/fxamacker/cbor/v2 v2.7.0/go.mod h1:pxXPTn3joSm21Gbwsv0w9OSA2y1HFR9qXEeXQVeNoDQ= +github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= +github.com/golang/protobuf v1.4.0-rc.1/go.mod h1:ceaxUfeHdC40wWswd/P6IGgMaK3YpKi5j83Wpe3EHw8= +github.com/golang/protobuf v1.4.0-rc.1.0.20200221234624-67d41d38c208/go.mod h1:xKAWHe0F5eneWXFV3EuXVDTCmh+JuBKY0li0aMyXATA= +github.com/golang/protobuf v1.4.0-rc.2/go.mod h1:LlEzMj4AhA7rCAGe4KMBDvJI+AwstrUpVNzEA03Pprs= +github.com/golang/protobuf v1.4.0-rc.4.0.20200313231945-b860323f09d0/go.mod h1:WU3c8KckQ9AFe+yFwt9sWVRKCVIyN9cPHBJSNnbL67w= +github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvqG2KuDX0= +github.com/golang/protobuf v1.4.2/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= +github.com/golang/snappy v0.0.4/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q= +github.com/google/go-cmp v0.3.0/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.3.1/go.mod h1:8QqcDgzrUqlUb/G2PQTWiueGozuR1884gddMywk6iLU= +github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= +github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU= +github.com/jessevdk/go-flags v0.0.0-20141203071132-1679536dcc89/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= +github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jinzhu/copier v0.4.0 h1:w3ciUoD19shMCRargcpm0cm91ytaBhDvuRpz1ODO/U8= github.com/jinzhu/copier v0.4.0/go.mod h1:DfbEm0FYsaqBcKcFuvmOZb218JkPGtvSHsKg8S8hyyg= +github.com/jrick/logrotate v1.0.0/go.mod h1:LNinyqDIJnpAur+b8yyulnQw/wDuN1+BYKlTRt3OuAQ= +github.com/kkdai/bstream v0.0.0-20161212061736-f391b8402d23/go.mod h1:J+Gs4SYgM6CZQHDETBtE9HaSEkGmuNXF86RwHhHUvq4= github.com/kr/pretty v0.1.0 h1:L/CwN0zerZDmRFUapSPitk6f+Q3+0za1rQkzVuMiMFI= github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORNo= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= +github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A= +github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE= +github.com/onsi/ginkgo v1.12.1/go.mod h1:zj2OWP4+oCPe1qIXoGWkgMRwljMUYCdkwsT2108oapk= +github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9klQyY= +github.com/onsi/gomega v1.4.1/go.mod h1:C1qb7wdrVGGVU+Z6iS04AVkA3Q65CEZX59MT0QO5uiA= +github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY= +github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY= +github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo= +github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 h1:Jamvg5psRIccs7FGNTlIRMkT8wgtp5eCXdBlqhYGL6U= github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= +github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME= +github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.10.0 h1:Xv5erBjTwe/5IxqUQTdXv5kgmIvbHo3QQyRwhJsOfJA= github.com/stretchr/testify v1.10.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= +github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7/go.mod h1:q4W45IWZaF22tdD+VEXcAWRA037jwmWEB5VWYORlTpc= github.com/utxorpc/go-codegen v0.15.0 h1:8zjHvDNBRU+SmyuyQz3Dt4xyLZE7lz7x+jAhcAC0AOw= github.com/utxorpc/go-codegen v0.15.0/go.mod h1:btx1dYNsjlhGeLRsc6gXYZ10I1ljbT2yCiPjpsTwl/I= github.com/x448/float16 v0.8.4 h1:qLwI1I70+NjRFUR3zs1JPUCgaCXSh3SW62uAKT1mSBM= github.com/x448/float16 v0.8.4/go.mod h1:14CWIYCyZA/cWjXOioeEpHeN/83MdbZDRQHoFcYsOfg= go.uber.org/goleak v1.3.0 h1:2K3zAYmnTNqV73imy9J1T3WC+gmCePx2hEGkimedGto= go.uber.org/goleak v1.3.0/go.mod h1:CoHD4mav9JJNrW/WLlf7HGZPjdw8EucARQHekz1X6bE= +golang.org/x/crypto v0.0.0-20170930174604-9419663f5a44/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4= +golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= +golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.32.0 h1:euUpcYgM8WcP71gNpTqQCn6rC2t6ULUPiOzfWaXVVfc= golang.org/x/crypto v0.32.0/go.mod h1:ZnnJkOaASj8g0AjIduWNlq2NRxL0PlBrbKVyZ6V/Ugc= +golang.org/x/net v0.0.0-20180719180050-a680a1efc54d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4= +golang.org/x/net v0.0.0-20190404232315-eb5bcb51f2a3/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg= +golang.org/x/net v0.0.0-20200520004742-59133d7f0dd7/go.mod h1:qpuaurCH72eLCgpAm/N6yyVIVM9cpaDIP3A8BGJEC5A= +golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA= +golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= +golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= +golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20190904154756-749cb33beabd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191005200804-aed5e4c7ecf9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200519105757-fe76b779f299/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20200814200057-3d37ad5750ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.29.0 h1:TPYlXGxvx1MGTn2GiZDhnjPA9wZzZeGKHHmKhHYvgaU= golang.org/x/sys v0.29.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= +golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk= +golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= +golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= +golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= +google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= +google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= +google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= +google.golang.org/protobuf v1.20.1-0.20200309200217-e05f789c0967/go.mod h1:A+miEFZTKqfCUM6K7xSMQL9OKL/b6hQv+e19PK+JZNE= +google.golang.org/protobuf v1.21.0/go.mod h1:47Nbq4nVaFHyn7ilMalzfO3qCViNmqZ2kzikPIcrTAo= +google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.36.1 h1:yBPeRvTftaleIgM3PZ/WBIZ7XM/eEYAaEyCwvyjq/gk= google.golang.org/protobuf v1.36.1/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 h1:qIbj1fsPNlZgppZ+VLlY7N33q108Sa+fhmuc+sWQYwY= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= +gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys= +gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw= +gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.2.4/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v2 v2.3.0/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI= +gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/ledger/common/address.go b/ledger/common/address.go index 61e9e57e..335c906a 100644 --- a/ledger/common/address.go +++ b/ledger/common/address.go @@ -19,8 +19,9 @@ import ( "hash/crc32" "strings" - "github.com/blinklabs-io/gouroboros/base58" - "github.com/blinklabs-io/gouroboros/bech32" + "github.com/btcsuite/btcd/btcutil/base58" + "github.com/btcsuite/btcd/btcutil/bech32" + "github.com/blinklabs-io/gouroboros/cbor" "golang.org/x/crypto/sha3" ) diff --git a/ledger/common/common.go b/ledger/common/common.go index 0d84b49a..51b0590d 100644 --- a/ledger/common/common.go +++ b/ledger/common/common.go @@ -19,10 +19,10 @@ import ( "encoding/json" "fmt" - "github.com/blinklabs-io/gouroboros/bech32" - "github.com/blinklabs-io/gouroboros/cbor" - + "github.com/btcsuite/btcd/btcutil/bech32" "golang.org/x/crypto/blake2b" + + "github.com/blinklabs-io/gouroboros/cbor" ) const (