-
-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #140 from palladians/feat/web-provider-fun
Feat: Implement web-provider package
- Loading branch information
Showing
57 changed files
with
2,442 additions
and
378 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
body { | ||
font-family: Arial, sans-serif; | ||
margin: 0; | ||
padding: 20px; | ||
background-color: #f5f5f5; | ||
color: #333; | ||
} | ||
|
||
#prompt-container { | ||
background-color: #fff; | ||
padding: 15px; | ||
border-radius: 5px; | ||
box-shadow: 0 2px 10px rgba(0, 0, 0, 0.2); | ||
} | ||
|
||
#message { | ||
margin-bottom: 20px; | ||
} | ||
|
||
#input-section, #confirm-section { | ||
display: flex; | ||
justify-content: space-between; | ||
align-items: center; | ||
margin-bottom: 10px; | ||
} | ||
|
||
#user-input { | ||
width: 70%; | ||
padding: 8px; | ||
border: 1px solid #ddd; | ||
border-radius: 4px; | ||
box-sizing: border-box; | ||
} | ||
|
||
button { | ||
padding: 10px 15px; | ||
border: none; | ||
border-radius: 4px; | ||
cursor: pointer; | ||
background-color: #4285f4; | ||
color: white; | ||
min-width: 80px; | ||
} | ||
|
||
button:hover { | ||
background-color: #357ae8; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
<head> | ||
<title>User Prompt</title> | ||
<link rel="stylesheet" type="text/css" href="prompt.css"> | ||
</head> | ||
<body> | ||
<div id="prompt-container"> | ||
<p id="message"></p> | ||
|
||
<div id="confirm-section" style="display: none;"> | ||
<button id="confirm-yes">Yes</button> | ||
<button id="confirm-no">No</button> | ||
</div> | ||
|
||
<div id="input-section" style="display: none;"> | ||
<input type="text" id="user-input" /> | ||
<button id="submit-button">Submit</button> | ||
<button id="cancel-button">Cancel</button> | ||
</div> | ||
</div> | ||
<script src="prompt.js"></script> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
/* eslint-disable */ | ||
document.addEventListener('DOMContentLoaded', () => { | ||
const params = new URLSearchParams(window.location.search) | ||
const message = params.get('message') | ||
const inputType = params.get('inputType') | ||
const windowId = parseInt(params.get('windowId')); | ||
|
||
document.getElementById('message').textContent = message | ||
|
||
const userInput = document.getElementById('user-input') | ||
const confirmSection = document.getElementById('confirm-section') | ||
const inputSection = document.getElementById('input-section') | ||
const submitButton = document.getElementById('submit-button') | ||
|
||
if (inputType === 'text' || inputType === 'password') { | ||
userInput.setAttribute('type', inputType) | ||
inputSection.style.display = 'flex' // Show input section | ||
} else if (inputType === 'confirmation') { | ||
confirmSection.style.display = 'flex' // Show confirmation section | ||
} | ||
|
||
submitButton.addEventListener('click', () => { | ||
chrome.runtime.sendMessage({ | ||
windowId: windowId, | ||
userInput: userInput.value | ||
}) | ||
window.close() | ||
}) | ||
|
||
document.getElementById('confirm-yes').addEventListener('click', () => { | ||
chrome.runtime.sendMessage({ | ||
windowId: windowId, | ||
userConfirmed: true | ||
}) | ||
window.close() | ||
}) | ||
|
||
document.getElementById('confirm-no').addEventListener('click', () => { | ||
chrome.runtime.sendMessage({ | ||
windowId: windowId, | ||
userConfirmed: false | ||
}) | ||
window.close() | ||
}) | ||
|
||
document.getElementById('cancel-button').addEventListener('click', () => { | ||
chrome.runtime.sendMessage({ | ||
windowId: windowId, | ||
userRejected: true | ||
}) | ||
window.close() | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,91 @@ | ||
import { MinaProvider } from '@palladxyz/web-provider' | ||
import { onMessage } from 'webext-bridge/background' | ||
import { runtime } from 'webextension-polyfill' | ||
|
||
// options should be defined by user | ||
const opts = { | ||
projectId: 'test', | ||
chains: ['Mina - Berkeley'] | ||
} | ||
const provider = await MinaProvider.init(opts, []) | ||
|
||
// Does this do anything? | ||
runtime.onInstalled.addListener(() => { | ||
onMessage('mina_chainId', () => { | ||
return 'Berkeley' | ||
onMessage('enable', async () => { | ||
console.log('test enable method') | ||
return await provider.enable() | ||
}) | ||
}) | ||
|
||
// Register message handlers directly, not inside any other callback | ||
onMessage('enable', async () => { | ||
console.log('test enable method') | ||
return await provider.enable() | ||
}) | ||
|
||
onMessage('mina_setState', async () => { | ||
console.log('test mina_setState method') | ||
//return await provider.request({ method: 'mina_setState', params: data }) | ||
return 'TODO: implement mina_setState' | ||
}) | ||
|
||
onMessage('mina_getState', async () => { | ||
console.log('test mina_getState method') | ||
//return await provider.request({ method: 'mina_getState' }) | ||
return { | ||
credential: { | ||
name: 'Pallad', | ||
proof: { | ||
publicInputs: [1], | ||
publicOutputs: [100], | ||
proof: '1hjdjf83...fjf' | ||
} | ||
} | ||
} | ||
}) | ||
|
||
onMessage('isConnected', async () => { | ||
console.log('test isConnected method') | ||
return await provider.isConnected() | ||
}) | ||
|
||
onMessage('mina_chainId', async () => { | ||
console.log('test mina_chainId method') | ||
return await provider.request({ method: 'mina_chainId' }) | ||
}) | ||
|
||
onMessage('mina_accounts', async () => { | ||
console.log('test mina_accounts method') | ||
return await provider.request({ method: 'mina_accounts' }) | ||
}) | ||
|
||
onMessage('mina_sign', async (data) => { | ||
console.log('test mina_sign method') | ||
return await provider.request({ method: 'mina_sign', params: data }) | ||
}) | ||
|
||
onMessage('mina_signFields', async (data) => { | ||
console.log('test mina_signFields method') | ||
return await provider.request({ method: 'mina_signFields', params: data }) | ||
}) | ||
|
||
onMessage('mina_signTransaction', async (data) => { | ||
console.log('test mina_signTransaction method') | ||
return await provider.request({ | ||
method: 'mina_signTransaction', | ||
params: data | ||
}) | ||
}) | ||
|
||
onMessage('mina_getBalance', async () => { | ||
console.log('test mina_getBalance method') | ||
return await provider.request({ method: 'mina_getBalance' }) | ||
}) | ||
|
||
onMessage('mina_createNullifier', async (data) => { | ||
console.log('test mina_createNullifier method') | ||
return await provider.request({ | ||
method: 'mina_createNullifier', | ||
params: data | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.