-
Notifications
You must be signed in to change notification settings - Fork 95
/
address_ed25519.gen.go
108 lines (83 loc) · 2.9 KB
/
address_ed25519.gen.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
package iotago
// Code generated by go generate; DO NOT EDIT. Check gen/ directory instead.
import (
"context"
"crypto/ed25519"
"io"
"golang.org/x/crypto/blake2b"
"github.com/iotaledger/hive.go/ierrors"
"github.com/iotaledger/hive.go/lo"
"github.com/iotaledger/hive.go/serializer/v2"
"github.com/iotaledger/hive.go/serializer/v2/stream"
"github.com/iotaledger/iota.go/v4/hexutil"
)
const (
// Ed25519AddressBytesLength is the length of an Ed25519Address.
Ed25519AddressBytesLength = blake2b.Size256
// Ed25519AddressSerializedBytesSize is the size of a serialized Ed25519Address with its type denoting byte.
Ed25519AddressSerializedBytesSize = serializer.SmallTypeDenotationByteSize + Ed25519AddressBytesLength
)
// Ed25519Address defines an Ed25519Address.
// An Ed25519Address is the Blake2b-256 hash of an Ed25519 public key.
type Ed25519Address [Ed25519AddressBytesLength]byte
func (addr *Ed25519Address) Clone() Address {
cpy := &Ed25519Address{}
copy(cpy[:], addr[:])
return cpy
}
func (addr *Ed25519Address) StorageScore(_ *StorageScoreStructure, _ StorageScoreFunc) StorageScore {
return 0
}
func (addr *Ed25519Address) ID() []byte {
return lo.PanicOnErr(CommonSerixAPI().Encode(context.TODO(), addr))
}
func (addr *Ed25519Address) Key() string {
return string(addr.ID())
}
func (addr *Ed25519Address) Unlock(msg []byte, sig Signature) error {
edSig, isEdSig := sig.(*Ed25519Signature)
if !isEdSig {
return ierrors.Wrapf(ErrSignatureAndAddrIncompatible, "can not unlock Ed25519Address with signature of type %s", sig.Type())
}
return edSig.Valid(msg, (*Ed25519Address)(addr))
}
func (addr *Ed25519Address) Equal(other Address) bool {
otherAddr, is := other.(*Ed25519Address)
if !is {
return false
}
return *addr == *otherAddr
}
func (addr *Ed25519Address) Type() AddressType {
return AddressEd25519
}
func (addr *Ed25519Address) Bech32(hrp NetworkPrefix) string {
return bech32StringBytes(hrp, addr.ID())
}
func (addr *Ed25519Address) String() string {
return hexutil.EncodeHex(addr.ID())
}
func (addr *Ed25519Address) Size() int {
return Ed25519AddressSerializedBytesSize
}
// Ed25519AddressFromPubKey returns the address belonging to the given Ed25519 public key.
func Ed25519AddressFromPubKey(pubKey ed25519.PublicKey) *Ed25519Address {
address := blake2b.Sum256(pubKey[:])
return (*Ed25519Address)(&address)
}
// Ed25519AddressFromReader parses the Ed25519Address from the given reader.
func Ed25519AddressFromReader(reader io.Reader) (*Ed25519Address, error) {
addrBytes, err := stream.ReadBytes(reader, Ed25519AddressSerializedBytesSize)
if err != nil {
return nil, ierrors.Wrap(err, "unable to read address bytes")
}
addr, _, err := AddressFromBytes(addrBytes)
if err != nil {
return nil, ierrors.Wrap(err, "unable to parse address from bytes")
}
address, ok := addr.(*Ed25519Address)
if !ok {
return nil, ierrors.Errorf("invalid address type: %T", addr)
}
return address, nil
}