Skip to content

Commit efec89a

Browse files
gzliudanfjl
andcommitted
accounts/keystore: use github.com/google/uuid (ethereum#22217)
This replaces the github.com/pborman/uuid dependency with github.com/google/uuid because the former is only a wrapper for the latter (since v1.0.0). Co-authored-by: Felix Lange <[email protected]>
1 parent 7509329 commit efec89a

File tree

6 files changed

+40
-21
lines changed

6 files changed

+40
-21
lines changed

accounts/keystore/key.go

+9-3
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ import (
3131
"github.com/XinFinOrg/XDPoSChain/accounts"
3232
"github.com/XinFinOrg/XDPoSChain/common"
3333
"github.com/XinFinOrg/XDPoSChain/crypto"
34-
"github.com/pborman/uuid"
34+
"github.com/google/uuid"
3535
)
3636

3737
const (
@@ -109,7 +109,10 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
109109
}
110110

111111
u := new(uuid.UUID)
112-
*u = uuid.Parse(keyJSON.Id)
112+
*u, err = uuid.Parse(keyJSON.Id)
113+
if err != nil {
114+
return err
115+
}
113116
k.Id = *u
114117
addr, err := hex.DecodeString(keyJSON.Address)
115118
if err != nil {
@@ -127,7 +130,10 @@ func (k *Key) UnmarshalJSON(j []byte) (err error) {
127130
}
128131

129132
func newKeyFromECDSA(privateKeyECDSA *ecdsa.PrivateKey) *Key {
130-
id := uuid.NewRandom()
133+
id, err := uuid.NewRandom()
134+
if err != nil {
135+
panic(fmt.Sprintf("Could not create random uuid: %v", err))
136+
}
131137
key := &Key{
132138
Id: id,
133139
Address: crypto.PubkeyToAddress(privateKeyECDSA.PublicKey),

accounts/keystore/passphrase.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ import (
4141
"github.com/XinFinOrg/XDPoSChain/common"
4242
"github.com/XinFinOrg/XDPoSChain/common/math"
4343
"github.com/XinFinOrg/XDPoSChain/crypto"
44-
"github.com/pborman/uuid"
44+
"github.com/google/uuid"
4545
"golang.org/x/crypto/pbkdf2"
4646
"golang.org/x/crypto/scrypt"
4747
)
@@ -226,9 +226,12 @@ func DecryptKey(keyjson []byte, auth string) (*Key, error) {
226226
return nil, err
227227
}
228228
key := crypto.ToECDSAUnsafe(keyBytes)
229-
229+
id, err := uuid.FromBytes(keyId)
230+
if err != nil {
231+
return nil, err
232+
}
230233
return &Key{
231-
Id: keyId,
234+
Id: id,
232235
Address: crypto.PubkeyToAddress(key.PublicKey),
233236
PrivateKey: key,
234237
}, nil
@@ -274,7 +277,11 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt
274277
if keyProtected.Version != version {
275278
return nil, nil, fmt.Errorf("version not supported: %v", keyProtected.Version)
276279
}
277-
keyId = uuid.Parse(keyProtected.Id)
280+
keyUUID, err := uuid.Parse(keyProtected.Id)
281+
if err != nil {
282+
return nil, nil, err
283+
}
284+
keyId = keyUUID[:]
278285
plainText, err := DecryptDataV3(keyProtected.Crypto, auth)
279286
if err != nil {
280287
return nil, nil, err
@@ -283,7 +290,11 @@ func decryptKeyV3(keyProtected *encryptedKeyJSONV3, auth string) (keyBytes []byt
283290
}
284291

285292
func decryptKeyV1(keyProtected *encryptedKeyJSONV1, auth string) (keyBytes []byte, keyId []byte, err error) {
286-
keyId = uuid.Parse(keyProtected.Id)
293+
keyUUID, err := uuid.Parse(keyProtected.Id)
294+
if err != nil {
295+
return nil, nil, err
296+
}
297+
keyId = keyUUID[:]
287298
mac, err := hex.DecodeString(keyProtected.Crypto.MAC)
288299
if err != nil {
289300
return nil, nil, err

accounts/keystore/presale.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ import (
2727

2828
"github.com/XinFinOrg/XDPoSChain/accounts"
2929
"github.com/XinFinOrg/XDPoSChain/crypto"
30-
"github.com/pborman/uuid"
30+
"github.com/google/uuid"
3131
"golang.org/x/crypto/pbkdf2"
3232
)
3333

@@ -37,7 +37,10 @@ func importPreSaleKey(keyStore keyStore, keyJSON []byte, password string) (accou
3737
if err != nil {
3838
return accounts.Account{}, nil, err
3939
}
40-
key.Id = uuid.NewRandom()
40+
key.Id, err = uuid.NewRandom()
41+
if err != nil {
42+
return accounts.Account{}, nil, err
43+
}
4144
a := accounts.Account{
4245
Address: key.Address,
4346
URL: accounts.URL{
@@ -86,7 +89,7 @@ func decryptPreSaleKey(fileContent []byte, password string) (key *Key, err error
8689
ecKey := crypto.ToECDSAUnsafe(ethPriv)
8790

8891
key = &Key{
89-
Id: nil,
92+
Id: uuid.UUID{},
9093
Address: crypto.PubkeyToAddress(ecKey.PublicKey),
9194
PrivateKey: ecKey,
9295
}

cmd/ethkey/generate.go

+6-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ import (
2525
"github.com/XinFinOrg/XDPoSChain/accounts/keystore"
2626
"github.com/XinFinOrg/XDPoSChain/cmd/utils"
2727
"github.com/XinFinOrg/XDPoSChain/crypto"
28-
"github.com/pborman/uuid"
28+
"github.com/google/uuid"
2929
"github.com/urfave/cli/v2"
3030
)
3131

@@ -85,9 +85,12 @@ If you want to encrypt an existing private key, it can be specified by setting
8585
}
8686

8787
// Create the keyfile object with a random UUID.
88-
id := uuid.NewRandom()
88+
UUID, err := uuid.NewRandom()
89+
if err != nil {
90+
utils.Fatalf("Failed to generate random uuid: %v", err)
91+
}
8992
key := &keystore.Key{
90-
Id: id,
93+
Id: UUID,
9194
Address: crypto.PubkeyToAddress(privateKey.PublicKey),
9295
PrivateKey: privateKey,
9396
}

go.mod

+1-2
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ require (
2323
github.com/mattn/go-colorable v0.1.13
2424
github.com/naoina/toml v0.1.2-0.20170918210437-9fafd6967416
2525
github.com/olekukonko/tablewriter v0.0.5
26-
github.com/pborman/uuid v1.2.0
2726
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7
2827
github.com/pkg/errors v0.9.1
2928
github.com/prometheus/prometheus v1.7.2-0.20170814170113-3101606756c5
@@ -52,6 +51,7 @@ require (
5251
github.com/gballet/go-libpcsclite v0.0.0-20191108122812-4678299bea08
5352
github.com/go-yaml/yaml v2.1.0+incompatible
5453
github.com/google/gofuzz v1.2.0
54+
github.com/google/uuid v1.6.0
5555
github.com/influxdata/influxdb-client-go/v2 v2.4.0
5656
github.com/influxdata/influxdb1-client v0.0.0-20220302092344-a9ab5670611c
5757
github.com/karalabe/usb v0.0.2
@@ -78,7 +78,6 @@ require (
7878
github.com/garslo/gogen v0.0.0-20170306192744-1d203ffc1f61 // indirect
7979
github.com/go-ole/go-ole v1.2.5 // indirect
8080
github.com/go-sourcemap/sourcemap v2.1.3+incompatible // indirect
81-
github.com/google/uuid v1.3.0 // indirect
8281
github.com/influxdata/line-protocol v0.0.0-20200327222509-2487e7298839 // indirect
8382
github.com/kilic/bls12-381 v0.1.0 // indirect
8483
github.com/kr/pretty v0.3.1 // indirect

go.sum

+2-5
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,8 @@ github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeN
9292
github.com/google/gofuzz v1.2.0 h1:xRy4A+RhZaiKjJ1bPfwQ8sedCA+YS2YcCHW6ec7JMi0=
9393
github.com/google/gofuzz v1.2.0/go.mod h1:dBl0BpW6vV/+mYPU4Po3pmUjxk6FQPldtuIdl/M65Eg=
9494
github.com/google/subcommands v1.2.0/go.mod h1:ZjhPrFU+Olkh9WazFPsl27BQ4UPiG37m3yTrtFlrHVk=
95-
github.com/google/uuid v1.0.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
96-
github.com/google/uuid v1.3.0 h1:t6JiXgmwXMjEs8VusXIJk2BXHsn+wx8BZdTaoZ5fu7I=
97-
github.com/google/uuid v1.3.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
95+
github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0=
96+
github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo=
9897
github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
9998
github.com/gorilla/websocket v1.4.2 h1:+/TMaTYc4QFitKJxsQ7Yye35DkWvkdLcvGKqM+x0Ufc=
10099
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
@@ -171,8 +170,6 @@ github.com/onsi/ginkgo v1.14.0/go.mod h1:iSB4RoI2tjJc9BBv4NKIKWKya62Rps+oPG/Lv9k
171170
github.com/onsi/gomega v1.7.1/go.mod h1:XdKZgCCFLUoM/7CFJVPcG8C1xQ1AJ0vpAezJrB7JYyY=
172171
github.com/onsi/gomega v1.10.1 h1:o0+MgICZLuZ7xjH7Vx6zS/zcu93/BEp1VwkIW1mEXCE=
173172
github.com/onsi/gomega v1.10.1/go.mod h1:iN09h71vgCQne3DLsj+A5owkum+a2tYe+TOCB1ybHNo=
174-
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
175-
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
176173
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7 h1:oYW+YCJ1pachXTQmzR3rNLYGGz4g/UgFcjb28p/viDM=
177174
github.com/peterh/liner v1.1.1-0.20190123174540-a2c9a5303de7/go.mod h1:CRroGNssyjTd/qIG2FyxByd2S8JEAZXBl4qUrZf8GS0=
178175
github.com/pkg/diff v0.0.0-20210226163009-20ebb0f2a09e/go.mod h1:pJLUxLENpZxwdsKMEsNbx1VGcRFpLqf3715MtcvvzbA=

0 commit comments

Comments
 (0)