Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use Chrome manifest V3 #2965

Merged
merged 71 commits into from
Aug 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
71 commits
Select commit Hold shift + click to select a range
2a09aef
host permissions
yushih Aug 2, 2022
3a36074
`browser_action` becomes `action`
yushih Aug 2, 2022
2672e72
migrate content_security_policy
yushih Aug 4, 2022
b8b51c2
Load zendesk into an iframe
neuodev Aug 9, 2022
0b7b7f5
Update iframe src
neuodev Aug 9, 2022
547d52f
build and dev config change for service worker
yushih Aug 9, 2022
5a53008
fix injection
yushih Aug 10, 2022
869df25
fix background service worker getting screen width
yushih Aug 11, 2022
9467580
change global variables in background service worker to storage API
yushih Aug 12, 2022
8304506
remove defunct `pendingTxs` in background service worker
yushih Aug 12, 2022
ce3ec39
fix rust module for background service worker
yushih Aug 14, 2022
c2cfa05
do not use port to communicate with background service worker
yushih Aug 14, 2022
48fbf8d
use chrome.storage API instead localStorage for submitted txs
yushih Aug 15, 2022
5f33ba4
change chrome.extension.getURL() to chrome.runtime.getURL()
yushih Aug 15, 2022
f0ec7f6
use cardano-serialization-lib to decrypt password in connector
yushih Aug 17, 2022
82cd0c0
use axios-fetch-adapter
yushih Aug 17, 2022
26a7d19
Merge branch 'develop' into yushi/manifest-v3
yushih Aug 18, 2022
8f70674
Merge remote-tracking branch 'origin/Ahmed/zd' into yushi/manifest-v3
yushih Aug 18, 2022
c71e33a
remove scripts/startWithMockServer.js
yushih Aug 22, 2022
ec90a43
flow and lint
yushih Aug 22, 2022
a744b00
change connect resolve to continuation
yushih Aug 24, 2022
6ed30e2
change signing confirmation resolve to continuation
yushih Aug 25, 2022
ed2fefa
remove global `connectedSites` in background service worker
yushih Aug 25, 2022
be0fe1b
prod build should use original rust loader
yushih Aug 29, 2022
fd121b4
Merge branch 'develop' into yushi/manifest-v3
neuodev Aug 29, 2022
f6be85c
Merge branch 'develop' into yushi/manifest-v3
neuodev Aug 30, 2022
fab6554
Use concurrently instead of stmux
neuodev Aug 30, 2022
972fb53
reformat code
yushih Aug 29, 2022
c3e3791
bug fix
yushih Aug 30, 2022
b7e9ce9
Revert "prod build should use original rust loader"
yushih Aug 31, 2022
1195082
webassembly module loading for fix production build
yushih Aug 31, 2022
135b464
fix submitted txs storing and retrieving
yushih Sep 1, 2022
7e28a60
Merge branch 'develop' into yushi/manifest-v3
neuodev Sep 3, 2022
c70c42e
Merge branch 'develop' into yushi/manifest-v3
neuodev Sep 13, 2022
c6279da
Merge remote-tracking branch 'origin/develop' into yushi/manifest-v3
vsubhuman Oct 6, 2022
29c1285
package.json update
vsubhuman Oct 6, 2022
394cd79
Merge remote-tracking branch 'origin/yushi/manifest-v3' into yushi/ma…
vsubhuman Oct 6, 2022
33e1f57
Merge branch 'develop' into yushi/manifest-v3
vsubhuman Oct 12, 2022
a89f3da
flow fixes
vsubhuman Oct 12, 2022
228274d
lint fixes
vsubhuman Oct 12, 2022
5b87a7d
Merge branch 'develop' into yushi/manifest-v3
vsubhuman Oct 13, 2022
071cdfd
bug fix - dapp connector wallet disconnect
yushih Sep 1, 2022
a44fe39
fix user cancelling signing
yushih Sep 5, 2022
02a2c71
bug fix
yushih Oct 30, 2022
8b4b987
bug fix
yushih Nov 5, 2022
2ad12ed
fix typo
yushih Nov 8, 2022
d737110
remove unintended change
yushih Nov 8, 2022
91d82aa
support mv2 build
yushih Nov 10, 2022
2a20ef7
bug fix
yushih Nov 11, 2022
600e8e2
bug fix
yushih Nov 14, 2022
8c9fa3c
flow & lint
yushih Nov 14, 2022
4b9786e
Merge remote-tracking branch 'origin/develop' into yushi/manifest-v3
vsubhuman Dec 9, 2022
a79f573
Merge remote-tracking branch 'origin/develop' into yushi/manifest-v3
vsubhuman Dec 9, 2022
4f3a9fd
connector naming fix (after merge fixes)
vsubhuman Dec 9, 2022
6d53cda
removing ergoConnectorExtensionId usage (after merge fixes)
vsubhuman Dec 9, 2022
1391793
fixing chrome reference
vsubhuman Dec 9, 2022
cdce77b
jest should ignore non-test file
yushih Dec 10, 2022
5693530
Merge branch 'develop' into yushi/manifest-v3
yushih Jul 24, 2023
eb4e8eb
fix merge error
yushih Jul 26, 2023
e6c0298
fix message passing between main window and ledger popup
yushih Jul 26, 2023
97ed905
fix connector sign tx
yushih Jul 26, 2023
d2eef51
Merge branch 'develop' into yushi/manifest-v3
neuodev Aug 1, 2023
d995938
fix rust module for service worker
yushih Aug 1, 2023
94e0666
Merge branch 'develop' into yushi/manifest-v3
vsubhuman Aug 3, 2023
bb332f9
fixing some async calls
vsubhuman Aug 4, 2023
0518846
lint fixes and an improvement todo comment added
vsubhuman Aug 4, 2023
f9a1c63
Removed incorrect resolving in `injectIntoPage` in connector
vsubhuman Aug 7, 2023
025cf23
Merge branch 'develop' into yushi/manifest-v3
vsubhuman Aug 10, 2023
39e5fd8
Switch `encryptWithPassword` to WalletV4
vsubhuman Aug 16, 2023
ff43941
package-lock update
vsubhuman Aug 18, 2023
122aa0d
eslint fixes
vsubhuman Aug 21, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
154 changes: 154 additions & 0 deletions packages/yoroi-connector/src/cardanoApiInject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
(() => {
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) {
const self = this;
function rpcWrapper(func, params) {
return rpc(func, params, self._returnType[0]);
}
this._auth = new CardanoAuth(auth, rpcWrapper);
this._cardano_rpc_call = rpcWrapper;
this._disconnection = [false];
this._returnType = ["cbor"];
window.addEventListener('yoroi_wallet_disconnected', function() {
if (!self._disconnection[0]) {
self._disconnection[0] = true;
self._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"');
}
this._returnType[0] = returnType;
},

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

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

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

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

})

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

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

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

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

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

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

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

submitTx(tx) {
return this._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 this._cardano_rpc_call('sign_tx/cardano', [{ tx, partialSign, returnTx }]);
}

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

// DEPRECATED
getCollateralUtxos(requiredAmount) {
return this._cardano_rpc_call("get_collateral_utxos", [requiredAmount]);
}

getCollateral(requiredAmount) {
return this._cardano_rpc_call("get_collateral_utxos", [requiredAmount]);
}
}
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' });
})();
120 changes: 120 additions & 0 deletions packages/yoroi-connector/src/initialInject.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
(() => {
const WALLET_NAME = 'yoroi';
const API_VERSION = '0.3.0';
const ICON_URL = 'data:image/svg+xml;base64,PHN2ZyB3aWR0aD0iNzIiIGhlaWdodD0iNjMiIHZpZXdCb3g9IjAgMCA3MiA2MyIgZmlsbD0ibm9uZSIgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIj4KPGcgY2xpcC1wYXRoPSJ1cmwoI2NsaXAwXzExODRfODQyNDApIj4KPHBhdGggZD0iTTU1LjYyNzEgNDguOTEzNkw0OS45MjEgNTIuODcxMkw3LjkwMjMyIDIzLjg2MjNDNy45MDIzMiAyMy44MDU2IDcuOTAyMzIgMjMuNzQ4OCA3Ljg4NTYgMjMuNjkyVjIxLjEwMzdDNy44ODU2IDIwLjI2NDMgNy44ODU2IDE5LjQyNjEgNy44ODU2IDE4LjU4ODlWMTUuOTUzOUw1NS42MjcxIDQ4LjkxMzZaTTQzLjkwMDYgMTEuNDc1M0M0MS4zNjM1IDEzLjIxMTkgMzguODAyOSAxNC45MTUyIDM2LjI2NTggMTYuNjUxOUMzNi4xMzk2IDE2Ljc2NjYgMzUuOTc1MSAxNi44MzAyIDM1LjgwNDQgMTYuODMwMkMzNS42MzM4IDE2LjgzMDIgMzUuNDY5MyAxNi43NjY2IDM1LjM0MzEgMTYuNjUxOUMzM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cg==';

var connectRequests = [];

window.addEventListener("message", function(event) {
if (event.data.type === "connector_connected") {
if (event.data.err !== undefined) {
connectRequests.forEach(promise => promise.reject(event.data.err));
} else {
const isSuccess = event.data.success;
connectRequests.forEach(promise => {
if (promise.protocol === 'cardano') {
if (isSuccess) {
promise.resolve(event.data.auth);
} else {
promise.reject({ code: -3, info: 'User Rejected' });
}
} else {
promise.resolve(isSuccess);
}
});
}
}
});

window.ergo_request_read_access = function() {
return new Promise(function(resolve, reject) {
window.postMessage({
type: "connector_connect_request/ergo",
}, location.origin);
connectRequests.push({ resolve: resolve, reject: reject });
});
};

window.ergo_check_read_access = function() {
if (typeof ergo !== "undefined") {
return ergo._ergo_rpc_call("ping", []);
} else {
return Promise.resolve(false);
}
};

// RPC setup
var cardanoRpcUid = 0;
var cardanoRpcResolver = new Map();

window.addEventListener("message", function(event) {
if (event.data.type === "connector_rpc_response" && event.data.protocol === "cardano") {
console.debug("page received from connector: " + JSON.stringify(event.data) + " with source = " + event.source + " and origin = " + event.origin);
const rpcPromise = cardanoRpcResolver.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);
}
}
}
});

