Coder Social home page Coder Social logo

fox-one / mixin-sdk-go Goto Github PK

View Code? Open in Web Editor NEW
45.0 8.0 13.0 707 KB

Golang sdk for Mixin Network & Mixin Messenger

Home Page: https://developers.mixin.one/

License: MIT License

Go 100.00%
mixin golang mixin-network mixin-messenger mixin-sdk mixin-sdk-go

mixin-sdk-go's Introduction

mixin-sdk-go

Golang sdk for Mixin Network & Mixin Messenger

Install

go get -u github.com/fox-one/mixin-sdk-go/v2

Features

  • Comprehensive most of the Mixin Network & Mixin Messenger api supported
  • Security verify Response X-Request-ID & signature automatically
  • Flexible initialize Client from keystore, ed25519_oauth_token or access_token

Examples

See _examples/ for a variety of examples.

Quick Start

package main

import (
	"context"
	"log"

	"github.com/fox-one/mixin-sdk-go/v2"
)

func main() {
	ctx := context.Background()
	s := &mixin.Keystore{
		ClientID:   "",
		SessionID:  "",
		PrivateKey: "",
		PinToken: "",
	}

	client, err := mixin.NewFromKeystore(s)
	if err != nil {
		log.Panicln(err)
	}

	user, err := client.UserMe(ctx)
	if err != nil {
		log.Printf("UserMe: %v", err)
		return
	}

	log.Println("user id", user.UserID)
}

Error handling?

check error code by mixin.IsErrorCodes

if _, err := client.UserMe(ctx); err != nil {
    switch {
    case mixin.IsErrorCodes(err,mixin.Unauthorized,mixin.EndpointNotFound):
    	// handle unauthorized error
    case mixin.IsErrorCodes(err,mixin.InsufficientBalance):
        // handle insufficient balance error
    default:
    }
}

mixin-sdk-go's People

Contributors

crazygit avatar cw35 avatar dependabot[bot] avatar firefly1126 avatar halimao avatar kuri-su avatar liusining avatar lyricat avatar pando-ci avatar testwill avatar tougee avatar tymon42 avatar xuhuiandfish avatar xwjdsh avatar xxm849 avatar yiplee avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

mixin-sdk-go's Issues

modifypin错误

windows上会错误
改成这样就好了:

	if pin != "" {
		body["old_pin"] = c.EncryptPin(pin)
	}
	time.Sleep(time.Nanosecond)//加上这句
	body["pin"] = c.EncryptPin(newPin)

search user API request

Hi,
I did not find this search user API in sdk, and found that there is already a deprecated API named SearchUser inside user.go, so if this SearchUser can be modified to follow the docs, I can PR for this.

client.ReadSnapshots api questions

My robot already has the READSNAPSHOTS permission, but I still can't find the user_id when I query the client.READSnapsshots interface

snapshots, _ := client.ReadSnapshots(ctx, "", time.Now(), "", 10)
	for _, snapshot := range snapshots {
		fmt.Println("snapshot.TraceID" + snapshot.TraceID)
		fmt.Println("snapshot.Receiver" + snapshot.Receiver)
		fmt.Println("snapshot.OpponentID" + snapshot.OpponentID)
		fmt.Println("snapshot.Sender" + snapshot.Sender)
	}

the result is

snapshot.TraceID7c3fb80a-1740-491a-96c9-771c2321a2cd
snapshot.Receiver
snapshot.OpponentID6a87e67f-02fb-47cf-b31f-32a13dd5b3d9
snapshot.Sender

Is there any way to find out sender???
Very thanks.

Replace jwt-go with golang-jwt

jwt-go is no longer maintained and has serious bugs. Please replace it with golang-jwt https://github.com/golang-jwt/jwt


CVE-2020-26160
high severity
Vulnerable versions: <= 3.2.0
Patched version: No fix

jwt-go allows attackers to bypass intended access restrictions in situations with []string{} for m["aud"] (which is allowed by the specification). Because the type assertion fails, "" is the value of aud. This is a security problem if the JWT token is presented to a service that lacks its own audience check. There is no patch available and users of jwt-go are advised to migrate to golang-jwt at version 3.2.1

关于使用ReadSnapshots接口的问题

为什么我使用该函数获取我自己的交易记录,记录里有opponent_id但是没有返回user_id
{
"snapshot_id": "b2feb56b-91a9-4325-be19-4e6a23223045",
"created_at": "2020-07-16T13:25:16.601114Z",
"trace_id": "6fa359dc-@@@@-@@@@-@@@@-1a46b2e19717",
"asset_id": "815b0b1a-2764-3736-8faa-42d694fa620a",
"opponent_id": "@@@4a693-@@@@-@@@@-@@@@-c7dfef844126",
"amount": "0.0001",
"opening_balance": ".@@@@",
"closing_balance": "
.@@@@-",
"memo": "pong",
"type": "transfer"
}

The request data has invalid field when I send buttons.

Problem description

I want to send a button and then I came across this. I've double-checked the code and still don't know what the problem is, so I'm asking for help.

code is here:

        data := `[{
			"label":"🔥 4swap",
			"action":"https://4swap.one",
			"color": "#FF0000",
		}]`

	msg := &mixin.MessageRequest{
		ConversationID: uuid.NewV5(uuid.FromStringOrNil(client.ClientID), "atank").String(),
		RecipientID:    "fedd7458-bdfc-488c-87be-6225ee3cf523",
		MessageID:      uuid.Must(uuid.NewV4()).String(),
		Category:       mixin.MessageCategoryAppButtonGroup,
		Data:           data,
	}
	err = client.SendMessage(ctx, msg)
	if err != nil {
		log.Fatalln(err)
	}

Error response:

image

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.