Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: include account in connector #2135

Merged
merged 2 commits into from
Mar 6, 2023
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
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import connectors from "../../connectors";

const validateAccount = async (message, sender) => {
const account = message.args;
const connector = new connectors[account.connector](account.config);
const connector = new connectors[account.connector](account, account.config);
await connector.init();

try {
Expand Down
18 changes: 11 additions & 7 deletions src/extension/background-script/connectors/citadel.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
import { Account } from "~/types";

import Connector, {
CheckPaymentArgs,
CheckPaymentResponse,
ConnectPeerResponse,
SendPaymentArgs,
SendPaymentResponse,
GetInfoResponse,
GetBalanceResponse,
GetInfoResponse,
GetInvoicesResponse,
KeysendArgs,
MakeInvoiceArgs,
MakeInvoiceResponse,
SendPaymentArgs,
SendPaymentResponse,
SignMessageArgs,
SignMessageResponse,
CheckPaymentArgs,
CheckPaymentResponse,
KeysendArgs,
} from "./connector.interface";

interface Config {
Expand All @@ -27,10 +29,12 @@ type RequestFunction = <ResponseType = unknown>(
) => Promise<ResponseType>;

class CitadelConnector implements Connector {
account: Account;
config: Config;
jwt: string;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
this.jwt = "";
}
Expand Down
5 changes: 4 additions & 1 deletion src/extension/background-script/connectors/commando.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import Hex from "crypto-js/enc-hex";
import UTF8 from "crypto-js/enc-utf8";
import LnMessage from "lnmessage";
import { v4 as uuidv4 } from "uuid";
import { Account } from "~/types";

import Connector, {
CheckPaymentArgs,
Expand Down Expand Up @@ -110,10 +111,12 @@ const supportedMethods: string[] = [
];

export default class Commando implements Connector {
account: Account;
config: Config;
ln: LnMessage;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
this.ln = new LnMessage({
remoteNodePublicKey: this.config.pubkey,
Expand Down
13 changes: 8 additions & 5 deletions src/extension/background-script/connectors/eclair.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
import Base64 from "crypto-js/enc-base64";
import UTF8 from "crypto-js/enc-utf8";
import { Account } from "~/types";

import Connector, {
SendPaymentArgs,
SendPaymentResponse,
CheckPaymentArgs,
CheckPaymentResponse,
ConnectPeerResponse,
GetBalanceResponse,
GetInfoResponse,
GetInvoicesResponse,
GetBalanceResponse,
KeysendArgs,
MakeInvoiceArgs,
MakeInvoiceResponse,
SendPaymentArgs,
SendPaymentResponse,
SignMessageArgs,
SignMessageResponse,
KeysendArgs,
} from "./connector.interface";

interface Config {
Expand All @@ -23,9 +24,11 @@ interface Config {
}

class Eclair implements Connector {
account: Account;
config: Config;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
}

Expand Down
16 changes: 9 additions & 7 deletions src/extension/background-script/connectors/galoy.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
import axios from "axios";
import { AxiosRequestConfig } from "axios";
import axios, { AxiosRequestConfig } from "axios";
import lightningPayReq from "bolt11";
import { Account } from "~/types";

import Connector, {
SendPaymentArgs,
SendPaymentResponse,
CheckPaymentArgs,
CheckPaymentResponse,
ConnectPeerResponse,
GetBalanceResponse,
GetInfoResponse,
GetInvoicesResponse,
GetBalanceResponse,
KeysendArgs,
MakeInvoiceArgs,
MakeInvoiceResponse,
SendPaymentArgs,
SendPaymentResponse,
SignMessageArgs,
SignMessageResponse,
KeysendArgs,
} from "./connector.interface";

interface Config {
Expand All @@ -25,9 +25,11 @@ interface Config {
}

class Galoy implements Connector {
account: Account;
config: Config;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
}

Expand Down
5 changes: 4 additions & 1 deletion src/extension/background-script/connectors/kollider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import sha256 from "crypto-js/sha256";
import { ACCOUNT_CURRENCIES } from "~/common/constants";
import { getBTCToSats, getSatsToBTC } from "~/common/utils/currencyConvert";
import HashKeySigner from "~/common/utils/signer";
import { Account } from "~/types";

import Connector, {
CheckPaymentArgs,
Expand Down Expand Up @@ -48,6 +49,7 @@ const defaultHeaders = {
};

export default class Kollider implements Connector {
account: Account;
config: Config;
access_token?: string;
access_token_created?: number;
Expand All @@ -58,7 +60,8 @@ export default class Kollider implements Connector {
currency: KolliderCurrencies;
currentAccountId: string | null;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
this.currency = config.currency;
this.currentAccountId = null;
Expand Down
13 changes: 8 additions & 5 deletions src/extension/background-script/connectors/lnbits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,24 @@ import Hex from "crypto-js/enc-hex";
import sha256 from "crypto-js/sha256";
import utils from "~/common/lib/utils";
import HashKeySigner from "~/common/utils/signer";
import { Account } from "~/types";

import state from "../state";
import Connector, {
SendPaymentArgs,
SendPaymentResponse,
CheckPaymentArgs,
CheckPaymentResponse,
ConnectorInvoice,
ConnectPeerResponse,
GetBalanceResponse,
GetInfoResponse,
GetInvoicesResponse,
GetBalanceResponse,
KeysendArgs,
MakeInvoiceArgs,
MakeInvoiceResponse,
SendPaymentArgs,
SendPaymentResponse,
SignMessageArgs,
SignMessageResponse,
KeysendArgs,
} from "./connector.interface";

interface Config {
Expand All @@ -28,9 +29,11 @@ interface Config {
}

class LnBits implements Connector {
account: Account;
config: Config;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
}

Expand Down
28 changes: 16 additions & 12 deletions src/extension/background-script/connectors/lnc.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import LNC from "@lightninglabs/lnc-web";
import { CredentialStore } from "@lightninglabs/lnc-web";
import LNC, { CredentialStore } from "@lightninglabs/lnc-web";
import Base64 from "crypto-js/enc-base64";
import Hex from "crypto-js/enc-hex";
import UTF8 from "crypto-js/enc-utf8";
Expand All @@ -8,23 +7,24 @@ import SHA256 from "crypto-js/sha256";
import snakeCase from "lodash.snakecase";
import { encryptData } from "~/common/lib/crypto";
import utils from "~/common/lib/utils";
import { Account } from "~/types";

import state from "../state";
import Connector, {
CheckPaymentArgs,
CheckPaymentResponse,
SendPaymentArgs,
SendPaymentResponse,
GetInfoResponse,
ConnectorInvoice,
ConnectPeerResponse,
GetBalanceResponse,
GetInfoResponse,
GetInvoicesResponse,
ConnectPeerResponse,
ConnectorInvoice,
KeysendArgs,
MakeInvoiceArgs,
MakeInvoiceResponse,
SendPaymentArgs,
SendPaymentResponse,
SignMessageArgs,
SignMessageResponse,
KeysendArgs,
} from "./connector.interface";

interface Config {
Expand Down Expand Up @@ -82,9 +82,11 @@ const snakeCaseObjectDeep = (value: FixMe): FixMe => {
};

class LncCredentialStore implements CredentialStore {
account: Account;
config: Config;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
}

Expand Down Expand Up @@ -136,7 +138,7 @@ class LncCredentialStore implements CredentialStore {
private async _save() {
const accounts = state.getState().accounts;
const password = state.getState().password as string;
const currentAccountId = state.getState().currentAccountId as string;
const currentAccountId = this.account.id;
accounts[currentAccountId].config = encryptData(this.config, password);
state.setState({ accounts });
await state.getState().saveToStorage();
Expand All @@ -145,13 +147,15 @@ class LncCredentialStore implements CredentialStore {
}

class Lnc implements Connector {
account: Account;
config: Config;
lnc: FixMe;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
this.lnc = new LNC({
credentialStore: new LncCredentialStore(config),
credentialStore: new LncCredentialStore(account, config),
});
}

Expand Down
5 changes: 4 additions & 1 deletion src/extension/background-script/connectors/lnd.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import UTF8 from "crypto-js/enc-utf8";
import WordArray from "crypto-js/lib-typedarrays";
import SHA256 from "crypto-js/sha256";
import utils from "~/common/lib/utils";
import { Account } from "~/types";

import Connector, {
CheckPaymentArgs,
Expand Down Expand Up @@ -135,9 +136,11 @@ const pathTemplateParser = (
};

class Lnd implements Connector {
account: Account;
config: Config;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
}

Expand Down
5 changes: 4 additions & 1 deletion src/extension/background-script/connectors/lndhub.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import hmacSHA256 from "crypto-js/hmac-sha256";
import sha256 from "crypto-js/sha256";
import utils from "~/common/lib/utils";
import HashKeySigner from "~/common/utils/signer";
import { Account } from "~/types";

import state from "../state";
import Connector, {
Expand Down Expand Up @@ -43,14 +44,16 @@ const defaultHeaders = {
};

export default class LndHub implements Connector {
account: Account;
config: Config;
access_token?: string;
access_token_created?: number;
refresh_token?: string;
refresh_token_created?: number;
noRetry?: boolean;

constructor(config: Config) {
constructor(account: Account, config: Config) {
this.account = account;
this.config = config;
}

Expand Down
2 changes: 1 addition & 1 deletion src/extension/background-script/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ const state = createState<State>((set, get) => ({
const password = get().password as string;
const config = decryptData(account.config as string, password);

const connector = new connectors[account.connector](config);
const connector = new connectors[account.connector](account, config);
await connector.init();

set({ connector: connector });
Expand Down