Skip to content

Commit

Permalink
trying to get wallet signature working
Browse files Browse the repository at this point in the history
  • Loading branch information
ardan-bkennedy committed Mar 14, 2024
1 parent 809d580 commit 04852dd
Show file tree
Hide file tree
Showing 3 changed files with 102 additions and 21 deletions.
93 changes: 81 additions & 12 deletions app/services/ui/assets/html/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -24,29 +24,98 @@
.then((res) => console.log('request accounts', res))
.catch((e) => console.log('request accounts ERR', e));
}

function accounts() {
ethereum
.request({
method: 'eth_accounts',
params: [],
})
.then((res) => console.log('accounts', res))
.catch((e) => console.log('accounts ERR', e));
}

function addEthereumChain() {
function personalSign() {
ethereum
.request({
method: 'wallet_addEthereumChain',
method: 'eth_signTypedData_v4',
params: [
"0x6327a38415c53ffb36c11db55ea74cc9cb4976fd",
{
chainId: '0x89',
chainName: 'Polygon',
blockExplorerUrls: ['https://polygonscan.com'],
nativeCurrency: { symbol: 'MATIC', decimals: 18 },
rpcUrls: ['https://polygon-rpc.com/'],
"types": {
"EIP712Domain": [
{
"name": "name",
"type": "string"
},
{
"name": "version",
"type": "string"
},
{
"name": "chainId",
"type": "uint256"
},
{
"name": "verifyingContract",
"type": "address"
}
],
"Person": [
{
"name": "name",
"type": "string"
},
{
"name": "wallet",
"type": "address"
}
],
"Mail": [
{
"name": "from",
"type": "Person"
},
{
"name": "to",
"type": "Person"
},
{
"name": "contents",
"type": "string"
}
]
},
"primaryType": "Mail",
"domain": {
"name": "Ether Mail",
"version": "1",
"chainId": 1,
"verifyingContract": "0xCcCCccccCCCCcCCCCCCcCcCccCcCCCcCcccccccC"
},
],
"message": {
"from": {
"name": "Cow",
"wallet": "0xCD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826"
},
"to": {
"name": "Bob",
"wallet": "0xbBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB"
},
"contents": "Hello, Bob!"
}
}
]
})
.then((res) => console.log('add', res))
.catch((e) => console.log('ADD ERR', e));
.then((res) => console.log('personal sign', res))
.catch((e) => console.log('personal sign ERR', e));
}
</script>
</head>
<body>
<h1>Testing Metamask Wallet</h1>
<h1>Testing Metamask Wallet 3</h1>
<button onclick="connect()">Connect</button>
<button onclick="addEthereumChain()">ADD ETHEREUM CHAIN</button>
<button onclick="accounts()">Accounts</button>
<button onclick="personalSign()">Sign Data</button>
</body>
</html>
19 changes: 13 additions & 6 deletions app/services/ui/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"embed"
"fmt"
"html/template"
"net/http"
"os"
"os/signal"
Expand Down Expand Up @@ -54,13 +53,21 @@ func main() {
var documents embed.FS

func show(w http.ResponseWriter, r *http.Request) {
tmpl, err := template.New("").ParseFS(documents, "assets/html/index.html")
// tmpl, err := template.New("").ParseFS(documents, "assets/html/index.html")
// if err != nil {
// http.Error(w, "Parse: "+err.Error(), http.StatusInternalServerError)
// return
// }

// if err := tmpl.ExecuteTemplate(w, "index.html", nil); err != nil {
// http.Error(w, "Exec:"+err.Error(), http.StatusInternalServerError)
// }

d, err := os.ReadFile("app/services/ui/assets/html/index.html")
if err != nil {
http.Error(w, "Parse: "+err.Error(), http.StatusInternalServerError)
http.Error(w, "Read: "+err.Error(), http.StatusInternalServerError)
return
}

if err := tmpl.ExecuteTemplate(w, "index.html", nil); err != nil {
http.Error(w, "Exec:"+err.Error(), http.StatusInternalServerError)
}
w.Write(d)
}
11 changes: 8 additions & 3 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,15 @@
# The coinbase address is the account to pay mining rewards to.
# The coinbase address is given a LOT of money to start.
#
# Create new accounts (use 123 as passphrase)
# geth account new --keystore zarf/ethereum/keystore
#
# For more ethereum calls look at the smart contract project
#
# WE NEED THESE VERSIONS OF THESE MODULES.
# github.com/crate-crypto/go-ipa v0.0.0-20231205143816-408dbffb2041 // indirect
# github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
# github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 // indirect
# github.com/crate-crypto/go-ipa v0.0.0-20231205143816-408dbffb2041 // indirect
# github.com/crate-crypto/go-kzg-4844 v0.7.0 // indirect
# github.com/cockroachdb/pebble v0.0.0-20230928194634-aa077af62593 // indirect

GOLANG := golang:1.22
NODE := node:16
Expand Down

0 comments on commit 04852dd

Please sign in to comment.