Skip to content

Commit

Permalink
fix(wallet/ui): amino encoding details (for Ledger)
Browse files Browse the repository at this point in the history
  • Loading branch information
dckc committed Oct 4, 2022
1 parent d4d6842 commit 72fc1f6
Showing 1 changed file with 38 additions and 12 deletions.
50 changes: 38 additions & 12 deletions packages/wallet/ui/src/util/keyManagement.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,20 +79,21 @@ const CosmosMessages = /** @type {const} */ ({
});

/**
* `/agoric.swingset.XXX` matches package agoric.swingset in swingset/msgs.go
* `/agoric.swingset.XXX` matches package agoric.swingset in swingset/msgs.proto
* aminoType taken from Type() in golang/cosmos/x/swingset/types/msgs.go
*/
export const SwingsetMsgs = /** @type {const} */ ({
MsgProvision: {
typeUrl: '/agoric.swingset.MsgProvision',
aminoType: 'swingset/MsgProvision',
aminoType: 'swingset/Provision',
},
MsgWalletAction: {
typeUrl: '/agoric.swingset.MsgWalletAction',
aminoType: 'swingset/WalletAction',
},
MsgWalletSpendAction: {
typeUrl: '/agoric.swingset.MsgWalletSpendAction',
aminoType: 'swingset/WalletAction',
aminoType: 'swingset/WalletSpendAction',
},
});

Expand Down Expand Up @@ -138,18 +139,43 @@ export const zeroFee = () => {
return fee;
};

const dbg = label => x => {
console.log(label, x);
return x;
};

/** @type {import('@cosmjs/stargate').AminoConverters} */
const SwingsetConverters = {
[SwingsetMsgs.MsgProvision.typeUrl]: {
aminoType: SwingsetMsgs.MsgProvision.aminoType,
toAmino: ({ action, owner }) => ({
action,
owner: toBech32(bech32Config.bech32PrefixAccAddr, fromBase64(owner)),
}),
fromAmino: ({ action, owner }) => ({
action,
owner: toBase64(toAccAddress(owner)),
}),
toAmino: protoVal => {
const { nickname, address, powerFlags, submitter } = dbg(
'provision toAmino protoVal',
)(protoVal);
return {
address: toBech32(
bech32Config.bech32PrefixAccAddr,
fromBase64(address),
),
nickname,
powerFlags,
submitter: toBech32(
bech32Config.bech32PrefixAccAddr,
fromBase64(submitter),
),
};
},
fromAmino: aminoVal => {
const { nickname, address, powerFlags, submitter } = dbg(
'provision fromAmino aminoVal',
)(aminoVal);
return {
address: toBase64(toAccAddress(address)),
nickname,
powerFlags,
submitter: toBase64(toAccAddress(submitter)),
};
},
},
[SwingsetMsgs.MsgWalletAction.typeUrl]: {
aminoType: SwingsetMsgs.MsgWalletAction.aminoType,
Expand All @@ -163,7 +189,7 @@ const SwingsetConverters = {
}),
},
[SwingsetMsgs.MsgWalletSpendAction.typeUrl]: {
aminoType: SwingsetMsgs.MsgWalletAction.aminoType,
aminoType: SwingsetMsgs.MsgWalletSpendAction.aminoType,
toAmino: ({ spendAction, owner }) => ({
spendAction,
owner: toBech32(bech32Config.bech32PrefixAccAddr, fromBase64(owner)),
Expand Down

0 comments on commit 72fc1f6

Please sign in to comment.