Skip to content

Commit 0f5f0c5

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

12 files changed

+197
-424
lines changed

cjs/client.cjs

Lines changed: 25 additions & 53 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,24 +24218,25 @@ 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) {
2423524235
if (err) {
2423624236
return callback(err, result);
2423724237
}
2423824238

24239+
// TODO: remove this?
2423924240
self.users.write(userId, { state: self.users.states.start });
2424024241

2424124242
callback(null, result);
@@ -24252,28 +24253,10 @@ Client.prototype._getDeviceName = function () {
2425224253
return "Browser";
2425324254
};
2425424255

24255-
Client.prototype._getSecret1 = function (identityData, keypair, callback) {
24256-
var self = this,
24257-
cs1Url;
24258-
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) {
24265-
if (err) {
24266-
return callback(err, null);
24267-
}
24268-
24269-
callback(null, sec1Data);
24270-
});
24271-
};
24272-
24273-
Client.prototype._getSecret2 = function (sec1Data, callback) {
24256+
Client.prototype._getSecret = function (secretUrl, callback) {
2427424257
var self = this;
2427524258

24276-
self.http.request({ url: sec1Data.cs2url }, callback);
24259+
self.http.request({ url: secretUrl }, callback);
2427724260
};
2427824261

2427924262
Client.prototype._createIdentity = function (userId, userPin, identityData, sec1Data, sec2Data, keypair, callback) {
@@ -24283,17 +24266,17 @@ Client.prototype._createIdentity = function (userId, userPin, identityData, sec1
2428324266
token;
2428424267

2428524268
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);
24269+
csHex = self.crypto.addShares(keypair.privateKey, sec1Data.dvsClientSecret, sec2Data.dvsClientSecret, identityData.curve);
24270+
token = self.crypto.extractPin(identityData.mpinId, keypair.publicKey, userPin, csHex, identityData.curve);
2428824271
} catch (err) {
2428924272
return callback(err, null);
2429024273
}
2429124274

2429224275
userData = {
2429324276
mpinId: identityData.mpinId,
2429424277
token: token,
24295-
curve: sec1Data.curve,
24296-
dtas: sec1Data.dtas,
24278+
curve: identityData.curve,
24279+
dtas: identityData.dtas,
2429724280
publicKey: keypair.publicKey,
2429824281
pinLength: identityData.pinLength,
2429924282
projectId: identityData.projectId,
@@ -24559,42 +24542,31 @@ Client.prototype._finishAuthentication = function (userId, userPin, scope, authO
2455924542

2456024543
Client.prototype._renewSecret = function (userId, userPin, activationData, callback) {
2456124544
var self = this,
24562-
identityData,
2456324545
keypair;
2456424546

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

24568-
self._getWaMSecret1(keypair, activationData.token, function (err, sec1Data) {
24549+
self._createMPinID(userId, activationData.token, keypair, function (err, identityData) {
2456924550
if (err) {
2457024551
return callback(err, null);
2457124552
}
2457224553

24573-
self._getSecret2(sec1Data, function (err, sec2Data) {
24554+
self._getSecret(identityData.secretUrls[0], function (err, sec1Data) {
2457424555
if (err) {
2457524556
return callback(err, null);
2457624557
}
2457724558

24578-
self._createIdentity(userId, userPin, identityData, sec1Data, sec2Data, keypair, callback);
24559+
self._getSecret(identityData.secretUrls[1], function (err, sec2Data) {
24560+
if (err) {
24561+
return callback(err, null);
24562+
}
24563+
24564+
self._createIdentity(userId, userPin, identityData, sec1Data, sec2Data, keypair, callback);
24565+
});
2457924566
});
2458024567
});
2458124568
};
2458224569

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-
2459824570
/**
2459924571
* Create a cryptographic signature of a given message
2460024572
*

cjs/promise.cjs

Lines changed: 25 additions & 53 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,24 +24218,25 @@ 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) {
2423524235
if (err) {
2423624236
return callback(err, result);
2423724237
}
2423824238

24239+
// TODO: remove this?
2423924240
self.users.write(userId, { state: self.users.states.start });
2424024241

2424124242
callback(null, result);
@@ -24252,28 +24253,10 @@ Client.prototype._getDeviceName = function () {
2425224253
return "Browser";
2425324254
};
2425424255

24255-
Client.prototype._getSecret1 = function (identityData, keypair, callback) {
24256-
var self = this,
24257-
cs1Url;
24258-
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) {
24265-
if (err) {
24266-
return callback(err, null);
24267-
}
24268-
24269-
callback(null, sec1Data);
24270-
});
24271-
};
24272-
24273-
Client.prototype._getSecret2 = function (sec1Data, callback) {
24256+
Client.prototype._getSecret = function (secretUrl, callback) {
2427424257
var self = this;
2427524258

24276-
self.http.request({ url: sec1Data.cs2url }, callback);
24259+
self.http.request({ url: secretUrl }, callback);
2427724260
};
2427824261

2427924262
Client.prototype._createIdentity = function (userId, userPin, identityData, sec1Data, sec2Data, keypair, callback) {
@@ -24283,17 +24266,17 @@ Client.prototype._createIdentity = function (userId, userPin, identityData, sec1
2428324266
token;
2428424267

2428524268
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);
24269+
csHex = self.crypto.addShares(keypair.privateKey, sec1Data.dvsClientSecret, sec2Data.dvsClientSecret, identityData.curve);
24270+
token = self.crypto.extractPin(identityData.mpinId, keypair.publicKey, userPin, csHex, identityData.curve);
2428824271
} catch (err) {
2428924272
return callback(err, null);
2429024273
}
2429124274

2429224275
userData = {
2429324276
mpinId: identityData.mpinId,
2429424277
token: token,
24295-
curve: sec1Data.curve,
24296-
dtas: sec1Data.dtas,
24278+
curve: identityData.curve,
24279+
dtas: identityData.dtas,
2429724280
publicKey: keypair.publicKey,
2429824281
pinLength: identityData.pinLength,
2429924282
projectId: identityData.projectId,
@@ -24559,42 +24542,31 @@ Client.prototype._finishAuthentication = function (userId, userPin, scope, authO
2455924542

2456024543
Client.prototype._renewSecret = function (userId, userPin, activationData, callback) {
2456124544
var self = this,
24562-
identityData,
2456324545
keypair;
2456424546

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

24568-
self._getWaMSecret1(keypair, activationData.token, function (err, sec1Data) {
24549+
self._createMPinID(userId, activationData.token, keypair, function (err, identityData) {
2456924550
if (err) {
2457024551
return callback(err, null);
2457124552
}
2457224553

24573-
self._getSecret2(sec1Data, function (err, sec2Data) {
24554+
self._getSecret(identityData.secretUrls[0], function (err, sec1Data) {
2457424555
if (err) {
2457524556
return callback(err, null);
2457624557
}
2457724558

24578-
self._createIdentity(userId, userPin, identityData, sec1Data, sec2Data, keypair, callback);
24559+
self._getSecret(identityData.secretUrls[1], function (err, sec2Data) {
24560+
if (err) {
24561+
return callback(err, null);
24562+
}
24563+
24564+
self._createIdentity(userId, userPin, identityData, sec1Data, sec2Data, keypair, callback);
24565+
});
2457924566
});
2458024567
});
2458124568
};
2458224569

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-
2459824570
/**
2459924571
* Create a cryptographic signature of a given message
2460024572
*

0 commit comments

Comments
 (0)