mirror of
https://github.com/GMWalletApp/epusdt.git
synced 2026-07-07 18:26:16 +00:00
fix: (update tron logic)
This commit is contained in:
@@ -1,7 +1,9 @@
|
||||
package crypto
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
|
||||
"github.com/shengdoushi/base58"
|
||||
)
|
||||
@@ -28,3 +30,24 @@ func EncodeCheck(input []byte) string {
|
||||
|
||||
return Encode(inputCheck)
|
||||
}
|
||||
|
||||
// DecodeCheck decodes a Base58Check string and validates its 4-byte checksum.
|
||||
func DecodeCheck(input string) ([]byte, error) {
|
||||
raw, err := base58.Decode(input, base58.BitcoinAlphabet)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(raw) < 4 {
|
||||
return nil, fmt.Errorf("base58check payload too short")
|
||||
}
|
||||
|
||||
payload := raw[:len(raw)-4]
|
||||
checksum := raw[len(raw)-4:]
|
||||
|
||||
h0 := sha256.Sum256(payload)
|
||||
h1 := sha256.Sum256(h0[:])
|
||||
if !bytes.Equal(checksum, h1[:4]) {
|
||||
return nil, fmt.Errorf("base58check checksum mismatch")
|
||||
}
|
||||
return payload, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user