Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/develop' into feat/YOEXT-680/rev…
Browse files Browse the repository at this point in the history
…amp-settings-page

# Conflicts:
#	packages/yoroi-extension/app/components/layout/TopBarLayout.js
#	packages/yoroi-extension/app/containers/profile/TermsOfUsePage.js
#	packages/yoroi-extension/app/containers/wallet/Receive.js
#	packages/yoroi-extension/app/containers/wallet/WalletReceivePage.js
#	packages/yoroi-extension/app/styles/overrides/revamp/Button.js
#	packages/yoroi-extension/app/styles/overrides/revamp/InputLabel.js
  • Loading branch information
vsubhuman committed Oct 7, 2023
2 parents 17da73e + 7432836 commit d60d430
Show file tree
Hide file tree
Showing 358 changed files with 18,110 additions and 9,142 deletions.
24 changes: 0 additions & 24 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,6 @@ jobs:
working-directory: ./packages/yoroi-extension
run: npm run test:build

- name: Create the report's folder
working-directory: ./packages/yoroi-extension
run: |
mkdir reports
touch ./reports/cucumberReports.json
- name: Run dapp connector tests
working-directory: ./packages/yoroi-extension
env:
Expand Down Expand Up @@ -244,12 +238,6 @@ jobs:
working-directory: ./packages/yoroi-extension
run: npm run test:build

- name: Create the report's folder
working-directory: ./packages/yoroi-extension
run: |
mkdir reports
touch ./reports/cucumberReports.json
- name: Run tests
working-directory: ./packages/yoroi-extension
run: xvfb-run -a -e /dev/stdout -s "-screen 0 1920x1080x24" npm run test:run:e2e:trezor:${{ matrix.browser }}
Expand Down Expand Up @@ -337,12 +325,6 @@ jobs:
working-directory: ./packages/yoroi-extension
run: npm run test:build:mainnet

- name: Create the report's folder
working-directory: ./packages/yoroi-extension
run: |
mkdir reports
touch ./reports/cucumberReports.json
- name: Run smoke tests
working-directory: ./packages/yoroi-extension
env:
Expand Down Expand Up @@ -434,12 +416,6 @@ jobs:
working-directory: ./packages/yoroi-extension
run: npm run test:build

