-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
77 lines (70 loc) · 2.19 KB
/
index.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
<!doctype html>
<html>
<head>
<title>Hello, Snaps!</title>
</head>
<body>
<h1>Hello, Snaps!</h1>
<button class="connect">Connect</button>
<button class="getPubkey">Get public key</button>
<button class="sign">Sign message</button>
<script>
const snapId = `local:${window.location.href}`;
const connectButton = document.querySelector('button.connect')
const getPubkeyButton = document.querySelector('button.getPubkey')
const signButton = document.querySelector('button.sign')
connectButton.addEventListener('click', connect)
getPubkeyButton.addEventListener('click', getPubkey)
signButton.addEventListener('click', sign)
// here we get permissions to interact with and install the snap
async function connect () {
await ethereum.request({
method: 'wallet_requestSnaps',
params: { [snapId]: {} }
})
}
async function getPubkey () {
try {
const response = await ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId,
request: {
method: 'getPublicKey',
params: {
derivationPath: [`0'`, `0'`, `0'`],
confirm: true
}
}
}
})
console.log(response);
} catch (err) {
console.error(err)
alert('Problem happened: ' + err.message || err)
}
}
async function sign () {
try {
const response = await ethereum.request({
method: 'wallet_invokeSnap',
params: {
snapId,
request: {
method: 'signMessage',
params: {
derivationPath: [`0'`, `0'`, `0'`],
message: '0x4150544f530a6d6573736167653a2048656c6c6f2066726f6d206163636f756e74203078663131366664313134653465363238346238383439306234393839393534346534613166346266643564663533373434616633303863383837313134306137300a6e6f6e63653a2072616e646f6d5f737472696e67'
}
}
}
})
console.log(response);
} catch (err) {
console.error(err)
alert('Problem happened: ' + err.message || err)
}
}
</script>
</body>
</html>