Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion apps/extension/src/Approvals/ApproveTx/ConfirmLedgerTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ export const ConfirmLedgerTx: React.FC<Props> = ({ details }) => {
const txArgs: TxProps = {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(0),
gasLimit: new BigNumber(20_000),
chainId,
publicKey,
};
Expand Down
15 changes: 0 additions & 15 deletions apps/extension/src/background/keyring/handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import {
} from "./messages";
import {
ConnectInterfaceMsg,
EncodeInitAccountMsg,
QueryAccountsMsg,
QueryBalancesMsg,
FetchAndStoreMaspParamsMsg,
Expand Down Expand Up @@ -83,11 +82,6 @@ export const getHandler: (service: KeyRingService) => Handler = (service) => {
env,
msg as QueryParentAccountsMsg
);
case EncodeInitAccountMsg:
return handleEncodeInitAccountMsg(service)(
env,
msg as EncodeInitAccountMsg
);
case CloseOffscreenDocumentMsg:
return handleCloseOffscreenDocumentMsg(service)(
env,
Expand Down Expand Up @@ -243,15 +237,6 @@ const handleQueryParentAccountsMsg: (
};
};

const handleEncodeInitAccountMsg: (
service: KeyRingService
) => InternalHandler<EncodeInitAccountMsg> = (service) => {
return (_, msg) => {
const { address, txMsg } = msg;
return service.encodeInitAccount(txMsg, address);
};
};

const handleSetActiveAccountMsg: (
service: KeyRingService
) => InternalHandler<SetActiveAccountMsg> = (service) => {
Expand Down
2 changes: 0 additions & 2 deletions apps/extension/src/background/keyring/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ import {
} from "./messages";
import {
ConnectInterfaceMsg,
EncodeInitAccountMsg,
QueryAccountsMsg,
QueryBalancesMsg,
FetchAndStoreMaspParamsMsg,
Expand All @@ -37,7 +36,6 @@ export function init(router: Router, service: KeyRingService): void {
router.registerMessage(CloseOffscreenDocumentMsg);
router.registerMessage(ConnectInterfaceMsg);
router.registerMessage(DeriveAccountMsg);
router.registerMessage(EncodeInitAccountMsg);
router.registerMessage(GenerateMnemonicMsg);
router.registerMessage(GetActiveAccountMsg);
router.registerMessage(LockKeyRingMsg);
Expand Down
29 changes: 0 additions & 29 deletions apps/extension/src/background/keyring/keyring.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import {
VecU8Pointer,
} from "@namada/crypto";
import {
Account,
Address,
ExtendedSpendingKey,
ExtendedViewingKey,
Expand Down Expand Up @@ -596,34 +595,6 @@ export class KeyRing {
return getAccountValuesFromStore(accounts);
}

async encodeInitAccount(
address: string,
txMsg: Uint8Array
): Promise<Uint8Array> {
if (!this._password) {
throw new Error("Not authenticated!");
}
const account = await this._keyStore.getRecord("address", address);
if (!account) {
throw new Error(`Account not found for ${address}`);
}

let pk: string;

try {
pk = crypto.decrypt(account.crypto, this._password, this._cryptoMemory);
} catch (e) {
throw new Error(`Could not unlock account for ${address}: ${e}`);
}

try {
const { tx_data } = new Account(txMsg, pk).to_serialized();
return tx_data;
} catch (e) {
throw new Error(`Could not encode InitAccount for ${address}: ${e}`);
}
}

async submitBond(txMsg: Uint8Array): Promise<void> {
if (!this._password) {
throw new Error("Not authenticated!");
Expand Down
15 changes: 1 addition & 14 deletions apps/extension/src/background/keyring/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { fromBase64, toBase64 } from "@cosmjs/encoding";
import { fromBase64 } from "@cosmjs/encoding";

import { PhraseSize } from "@namada/crypto";
import { KVStore, Store } from "@namada/storage";
Expand Down Expand Up @@ -323,19 +323,6 @@ export class KeyRingService {
}
}

/**
* Creating an InitAccount for Namada requires a secret,
* therefore, we need to query the private key for this account from
* storage
*/
async encodeInitAccount(txMsg: string, address: string): Promise<string> {
const tx_data = await this._keyRing.encodeInitAccount(
address,
fromBase64(txMsg)
);
return toBase64(tx_data);
}

async setActiveAccount(id: string, type: ParentAccount): Promise<void> {
await this._keyRing.setActiveAccount(id, type);
this.broadcaster.updateAccounts();
Expand Down
20 changes: 18 additions & 2 deletions apps/extension/src/background/ledger/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,14 +57,22 @@ export class LedgerService {
TxMsgValue
);

if (!publicKey) {
throw new Error("Public key not found in txMsg");
}

// Query account from Ledger storage to determine path for signer
const account = await this._ledgerStore.getRecord("publicKey", publicKey);

if (!account) {
throw new Error(`Ledger account not found for ${publicKey}`);
}

const bytes = await this.sdk.build_tx(TxType.RevealPK, fromBase64(txMsg));
const bytes = await this.sdk.build_tx(
TxType.RevealPK,
fromBase64(txMsg),
publicKey
);
const path = makeBip44Path(coinType, account.path);

return { bytes, path };
Expand Down Expand Up @@ -168,7 +176,15 @@ export class LedgerService {
throw new Error(`Ledger account not found for ${address}`);
}

const bytes = await this.sdk.build_tx(txType, fromBase64(txMsg));
if (!account.publicKey) {
throw new Error(`Ledger account missing public key for ${address}`);
}

const bytes = await this.sdk.build_tx(
txType,
fromBase64(txMsg),
account.publicKey
);
const path = makeBip44Path(coinType, account.path);

return { bytes, path };
Expand Down
2 changes: 1 addition & 1 deletion apps/extension/src/background/offscreen/offscreen.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const SW_TTL = 20000;
sender: unknown,
sendResponse: (response?: unknown) => void
): boolean {
const {data, type, routerId, target} = submitTransferMessage;
const { data, type, routerId, target } = submitTransferMessage;

if (target !== OFFSCREEN_TARGET) {
return false;
Expand Down
9 changes: 0 additions & 9 deletions apps/extension/src/provider/InjectedNamada.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,15 +105,6 @@ export class InjectedNamada implements INamada {
type,
});
}
public async encodeInitAccount(props: {
txMsg: string;
address: string;
}): Promise<string | undefined> {
return await InjectedProxy.requestMethod<
{ txMsg: string; address: string },
string
>("encodeInitAccount", props);
}

public version(): string {
return this._version;
Expand Down
20 changes: 1 addition & 19 deletions apps/extension/src/provider/Namada.test.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
/* eslint-disable @typescript-eslint/no-explicit-any */
import { toBase64 } from "@cosmjs/encoding";

import { AccountMsgValue, Message, Chain, Namada } from "@namada/types";
import { Chain, Namada } from "@namada/types";

import { KVKeys } from "router";
import { init, KVStoreMock } from "test/init";
Expand Down Expand Up @@ -72,21 +71,4 @@ describe("Namada", () => {
const chains = await iDBStore.get("chains");
expect(chains?.pop()).toEqual(chain);
});

// This test shows that init account is NOT working - it is also unused.
// We will have to change assertion after fixing initAccount fn
it("should THROW AN ERROR on encode init account", async () => {
const accountMsgValue = new AccountMsgValue({
vpCode: new Uint8Array(),
});
const accountMessage = new Message<AccountMsgValue>();
const serialized = accountMessage.encode(accountMsgValue);

await expect(
namada.encodeInitAccount({
txMsg: toBase64(serialized),
address: keyStore[0].address,
})
).rejects.toThrow();
});
});
12 changes: 0 additions & 12 deletions apps/extension/src/provider/Namada.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ import {
GetChainMsg,
GetChainsMsg,
SuggestChainMsg,
EncodeInitAccountMsg,
QueryAccountsMsg,
FetchAndStoreMaspParamsMsg,
HasMaspParamsMsg,
Expand Down Expand Up @@ -144,17 +143,6 @@ export class Namada implements INamada {
);
}

public async encodeInitAccount(props: {
txMsg: string;
address: string;
}): Promise<string | undefined> {
const { txMsg, address } = props;
return await this.requester?.sendMessage(
Ports.Background,
new EncodeInitAccountMsg(txMsg, address)
);
}

public version(): string {
return this._version;
}
Expand Down
22 changes: 0 additions & 22 deletions apps/extension/src/provider/Signer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,8 @@ import { toBase64 } from "@cosmjs/encoding";
import {
Account,
Namada,
AccountMsgValue,
IbcTransferMsgValue,
IbcTransferProps,
InitAccountProps,
Message,
Signer as ISigner,
TransferMsgValue,
Expand Down Expand Up @@ -118,24 +116,4 @@ export class Signer implements ISigner {
type,
});
}

/**
* Encode an InitAccount message
*/
public async encodeInitAccount(
args: InitAccountProps,
signer: string
): Promise<string | undefined> {
const { vpCode } = args;
const accountMsgValue = new AccountMsgValue({
vpCode,
});
const accountMessage = new Message<AccountMsgValue>();
const serialized = accountMessage.encode(accountMsgValue);

return await this._namada.encodeInitAccount({
txMsg: toBase64(serialized),
address: signer,
});
}
}
29 changes: 0 additions & 29 deletions apps/extension/src/provider/messages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ enum MessageType {
QueryBalances = "query-balances",
SubmitIbcTransfer = "submit-ibc-transfer",
SubmitLedgerTransfer = "submit-ledger-transfer",
EncodeInitAccount = "encode-init-account",
EncodeRevealPublicKey = "encode-reveal-public-key",
GetChain = "get-chain",
GetChains = "get-chains",
Expand Down Expand Up @@ -183,34 +182,6 @@ export class QueryBalancesMsg extends Message<
}
}

export class EncodeInitAccountMsg extends Message<string> {
public static type(): MessageType {
return MessageType.EncodeInitAccount;
}

constructor(public readonly txMsg: string, public readonly address: string) {
super();
}

validate(): void {
if (!this.address) {
throw new Error("An address is required!");
}
if (!this.txMsg) {
throw new Error("An encoded txMsg is required!");
}
return;
}

route(): string {
return Route.KeyRing;
}

type(): string {
return EncodeInitAccountMsg.type();
}
}

export class ApproveTransferMsg extends Message<void> {
public static type(): MessageType {
return MessageType.ApproveTransfer;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ export const submitIbcTransfer = async (
tx: {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(0),
gasLimit: new BigNumber(20_000),
publicKey,
chainId,
},
Expand Down Expand Up @@ -93,7 +93,7 @@ export const submitBridgeTransfer = async (
tx: {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(0),
gasLimit: new BigNumber(20_000),
chainId,
},
source: address,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ export const submitTransferTransaction = async (
tx: {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(0),
gasLimit: new BigNumber(20_000),
chainId,
publicKey: publicKey,
signer: faucet ? target : undefined,
Expand Down
12 changes: 6 additions & 6 deletions apps/namada-interface/src/slices/StakingAndGovernance/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,9 @@ const toMyValidators = (
index == -1
? (arr: MyValidators[]) => arr
: (arr: MyValidators[], idx: number) => [
...arr.slice(0, idx),
...arr.slice(idx + 1),
];
...arr.slice(0, idx),
...arr.slice(idx + 1),
];

const stakedAmount = new BigNumber(stake).plus(
new BigNumber(v?.stakedAmount || 0)
Expand Down Expand Up @@ -249,7 +249,7 @@ export const postNewBonding = createAsyncThunk<
tx: {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(0),
gasLimit: new BigNumber(20_000),
chainId,
publicKey,
},
Expand Down Expand Up @@ -285,7 +285,7 @@ export const postNewUnbonding = createAsyncThunk<
tx: {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(0),
gasLimit: new BigNumber(20_000),
chainId,
publicKey,
},
Expand Down Expand Up @@ -314,7 +314,7 @@ export const postNewWithdraw = createAsyncThunk<
tx: {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(0),
gasLimit: new BigNumber(20_000),
chainId,
publicKey,
},
Expand Down
Loading