function cardano_rpc_call(func, params, returnType) {
return new Promise(function(resolve, reject) {
window.postMessage({
type: "connector_rpc_request",
protocol: "cardano",
url: location.hostname,
uid: cardanoRpcUid,
function: func,
params,
returnType: returnType || "cbor",
}, location.origin);
console.debug("cardanoRpcUid = " + cardanoRpcUid);
cardanoRpcResolver.set(cardanoRpcUid, { resolve: resolve, reject: reject });
cardanoRpcUid += 1;
});
}

function cardano_request_read_access(cardanoAccessRequest) {
const { requestIdentification, onlySilent } = (cardanoAccessRequest || {});
return new Promise(function(resolve, reject) {
window.postMessage({
type: "connector_connect_request/cardano",
requestIdentification,
onlySilent,
}, location.origin);
connectRequests.push({
protocol: 'cardano',
resolve: (auth) => {
const authWrapper = auth == null ? null : Object.freeze({
walletId: auth.walletId,
pubkey: auth.pubkey,
});
resolve(Object.freeze(new CardanoAPI(authWrapper, cardano_rpc_call)));
},
reject: reject
});
});
}

function cardano_check_read_access() {
return cardano_rpc_call("is_enabled/cardano", []);
}

window.cardano = {
...(window.cardano||{}),
[WALLET_NAME]: {
icon: ICON_URL,
enable: cardano_request_read_access,
isEnabled: cardano_check_read_access,
apiVersion: API_VERSION,
name: WALLET_NAME,
}
};

window.postMessage({ type: 'scripted_injected' });
})();
Loading
Loading