doorbird
Version:
Node JS library for the Doorbird LAN API.
112 lines • 6.15 kB
JavaScript
;
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
var desc = Object.getOwnPropertyDescriptor(m, k);
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
desc = { enumerable: true, get: function() { return m[k]; } };
}
Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
if (k2 === undefined) k2 = k;
o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
o["default"] = v;
});
var __importStar = (this && this.__importStar) || function (mod) {
if (mod && mod.__esModule) return mod;
var result = {};
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
__setModuleDefault(result, mod);
return result;
};
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __generator = (this && this.__generator) || function (thisArg, body) {
var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
function verb(n) { return function (v) { return step([n, v]); }; }
function step(op) {
if (f) throw new TypeError("Generator is already executing.");
while (g && (g = 0, op[0] && (_ = 0)), _) try {
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
if (y = 0, t) op = [op[0] & 2, t.value];
switch (op[0]) {
case 0: case 1: t = op; break;
case 4: _.label++; return { value: op[1], done: false };
case 5: _.label++; y = op[1]; op = [0]; continue;
case 7: op = _.ops.pop(); _.trys.pop(); continue;
default:
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
if (t[2]) _.ops.pop();
_.trys.pop(); continue;
}
op = body.call(thisArg, _);
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
}
};
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
var libsodium_wrappers_sumo_1 = __importDefault(require("libsodium-wrappers-sumo"));
var chacha = __importStar(require("chacha-js"));
var argonKeyLength = 32;
var password = 'QzT3jeK3JY';
var strech = function (salt, opslimit, memlimit) { return __awaiter(void 0, void 0, void 0, function () {
var sodium, streched;
return __generator(this, function (_a) {
switch (_a.label) {
case 0: return [4 /*yield*/, libsodium_wrappers_sumo_1.default.ready];
case 1:
_a.sent();
sodium = libsodium_wrappers_sumo_1.default;
streched = Buffer.from(sodium.crypto_pwhash(argonKeyLength, password.substring(0, 5), salt, opslimit.readInt32BE(), memlimit.readInt32BE(), sodium.crypto_pwhash_ALG_ARGON2I13));
return [2 /*return*/, streched];
}
});
}); };
var msg = Buffer.from([
0xDE, 0xAD, 0xBE, 0x01, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x20, 0x00, 0x77, 0x35, 0x36, 0xDC,
0xC3, 0x0E, 0x2E, 0x84, 0x7E, 0x0E, 0x75, 0x29, 0xE2, 0x34, 0x60, 0xCF, 0xE3, 0xFF, 0xCC, 0x52,
0x3F, 0x37, 0xB2, 0xF2, 0xDC, 0x1A, 0x71, 0x80, 0xF2, 0x9B, 0x2E, 0xA0, 0x27, 0xA9, 0x82, 0x41,
0x9C, 0xCE, 0x45, 0x9D, 0x27, 0x45, 0x2E, 0x42, 0x14, 0xBE, 0x9C, 0x74, 0xE9, 0x33, 0x3A, 0x21,
0xDB, 0x10, 0x78, 0xB9, 0xF6, 0x7B
]);
var identifier = msg.subarray(0, 3);
var version = msg.subarray(3, 4);
var opslimit = msg.subarray(4, 8);
var memlimit = msg.subarray(8, 12);
var salt = msg.subarray(12, 28);
var nonce = msg.subarray(28, 36);
var ciphertext = msg.subarray(36, 70);
console.log("Identifier:", identifier.toString('base64'));
console.log("Version:", version[0]);
strech(salt, opslimit, memlimit).then(function (streched) {
console.log("Streched:", streched);
var decipher = chacha.AeadLegacy(streched, nonce, true);
var result = decipher.update(ciphertext);
console.log("Deciphered:", result);
var intercomId = result.subarray(0, 6);
var event = result.subarray(6, 14);
var timestamp = result.subarray(14, 18);
console.log("IntercomId:", intercomId.toString("utf-8"));
console.log("Event:", event.toString("utf-8"));
var date = new Date(0);
date.setUTCSeconds(timestamp.readInt32BE());
console.log("Timestamp:", date);
});
//# sourceMappingURL=decrypt_example_v1.js.map