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
32 changes: 30 additions & 2 deletions cjs/client.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23525,6 +23525,15 @@ Crypto.prototype.sign = function (curve, mpinId, publicKey, token, userPin, mess
};
};

Crypto.prototype.randomString = function (len) {
const byteArr = new Array(len);
for (let i = 0; i < len; ++i) {
byteArr[i] = this.rng.getByte();
}

return this._bytesToHex(byteArr);
};

/**
* Returns the public key bytes appended to the M-PIN ID bytes in hex encoding
* @private
Expand Down Expand Up @@ -23896,7 +23905,7 @@ function Client(options) {
}

// Set the client name using the current lib version and provided application info
options.clientName = "MIRACL Client.js/8.8.0" + (options.applicationInfo ? " " + options.applicationInfo : "");
options.clientName = "MIRACL Client.js/8.9.0" + (options.applicationInfo ? " " + options.applicationInfo : "");

this.options = options;

Expand Down Expand Up @@ -24067,7 +24076,8 @@ Client.prototype.getActivationToken = function (verificationURI, callback) {
type: "POST",
data: {
userId: params["user_id"],
code: params["code"]
code: params["code"],
deviceTag: this._getDeviceTag()
}
};

Expand Down Expand Up @@ -24150,6 +24160,7 @@ Client.prototype._createMPinID = function (userId, activationToken, keypair, cal
data: {
userId: userId,
deviceName: this._getDeviceName(),
deviceTag: this._getDeviceTag(),
activationToken: activationToken,
publicKey: keypair.publicKey
}
Expand All @@ -24174,6 +24185,23 @@ Client.prototype._getDeviceName = function () {
return "Browser";
};

Client.prototype._getDeviceTag = function () {
const tag = this.options.userStorage.getItem("miraclDeviceTag");
if (tag) {
return tag;
}

let newTag;
try {
newTag = this.crypto.randomString(16);
this.options.userStorage.setItem("miraclDeviceTag", newTag);
} catch (err) {
newTag = "";
}

return newTag;
};

Client.prototype._getSecret = function (secretUrl, callback) {
const requestData = {
url: secretUrl
Expand Down
32 changes: 30 additions & 2 deletions cjs/promise.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -23525,6 +23525,15 @@ Crypto.prototype.sign = function (curve, mpinId, publicKey, token, userPin, mess
};
};

Crypto.prototype.randomString = function (len) {
const byteArr = new Array(len);
for (let i = 0; i < len; ++i) {
byteArr[i] = this.rng.getByte();
}

return this._bytesToHex(byteArr);
};

/**
* Returns the public key bytes appended to the M-PIN ID bytes in hex encoding
* @private
Expand Down Expand Up @@ -23896,7 +23905,7 @@ function Client(options) {
}

// Set the client name using the current lib version and provided application info
options.clientName = "MIRACL Client.js/8.8.0" + (options.applicationInfo ? " " + options.applicationInfo : "");
options.clientName = "MIRACL Client.js/8.9.0" + (options.applicationInfo ? " " + options.applicationInfo : "");

this.options = options;

Expand Down Expand Up @@ -24067,7 +24076,8 @@ Client.prototype.getActivationToken = function (verificationURI, callback) {
type: "POST",
data: {
userId: params["user_id"],
code: params["code"]
code: params["code"],
deviceTag: this._getDeviceTag()
}
};

Expand Down Expand Up @@ -24150,6 +24160,7 @@ Client.prototype._createMPinID = function (userId, activationToken, keypair, cal
data: {
userId: userId,
deviceName: this._getDeviceName(),
deviceTag: this._getDeviceTag(),
activationToken: activationToken,
publicKey: keypair.publicKey
}
Expand All @@ -24174,6 +24185,23 @@ Client.prototype._getDeviceName = function () {
return "Browser";
};

Client.prototype._getDeviceTag = function () {
const tag = this.options.userStorage.getItem("miraclDeviceTag");
if (tag) {
return tag;
}

let newTag;
try {
newTag = this.crypto.randomString(16);
this.options.userStorage.setItem("miraclDeviceTag", newTag);
} catch (err) {
newTag = "";
}

return newTag;
};

Client.prototype._getSecret = function (secretUrl, callback) {
const requestData = {
url: secretUrl
Expand Down
32 changes: 30 additions & 2 deletions dist/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -23526,6 +23526,15 @@ Crypto.prototype.sign = function (curve, mpinId, publicKey, token, userPin, mess
};
};

Crypto.prototype.randomString = function (len) {
const byteArr = new Array(len);
for (let i = 0; i < len; ++i) {
byteArr[i] = this.rng.getByte();
}

return this._bytesToHex(byteArr);
};

/**
* Returns the public key bytes appended to the M-PIN ID bytes in hex encoding
* @private
Expand Down Expand Up @@ -23897,7 +23906,7 @@ function Client(options) {
}

// Set the client name using the current lib version and provided application info
options.clientName = "MIRACL Client.js/8.8.0" + (options.applicationInfo ? " " + options.applicationInfo : "");
options.clientName = "MIRACL Client.js/8.9.0" + (options.applicationInfo ? " " + options.applicationInfo : "");

this.options = options;

Expand Down Expand Up @@ -24068,7 +24077,8 @@ Client.prototype.getActivationToken = function (verificationURI, callback) {
type: "POST",
data: {
userId: params["user_id"],
code: params["code"]
code: params["code"],
deviceTag: this._getDeviceTag()
}
};

Expand Down Expand Up @@ -24151,6 +24161,7 @@ Client.prototype._createMPinID = function (userId, activationToken, keypair, cal
data: {
userId: userId,
deviceName: this._getDeviceName(),
deviceTag: this._getDeviceTag(),
activationToken: activationToken,
publicKey: keypair.publicKey
}
Expand All @@ -24175,6 +24186,23 @@ Client.prototype._getDeviceName = function () {
return "Browser";
};

Client.prototype._getDeviceTag = function () {
const tag = this.options.userStorage.getItem("miraclDeviceTag");
if (tag) {
return tag;
}

let newTag;
try {
newTag = this.crypto.randomString(16);
this.options.userStorage.setItem("miraclDeviceTag", newTag);
} catch (err) {
newTag = "";
}

return newTag;
};

Client.prototype._getSecret = function (secretUrl, callback) {
const requestData = {
url: secretUrl
Expand Down
2 changes: 1 addition & 1 deletion dist/client.min.js

Large diffs are not rendered by default.

32 changes: 30 additions & 2 deletions dist/client.promise.js
Original file line number Diff line number Diff line change
Expand Up @@ -23526,6 +23526,15 @@ Crypto.prototype.sign = function (curve, mpinId, publicKey, token, userPin, mess
};
};

Crypto.prototype.randomString = function (len) {
const byteArr = new Array(len);
for (let i = 0; i < len; ++i) {
byteArr[i] = this.rng.getByte();
}

return this._bytesToHex(byteArr);
};

/**
* Returns the public key bytes appended to the M-PIN ID bytes in hex encoding
* @private
Expand Down Expand Up @@ -23897,7 +23906,7 @@ function Client(options) {
}

// Set the client name using the current lib version and provided application info
options.clientName = "MIRACL Client.js/8.8.0" + (options.applicationInfo ? " " + options.applicationInfo : "");
options.clientName = "MIRACL Client.js/8.9.0" + (options.applicationInfo ? " " + options.applicationInfo : "");

this.options = options;

Expand Down Expand Up @@ -24068,7 +24077,8 @@ Client.prototype.getActivationToken = function (verificationURI, callback) {
type: "POST",
data: {
userId: params["user_id"],
code: params["code"]
code: params["code"],
deviceTag: this._getDeviceTag()
}
};

Expand Down Expand Up @@ -24151,6 +24161,7 @@ Client.prototype._createMPinID = function (userId, activationToken, keypair, cal
data: {
userId: userId,
deviceName: this._getDeviceName(),
deviceTag: this._getDeviceTag(),
activationToken: activationToken,
publicKey: keypair.publicKey
}
Expand All @@ -24175,6 +24186,23 @@ Client.prototype._getDeviceName = function () {
return "Browser";
};

Client.prototype._getDeviceTag = function () {
const tag = this.options.userStorage.getItem("miraclDeviceTag");
if (tag) {
return tag;
}

let newTag;
try {
newTag = this.crypto.randomString(16);
this.options.userStorage.setItem("miraclDeviceTag", newTag);
} catch (err) {
newTag = "";
}

return newTag;
};

Client.prototype._getSecret = function (secretUrl, callback) {
const requestData = {
url: secretUrl
Expand Down
2 changes: 1 addition & 1 deletion dist/client.promise.min.js

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@miracl/client-js",
"version": "8.8.0",
"version": "8.9.0",
"description": "MIRACL Trust client library",
"main": "./src/client.js",
"exports": {
Expand Down
23 changes: 21 additions & 2 deletions src/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ export default function Client(options) {
}

// Set the client name using the current lib version and provided application info
options.clientName = "MIRACL Client.js/8.8.0" + (options.applicationInfo ? " " + options.applicationInfo : "");
options.clientName = "MIRACL Client.js/8.9.0" + (options.applicationInfo ? " " + options.applicationInfo : "");

this.options = options;

Expand Down Expand Up @@ -225,7 +225,8 @@ Client.prototype.getActivationToken = function (verificationURI, callback) {
type: "POST",
data: {
userId: params["user_id"],
code: params["code"]
code: params["code"],
deviceTag: this._getDeviceTag()
}
};

Expand Down Expand Up @@ -308,6 +309,7 @@ Client.prototype._createMPinID = function (userId, activationToken, keypair, cal
data: {
userId: userId,
deviceName: this._getDeviceName(),
deviceTag: this._getDeviceTag(),
activationToken: activationToken,
publicKey: keypair.publicKey
}
Expand All @@ -332,6 +334,23 @@ Client.prototype._getDeviceName = function () {
return "Browser";
};

Client.prototype._getDeviceTag = function () {
const tag = this.options.userStorage.getItem("miraclDeviceTag");
if (tag) {
return tag;
}

let newTag;
try {
newTag = this.crypto.randomString(16);
this.options.userStorage.setItem("miraclDeviceTag", newTag);
} catch (err) {
newTag = "";
}
Comment thread
tatiNo5 marked this conversation as resolved.

return newTag;
};

Client.prototype._getSecret = function (secretUrl, callback) {
const requestData = {
url: secretUrl
Expand Down
9 changes: 9 additions & 0 deletions src/crypto.js
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,15 @@ Crypto.prototype.sign = function (curve, mpinId, publicKey, token, userPin, mess
};
};

Crypto.prototype.randomString = function (len) {
const byteArr = new Array(len);
for (let i = 0; i < len; ++i) {
byteArr[i] = this.rng.getByte();
}

return this._bytesToHex(byteArr);
};

/**
* Returns the public key bytes appended to the M-PIN ID bytes in hex encoding
* @private
Expand Down
34 changes: 33 additions & 1 deletion test/test-client.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { afterEach, before, describe, it } from "mocha";
import { afterEach, before, beforeEach, describe, it } from "mocha";
import Client from "../src/client.js";
import { expect } from "chai";
import { readFileSync } from "fs";
Expand Down Expand Up @@ -234,3 +234,35 @@ describe("Client sendPushNotificationForAuth", () => {
client.http.request.restore && client.http.request.restore();
});
});

describe("Client _getDeviceTag", () => {
let client, storage;

beforeEach(() => {
const config = testConfig();
storage = config.userStorage;
client = new Client(config);
});

it("should generate a new device tag", () => {
expect(storage.getItem("miraclDeviceTag")).to.be.null;

const tag = client._getDeviceTag();

expect(storage.getItem("miraclDeviceTag")).to.equal(tag);
});

it("should get the existing device tag", () => {
storage.setItem("miraclDeviceTag", "tagvalue");

expect(client._getDeviceTag()).to.equal("tagvalue");
});

it("should return an empty string on crypto failure", () => {
sinon.stub(client.crypto, "randomString").throws(new Error("Cryptography error"));

expect(client._getDeviceTag()).to.equal("");

client.crypto.randomString.restore && client.crypto.randomString.restore();
});
});
Loading
Loading