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

t2p-clientlib

v1.0.6

Published

Generate header token for request client token for using api service

Downloads

127

Readme

How to use library

T2P Authen Client Lib

How to Generate Toke Type H to use for Host to Host request

    //# Example 

    const t2plib = require('t2p-clientlib');
    const fs = require('fs')


    try {
        //###file client.key contains base64Ecode of Key that is provided to partner
        const clientKey = fs.readFileSync('client.key', 'utf8')

        //### Generate for using to request to get token Type C only (use by client mobile request header)
        var token = t2plib.preapare("requestbodydata",clientKey)
        console.log("<<tokenType H>>")
        console.log(token)
        console.log("\n")

        //### Generate for use with specific API URI only (use by Host to Host request header)
        var token = t2plib.preapare("requestbodydata",clientKey, '/wallet/some/api/function/')
        console.log("<<tokenType H>>")
        console.log(token)
        console.log("\n")

        //### Generate for use with any API (use by Host to Host request header)
        var token = t2plib.preapare("requestbodydata",clientKey, '')
        console.log("<<tokenType H>>")
        console.log(token)
        console.log("\n")

/*
        // OUTPUT
        {
            header: 'ZXlKamJHbGxiblJEYjJSbElqb2lRMHhKTVRBd01EQXpJaXdpYTJWNVEyOWtaU0k2SWt0RE1UQXdNREF5TUNJc0luUnBiV1Z6ZEdGdGNDSTZJakl3TWpFd056STBNVGMxTXpJNElpd2lZMnhwWlc1MFRHbGlWbVZ5YzJsdmJpSTZJakV1TUM0d0lpd2lkRzlyWlc1VWVYQmxJam9pU0NJc0luVnlhU0k2SWk5aGRYUm9aVzR2ZGpFdlkyeHBaVzUwVkc5clpXNHZaMlZ1WlhKaGRHVWlMQ0p0WlhSb2IyUWlPaUpRVDFOVUluMD06ZmE5YmJlMGQ1MmMzZDlhODVlMTM5YTEzYmRmZDM5YWJjMGM3ZThiNmY3MmVmZjdhNjQ4MzcwMjMyZmY3ZWE4NDQyOTZmOTNmMDNjZWY1ZTZiZmJlYWE0YTBmMTkwMzM3ZGUzOTMzNGUyZmRhNTNiZTFjNzUxNTZlYjJhZDcxZTk=',
            body: 'E94FXKbgTzpyRzFbT5vilXRN9VxvGYrk2m8MlY6FEn1fpSGdEUAY5tgn5EYrK34wVIa2mMN/Uyfle80lozjK1ojyMDmdTRnTFasgvA1Ibj4RPOYc6AI3CvfEQ6guwl7SZQCM4/DoF/ltCO0aZuAkeM1X04xzv7TeZCVN0zRLE/cyd/OZJb31jKVr5uhJ3WE9zkpkCmhQokAnfjReHhWbXfDSmJknSXEst2BIeM1TDCnMQBnB1hp6pwFAw6+68APn6+qki2Pet+9EYJwSIWUAIQ0ITLSyViUTtpk5UBYY/IiFVQYZpHwDwksPdfsoGvIWSAjVsJYjkwJgRY3fE8I7eQ==:KCcLTzjBIDRkt47oJhuhug=='
        }
*/
    } catch (err) {
    console.error(err)
    }

How to request for token type C for using on client (Mobile/Web)

    1. on the server generate token type H for host to host with fix uri input (/authen/v1/clientToken/generate) of the request token
    2. use token that recieve post to request token to url : https://test-api-authen.t2p.co.th/authen/v1/clientToken/generate

      (Prod : https://api-authen.t2p.co.th/authen/v1/clientToken/generate )

Decrypt the response from Host to Host request

    
    const t2plib = require('t2p-clientlib');
    const fs = require('fs')


    try {
        //file client.key contains base64Ecode of Key that is provided to partner
        const clientKey = fs.readFileSync('client.key', 'utf8')

        //Make Request to service then get the response as in API document

        decryptedText = t2plib.decryptData(encryptedText, clientKey)
    } catch (err) {
        console.error(err)
    }

Verify HashMac of input data using ClientKey

    
    const t2plib = require('t2p-clientlib');
    const fs = require('fs')


    try {
        //file client.key contains base64Ecode of Key that is provided to partner
        const clientKey = fs.readFileSync('client.key', 'utf8')

        #hashMac of input data
        var hash = '2819f93a1c5ba61028ba3fc01a50b3131e96795e6cb88c552759f4f001a66ee10583f63830774743d4d314d883fcebd2f59ffc6e78361807a0e3c0bfbf693464'
        var inputData = "somedata"

        var hashVerify = t2plib.verifyHashMac(inputData, hash, clientKey)
        console.log(hashVerify)
    } catch (err) {
        console.error(err)
    }

Generate HashMac of input data using ClientKey

    const t2plib = require('t2p-clientlib');
    const fs = require('fs')


    try {
        //file client.key contains base64Ecode of Key that is provided to partner
        const clientKey = fs.readFileSync('client.key', 'utf8')

        #hashMac of input data
        var inputData = "somedata"
        var hash = t2plib.generateHashMac(inputData, clientKey)
        console.log(hash)

    } catch (err) {
        console.error(err)
    }