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

Merged
merged 10 commits into from
May 24, 2024
Merged

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)
web-tools ❌ Failed (Inspect) May 23, 2024 8:26pm
4 Ignored Deployments
Name Status Preview Comments Updated (UTC)
ledger-live-docs ⬜️ Ignored (Inspect) Visit Preview May 23, 2024 8:26pm
ledger-live-github-bot ⬜️ Ignored (Inspect) Visit Preview May 23, 2024 8:26pm
native-ui-storybook ⬜️ Ignored (Inspect) Visit Preview May 23, 2024 8:26pm
react-ui-storybook ⬜️ Ignored (Inspect) Visit Preview May 23, 2024 8:26pm

@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↗︎

libs/coin-modules/coin-cardano/src/bridge/js.ts Outdated Show resolved Hide resolved
libs/coin-modules/coin-cardano/src/js-signOperation.ts Outdated Show resolved Hide resolved
libs/coin-modules/coin-cardano/src/logic.ts Outdated Show resolved Hide resolved
libs/coin-modules/coin-cardano/src/logic.ts Show resolved Hide resolved
libs/coin-modules/coin-cardano/src/types.ts Outdated Show resolved Hide resolved
libs/ledger-live-common/src/generated/types.ts Outdated Show resolved Hide resolved
lvndry
lvndry previously approved these changes May 17, 2024
lambertkevin
lambertkevin 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 116
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 🫤

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I know, but what is bothering me is that all this logic is relying on @cardano-foundation/ledgerjs-hw-app-cardano, which relies itself on @ledgerhq/hw-transport (forbidden to use in CoinModule).

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 Author

Choose a reason for hiding this comment

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

I prefer to separate UI from CoinModules direct use. This is why I keep in LLC some entrypoint to access the coin-modules.
Ideally, the logic required by the UI should be LLC. The UI shouldn't have any clue about what the meaning of what it displays.

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 ?

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>
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>
* Sign Transaction with Ledger hardware
*/
const buildSignOperation =
(signerContext: SignerContext<CardanoSigner>): SignOperationFnSignature<Transaction> =>
Copy link
Contributor

Choose a reason for hiding this comment

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

Just a note but we could also type SignOperationFnSignature<CardanoAccount, Transaction>

@sprohaszka-ledger sprohaszka-ledger merged commit cec1599 into develop May 24, 2024
57 of 58 checks passed
@sprohaszka-ledger sprohaszka-ledger deleted the feat/LIVE-8166-cardano branch May 24, 2024 16:16
lvndry pushed a commit that referenced this pull request May 27, 2024
* chore: define cardano in its own module

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

* fix: lint

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

* chore: update unimported

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

* chore: feedbacks

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

* fix: remove unnecessary test in favor of relying on type

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

* fix: lint issue

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

* feat: limit code in LLC by adding simpler serialiazer for signer

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

* chore: simplify signOperation readability

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

* chore: reorganize imports

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

* fix: unimported and lock file

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>

---------

Signed-off-by: Stéphane Prohaszka <stephane.prohaszka@ledger.fr>
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