Skip to content

Commit

Permalink
Merge pull request #3312 from Emurgo/chore/YOEXT-812/cip95-for-4.23
Browse files Browse the repository at this point in the history
Port CIP-95 implementation to 4.23
  • Loading branch information
vsubhuman authored Oct 28, 2023
2 parents a7c2c16 + 42ac1fe commit af7cc14
Show file tree
Hide file tree
Showing 9 changed files with 290 additions and 15 deletions.
24 changes: 23 additions & 1 deletion packages/yoroi-connector/src/cardanoApiInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,25 @@
}
});
}

cip95 = Object.freeze({

getPubDRepKey: () => {
return CardanoAPI._cardano_rpc_call("get_drep_key", []);
},

getRegisteredPubStakeKeys: () => {
return CardanoAPI._cardano_rpc_call("get_stake_key", [])
.then(({ key, isRegistered }) => isRegistered ? [key] : []);
},

getUnregisteredPubStakeKeys: () => {
return CardanoAPI._cardano_rpc_call("get_stake_key", [])
.then(({ key, isRegistered }) => isRegistered ? [] : [key]);
},

})

experimental = Object.freeze({

setReturnType: (returnType) => {
Expand Down Expand Up @@ -84,7 +102,11 @@
},

})


getExtensions() {
return [{ cip: 95 }];
}

getNetworkId() {
return CardanoAPI._cardano_rpc_call("get_network_id", []);
}
Expand Down
5 changes: 3 additions & 2 deletions packages/yoroi-connector/src/initialInject.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,13 +90,14 @@

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

window.postMessage({ type: 'scripted_injected' });
Expand Down
7 changes: 0 additions & 7 deletions packages/yoroi-extension/app/api/crypto.js

This file was deleted.

2 changes: 2 additions & 0 deletions packages/yoroi-extension/app/config/numbersConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,11 @@ export const ChainDerivations = Object.freeze({
EXTERNAL: 0,
INTERNAL: 1,
CHIMERIC_ACCOUNT: 2,
GOVERNANCE_DREP_KEYS: 3,
});

export const STAKING_KEY_INDEX = 0;
export const DREP_KEY_INDEX = 0;

/**
* Constant K as defined in Ouroboros Classic
Expand Down
42 changes: 42 additions & 0 deletions packages/yoroi-extension/chrome/extension/background.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ import {
connectorGetAssets,
getTokenMetadataFromIds,
MAX_COLLATERAL,
connectorGetDRepKey, connectorGetStakeKey,
} from './connector/api';
import {
updateTransactions as cardanoUpdateTransactions
Expand Down Expand Up @@ -1385,6 +1386,47 @@ async function handleInjectorMessage(message, sender) {
handleError(e);
}
break;
case 'get_drep_key':
try {
await RustModule.load();
await withDb(async (db, localStorageApi) => {
await withSelectedWallet(
tabId,
async (wallet) => {
const dRepKey = await connectorGetDRepKey(wallet);
rpcResponse({ ok: dRepKey });
},
db,
localStorageApi,
)
});
} catch (e) {
handleError(e);
}
break;
case 'get_stake_key':
try {
await RustModule.load();
await withDb(async (db, localStorageApi) => {
await withSelectedWallet(
tabId,
async (wallet) => {
const stateFetcher: CardanoIFetcher =
await getCardanoStateFetcher(localStorageApi);
const resp = await connectorGetStakeKey(
wallet,
stateFetcher.getAccountState,
);
rpcResponse({ ok: resp });
},
db,
localStorageApi,
)
});
} catch (e) {
handleError(e);
}
break;
case `get_change_address`:
try {
await withDb(async (db, localStorageApi) => {
Expand Down
Loading

0 comments on commit af7cc14

Please sign in to comment.