feat: Add Be and tbd skill, also added Roadmap file

This commit is contained in:
2026-05-10 16:32:12 -04:00
parent 3500ade13f
commit 0bb8885802
29587 changed files with 10611695 additions and 0 deletions

View File

@@ -0,0 +1,20 @@
var Jibo = require('../core');
['checkEmail', 'create', 'login', 'resendActivationCode', 'activateByCode', 'confirmEmailReset',
'sendPasswordReset', 'passwordResetByCode', 'getAccountByAccessToken', 'facebookConnect'].forEach(function(method) {
Jibo.Account.prototype[method] = function(params, callback) {
return this.makeUnauthenticatedRequest(method, params, callback);
};
});
var FIXED_KEY = 'jibokey';
Jibo.Account.prototype.encryptQr = Jibo.Account.prototype.decryptQr = function(source, key) {
key = key || FIXED_KEY;
var result = '';
for (var i = 0; i < source.length; i++) {
var encodedChar = source.charCodeAt(i) ^ key.charCodeAt(i % key.length);
result = result + String.fromCharCode(encodedChar);
}
return result;
};

View File

@@ -0,0 +1,48 @@
// var fs = require('fs');
// var Jibo = require('../core');
// var request = require('request');
// // require('request-debug')(request);
//
// Jibo.util.update(Jibo.Backup.prototype, {
// upload: function(loopId, stream, size, callback) {
// this.new(
// { loopId: loopId },
// function(err, result) {
// if (err) {
// return callback(err);
// }
// stream.pipe(
// request({
// uri: result.uploadUrl,
// method: 'PUT',
// headers: {
// Accept: '*/*',
// 'content-type': 'application/octet-stream',
// 'Content-Length': size //Content-Length is required to upload to AWS S3 pre-signed URL
// }
// },
// function (err, response, responseBody) {
// if (err) {
// return callback({
// err: err,
// headers: response.headers,
// body: responseBody
// });
// }
//
// callback(null, {
// etag: response.headers.etag,
// date: response.headers.date
// });
// })
// );
// });
// },
// uploadFile: function(loopId, fileName, callback) {
// this.upload(
// loopId,
// fs.createReadStream(fileName),
// fs.statSync(fileName).size,
// callback);
// }
// });

View File

