Skip to content

Commit 62ca85d

Browse files
author
Weiwu Zhang
committedApr 8, 2021
using ES module instead of nodejs require (for webpack). Also making the folder structure webpack friendly
1 parent 90322a6 commit 62ca85d

File tree

5 files changed

+51
-45
lines changed

5 files changed

+51
-45
lines changed
 

‎xmldsig/js/README.md

+25-7
Original file line numberDiff line numberDiff line change
@@ -7,32 +7,50 @@ demonstration on how to verify xmldsig with JavaScript code.
77

88
First, make sure your nodejs is above version 15.0.0 where [WebCrypto was introduced](https://www.nearform.com/blog/implementing-the-web-cryptography-api-for-node-js-core/)
99

10-
Then, install the dependencies
10+
Then, install the dependencies in the `src` directory:
1111

1212
````
13-
$ npm install
13+
src$ npm install
1414
````
1515

16-
Finally, apply an xmldom patch for [a known bug](https://github.com/xmldom/xmldom/issues/203). Note that this patch is destructive, the resulting xmldom won't work properly on html files (which we don't use in our case). Such a patch will not be needed (hence will be deleted from this repo) when xmldom release the next version after 0.5.0.
16+
Finally, also in `src`, apply an xmldom patch for [a known bug](https://github.com/xmldom/xmldom/issues/203). Note that this patch is destructive, the resulting xmldom won't work properly on html files (which we don't use in our case). Such a patch will not be needed (hence will be deleted from this repo) when xmldom release the next version after 0.5.0.
1717

1818
````
19-
$ patch -p0 < xmldom.patch
19+
src$ patch -p0 < xmldom.patch
2020
````
2121

2222
## Test ##
2323

2424
Let's say you have a bunch of signed TokenScripts residing in `../../../TokenScript-Repo/aw.app/2020/06/` (which you can get by checking out [TokenScript-Repo](https://github.com/AlphaWallet/TokenScript-Repo)). Run the files through the `xmldsigverifier.js` script:
2525

2626
````
27-
$ node xmldsigverifier.js ../../../TokenScript-Repo/aw.app/2020/06/*
27+
src$ node xmldsigverifier.js ../../../TokenScript-Repo/aw.app/2020/06/*
2828
[ OK ] ../../../TokenScript-Repo/aw.app/2020/06/aDAI.tsml
2929
[ OK ] ../../../TokenScript-Repo/aw.app/2020/06/cBAT.tsml
3030
3131
[ OK ] ../../../TokenScript-Repo/aw.app/2020/06/WETH.tsml
3232
````
3333

34+
## Creating a webpack ##
35+
36+
Somehow webpack version >5 requires further configuration which hasn't been done, so make sure you use an earlier version of webpack, such as 4.44.2. Run `webpack` at this level, that is, not under `src` directory:
37+
38+
39+
````
40+
$ webpack
41+
Hash: 5f6510c90828ac124c4f
42+
Version: webpack 4.44.2
43+
Time: 8110ms
44+
Built at: 08/04/2021 11:31:47
45+
Asset Size Chunks Chunk Names
46+
main.js 1.1 MiB 0 [emitted] [big] main
47+
Entrypoint main [big] = main.js
48+
````
49+
50+
The resulting file should be `dist/main.js`.
51+
3452
## Work in progress ##
3553

36-
- Because this signature verifier doesn't check the certificates, the result is not an indication whether or not the TokenScript is signed with the correct key. More work needs to be done to use it in production environment.
54+
- It currently fails with ECDSA signatures.
3755

38-
- A version that can run in the web browser is needed.
56+
- Because this signature verifier doesn't check the certificates, the result is not an indication whether or not the TokenScript is signed with the correct key. More work needs to be done to use it in production environment.

‎xmldsig/js/package.json renamed to ‎xmldsig/js/src/package.json

+1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
2+
"type": "module",
23
"engines": {
34
"node": ">=0.15"
45
},
File renamed without changes.

‎xmldsig/js/src/xmldsigverifier.js

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
"use strict";
2+
3+
import fs from 'fs';
4+
import verify from './index.js';
5+
6+
if (process.argv.length == 2) {
7+
console.log("xmldsigverifier demonstration script. Need parameters - xml files with enveloped signatures")
8+
}
9+
10+
for (var i=2; i<process.argv.length; i++) {
11+
const filename = process.argv[i];
12+
verify(fs.readFileSync(filename).toString())
13+
.then(res => {
14+
if (res == true) {
15+
console.log("[ OK ] " + filename);
16+
} else {
17+
console.log("[FAILED] " + filename);
18+
}
19+
})
20+
.catch(e => {
21+
console.log("[ERROR ] " + filename);
22+
console.log(e)
23+
});
24+
}
25+

‎xmldsig/js/xmldsigverifier.js

-38
This file was deleted.

0 commit comments

Comments
 (0)
Please sign in to comment.