forked from michaeltout/VerusConnect
-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #270 from VerusCoin/dev
v1.2.7
- Loading branch information
Showing
11 changed files
with
185 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
module.exports = (api) => { | ||
/** | ||
* Returns the VDXF key of the URI string. | ||
* | ||
* @param {String} coin The chainTicker of the coin to make the call on | ||
* @param {String} vdxfuri This message is converted from hex, the data is hashed, then returned | ||
* @param {Object} initialvdxfdata The optional data of (vdxfkey, uint256, indexnum) that is combined. | ||
*/ | ||
api.native.get_vdxf_id = ( | ||
coin, | ||
vdxfuri, | ||
initialvdxfdata = {}, | ||
) => { | ||
return new Promise((resolve, reject) => { | ||
api.native | ||
.callDaemon( | ||
coin, | ||
"getvdxfid", | ||
[ | ||
vdxfuri, | ||
initialvdxfdata | ||
] | ||
) | ||
.then(resultObj => { | ||
resolve(resultObj) | ||
}) | ||
.catch(err => { | ||
reject(err); | ||
}); | ||
}); | ||
}; | ||
|
||
api.setPost('/native/get_vdxf_id', (req, res, next) => { | ||
const { | ||
chainTicker, | ||
vdxfuri, | ||
initialvdxfdata | ||
} = req.body; | ||
|
||
api.native | ||
.get_vdxf_id( | ||
chainTicker, | ||
vdxfuri, | ||
initialvdxfdata | ||
) | ||
.then(resultObj => { | ||
const retObj = { | ||
msg: "success", | ||
result: resultObj | ||
}; | ||
|
||
res.send(JSON.stringify(retObj)); | ||
}) | ||
.catch(error => { | ||
const retObj = { | ||
msg: "error", | ||
result: error.message | ||
}; | ||
|
||
res.send(JSON.stringify(retObj)); | ||
}); | ||
}); | ||
|
||
return api; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
56 changes: 56 additions & 0 deletions
56
routes/api/native/verusid/provision/signIdProvisioningRequest.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
const { VerusIDSignature, IDENTITY_AUTH_SIG_VDXF_KEY } = require("verus-typescript-primitives"); | ||
const { ProvisioningRequest } = require("verus-typescript-primitives/dist/vdxf/classes/provisioning/ProvisioningRequest"); | ||
|
||
module.exports = (api) => { | ||
/** | ||
* Signs a provisioning request using an r-address. | ||
* | ||
* @param {String} coin The chainTicker of the coin to make the call on | ||
* @param {String} request The provisioning request to sign | ||
* @param {String} raddress The raddress to sign the provioning requset with | ||
*/ | ||
api.native.verusid.provision.sign_id_provisioning_request = async (coin, request, raddress) => { | ||
|
||
const provisioningRequest = new ProvisioningRequest(request); | ||
|
||
const signdataResult = await api.native.sign_data(coin, | ||
{ | ||
"address": raddress, | ||
"datahash": provisioningRequest.challenge.toSha256().toString("hex") | ||
} | ||
) | ||
|
||
provisioningRequest.signature = new VerusIDSignature( | ||
{ signature: signdataResult.signature }, | ||
IDENTITY_AUTH_SIG_VDXF_KEY | ||
); | ||
|
||
return provisioningRequest; | ||
} | ||
|
||
api.setPost('/native/verusid/provision/sign_id_provisioning_request', async (req, res, next) => { | ||
const { | ||
chainTicker, | ||
request, | ||
raddress | ||
} = req.body; | ||
|
||
try { | ||
res.send( | ||
JSON.stringify({ | ||
msg: "success", | ||
result: await api.native.verusid.provision.sign_id_provisioning_request(chainTicker, request, raddress), | ||
}) | ||
); | ||
} catch (e) { | ||
res.send( | ||
JSON.stringify({ | ||
msg: "error", | ||
result: e.message, | ||
}) | ||
); | ||
} | ||
}); | ||
|
||
return api; | ||
} |
50 changes: 50 additions & 0 deletions
50
routes/api/native/verusid/provision/verifyIdProvisioningResponse.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
const { LoginConsentProvisioningResponse } = require("verus-typescript-primitives"); | ||
const { ROOT_SYSTEM_NAME } = require("../../../utils/constants/dev_options"); | ||
|
||
module.exports = (api) => { | ||
/** | ||
* Verifies a provisioning response | ||
* @param {LoginConsentProvisioningResponse} Response | ||
*/ | ||
api.native.verusid.provision.verify_id_provisioning_response = async (response) => { | ||
const provisioningResponse = new LoginConsentProvisioningResponse(response); | ||
|
||
// Convert the system id to the chain name. | ||
const currencyObject = await api.native.get_currency( | ||
ROOT_SYSTEM_NAME, | ||
response.system_id | ||
); | ||
const chainTicker = currencyObject.name.toUpperCase(); | ||
|
||
const verified = await api.native.verify_hash( | ||
chainTicker, | ||
provisioningResponse.signing_id, | ||
provisioningResponse.decision.toSha256().toString('hex'), | ||
provisioningResponse.signature.signature | ||
); | ||
|
||
return verified ? { verified } : { verified, message: "Failed to verify signature" }; | ||
}; | ||
|
||
api.setPost("/native/verusid/provision/verify_id_provisioning_response", async (req, res, next) => { | ||
const { response } = req.body; | ||
|
||
try { | ||
res.send( | ||
JSON.stringify({ | ||
msg: "success", | ||
result: await api.native.verusid.provision.verify_id_provisioning_response(response), | ||
}) | ||
); | ||
} catch (e) { | ||
res.send( | ||
JSON.stringify({ | ||
msg: "error", | ||
result: e.message, | ||
}) | ||
); | ||
} | ||
}); | ||
|
||
return api; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,7 @@ | ||
module.exports = (api) => { | ||
api.native.verusid = {} | ||
api.native.verusid.login = {} | ||
api.native.verusid.provision = {} | ||
|
||
return api; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
1.2.6 | ||
1.2.7 |