npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

mixin-node-client

v0.11.0

Published

Node.js SDK for Mixin Network

Downloads

16

Readme

mixin-node-client

build status code coverage code style styled with prettier made with lass license

Node.js SDK for Mixin Network, heavily inspired by mixin-node, but is much more developer friendly

Table of Contents

Install

yarn add mixin-node-client
# OR npm install mixin-node-client -S

Usage

1. Generate Config

Steps to use generate config for dapp:

  1. Create a dapp on developers.mixin.one, get clientId and clientSecret(the result when Click to generate a new secret)
  2. Generate config from a new session info of your dapp (the result when Click to generate a new session) using mixin-cli (a command line tool by me).

Config file format, remember to replace clientId and clientSecret with yours:

// Generated with awesome https://github.com/wangshijun/mixin-cli
module.exports = {
  clientId: '<PUT YOUR DAPP CLIENT_ID HERE>',
  clientSecret: '<PUT YOUR DAPP CLIENT_SECRET HERE>',
  assetPin: '310012',
  sessionId: '621c905b-1739-45e7-b668-b5531dd83646',
  aesKey: '56GcGs2EFHBPV2Xsb/OiwLdgjGt3q53JcFeLmbUutEk=',
  privateKey: `-----BEGIN RSA PRIVATE KEY-----
MIICXAIBAAKBgQCsNaGbDx1UeKrTux01nC6R7/bu2GUELe6Q2mBSPymkZW2fpiaO
FjkTI1MkEE8Eq1kGm/+6vAP84LMXG/W49UqZTBkKkrQ=
-----END RSA PRIVATE KEY-----`,
};

2. HttpClient

HttpClient provides wrapper for all API supported by mixin network and mixin messenger, such as pin/user/asset/snapshot:

const { HttpClient } = require('mixin-node-client');
const config = require('./config');

const client = new HttpClient(config);

const recipientId = 'ca630936-5af6-427e-ac4a-864a4c64f372'; // UserId
const senderId = '7701e7bf-2a86-4655-982e-023564fa8945'; // UserID
const assetId = '965e5c6e-434c-3fa9-b780-c50f43cd955c'; // CNB

(async () => {
  const assets = await client.getAssets();
  const verifyPin = await client.verifyPin(config.assetPin);
  const user = await client.getUser(senderId);
  console.log({ assets, verifyPin, user });
})();

Full API list supported by HttpClient:

  • getUserAssets, get asset list owned by user
  • getUserAsset, get asset detail owned by user
  • getNetworkAssets, get top asset list by mixin network
  • getNetworkAsset, get top asset detail by mixin network
  • getWithdrawAddress, get withdraw address
  • createWithdrawAddress, create withdraw address
  • deleteWithdrawAddress, delete withdraw address
  • withdraw, request withdraw from mixin network
  • deposit, get deposit address for asset
  • getSnapshots, get network snapshot list
  • getSnapshot, get network snapshot detail
  • verifyPin, verify asset pin
  • updatePin, update/create asset pin
  • createTransfer, create transfer with an asset
  • getTransfer, read transfer detail
  • verifyPayment, verify transfer state
  • getProfile, get user profile
  • updatePreference, update user preference
  • updateProfile, update user profile
  • createUser, create user
  • getUser, get user by id
  • getUsers, get multiple users by id
  • getFriends, get friend list
  • getContacts, get contact list
  • createConversation, create new conversation
  • readConversation, read conversation detail
  • sendMessage, send raw message to specific conversation, see next section for message sender util.

Working example for HttpClient can be found HERE

Message Sender Util

Because we can send messages to a conversation, HttpClient provide neat methods to send all kinds of message to Mixin Messenger:

console.log(client.getMessageSenders());
// [ 'sendText',
//   'sendImage',
//   'sendVideo',
//   'sendData',
//   'sendSticker',
//   'sendContact',
//   'sendButton',
//   'sendButtons',
//   'sendApp' ]
const text = await client.sendText({
  conversationId: conversation.conversation_id,
  data: 'Hello from node.js new client sdk',
});
const button = await client.sendButton({
  conversationId: conversation.conversation_id,
  data: { label: 'Open Mixin', color: '#FF0000', action: 'https://mixin.one' },
});

For syntax of sending messages, see working example HERE.

3. SocketClient

SocketClient provide basic wrapper for Mixin Messenger WebSocket Messages, you can use it to listen and react to socket messages.

const { SocketClient } = require('mixin-node-client');
const config = require('./config');

const client = new SocketClient(config);

socket.on(
  'message',
  socket.getMessageHandler(message => {
    console.log('Message Received', message);
    if (message.data && message.data.category === 'PLAIN_TEXT' && message.data.data.toLowerCase() === 'hi') {
      // We support `sendText`, `sendButton`, `sendImage` here
      return socket.sendText('Hi there!', message);
    }

    return Promise.resolve(message);
  })
);

Working example for SocketClient can be found HERE

Same set of message sender utils are also supported by SocketClient (Note: parameters are different for message sender utils of HttpClient and SocketClient, because we have the conversationId from the onMessage callback):

socket.sendText('Hi there!', message);
socket.sendButton({ label: 'Open Mixin', color: '#FF0000', action: 'https://mixin.one' }, message);

Debugging

If you are curious what happened during each API call, try run example code with following command:

DEBUG=mixin-node-client:* node examples/http.js
DEBUG=mixin-node-client:* node examples/socket.js
DEBUG=mixin-node-client:* node examples/message.js

The mixin dapp included in the examples folder can be found with the following qrcode:

Contributors

| Name | | -------------- | | wangshijun |

License

MIT © wangshijun