identity

package
v0.0.0-...-9a83fbb Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 25, 2023 License: MIT Imports: 22 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CreateSignMessage

func CreateSignMessage(address common.Address, t SignType) string

func Module

func Module(sb *server.ServerBuiler)

func VerifySignMessage

func VerifySignMessage(address common.Address, sign string, signType SignType, t WalletType) bool

Types

type Contact

type Contact struct {
	Id          string            `bson:"id"`
	Type        string            `bson:"type"`
	Name        string            `bson:"name,omitempty"`
	Description string            `bson:"description,omitempty"`
	Icon        string            `bson:"icon,omitempty"`
	Url         string            `bson:"url,omitempty"`
	Privates    map[string]string `bson:"privates,omitempty"`
}

type ContactDto

type ContactDto struct {
	Type        string `json:"contactType" binding:"required"`
	Name        string `json:"name,omitempty"`
	Description string `json:"description,omitempty"`
	Icon        string `json:"icon,omitempty"`
	Url         string `json:"url,omitempty"`
}

func NewContractDto

func NewContractDto(c *Contact) *ContactDto

func (*ContactDto) ToEntity

func (cc *ContactDto) ToEntity() *Contact

type LinkPlatformInput

type LinkPlatformInput struct {
	Handle      string            `json:"handle"`                      // 对应平台的用户标识
	Platform    UserPlatformType  `json:"platform" binding:"required"` // 平台唯一标识,如 lens, cc(CyberConnect), deschool
	DisplayName string            `json:"displayName"`                 // 平台上的用户名
	Address     string            `json:"address"  binding:"required"` // 平台地址
	WalletType  WalletType        `json:"walletType"`                  // 当前签名的钱包类型
	SignHex     string            `json:"signHex"`
	Avatar      string            `json:"avatar"`
	Data        map[string]string `json:"data"` // 附加数据
}

func (*LinkPlatformInput) ToEntity

func (l *LinkPlatformInput) ToEntity() *UserPlatform

type Platform

type Platform struct {
	Platform UserPlatformType  `json:"platform"`
	Address  string            `json:"address"`
	Handle   string            `json:"handle"`
	Data     map[string]string `json:"data,omitempty"`
}

func NewPlatform

func NewPlatform(p *UserPlatform, isSelf bool) *Platform

type SignNonce

type SignNonce struct {
	ddd.AuditEntityBase `bson:",inline"`
	Address             string `bson:"address"`
	Nonce               string `bson:"Nonce"`
}

type SignType

type SignType string

SignType 签名的类型

const (
	// SignTypeLogin 登录签名
	SignTypeLogin SignType = "login"
	// SignTypeLink link platform 签名
	SignTypeLink SignType = "link"
)

type UnlinkPlatformInput

type UnlinkPlatformInput struct {
	Handle   string           `json:"handle"`                      // 对应平台的用户标识
	Address  string           `json:"address"  binding:"required"` // 平台地址
	Platform UserPlatformType `json:"platform" binding:"required"` // 平台唯一标识,如 lens, cc(CyberConnect), deschool
}

type User

type User struct {
	ddd.FullAuditEntityBase `bson:",inline"`
	ddd.WithExtraEntity     `bson:",inline"`
	Address                 string          `bson:"address"`
	UserName                string          `bson:"userName"`
	DisplayName             string          `bson:"displayName"`
	Avatar                  string          `bson:"avatar"`
	Bio                     string          `bson:"bio"`
	Contacts                []*Contact      `bson:"contacts"`
	Platforms               []*UserPlatform `bson:"-"`
}

func (*User) Contract

func (u *User) Contract(name string) string

func (*User) SetContract

func (u *User) SetContract(c *Contact)

type UserInfo

type UserInfo struct {
	Id          string        `json:"id"`
	Address     string        `json:"address"`
	DisplayName string        `json:"displayName"`
	Avatar      string        `json:"avatar"`
	Bio         string        `json:"bio"`
	Platforms   []*Platform   `json:"platforms"`
	Contacts    []*ContactDto `json:"contacts,omitempty"`
}

func NewUserInfo

func NewUserInfo(user *User, isSelf bool) *UserInfo

type UserManager

type UserManager struct {
	Repo UserRepository
}

func NewUserManager

func NewUserManager(d *di.Container) *UserManager

func (*UserManager) Find

func (m *UserManager) Find(ctx context.Context, addr string) *User
func (m *UserManager) Link(ctx context.Context, link *UserPlatform)

func (*UserManager) Login

func (m *UserManager) Login(ctx context.Context, address common.Address, signHex string, t WalletType, platform *UserPlatform) *User

func (*UserManager) ManyIncludePlatforms

func (m *UserManager) ManyIncludePlatforms(ctx context.Context, users []User)
func (m *UserManager) Unlink(ctx context.Context, userId primitive.ObjectID, platform UserPlatformType, address string, handle string)

func (*UserManager) Update

func (m *UserManager) Update(ctx context.Context, info *User)

type UserPlatform

type UserPlatform struct {
	ddd.AuditEntityBase `bson:",inline"`
	ddd.WithExtraEntity `bson:",inline"`
	UserId              primitive.ObjectID `bson:"userId"`   // 对应用户的唯一标识
	Platform            UserPlatformType   `bson:"platform"` // 平台唯一标识,如 lens, cc(CyberConnect), deschool
	Handle              string             `bson:"handle"`   // 对应平台的用户标识
	Address             string             `bson:"address"`  // 使用平台的地址
	DisplayName         string             `bson:"displayName"`
	Avatar              string             `bson:"avatar"`
	VerifiedAt          time.Time          `bson:"verifiedAt"`
}

type UserPlatformType

type UserPlatformType int
const (
	PlatformDeSchool     UserPlatformType = 1
	PlatformLens         UserPlatformType = 2
	PlatformCyberConnect UserPlatformType = 3
)

type UserRepository

type UserRepository interface {
	ddd.Repository[User]
	Insert(ctx context.Context, u *User) primitive.ObjectID
	Update(ctx context.Context, Id primitive.ObjectID, u *User) int
	InsertMany(ctx context.Context, us []User, ignoreErr bool) []primitive.ObjectID
	LinkPlatform(ctx context.Context, p *UserPlatform)
	UnlinkPlatform(ctx context.Context, userId primitive.ObjectID, address common.Address, handle string, platform UserPlatformType) int

	Find(ctx context.Context, address common.Address) *User
	GetManyByAddr(ctx context.Context, userIds []common.Address) []User
	GetPlatforms(ctx context.Context, userId primitive.ObjectID) []UserPlatform
	GetManyPlatforms(ctx context.Context, userIds []primitive.ObjectID) []UserPlatform

	GetUsers(ctx context.Context, q *string, platform *UserPlatformType, p *x.PageAndSort) []User
}

type UserUpdateInput

type UserUpdateInput struct {
	DisplayName *string       `json:"displayName"`
	Avatar      *string       `json:"avatar"`
	Bio         *string       `json:"bio"`
	Contacts    []*ContactDto `json:"contacts"`
}

func (*UserUpdateInput) ToEntity

func (input *UserUpdateInput) ToEntity(u *User)

type WalletType

type WalletType string
const (
	MetaMask WalletType = "MetaMask"
	UniPass  WalletType = "UniPass"
)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL