Skip to content

vesselpassport/vessel-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Vessel Go Library

The Vessel Go library makes it easy to integrate with Vessel Web3 identity tokens and attestations in Go applications.

Install

$ go get github.com/vesselxyz/vessel-go

Usage

[TODO]

Example usage

Configure a permitted server name scope for incoming sessions: NOTE: This should match your TLS certificate hostname

func main() {
	// Add my server name to the list of permitted scopes
	vessel.AddPermittedScope("my.servername.com")
  
	// Start the HTTPS server and handle requests ...
	err := http.ListenAndServeTLS(":443", "server.crt", "server.key", nil)
	if err != nil {
		log.Fatal("ListenAndServe: ", err)
	}
}

Extracting the Web3 User's ID & Attestations from an HTTPS request:

func HandleWeb3UserRequest(w http.ResponseWriter, req *http.Request) {

	// Verify the validity of the web3 session cookie
	web3session, err := vessel.GetWeb3UserContext(req)
	if err != nil {
		w.WriteHeader(http.StatusUnauthorized)
		return
	}

	fmt.Printf("[+] Got verified web3 ID session for: \"%s\"\r\n", web3session.UserID)

	// Extract verified attestations
	verified_username := web3session.Attestations["name"]
	verified_email := web3session.Attestations["email"]
	verified_sms := web3session.Attestations["sms"]

	fmt.Fprintf(w, "<h1>Greeetings %s<h1>", web3session.UserID)
	fmt.Fprintf(w, "<h2>You have the following attestations present:<h2>\r\n")
	fmt.Fprintf(w, "<h2>Has Web3 Auth Token: true\r\n</h2>")
	fmt.Fprintf(w, "<h2>Has Web3 Username: %v (%s)\r\n</h2>", (len(verified_username) != 0), verified_username)
	fmt.Fprintf(w, "<h2>Has Web3 Verified Email: %v (%s)\r\n</h2>", (len(verified_email) != 0), verified_email)
	fmt.Fprintf(w, "<h2>Has Web3 Verified SMS: %v (%s)\r\n</h2>", (len(verified_sms) != 0), verified_sms)
}

Support

Have questions while integrating Vessel into your app? Reach out to us at developers@vessel.xyz!

About

Vessel-GO - A go language resource library for Vessel web3 sites and services

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages