guardee-js
Installation
npm install guardee
Basic Usage
The constructor of the guardee client takes an object with parameters such as signalserver_host
, signalserver_key
and connect_option
. Syntax:
const Guardee = require('guardee');
const guardee = new Guardee({
signalserver_host: 'http://signalserver.guardee.io',
signalserver_key: '906c7939ed0007b48b9c779302d788299183cb4a',
connect_option: {
initiator: true,
},
});
signalserver_host
and signalserver_key
You need to acquire signalserver_host
and signalserver_key
which contemporary Guardee wallet provides. These arguments are used to communicate with the signal server for peer-to-peer connection between your dApp and Guardee wallet.
connect_option
connetion_option
is used by guardee.connector
to provide options for its peer-to-peer connection. In case of NodeJS, you need to provide wrtc as a parameter.
const Guardee = require('guardee');
const wrtc = require('wrtc');
const guardee = new Guardee({
signalserver_host: 'http://signalserver.guardee.io',
signalserver_key: '906c7939ed0007b48b9c779302d788299183cb4a',
connect_option: {
initiator: true,
wrtc: wrtc
},
});
API
guardee.connector
RegisterGenesisOffer
Register genesis connection offer to signal server.
connectionOffer
: Object { connectionId
, offer
} (optional) connection offer objectwaitSeconds
: Number How long should the code wait measured in seconds (default = 60)
Request
Send request to connected peer
type
: String request type (account_connection
, sign_tx
, send_tx
)body
: Object request bodyencode
: Boolean (optional) whether to stringify request bodyencrypt
: Boolean (optional) whether to encode and encrypt request body with passwordpassword
: String (optional) password to encrypt request body
Response
Send response to connected peer
type
: String response type (account_connection
, sign_tx
, send_tx
)body
: Object response bodyencode
: Boolean (optional) whether to stringify response bodyencrypt
: Boolean (optional) whether to encode and encrypt response body with passwordpassword
: String (optional) password to encrypt response body
SendDataSequence
Send data sequence to the connected peer
type
: String data sequence type ('sign_tx', 'send_tx')dataSequence
: Array array of sequential transactions
SendDataChunkSequence
Send already chunked data sequence to the connected peer
type
: String data sequence type ('sign_tx', 'send_tx')dataChunkSequence
: Array chunked array of sequential transactions
Destroy
Destroy all guardee.connector.connections
notice
: Boolean whether to notice connection peer of destruction
On
Listen on given event and run callback
event
: Stringcb
: Function
guardee.encoder
Stringify
Encode given object into safe uri component
Parse
Decode given string into original object
Events
There are 14 different events that guardee.connector
emits when connection issues occur.
genesis_connection
: Emitted when the genesis connection is initiatedgenesis_offer
: Emitted when the genesis connection offer is generatedgenesis_offer_register
: Emitted when the genesis connection offer is registered to the signal servergenesis_answer_received
: Emitted when the answer for the genesis connection offer is receivedgenesis_answer_set
: Emitted when the answer for the genesis connection is set to the instanceerror
: Emitted when error occursready
: Emitted when stable amount of connections are alivedestroy
: Emitted when all peer connection is destroyedrequest
: Emitted when request is receivedresponse
: Emitted when response is receivedchunk
: Emitted when chunk is receivedchunk_start
: Emitted when the first chunk is sentchunk_data
: Emitted when chunk data is sentchunk_end
: Emitted when the last chunk is sent