To request text be signed, submit the form below.
crypto.signText()
returns a Promise
which, when resolved,
contains the signed text.
Use the Redwax SignText web extension to allow signing of arbitrary text using a digital certificate.
The following example form shows how to trigger crypto.signText()
to sign the given text.
To request text be signed, submit the form below.
crypto.signText()
returns a Promise
which, when resolved,
contains the signed text.
To detect presence of the API, call crypto.signText()
without
any parameters. If you receive a Promise
in return, the new
API is present..
The original crypto.signText()
as implemented by Netscape and then
Firefox returned a string
instead of a Promise
. The
following code shows the legacy behaviour, and should not be used in modern code.
The following form detects the return value from crypto.signText()
.
If we detect a string
, we populate the field immediately, otherwise
we resolve the promise returned. This form should work on both new and legacy
browsers.
The javascript used to trigger the crypto.signText()
functionality can be downloaded here, and is included
for reference below.
function signRequest(form) {
if (crypto.signText) {
crypto.signText(form['tobesigned'].value).then(response => { form['signed'].value = response });
}
else {
alert('An implementation of crypto.signText() is not installed in this browser.');
}
}
function detectRequest(form) {
if (crypto.signText) {
crypto.signText().then(response => form['detected'].value = response.name + ' v' + response.version);
}
else {
alert('An implementation of crypto.signText() is not installed in this browser.');
}
}
function signLegacyRequest(form) {
if (crypto.signText) {
form['legacysigned'].value = crypto.signText(form['tobelegacysigned'].value, 'ask');
return true;
}
else {
alert('An implementation of crypto.signText() is not installed in this browser.');
}
}
function signCombinedRequest(form) {
if (crypto.signText) {
value = crypto.signText(form['tobecombinedsigned'].value, 'ask');
if (typeof value === 'string') {
form['combinedsigned'].value = value;
}
else {
value.then(response => { form['combinedsigned'].value = response }).catch(error => {alert(error)});
}
return true;
}
else {
alert('An implementation of crypto.signText() is not installed in this browser.');
}
}