Documentation ¶
Overview ¶
Code generated by gitee.com/magic-mountain/utils/rpc/gen.go.
Code generated by gitee.com/magic-mountain/utils/rpc/gen.go.
Index ¶
- Constants
- Variables
- func ApendWalletCmd(app *cli.App)
- func Verify(ctx context.Context, address []byte, msg []byte, sig *crypto.Signature) error
- type Iwallet
- type IwalletService
- func (s *IwalletService) Default(p0 context.Context) address.Address
- func (s *IwalletService) Delete(p0 context.Context, p1 address.Address) error
- func (s *IwalletService) Export(p0 context.Context) (string, error)
- func (s *IwalletService) Import(p0 context.Context, p1 string, p2 string) error
- func (s *IwalletService) Init(p0 context.Context, p1 crypto.SigType) (address.Address, error)
- func (s *IwalletService) List(p0 context.Context) ([]address.Address, error)
- func (s *IwalletService) New(p0 context.Context, p1 crypto.SigType) (address.Address, error)
- func (s *IwalletService) Setdefault(p0 context.Context, p1 address.Address) error
- func (s *IwalletService) Sign(p0 context.Context, p1 []byte, p2 []byte) (*crypto.Signature, error)
- func (s *IwalletService) SignDefault(p0 context.Context, p1 []byte) (*crypto.Signature, error)
- func (s *IwalletService) Verify(p0 context.Context, p1 []byte, p2 []byte, p3 *crypto.Signature) (bool, error)
- type IwalletStruct
- func (s *IwalletStruct) Default(p0 context.Context) address.Address
- func (s *IwalletStruct) Delete(p0 context.Context, p1 address.Address) error
- func (s *IwalletStruct) Export(p0 context.Context) (string, error)
- func (s *IwalletStruct) Import(p0 context.Context, p1 string, p2 string) error
- func (s *IwalletStruct) Init(p0 context.Context, p1 crypto.SigType) (address.Address, error)
- func (s *IwalletStruct) List(p0 context.Context) ([]address.Address, error)
- func (s *IwalletStruct) New(p0 context.Context, p1 crypto.SigType) (address.Address, error)
- func (s *IwalletStruct) Setdefault(p0 context.Context, p1 address.Address) error
- func (s *IwalletStruct) Sign(p0 context.Context, p1 []byte, p2 []byte) (*crypto.Signature, error)
- func (s *IwalletStruct) SignDefault(p0 context.Context, p1 []byte) (*crypto.Signature, error)
- func (s *IwalletStruct) Verify(p0 context.Context, p1 []byte, p2 []byte, p3 *crypto.Signature) (bool, error)
- type IwalletStub
- type Key
- type KeyInfo
- type Keys
- type Wallet
- func (w *Wallet) Default(ctx context.Context) address.Address
- func (w *Wallet) Delete(ctx context.Context, address address.Address) error
- func (w *Wallet) Export(ctx context.Context) (string, error)
- func (w *Wallet) Import(ctx context.Context, hexs string, pwd string) error
- func (w *Wallet) Init(ctx context.Context, typ crypto.SigType) (address.Address, error)
- func (w *Wallet) List(ctx context.Context) ([]address.Address, error)
- func (w *Wallet) New(ctx context.Context, typ crypto.SigType) (address.Address, error)
- func (w *Wallet) Setdefault(ctx context.Context, a address.Address) error
- func (w *Wallet) Sign(ctx context.Context, address []byte, msg []byte) (*crypto.Signature, error)
- func (w *Wallet) SignDefault(ctx context.Context, msg []byte) (*crypto.Signature, error)
- func (w *Wallet) StratrpcServer(url string) error
- func (w *Wallet) Verify(ctx context.Context, address []byte, msg []byte, sig *crypto.Signature) (bool, error)
Constants ¶
View Source
const ( KTBLS string = "bls" KTSecp256k1 string = "secp256k1" KTSecp256k1Ledger string = "secp256k1-ledger" )
View Source
const ( // KNamePrefix = "wallet-" // KList = "asmb-chain-wallet-list" KDefault = "asmb-chain-wallet" )
Variables ¶
View Source
var DefaultCmd = &cli.Command{ Name: "default", Usage: "显示默认地址", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { w, c, err := getwallet(cctx) defer c() if err != nil { return err } addr := w.Default(context.Background()) fmt.Println(addr.String()) return nil }, }
View Source
var DeleteCmd = &cli.Command{ Name: "delete", Usage: "创建一个新的地址", Flags: []cli.Flag{ cli.StringFlag{ Name: "addr,a", Required: true, Usage: "地址", }, }, Action: func(cctx *cli.Context) error { w, c, err := getwallet(cctx) defer c() if err != nil { return err } addr, err := address.NewFromString(cctx.String("addr")) if err != nil { return err } err = w.Delete(context.Background(), addr) if err != nil { return err } else { fmt.Println("删除成功") } return nil }, }
View Source
var ExportCmd = &cli.Command{ Name: "export", Usage: "导出", Action: func(cctx *cli.Context) error { w, c, err := getwallet(cctx) defer c() if err != nil { return err } hexs, err := w.Export(context.Background()) if err != nil { return err } fmt.Println(hexs) return nil }, }
View Source
var ImportCmd = &cli.Command{ Name: "import", Usage: "创建一个新的地址", Flags: []cli.Flag{ cli.StringFlag{ Name: "password2,p2", Value: "123456", Usage: "导入文本密码", Required: false, }, cli.StringFlag{ Name: "keyhexstr,khex", Value: "", Usage: "钱包密码", Required: true, }, }, Action: func(cctx *cli.Context) error { w, c, err := getwallet(cctx) defer c() if err != nil { return err } err = w.Import(context.Background(), cctx.String("keyhexstr"), cctx.String("password2")) if err != nil { return err } fmt.Println("导入成功") return nil }, }
View Source
var InitCmd = &cli.Command{ Name: "init", Usage: "初始化钱包", Flags: []cli.Flag{ cli.IntFlag{ Name: "type,t", Value: 1, Usage: "SigType SigTypeSecp256k1=1 SigTypeBLS=2", }, }, Action: func(cctx *cli.Context) error { w, c, err := getwallet(cctx) defer c() if err != nil { return err } addr, err := w.Init(context.Background(), crypto.SigType(cctx.Int("type"))) if err != nil { return err } fmt.Printf("创建了一个默认地址:%s\n", addr.String()) return nil }, }
View Source
var ListCmd = &cli.Command{ Name: "list", Usage: "显示所有地址", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { w, _, err := getwallet(cctx) if err != nil { return err } ctxout, cancel := context.WithTimeout(context.Background(), time.Second*500) defer cancel() addrs, err := w.List(ctxout) if err != nil { fmt.Println(err) } for _, value := range addrs { fmt.Println(value.String()) jsonbytes, _ := json.Marshal(value.Payload()) fmt.Printf("%s\n", jsonbytes) } return nil }, }
View Source
var NewCmd = &cli.Command{ Name: "new", Usage: "创建一个新的地址", Flags: []cli.Flag{ cli.IntFlag{ Name: "type,t", Value: 1, Usage: "SigType SigTypeSecp256k1=1 SigTypeBLS=2", }, }, Action: func(cctx *cli.Context) error { w, c, err := getwallet(cctx) defer c() if err != nil { return err } addr, err := w.New(context.Background(), crypto.SigType(cctx.Int("type"))) if err != nil { return err } fmt.Println(addr.String()) return nil }, }
View Source
var RpcCmd = &cli.Command{ Name: "rpc", Usage: "开启本地rpc服务", Flags: []cli.Flag{}, Action: func(cctx *cli.Context) error { d, err := leveldb.OpenFile(filepath.Dir(os.Args[0]), nil) if err != nil { return err } defer d.Close() if err != nil { return err } w, err := Newwallet(cctx.GlobalString("password"), d) if err != nil { return err } fmt.Printf("wallet local rpcserver start at %s\n", cctx.GlobalString("url")) err = w.StratrpcServer(cctx.GlobalString("url")) if err != nil { return err } return nil }, }
View Source
var SetdefaultCmd = &cli.Command{ Name: "setdefault", Usage: "设置默认地址", Flags: []cli.Flag{ cli.StringFlag{ Name: "addr,a", Required: true, Usage: "默认地址", }, }, Action: func(cctx *cli.Context) error { w, c, err := getwallet(cctx) defer c() if err != nil { return err } if !cctx.IsSet("addr") { return errors.New("addr is not set") } addr_f, err := address.NewFromString(cctx.String("addr")) if err != nil { return err } err = w.Setdefault(context.Background(), addr_f) if err != nil { return err } fmt.Println("设置成功") return nil }, }
View Source
var SignCmd = &cli.Command{ Name: "sign", Usage: "数据签名", Flags: []cli.Flag{ cli.StringFlag{ Name: "msg,m", Required: true, Usage: "要签名的数据", }, }, Action: func(cctx *cli.Context) error { w, c, err := getwallet(cctx) defer c() if err != nil { return err } sig, err := w.SignDefault(context.Background(), []byte(cctx.String("msg"))) if err != nil { return err } sigBytes := append([]byte{byte(sig.Type)}, sig.Data...) fmt.Println(hex.EncodeToString(sigBytes)) return nil }, }
View Source
var VerifyCmd = &cli.Command{ Name: "verify", Usage: "验证数据签名", Flags: []cli.Flag{ cli.StringFlag{ Name: "sign,s", Required: true, Usage: "已签名的数据", }, cli.StringFlag{ Name: "msg,m", Required: true, Usage: "原始数据", }, cli.StringFlag{ Name: "addr,a", Required: false, Usage: "地址", }, }, Action: func(cctx *cli.Context) error { w, c, err := getwallet(cctx) defer c() if err != nil { return err } addr := w.Default(context.Background()) if cctx.IsSet("addr") { addr, err = address.NewFromString(cctx.String("addr")) if err != nil { return err } } sign, err := hex.DecodeString(cctx.String("sign")) if err != nil { return err } var sig crypto.Signature if err := sig.UnmarshalBinary(sign); err != nil { return err } isv, err := w.Verify(context.Background(), addr.Payload(), []byte(cctx.String("msg")), &sig) if err != nil { return err } fmt.Printf("验证结果:%v\n", isv) return nil }, }
Functions ¶
func ApendWalletCmd ¶
Types ¶
type Iwallet ¶
type Iwallet interface { Init(ctx context.Context, typ crypto.SigType) (address.Address, error) //perm:admin New(ctx context.Context, typ crypto.SigType) (address.Address, error) //perm:admin List(ctx context.Context) ([]address.Address, error) //perm:admin Delete(ctx context.Context, address address.Address) error //perm:admin SignDefault(ctx context.Context, msg []byte) (*crypto.Signature, error) //perm:admin Sign(ctx context.Context, address []byte, msg []byte) (*crypto.Signature, error) //perm:admin Verify(ctx context.Context, address []byte, msg []byte, sig *crypto.Signature) (bool, error) //perm:admin Export(ctx context.Context) (string, error) //perm:admin Import(ctx context.Context, hexs string, pwd string) error //perm:admin Default(ctx context.Context) address.Address //perm:admin Setdefault(ctx context.Context, a address.Address) error //perm:admin }
type IwalletService ¶
type IwalletService struct { Clist *concurrent.ConcurrentList Local Iwallet }
func (*IwalletService) Default ¶
func (s *IwalletService) Default(p0 context.Context) address.Address
func (*IwalletService) Delete ¶
func (s *IwalletService) Delete(p0 context.Context, p1 address.Address) error
func (*IwalletService) List ¶
func (s *IwalletService) List(p0 context.Context) ([]address.Address, error)
func (*IwalletService) Setdefault ¶
func (s *IwalletService) Setdefault(p0 context.Context, p1 address.Address) error
func (*IwalletService) SignDefault ¶
type IwalletStruct ¶
type IwalletStruct struct { Internal struct { Default func(p0 context.Context) address.Address `perm:"admin"` Delete func(p0 context.Context, p1 address.Address) error `perm:"admin"` Export func(p0 context.Context) (string, error) `perm:"admin"` Import func(p0 context.Context, p1 string, p2 string) error `perm:"admin"` Init func(p0 context.Context, p1 crypto.SigType) (address.Address, error) `perm:"admin"` List func(p0 context.Context) ([]address.Address, error) `perm:"admin"` New func(p0 context.Context, p1 crypto.SigType) (address.Address, error) `perm:"admin"` Setdefault func(p0 context.Context, p1 address.Address) error `perm:"admin"` Sign func(p0 context.Context, p1 []byte, p2 []byte) (*crypto.Signature, error) `perm:"admin"` SignDefault func(p0 context.Context, p1 []byte) (*crypto.Signature, error) `perm:"admin"` Verify func(p0 context.Context, p1 []byte, p2 []byte, p3 *crypto.Signature) (bool, error) `perm:"admin"` } }
func (*IwalletStruct) Default ¶
func (s *IwalletStruct) Default(p0 context.Context) address.Address
func (*IwalletStruct) Delete ¶
func (s *IwalletStruct) Delete(p0 context.Context, p1 address.Address) error
func (*IwalletStruct) List ¶
func (s *IwalletStruct) List(p0 context.Context) ([]address.Address, error)
func (*IwalletStruct) Setdefault ¶
func (s *IwalletStruct) Setdefault(p0 context.Context, p1 address.Address) error
func (*IwalletStruct) SignDefault ¶
type IwalletStub ¶
type IwalletStub struct { }
type Keys ¶
type Keys struct { Defaultkey *Key //当前签名key Keylist []*Key // contains filtered or unexported fields }
type wallethash [20]byte
type Wallet ¶
type Wallet struct { Keys *Keys // contains filtered or unexported fields }
func NewwalletCur ¶
func (*Wallet) Setdefault ¶
func (*Wallet) SignDefault ¶
func (*Wallet) StratrpcServer ¶
Click to show internal directories.
Click to hide internal directories.