Skip to content

Commit

Permalink
Port ledger hotfix (#1864)
Browse files Browse the repository at this point in the history
  • Loading branch information
SebastienGllmt committed Jan 9, 2021
1 parent c86edfe commit a570650
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 40 deletions.
11 changes: 7 additions & 4 deletions app/api/ada/transactions/shelley/ledgerTx.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import type {
Address, Value, Addressing,
} from '../../lib/storage/models/PublicDeriver/interfaces';
import { HaskellShelleyTxSignRequest } from './HaskellShelleyTxSignRequest';
import { AddressTypeNibbles, CertTypes } from '@cardano-foundation/ledgerjs-hw-app-cardano';
import { AddressTypeNibbles, CertificateTypes } from '@cardano-foundation/ledgerjs-hw-app-cardano';
import { RustModule } from '../../lib/cardanoCrypto/rustLoader';
import { toHexOrBase58 } from '../../lib/storage/bridge/utils';
import {
Expand Down Expand Up @@ -192,27 +192,30 @@ function formatLedgerCertificates(
const registrationCert = cert.as_stake_registration();
if (registrationCert != null) {
result.push({
type: CertTypes.staking_key_registration,
type: CertificateTypes.STAKE_REGISTRATION,
path: getPath(registrationCert.stake_credential()),
poolKeyHashHex: undefined,
poolRegistrationParams: undefined,
});
continue;
}
const deregistrationCert = cert.as_stake_deregistration();
if (deregistrationCert != null) {
result.push({
type: CertTypes.staking_key_deregistration,
type: CertificateTypes.STAKE_DEREGISTRATION,
path: getPath(deregistrationCert.stake_credential()),
poolKeyHashHex: undefined,
poolRegistrationParams: undefined,
});
continue;
}
const delegationCert = cert.as_stake_delegation();
if (delegationCert != null) {
result.push({
type: CertTypes.delegation,
type: CertificateTypes.STAKE_DELEGATION,
path: getPath(delegationCert.stake_credential()),
poolKeyHashHex: Buffer.from(delegationCert.pool_keyhash().to_bytes()).toString('hex'),
poolRegistrationParams: undefined,
});
continue;
}
Expand Down
5 changes: 3 additions & 2 deletions app/api/ada/transactions/shelley/ledgerTx.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import {
normalizeToAddress,
} from '../../lib/storage/bridge/utils';
import { HaskellShelleyTxSignRequest } from './HaskellShelleyTxSignRequest';
import { AddressTypeNibbles, CertTypes } from '@cardano-foundation/ledgerjs-hw-app-cardano';
import { AddressTypeNibbles, CertificateTypes } from '@cardano-foundation/ledgerjs-hw-app-cardano';
import { networks } from '../../lib/storage/database/prepackaged/networks';
import { HARD_DERIVATION_START, WalletTypePurpose, CoinTypes, ChainDerivations } from '../../../../config/numbersConfig';

Expand Down Expand Up @@ -418,7 +418,8 @@ test('Create Ledger transaction', async () => {
0,
],
poolKeyHashHex: undefined,
type: CertTypes.staking_key_registration,
poolRegistrationParams: undefined,
type: CertificateTypes.STAKE_REGISTRATION,
}],
metadataHashHex: undefined,
});
Expand Down
12 changes: 7 additions & 5 deletions features/mock-ledger-connect/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '../../app/api/ada/lib/cardanoCrypto/cryptoWallet';
import { testWallets } from '../mock-chain/TestWallets';
import { IncorrectDeviceError } from '../../app/domain/ExternalDeviceCommon';
import { AddressTypeNibbles, CertTypes } from '@cardano-foundation/ledgerjs-hw-app-cardano';
import { AddressTypeNibbles, CertificateTypes } from '@cardano-foundation/ledgerjs-hw-app-cardano';

type WalletInfo = {|
rootKey: RustModule.WalletV4.Bip32PrivateKey;
Expand Down Expand Up @@ -214,10 +214,12 @@ class MockLedgerConnect {
input.outputIndex
)
);
if (input.path == null) throw new Error(`${nameof(MockLedgerConnect)} no path for input`);
const { path } = input;
const spendingKey = derivePath(selectedWallet.rootKey, input.path);
keys.push({
witGen: (hash) => spendingKey.to_raw_key().sign(hash.to_bytes()),
path: input.path,
path,
});
}
const outputs = RustModule.WalletV4.TransactionOutputs.new();
Expand Down Expand Up @@ -260,12 +262,12 @@ class MockLedgerConnect {
const stakeCredential = RustModule.WalletV4.StakeCredential.from_keyhash(
stakingKey.to_public().hash()
);
if (cert.type === CertTypes.staking_key_registration) {
if (cert.type === CertificateTypes.STAKE_REGISTRATION) {
certs.add(RustModule.WalletV4.Certificate.new_stake_registration(
RustModule.WalletV4.StakeRegistration.new(stakeCredential)
));
}
if (cert.type === CertTypes.staking_key_deregistration) {
if (cert.type === CertificateTypes.STAKE_DEREGISTRATION) {
keys.push({
witGen: (hash) => stakingKey.sign(hash.to_bytes()),
path: cert.path
Expand All @@ -274,7 +276,7 @@ class MockLedgerConnect {
RustModule.WalletV4.StakeDeregistration.new(stakeCredential)
));
}
if (cert.type === CertTypes.delegation) {
if (cert.type === CertificateTypes.STAKE_DELEGATION) {
keys.push({
witGen: (hash) => stakingKey.sign(hash.to_bytes()),
path: cert.path
Expand Down
54 changes: 27 additions & 27 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -154,12 +154,12 @@
"ws": "7.4.2"
},
"dependencies": {
"@cardano-foundation/ledgerjs-hw-app-cardano": "2.0.1",
"@cardano-foundation/ledgerjs-hw-app-cardano": "2.1.0",
"@download/blockies": "1.0.3",
"@emurgo/cardano-serialization-lib-browser": "4.2.0",
"@emurgo/cip4-js": "1.0.5",
"@emurgo/js-chain-libs": "0.7.1",
"@emurgo/ledger-connect-handler": "3.0.1",
"@emurgo/ledger-connect-handler": "3.0.2",
"@svgr/webpack": "5.5.0",
"axios": "0.21.1",
"bech32": "1.1.4",
Expand Down

0 comments on commit a570650

Please sign in to comment.