Skip to content

Commit 9afd990

Browse files
fix: lit encryption issues (#264)
1 parent ee02507 commit 9afd990

File tree

9 files changed

+550
-217
lines changed

9 files changed

+550
-217
lines changed

package-lock.json

Lines changed: 469 additions & 122 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

packages/create-invoice-form/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @requestnetwork/create-invoice-form
22

3+
## 0.11.11
4+
5+
### Patch Changes
6+
7+
- Fix Lit Protocol Encryption Issues
8+
39
## 0.11.10
410

511
### Patch Changes

packages/create-invoice-form/package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestnetwork/create-invoice-form",
3-
"version": "0.11.10",
3+
"version": "0.11.11",
44
"main": "./dist/web-component.umd.cjs",
55
"scripts": {
66
"dev": "vite dev",
@@ -33,8 +33,8 @@
3333
"!dist/**/*.spec.*"
3434
],
3535
"dependencies": {
36-
"@requestnetwork/data-format": "0.19.4",
37-
"@requestnetwork/request-client.js": "0.53.0",
36+
"@requestnetwork/data-format": "0.19.5",
37+
"@requestnetwork/request-client.js": "0.54.0",
3838
"@wagmi/core": "^2.15.2",
3939
"validator": "^13.12.0",
4040
"viem": "^2.21.53"

packages/create-invoice-form/src/lib/create-invoice-form.svelte

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,15 @@
2525
import Modal from "@requestnetwork/shared-components/modal.svelte";
2626
import { EncryptionTypes, CipherProviderTypes } from "@requestnetwork/types";
2727
28+
interface CipherProvider extends CipherProviderTypes.ICipherProvider {
29+
disconnectWallet: () => void;
30+
}
31+
2832
export let config: IConfig;
2933
export let wagmiConfig: WagmiConfig;
3034
export let requestNetwork: RequestNetwork | null | undefined;
3135
export let currencies: CurrencyTypes.CurrencyInput[] = [];
32-
let cipherProvider: CipherProviderTypes.ICipherProvider | undefined;
36+
let cipherProvider: CipherProvider | undefined;
3337
3438
let account: GetAccountReturnType;
3539
let isTimeout = false;
@@ -115,11 +119,12 @@
115119
totalAmount: 0,
116120
};
117121
118-
$: cipherProvider = requestNetwork?.getCipherProvider();
122+
$: cipherProvider = requestNetwork?.getCipherProvider() as CipherProvider;
119123
120124
$: {
121125
if (wagmiConfig) {
122126
account = getAccount(wagmiConfig);
127+
cipherProvider?.disconnectWallet();
123128
}
124129
}
125130

packages/invoice-dashboard/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @requestnetwork/invoice-dashboard
22

3+
## 0.11.9
4+
5+
### Patch Changes
6+
7+
- Fix Lit Protocol Encryption Issues
8+
39
## 0.11.8
410

511
### Patch Changes

packages/invoice-dashboard/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestnetwork/invoice-dashboard",
3-
"version": "0.11.8",
3+
"version": "0.11.9",
44
"main": "./dist/web-component.umd.cjs",
55
"scripts": {
66
"dev": "vite dev",
@@ -37,9 +37,9 @@
3737
"react-dom": "^16.8.0 || ^17.0.0 || ^18.0.0"
3838
},
3939
"dependencies": {
40-
"@requestnetwork/payment-detection": "0.48.0",
41-
"@requestnetwork/payment-processor": "0.51.0",
42-
"@requestnetwork/request-client.js": "0.53.0",
40+
"@requestnetwork/payment-detection": "0.49.0",
41+
"@requestnetwork/payment-processor": "0.52.0",
42+
"@requestnetwork/request-client.js": "0.54.0",
4343
"@wagmi/connectors": "^5.5.3",
4444
"@wagmi/core": "^2.15.2",
4545
"ethers": "^5.7.2",

packages/invoice-dashboard/src/lib/view-requests.svelte

Lines changed: 45 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -48,19 +48,22 @@
4848
import { checkStatus } from "@requestnetwork/shared-utils/checkStatus";
4949
import { ethers } from "ethers";
5050
51+
interface CipherProvider extends CipherProviderTypes.ICipherProvider {
52+
getSessionSignatures: (
53+
signer: ethers.Signer,
54+
walletAddress: `0x${string}`,
55+
domain: string,
56+
statement: string
57+
) => Promise<any>;
58+
disconnectWallet: () => void;
59+
}
60+
5161
export let config: IConfig;
5262
export let wagmiConfig: WagmiConfig;
5363
export let requestNetwork: RequestNetwork | null | undefined;
5464
export let currencies: CurrencyTypes.CurrencyInput[] = [];
5565
56-
let cipherProvider:
57-
| (CipherProviderTypes.ICipherProvider & {
58-
getSessionSignatures: (
59-
signer: ethers.Signer,
60-
walletAddress: `0x${string}`
61-
) => Promise<any>;
62-
})
63-
| undefined;
66+
let cipherProvider: CipherProvider | undefined;
6467
6568
let sliderValueForDecryption = JSON.parse(
6669
localStorage?.getItem("isDecryptionEnabled") ?? "false"
@@ -72,7 +75,7 @@
7275
let activeConfig = config ? config : defaultConfig;
7376
let mainColor = activeConfig.colors.main;
7477
let secondaryColor = activeConfig.colors.secondary;
75-
let account: GetAccountReturnType = wagmiConfig && getAccount(wagmiConfig);
78+
let account: GetAccountReturnType | undefined = wagmiConfig && getAccount(wagmiConfig);
7679
7780
let loading = false;
7881
let searchQuery = "";
@@ -87,8 +90,6 @@
8790
})
8891
| undefined;
8992
let currencyManager: CurrencyManager;
90-
let previousWalletAddress: string | undefined;
91-
let previousNetwork: string | undefined;
9293
9394
let columns = {
9495
issuedAt: false,
@@ -102,63 +103,45 @@
102103
let sortOrder = "desc";
103104
let sortColumn = "timestamp";
104105
105-
let previousAddress: string | undefined;
106+
const handleWalletConnection = async () => {
107+
account = getAccount(wagmiConfig);
108+
await loadRequests(sliderValueForDecryption, account, requestNetwork);
109+
};
106110
107-
$: {
108-
if (wagmiConfig) {
109-
const newAccount = getAccount(wagmiConfig);
110-
if (newAccount?.address !== previousAddress) {
111-
account = newAccount;
112-
previousAddress = newAccount?.address;
113-
114-
if (newAccount?.address) {
115-
tick().then(() => {
116-
enableDecryption();
117-
getRequests();
118-
});
119-
} else {
120-
requests = [];
121-
activeRequest = undefined;
122-
previousWalletAddress = undefined;
123-
previousNetwork = undefined;
124-
}
125-
}
126-
}
127-
}
111+
const handleWalletDisconnection = () => {
112+
cipherProvider?.disconnectWallet();
113+
requests = [];
114+
activeRequest = undefined;
115+
cipherProvider = undefined;
116+
account = undefined;
117+
};
128118
129-
let unwatchAccount: WatchAccountReturnType | undefined;
119+
const handleWalletChange = (data: any) => {
120+
if (data?.address) {
121+
handleWalletConnection();
122+
} else {
123+
handleWalletDisconnection();
124+
}
125+
};
130126
131127
onMount(() => {
132128
unwatchAccount = watchAccount(wagmiConfig, {
133129
onChange(data) {
134-
if (data?.address !== previousAddress) {
135-
account = data;
136-
previousAddress = data?.address;
137-
138-
if (data?.address) {
139-
getRequests();
140-
} else {
141-
requests = [];
142-
activeRequest = undefined;
143-
previousWalletAddress = undefined;
144-
previousNetwork = undefined;
145-
}
146-
}
130+
tick().then(() => {
131+
handleWalletChange(data);
132+
});
147133
},
148134
});
149135
});
150136
137+
let unwatchAccount: WatchAccountReturnType | undefined;
138+
151139
onDestroy(() => {
152140
if (typeof unwatchAccount === "function") unwatchAccount();
153141
});
154142
155143
$: cipherProvider =
156-
requestNetwork?.getCipherProvider() as CipherProviderTypes.ICipherProvider & {
157-
getSessionSignatures: (
158-
signer: ethers.Signer,
159-
walletAddress: `0x${string}`
160-
) => Promise<any>;
161-
};
144+
requestNetwork?.getCipherProvider() as CipherProvider;
162145
163146
$: {
164147
signer = account?.address;
@@ -170,9 +153,8 @@
170153
currencyManager = initializeCurrencyManager(currencies);
171154
});
172155
173-
const getRequests = async () => {
156+
const getRequests = async (account: GetAccountReturnType, requestNetwork: RequestNetwork | undefined | null) => {
174157
if (!account?.address || !requestNetwork) return;
175-
loading = true;
176158
177159
try {
178160
const requestsData = await requestNetwork?.fromIdentity({
@@ -184,8 +166,6 @@
184166
.sort((a, b) => b.timestamp - a.timestamp);
185167
} catch (error) {
186168
console.error("Failed to fetch requests:", error);
187-
} finally {
188-
loading = false;
189169
}
190170
};
191171
@@ -211,25 +191,6 @@
211191
let currentPage = 1;
212192
let totalPages = 1;
213193
214-
$: {
215-
const currentWalletAddress = account?.address;
216-
const currentNetwork = account?.chainId?.toString();
217-
218-
if (
219-
currentWalletAddress &&
220-
currentWalletAddress !== previousWalletAddress
221-
) {
222-
getRequests();
223-
previousWalletAddress = currentWalletAddress;
224-
225-
activeRequest = undefined;
226-
}
227-
228-
if (currentNetwork && currentNetwork !== previousNetwork) {
229-
previousNetwork = currentNetwork;
230-
}
231-
}
232-
233194
$: {
234195
if (sortColumn && sortOrder) {
235196
requests = [...(requests ?? [])].sort((a, b) => {
@@ -422,13 +383,15 @@
422383
activeRequest = undefined;
423384
};
424385
425-
const enableDecryption = async () => {
386+
const loadRequests = async (sliderValue: string, currentAccount: GetAccountReturnType, currentRequestNetwork: RequestNetwork | undefined | null) => {
387+
if (!currentAccount?.address || !currentRequestNetwork && !cipherProvider) return;
388+
426389
loading = true;
427-
if (sliderValueForDecryption === "on") {
390+
if (sliderValue === "on") {
428391
try {
429392
const signer = await getEthersSigner(wagmiConfig);
430-
if (signer && account?.address) {
431-
await cipherProvider?.getSessionSignatures(signer, account.address);
393+
if (signer && currentAccount?.address) {
394+
await cipherProvider?.getSessionSignatures(signer, currentAccount.address, window.location.host, "Sign in to Lit Protocol through Request Network");
432395
cipherProvider?.enableDecryption(true);
433396
localStorage?.setItem("isDecryptionEnabled", JSON.stringify(true));
434397
}
@@ -442,10 +405,10 @@
442405
cipherProvider?.enableDecryption(false);
443406
localStorage?.setItem("isDecryptionEnabled", JSON.stringify(false));
444407
}
445-
await getRequests();
408+
await getRequests(currentAccount, currentRequestNetwork);
446409
loading = false;
447410
};
448-
$: sliderValueForDecryption, enableDecryption();
411+
$: loadRequests(sliderValueForDecryption, account, requestNetwork);
449412
</script>
450413

451414
<div

packages/payment-widget/CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# @requestnetwork/payment-widget
22

3+
## 0.3.7
4+
5+
### Patch Changes
6+
7+
- Fix Lit Protocol Encryption Issues
8+
39
## 0.3.6
410

511
### Patch Changes

packages/payment-widget/package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@requestnetwork/payment-widget",
3-
"version": "0.3.6",
3+
"version": "0.3.7",
44
"main": "./dist/web-component.umd.cjs",
55
"scripts": {
66
"dev": "vite dev",
@@ -56,9 +56,9 @@
5656
"access": "public"
5757
},
5858
"dependencies": {
59-
"@requestnetwork/payment-processor": "0.51.0",
60-
"@requestnetwork/request-client.js": "0.53.0",
61-
"@requestnetwork/web3-signature": "0.8.4",
59+
"@requestnetwork/payment-processor": "0.52.0",
60+
"@requestnetwork/request-client.js": "0.54.0",
61+
"@requestnetwork/web3-signature": "0.8.5",
6262
"@web3modal/ethers5": "^5.0.11",
6363
"ethers": "^5.7.2",
6464
"vite-plugin-node-polyfills": "^0.22.0"

0 commit comments

Comments
 (0)