Webpackify
This commit is contained in:
Родитель
76d9ac9565
Коммит
8cf73b6908
|
@ -0,0 +1,2 @@
|
|||
dist/
|
||||
node_modules/
|
|
@ -0,0 +1,30 @@
|
|||
{
|
||||
"name": "pioneer-studies-addon-utils",
|
||||
"description": "A utility library for Pioneer studies",
|
||||
"version": "1.0.0",
|
||||
"maintainers": [
|
||||
{
|
||||
"name": "Rehan Dalal",
|
||||
"email": "rdalal@mozilla.com"
|
||||
}
|
||||
],
|
||||
"repositories": [
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/mozilla/pioneer-studies-addon-utils.git"
|
||||
}
|
||||
],
|
||||
"licenses": [
|
||||
{
|
||||
"name": "MPL 2.0",
|
||||
"url": "https://github.com/mozilla/pioneer-studies-addon-utils/blob/master/LICENSE"
|
||||
}
|
||||
],
|
||||
"scripts": {
|
||||
"build": "webpack"
|
||||
},
|
||||
"devDependencies": {
|
||||
"jose-jwe-jws": "0.1.5",
|
||||
"webpack": "3.7.1"
|
||||
}
|
||||
}
|
|
@ -1,23 +1,19 @@
|
|||
"use strict";
|
||||
'use strict';
|
||||
|
||||
const { utils: Cu } = Components;
|
||||
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
|
||||
Cu.import('resource://gre/modules/XPCOMUtils.jsm');
|
||||
|
||||
const { TelemetryController } = Cu.import("resource://gre/modules/TelemetryController.jsm", null);
|
||||
const { TelemetryController } = Cu.import('resource://gre/modules/TelemetryController.jsm', null);
|
||||
|
||||
// TODO: fix import path
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "Jose", "resource://pioneer-study-nothing/Jose.jsm");
|
||||
XPCOMUtils.defineLazyModuleGetter(this, "JoseJWE", "resource://pioneer-study-nothing/Jose.jsm");
|
||||
Components.utils.importGlobalProperties(['crypto']); // Crypto is not available by default
|
||||
const { Jose, JoseJWE } = require('jose-jwe-jws/dist/jose-commonjs.js');
|
||||
|
||||
// The encryption key ID from the server
|
||||
const ENCRYPTION_KEY_ID = "pioneer-20170905";
|
||||
const ENCRYPTION_KEY_ID = 'pioneer-20170905';
|
||||
|
||||
// The public key used for encryption
|
||||
const PK = {
|
||||
"e": "AQAB",
|
||||
"kty": "RSA",
|
||||
"n": "3nI-DQ7NoUZCvT348Vi4JfGC1h6R3Qf_yXR0dKM5DmwsuQMxguce6sZ28GWQHJjgbdcs8nTuNQihyVtr9vLsoKUVSmPs_a3QEGXEhTpuTtm7cCb_7HyAlwGtysn2AsdElG8HsDFWlZmiDaHTrTmdLnuk-Z3GRg4nnA4xs4vvUuh0fCVIKoSMFyt3Tkc6IBWJ9X3XrDEbSPrghXV7Cu8LMK3Y4avy6rjEGjWXL-WqIPhiYJcBiFnCcqUCMPvdW7Fs9B36asc_2EQAM5d7BAiBwMjoosSyU6b4JGpI530c3xhqLbX00q1ePCG732cIwp0-bGWV_q0FpQX2M9cNv2Ax4Q"
|
||||
};
|
||||
const PUBLIC_KEY = require('./public_key.json');
|
||||
|
||||
|
||||
class PioneerUtils {
|
||||
constructor(config) {
|
||||
|
@ -27,7 +23,7 @@ class PioneerUtils {
|
|||
|
||||
setupEncrypter() {
|
||||
if (this.encrypter === null) {
|
||||
const rsa_key = Jose.Utils.importRsaPublicKey(PK, "RSA-OAEP");
|
||||
const rsa_key = Jose.Utils.importRsaPublicKey(PUBLIC_KEY, 'RSA-OAEP');
|
||||
const cryptographer = new Jose.WebCryptographer();
|
||||
this.encrypter = new JoseJWE.Encrypter(cryptographer, rsa_key);
|
||||
}
|
||||
|
@ -38,7 +34,7 @@ class PioneerUtils {
|
|||
return await this.encrypter.encrypt(data);
|
||||
}
|
||||
|
||||
async sendEncryptedPing(data) {
|
||||
async submitEncryptedPing(data) {
|
||||
const payload = {
|
||||
encryptedData: await this.encryptData(JSON.stringify(data)),
|
||||
encryptionKeyId: ENCRYPTION_KEY_ID,
|
||||
|
@ -47,9 +43,12 @@ class PioneerUtils {
|
|||
studyVersion: this.config.studyVersion,
|
||||
};
|
||||
|
||||
const telOptions = {addClientId: true, addEnvironment: true};
|
||||
const telOptions = {
|
||||
addClientId: true,
|
||||
addEnvironment: true
|
||||
};
|
||||
|
||||
return TelemetryController.submitExternalPing("pioneer-study", payload, telOptions);
|
||||
return TelemetryController.submitExternalPing('pioneer-study', payload, telOptions);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
{
|
||||
"e": "AQAB",
|
||||
"kty": "RSA",
|
||||
"n": "3nI-DQ7NoUZCvT348Vi4JfGC1h6R3Qf_yXR0dKM5DmwsuQMxguce6sZ28GWQHJjgbdcs8nTuNQihyVtr9vLsoKUVSmPs_a3QEGXEhTpuTtm7cCb_7HyAlwGtysn2AsdElG8HsDFWlZmiDaHTrTmdLnuk-Z3GRg4nnA4xs4vvUuh0fCVIKoSMFyt3Tkc6IBWJ9X3XrDEbSPrghXV7Cu8LMK3Y4avy6rjEGjWXL-WqIPhiYJcBiFnCcqUCMPvdW7Fs9B36asc_2EQAM5d7BAiBwMjoosSyU6b4JGpI530c3xhqLbX00q1ePCG732cIwp0-bGWV_q0FpQX2M9cNv2Ax4Q"
|
||||
}
|
|
@ -0,0 +1,13 @@
|
|||
/* eslint-env node */
|
||||
var path = require("path");
|
||||
|
||||
module.exports = {
|
||||
context: __dirname,
|
||||
entry: {
|
||||
PioneerUtils: "./src/PioneerUtils.jsm",
|
||||
},
|
||||
output: {
|
||||
path: path.resolve(__dirname, "dist/"),
|
||||
filename: "[name].jsm",
|
||||
},
|
||||
};
|
Загрузка…
Ссылка в новой задаче