@openrelay/web3-sign-element v0.1.1
layout: widget title: "Web3 Signature" date: 2018-09-26 08:15:00 -0500 categories: widgets code: html: |
<or-web3>
<or-web3-sign rawMessage="Hello world!"></or-web3-sign>
<ul>
<li>Signature: <span id="signature"></span>
<li>Error: <span id="error"></span>
</ul>
</or-web3>
js: |
let signButton = demoDoc.querySelector("or-web3-sign");
signButton.addEventListener("sign", function(event) {
demoDoc.querySelector("#error").innerHTML = event.detail.error;
demoDoc.querySelector("#signature").innerHTML = event.detail.signature;
});
npm:
"@openrelay/web3-sign-element"
The <or-web3-sign>
element provides a button users can click to sign a
message. This will trigger the user's web3 client to prompt for a signature of
the message attribute of the <or-web3-sign>
element.
Signature Format
The signature will be a byte string of the following data:
start | length | description |
---|---|---|
0 | 1 | The v component of an ECDSA signature |
1 | 32 | The r component of an ECDSA signature |
33 | 32 | The s component of an ECDSA signature |
66 | 1 | The 0x signature type |
The signature type will depend on the Web3 client. For clients that prefix
signed messages with \x19Ethereum Signed Message:\n32
, the signature type
will be 03
for the EthSign signature type. For clients that do not prefix
signed messages, the signature type will be 02
for the EIP712 signature type.
Note that at this time the <or-web3-sign>
does not use EIP712 to sign
messages, but signing an EIP712 hash without a prefix produces the same output
as using EIP712 to produce the signature.
API
HTML Attributes
message
— A 32 byte, hex encoded message to be signed.rawMessage
(optional) — An arbitrary string that will be keccak256 hashed to fill in the message attribute.
Note that only one of message
or rawMessage
should be provided.
Events
Outgoing Events
sign
— Fired when the user successfully signs a message. The signature can be found ate.detail.signature
. If the user rejects the signature, or signing otherwise fails, an error will be emitted ate.detail.error
.