- name: Create the report's folder
working-directory: ./packages/yoroi-extension
run: |
mkdir reports
touch ./reports/cucumberReports.json
- name: Run tests
working-directory: ./packages/yoroi-extension
env:
Expand Down
157 changes: 157 additions & 0 deletions packages/yoroi-connector/src/cardanoApiInject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
(() => {
class CardanoAuth {
constructor(auth, rpc) {
this._auth = auth;
this._cardano_rpc_call = rpc;
}

isEnabled() {
return this._auth != null;
}

getWalletId() {
if (!this._auth) {
throw new Error('This connection does not have auth enabled!');
}
return this._auth.walletId;
}

getWalletPubkey() {
if (!this._auth) {
throw new Error('This connection does not have auth enabled!');
}
return this._auth.pubkey;
}

signHexPayload(payload_hex_string) {
if (!this._auth) {
throw new Error('This connection does not have auth enabled!');
}
return this._cardano_rpc_call("auth_sign_hex_payload/cardano", [payload_hex_string]);
}

checkHexPayload(payload_hex_string, signature_hex_string) {
if (!this._auth) {
throw new Error('This connection does not have auth enabled!');
}
return this._cardano_rpc_call("auth_check_hex_payload/cardano", [payload_hex_string, signature_hex_string]);
}
}
class CardanoAPI {

constructor(auth, rpc) {
function rpcWrapper(func, params) {
return rpc(func, params, CardanoAPI._returnType[0]);
}
CardanoAPI._auth = new CardanoAuth(auth, rpcWrapper);
CardanoAPI._cardano_rpc_call = rpcWrapper;
CardanoAPI._disconnection = [false];
CardanoAPI._returnType = ["cbor"];
window.addEventListener('yoroi_wallet_disconnected', function() {
if (!CardanoAPI._disconnection[0]) {
CardanoAPI._disconnection[0] = true;
CardanoAPI._disconnection.slice(1).forEach(f => f());
}
});
}

experimental = Object.freeze({

setReturnType: (returnType) => {
if (returnType !== 'cbor' && returnType !== 'json') {
throw new Error('Possible return type values are: "cbor" or "json"');
}
CardanoAPI._returnType[0] = returnType;
},

auth: () => {
return CardanoAPI._auth;
},

createTx: (req) => {
return CardanoAPI._cardano_rpc_call("create_tx/cardano", [req]);
},

listNFTs: () => {
return CardanoAPI._cardano_rpc_call("list_nfts/cardano", []);
},

onDisconnect: (callback) => {
if (CardanoAPI._disconnection[0]) {
throw new Error('Cardano API instance is already disconnected!');
}
CardanoAPI._disconnection.push(callback);
},

})

getNetworkId() {
return CardanoAPI._cardano_rpc_call("get_network_id", []);
}

getBalance(token_id = '*') {
return CardanoAPI._cardano_rpc_call("get_balance", [token_id]);
}

getUsedAddresses(paginate = undefined) {
return CardanoAPI._cardano_rpc_call("get_used_addresses", [paginate]);
}

getUnusedAddresses() {
return CardanoAPI._cardano_rpc_call("get_unused_addresses", []);
}

getRewardAddresses() {
return CardanoAPI._cardano_rpc_call("get_reward_addresses/cardano", []);
}

getChangeAddress() {
return CardanoAPI._cardano_rpc_call("get_change_address", []);
}

getUtxos(amount = undefined, paginate = undefined) {
return CardanoAPI._cardano_rpc_call("get_utxos/cardano", [amount, paginate]);
}

submitTx(tx) {
return CardanoAPI._cardano_rpc_call('submit_tx', [tx]);
}

signTx(param, _partialSign = false) {
if (param == null) {
throw new Error('.signTx argument cannot be null!');
}
let tx = param;
let partialSign = _partialSign;
let returnTx = false;
if (typeof param === 'object') {
tx = param.tx;
partialSign = param.partialSign;
returnTx = param.returnTx;
} else if (typeof param !== 'string') {
throw new Error('.signTx argument is expected to be an object or a string!')
}
return CardanoAPI._cardano_rpc_call('sign_tx/cardano', [{ tx, partialSign, returnTx }]);
}

signData(address, payload) {
return CardanoAPI._cardano_rpc_call("sign_data", [address, payload]);
}

// DEPRECATED
getCollateralUtxos(requiredAmount) {
const amount = typeof requiredAmount === 'object' ? requiredAmount.amount : requiredAmount;
const strAmount = amount == null || amount === '' ? null : String(amount);
return CardanoAPI._cardano_rpc_call("get_collateral_utxos", [strAmount]);
}

getCollateral(requiredAmount) {
const amount = typeof requiredAmount === 'object' ? requiredAmount.amount : requiredAmount;
const strAmount = amount == null || amount === '' ? null : String(amount);
return CardanoAPI._cardano_rpc_call("get_collateral_utxos", [strAmount]);
}
}
window.CardanoAPI = CardanoAPI;

window.postMessage({ type: 'scripted_injected' });
})();
79 changes: 79 additions & 0 deletions packages/yoroi-connector/src/ergoApiInject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
// RPC set-up
(() => {
var ergoRpcUid = 0;
var ergoRpcResolver = new Map();

window.addEventListener("message", function(event) {
if (event.data.type == "connector_rpc_response" && event.data.protocol === "ergo") {
console.debug("page received from connector: " + JSON.stringify(event.data) + " with source = " + event.source + " and origin = " + event.origin);
const rpcPromise = ergoRpcResolver.get(event.data.uid);
if (rpcPromise !== undefined) {
const ret = event.data.return;
if (ret.err !== undefined) {
rpcPromise.reject(ret.err);
} else {
rpcPromise.resolve(ret.ok);
}
}
}
});

class ErgoAPI {
get_balance(token_id = 'ERG') {
return this._ergo_rpc_call("get_balance", [token_id]);
}

get_utxos(amount = undefined, token_id = 'ERG', paginate = undefined) {
return this._ergo_rpc_call("get_utxos", [amount, token_id, paginate]);
}

get_used_addresses(paginate = undefined) {
return this._ergo_rpc_call("get_used_addresses", [paginate]);
}

get_unused_addresses() {
return this._ergo_rpc_call("get_unused_addresses", []);
}

get_change_address() {
return this._ergo_rpc_call("get_change_address", []);
}

sign_tx(tx) {
return this._ergo_rpc_call("sign_tx", [tx]);
}

sign_tx_input(tx, index) {
return this._ergo_rpc_call("sign_tx_input", [tx, index]);
}

// This is unsupported by current version of Yoroi
// and the details of it are not finalized yet in the EIP-012
// dApp bridge spec.
// sign_data(addr, message) {
// return this._ergo_rpc_call("sign_data", [addr, message]);
// }

submit_tx(tx) {
return this._ergo_rpc_call("submit_tx", [tx]);
}

_ergo_rpc_call(func, params) {
return new Promise(function(resolve, reject) {
window.postMessage({
type: "connector_rpc_request",
protocol: "ergo",
uid: ergoRpcUid,
function: func,
params: params
}, location.origin);
console.debug("ergoRpcUid = " + ergoRpcUid);
ergoRpcResolver.set(ergoRpcUid, { resolve: resolve, reject: reject });
ergoRpcUid += 1;
});
}
}

window.ergo = Object.freeze(new ErgoAPI());
window.postMessage({ type: 'scripted_injected' });
})();
Loading

0 comments on commit d60d430

Please sign in to comment.