Skip to content
This repository has been archived by the owner on Jul 15, 2022. It is now read-only.

Cosmos JS #1897

Merged
348 commits merged into from
Apr 26, 2022
Merged
Show file tree
Hide file tree
Changes from 250 commits
Commits
Show all changes
348 commits
Select commit Hold shift + click to select a range
a2d9a58
trigger bot
gre Feb 22, 2022
98006c2
trigger bot
gre Feb 22, 2022
3b294b5
trigger bot
gre Feb 22, 2022
505da17
trigger bot
gre Feb 22, 2022
496cdbe
trigger bot
gre Feb 22, 2022
352e6a5
trigger bot
gre Feb 22, 2022
c28ed16
trigger bot
gre Feb 22, 2022
f44e63a
trigger bot
gre Feb 22, 2022
61bc734
trigger bot
gre Feb 22, 2022
512f45d
trigger bot
gre Feb 22, 2022
289ef6d
fix could not find optimisticOperation in redelegate transaction
alexalouit Feb 22, 2022
f096a2c
trigger bot
gre Feb 22, 2022
6121e72
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 22, 2022
31c1078
trigger bot
gre Feb 22, 2022
33fe422
Cosmos JS (#1730)
Feb 22, 2022
c113968
restore getStargateRewardsState methode
alexalouit Feb 22, 2022
6c72c62
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 22, 2022
9f1159b
Cosmos JS (#1731)
Feb 22, 2022
7a3a949
trigger bot
gre Feb 22, 2022
0c5a3fb
trigger bot
gre Feb 22, 2022
8278876
trigger bot
gre Feb 22, 2022
681efbb
trigger bot
gre Feb 22, 2022
1a405f2
trigger bot
gre Feb 22, 2022
f875c48
trigger bot
gre Feb 22, 2022
ede4bf4
trigger bot
gre Feb 22, 2022
390ba7b
trigger bot
gre Feb 22, 2022
e8a60e8
trigger bot
gre Feb 22, 2022
17fd5eb
trigger bot
gre Feb 22, 2022
8543228
trigger bot
gre Feb 22, 2022
0442088
trigger bot
gre Feb 22, 2022
0c6b768
trigger bot
gre Feb 22, 2022
2d5cdfb
trigger bot
gre Feb 22, 2022
28830bb
trigger bot
gre Feb 22, 2022
80b2512
trigger bot
gre Feb 22, 2022
263f623
trigger bot
gre Feb 22, 2022
0da65b0
trigger bot
gre Feb 22, 2022
5a7dbb6
trigger bot
gre Feb 22, 2022
872d071
trigger bot
gre Feb 22, 2022
9a22a2e
trigger bot
gre Feb 22, 2022
e4260b9
trigger bot
gre Feb 22, 2022
2aa60f6
trigger bot
gre Feb 22, 2022
dadae1b
trigger bot
gre Feb 22, 2022
652ad68
trigger bot
gre Feb 22, 2022
f24fc10
try to limit even more the cost of delegation
gre Feb 24, 2022
9432e49
lint
gre Feb 24, 2022
f8af6f6
Add files via upload
gre Feb 24, 2022
f5e8a23
Merge branch 'develop' into cosmos-js
gre Feb 24, 2022
c3e6853
amount of the operation more close
alexalouit Feb 25, 2022
6631073
return transaction in prepareTransaction
alexalouit Feb 25, 2022
f3e856c
prevent cosmos-js bot to do invalid scenarios of amount=0
gre Feb 25, 2022
a4b0c61
keep immutable paradigm for prepareTransaction
alexalouit Feb 25, 2022
5e0ac64
bot: do not limit a maxRun for 'send some'
gre Feb 25, 2022
b5e6e7f
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 25, 2022
07480af
Cosmos JS (#1743)
Feb 25, 2022
1808ef4
add .github/workflows/bot7-meredenis.yml
gre Feb 25, 2022
8780fb4
fix amount update in prepareTransaction
alexalouit Feb 25, 2022
e6637dd
fix amount control to be more specific
alexalouit Feb 25, 2022
c0b2f6b
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 25, 2022
774230a
fix BigNumber compare
alexalouit Feb 25, 2022
5d663f0
Cosmos JS (#1746)
Feb 25, 2022
8820ebf
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 25, 2022
8ee49ac
fix spendableBalance
alexalouit Feb 25, 2022
15b90bf
Cosmos JS (#1749)
Feb 25, 2022
33cefe8
separate postBuildTransaction logic + fix use useAllAmount
alexalouit Feb 25, 2022
7e2f220
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 25, 2022
fed024c
Cosmos JS (#1751)
Feb 26, 2022
d6affa8
bot: lower claim reward at 1000
gre Feb 28, 2022
ba3e2ba
Merge branch 'develop' into cosmos-js
gre Feb 28, 2022
904f65d
bot: lower the # of // delegations for cosmos
gre Feb 28, 2022
46a6eb3
trigger bot
gre Feb 28, 2022
8a8dd43
trigger bot
gre Feb 28, 2022
db3c475
trigger bot
gre Feb 28, 2022
ba4efc4
trigger bot
gre Feb 28, 2022
9e11ca3
trigger bot
gre Feb 28, 2022
8f9ad6d
bot: fixes 0 atom undelegate
gre Feb 28, 2022
c33df5a
trigger bot
gre Feb 28, 2022
d816e8c
v21.33.1-cosmos.0
gre Feb 28, 2022
2ba3aa1
trigger bot
gre Feb 28, 2022
83ca8bd
trigger bot
gre Feb 28, 2022
75b3141
update cosmos specs for claim rewards
gre Feb 28, 2022
159333b
trigger bot
gre Feb 28, 2022
b93329a
trigger bot
gre Feb 28, 2022
7e61acb
trigger bot
gre Feb 28, 2022
ab7277f
trigger bot
gre Feb 28, 2022
78e56b1
trigger bot
gre Feb 28, 2022
4ed4004
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Feb 28, 2022
0b0294c
fix rewards
alexalouit Feb 28, 2022
1a193ab
trigger bot
gre Feb 28, 2022
c031ec2
Cosmos JS (#1761)
Feb 28, 2022
6b3d689
trigger bot
gre Feb 28, 2022
3b7778b
trigger bot
gre Feb 28, 2022
c21b670
trigger bot
gre Feb 28, 2022
a5da16d
trigger bot
gre Feb 28, 2022
4ec75c0
trigger bot
gre Feb 28, 2022
447c6db
trigger bot
gre Feb 28, 2022
6a69a58
fix unbondings
alexalouit Feb 28, 2022
df78494
fix fees calculation and add cache usage
alexalouit Feb 28, 2022
5978c5a
Merge pull request #1763 from wa-aal/cosmos-js
gre Mar 1, 2022
0314f33
trigger bot
gre Mar 1, 2022
3a053f4
v21.33.1-cosmos.1
gre Mar 1, 2022
b1454cf
v21.33.1-cosmos.2
gre Mar 1, 2022
756d11a
trigger bot
gre Mar 1, 2022
28dd054
trigger bot
gre Mar 1, 2022
377f352
trigger bot
gre Mar 1, 2022
dad80e3
trigger bot
gre Mar 1, 2022
cddb0e3
cosmos bot: lower the amount for general tx & lower part alloc in del…
gre Mar 1, 2022
1a801b9
ensure for all cosmos mutation that only one op results of a tx
gre Mar 7, 2022
f155a8c
be more conform between optimistic and final operation
alexalouit Mar 8, 2022
5cd89e6
be more conform between optimistic and final operation (#1786)
Mar 9, 2022
c150236
Filecoin fixes (#1740)
emmanuelm41 Mar 1, 2022
a4ed4c3
Create dependencies.md
gre Mar 1, 2022
38999d7
Add env var to enable learn staging URL
ofreyssinet-ledger Feb 24, 2022
b7f1cce
lint
ofreyssinet-ledger Mar 1, 2022
7629615
Bump urijs from 1.19.8 to 1.19.9 (#1774)
dependabot[bot] Mar 4, 2022
736e9f6
Bump urijs from 1.19.8 to 1.19.9 in /tools (#1776)
dependabot[bot] Mar 4, 2022
026fdb9
Bump urijs from 1.19.8 to 1.19.9 in /cli (#1775)
dependabot[bot] Mar 4, 2022
29594de
Bump urijs from 1.19.8 to 1.19.9 in /mobile-test-app (#1773)
dependabot[bot] Mar 4, 2022
c35a42b
Bump plist from 3.0.1 to 3.0.4 in /mobile-test-app (#1767)
dependabot[bot] Mar 4, 2022
7bc65ef
disable a failing test of countervalues (#1778)
gre Mar 4, 2022
abed37b
re-enable countervalues test (#1779)
gre Mar 4, 2022
4da2feb
fix device actions used by bot and add new test case (#1784)
emmanuelm41 Mar 7, 2022
3045eea
Fixes for XTZ JS (still under experimental, no impact)
gre Mar 8, 2022
90ec482
Update Ethereum related libraries (#1780)
gre Mar 8, 2022
ab15f17
bitcoin bot to slack on ll-bitcoin-ci
gre Mar 8, 2022
819c7ae
v21.34.0-cosmos.0
hakim-adamik Mar 9, 2022
24fa16d
use old code logic
alexalouit Mar 9, 2022
9c4dee1
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
f563ebf
Cosmos JS (#1791)
Mar 9, 2022
3b0a03c
fix senders/recipients regression
alexalouit Mar 9, 2022
d68156c
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
a17b5db
Cosmos JS (#1793)
Mar 9, 2022
69d62dd
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
86f5367
fix duplicate data
alexalouit Mar 9, 2022
172632f
Cosmos JS (#1794)
Mar 9, 2022
85dddb6
fix duplicate data (again)
alexalouit Mar 9, 2022
c92c461
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
316a40f
Cosmos JS (#1795)
Mar 9, 2022
2480c1a
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 9, 2022
565e8be
append block height
alexalouit Mar 9, 2022
4ef5904
Cosmos JS (#1796)
Mar 9, 2022
f9bd610
trigger bot
hakim-adamik Mar 9, 2022
d154b69
Cosmos-JS - Fix random balance changes (#1797)
Mar 10, 2022
26b2155
trigger bot
gre Mar 10, 2022
57e3763
Fix setting of experimental JS currencies
hakim-adamik Mar 10, 2022
4211fb5
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 10, 2022
489cdd8
fix specific empty amount case in reward transaction
alexalouit Mar 10, 2022
e3a5963
Cosmos JS (#1799)
Mar 10, 2022
9ebefaf
Merge remote-tracking branch 'ledgerhq/develop' into HEAD
hakim-adamik Mar 10, 2022
a9a3a42
Merge branch 'develop' into cosmos-js
gre Mar 10, 2022
5a6b0c6
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 10, 2022
b93e846
temporary debug operation broadcasted
alexalouit Mar 10, 2022
6379b0a
use toOperationRaw method
alexalouit Mar 11, 2022
f05abf7
return patchedOperation
alexalouit Mar 11, 2022
83e1a98
Cosmos JS (#1800)
Mar 11, 2022
8bda82c
restore broadcast operation
alexalouit Mar 11, 2022
607f359
Update js-synchronisation.ts
alexalouit Mar 11, 2022
eb7198f
remove block height support
alexalouit Mar 11, 2022
ecf61d5
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 11, 2022
beac78d
Cosmos JS (#1801)
Mar 11, 2022
0b7254c
Merge branch 'develop' into cosmos-js
gre Mar 11, 2022
5f1c706
v21.34.1-cosmos.3
gre Mar 11, 2022
44cd92f
Revert "remove block height support"
alexalouit Mar 11, 2022
028fb78
log allOperationsMatchingId
gre Mar 11, 2022
bfdc5f4
lint
gre Mar 11, 2022
195983a
augment the nb of cosmos accounts
gre Mar 11, 2022
e21e6bd
trigger bot
gre Mar 11, 2022
c8eccf6
trigger bot
gre Mar 11, 2022
f7ed28e
trigger bot
gre Mar 11, 2022
2304732
trigger bot
gre Mar 11, 2022
00e3289
enable crypto_org to run tests
gre Mar 11, 2022
7a7f6fa
More strict type
alexalouit Mar 11, 2022
8c2dcab
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 11, 2022
78097b8
reverse order of validators
alexalouit Mar 11, 2022
9bb1042
Cosmos JS (#1803)
Mar 11, 2022
8a34cc7
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 11, 2022
8f2ceb4
fix validators type in createTransmission
alexalouit Mar 11, 2022
e1cf2f0
add sequence to ops
alexalouit Mar 11, 2022
a7a2972
strict output getAccount type
alexalouit Mar 11, 2022
7b7ffe1
fix operations sequence
alexalouit Mar 11, 2022
1f91005
Cosmos JS (#1804)
Mar 14, 2022
b0e55cd
Add a workaround that prevent 2 last operations to be same id (#1807)
gre Mar 14, 2022
25a30c4
Fixes deduplication logic of mergeOps
gre Mar 14, 2022
c0351fc
Merge branch 'fix-jshelpers-mergeops-dedup-logic' into cosmos-js
gre Mar 14, 2022
7f0061f
Revert "Add a workaround that prevent 2 last operations to be same id…
gre Mar 14, 2022
e60e65b
Merge remote-tracking branch 'upstream/cosmos-js' into cosmos-js
alexalouit Mar 14, 2022
3560296
fix multiple tx messages
alexalouit Mar 14, 2022
83071ab
Remove all libcore codebase
gre Mar 24, 2022
d102c5f
remove calculateFees libcore logic
alexalouit Mar 24, 2022
add2667
trigger some bot (commit to revert before merging this PR)
gre Mar 24, 2022
347e99a
lint
gre Mar 24, 2022
88a6aa1
remove useless cli test run
gre Mar 24, 2022
082c946
fix type issue
gre Mar 24, 2022
d0ab432
cli update
gre Mar 24, 2022
fa9407f
Revert "trigger some bot (commit to revert before merging this PR)"
gre Mar 24, 2022
430bdfb
update cli/README
gre Mar 24, 2022
111e9da
don't use round ceil
alexalouit Mar 24, 2022
2e5af7f
add comment note
alexalouit Mar 24, 2022
0f5352d
Merge remote-tracking branch 'upstream/sunset-libcore' into cosmos-js
alexalouit Mar 24, 2022
11e872b
sync with upstream
alexalouit Mar 24, 2022
da2eec3
Merge branch 'develop' into sunset-libcore
gre Mar 25, 2022
676aff6
fix merge
gre Mar 25, 2022
640f015
Cosmos js (#1832)
Mar 25, 2022
c0fab4e
Modularize the all.libcore.tests (#1834)
gre Mar 25, 2022
c0e9695
LL-1589 more robust bitcoin retry (#1835)
hzheng-ledger Mar 29, 2022
34d2793
Additional cleanup on bitcoin implem
hakim-adamik Mar 30, 2022
3bac381
fix mixed transaction sync
alexalouit Apr 1, 2022
c3635b2
fix balance
alexalouit Apr 1, 2022
f860d20
Merge remote-tracking branch 'upstream/sunset-libcore' into cosmos-js
alexalouit Apr 1, 2022
77086fd
Set bot on family/cosmos branch
hakim-adamik Apr 1, 2022
7bfca02
Merge remote-tracking branch 'upstream/family/cosmos' into cosmos-js
alexalouit Apr 1, 2022
3d69586
Merge branch 'release/v21.36.0' into develop
valpinkman Apr 4, 2022
c171d0b
fix bch address convert issue (#1847)
hzheng-ledger Apr 5, 2022
c2256fe
Hotfix - v21.36.1 on Develop (#1860)
lambertkevin Apr 6, 2022
7e6888e
Remove all libcore codebase (#1831)
gre Apr 5, 2022
324ee63
Add ETH goerli (#1841)
hzheng-ledger Apr 5, 2022
e22739e
Cosmos fixes (#1846)
Apr 5, 2022
25bc993
Family/crypto org (#1852)
Apr 5, 2022
cee4a00
[LIVE-1174] - Feature: Upgrade NFT Architecture (#1805)
lambertkevin Apr 5, 2022
f42af0b
Add polygon to NFT currencies (#1848)
lambertkevin Apr 5, 2022
196130a
[LIVE-1909] - Bugfix: OpenSea Lazy mint quantity fix (#1862)
lambertkevin Apr 6, 2022
84a21df
Reset CLI LLC dep
lambertkevin Apr 5, 2022
7ef865d
LIVE-1890 Replace all deprecated uses of open(deviceId) with withDevi…
Apr 7, 2022
e3f33a8
Merge remote-tracking branch 'upstream/develop' into cosmos-js
alexalouit Apr 7, 2022
2ea9121
Fix nft operations wrong order to infer balance (#1865)
lambertkevin Apr 7, 2022
8eeb10d
Replace all deprecated uses of open(deviceId) with withDevice (#1864)
Apr 7, 2022
20b56c4
[LIVE-1911][LIVE-1912] Feature - Add collection name resolver to eth …
lambertkevin Apr 7, 2022
83286af
Bump plist from 3.0.4 to 3.0.5 in /mobile-test-app (#1849)
dependabot[bot] Apr 7, 2022
f34367d
Bump cocoapods-downloader from 1.3.0 to 1.6.3 in /mobile-test-app (#1…
dependabot[bot] Apr 7, 2022
e842162
Bump ansi-regex from 3.0.0 to 3.0.1 (#1850)
dependabot[bot] Apr 7, 2022
80d7186
Solana staking (#1844)
Apr 7, 2022
0ed12b7
v22.0.0
lambertkevin Apr 5, 2022
78650fe
Merge pull request #1853 from LedgerHQ/release/v22.0.0
lambertkevin Apr 7, 2022
1e72d95
Merge remote-tracking branch 'origin/release/v22.0.0'
lambertkevin Apr 7, 2022
347a38f
(Solana): fix missing superstruct dependency -> making app crashes
LFBarreto Apr 8, 2022
6d8d927
v21.36.2
LFBarreto Apr 8, 2022
5f74138
Revert "Merge remote-tracking branch 'origin/release/v22.0.0'"
lambertkevin Apr 8, 2022
ddd623e
Revert "Merge pull request #1853 from LedgerHQ/release/v22.0.0"
lambertkevin Apr 8, 2022
66d37c8
Merge branch 'develop' into hotfix/v21.36.2
lambertkevin Apr 8, 2022
adff6b7
Merge pull request #1868 from LedgerHQ/hotfix/v21.36.2
lambertkevin Apr 8, 2022
7245f68
(Solana): fix missing superstruct dependency -> making app crashes
LFBarreto Apr 8, 2022
988a8ff
v21.36.2
LFBarreto Apr 8, 2022
9948fc3
Merge remote-tracking branch 'origin/hotfix/v21.36.2'
lambertkevin Apr 8, 2022
0bde0b7
Update Cosmos dataset snapshot to fix test (#1861)
henri-ly Apr 8, 2022
c91c3fa
Merge remote-tracking branch 'upstream/develop' into cosmos-js
alexalouit Apr 8, 2022
0a98a52
Merge remote-tracking branch 'upstream/master' into cosmos-js
alexalouit Apr 11, 2022
24ce1e7
move from cosmjs/ledger-amino to ledgerhq/hw-app-cosmos
alexalouit Apr 11, 2022
53cfe66
fix message and signature
alexalouit Apr 14, 2022
879cde2
Merge remote-tracking branch 'upstream/family/cosmos' into cosmos-js
alexalouit Apr 15, 2022
828fec7
fix derivation path
alexalouit Apr 19, 2022
2ac1e6a
remove cosmjs/ledger-amino package
alexalouit Apr 22, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/families/cosmos/js-prepareTransaction.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { Account } from "../../types";
import { Transaction } from "./types";
import BigNumber from "bignumber.js";
import { simulate } from "./api/Cosmos";
import { encodePubkey } from "@cosmjs/proto-signing";
import { getEnv } from "../../env";
import { buildTransaction, postBuildTransaction } from "./js-buildTransaction";
import { getMaxEstimatedBalance } from "./logic";
Expand Down Expand Up @@ -50,10 +49,13 @@ const getEstimatedFees = async (

// be sure payload is complete
if (unsignedPayload) {
const pubkey = encodePubkey({
type: "tendermint/PubKeySecp256k1",
value: Buffer.from(account.seedIdentifier, "hex").toString("base64"),
});
const pubkey = {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: new Uint8Array([
...new Uint8Array([10, 33]),
...new Uint8Array(Buffer.from(account.seedIdentifier, "hex")),
]),
};

const tx_bytes = await postBuildTransaction(
account,
Expand Down
91 changes: 55 additions & 36 deletions src/families/cosmos/js-signOperation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ import type { Transaction } from "./types";
import { getAccount, getChainId } from "./api/Cosmos";
import { Observable } from "rxjs";
import { withDevice } from "../../hw/deviceAccess";
import { encodePubkey } from "@cosmjs/proto-signing";
import { encodeOperationId } from "../../operation";
import { LedgerSigner } from "@cosmjs/ledger-amino";
import Cosmos from "@ledgerhq/hw-app-cosmos";
import { AminoTypes } from "@cosmjs/stargate";
import { stringToPath } from "@cosmjs/crypto";
import { buildTransaction, postBuildTransaction } from "./js-buildTransaction";
import BigNumber from "bignumber.js";
import { Secp256k1Signature } from "@cosmjs/crypto";

const aminoTypes = new AminoTypes({ prefix: "cosmos" });

Expand All @@ -32,52 +31,40 @@ const signOperation = ({
let cancelled;

async function main() {
const hwApp = new Cosmos(transport);

const { accountNumber, sequence } = await getAccount(
account.freshAddress
);

const chainId = await getChainId();

const hdPaths: any = stringToPath("m/" + account.freshAddressPath);

const ledgerSigner = new LedgerSigner(transport, {
hdPaths: [hdPaths],
});

o.next({ type: "device-signature-requested" });

const accounts = await ledgerSigner.getAccounts();

let pubkey;
const { publicKey } = await hwApp.getAddress(
// is valid?
account.freshAddresses[0].derivationPath,
alexalouit marked this conversation as resolved.
Show resolved Hide resolved
"cosmos",
false
);

accounts.forEach((a) => {
if (a.address == account.freshAddress) {
pubkey = encodePubkey({
type: "tendermint/PubKeySecp256k1",
value: Buffer.from(a.pubkey).toString("base64"),
});
}
});
const pubkey = {
typeUrl: "/cosmos.crypto.secp256k1.PubKey",
value: new Uint8Array([
...new Uint8Array([10, 33]),
...new Uint8Array(Buffer.from(publicKey, "hex")),
]),
};

const unsignedPayload = await buildTransaction(account, transaction);

const msgs = unsignedPayload.map((msg) => aminoTypes.toAmino(msg));

// Note:
// We don't use Cosmos App,
// Cosmos App support legacy StdTx and required to be ordered in a strict way,
// Cosmos API expects a different sorting, resulting in a separate signature.
// https://github.com/LedgerHQ/app-cosmos/blob/6c194daa28936e273f9548eabca9e72ba04bb632/app/src/tx_parser.c#L52

// Cosmos App sign data in Amino way only, not Protobuf.
// Cosmos Nano App sign data in Amino way only, not Protobuf.
// This is a legacy outdated standard and a long-term blocking point.

// @ledgerhq/hw-app-cosmos don't allow to push message to device message converted
// by the AminoConverter from @cosmjs/stargate. There's two things who don't work:
// 1st, the way who message is sorted.
// 2nd, cast of numeric value (integer/numeric versus string).

const signed = await ledgerSigner.signAmino(account.freshAddress, {
const message = {
chain_id: chainId,
account_number: accountNumber.toString(),
sequence: sequence.toString(),
Expand All @@ -92,17 +79,30 @@ const signOperation = ({
},
msgs: msgs,
memo: transaction.memo || "",
});
};

const { signature } = await hwApp.sign(
account.freshAddressPath,
JSON.stringify(sortedObject(message))
);

if (!signature) {
throw new Error("Cosmos: no Signature Found");
}

const secp256k1Signature = Secp256k1Signature.fromDer(
new Uint8Array(signature)
).toFixedLength();

const tx_bytes = await postBuildTransaction(
account,
transaction,
pubkey,
unsignedPayload,
new Uint8Array(Buffer.from(signed.signature.signature, "base64"))
secp256k1Signature
);

const signature = Buffer.from(tx_bytes).toString("hex");
const signed = Buffer.from(tx_bytes).toString("hex");

if (cancelled) {
return;
Expand Down Expand Up @@ -169,7 +169,7 @@ const signOperation = ({
type: "signed",
signedOperation: {
operation,
signature,
signature: signed,
expirationDate: null,
},
});
Expand All @@ -186,4 +186,23 @@ const signOperation = ({
})
);

const sortedObject = (obj) => {
if (typeof obj !== "object" || obj === null) {
return obj;
}

if (Array.isArray(obj)) {
return obj.map(sortedObject);
}

const sortedKeys = Object.keys(obj).sort();
const result = {};

sortedKeys.forEach((key) => {
result[key] = sortedObject(obj[key]);
});

return result;
};

export default signOperation;