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

@affidaty/t2-lib-core

v2.6.2

Published

Official Trinci 2 SDK JavaScript library core

Downloads

19

Readme

T2Lib

Official Trinci 2 SDK JavaScript library core

Description

This library allows to interact with Trinci nodes and eases the creation, use, management and transcoding of accounts, keys, transactions, connections and everything else needed to successfully operate on a TRINCI blockchain network.

It works server side (cjs and module support) as well as in browsers. This allows you to manage your accounts ang send transactions directly from a browser avoiding third services altogether. Note that cryptographic part of this library relies on Webcrypto and needs for a browser to support in in order to be fully functional.

NPM scripts

npm run test             # execute tests

npm run docs             # generate documentation in /docs

npm run lint             # lint code

npm run lint:fix         # lint and fix(where possible)

npm run build-cjs        # build CommonJS sources in /dist/cjs

npm run build-esm        # build ES Modules sources in /dist/esm with type
                         # declarations types in /dist/types

npm run build-browser    # build browser version in /dist/browser to
                         # include with <script> tag

npm run build            # build all versions mentioned above

Examples

import t2libcore from '@affidaty/t2-lib-core';
// CommonJS also works:
// const t2libcore = require('@affidaty/t2-lib');

// account generation
const acc = new t2libcore.Account();
await acc.generate();

//keys export/import and interactions
const pubKey = acc.keyPair.publicKey;
const pubKeyRaw = await acc.keyPair.publicKey.getRaw();
const pubKeySPKI = await pubKey.getSPKI();
const keyPair1 = acc.keyPair;
await keyPair1.publicKey.setRaw(pubKeyRaw);

const keyPair2 = new t2libcore.ECDSAKeyPair();
await keyPair2.publicKey.setSPKI(pubKeySPKI);
keyPair2.privateKey = acc.keyPair.privateKey;
const acc2 = new t2libcore.Account();
await acc2.setKeyPair(keyPair2);
console.log(acc2.accountId);

// mint transaction example
const basicAssetSc = new Uint8Array(Buffer.from('122018086245b6ac31b4b71a3c3c7aa57964052741873d8b93e876f883694feaed48', 'hex'));
const defaultNetworkName = 'skynet';
const nonce = new Uint8Array(8);
await t2lib.WebCrypto.getRandomValues(nonce);

const tx = new t2libcore.Transaction();
tx.setAccountId(acc1.accountId);
tx.setNonce(nonce);
tx.setNetworkName(defaultNetworkName);
tx.setSmartContractHash(basicAssetSc);
tx.setSmartContractMethod('mint');
tx.setSmartContractMethodArgs({
    to: acc2.accountId,
    units: 1,
});
await tx.sign(acc1.keyPair);
const txBytes = Buffer.from(await tx.toBytes()).toString('hex');
console.log(txBytes);

Browser support

This library also works in browser. It's minified version can be found at <pkg_install_dir>/dist/browser/t2lib.min.js just include it with

<script src="../dist/browser/t2libcore.min.js"></script>

and start to use it as you would with NodeJS.

Documentation

Wiki JSDoc