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

@commercio.network/commercio-sdk.js

v1.0.0

Published

Commercio SDK Javascript

Downloads

29

Readme

Commercio-SDK.js

GitHub release GitHub license GitHub top language GitHub code size in bytes

NPM

This repository contains the code of the Javascript Commercio SDK.

Helper methods

Inside the SDK you will find the following helper methods that will help you compose messages to perform almost all operations on the blockchain of Commercio.network.

N.B.: this SDK does not include the "Sacco" library, therefore the features of the other Commercio.network SDKs that use Sacco are not available.

Docs

  • commercioDocFromWallet, creates a Commercio Doc.
  • buildShareDocumentMsgList, builds an array of ShareDocument messages.
  • commercioDocReceiptFromWallet, creates a Commercio Doc receipt.
  • buildSendDocumentReceiptMsgList, builds an array of SendDocumentReceipt messages.

Example to share a document:

let commercioDoc = commercioDocFromWallet({
  bech32Address: "<Sender Did>",
  recipients: [
    "<Recipient did>"
  ],
  metadataContentUri: "<Metadata content URI>",
  metadataSchema: {
    uri: "<Metadata schema definition URI>",
    version: "<Metadata schema version>"
  }
});
let shareDocumentMsgList = buildShareDocumentMsgList([commercioDoc]);

Example to send a receipt for a document

let commercioDocReceipt = commercioDocReceiptFromWallet({
  sender: "<Document sender address>",
  recipient: "<Document recipient address>",
  txHash: "<Tx hash in which the document has been sent>",
  documentUuid: "<Document UUID>"
});
let sendDocumentReceiptMsgList = buildSendDocumentReceiptMsgList([commercioDocReceipt]);

Id

  • didDocumentFromWallet, creates a DDO.
  • buildDidDocumentProofSignatureContent, builds the proof signature content of DDO.
  • buildDidDocumentPublicKey, builds a DDO public key.
  • buildSetDidDocumentMsgList, builds an array of SetIdentity messages.
  • didPowerUpfromWallet, creates a Did PowerUp.
  • buildRequestDidPowerUpMsgList, builds an array of RequestDidPowerUp messages.

Example to set a DDO:

let publicKeyVerification = buildDidDocumentPublicKey({
  id: "<user Did plus suffix #keys-1>",
  type: "RsaVerificationKey2018",
  controller: "<user Did>",
  publicKeyPem: "<public Pem key>"
});
let publicKeySignature = buildDidDocumentPublicKey({
  id: "<user Did plus suffix #keys-2>",
  type: "RsaSignatureKey2018",
  controller: "<user Did>",
  publicKeyPem: "<public Pem key>"
});
let didDocumentProofSignatureContent = buildDidDocumentProofSignatureContent({
  context: "https://www.w3.org/ns/did/v1",
  did: "<user did>",
  publicKeys: [publicKeyVerification, publicKeySignature]
});

// Create the 'signatureValue' following these instructions: https://docs.commercio.network/x/id/#associating-a-did-document-to-your-identity

let didDocument = didDocumentFromWallet({
  context: didDocumentProofSignatureContent['@context'],
  did: didDocumentProofSignatureContent['id'],
  publicKeys: didDocumentProofSignatureContent['publicKey'],
  bech32PublicKey: "<did bech32 pubkey>",
  signatureValue: "<the 'signatureValue' previously generated>",
  purpose: "<the proof purpose>"
});
let setDidDocumentMsgList = buildSetDidDocumentMsgList([didDocument]);

Example to request a PowerUp:

let didPowerUp = didPowerUpfromWallet({
  senderDid: "<user who sends the power-up request>",
  pairwiseDid: "<pairwise address to power-up>",
  amount: "<Amount to be sent>",
  privateKey: "<private RSA key of sender>",
  governmentRsaPubKey: "<public key of external centralized entity Tk>"
});
let requestDidPowerUpMsgList = buildRequestDidPowerUpMsgList([didPowerUp]);

Membership

  • inviteUserFromWallet, creates an Invite User.
  • buildInviteUserMsgList, builds an array of InviteUser messages.
  • buyMembershipFromWallet, creates a Buy Membership.
  • buildBuyMembershipMsgList, builds an array of BuyMembership messages.

Example to invire a user:

let inviteUser = inviteUserFromWallet({
  recipient: "<address of the user to be invited>",
  sender: "<your address>"
});
let inviteUserMsgList = buildInviteUserMsgList([inviteUser]);

Example to buy a membership:

import { memberhipTypes } from "@commercio.network/commercio-sdk.js";

let buyMembership = buyMembershipFromWallet({
  bech32Address: "<your address>",
  membershipType: memberhipTypes.BLACK
});
let buyMembershipMsgList = buildBuyMembershipMsgList([buyMembership]);

Mint

  • openCdpFromWallet, creates an OpenCdp.
  • buildOpenCdpMsgList, builds an array of 1 open CDP message.
  • buildCloseCdpMsgList, creates a CloseCdp.
  • closeCdpFromWallet, builds an array of close CDP messages.

Example to open a CDP:

let openCdp = openCdpFromWallet({
  bech32Address: "<user address>",
  amount: "<amount to be deposited>"
});
let openCdpMsgList = buildOpenCdpMsgList(openCdp);

Example to close a CDP:

let closeCdp = closeCdpFromWallet({
  bech32Address: "<user address>",
  timeStamp: "<block height at which the CDP is being inserted into the chain>"
});
let closeCdpMsgList = buildCloseCdpMsgList([closeCdp]);

Utilities

  • hashGenerator, to get message hash:
    • getHash256
  • keysHandler, to manage RSA keys:
    • privateKeyFromPem
    • publicKeyFromPem
    • privateKeyToPem
    • publicKeyToPem
    • publicKeyFromPrivate

References

Commercio-sdk.js uses node-forge to perform encryption operations.

How to build and publish the library

# update the version number
npm run build
npm login
npm publish

Reference guide

How to publish a npm package