-
Notifications
You must be signed in to change notification settings - Fork 102
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/develop' into feat/YOEXT-680/rev…
…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
Showing
358 changed files
with
18,110 additions
and
9,142 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
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' }); | ||
})(); |
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,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' }); | ||
})(); |
Oops, something went wrong.