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

[Coin Modularization] Cardano #6812

Open
wants to merge 6 commits into
base: develop
Choose a base branch
from

Conversation

sprohaszka-ledger
Copy link
Contributor

@sprohaszka-ledger sprohaszka-ledger commented May 6, 2024

βœ… Checklist

  • npx changeset was attached.
  • Covered by automatic tests.
  • Impact of the changes:
    • ...

πŸ“ Description

Move Cardano...

❓ Context


🧐 Checklist for the PR Reviewers

  • The code aligns with the requirements described in the linked JIRA or GitHub issue.
  • The PR description clearly documents the changes made and explains any technical trade-offs or design decisions.
  • There are no undocumented trade-offs, technical debt, or maintainability issues.
  • The PR has been tested thoroughly, and any potential edge cases have been considered and handled.
  • Any new dependencies have been justified and documented.
  • Performance considerations have been taken into account. (changes have been profiled or benchmarked if necessary)

Copy link

vercel bot commented May 6, 2024

The latest updates on your projects. Learn more about Vercel for Git β†—οΈŽ

Name Status Preview Comments Updated (UTC)
react-ui-storybook βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 17, 2024 11:10am
web-tools βœ… Ready (Inspect) Visit Preview πŸ’¬ Add feedback May 17, 2024 11:10am
3 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ledger-live-docs ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 11:10am
ledger-live-github-bot ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 11:10am
native-ui-storybook ⬜️ Ignored (Inspect) Visit Preview May 17, 2024 11:10am

@live-github-bot live-github-bot bot added desktop Has changes in LLD mobile Has changes in LLM common Has changes in live-common ledgerjs Has changes in the ledgerjs open source libs labels May 6, 2024
Copy link

socket-security bot commented May 7, 2024

New dependencies detected. Learn more about Socket for GitHub β†—οΈŽ

Package New capabilities Transitives Size Publisher
npm/@ledgerhq/coin-cardano@0.0.1 None 0 0 B

View full reportβ†—οΈŽ

Signed-off-by: StΓ©phane Prohaszka <stephane.prohaszka@ledger.fr>
Signed-off-by: StΓ©phane Prohaszka <stephane.prohaszka@ledger.fr>
Signed-off-by: StΓ©phane Prohaszka <stephane.prohaszka@ledger.fr>
Signed-off-by: StΓ©phane Prohaszka <stephane.prohaszka@ledger.fr>
Signed-off-by: StΓ©phane Prohaszka <stephane.prohaszka@ledger.fr>
lvndry
lvndry previously approved these changes May 17, 2024
Copy link
Contributor

@lambertkevin lambertkevin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, but a few questions because I might have missed some of the explanations for some logic in LLC πŸ‘

Comment on lines +39 to +137
return {
getAddress: async ({
path,
stakingPathString,
networkParams,
verify,
}: GetAddressRequest): Promise<CardanoAddress> => {
const network =
networkParams.networkId === Networks.Mainnet.networkId
? Networks.Mainnet
: Networks.Testnet;

const r = await ada.deriveAddress({
network,
address: {
type: AddressType.BASE_PAYMENT_KEY_STAKE_KEY,
params: {
spendingPath: str_to_path(path),
stakingPath: str_to_path(stakingPathString),
},
},
});
if (verify) {
await ada.showAddress({
network,
address: {
type: AddressType.BASE_PAYMENT_KEY_STAKE_KEY,
params: {
spendingPath: str_to_path(path),
stakingPath: str_to_path(stakingPathString),
},
},
});
}
const address = TyphonUtils.getAddressFromHex(r.addressHex) as TyphonAddress.BaseAddress;
return {
address: address.getBech32(),
// Here, we use publicKey hash, as cardano app doesn't export the public key
publicKey: address.paymentCredential.hash,
};
},
getPublicKey: async (accountPath: string): Promise<CardanoExtendedPublicKey> => {
return ada.getExtendedPublicKey({
path: str_to_path(accountPath),
});
},
sign: async ({
unsignedTransaction,
accountPubKey,
accountIndex,
networkParams,
}: CardanoSignRequest): Promise<CardanoSignature> => {
const rawInputs = unsignedTransaction.getInputs();
const ledgerAppInputs = rawInputs.map(i => prepareLedgerInput(i, accountIndex));

const rawOutptus = unsignedTransaction.getOutputs();
const ledgerAppOutputs = rawOutptus.map(o => prepareLedgerOutput(o, accountIndex));

const rawCertificates = unsignedTransaction.getCertificates();
const ledgerCertificates = rawCertificates.map(prepareCertificate);

const rawWithdrawals = unsignedTransaction.getWithdrawals();
const ledgerWithdrawals = rawWithdrawals.map(prepareWithdrawal);

const auxiliaryDataHashHex = unsignedTransaction.getAuxiliaryDataHashHex();

const network =
networkParams.networkId === Networks.Mainnet.networkId
? Networks.Mainnet
: Networks.Testnet;

const trxOptions: SignTransactionRequest = {
signingMode: TransactionSigningMode.ORDINARY_TRANSACTION,
tx: {
network,
inputs: ledgerAppInputs,
outputs: ledgerAppOutputs,
certificates: ledgerCertificates,
withdrawals: ledgerWithdrawals,
fee: unsignedTransaction.getFee().toString(),
ttl: unsignedTransaction.getTTL()?.toString(),
validityIntervalStart: null,
auxiliaryData: auxiliaryDataHashHex
? {
type: TxAuxiliaryDataType.ARBITRARY_HASH,
params: {
hashHex: auxiliaryDataHashHex,
},
}
: null,
},
additionalWitnessPaths: [],
};

const r = await ada.signTransaction(trxOptions);
return signTx(unsignedTransaction, accountPubKey, r.witnesses);
},
};
};
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Feels kinda wrong to have that much coin logic into LLC don't you think ? πŸ€”
Really feels like the coin-module would be unusable without LLC here 🫀

Comment on lines +1 to +3
export type { APIGetPoolsDetail, StakePool } from "@ledgerhq/coin-cardano/api/api-types";
export { fetchPoolDetails } from "@ledgerhq/coin-cardano/api/getPools";
export { LEDGER_POOL_IDS } from "@ledgerhq/coin-cardano/utils";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this necessary ? Can't UI specific to Cardano simply get the types from @ledgerhq/coin-cardano directly ? Or do you specifically want that to be an entrypoint for those types & constants ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same thing here I'm not quite sure to get why this should continue to live in LLC ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
common Has changes in live-common desktop Has changes in LLD ledgerjs Has changes in the ledgerjs open source libs mobile Has changes in LLM
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants