Class NGEPlatform


  • public abstract class NGEPlatform
    extends java.lang.Object
    • Constructor Detail

      • NGEPlatform

        public NGEPlatform()
    • Method Detail

      • set

        public static void set​(NGEPlatform platform)
      • setBrowserInterceptor

        public static void setBrowserInterceptor​(BrowserInterceptor interceptor)
      • setStoreInterceptor

        public static void setStoreInterceptor​(VStoreInterceptor interceptor)
      • generatePrivateKey

        public abstract byte[] generatePrivateKey()
      • genPubKey

        public abstract byte[] genPubKey​(byte[] secKey)
      • toJSON

        public abstract java.lang.String toJSON​(java.util.Collection obj)
      • toJSON

        public abstract java.lang.String toJSON​(java.util.Map obj)
      • fromJSON

        public abstract <T> T fromJSON​(java.lang.String json,
                                       java.lang.Class<T> claz)
      • secp256k1SharedSecret

        public abstract byte[] secp256k1SharedSecret​(byte[] privKey,
                                                     byte[] pubKey)
      • hmac

        public abstract byte[] hmac​(byte[] key,
                                    byte[] data1,
                                    byte[] data2)
      • hkdf_extract

        public abstract byte[] hkdf_extract​(byte[] salt,
                                            byte[] ikm)
      • hkdf_expand

        public abstract byte[] hkdf_expand​(byte[] prk,
                                           byte[] info,
                                           int length)
      • base64encode

        public abstract java.lang.String base64encode​(byte[] data)
      • base64decode

        public abstract byte[] base64decode​(java.lang.String data)
      • chacha20

        public abstract byte[] chacha20​(byte[] key,
                                        byte[] nonce,
                                        byte[] data,
                                        boolean forEncryption)
      • newRTCTransport

        public abstract RTCTransport newRTCTransport​(RTCSettings settings,
                                                     java.lang.String connId,
                                                     java.util.Collection<java.lang.String> stunServers)
      • sha256

        public abstract java.lang.String sha256​(java.lang.String data)
      • sha256

        public abstract byte[] sha256​(byte[] data)
      • verify

        public abstract boolean verify​(java.lang.String data,
                                       java.lang.String sign,
                                       byte[] pubKey)
      • signAsync

        public abstract AsyncTask<java.lang.String> signAsync​(java.lang.String data,
                                                              byte[] privKey)
      • verifyAsync

        public abstract AsyncTask<java.lang.Boolean> verifyAsync​(java.lang.String data,
                                                                 java.lang.String sign,
                                                                 byte[] pubKey)
      • randomBytes

        public abstract byte[] randomBytes​(int n)
      • newAsyncExecutor

        public final AsyncExecutor newAsyncExecutor()
      • newAsyncExecutor

        public abstract AsyncExecutor newAsyncExecutor​(java.lang.Object hint)
      • promisify

        public abstract <T> AsyncTask<T> promisify​(java.util.function.BiConsumer<java.util.function.Consumer<T>,​java.util.function.Consumer<java.lang.Throwable>> func,
                                                   AsyncExecutor executor)
      • wrapPromise

        public abstract <T> AsyncTask<T> wrapPromise​(java.util.function.BiConsumer<java.util.function.Consumer<T>,​java.util.function.Consumer<java.lang.Throwable>> func)
      • awaitAll

        public <T> AsyncTask<java.util.List<T>> awaitAll​(java.util.List<AsyncTask<T>> promises)
        Waits for all promises to resolve.

        If one of the promises fails, the returned promise is fails with the same error.

        Type Parameters:
        T - the type of the promises
        Parameters:
        promises - the list of promises
        Returns:
        a promise that resolves to a list of results
      • awaitAny

        public <T> AsyncTask<T> awaitAny​(java.util.List<AsyncTask<T>> promises)
        Waits for any promise to resolve.
        Type Parameters:
        T - the type of the promises
        Parameters:
        promises - the list of promises
        Returns:
        a promise that resolves to the result of the first resolved promise

        If all promises fail, the returned promise fails with an exception, otherwise it resolves with the result of the first resolved promise.

      • awaitAny

        public <T> AsyncTask<T> awaitAny​(java.util.List<AsyncTask<T>> promises,
                                         java.util.function.Predicate<T> filter)
        Waits for any promise to resolve and match the filter. Same as awaitAny but with a filter that the result must match. If the result does not match the filter, it is ignored and the next promise is waited for.

        If all promises fail or none match the filter, the returned promise fails with an exception, otherwise it resolves with the result of the first resolved promise that matches the filter.

        Type Parameters:
        T - the type of the promises
        Parameters:
        promises - the list of promises
        filter - the filter to match
        Returns:
        a promise that resolves to the result of the first resolved promise that matches the filter
      • awaitAllSettled

        public <T> AsyncTask<java.util.List<AsyncTask<T>>> awaitAllSettled​(java.util.List<AsyncTask<T>> promises)
        Awaits for all promises to settle (either resolve or reject). The returned promise always resolves with the list of all promises.
        Type Parameters:
        T - the type of the promises
        Parameters:
        promises - the list of promises
        Returns:
        a promise that resolves to the list of all promises
      • getTimestampSeconds

        public abstract long getTimestampSeconds()
      • newConcurrentQueue

        public abstract <T> java.util.Queue<T> newConcurrentQueue​(java.lang.Class<T> claz)
      • httpGet

        public AsyncTask<java.lang.String> httpGet​(java.lang.String url,
                                                   java.time.Duration timeout,
                                                   java.util.Map<java.lang.String,​java.lang.String> headers)
      • httpRequest

        public abstract AsyncTask<NGEHttpResponse> httpRequest​(java.lang.String method,
                                                               java.lang.String inurl,
                                                               byte[] body,
                                                               java.time.Duration timeout,
                                                               java.util.Map<java.lang.String,​java.lang.String> headers)
      • httpRequestStream

        public abstract AsyncTask<NGEHttpResponseStream> httpRequestStream​(java.lang.String method,
                                                                           java.lang.String inurl,
                                                                           byte[] body,
                                                                           java.time.Duration timeout,
                                                                           java.util.Map<java.lang.String,​java.lang.String> headers)
      • setClipboardContent

        public abstract void setClipboardContent​(java.lang.String data)
      • getClipboardContent

        public abstract AsyncTask<java.lang.String> getClipboardContent()
      • openInWebBrowser

        public abstract void openInWebBrowser​(java.lang.String url)
      • scrypt

        public abstract byte[] scrypt​(byte[] P,
                                      byte[] S,
                                      int N,
                                      int r,
                                      int p,
                                      int dkLen)
      • xchacha20poly1305

        public abstract byte[] xchacha20poly1305​(byte[] key,
                                                 byte[] nonce,
                                                 byte[] data,
                                                 byte[] associatedData,
                                                 boolean forEncryption)
      • nfkc

        public abstract java.lang.String nfkc​(java.lang.String str)
      • getDataStore

        public abstract VStore getDataStore​(java.lang.String appName,
                                            java.lang.String storeName)
      • getCacheStore

        public abstract VStore getCacheStore​(java.lang.String appName,
                                             java.lang.String cacheName)
      • registerFinalizer

        public abstract java.lang.Runnable registerFinalizer​(java.lang.Object obj,
                                                             java.lang.Runnable finalizer)
      • isLoopbackAddress

        public boolean isLoopbackAddress​(java.net.URI uri)
        Checks if the given URI is a loopback address. Polyfill for non jcl compliant platforms. This method should be overriden by a platform specific implementation
        Parameters:
        uri - the URI to check
        Returns:
        true if the URI is a loopback address, false otherwise
      • openResource

        public abstract java.io.InputStream openResource​(java.lang.String resourceName)
                                                  throws java.io.IOException
        Throws:
        java.io.IOException
      • aes256cbc

        public abstract byte[] aes256cbc​(byte[] key,
                                         byte[] iv,
                                         byte[] data,
                                         boolean forEncryption)
        Encrypts or decrypts data using AES-256 in CBC mode with PKCS7 padding.
        Parameters:
        key - A 32-byte key for AES-256
        iv - A 16-byte initialization vector
        data - The data to encrypt or decrypt
        forEncryption - True for encryption, false for decryption
        Returns:
        The encrypted or decrypted data
      • callFunction

        public void callFunction​(java.lang.String function,
                                 java.lang.Object args,
                                 java.util.function.Consumer<java.lang.Object> res,
                                 java.util.function.Consumer<java.lang.Throwable> rej)
        Run platform specific script
      • canCallFunction

        public void canCallFunction​(java.lang.String function,
                                    java.util.function.Consumer<java.lang.Boolean> res)
      • getPlatformName

        public abstract java.lang.String getPlatformName()
      • runInThread

        public void runInThread​(java.lang.Thread thread,
                                java.util.function.Consumer<java.lang.Runnable> enqueue,
                                java.lang.Runnable action)