Skip to content

Commit c91b24a

Browse files
committed
Implement new registration API
1 parent 4e6c8f7 commit c91b24a

12 files changed

+262
-387
lines changed

cjs/client.cjs

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23952,7 +23952,7 @@ function Client(options) {
2395223952
}
2395323953

2395423954
// Set the client name using the current lib version and provided application info
23955-
options.clientName = "MIRACL Client.js/8.6.0" + (options.applicationInfo ? " " + options.applicationInfo : "");
23955+
options.clientName = "MIRACL Client.js/8.7.0" + (options.applicationInfo ? " " + options.applicationInfo : "");
2395623956

2395723957
self.options = options;
2395823958

@@ -24175,7 +24175,7 @@ Client.prototype.register = function (userId, activationToken, pinCallback, call
2417524175

2417624176
keypair = self.crypto.generateKeypair("BN254CX");
2417724177

24178-
self._createMPinID(userId, activationToken, function (err, identityData) {
24178+
self._createMPinID(userId, activationToken, keypair, function (err, identityData) {
2417924179
if (err) {
2418024180
if (identityData && identityData.error === "INVALID_ACTIVATION_TOKEN") {
2418124181
return callback(new Error("Invalid activation token", { cause: err }), null);
@@ -24188,12 +24188,12 @@ Client.prototype.register = function (userId, activationToken, pinCallback, call
2418824188
return callback(new Error("Project mismatch"), null);
2418924189
}
2419024190

24191-
self._getSecret1(identityData, keypair, function (err, sec1Data) {
24191+
self._getSecret(identityData.secretUrls[0], function (err, sec1Data) {
2419224192
if (err) {
2419324193
return callback(new Error("Registration fail", { cause: err }), null);
2419424194
}
2419524195

24196-
self._getSecret2(sec1Data, function (err, sec2Data) {
24196+
self._getSecret(identityData.secretUrls[1], function (err, sec2Data) {
2419724197
if (err) {
2419824198
return callback(new Error("Registration fail", { cause: err }), null);
2419924199
}
@@ -24218,17 +24218,17 @@ Client.prototype.register = function (userId, activationToken, pinCallback, call
2421824218
});
2421924219
};
2422024220

24221-
Client.prototype._createMPinID = function (userId, activationToken, callback) {
24221+
Client.prototype._createMPinID = function (userId, activationToken, keypair, callback) {
2422224222
var self = this,
2422324223
regData = {};
2422424224

24225-
regData.url = self.options.server + "/rps/v2/user";
24226-
regData.type = "PUT";
24225+
regData.url = self.options.server + "/registration";
24226+
regData.type = "POST";
2422724227
regData.data = {
2422824228
userId: userId,
24229-
mobile: 0,
2423024229
deviceName: self._getDeviceName(),
24231-
activateCode: activationToken
24230+
activationToken: activationToken,
24231+
publicKey: keypair.publicKey
2423224232
};
2423324233

2423424234
self.http.request(regData, function (err, result) {
@@ -24252,48 +24252,43 @@ Client.prototype._getDeviceName = function () {
2425224252
return "Browser";
2425324253
};
2425424254

24255-
Client.prototype._getSecret1 = function (identityData, keypair, callback) {
24255+
Client.prototype._getSecret = function (secretUrl, callback) {
2425624256
var self = this,
24257-
cs1Url;
24257+
requestData = { url: secretUrl };
2425824258

24259-
cs1Url = self.options.server + "/rps/v2/signature/";
24260-
cs1Url += identityData.mpinId;
24261-
cs1Url += "?regOTT=" + identityData.regOTT;
24262-
cs1Url += "&publicKey=" + keypair.publicKey;
24263-
24264-
self.http.request({ url: cs1Url }, function (err, sec1Data) {
24259+
self.http.request(requestData, function (err, result) {
2426524260
if (err) {
24266-
return callback(err, null);
24261+
if (err.message === "The request was aborted") {
24262+
self.http.request(requestData, callback);
24263+
} else {
24264+
callback(err, result);
24265+
}
24266+
24267+
return;
2426724268
}
2426824269

24269-
callback(null, sec1Data);
24270+
callback(null, result);
2427024271
});
2427124272
};
2427224273

24273-
Client.prototype._getSecret2 = function (sec1Data, callback) {
24274-
var self = this;
24275-
24276-
self.http.request({ url: sec1Data.cs2url }, callback);
24277-
};
24278-
2427924274
Client.prototype._createIdentity = function (userId, userPin, identityData, sec1Data, sec2Data, keypair, callback) {
2428024275
var self = this,
2428124276
userData,
2428224277
csHex,
2428324278
token;
2428424279

2428524280
try {
24286-
csHex = self.crypto.addShares(keypair.privateKey, sec1Data.dvsClientSecretShare, sec2Data.dvsClientSecret, sec1Data.curve);
24287-
token = self.crypto.extractPin(identityData.mpinId, keypair.publicKey, userPin, csHex, sec1Data.curve);
24281+
csHex = self.crypto.addShares(keypair.privateKey, sec1Data.dvsClientSecret, sec2Data.dvsClientSecret, identityData.curve);
24282+
token = self.crypto.extractPin(identityData.mpinId, keypair.publicKey, userPin, csHex, identityData.curve);
2428824283
} catch (err) {
2428924284
return callback(err, null);
2429024285
}
2429124286

2429224287
userData = {
2429324288
mpinId: identityData.mpinId,
2429424289
token: token,
24295-
curve: sec1Data.curve,
24296-
dtas: sec1Data.dtas,
24290+
curve: identityData.curve,
24291+
dtas: identityData.dtas,
2429724292
publicKey: keypair.publicKey,
2429824293
pinLength: identityData.pinLength,
2429924294
projectId: identityData.projectId,
@@ -24559,42 +24554,31 @@ Client.prototype._finishAuthentication = function (userId, userPin, scope, authO
2455924554

2456024555
Client.prototype._renewSecret = function (userId, userPin, activationData, callback) {
2456124556
var self = this,
24562-
identityData,
2456324557
keypair;
2456424558

24565-
identityData = self.users.get(userId);
2456624559
keypair = self.crypto.generateKeypair(activationData.curve);
2456724560

24568-
self._getWaMSecret1(keypair, activationData.token, function (err, sec1Data) {
24561+
self._createMPinID(userId, activationData.token, keypair, function (err, identityData) {
2456924562
if (err) {
2457024563
return callback(err, null);
2457124564
}
2457224565

24573-
self._getSecret2(sec1Data, function (err, sec2Data) {
24566+
self._getSecret(identityData.secretUrls[0], function (err, sec1Data) {
2457424567
if (err) {
2457524568
return callback(err, null);
2457624569
}
2457724570

24578-
self._createIdentity(userId, userPin, identityData, sec1Data, sec2Data, keypair, callback);
24571+
self._getSecret(identityData.secretUrls[1], function (err, sec2Data) {
24572+
if (err) {
24573+
return callback(err, null);
24574+
}
24575+
24576+
self._createIdentity(userId, userPin, identityData, sec1Data, sec2Data, keypair, callback);
24577+
});
2457924578
});
2458024579
});
2458124580
};
2458224581

24583-
Client.prototype._getWaMSecret1 = function (keypair, registerToken, callback) {
24584-
var self = this,
24585-
cs1Url,
24586-
reqData;
24587-
24588-
reqData = {
24589-
publicKey: keypair.publicKey,
24590-
dvsRegisterToken: registerToken
24591-
};
24592-
24593-
cs1Url = self.options.server + "/rps/v2/dvsregister";
24594-
24595-
self.http.request({ url: cs1Url, type: "POST", data: reqData }, callback);
24596-
};
24597-
2459824582
/**
2459924583
* Create a cryptographic signature of a given message
2460024584
*

cjs/promise.cjs

Lines changed: 33 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -23952,7 +23952,7 @@ function Client(options) {
2395223952
}
2395323953

2395423954
// Set the client name using the current lib version and provided application info
23955-
options.clientName = "MIRACL Client.js/8.6.0" + (options.applicationInfo ? " " + options.applicationInfo : "");
23955+
options.clientName = "MIRACL Client.js/8.7.0" + (options.applicationInfo ? " " + options.applicationInfo : "");
2395623956

2395723957
self.options = options;
2395823958

@@ -24175,7 +24175,7 @@ Client.prototype.register = function (userId, activationToken, pinCallback, call
2417524175

2417624176
keypair = self.crypto.generateKeypair("BN254CX");
2417724177

24178-
self._createMPinID(userId, activationToken, function (err, identityData) {
24178+
self._createMPinID(userId, activationToken, keypair, function (err, identityData) {
2417924179
if (err) {
2418024180
if (identityData && identityData.error === "INVALID_ACTIVATION_TOKEN") {
2418124181
return callback(new Error("Invalid activation token", { cause: err }), null);
@@ -24188,12 +24188,12 @@ Client.prototype.register = function (userId, activationToken, pinCallback, call
2418824188
return callback(new Error("Project mismatch"), null);
2418924189
}
2419024190

24191-
self._getSecret1(identityData, keypair, function (err, sec1Data) {
24191+
self._getSecret(identityData.secretUrls[0], function (err, sec1Data) {
2419224192
if (err) {
2419324193
return callback(new Error("Registration fail", { cause: err }), null);
2419424194
}
2419524195

24196-
self._getSecret2(sec1Data, function (err, sec2Data) {
24196+
self._getSecret(identityData.secretUrls[1], function (err, sec2Data) {
2419724197
if (err) {
2419824198
return callback(new Error("Registration fail", { cause: err }), null);
2419924199
}
@@ -24218,17 +24218,17 @@ Client.prototype.register = function (userId, activationToken, pinCallback, call
2421824218
});
2421924219
};
2422024220

24221-
Client.prototype._createMPinID = function (userId, activationToken, callback) {
24221+
Client.prototype._createMPinID = function (userId, activationToken, keypair, callback) {
2422224222
var self = this,
2422324223
regData = {};
2422424224

24225-
regData.url = self.options.server + "/rps/v2/user";
24226-
regData.type = "PUT";
24225+
regData.url = self.options.server + "/registration";
24226+
regData.type = "POST";
2422724227
regData.data = {
2422824228
userId: userId,
24229-
mobile: 0,
2423024229
deviceName: self._getDeviceName(),
24231-
activateCode: activationToken
24230+
activationToken: activationToken,
24231+
publicKey: keypair.publicKey
2423224232
};
2423324233

2423424234
self.http.request(regData, function (err, result) {
@@ -24252,48 +24252,43 @@ Client.prototype._getDeviceName = function () {
2425224252
return "Browser";
2425324253
};
2425424254

24255-
Client.prototype._getSecret1 = function (identityData, keypair, callback) {
24255+
Client.prototype._getSecret = function (secretUrl, callback) {
2425624256
var self = this,
24257-
cs1Url;
24257+
requestData = { url: secretUrl };
2425824258

24259-
cs1Url = self.options.server + "/rps/v2/signature/";
24260-
cs1Url += identityData.mpinId;
24261-
cs1Url += "?regOTT=" + identityData.regOTT;
24262-
cs1Url += "&publicKey=" + keypair.publicKey;
24263-
24264-
self.http.request({ url: cs1Url }, function (err, sec1Data) {
24259+
self.http.request(requestData, function (err, result) {
2426524260
if (err) {
24266-
return callback(err, null);
24261+
if (err.message === "The request was aborted") {
24262+
self.http.request(requestData, callback);
24263+
} else {
24264+
callback(err, result);
24265+
}
24266+
24267+
return;
2426724268
}
2426824269

24269-
callback(null, sec1Data);
24270+
callback(null, result);
2427024271
});
2427124272
};
2427224273

24273-
Client.prototype._getSecret2 = function (sec1Data, callback) {
24274-
var self = this;
24275-
24276-
self.http.request({ url: sec1Data.cs2url }, callback);
24277-
};
24278-
2427924274
Client.prototype._createIdentity = function (userId, userPin, identityData, sec1Data, sec2Data, keypair, callback) {
2428024275
var self = this,
2428124276
userData,
2428224277
csHex,
2428324278
token;
2428424279

2428524280
try {
24286-
csHex = self.crypto.addShares(keypair.privateKey, sec1Data.dvsClientSecretShare, sec2Data.dvsClientSecret, sec1Data.curve);
24287-
token = self.crypto.extractPin(identityData.mpinId, keypair.publicKey, userPin, csHex, sec1Data.curve);
24281+
csHex = self.crypto.addShares(keypair.privateKey, sec1Data.dvsClientSecret, sec2Data.dvsClientSecret, identityData.curve);
24282+
token = self.crypto.extractPin(identityData.mpinId, keypair.publicKey, userPin, csHex, identityData.curve);
2428824283
} catch (err) {
2428924284
return callback(err, null);
2429024285
}
2429124286

2429224287
userData = {
2429324288
mpinId: identityData.mpinId,
2429424289
token: token,
24295-
curve: sec1Data.curve,
24296-
dtas: sec1Data.dtas,
24290+
curve: identityData.curve,
24291+
dtas: identityData.dtas,
2429724292
publicKey: keypair.publicKey,
2429824293
pinLength: identityData.pinLength,
2429924294
projectId: identityData.projectId,
@@ -24559,42 +24554,31 @@ Client.prototype._finishAuthentication = function (userId, userPin, scope, authO
2455924554

2456024555
Client.prototype._renewSecret = function (userId, userPin, activationData, callback) {
2456124556
var self = this,
24562-
identityData,
2456324557
keypair;
2456424558

24565-
identityData = self.users.get(userId);
2456624559
keypair = self.crypto.generateKeypair(activationData.curve);
2456724560

24568-
self._getWaMSecret1(keypair, activationData.token, function (err, sec1Data) {
24561+
self._createMPinID(userId, activationData.token, keypair, function (err, identityData) {
2456924562
if (err) {
2457024563
return callback(err, null);
2457124564
}
2457224565

24573-
self._getSecret2(sec1Data, function (err, sec2Data) {
24566+
self._getSecret(identityData.secretUrls[0], function (err, sec1Data) {
2457424567
if (err) {
2457524568
return callback(err, null);
2457624569
}
2457724570

24578-
self._createIdentity(userId, userPin, identityData, sec1Data, sec2Data, keypair, callback);
24571+
self._getSecret(identityData.secretUrls[1], function (err, sec2Data) {
24572+
if (err) {
24573+
return callback(err, null);
24574+
}
24575+
24576+
self._createIdentity(userId, userPin, identityData, sec1Data, sec2Data, keypair, callback);
24577+
});
2457924578
});
2458024579
});
2458124580
};
2458224581

24583-
Client.prototype._getWaMSecret1 = function (keypair, registerToken, callback) {
24584-
var self = this,
24585-
cs1Url,
24586-
reqData;
24587-
24588-
reqData = {
24589-
publicKey: keypair.publicKey,
24590-
dvsRegisterToken: registerToken
24591-
};
24592-
24593-
cs1Url = self.options.server + "/rps/v2/dvsregister";
24594-
24595-
self.http.request({ url: cs1Url, type: "POST", data: reqData }, callback);
24596-
};
24597-
2459824582
/**
2459924583
* Create a cryptographic signature of a given message
2460024584
*

0 commit comments

Comments
 (0)