Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
baas-ide
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
JIRA
JIRA
Merge Requests
1
Merge Requests
1
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
guxukai
baas-ide
Commits
e6918e3f
Unverified
Commit
e6918e3f
authored
Aug 23, 2018
by
yann300
Committed by
GitHub
Aug 23, 2018
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1474 from oogetyboogety/master
Add ability to sign messages for web3 providers and Javascript VM
parents
12dbc719
19eabeee
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
64 additions
and
0 deletions
+64
-0
run-tab.js
src/app/tabs/run-tab.js
+64
-0
No files found.
src/app/tabs/run-tab.js
View file @
e6918e3f
...
...
@@ -13,6 +13,8 @@ var helper = require('../../lib/helper.js')
var
executionContext
=
require
(
'../../execution-context'
)
var
modalDialogCustom
=
require
(
'../ui/modal-dialog-custom'
)
var
copyToClipboard
=
require
(
'../ui/copy-to-clipboard'
)
const
Buffer
=
require
(
'safe-buffer'
).
Buffer
var
Personal
=
require
(
'web3-eth-personal'
)
var
Card
=
require
(
'../ui/card'
)
var
Recorder
=
require
(
'../../recorder'
)
var
addTooltip
=
require
(
'../ui/tooltip'
)
...
...
@@ -527,6 +529,7 @@ function settings (container, self) {
<div class=
${
css
.
account
}
>
<select name="txorigin" class="
${
css
.
select
}
" id="txorigin"></select>
${
copyToClipboard
(()
=>
document
.
querySelector
(
'#runTabView #txorigin'
).
value
)}
<i class="fa fa-pencil-square-o
${
css
.
icon
}
" aria-hiden="true" onclick=
${
signMessage
}
title="Sign a message using this account key"></i>
</div>
</div>
`
...
...
@@ -625,6 +628,67 @@ function settings (container, self) {
}
})
}
function
signMessage
(
event
)
{
self
.
_deps
.
udapp
.
getAccounts
((
err
,
accounts
)
=>
{
if
(
err
)
{
addTooltip
(
`Cannot get account list:
${
err
}
`
)
}
var
signMessageDialog
=
{
'title'
:
'Sign a message'
,
'text'
:
'Enter a message to sign'
,
'inputvalue'
:
'Message to sign'
}
var
$txOrigin
=
container
.
querySelector
(
'#txorigin'
)
var
account
=
$txOrigin
.
selectedOptions
[
0
].
value
var
isVM
=
executionContext
.
isVM
()
var
isInjected
=
executionContext
.
getProvider
()
===
'injected'
function
alertSignedData
(
error
,
hash
,
signedData
)
{
if
(
error
&&
error
.
message
!==
''
)
{
console
.
log
(
error
)
addTooltip
(
error
.
message
)
}
else
{
modalDialogCustom
.
alert
(
yo
`<div><b>hash:</b>
${
hash
}
<br><b>signature:</b>
${
signedData
}
</div>`
)
}
}
if
(
isVM
)
{
modalDialogCustom
.
promptMulti
(
signMessageDialog
,
(
message
)
=>
{
const
personalMsg
=
ethJSUtil
.
hashPersonalMessage
(
Buffer
.
from
(
message
))
var
privKey
=
self
.
_deps
.
udapp
.
accounts
[
account
].
privateKey
try
{
var
rsv
=
ethJSUtil
.
ecsign
(
personalMsg
,
privKey
)
var
signedData
=
ethJSUtil
.
toRpcSig
(
rsv
.
v
,
rsv
.
r
,
rsv
.
s
)
alertSignedData
(
null
,
'0x'
+
personalMsg
.
toString
(
'hex'
),
signedData
)
}
catch
(
e
)
{
addTooltip
(
e
.
message
)
return
}
},
false
)
}
else
if
(
isInjected
)
{
modalDialogCustom
.
promptMulti
(
signMessageDialog
,
(
message
)
=>
{
const
hashedMsg
=
executionContext
.
web3
().
sha3
(
message
)
try
{
executionContext
.
web3
().
eth
.
sign
(
account
,
hashedMsg
,
(
error
,
signedData
)
=>
{
alertSignedData
(
error
,
hashedMsg
,
signedData
)
})
}
catch
(
e
)
{
addTooltip
(
e
.
message
)
console
.
log
(
e
)
return
}
})
}
else
{
modalDialogCustom
.
promptPassphrase
(
'Passphrase to sign a message'
,
'Enter your passphrase for this account to sign the message'
,
''
,
(
passphrase
)
=>
{
modalDialogCustom
.
promptMulti
(
signMessageDialog
,
(
message
)
=>
{
const
hashedMsg
=
executionContext
.
web3
().
sha3
(
message
)
try
{
var
personal
=
new
Personal
(
executionContext
.
web3
().
currentProvider
)
personal
.
sign
(
hashedMsg
,
account
,
passphrase
,
(
error
,
signedData
)
=>
{
alertSignedData
(
error
,
hashedMsg
,
signedData
)
})
}
catch
(
e
)
{
addTooltip
(
e
.
message
)
console
.
log
(
e
)
return
}
})
},
false
)
}
})
}
return
el
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment