golang_token

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Dec 6, 2023 License: MIT Imports: 14 Imported by: 0

README

Golang Token

A simple library to validate and generate token in GO

Installation

Use go get to retrieve the SDK to add it to your project's Go module dependencies.

go get gitlab.com/token-library/golang-token

To update the SDK use go get -u to retrieve the latest version of the SDK.

go get -u gitlab.com/token-library/golang-token

Example

Seamless 1.1 Token

The following example would help you to validate or generate the X-API-TOKEN. The token generation rule refers to the Seamless Wallet 1.1 Doc

Validate X-API-TOKEN
package main

import (
	liveCasino "gitlab.com/token-library/golang-token"
)

func main() {
	key := "<your agent ID>"
	secret := "<your agent key>"
	seamlessWalletToken, err := liveCasino.NewSeamlessWalletToken(key, secret)
	if err != nil {
		panic(err)
	}

	payload := "{\"requestId\":\"test-123\",\"user\":\"member\"}"
	token := "the-X-API-TOKEN-form-header"
	seamlessWalletToken.Validate(payload, token)
}
Generate X-API-TOKEN
package main

import (
	"fmt"
	
	liveCasino "gitlab.com/token-library/golang-token"
)

func main() {
	key := "<your agent ID>"
	secret := "<your agent key>"
	seamlessWalletToken, err := liveCasino.NewSeamlessWalletToken(key, secret)
	if err != nil {
		panic(err)
	}

	payload := "{\"requestId\":\"test-123\",\"status\":\"ok\",\"user\":\"member\",\"currency\":\"USD\",\"balance\":100}"
	token, err := seamlessWalletToken.GenerateToken(payload)
	if err != nil {
		panic(err)
	}
	fmt.Println(token)
}
API Key(For keno-api)

The following example would help you to generate the Key in request parameters. The token generation rule refers to the Encryption Flow

Generate key
package main

import (
	"fmt"
	
	liveCasino "gitlab.com/token-library/golang-token"
)

func main() {
	key := "<your agent ID>"
	secret := "<your agent key>"
	apiToken, err := liveCasino.NewApiToken(key, secret)
	if err != nil {
		panic(err)
	}

    // need to sort by key
	type request struct {
		AgentId    string
		Account    string
		LimitStake string
	}
	params := request{
		Account:    "member",
		AgentId:    key,
		LimitStake: "1,2,3",
	}
	payload, _ := json.Marshal(params)

	fmt.Println(liveCasino.GenerateKey(string(payload)))
}
HMAC Signature(For v2 api)

The following example would help you to generate the Signature in the request header.

Query String(GET)
package main

import (
	"fmt"
	
	liveCasino "gitlab.com/token-library/golang-token"
)

func main() {
	key := "<your agent ID>"
	secret := "<your agent key>"
	apiV2Signature, err := liveCasino.NewApiV2Signature(key, secret)
	if err != nil {
		panic(err)
	}
    
    // TODO
}
Request Body(POST, PATCH)
package main

import (
	"fmt"
	
	liveCasino "gitlab.com/token-library/golang-token"
)

func main() {
	key := "<your agent ID>"
	secret := "<your agent key>"
	apiV2Signature, err := liveCasino.NewApiV2Signature(key, secret)
	if err != nil {
		panic(err)
	}
    
    // TODO
}

Tests

Please install the golangci-lint if you want to lint the code

golangci-lint run -v
go test -v

License

Please see MIT License File for more information.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ApiToken

type ApiToken struct {
	// contains filtered or unexported fields
}

func NewApiToken

func NewApiToken(key, secret string) (*ApiToken, error)

func (*ApiToken) GenerateKey

func (token *ApiToken) GenerateKey(payload string) (string, error)

func (*ApiToken) Validate

func (token *ApiToken) Validate(payload, md5Hash string) bool

type ApiV2Signature

type ApiV2Signature struct {
	// contains filtered or unexported fields
}

func NewApiV2Signature

func NewApiV2Signature(key, secret string) (*ApiV2Signature, error)

func (*ApiV2Signature) GenerateSignature

func (s *ApiV2Signature) GenerateSignature(payload string, timestamp int64) (string, error)

func (*ApiV2Signature) Validate

func (s *ApiV2Signature) Validate(payload string, timestamp int64, signature string) (bool, error)

type SeamlessWalletToken

type SeamlessWalletToken struct {
	// contains filtered or unexported fields
}

func NewSeamlessWalletToken

func NewSeamlessWalletToken(key, secret string) (*SeamlessWalletToken, error)

func (*SeamlessWalletToken) GenerateToken

func (token *SeamlessWalletToken) GenerateToken(payload string) (string, error)

func (*SeamlessWalletToken) Normalize

func (token *SeamlessWalletToken) Normalize(payload map[string]interface{}) string

func (*SeamlessWalletToken) Validate

func (token *SeamlessWalletToken) Validate(payload, sha1Hash string) bool

Jump to

Keyboard shortcuts

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