@@ -0,0 +1,279 @@
var Jibo = require('../core');
var NodeRSA = require('node-rsa');
var crypto = require('crypto');
var constants = require('constants');
var Storage = require('./storage');
var storage = new Storage();
var CIPHER_NAME = 'aes-256-cbc';
var RSA_KEY_SIZE = 2048;
var SYMM_KEY_SIZE = 32;
Jibo.Key.prototype.storage = storage;
Jibo.Key.prototype.createRsaKeys = function(callback) {
var key = new NodeRSA({ b: RSA_KEY_SIZE });
callback(null, {
PrivateKey: key.exportKey('private'),
PublicKey: key.exportKey('public')
});
};
Jibo.Key.prototype.encryptCommonKey = function(params, callback) {
if (!params.PublicKey) {
return callback('Public key is required');
}
if (!params.Body) {
return callback('Body is required');
}
this.encryptRsa({ Body: params.Body, Key: params.PublicKey }, callback);
};
Jibo.Key.prototype.decryptCommonKey = function(params, callback) {
if (!params.PrivateKey) {
return callback('Private key is required');
}
if (!params.Body) {
return callback('Body is required');
}
this.decryptRsa({ Body: params.Body, Key: params.PrivateKey }, callback);
};
Jibo.Key.prototype.encryptRsa = function(params, callback) {
callback(null, crypto.publicEncrypt({
key: params.Key,
padding: constants.RSA_PKCS1_PADDING
}, new Buffer(params.Body, 'base64')));
};
Jibo.Key.prototype.decryptRsa = function(params, callback) {
callback(null, crypto.privateDecrypt({
key: params.Key,
padding: constants.RSA_PKCS1_PADDING
}, new Buffer(params.Body, 'base64')));
};
Jibo.Key.prototype.getIv = function(key) {
var positions = [2, 4, 6, 8, 31, 29, 27, 25, 9, 11, 13, 15, 24, 22, 20, 18];
var iv = new Buffer(positions.length);
for (var i = 0; i < positions.length; i++) {
iv[i] = key[positions[i]];
}
return iv;
};
Jibo.Key.prototype.encryptSymmetric = function(params, callback) {
if (!params.Key) {
return callback('Key is required');
}
if (!params.Body) {
return callback('Body is required');
}
var binaryKey = new Buffer(params.Key, 'base64');
var cipher = crypto.createCipheriv(CIPHER_NAME, binaryKey, this.getIv(binaryKey));
var crypted = cipher.update(params.Body, 'utf8', 'hex');
crypted += cipher.final('hex');
return callback(null, crypted);
};
Jibo.Key.prototype.encryptSymmetricStream = function(params) {
if (!params.Key) {
throw new Error('Key is required');
}
if (!params.Body) {
throw new Error('Body is required');
}
var binaryKey = new Buffer(params.Key, 'base64');
var stream = crypto.createCipheriv(CIPHER_NAME, binaryKey, this.getIv(binaryKey));
return params.Body.pipe(stream);
};
Jibo.Key.prototype.decryptSymmetric = function(params, callback) {
if (!params.Key) {
return callback('Key is required');
}
if (!params.Body) {
return callback('Body is required');
}
var binaryKey = new Buffer(params.Key, 'base64');
var decipher = crypto.createDecipheriv(CIPHER_NAME, binaryKey, this.getIv(binaryKey));
var dec = decipher.update(params.Body, 'hex', 'utf8');
dec += decipher.final('utf8');
callback(null, dec);
};
Jibo.Key.prototype.decryptSymmetricStream = function(params) {
if (!params.Key) {
throw new Error('Key is required');
}
if (!params.Body) {
throw new Error('Body is required');
}
var binaryKey = new Buffer(params.Key, 'base64');
var stream = crypto.createDecipheriv(CIPHER_NAME, binaryKey, this.getIv(binaryKey));
return params.Body.pipe(stream);
};
Jibo.Key.prototype.loadOrCreateKeyPair = function(callback) {
var keyClientContext = this;
this.storage.load('keypair', function(pairErr, pairResult) {
if (pairErr) {
return keyClientContext.createRsaKeys(function(createErr, createResult) {
if (createErr) {
return callback(createErr);
}
var jsonResult = JSON.stringify(createResult);
keyClientContext.storage.save('keypair', jsonResult, function(saveErr) {
if (saveErr) {
return callback(saveErr);
}
callback(null, createResult);
});
});
}
var parsedResult = {};
try {
parsedResult = JSON.parse(pairResult);
} catch (e) {
return callback('Cannot read previously saved key pair');
}
callback(null, parsedResult);
});
};
Jibo.Key.prototype.addPemHeader = function(key) {
var cleanKey = this.removePemHeader(key);
var keyInChunks = key.match(/.{1,64}/g);
return '-----BEGIN PUBLIC KEY-----\n' + keyInChunks.join('\n') + '\n-----END PUBLIC KEY-----';
};
Jibo.Key.prototype.removePemHeader = function(key) {
return key.replace('-----BEGIN PUBLIC KEY-----', '').replace('-----END PUBLIC KEY-----', '').replace(/\n/g, '');
};
Jibo.Key.prototype.requestSymmetricKey = function(params, callback) {
if (!params.loopId) {
return callback('loopId parameter is required');
}
var keyClientContext = this;
this.loadOrCreateKeyPair(function(pairErr, pairResult) {
if (pairErr) {
return callback(pairErr);
}
keyClientContext.createRequest({
publicKey: keyClientContext.removePemHeader(pairResult.PublicKey),
loopId: params.loopId
}, callback);
});
};
Jibo.Key.prototype.shareSymmetricKey = function(params, callback) {
if (!params.loopId) {
return callback('loopId is required parameter');
}
if (!params.id) {
return callback('id is required parameter');
}
var keyClientContext = this;
this.storage.load('symmetric-' + params.loopId, function(symmErr, symmResult) {
if (symmErr) {
return callback(symmErr);
}
keyClientContext.getRequest({
id: params.id
}, function(getErr, getResult) {
if (getErr) {
return callback(getErr);
}
// Encrypt and send symmetric key for sharing with requestor
keyClientContext.encryptCommonKey({
Body: symmResult,
PublicKey: keyClientContext.addPemHeader(getResult.publicKey)
}, function(commonErr, commonResult) {
if (commonErr) {
return callback(commonErr);
}
// Now share encrypted key with requestor
keyClientContext.share({
id: params.id,
encryptedKey: commonResult.toString('base64')
}, callback);
});
});
});
};
Jibo.Key.prototype.createSymmetricKey = function(params, callback) {
if (!params.loopId) {
return callback('loopId is required parameter');
}
var keyClientContext = this;
this.storage.load('symmetric-' + params.loopId, function(symmErr, symmResult) {
if (!symmErr && symmResult) {
return callback('Symmetric key already exists');
}
crypto.randomBytes(SYMM_KEY_SIZE, function(err, buffer) {
if (err) {
return callback(err);
}
var token = buffer.toString('base64');
keyClientContext.storage.save('symmetric-' + params.loopId, token, function(saveErr) {
if (saveErr) {
return callback(saveErr);
}
callback(null, token);
});
});
});
};
Jibo.Key.prototype.loadSymmetricKey = function(params, callback) {
if (!params.loopId) {
return callback('loopId is required parameter');
}
this.storage.load('symmetric-' + params.loopId, callback);
};
Jibo.Key.prototype.loadOrCreateSymmetricKey = function(params, callback) {
var keyClientContext = this;
this.loadSymmetricKey(params, function(loadErr, loadResult) {
if (!loadErr && loadResult) {
return callback(null, loadResult);
}
keyClientContext.createSymmetricKey(params, callback);
})
};
Jibo.Key.prototype.saveSymmetricKey = function(params, callback) {
if (!params.loopId) {
return callback('loopId is required parameter');
}
if (!params.id) {
return callback('id is required parameter');
}
var keyClientContext = this;
this.getRequest({
id: params.id
}, function(getErr, getResult) {
if (getErr) {
return callback(getErr);
}
// Retrieve own private key
keyClientContext.loadOrCreateKeyPair(function(pairErr, pairResult) {
if (pairErr) {
return callback(pairErr);
}
var encryptedKey = new Buffer(getResult.encryptedKey, 'base64');
keyClientContext.decryptCommonKey({
Body: encryptedKey,
PrivateKey: pairResult.PrivateKey
}, function(decErr, decResult) {
if (decErr) {
return callback(decErr);
}
// Save received symmetric key
// After that you can go on with encription/decryption of all binaries that are in queue
keyClientContext.storage.save('symmetric-' + params.loopId, decResult.toString('base64'), callback);
});
});
});
};

