Add test & set version

This commit is contained in:
microshine
2016-05-09 12:28:15 +03:00
parent 634752a79e
commit df611346dd
2 changed files with 57 additions and 0 deletions
+47
View File
@@ -0,0 +1,47 @@
/// <reference path="./xadesjs.d.ts" />
let xmlString = "<root><child1/><child2/><child3/></root>";
let xmlDoc = new DOMParser().parseFromString(xmlString, "application/xml");
let signedXml = new xadesjs.SignedXml(xmlDoc);
let alg = {
name: "ECDSA",
namedCurve: "P-256"
};
xadesjs.Application.crypto.subtle.generateKey(
alg,
false,
["sign", "verify"]
)
.then((keys: CryptoKeyPair) => {
signedXml.SigningKey = keys.privateKey;
// Add the key to the SignedXml document.
// Create a reference to be signed.
let reference = new xadesjs.Reference();
reference.Uri = "";
// Add an enveloped transformation to the reference.
reference.AddTransform(new xadesjs.XmlDsigEnvelopedSignatureTransform());
// Add the reference to the SignedXml object.
signedXml.AddReference(reference);
// Set prefix for Signature namespace
signedXml.Prefix = "ds";
// Compute the signature.
return signedXml.ComputeSignature({ name: "ECDSA", hash: { name: "SHA-256" } } as any);
})
.then(function () {
// Append signature
let xmlDigitalSignature = signedXml.GetXml();
xmlDoc.documentElement.appendChild(xmlDigitalSignature);
// Serialize XML document
let signedDocument = new XMLSerializer().serializeToString(xmlDoc);
return Promise.resolve(signedDocument);
})
.then((doc: string) => {
console.log("Signed document:", doc);
})
.catch((e) => {
console.error("Error", e);
})
+10
View File
@@ -1,5 +1,15 @@
// Type definitions for graphene-pk11 v2.0.0
// Project: https://github.com/PeculiarVentures/graphene
// Definitions by: Stepan Miroshin <https://github.com/microshine>
// Definitions: https://github.com/borisyankov/DefinitelyTyped
/// <reference path="./promise.d.ts" />
/**
* A pure Javascript implementation of XMLDSIG and XAdES based on Web Crypto https://xadesjs.com
* v1.0.0
*/
declare namespace xadesjs {
const APPLICATION_XML: string;