JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 6
  • Score
    100M100P100Q27329F
  • License ISC

Package Exports

  • mtrjs

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (mtrjs) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

mtrjs

Small collection of JavaScript functions for Metro. Allows for local signing of transactions, token creation/validation and encryption/decryption of arbitrary messages.

Install

npm install mtrjs

Test

npm test

Usage

node.js:
var mtrjs = require('mtrjs');

// Create an account
var acc = mtrjs.secretPhraseToAccountId('secret');
console.log(acc);
Browser:

Create the bundle with browserify:

browserify index.js -s mtrjs > build/mtrjs.js

Use in HTML file:

<script src="mtrjs.js"></script>
<script>
    var acc = mtrjs.secretPhraseToAccountId('secret');
    console.log(acc);
</script>

Functions

secretPhraseToPublicKey(secretPhrase)

Returns public key of a given passphrase

publicKeyToAccountId(publicKey, numeric)

Returns account ID of a given public key. Set the second parameter to true to get numeric account ID instead of RS format

secretPhraseToAccountId(secretPhrase, numeric)

Returns account ID of a given passphrase. Set the second parameter to true to get numeric account ID instead of RS format.

signTransactionBytes(unsignedTransactionBytes, secretPhrase)

Signs a hex string of unsigned transaction bytes (e.g. as received from NRS API) with the provided passphrase and returns it.

createToken(string, secretPhrase)

Generates a Metro cryptographic token

parseToken(token, string)

Parses a Metro cryptographic token. Returns an object with the keys isValid, timestamp, publicKey and accountRS.

encryptMessage(plainText, recipientPublicKey, senderSecretPhrase)

Returns an object with the keys nonce and message

decryptMessage(cipherText, nonce, senderPublicKey, recipientSecretPhrase)

Returns the deciphered text as string

rsConvert(address)

Converts address in numeric format to Reed-Solomon format, or vice versa. Returns an object with the keys account and accountRS