Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/MixinNetwork/bot-api-go-client
🤖️ Mixin API for Go
https://github.com/MixinNetwork/bot-api-go-client
mixin mixin-bot
Last synced: about 1 month ago
JSON representation
🤖️ Mixin API for Go
- Host: GitHub
- URL: https://github.com/MixinNetwork/bot-api-go-client
- Owner: MixinNetwork
- License: apache-2.0
- Created: 2018-04-27T07:08:39.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2024-04-29T10:31:10.000Z (4 months ago)
- Last Synced: 2024-04-30T05:32:10.412Z (4 months ago)
- Topics: mixin, mixin-bot
- Language: Go
- Homepage:
- Size: 551 KB
- Stars: 69
- Watchers: 17
- Forks: 24
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mixin - Golang SDK
README
## Installation
```
go get github.com/MixinNetwork/bot-api-go-client
```## Quick Start
```golang
package mainimport (
"context"
"crypto/rand"
"crypto/rsa"
"crypto/x509"
"encoding/base64"
"encoding/pem"
"fmt"
"time""github.com/MixinNetwork/bot-api-go-client"
)const (
appId = ""
appSessionId = ""
appPrivateKey = ``
)func main() {
ctx := context.Background()
// Generate Ed25519 key pair.
pub, privateKey, err := ed25519.GenerateKey(rand.Reader)
if err != nil {
return nil, "", err
}
sessionSecret := base64.RawURLEncoding.EncodeToString(pub[:])
// Rigster the user on the Mixin network
user, err := bot.CreateUser(ctx, sessionSecret, "fullname", appId, appSessionId, appPrivateKey)
if err != nil {
fmt.Println(err)
return
}
userSessionKey := base64.RawURLEncoding.EncodeToString(privateKey)
// encrypt PIN
encryptedPIN, err := bot.EncryptEd25519PIN(pin, user.PINTokenBase64, userSessionKey, uint64(time.Now().UnixNano()))
if err != nil {
return err
}
fmt.Println(encryptedPIN)
// Set initial code.
err = bot.UpdatePin(ctx, "", encryptedPIN, user.UserId, user.SessionId, userSessionKey)
if err != nil {
fmt.Println(err)
return
}
//Sign authentication token.
authenticationToken, err := bot.SignAuthenticationToken(user.UserId, user.SessionId, userSessionKey, "GET", "/assets", "")
if err != nil {
fmt.Println(err)
return
}
// Read asset list
assets, err := bot.AssetList(ctx, authenticationToken)
if err != nil {
fmt.Println(err)
return
}
for _, a := range assets {
fmt.Println(a.AssetId)
}
}```
Fo more examples, see [examples](https://github.com/MixinNetwork/bot-api-go-client/blob/master/examples/wallet.go)。