View File

@@ -0,0 +1,7 @@
var Jibo = require('../core');
['updateAgreementStatus'].forEach(function(method) {
Jibo.Loop.prototype[method] = function(params, callback) {
return this.makeUnauthenticatedRequest(method, params, callback);
};
});

View File

@@ -0,0 +1,79 @@
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var WebSocket = typeof window !== 'undefined' && window.WebSocket;
if (!WebSocket) {
try {
WebSocket = require('@jibo/ws');
} catch (e) {
// It's ok to build w/o this WS support
}
}
var Jibo = require('../core');
function NotificationEmiter(options) {
EventEmitter.call(this);
options.reconnectInterval = options.reconnectInterval || 1000 * 10
var ws;
var self = this;
var forceClosing = false;
(function connect() {
if (forceClosing) {
console.log('closing connection')
return;
}
console.log('trying to connect:', options.url);
ws = new WebSocket(options.url);
ws.on('open', function() {
self.emit('open')
});
ws.on('pong', function(data) {
self.emit('pong', data)
});
ws.on('message', function(data, flags) {
var parsedData = data;
try {
parsedData = JSON.parse(data);
self.emit('message', parsedData, flags);
} catch (e) {
self.emit('error', e);
}
if (parsedData.error) {
self.emit('error', parsedData.error);
}
});
ws.on('close', function(code, message) {
self.emit('close', code, message);
setTimeout(connect, options.reconnectInterval);
});
ws.on('error', function(error) {
self.emit('websocket error', error);
setTimeout(connect, options.reconnectInterval);
});
})();
self.close = function() {
forceClosing = true;
ws.close()
}
self.ping = function(data) {
ws.ping(data);
}
}
util.inherits(NotificationEmiter, EventEmitter);
Jibo.util.update(Jibo.Notification.prototype, {
connect: function(options, callback) {
var wsEndpoint = this.endpointFromTemplate(this.config.wsendpoint);
this.newRobotToken(options, function(err, result) {
if (err) {
return callback(err);
}
var notificationHub = new NotificationEmiter({
url: wsEndpoint +'/'+ result.token
});
callback(null, notificationHub);
});
}
});

View File

@@ -0,0 +1,7 @@
var Jibo = require('../core');
['getStatus', 'setupRobot'].forEach(function(method) {
Jibo.OOBE.prototype[method] = function(params, callback) {
return this.makeUnauthenticatedRequest(method, params, callback);
};
});

View File

@@ -0,0 +1,14 @@
var Jibo = require('../core');
var fs = require('fs');
Jibo.Storage = function() {};
Jibo.Storage.prototype.load = function(name, callback) {
fs.readFile(__dirname + '/' + name + '.json', { encoding: 'utf8'}, callback);
};
Jibo.Storage.prototype.save = function(name, body, callback) {
fs.writeFile(__dirname + '/' + name + '.json', body, callback);
};
module.exports = Jibo.Storage;