Skip to content

Instantly share code, notes, and snippets.

@joebandenburg
Last active August 29, 2015 14:13
Show Gist options
  • Save joebandenburg/da3cf490309374120aa4 to your computer and use it in GitHub Desktop.
Save joebandenburg/da3cf490309374120aa4 to your computer and use it in GitHub Desktop.
Bunch of API prototypes
function receiveMessage(from, message, type) {
var session = axolotl.getSession(from);
// session could be in some sort of uninitalised state here - yuck!
if (type === "PreKeyWhisperMessage") {
return session.decryptPreKeyMessage(message);
} else if (type === "WhisperMessage") {
return session.decryptMessage(message);
}
}
function sendMessage(to, message) {
var session = axolotl.getSession(to);
if (!session.isReady()) {
var bundle = ...
session.initialise(bundle);
}
return session.encryptMessage(message);
}
function receiveMessage(from, message, type) {
var session = axolotl.getSession(from); // may return null.
if (type === "PreKeyWhisperMessage") {
if (!session) {
session = axolotl.createSessionFromPreKeyWhisperMessage(from, message);
}
return session.decryptPreKeyMessage(message);
} else if (type === "WhisperMessage") {
if (!session) {
throw new Error("No session");
}
return session.decryptMessage(message);
}
}
function sendMessage(to, message) {
var session = axolotl.getSession(to);
if (!session) {
var bundle = ...
session = axolotl.createSessionFromPreKeyBundle(to, bundle);
}
session.encryptMessage(message);
}
function receiveMessage(from, message, type) {
if (type === "PreKeyWhisperMessage") {
return axolotl.decryptPreKeyMessage(from, message);
} else if (type === "WhisperMessage") {
return axolotl.decryptMessage(from, message);
}
}
function sendMessage(to, message) {
if (!axolotl.hasSession(to)) {
var bundle = ...
axolotl.createSessionFromPreKeyBundle(to, bundle);
}
return axolotl.encryptMessage(to, from);
}
// or
function sendMessage(to, message) {
return axolotl.encryptMessage(to, from); // calls store.getPreKeyBundle(to)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment