private

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Jul 17, 2023 License: MIT Imports: 12 Imported by: 0

README

Private module

Note

The passphrase is used in the private module is not sended to the chain.

Usage

(Tx) Initial administrator of the private chain
// Set initial admin of the private chain
initialAdminMsg := types.InitialAdminMsg{
    InitAdminDIDKey: "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty#key1",
    DIDPassphrase:   "passphrase",
    DIDKeyPath:      "DID/KEY/DIRECTORY",
}

txbytes, err := xplac.InitialAdmin(initialAdminMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Add administrator
// Add administrator
// Init admin can only add another admins
addAdminMsg := types.AddAdminMsg{
    NewAdminDIDKey:         "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty#key1",
    NewAdminAddress:        "xpriv1k9vu5k7nzq8rfdqu5prvrxlpsrh9y5kxxvla77",
    InitAdminDIDKey:        "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty#key1",
    InitAdminDIDPassphrase: "passphrase",
    InitAdminDIDKeyPath:    "DID/KEY/DIRECTORY",
}

txbytes, err := xplac.AddAdmin(addAdminMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Participate
// Users try to participate to the private chain
participateMsg := types.ParticipateMsg{
    ParticipantDIDKey: "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty#key1",
    DIDPassphrase:     "passphrase",
    DIDKeyPath:        "DID/KEY/DIRECTORY",
}

txbytes, err := xplac.Participate(participateMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Accept
// Admin accepts the participant to join private chain
acceptMsg := types.AcceptMsg{
    ParticipantDID:     "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty",
    AdminDIDKey:        "did:xpla:AGX4EWyvuqA1ivpwbstRu1vSgnTXAqyM3agQvbjstRcp#key1",
    AdminDIDPassphrase: "passphrase",
    AdminDIDKeyPath:    "DID/KEY/DIRECTORY",
}

txbytes, err := xplac.Accept(acceptMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Deny
// Admin denies the participant to join private chain
denyMsg := types.DenyMsg{
    ParticipantDID: "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty",
    AdminDID:       "did:xpla:AGX4EWyvuqA1ivpwbstRu1vSgnTXAqyM3agQvbjstRcp",
}
txbytes, err := xplac.Deny(denyMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Exile
// Admin exile the participant of the private chain
exileMsg := types.ExileMsg{
    ParticipantDID: "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty",
}

txbytes, err := xplac.Exile(exileMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Tx) Quit
// The participant quit of the private chain
quitMsg := types.QuitMsg{
    ParticipantDIDKey: "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty#key1",
    DIDPassphrase:     "passphrase",
    DIDKeyPath:        "DID/KEY/DIRECTORY",
}
txbytes, err := xplac.Quit(quitMsg).CreateAndSignTx()
res, err := xplac.Broadcast(txbytes)
(Query) Get admin list
// Get Admin list
res, err = xplac.Admin().Query()
(Query) Participate state
// Get participate state
participateStateMsg := types.ParticipateStateMsg{
    DID: "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty",
}

res, err = xplac.ParticipateState(participateStateMsg).Query()
(Query) Generate DID signature by using DID sequence
// Generate DID signature
// Sign includes current DID sequence which is increased when user uses DID by sending tx
// Only the owner of the DID can receive DID signature
genDIDSignMsg := types.GenDIDSignMsg{
    DIDKey:        "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty#key1",
    DIDPassphrase: passphrase,
    DIDKeyPath:    config.CommonParams.DefaultDIDKeypath,
}

res, err = xplac.GenDIDSign(genDIDSignMsg).Query()
(Query) Issue Verfiable Credential
// Get the VP
// "DIDSignBase64" is result by querying "GenDIDSign"
issueVCMsg := types.IssueVCMsg{
    DIDKey:        "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty#key1",
    DIDSignBase64: "u6+LFHzyluJ2pXyggZPTCp6c6sGVL13BvqGAwjAjUClV+3C6ivSoObUvCvnegMA4BbFkD9nUPP/2Wtsk51xMwA==",
}

res, err = xplac.IssueVC(issueVCMsg).Query()
(Query) Get Verifiable Presentation
// Get the VP includes VC
// "DIDSignBase64" is result by querying "GenDIDSign"
getVPMsg := types.GetVPMsg{
    DIDKey:        "did:xpla:EyAhwxY8KYKNqfZKFoWs9GT1jchFNwrs8MMfeyssmqty#key1",
    DIDSignBase64: "u6+LFHzyluJ2pXyggZPTCp6c6sGVL13BvqGAwjAjUClV+3C6ivSoObUvCvnegMA4BbFkD9nUPP/2Wtsk51xMwA==",
}

res, err = xplac.GetVP(getVPMsg).Query()

Documentation

Index

Constants

View Source
const (
	PrivateModule                  = "private"
	PrivateInitialAdminMsgType     = "initial-admin"
	PrivateAddAdminMsgType         = "add-admin"
	PrivateParticipateMsgType      = "participate"
	PrivateAcceptMsgType           = "accept"
	PrivateDenyMsgType             = "deny"
	PrivateExileMsgType            = "exile"
	PrivateQuitMsgType             = "quit"
	PrivateQueryAdminMsgType       = "query-admin"
	PrivateParticipateStateMsgType = "participate-state"
	PrivateGenDIDSignMsgType       = "gen-did-sig"
	PrivateIssueVCMsgType          = "issue-vc"
	PrivateGetVPMsgType            = "get-vp"
)

Variables

This section is empty.

Functions

func MakeAcceptMsg

func MakeAcceptMsg(acceptMsg types.AcceptMsg, privKey key.PrivateKey) (privtypes.MsgAccept, error)

(Tx) make msg - accept

func MakeAddAdminMsg

func MakeAddAdminMsg(addAdminMsg types.AddAdminMsg, privKey key.PrivateKey) (privtypes.MsgAddAdmin, error)

(Tx) make msg - add admin

func MakeDenyMsg

func MakeDenyMsg(denyMsg types.DenyMsg, privKey key.PrivateKey) (privtypes.MsgDeny, error)

(Tx) make msg - deny

func MakeExileMsg

func MakeExileMsg(exileMsg types.ExileMsg, privKey key.PrivateKey) (privtypes.MsgExile, error)

(Tx) make msg - exile

func MakeGenDIDSignMsg

func MakeGenDIDSignMsg(genDIDSignMsg types.GenDIDSignMsg, lcdUrl, grpcUrl string, grpcConn grpc.ClientConn, ctx context.Context) (string, error)

(Query) make msg - gen DID signature

func MakeGetVPMsg

func MakeGetVPMsg(getVPMsg types.GetVPMsg) (privtypes.QueryGetVPRequest, error)

(Query) make msg - get vp

func MakeInitialAdminMsg

func MakeInitialAdminMsg(initialAdminMsg types.InitialAdminMsg, privKey key.PrivateKey) (privtypes.MsgInitialAdmin, error)

(Tx) make msg - initial admin

func MakeIssueVCMsg

func MakeIssueVCMsg(issueVCMsg types.IssueVCMsg) (privtypes.QueryIssueVCRequest, error)

(Query) make msg - issue vc

func MakeParticipateMsg

func MakeParticipateMsg(participateMsg types.ParticipateMsg, lcdUrl, grpcUrl string, grpcConn grpc.ClientConn, privKey key.PrivateKey, ctx context.Context) (privtypes.MsgParticipate, error)

(Tx) make msg - participate

func MakeParticipateStateMsg

func MakeParticipateStateMsg(participateStateMsg types.ParticipateStateMsg) (privtypes.QueryParticipateStateRequest, error)

(Query) make msg - participate state

func MakeQueryAdminMsg

func MakeQueryAdminMsg() (privtypes.QueryAdminRequest, error)

(Query) make msg - query admin

func MakeQuitMsg

func MakeQuitMsg(quitMsg types.QuitMsg, lcdUrl, grpcUrl string, grpcConn grpc.ClientConn, privKey key.PrivateKey, ctx context.Context) (privtypes.MsgQuit, error)

(Tx) make msg - quit

Types

This section is empty.

Jump to

Keyboard shortcuts

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