diff --git a/src/BTCDepositAddressDeriver.sol b/src/BTCDepositAddressDeriver.sol index 00ac591..aeb04d2 100644 --- a/src/BTCDepositAddressDeriver.sol +++ b/src/BTCDepositAddressDeriver.sol @@ -17,7 +17,7 @@ error CannotParseBtcAddress( // Types of Bitcoin Network -contract BTCDepositAddressDeriver { +contract BTCDepositAddressDeriver is Bech32m, Deriver { event SeedChanged(string btcAddr1, string btcAddr2, string hrp); diff --git a/src/Bech32m.sol b/src/Bech32m.sol index 7340d51..32001b7 100644 --- a/src/Bech32m.sol +++ b/src/Bech32m.sol @@ -7,7 +7,7 @@ pragma solidity ^0.8.24; error EncodingIsUnknown(); -library Bech32m { +contract Bech32m { enum BechEncoding { // Used is SegWit v.0 @@ -50,49 +50,6 @@ library Bech32m { IncorrectEncodingForSegwitVn } - function explainDecodeError(DecodeError err) public pure returns (string memory) { - if (err == DecodeError.NoError) { - return string("No error"); - } else if (err == DecodeError.IncorrectPadding) { - return string("Incorrect Padding"); - } else if (err == DecodeError.IncorrectLength) { - return string("Incorrect address length"); - } else if (err == DecodeError.CharacterOutOfRange) { - return string("Address contain character out of range"); - } else if (err == DecodeError.MixedCase) { - return string("Address consists of both capital and small letters"); - } else if (err == DecodeError.IncorrectChecksum) { - return string("Address checksum does not match"); - } else if (err == DecodeError.TooShortChecksum) { - return string("Address checksum is too short"); - } else if (err == DecodeError.InputIsTooLong) { - return string("Address is too long"); - } else if (err == DecodeError.NotBech32Character) { - return string("Address contains character which is not in bech32 encoding"); - } else if (err == DecodeError.HRPIsEmpty) { - return string("Network prefix is empty"); - } else if (err == DecodeError.NoDelimiter) { - return string("No prefix delimiter in the address"); - } else if (err == DecodeError.HRPMismatch) { - return string("Network prefix is different from expected"); - } else if (err == DecodeError.WitnessProgramTooSmall) { - return string("Witness program should be at least 2 bytes"); - } else if (err == DecodeError.EmptyData) { - return string("Witness program is empty"); - } else if (err == DecodeError.WitnessProgramTooLarge) { - return string("Witness program should be maximum 40 bytes"); - } else if (err == DecodeError.SegwitVersionTooLarge) { - return string("Segwit version should be from 0 to 16 (including). Got some larger number."); - } else if (err == DecodeError.IncorrectSegwitV0Program) { - return string("Length of segwit v0 program should be either 20 or 32 bytes"); - } else if (err == DecodeError.IncorrectEncodingForSegwitV0) { - return string("Segwit v0 should be encoded using Bech32"); - } else if (err == DecodeError.IncorrectEncodingForSegwitVn) { - return string("Segwit with versions 1-16 should be encoded with Bech32m"); - } - return ""; -} - // Possible characters for Bitcoin address bytes internal constant CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l"; @@ -617,7 +574,7 @@ library Bech32m { // Decode a segwit address function decodeSegwitAddress( - bytes calldata expectedHrp, + bytes memory expectedHrp, bytes calldata addr ) public pure returns (uint8, bytes memory, DecodeError) { ( diff --git a/src/Deriver.sol b/src/Deriver.sol index dea32bb..befeafb 100644 --- a/src/Deriver.sol +++ b/src/Deriver.sol @@ -6,7 +6,7 @@ import {EllipticCurve} from "../lib/elliptic-curve-solidity/contracts/EllipticCu import {Bech32m} from "./Bech32m.sol"; -library Deriver { +contract Deriver is Bech32m { // BEGIN SECP256k1 CONSTANTS uint256 public constant GX =