55 "encoding/json"
66 "fmt"
77
8+ "github.com/iotaledger/hive.go/serializer"
89 "github.com/iotaledger/iota.go/v2/bech32"
910 "github.com/iotaledger/iota.go/v2/ed25519"
1011 "golang.org/x/crypto/blake2b"
@@ -31,12 +32,12 @@ const (
3132 // Ed25519AddressBytesLength is the length of an Ed25519 address.
3233 Ed25519AddressBytesLength = blake2b .Size256
3334 // Ed25519AddressSerializedBytesSize is the size of a serialized Ed25519 address with its type denoting byte.
34- Ed25519AddressSerializedBytesSize = SmallTypeDenotationByteSize + Ed25519AddressBytesLength
35+ Ed25519AddressSerializedBytesSize = serializer . SmallTypeDenotationByteSize + Ed25519AddressBytesLength
3536)
3637
3738// Address describes a general address.
3839type Address interface {
39- Serializable
40+ serializer. Serializable
4041 fmt.Stringer
4142
4243 // Type returns the type of the address.
@@ -47,7 +48,7 @@ type Address interface {
4748}
4849
4950// AddressSelector implements SerializableSelectorFunc for address types.
50- func AddressSelector (addressType uint32 ) (Serializable , error ) {
51+ func AddressSelector (addressType uint32 ) (serializer. Serializable , error ) {
5152 return newAddress (byte (addressType ))
5253}
5354
@@ -61,7 +62,7 @@ func newAddress(addressType byte) (address Address, err error) {
6162}
6263
6364func bech32String (hrp NetworkPrefix , addr Address ) string {
64- bytes , _ := addr .Serialize (DeSeriModeNoValidation )
65+ bytes , _ := addr .Serialize (serializer . DeSeriModeNoValidation )
6566 s , err := bech32 .Encode (string (hrp ), bytes )
6667 if err != nil {
6768 panic (err )
@@ -77,21 +78,21 @@ func ParseBech32(s string) (NetworkPrefix, Address, error) {
7778 }
7879
7980 if len (addrData ) == 0 {
80- return "" , nil , ErrDeserializationNotEnoughData
81+ return "" , nil , serializer . ErrDeserializationNotEnoughData
8182 }
8283
8384 addr , err := newAddress (addrData [0 ])
8485 if err != nil {
8586 return "" , nil , err
8687 }
8788
88- n , err := addr .Deserialize (addrData , DeSeriModePerformValidation )
89+ n , err := addr .Deserialize (addrData , serializer . DeSeriModePerformValidation )
8990 if err != nil {
9091 return "" , nil , err
9192 }
9293
9394 if n != len (addrData ) {
94- return "" , nil , ErrDeserializationNotAllConsumed
95+ return "" , nil , serializer . ErrDeserializationNotAllConsumed
9596 }
9697
9798 return NetworkPrefix (hrp ), addr , nil
@@ -134,23 +135,23 @@ func (edAddr *Ed25519Address) String() string {
134135 return hex .EncodeToString (edAddr [:])
135136}
136137
137- func (edAddr * Ed25519Address ) Deserialize (data []byte , deSeriMode DeSerializationMode ) (int , error ) {
138- if deSeriMode .HasMode (DeSeriModePerformValidation ) {
139- if err := checkMinByteLength (Ed25519AddressSerializedBytesSize , len (data )); err != nil {
138+ func (edAddr * Ed25519Address ) Deserialize (data []byte , deSeriMode serializer. DeSerializationMode ) (int , error ) {
139+ if deSeriMode .HasMode (serializer . DeSeriModePerformValidation ) {
140+ if err := serializer . CheckMinByteLength (Ed25519AddressSerializedBytesSize , len (data )); err != nil {
140141 return 0 , fmt .Errorf ("invalid Ed25519 address bytes: %w" , err )
141142 }
142- if err := checkTypeByte (data , AddressEd25519 ); err != nil {
143+ if err := serializer . CheckTypeByte (data , AddressEd25519 ); err != nil {
143144 return 0 , fmt .Errorf ("unable to deserialize Ed25519 address: %w" , err )
144145 }
145146 }
146- copy (edAddr [:], data [SmallTypeDenotationByteSize :])
147+ copy (edAddr [:], data [serializer . SmallTypeDenotationByteSize :])
147148 return Ed25519AddressSerializedBytesSize , nil
148149}
149150
150- func (edAddr * Ed25519Address ) Serialize (deSeriMode DeSerializationMode ) (data []byte , err error ) {
151+ func (edAddr * Ed25519Address ) Serialize (deSeriMode serializer. DeSerializationMode ) (data []byte , err error ) {
151152 var b [Ed25519AddressSerializedBytesSize ]byte
152153 b [0 ] = AddressEd25519
153- copy (b [SmallTypeDenotationByteSize :], edAddr [:])
154+ copy (b [serializer . SmallTypeDenotationByteSize :], edAddr [:])
154155 return b [:], nil
155156}
156157
@@ -197,12 +198,12 @@ type jsonEd25519Address struct {
197198 Address string `json:"address"`
198199}
199200
200- func (j * jsonEd25519Address ) ToSerializable () (Serializable , error ) {
201+ func (j * jsonEd25519Address ) ToSerializable () (serializer. Serializable , error ) {
201202 addrBytes , err := hex .DecodeString (j .Address )
202203 if err != nil {
203204 return nil , fmt .Errorf ("unable to decode address from JSON for Ed25519 address: %w" , err )
204205 }
205- if err := checkExactByteLength (len (addrBytes ), Ed25519AddressBytesLength ); err != nil {
206+ if err := serializer . CheckExactByteLength (len (addrBytes ), Ed25519AddressBytesLength ); err != nil {
206207 return nil , fmt .Errorf ("unable to decode address from JSON for Ed25519 address: %w" , err )
207208 }
208209 addr := & Ed25519Address {}
0 commit comments