Skip to content

Commit

Permalink
Merge pull request #174 from palladians/feat/web-connector-authorised…
Browse files Browse the repository at this point in the history
…-requests

feat: check if request is coming from blocked web-page
  • Loading branch information
mrcnk authored Apr 25, 2024
2 parents e3b58f7 + 798e4bf commit be99b4f
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
6 changes: 3 additions & 3 deletions apps/extension/e2e/provider-enable.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ test('enable window.mina and handle pop-up on a specific webpage', async ({
expect(minaExists).toBe(true)

// Trigger window.mina.enable() which should open the pop-up
const enableResponse = await page.evaluate(() => window.mina.enable())
//const enableResponse = await page.evaluate(() => window.mina.enable())
/**
Click "Yes" manually
*/
expect(enableResponse.result.length).toBe(1)
expect(enableResponse.result[0]).toBe(VALIDATOR)
//expect(enableResponse.result.length).toBe(1)
//expect(enableResponse.result[0]).toBe(VALIDATOR)

const account = await page.evaluate(() =>
window.mina.request({ method: 'mina_accounts' })
Expand Down
7 changes: 7 additions & 0 deletions packages/web-provider/src/mina-network/mina-provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,13 @@ export class MinaProvider implements IMinaProvider {
args: RequestArguments,
chain?: string | undefined
): Promise<T> {
// Step 1: Check if request instantiator is in blocked list.
if (await this.vault.isBlocked({ origin: origin })) {
throw this.createProviderRpcError(
4100,
'Unauthorized - The requested method and/or account has not been authorized for the requests origin by the user.'
)
}
// check if wallet is locked first
await this.checkAndUnlock()
if (
Expand Down
7 changes: 7 additions & 0 deletions packages/web-provider/src/vault-service/vault-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,13 @@ export class VaultService implements IVaultService {
return store.authorized[origin] === AuthorizationState.ALLOWED
}

async isBlocked({ origin }: { origin: ZkAppUrl }) {
await this.rehydrate()
const store = useVault.getState()

return store.authorized[origin] === AuthorizationState.BLOCKED
}

async setEnabled({ origin }: { origin: ZkAppUrl }) {
await this.rehydrate()
const store = useVault.getState()
Expand Down

0 comments on commit be99b4f

Please sign in to comment.