0.2.30 • Published 2 days ago

@babbage/tokenator v0.2.30

Weekly downloads
-
License
Open BSV License
Repository
-
Last release
2 days ago

tokenator

Overview

Tokenator is a versatile and powerful tool that allows developers to easily create and transfer tokens peer-to-peer on the MetaNet.

The base-level class provides basic functionality such as sending, receiving, and deleting messages, while derived classes can be used to build specialized tokens for various applications. Examples of these derived classes include PaymentTokenator, EmailTokenator, PushDropTokenator, and ScribeTokenator.

With Tokenator, developers can take advantage of the power of the BSV blockchain, the simple messageBox architecture of PeerServ, privacy and mutual authentication with Authrite, and monetization with PacketPay to create cutting-edge decentralized applications.

Installation

npm i @babbage/tokenator

Example Usage

const Tokenator = require('@babage/tokenator')
const johnSmith = '022600d2ef37d123fdcac7d25d7a464ada7acd3fb65a0daf85412140ee20884311'

const init = async () => {
    // Create a new instance of the PushDropTokenator class
    // Configure the parameters according to the protocol being used
    const tokenator = new Tokenator({
        peerServHost: 'https://staging-peerserv.babbage.systems'
    })
    // Send a generic message using Babbage
    await tokenator.sendMessage({
        recipient: johnSmith,
        messageBox: 'example_inbox',
        body: 'This is an example message!'
    })

    // John can now list messages in his messageBox on PeerServ
    const messages = await tokenator.listMessages({
        messageBox: 'example_inbox'
    })

    console.log(messages[0].body) // --> 'This is an example message!'

    // Acknowledge that the messages have been received and can be deleted.
    await tokenator.acknowledgeMessage({
        messageIds: messages.map(x => x.messageId)
    })
}

init()

API

Table of Contents

PeerServMessage

Defines the structure of a PeerServ Message

Type: Object

Properties

  • messageId Number identifies a particular message
  • body String the body of the message (may be a stringified object)
  • sender String the identityKey of the sender
  • created_at String message creation timestamp as a string
  • updated_at String message update timestamp as a string

Tokenator

Extendable class for interacting with a PeerServ

Parameters

  • obj object? All parameters are given in an object (optional, default {})

    • obj.peerServHost String? The PeerServ host you want to connect to (optional, default 'https://staging-peerserv.babbage.systems')
    • obj.clientPrivateKey String? A private key to use for mutual authentication with Authrite. (Defaults to Babbage signing strategy)

initializeConnection

Establish an initial socket connection to a room The room ID is based on your identityKey and the messageBox

Parameters

listenForLiveMessages

Start listening on your "public" message room Anyone can send you a message here

Parameters
  • obj object all params given in an object

    • obj.onMessage function onMessage handler function
    • obj.messageBox string name of messageBox to listen on

sendLiveMessage

Send a message over sockets, with a backup of messageBox delivery

Parameters
  • obj object all params given in an object

    • obj.message string The message contents to send
    • obj.messageBox string The messageBox the message should be sent to depending on the protocol being used
    • obj.recipient string The identityKey of the intended recipient

sendMessage

Sends a message to a PeerServ recipient

Parameters
  • message object The object containing the message params

    • message.recipient string The identityKey of the intended recipient
    • message.messageBox string The messageBox the message should be sent to depending on the protocol being used
    • message.body (string | object) The body of the message

Returns String status message

listMessages

Lists messages from PeerServ

Parameters
  • obj Object An object containing the messageBox

    • obj.messageBox Array The name of the messageBox to list messages from

Returns Array<PeerServMessage> of matching messages returned from PeerServ

acknowledgeMessage

Acknowledges one or more messages as having been recieved ensuring deletion of the message(s)

Parameters
  • obj Object An object containing the messageIds

    • obj.messageIds Array An array of Numbers indicating which message(s) to acknowledge

Returns Array of messages formatted according to the particular protocol in use

License

The license for the code in this repository is the Open BSV License.

0.2.30

2 days ago

0.2.29

6 days ago

0.2.27

10 days ago

0.2.28

9 days ago

0.2.26

12 days ago

0.2.25

19 days ago

0.2.24

20 days ago

0.2.23

1 month ago

0.2.22

1 month ago

0.2.21

1 month ago

0.2.20

1 month ago

0.2.19

1 month ago

0.2.18

1 month ago

0.2.17

1 month ago

0.2.16

1 month ago

0.2.15

1 month ago

0.2.14

2 months ago

0.2.13

2 months ago

0.2.12

2 months ago

0.2.11

2 months ago

0.2.10

2 months ago

0.2.7

2 months ago

0.2.9

2 months ago

0.2.8

2 months ago

0.2.6

2 months ago

0.2.5

2 months ago

0.2.4

2 months ago

0.2.1

2 months ago

0.2.0

2 months ago

0.2.3

2 months ago

0.2.2

2 months ago

0.1.30

2 months ago

0.1.28

2 months ago

0.1.29

2 months ago

0.1.27

3 months ago

0.1.25

3 months ago

0.1.26

3 months ago

0.1.24

3 months ago

0.1.22

3 months ago

0.1.23

3 months ago

0.1.21

3 months ago

0.1.20

3 months ago

0.1.19

3 months ago

0.1.16

3 months ago

0.1.17

3 months ago

0.1.18

3 months ago

0.1.15

3 months ago

0.1.14

4 months ago

0.1.13

4 months ago

0.1.12

4 months ago

0.1.11

4 months ago

0.1.10

4 months ago

0.1.9

4 months ago

0.1.8

5 months ago

0.1.7

5 months ago

0.1.6

5 months ago

0.1.4

6 months ago

0.1.5

6 months ago

0.1.3

9 months ago

0.1.2

11 months ago

0.1.1

12 months ago

0.1.0

1 year ago