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)
      • secp256k1PrivateKeyVerify

        public abstract boolean secp256k1PrivateKeyVerify​(byte[] privateKey)
        Verifies whether a secp256k1 private key is valid. A key is valid if it is 32 bytes long and its integer value is in [1, n-1], where n is the secp256k1 curve order.
        Parameters:
        privateKey - raw private key (32 bytes)
        Returns:
        true if valid, otherwise false
      • secp256k1PublicKeyVerify

        public abstract boolean secp256k1PublicKeyVerify​(byte[] publicKey)
        Verifies whether a secp256k1 public key is valid. It must be an SEC1 compressed key (33 bytes) or uncompressed key (65 bytes), decodable on the curve and not at infinity.
        Parameters:
        publicKey - SEC1 compressed or uncompressed public key
        Returns:
        true if valid, otherwise false
      • secp256k1PublicKeyCreate

        public abstract byte[] secp256k1PublicKeyCreate​(byte[] privateKey,
                                                        boolean compressed)
        Derives a secp256k1 public key from a private key.
        Parameters:
        privateKey - raw private key (32 bytes), valid
        compressed - true for compressed output (33 bytes), false for uncompressed output (65 bytes)
        Returns:
        SEC1 public key in the requested format
        Throws:
        java.lang.IllegalArgumentException - if the private key is invalid
      • secp256k1SignRecoverable

        public abstract Secp256k1RecoverableSignature secp256k1SignRecoverable​(byte[] hash32,
                                                                               byte[] privateKey)
        Signs a 32-byte hash with ECDSA over secp256k1 and returns a recoverable signature. The signature must be in compact 64-byte format: r(32) || s(32), with low-S normalization (BIP-62 style) for cross-platform stability. recoveryId must be in [0..3].
        Parameters:
        hash32 - message hash (exactly 32 bytes)
        privateKey - raw private key (32 bytes), valid
        Returns:
        recoverable signature containing signature64 and recoveryId
        Throws:
        java.lang.IllegalArgumentException - if inputs are invalid
      • secp256k1RecoverPublicKey

        public abstract byte[] secp256k1RecoverPublicKey​(byte[] hash32,
                                                         byte[] signature64,
                                                         int recoveryId,
                                                         boolean compressed)
        Recovers a secp256k1 public key from hash + recoverable signature.
        Parameters:
        hash32 - message hash (exactly 32 bytes)
        signature64 - compact 64-byte signature: r||s
        recoveryId - recovery id in [0..3]
        compressed - true for compressed output (33 bytes), false for uncompressed output (65 bytes)
        Returns:
        recovered public key in the requested format
        Throws:
        java.lang.IllegalArgumentException - if inputs are invalid or recovery is impossible
      • 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​(java.time.Duration p2pAttemptTimeout,
                                                     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)
      • schnorrVerify

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

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

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

        @Deprecated
        public boolean verify​(java.lang.String data,
                              java.lang.String sign,
                              byte[] pubKey)
        Deprecated.
        This generically named method is deprecated in favor of schnorrVerify(String, String, byte[]) that does the same
      • signAsync

        @Deprecated
        public AsyncTask<java.lang.String> signAsync​(java.lang.String data,
                                                     byte[] privKey)
        Deprecated.
        This generically named method is deprecated in favor of schnorrSignAsync(String, byte[]) that does the same
      • verifyAsync

        @Deprecated
        public AsyncTask<java.lang.Boolean> verifyAsync​(java.lang.String data,
                                                        java.lang.String sign,
                                                        byte[] pubKey)
        Deprecated.
        This generically named method is deprecated in favor of schnorrVerifyAsync(String, String, byte[]) that does the same
      • 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)
      • panic

        public void panic​(java.lang.String err)
      • getNativeAllocator

        public abstract NGEAllocator getNativeAllocator()