> For the complete documentation index, see [llms.txt](https://wallet-docs.broearn.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://wallet-docs.broearn.com/advanced/auth/web-golang.md).

# Web Golang

{% code overflow="wrap" %}

```go

package main

import (
	"crypto/ed25519"
	"errors"
	"fmt"
	"github.com/btcsuite/btcd/btcutil/base58"
	"net/url"
	"strconv"
	"time"
)

var (
	// Copy for displaying on wallet signature page, allowing customization
	sprintfStr = "Welcome to %s!\\n\\nClick to sign in and accept the %s Terms of Service: %s\\n\\nThis request will not trigger a blockchain transaction or cost any gas fees.\\n\\nNonce:%d"
	// The project name used to display on the wallet signature page
	companyName = "Your Project Name"
	// Current website address for services provided
	serviceDomain = "https://www.youdomain.com"
	CheckTime     = false
)

// sign message str
func getSignMsg() string {
	return url.PathEscape(fmt.Sprintf(sprintfStr, companyName, companyName, serviceDomain, time.Now().Unix()))
}

// verify signature
func checkSign(signature, message, publicKey string) (string, error) {
	if signature == "" || message == "" || publicKey == "" {
		return "", errors.New("parameter error")
	}

	// verify expiration time
	if CheckTime {
		messageText := base58.Decode(message)
		if len(messageText) > 16 {
			clientTime := sprintfStr[len(messageText)-16:]
			clientTimeInt, _ := strconv.ParseInt(clientTime, 10, 64)
			if checkTime(clientTimeInt) {
				return "", errors.New("signature error")
			}
		} else {
			return "", errors.New("format error, please keep ending with the string \"Nonce%3A\" and a timestamp of length 10, like this \"Nonce%3A1689054559")
		}
	}

	verify := ed25519.Verify(base58.Decode(publicKey), base58.Decode(message), base58.Decode(signature))
	if verify {
		return publicKey, nil
	}
	return "", errors.New("signature error")
}

// CheckTime Check if the client time is within a certain range
func checkTime(clientTime int64) bool {
	sysTime := time.Now().Unix()
	time1 := sysTime + 120
	time2 := sysTime - 120
	return clientTime < time1 && clientTime > time2
}

// Example
func main() {
	fmt.Println(getSignMsg())

	publicKey, err := checkSign("21SNZbbXyhUkN9RXyfKBthzCq8fKA3asV5xcZ6RuQpDcsGRzr6aRreMfrV63jjE5Wc9yx1TzmSuf8h1nvtzSe9Rz",
		"3Qm87Hq6eP6pgoyMa5SraCsWJFB1HcwoTYWbmvhzhFVBTr7Sbm2NgX7JvZ5DEcEXXirwewpsPzDmLoV8Bz8HmQSv4ZJ1kJzbg2NKhk7HcshtczUssJSrfJosev87EcwpXb5GAjJGJunv96P63n36v9WHjaqkqSiRwRetx8GhGPZ3jVCFphEo96Ciz8oQaggqG9TnxP9P1JiyGKuewJkcWnEXyc581yjEF3iwqEVQcmL8BDoLS9kpa17oLPmiPLNXxUXhUXd8bGUrncQmfhG8yNjNQ44wpacbxMZXrtw4ACrBY6qUBRGPbU469RmmWEenF4R8R4rH9Wb22YmRWUmvBPCDVJCCauLvpjwA6Gapv9Lb5HSMtix3241pxd2JhoqhkWK",
		"7x9XDk1JZTukhN2KQSGqSL1SaoEbGwzdMR3tYLpiJeex")

	if err == nil {
		fmt.Println("Verification passed, wallet address is: " + publicKey)
	} else {
		fmt.Println(err)
	}
}

```

{% endcode %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://wallet-docs.broearn.com/advanced/auth/web-golang.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
