Coder Social home page Coder Social logo

mixin-node's Introduction

mixin-node

The nodejs SDK for mixin.one

  1. Following mixin developers documentation https://developers.mixin.one/guides create your mixin app.
  2. Click the button "Click to generate a new session". Now you will have the bot session secrets.

The 6 digit number is your asset PIN The UUID is the new session ID The third line is the encrypted PIN_TOKEN The RSA PRIVATE KEY is your session KEY, please save the private Key as a file.

  1. decrypt the PIN_TOKEN using tools/decryptkey.go
go run tools/decryptkey.go -key mixin.key -label ********-eb33-4112-b30a-2ae287dfbe32 -message **********OIGnELd1XnAF...W4lFKnA/WEKkIwkzEM=

key is the filename of the private key label is the session ID message is the PIN_TOKEN

Then you have the decrypted string which is the aeskey.

  1. Please see the transfer example in examples/test.js. Or here for reference:
npm install mixin-node --save
const mixinjs = require('mixin-node');  
let opts = { 
    client_id         : "**********095-4960-8dd1-edf6e583a2a9",
    aeskey            : "*****DEN7P3k172oBLW3g/TUZa6Xa5MrgOOzKfXdv5A=",
    pin               : "854423",
    session_id    : "a335e1e3-eb33-4112-b30a-2ae287dfbe32",
    privatekey    : "mixin_dev.key" //filepath(String) or PrivateKey(Buffer)
}

let mixin = new mixinjs(opts);

let asset_id = "965e5c6e-434c-3fa9-b780-c50f43cd955c"; //CNB
let recipient_id = "*************-4152-9c5a-839d286f7e4f"; //User Account ID
let amount = "100";
let memo ="test transfer"

mixin.transferFromBot(asset_id, recipient_id, amount, memo)
.then( (result) =>{
  console.log(result);
}).catch( (err) => {
  console.log(err);
});

  1. 按照mixin开发者手册指引,建立app. https://developers.mixin.one/guides
  2. 在Dashboard 点击 Click to generate a new session,记录下全部生成的信息。

第一行的 6 位数字是 api接入 的提现/转账PIN 码,此处也是机器人的提现/转账密码 第二行的 UUID 是 session ID, 第三行是PIN_TOKEN,

最后一部分 RSA PRIVATE KEY 是跟 API 进行交互时用来签名 JWT 的私钥,请把这部分保存成一个单独的文件,比如叫做 mixin.key

  1. 解密获得aeskey,在本repo的tools下提供了一个decryptkey.go这个工具用于解密
go run tools/decryptkey.go -key mixin.key -label a335e1e3-eb33-4112-b30a-2ae287dfbe32 -message **********OIGnELd1XnAF...W4lFKnA/WEKkIwkzEM=

key 是前面保存的PRIVATE KEY的文件名,比如mixin.key label 是第2步中的session ID message 是第2步中的第三行,PIN_TOKEN

运行之后会获得解密的aeskey

  1. 通过机器人转账的例子代码
npm install mixin-node --save
const mixinjs = require('mixin-node');  
let opts = { 
    client_id         : "**********095-4960-8dd1-edf6e583a2a9",
    aeskey            : "*****DEN7P3k172oBLW3g/TUZa6Xa5MrgOOzKfXdv5A=",
    pin               : "854423",
    session_id    : "a335e1e3-eb33-4112-b30a-2ae287dfbe32",
    privatekey    : "mixin_dev.key" //可以用带有路径的文件名string,或者直接传入Buffer
}

let mixin = new mixinjs(opts);

let asset_id = "965e5c6e-434c-3fa9-b780-c50f43cd955c"; //CNB
let recipient_id = "*************-4152-9c5a-839d286f7e4f"; //User Account ID
let amount = "100";
let memo ="test transfer"

mixin.transferFromBot(asset_id, recipient_id, amount, memo)
.then( (result) =>{
  console.log(result);
}).catch( (err) => {
  console.log(err);
});

mixin-node's People

Contributors

huo-ju avatar

Watchers

James Cloos avatar  avatar

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.