@@ -11,20 +11,20 @@ import (
11
11
"crypto/rand"
12
12
"crypto/sha256"
13
13
"crypto/sha512"
14
+ "math/big"
14
15
"strings"
15
16
16
- "github.com/holiman/uint256"
17
17
"github.com/pkg/errors"
18
18
"golang.org/x/crypto/pbkdf2"
19
19
)
20
20
21
21
var (
22
- one = uint256 .NewInt (1 )
23
- two = uint256 .NewInt (2 )
22
+ one = big .NewInt (1 )
23
+ two = big .NewInt (2 )
24
24
25
25
bitsChunkSize = 11
26
- shift11BitsMask = new (uint256 .Int ).Lsh (one , uint (bitsChunkSize )) // 2^11 = 2048
27
- last11BitsMask = new (uint256 .Int ).Sub (shift11BitsMask , one ) // 2^11 - 1 = 2047
26
+ shift11BitsMask = new (big .Int ).Lsh (one , uint (bitsChunkSize )) // 2^11 = 2048
27
+ last11BitsMask = new (big .Int ).Sub (shift11BitsMask , one ) // 2^11 - 1 = 2047
28
28
)
29
29
30
30
// NewEntropy will create random entropy bytes
@@ -61,10 +61,10 @@ func NewMnemonic(entropy []byte) (string, error) {
61
61
62
62
// Add checksum to entropy.
63
63
// Entropy as an int so we can bitmask without worrying about bytes slices.
64
- entropyInt := new (uint256. Int ). SetBytes ( addChecksum (entropy ) )
64
+ entropyInt := addChecksum (entropy )
65
65
66
- // Throw away uint256 .Int for AND masking.
67
- word := uint256 .NewInt (0 )
66
+ // Throw away big .Int for AND masking.
67
+ word := big .NewInt (0 )
68
68
69
69
// Slice to hold words in.
70
70
words := make ([]string , sentenceLength )
@@ -92,10 +92,10 @@ func NewSeed(mnemonic, password string) []byte {
92
92
}
93
93
94
94
// Appends to data the first (len(data) / 32)bits of the result of sha256(data)
95
- // abd returns the result as a uint256 .Int.
95
+ // abd returns the result as a big .Int.
96
96
//
97
97
// Currently only supports data up to 32 bytes.
98
- func addChecksum (data []byte ) [] byte {
98
+ func addChecksum (data []byte ) * big. Int {
99
99
// Get first byte of sha256
100
100
hash := computeChecksum (data )
101
101
firstChecksumByte := hash [0 ]
@@ -106,7 +106,7 @@ func addChecksum(data []byte) []byte {
106
106
// For each bit of check sum we want we shift the data one the left
107
107
// and then set the (new) right most bit equal to checksum bit at that index
108
108
// staring from the left
109
- dataInt := new (uint256 .Int ).SetBytes (data )
109
+ dataInt := new (big .Int ).SetBytes (data )
110
110
for i := uint (0 ); i < checksumBitLength ; i ++ {
111
111
// Bitshift 1 left
112
112
dataInt .Mul (dataInt , two )
@@ -117,7 +117,7 @@ func addChecksum(data []byte) []byte {
117
117
}
118
118
}
119
119
120
- return dataInt . Bytes ()
120
+ return dataInt
121
121
}
122
122
123
123
func computeChecksum (data []byte ) []byte {
0 commit comments