Skip to content

Commit 562e4c1

Browse files
authored
Merge branch 'main' into fix-mina-attestations
2 parents f2546d3 + b0e9ab5 commit 562e4c1

File tree

2 files changed

+47
-9
lines changed

2 files changed

+47
-9
lines changed

packages/features/src/settings/routes/authorized-zkapps.tsx

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ export type ZkApp = {
1010
image: string
1111
url: string
1212
}
13+
14+
// https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
15+
const URLRegex =
16+
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/
17+
1318
export const AuthorizedZkAppsRoute = () => {
1419
const navigate = useNavigate()
1520
const [connectedApps, setConnectedApps] = useState([] as ZkApp[])
@@ -22,16 +27,18 @@ export const AuthorizedZkAppsRoute = () => {
2227
const { permissions } = (await chrome.storage.local.get({
2328
permissions: [],
2429
})) as Record<string, "ALLOWED">
25-
// https://stackoverflow.com/questions/3809401/what-is-a-good-regular-expression-to-match-a-url
26-
const URLRegex =
27-
/https?:\/\/(www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b([-a-zA-Z0-9()@:%_\+.~#?&//=]*)/
2830
const appsWithMetadata = await Promise.all(
2931
Object.keys(permissions)
3032
.filter((key) => URLRegex.test(key))
3133
.map(async (url) => {
32-
const metadata = (await fetcher(
33-
`https://api.dub.co/metatags?url=${url}`,
34-
)) as Omit<ZkApp, "url">
34+
let metadata: Omit<ZkApp, "url"> = {
35+
title: "",
36+
description: "",
37+
image: "",
38+
}
39+
try {
40+
metadata = await fetcher(`https://api.dub.co/metatags?url=${url}`)
41+
} catch (e) {}
3542
return { url, ...metadata }
3643
}),
3744
)
@@ -42,7 +49,19 @@ export const AuthorizedZkAppsRoute = () => {
4249
const filteredApps = connectedApps.filter(
4350
(app) => app.url !== appToDelete.url,
4451
)
45-
await chrome.storage.local.set({ permissions: filteredApps })
52+
53+
const { permissions } = await chrome.storage.local.get({
54+
permissions: {} as ZkApp[] & Record<string, "ALLOWED">,
55+
})
56+
const newPermissions = Object.assign({}, filteredApps) as ZkApp[] &
57+
Record<string, "ALLOWED">
58+
for (const k of Object.keys(permissions).filter(
59+
(key) => URLRegex.test(key) && key !== appToDelete.url,
60+
)) {
61+
newPermissions[k] = permissions[k]
62+
}
63+
await chrome.storage.local.set({ permissions: newPermissions })
64+
4665
setConnectedApps(filteredApps)
4766
}
4867

packages/web-provider/src/vault-service/vault-service.ts

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ import dayjs from "dayjs"
88
import Client from "mina-signer"
99

1010
import type { SignedTransaction } from "@mina-js/utils"
11+
import type {
12+
Payment,
13+
StakeDelegation,
14+
ZkappCommand,
15+
} from "mina-signer/dist/node/mina-signer/src/types"
1116
import type { IVaultService } from "./types"
1217

1318
export enum AuthorizationState {
@@ -74,9 +79,23 @@ export const createVaultService = (): IVaultService => {
7479
const accounts = await getAccounts()
7580
const publicKey = accounts?.[0]
7681
if (!publicKey) throw new Error("Wallet is not initialized.")
77-
const validTransaction = signer.verifyTransaction(sendable.input as never)
78-
if (!validTransaction) throw new Error("Invalid transaction.")
7982
const type = getTxType(sendable.input as never)
83+
const signedData: StakeDelegation | Payment | ZkappCommand =
84+
sendable.input as any
85+
const verifyTransactionParams =
86+
"feePayer" in signedData
87+
? {
88+
signature: signedData.zkappCommand.feePayer.authorization,
89+
publicKey: signedData.zkappCommand.feePayer.body.publicKey,
90+
data: signedData,
91+
}
92+
: {
93+
signature: (sendable as any).signature,
94+
publicKey: signedData.from,
95+
data: signedData,
96+
}
97+
if (!signer.verifyTransaction(verifyTransactionParams))
98+
throw new Error("Invalid transaction.")
8099
const payload =
81100
type === "zkapp"
82101
? { input: sendable.input }

0 commit comments

Comments
 (0)