//public Task<byte[]> decrypt(object algorithm, CryptoKey key, byte[] data)
        public IPromise<ArrayBuffer> decrypt(object algorithm, CryptoKey key, byte[] data)
        {
            // as jsc is transforming Delegate to IFunction
            // could we do the same for Promise to Task on return?

            return null;
        }
        // Promise encrypt(Dictionary algorithm, CryptoKey key, ArrayBuffer data);
        //public IPromise<byte[]> encrypt(object algorithm, CryptoKey key, byte[] data)
        public IPromise<ArrayBuffer> encrypt(object algorithm, CryptoKey key, byte[] data)
        {
            // X:\jsc.svn\examples\javascript\Test\TestWebCryptoEncryption\TestWebCryptoEncryption\Application.cs

            return null;
        }
        //[CallWith=ScriptState, ImplementedAs=verifySignature, MeasureAs=SubtleCryptoVerify] Promise verify(AlgorithmIdentifier algorithm, CryptoKey key, BufferSource signature, BufferSource data);
        public IPromise<bool> verify(object algorithm, CryptoKey key, byte[] signature, byte[] data)
        {
            // X:\jsc.svn\examples\javascript\Test\TestWebCryptoEncryption\TestWebCryptoEncryption\Application.cs

            return null;
        }
        //Promise<any> exportKey(KeyFormat format, CryptoKey key)
        public IPromise<object> exportKey(string format, CryptoKey key)
        {
            // X:\jsc.svn\examples\javascript\Test\TestWebCryptoKeyExport\TestWebCryptoKeyExport\Application.cs

            return null;
        }
        // jsc should translate Tasks to Promises if defined on Native apis?
        public static Task<bool> verifyAsync(
            this SubtleCrypto that,

            CryptoKey publicKey, byte[] signature, byte[] data)
        {
            // Z:\jsc.svn\examples\javascript\crypto\ClientVerifiedWebServiceAuthority\ClientVerifiedWebServiceAuthority\Application.cs
            var x = new TaskCompletionSource<bool>();

            Native.crypto.subtle.verify(
                 new
                 {
                     name = "RSASSA-PKCS1-v1_5",
                 },
                publicKey, //from generateKey or importKey above
                signature, //ArrayBuffer of the signature
                //Encoding.UTF8.GetBytes(x.value) //ArrayBuffer of the data
                data //ArrayBuffer of the data

            ).then(

            onSuccess: verified =>
                {
                    x.SetResult(verified);

                }
            );

            return x.Task;
        }
        public static Task<byte[]> decryptAsync(
            this SubtleCrypto that,

            object algorithm, CryptoKey key, byte[] data
        )
        {
            Console.WriteLine(
             "enter decryptAsync"
             );

            var x = new TaskCompletionSource<byte[]>();
            var promise = that.decrypt(algorithm, key, data);

            // android webview wont like .catch
            promise.@catch(
                err =>
                {// X:\jsc.svn\examples\javascript\Test\TestWebCryptoKeyExport\TestWebCryptoKeyExport\Application.cs
                    // setexception?

                    Console.WriteLine(
                        "decryptAsync " + new { err }
                        );
                }
            );

            // tested by?
            promise.then(
                z => { x.SetResult(z); }
            );

            return x.Task;
        }
        // X:\jsc.svn\examples\javascript\Test\TestWebCryptoEncryption\TestWebCryptoEncryption\Application.cs
        public static Task<byte[]> encryptAsync(
                this SubtleCrypto that,

                object algorithm, CryptoKey key, byte[] data
            )
        {
            var x = new TaskCompletionSource<byte[]>();
            var promise = that.encrypt(algorithm, key, data);

            promise.then(
                z => { x.SetResult(z); }
            );

            return x.Task;
        }
        // what an ugly name. keep it?
        public static Task<JsonWebKey> exportJSONWebKeyAsync(
        this SubtleCrypto that,

        CryptoKey key
    )
        {
            // X:\jsc.svn\examples\javascript\Test\TestWebCryptoKeyExport\TestWebCryptoKeyExport\Application.cs

            var x = new TaskCompletionSource<JsonWebKey>();
            var promise = that.exportKey("jwk", key);

            promise.then(
                z => { x.SetResult((JsonWebKey)z); }
            );

            return x.Task;
        }