-
Notifications
You must be signed in to change notification settings - Fork 0
/
SignMessage.vue
79 lines (78 loc) · 2.27 KB
/
SignMessage.vue
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
78
79
<template>
<b-container fluid class="p-3">
<b-form @submit="signToken">
<b-input-group prepend="Token ID">
<b-form-input v-model="token.id" placeholder="Enter NFT Token ID"></b-form-input>
<b-input-group-append>
<b-form-select v-model="token.contract" :options="contracts" class="bg-secondary text-white">
<template #first>
<b-form-select-option :value="null" disabled>-- Select a token type --</b-form-select-option>
</template>
</b-form-select>
<b-button variant="info" type="submit">Sign</b-button>
</b-input-group-append>
</b-input-group>
</b-form>
<b-card class="mt-3 text-start" header="Token Signature" v-if="message">
<pre class="m-0">{{ message }}</pre>
</b-card>
<b-card class="mt-3 text-start" header="Signature Error" v-if="error">
<pre class="m-0">{{ error }}</pre>
</b-card>
<b-card class="mt-3 text-start" header="Signature Verification" v-if="verification">
<pre class="m-0">{{ verification }}</pre>
</b-card>
</b-container>
</template>
<script>
import { signMessage, verifyToken, getContracts } from '../services/SigService'
export default {
name: 'SignMessage',
data() {
return {
token: {
id: '',
contract: null
},
contracts: [],
message: null,
error: null,
verification: null
}
},
watch: {
message(newValue) {
if (newValue.signature) {
verifyToken(newValue).then(result => {
this.verification = result;
})
}
}
},
methods: {
signToken() {
signMessage(this.token.id, this.token.contract).then(result => {
if (result.error) {
this.error = {error: result.error}
this.message = null
} else {
this.error = null
this.message = {
tokenId: this.token.id,
contract: this.token.contract,
signature: result.signature,
signer: result.address
}
}
})
}
},
mounted() {
console.log("SignMessage mount - get contract list !!!!")
getContracts().then(data => {
this.contracts = data.map(x => ({value: x.address, text: x.name}));
console.log(this.contracts);
})
}
}
</script>