github.com/machinefi/w3bstream@v1.6.5-rc9.0.20240426031326-b8c7c4876e72/cmd/srv-applet-mgr/apis/account/get.go (about) 1 package account 2 3 import ( 4 "context" 5 "crypto/ed25519" 6 7 solcommon "github.com/blocto/solana-go-sdk/common" 8 "github.com/ethereum/go-ethereum/common" 9 "github.com/ethereum/go-ethereum/crypto" 10 11 "github.com/machinefi/w3bstream/cmd/srv-applet-mgr/apis/middleware" 12 "github.com/machinefi/w3bstream/pkg/depends/kit/httptransport/httpx" 13 "github.com/machinefi/w3bstream/pkg/enums" 14 "github.com/machinefi/w3bstream/pkg/modules/operator" 15 ) 16 17 // Deprecated use operator.ListOperator 18 type GetOperatorAddr struct { 19 httpx.MethodGet `summary:"Get account operator by name"` 20 21 AccountOperatorName string `in:"query" name:"accountOperatorName,omitempty"` // account operator name 22 } 23 24 func (r *GetOperatorAddr) Path() string { return "/operatoraddr" } 25 26 func (r *GetOperatorAddr) Output(ctx context.Context) (interface{}, error) { 27 if r.AccountOperatorName == "" { 28 r.AccountOperatorName = operator.DefaultOperatorName 29 } 30 31 ca := middleware.MustCurrentAccountFromContext(ctx) 32 op, err := operator.GetByAccountAndName(ctx, ca.AccountID, r.AccountOperatorName) 33 if err != nil { 34 return nil, err 35 } 36 if op.Type == enums.OPERATOR_KEY__ECDSA { 37 prvkey, err := crypto.HexToECDSA(op.PrivateKey) 38 if err != nil { 39 return nil, err 40 } 41 pubkey := crypto.PubkeyToAddress(prvkey.PublicKey) 42 return pubkey.Hex(), nil 43 } else { 44 b := common.FromHex(op.PrivateKey) 45 prik := ed25519.PrivateKey(b) 46 pubk := solcommon.PublicKeyFromBytes(prik.Public().(ed25519.PublicKey)) 47 return pubk.ToBase58(), nil 48 } 49 }