Class: Session

session~ Session


new Session(connection, privKey, sessionSecret, options)

A Session object represents the state of a communications exchange between two people. Sessions are what create and read Chat messages, decrypt communications, and negotiate encryption between parties.

Parameters:
Name Type Description
connection Driver

blockchain connection

privKey String

Private key of the user's testnet addres

sessionSecret Buffer

the 128 byte session private key, used for negotiating a shared secret.

options Object
Properties
Name Type Description
endBlock Integer

The highest block to search for messages

receiverAddr String

The receiving party's address. This is required when starting a new session. (and never otherwise)

withChat Chat

The Chat initiation message that will be used as the basis for the session. This is required if receiverAddr is not specified.

Members


between :Integer

The public testnet addresses of the two parties engaged in this session. senderAddr is listied before receiverAddr.

Type:
  • Integer

connection :Driver

Returns the connection that this Session is querying against

Type:
  • Driver

endBlock :Integer

Don't search higher than the specified block height.

Type:
  • Integer
Default Value:
  • null

privKey :String

The user's Bitcoin private key. Probably/certainly a testnet private key

Type:
  • String

receiverAddr :String

The public address of the user who is the recipient of this communication.

Type:
  • String

senderAddr :Integer

The public address of the user who's private key was passed in the constructor's privKey argument.

Type:
  • Integer

sessionKey :Buffer

A 128 byte private key for encrypting this Session's communications. Expected to be provided as a Buffer object.

Type:
  • Buffer

withChat :Integer

If the withChat option was passed in the constructor, this returns the chat initiation message that this sender is authenticating against.

Type:
  • Integer
Default Value:
  • null

Methods


<static> all(connection, addr, cb)

List all outstanding chat initiation requests over supplied address

Parameters:
Name Type Description
connection Driver

blockchain connection

addr String

Public (testnet) Address to query for requests

cb function

Callback to receive the initation chat messages in the form: function(err, chats).


authenticate(next, derEncoding)

Authenticate this session against an initiator's request. If the session is authenticated already an error will be returned.

Parameters:
Name Type Description
next function

Callback to receive the broadcasted chat authorization message in the form: function(err, chat)

derEncoding Buffer

Optional. Der's are randomly generated and not intended to be supplied other than for the purposed of determininstically testing this codebase.


getCommunicationAuth(cb)

Retrieve all chat initialization acknowledgements (aka authorizations) between this sender and receiver

Parameters:
Name Type Description
cb function

Callback to receive array of chat messages in the form: function(err, messages)


getCommunicationInit(cb)

Retrieve all chat initialization requests between this sender and receiver

Parameters:
Name Type Description
cb function

Callback to receive array of chat messages in the form: function(err, messages)


getCommunications(cb)

List all the decrypted chats that have been sent over this channel between the sender and receiver.

Parameters:
Name Type Description
cb function

Callback to receive the chat messages in the form: function(err, chats). Note that these chats will have been seeded with the symmKey for the purpose of retrieving their contentsPlain()


getNegotiation(cb)

Retrieve the negotiation messages for this session (init and auth)

Parameters:
Name Type Description
cb function

Callback to receive negotiation messages in the form: function(err, commInit, commAuth)


getSymmKey(cb)

Get the negotiated Diffie Helmann symmetric key being used in this session. Note that this isn't the supplied private key, this is the negotiated secret between the communicating parties, and will be a 128 byte Buffer

Parameters:
Name Type Description
cb function

Callback to receive the computed status in the form: function(err, symmKey)


isAuthenticated(cb)

Retrieve authentication/negotiation status of the current session

Parameters:
Name Type Description
cb function

Callback to receive the computed status in the form: function(err, isAuthenticated)


send(contents, cb, iv)

Send a plain-text message to the receiver in this Session channel.

Parameters:
Name Type Description
contents String

Plain-text string of the message you wish to send

cb function

Callback to receive the broadcasted chat message message in the form: function(err, chat)

iv Buffer

Optional 16 byte number. Iv passing is supported only for the purpose of making tests completely deterministic. Otherwise, a random number is used for this purpose.