Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
test/*.crx
test/*.zip
test/*.xml
node_modules
node_modules
tmp
4 changes: 4 additions & 0 deletions src/crx.js
Original file line number Diff line number Diff line change
Expand Up @@ -280,12 +280,16 @@ ChromeExtension.prototype = {

/**
* Generates an appId from the publicKey.
* Public key has to be set for this to work, otherwise an error is thrown.
*
* BC BREAK `this.appId` is not stored anymore (since 1.0.0)
*
* @returns {string}
*/
generateAppId: function () {
if (typeof this.publicKey !== 'string' && !(this.publicKey instanceof Buffer)) {
throw new Error('Public key is not set');
}
return crypto
.createHash("sha256")
.update(this.publicKey)
Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,9 @@ test('it should fail if the extension content is loaded without having prelimina
t.ok(err instanceof Error);
});
});

test('it should fail if the public key was not set prior to trying to generate the app ID', function(t) {
t.plan(1);
var crx = newCrx();
t.throws(function() { crx.generateAppId(); }, /Public key is not set/);
});