TokenScript icon indicating copy to clipboard operation
TokenScript copied to clipboard

find out how to run this JavaScript code on iOS/Android

Open SmartLayer opened this issue 3 years ago • 0 comments

Go to xmldsig/js/src to play it yourself. The readme there should be enough guidance for you to run the JavaScript, providing many signed XML files (signed TokenScripts) and verify the signature of each.

(Optional) witness that xmldsig verification with JS works on commandline

Follow the instructions here:

https://github.com/TokenScript/TokenScript/tree/main/xmldsig/js

This way you can be sure the code demonstrated in https://github.com/TokenScript/TokenScript/blob/main/xmldsig/js/src/xmldsigverifier.js can verify XML signature.

Now the problem is how to make iOS/Android run this code. Android is secondary because it already can verify XMLDSIG.

How to take working node.js code to iOS is unknown to me. One thing for sure, the node.js code, in this case 16 lines https://github.com/TokenScript/TokenScript/blob/main/xmldsig/js/src/index.js is not pure JavaScript code that can run everywhere without treatment, because

  1. It has dependencies, in this case XMLDSIG
  2. It has dependencies in node "Core" modules.

Use webpack?

Webpack (before version 5) suggested that they can package core modules with polyfills.

Create a webpack. There is the instruction in README but I already created one on my PC which you can use here, saving you the trouble of running webpack.

main.js.gz

Since this webpack is created from index.js, it should contain the verify function (which is called from the said xmldsigverifier.js) but not the xmldsigverifier.js itself.

But it is a mystery how to call that verify() function theoretically included in main.js. I created one such HTML file:

<html>
        <script scr="main.js" type="text/javascript"></script>
        <script type="text/javascript">
                window.onload = function(e) {
                        console.log(verify("hello"));
                }
        </script>
</html>

I was expecting verify() to fail but I got "verify()" undefined.

Since webpack is created for web developers, there should be a way to call a function packed in a webpack?

SmartLayer avatar Apr 09 '21 06:04 SmartLayer