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
6 changes: 3 additions & 3 deletions apps/airdrop/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
"lint:fix": "npx yarn lint -- --fix"
},
"dependencies": {
"@namada/components": "0.1.0",
"@namada/hooks": "0.1.0",
"@namada/utils": "0.1.0",
"@namada/components": "0.2.1",
"@namada/hooks": "0.2.1",
"@namada/utils": "0.2.1",
"buffer": "^6.0.3",
"dompurify": "^3.0.2",
"gsap": "^3.12.2",
Expand Down
16 changes: 8 additions & 8 deletions apps/extension/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@namada/extension",
"version": "0.2.0",
"version": "0.2.1",
"description": "Namada Browser Extension",
"repository": "https://github.com/anoma/namada-interface/",
"author": "Heliax Dev <info@heliax.dev>",
Expand Down Expand Up @@ -36,13 +36,13 @@
"@ledgerhq/hw-transport": "^6.30.0",
"@ledgerhq/hw-transport-webhid": "^6.28.0",
"@ledgerhq/hw-transport-webusb": "^6.28.0",
"@namada/chains": "0.1.0",
"@namada/components": "0.1.0",
"@namada/crypto": "0.1.0",
"@namada/shared": "0.1.0",
"@namada/storage": "0.1.0",
"@namada/types": "0.1.0",
"@namada/utils": "0.1.0",
"@namada/chains": "0.2.1",
"@namada/components": "0.2.1",
"@namada/crypto": "0.2.1",
"@namada/shared": "0.2.1",
"@namada/storage": "0.2.1",
"@namada/types": "0.2.1",
"@namada/utils": "0.2.1",
"@zondax/ledger-namada": "^0.0.3",
"bignumber.js": "^9.1.1",
"buffer": "^6.0.3",
Expand Down
11 changes: 5 additions & 6 deletions apps/extension/src/App/Accounts/AddAccount.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import React, { useCallback, useEffect, useState } from "react";
import { useNavigate } from "react-router-dom";

import { chains, defaultChainId } from "@namada/chains";
import { chains } from "@namada/chains";
import { ActionButton, Input, Toggle } from "@namada/components";
import { AccountType, DerivedAccount } from "@namada/types";
import { makeBip44Path } from "@namada/utils";
Expand Down Expand Up @@ -147,7 +147,7 @@ const AddAccount: React.FC<Props> = ({

const bip44Prefix = "m/44";
const zip32Prefix = "m/32";
const { coinType } = chains[defaultChainId].bip44;
const { coinType } = chains.namada.bip44;

const authorize = useAuth(requester);

Expand Down Expand Up @@ -207,7 +207,7 @@ const AddAccount: React.FC<Props> = ({
index,
};
const bip44PathString = makeBip44Path(
chains[defaultChainId].bip44.coinType,
chains.namada.bip44.coinType,
bip44Path
);

Expand Down Expand Up @@ -383,9 +383,8 @@ const AddAccount: React.FC<Props> = ({

<div className="text-sm text-neutral-400">
Derivation path:{" "}
<span>{`${parentDerivationPath}${
isTransparent ? `${change}/` : ""
}${index}`}</span>
<span>{`${parentDerivationPath}${isTransparent ? `${change}/` : ""
}${index}`}</span>
</div>

<div className="text-xs py-1 text-red-500">{validation}</div>
Expand Down
9 changes: 7 additions & 2 deletions apps/extension/src/Approvals/ApproveTx/ConfirmLedgerTx.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { toBase64 } from "@cosmjs/encoding";
import BigNumber from "bignumber.js";
import { useCallback, useEffect, useState } from "react";

import { defaultChainId as chainId } from "@namada/chains";
import { ActionButton, Alert, Stack } from "@namada/components";
import { TxType, TxTypeLabel } from "@namada/shared";
import { Message, Tokens, TxMsgValue, TxProps } from "@namada/types";
Expand All @@ -19,6 +18,7 @@ import {
SubmitSignedTxMsg,
} from "background/ledger";
import { useRequester } from "hooks/useRequester";
import { GetChainMsg } from "provider";
import { Ports } from "router";
import { closeCurrentTab } from "utils";

Expand All @@ -44,11 +44,16 @@ export const ConfirmLedgerTx: React.FC<Props> = ({ details }) => {
"Public key not found! Review and approve reveal pk on your Ledger"
);

const chain = await requester.sendMessage(
Ports.Background,
new GetChainMsg()
);

const txArgs: TxProps = {
token: Tokens.NAM.address || "",
feeAmount: new BigNumber(0),
gasLimit: new BigNumber(20_000),
chainId,
chainId: chain.chainId,
publicKey,
};

Expand Down
8 changes: 4 additions & 4 deletions apps/extension/src/background/chains/service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { chains, defaultChainId } from "@namada/chains";
import { chains } from "@namada/chains";
import { KVStore } from "@namada/storage";
import { Chain } from "@namada/types";
import { ExtensionBroadcaster } from "extension";
Expand All @@ -9,13 +9,13 @@ export class ChainsService {
constructor(
protected readonly chainsStore: KVStore<Chain>,
protected readonly broadcaster: ExtensionBroadcaster
) {}
) { }

async getChain(): Promise<Chain | undefined> {
async getChain(): Promise<Chain> {
const chain = await this.chainsStore.get(CHAINS_KEY);
if (!chain) {
// Initialize default chain in storage
const defaultChain = chains[defaultChainId];
const defaultChain = chains.namada;
await this.chainsStore.set(CHAINS_KEY, defaultChain);
return defaultChain;
}
Expand Down
8 changes: 4 additions & 4 deletions apps/extension/src/background/keyring/keyring.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { deserialize } from "@dao-xyz/borsh";

import { chains, defaultChainId } from "@namada/chains";
import { chains } from "@namada/chains";
import {
HDWallet,
Mnemonic,
Expand Down Expand Up @@ -191,7 +191,7 @@ export class KeyRing {
const phrase = accountSecret.seedPhrase.join(" ");
const mnemonic = Mnemonic.from_phrase(phrase);
const seed = mnemonic.to_seed();
const { coinType } = chains[defaultChainId].bip44;
const { coinType } = chains.namada.bip44;
const bip44Path = makeBip44PathArray(coinType, path);
const hdWallet = new HDWallet(seed);
const key = hdWallet.derive(new Uint32Array(bip44Path));
Expand Down Expand Up @@ -262,7 +262,7 @@ export class KeyRing {
path: Bip44Path,
parentId: string
): DerivedAccountInfo {
const { coinType } = chains[defaultChainId].bip44;
const { coinType } = chains.namada.bip44;
const derivationPath = makeBip44PathArray(coinType, path);
const hdWallet = new HDWallet(seed);
const key = hdWallet.derive(new Uint32Array(derivationPath));
Expand Down Expand Up @@ -619,7 +619,7 @@ export class KeyRing {
throw new Error(`Account for ${address} not found!`);
}
const { path } = accountStore;
const { coinType } = chains[defaultChainId].bip44;
const { coinType } = chains.namada.bip44;
const bip44Path = makeBip44PathArray(coinType, path);

const sensitiveProps =
Expand Down
5 changes: 4 additions & 1 deletion apps/extension/src/background/keyring/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ export class KeyRingService {
): Promise<void> {
const offscreenDocumentPath = "offscreen.html";
const routerId = await getNamadaRouterId(this.extensionStore);
const rpc = await this.sdkService.getRpc();

if (!(await hasOffscreenDocument(offscreenDocumentPath))) {
await createOffscreenWithTxWorker(offscreenDocumentPath);
Expand All @@ -268,7 +269,7 @@ export class KeyRingService {
type: SUBMIT_TRANSFER_MSG_TYPE,
target: OFFSCREEN_TARGET,
routerId,
data: { transferMsg, txMsg, msgId, signingKey },
data: { transferMsg, txMsg, msgId, signingKey, rpc },
});

if (result?.error) {
Expand All @@ -284,12 +285,14 @@ export class KeyRingService {
msgId: string,
signingKey: SigningKey
): Promise<void> {
const rpc = await this.sdkService.getRpc();
initSubmitTransferWebWorker(
{
transferMsg,
txMsg,
msgId,
signingKey,
rpc,
},
this.handleTransferCompleted.bind(this)
);
Expand Down
27 changes: 12 additions & 15 deletions apps/extension/src/background/ledger/ledger.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,19 @@
import TransportUSB from "@ledgerhq/hw-transport-webusb";
import TransportHID from "@ledgerhq/hw-transport-webhid";
import Transport from "@ledgerhq/hw-transport";
import TransportHID from "@ledgerhq/hw-transport-webhid";
import TransportUSB from "@ledgerhq/hw-transport-webusb";

import { toHex } from "@cosmjs/encoding";
import { chains } from "@namada/chains";
import { makeBip44Path } from "@namada/utils";
import {
LedgerError,
NamadaApp,
ResponseAppInfo,
ResponseSign,
ResponseVersion,
LedgerError,
} from "@zondax/ledger-namada";
import { defaultChainId, chains } from "@namada/chains";
import { makeBip44Path } from "@namada/utils";
import { toHex } from "@cosmjs/encoding";

const namadaChain = chains[defaultChainId];
const { coinType } = namadaChain.bip44;
const { coinType } = chains.namada.bip44;

export const initLedgerUSBTransport = async (): Promise<Transport> => {
return await TransportUSB.create();
Expand All @@ -31,7 +30,7 @@ export const DEFAULT_LEDGER_BIP44_PATH = makeBip44Path(coinType, {
});

export class Ledger {
constructor(public readonly namadaApp: NamadaApp | undefined = undefined) {}
constructor(public readonly namadaApp: NamadaApp | undefined = undefined) { }

/**
* Returns an initialized Ledger class instance with initialized Transport
Expand Down Expand Up @@ -78,9 +77,8 @@ export class Ledger {
}

const path = bip44Path || DEFAULT_LEDGER_BIP44_PATH;
const { address, publicKey } = await this.namadaApp.getAddressAndPubKey(
path
);
const { address, publicKey } =
await this.namadaApp.getAddressAndPubKey(path);

return {
// Return address as bech32-encoded string
Expand All @@ -100,9 +98,8 @@ export class Ledger {
const path = bip44Path || DEFAULT_LEDGER_BIP44_PATH;

try {
const { address, publicKey } = await this.namadaApp.showAddressAndPubKey(
path
);
const { address, publicKey } =
await this.namadaApp.showAddressAndPubKey(path);

return {
// Return address as bech32-encoded string
Expand Down
6 changes: 3 additions & 3 deletions apps/extension/src/background/ledger/service.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { fromBase64 } from "@cosmjs/encoding";
import { deserialize } from "@dao-xyz/borsh";

import { chains, defaultChainId } from "@namada/chains";
import { chains } from "@namada/chains";
import { TxType } from "@namada/shared";
import { KVStore } from "@namada/storage";
import { AccountType, TxMsgValue } from "@namada/types";
Expand Down Expand Up @@ -31,7 +31,7 @@ export class LedgerService {
async getRevealPKBytes(
txMsg: string
): Promise<{ bytes: Uint8Array; path: string }> {
const { coinType } = chains[defaultChainId].bip44;
const { coinType } = chains.namada.bip44;

try {
// Deserialize txMsg to retrieve source
Expand Down Expand Up @@ -154,7 +154,7 @@ export class LedgerService {

const { txMsg, specificMsg } = storeResult;

const { coinType } = chains[defaultChainId].bip44;
const { coinType } = chains.namada.bip44;

try {
// Query account from Ledger storage to determine path for signer
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 @@ -22,7 +22,7 @@ const SW_TTL = 20000;
// sent using sendResponse; false otherwise.
function handleMessages(
submitTransferMessage: SubmitTransferMessage,
sender: unknown,
_sender: unknown,
sendResponse: (response?: unknown) => void
): boolean {
const { data, type, routerId, target } = submitTransferMessage;
Expand Down
6 changes: 3 additions & 3 deletions apps/extension/src/background/sdk/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { ChainsService } from "background/chains";
export class SdkService {
constructor(protected readonly chainsService: ChainsService) {}

private async _getRpc(): Promise<string> {
public async getRpc(): Promise<string> {
// Pull chain config from store, as the RPC value may have changed:
const chain = await this.chainsService.getChain();

Expand All @@ -16,12 +16,12 @@ export class SdkService {
}

async getSdk(): Promise<Sdk> {
const rpc = await this._getRpc();
const rpc = await this.getRpc();
return new Sdk(rpc);
}

async getQuery(): Promise<Query> {
const rpc = await this._getRpc();
const rpc = await this.getRpc();
return new Query(rpc);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { fromBase64 } from "@cosmjs/encoding";
import { deserialize, serialize } from "@dao-xyz/borsh";
import { chains, defaultChainId } from "@namada/chains";
import { Sdk } from "@namada/shared";
import { initMulticore as initShared } from "@namada/shared/src/init";
import { TxMsgValue } from "@namada/types";
Expand All @@ -17,16 +16,19 @@ import {
wasm.arrayBuffer()
);
await initShared(sharedWasm);
const sdk = new Sdk(chains[defaultChainId].rpc);
await sdk.load_masp_params();

addEventListener(
"message",
async ({ data }: { data: SubmitTransferMessageData }) => {
try {
const { privateKey, xsk } = data.signingKey;
const {
signingKey: { privateKey, xsk },
rpc,
} = data;
let txMsg = fromBase64(data.txMsg);

const sdk = new Sdk(rpc);
await sdk.load_masp_params();
// For transparent transactions we have to reveal the public key.
if (privateKey) {
await sdk.reveal_pk(privateKey, txMsg);
Expand Down
1 change: 1 addition & 0 deletions apps/extension/src/background/web-workers/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type SubmitTransferMessageData = {
txMsg: string;
msgId: string;
signingKey: SigningKey;
rpc: string;
};

export const INIT_MSG = "init";
Expand Down
8 changes: 5 additions & 3 deletions apps/extension/src/provider/Signer.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { toBase64 } from "@cosmjs/encoding";
import { defaultChainId } from "@namada/chains";
import { chains } from "@namada/chains";
import { SupportedTx, TxType } from "@namada/shared";
import {
Account,
Expand Down Expand Up @@ -35,10 +35,11 @@ export class Signer implements ISigner {
({ alias, address, type, publicKey }) => ({
alias,
address,
chainId: defaultChainId,
chainId: chains.namada.chainId,
type,
publicKey,
isShielded: type === AccountType.ShieldedKeys,
chainKey: "namada",
})
);
}
Expand All @@ -52,10 +53,11 @@ export class Signer implements ISigner {
return {
alias,
address,
chainId: defaultChainId,
chainId: chains.namada.chainId,
type,
publicKey,
isShielded: type === AccountType.ShieldedKeys,
chainKey: "namada",
};
}
}
Expand Down
Loading