Skip to content

Commit

Permalink
Merge pull request #266 from VerusCoin/dev
Browse files Browse the repository at this point in the history
v1.2.5-3
  • Loading branch information
Asherda authored Nov 11, 2024
2 parents b8bc9bd + 528d70f commit 113286f
Show file tree
Hide file tree
Showing 17 changed files with 399 additions and 79 deletions.
4 changes: 2 additions & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ stages:
variables:
DOCKER_DRIVER: overlay2
DEFAULT_VERUSCOIN_BRANCH: release
VERUS_VERSION: 1.2.5-2
VERUSCOIN_VERSION: 1.2.5-2
VERUS_VERSION: 1.2.5-3
VERUSCOIN_VERSION: 1.2.5-3
KOMODO_VERSION: 0.9.0
KOMODO_DOWNLOAD_URL: https://github.com/KomodoPlatform/komodo/releases/download
PIRATE_VERSION: 5.9.0
Expand Down
4 changes: 2 additions & 2 deletions main.js
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ if (!hasLock) {
focusMain();

if (process.platform == "win32" || process.platform == "linux") {
const argIndex = (appConfig.general.main.dev || process.argv.indexOf("devmode") > -1) ? 2 : 1;
const argIndex = 2;
openurlhandler(null, argv.slice(1).toString().split(",")[argIndex], api.dlhandler);
}
}
Expand All @@ -562,7 +562,7 @@ if (!hasLock) {
app.on("second-instance", handleSecondInstance);

// Deep linking
if (appConfig.general.main.enableDeeplink) {
if (!appConfig.general.main.disableDeeplink) {
api.log("setting up deeplink", "init");
setuplink(app);
} else {
Expand Down
8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "verus-desktop",
"productName": "Verus-Desktop",
"version": "1.2.5-2",
"version": "1.2.5-3",
"description": "Verus Desktop Wallet App",
"main": "main.js",
"scripts": {
Expand Down Expand Up @@ -45,14 +45,15 @@
"typescript": "4.4.4"
},
"dependencies": {
"@bitgo/utxo-lib": "git+https://github.com/VerusCoin/BitGoJS.git#utxo-lib-verus",
"@electron/remote": "1.1.0",
"@ethersproject/signing-key": "5.0.5",
"@xmldom/xmldom": "0.8.4",
"agama-wallet-lib": "git+https://github.com/VerusCoin/agama-wallet-lib.git#dev",
"arch": "2.1.0",
"async": "2.6.4",
"axios": "1.6.5",
"base64url": "https://github.com/michaeltout/base64url.git",
"base64url": "git+https://github.com/VerusCoin/base64url.git",
"bigi": "1.4.2",
"bitgo-utxo-lib": "git+https://github.com/VerusCoin/bitgo-utxo-lib.git",
"blake2b": "https://github.com/VerusCoin/blake2b.git",
Expand Down Expand Up @@ -134,7 +135,8 @@
"artifactName": "${productName}-v${version}-${arch}.${ext}",
"icon": "assets/icons/agama_icons",
"desktop": {
"Encoding": "UTF-8"
"Encoding": "UTF-8",
"MimeType": "x-scheme-handler/i5jtwbp6zymeay9llnraglgjqgdrffsau4"
},
"target": [
"appimage"
Expand Down
4 changes: 4 additions & 0 deletions routes/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ api = require('./api/native/callDaemon')(api);
api = require('./api/native/addresses')(api);
api = require('./api/native/balances')(api);
api = require('./api/native/definedchains')(api);
api = require('./api/native/getBlock.js')(api);
api = require('./api/native/info')(api);
api = require('./api/native/mininginfo')(api);
api = require('./api/native/getTransaction.js')(api);
Expand Down Expand Up @@ -172,6 +173,9 @@ api = require('./api/native/getNetworkGraph')(api);
api = require('./api/native/verusbridge/verusbridge.js')(api);
api = require('./api/native/verusbridge/vethconf.js')(api);

// lite
api = require('./api/getSignatureInfo.js')(api);

// general network calls
api.networkFees = {}
api.coinSupply = {}
Expand Down
12 changes: 8 additions & 4 deletions routes/api/dlhandler.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,21 @@
const { LOGIN_CONSENT_REQUEST_VDXF_KEY } = require('verus-typescript-primitives');
const { LOGIN_CONSENT_REQUEST_VDXF_KEY, LoginConsentRequest } = require('verus-typescript-primitives');
const base64url = require("base64url");
const { IS_TESTNET } = require('./utils/constants/dev_options');

module.exports = (api) => {
api.dlhandler = (url) => {
const handlers = {
[LOGIN_CONSENT_REQUEST_VDXF_KEY.vdxfid]: (url) => {
const value = url.searchParams.get(LOGIN_CONSENT_REQUEST_VDXF_KEY.vdxfid)

const req = new LoginConsentRequest();
req.fromBuffer(base64url.toBuffer(value));

return api.loginConsentUi.request(
JSON.parse(base64url.decode(value)),
req.toJson(),
{
id: "VERUS_DESKTOP_MAIN",
search_builtin: true
search_builtin: true,
main_chain_ticker: IS_TESTNET ? "VRSCTEST" : "VRSC"
}
)
}
Expand Down
56 changes: 56 additions & 0 deletions routes/api/getSignatureInfo.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const {
IdentitySignature,
networks,
} = require("@bitgo/utxo-lib");

module.exports = (api) => {
/**
* Gets the version, hashtype and height from a signature.
*
* @param {String} coin The chainTicker of the coin to make the call on
* @param {String} systemId The iaddress of the system
* @param {String} signature The signature to process
* @param {String} iaddress The iaddress associated with the signature
*/
api.getSignatureInfo = (coin, systemId, signature, iaddress) => {

const network = coin == "VRSC" ? networks.verus : networks.verustest;

const sig = new IdentitySignature(network);

sig.fromBuffer(Buffer.from(signature, "base64"), 0, systemId, iaddress);

return {
version: sig.version,
hashtype: sig.hashType,
height: sig.blockHeight,
};
}

api.setPost('/lite/get_signature_info', (req, res, next) => {
const {
chainTicker,
systemId,
signature,
iaddress
} = req.body;

try {
res.send(
JSON.stringify({
msg: "success",
result: api.getSignatureInfo(chainTicker, systemId, signature, iaddress),
})
);
} catch (e) {
res.send(
JSON.stringify({
msg: "error",
result: e.message,
})
);
}
});

return api;
}
65 changes: 65 additions & 0 deletions routes/api/native/getBlock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
module.exports = (api) => {
/**
* Gets the version, hashtype and height from a signature.
*
* @param {String} coin The chainTicker of the coin to make the call on
* @param {String} hashorheight The block hash or height
* @param {String} verbosity The verbosity of the result. 0 for hex encoded data, 1 for a json object, and 2 for json object with transaction data
*/
api.native.get_block = (
coin,
hashorheight,
verbosity = 1,
) => {
return new Promise((resolve, reject) => {
api.native
.callDaemon(
coin,
"getblock",
[
hashorheight,
verbosity
]
)
.then(resultObj => {
resolve(resultObj)
})
.catch(err => {
reject(err);
});
});
};

api.setPost('/native/get_block', (req, res, next) => {
const {
chainTicker,
hashorheight,
verbosity
} = req.body;

api.native
.get_block(
chainTicker,
hashorheight,
verbosity
)
.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;
}
30 changes: 30 additions & 0 deletions routes/api/native/signdata.js
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,36 @@ module.exports = (api) => {
});
};

/**
* Signs data given the arguments including an identity/address currently in the wallet
* and the data to be signed
*
* @param {String} coin The chainTicker of the coin to make the call on
* @param {String} arguments The arguments to pass to signdata
*/
api.native.sign_data = (
coin,
arguments,
) => {
return new Promise((resolve, reject) => {
api.native
.callDaemon(
coin,
"signdata",
[
arguments,
]
)
.then(resultObj => {
resolve(resultObj)
})
.catch(err => {
reject(err);
});
});
};


api.setPost('/native/sign_message', (req, res, next) => {
const {
chainTicker,
Expand Down
28 changes: 16 additions & 12 deletions routes/api/native/verusid/login/signResponse.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,35 @@ const {
module.exports = (api) => {
api.native.verusid.login.sign_response = async (response) => {
const loginResponse = new LoginConsentResponse(response);
const chainTicker = response.chainTicker
// Add the chainTicker when checking the request since the verify request needs it.
let decisionRequest = loginResponse.decision.request
decisionRequest.chainTicker = chainTicker

const verificatonCheck = await api.native.verusid.login.verify_request(
loginResponse.decision.request
decisionRequest
);

if (!verificatonCheck.verified) {
throw new Error(verificatonCheck.message);
}

const subject = loginResponse.decision.request.challenge.subject;
if (subject != null && loginResponse.signing_id !== subject)
throw new Error("Cannot sign request for different user.");

const userSignature = await api.native.sign_message(
loginResponse.chain_id,
loginResponse.signing_id,
loginResponse.getSignedData()
);
const signdataResult = await api.native.sign_data(chainTicker,
{
"address": loginResponse.signing_id,
"datahash": loginResponse.decision.toSha256().toString("hex")
}
)

loginResponse.signature = new VerusIDSignature(
{ signature: userSignature.signature },
{ signature: signdataResult.signature },
LOGIN_CONSENT_RESPONSE_SIG_VDXF_KEY
);

return { response: loginResponse.stringable() };
// Remove the chainTicker field since it's not normally part of the response.
delete decisionRequest.chainTicker

return { response: loginResponse};
};

api.setPost("/native/verusid/login/sign_response", async (req, res, next) => {
Expand Down
7 changes: 4 additions & 3 deletions routes/api/native/verusid/login/verifyRequest.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@ module.exports = (api) => {
*/
api.native.verusid.login.verify_request = async (request) => {
const loginConsentRequest = new LoginConsentRequest(request);
const chainTicker = request.chainTicker

const verified = await api.native.verify_message(
loginConsentRequest.chain_id,
const verified = await api.native.verify_hash(
chainTicker,
loginConsentRequest.signing_id,
loginConsentRequest.getSignedData(),
loginConsentRequest.challenge.toSha256().toString('hex'),
loginConsentRequest.signature.signature
);

Expand Down
16 changes: 12 additions & 4 deletions routes/api/plugin/builtin/loginconsentui.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const {
LOGIN_CONSENT_RESPONSE_VDXF_KEY,
LOGIN_CONSENT_WEBHOOK_VDXF_KEY,
LOGIN_CONSENT_REDIRECT_VDXF_KEY,
LoginConsentResponse,
} = require("verus-typescript-primitives");
const { pushMessage } = require('../../../ipc/ipc');
const { ReservedPluginTypes } = require('../../utils/plugin/builtin');
Expand All @@ -14,8 +15,8 @@ module.exports = (api) => {
api.loginConsentUi = {}

api.loginConsentUi.handle_redirect = (response, redirectinfo) => {
const { type, uri } = redirectinfo
const { vdxfkey, uri } = redirectinfo

const handlers = {
[LOGIN_CONSENT_WEBHOOK_VDXF_KEY.vdxfid]: async () => {
return await axios.post(
Expand All @@ -25,17 +26,24 @@ module.exports = (api) => {
},
[LOGIN_CONSENT_REDIRECT_VDXF_KEY.vdxfid]: () => {
const url = new URL(uri)

// Prevent opening any urls that don't go to the browser.
if (!['https:', 'http:'].includes(url.protocol)) {
return null;
}

const res = new LoginConsentResponse(response)
url.searchParams.set(
LOGIN_CONSENT_RESPONSE_VDXF_KEY.vdxfid,
base64url(JSON.stringify(response))
base64url(res.toBuffer())
);

shell.openExternal(url.toString())
return null
}
}

return handlers[type] == null ? null : handlers[type]();
return handlers[vdxfkey] == null ? null : handlers[vdxfkey]();
}

api.loginConsentUi.request = async (
Expand Down
5 changes: 5 additions & 0 deletions routes/api/utils/constants/dev_options.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
const IS_TESTNET = false;

module.exports = {
IS_TESTNET
}
Loading

0 comments on commit 113286f

Please sign in to comment.