Package org.ngengine.platform
Class NGEPlatform
- java.lang.Object
-
- org.ngengine.platform.NGEPlatform
-
public abstract class NGEPlatform extends java.lang.Object
-
-
Constructor Summary
Constructors Constructor Description NGEPlatform()
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description abstract byte[]aes256cbc(byte[] key, byte[] iv, byte[] data, boolean forEncryption)Encrypts or decrypts data using AES-256 in CBC mode with PKCS7 padding.java.nio.ByteBufferaes256cbc(java.nio.ByteBuffer key, java.nio.ByteBuffer iv, java.nio.ByteBuffer data, boolean forEncryption)<T> AsyncTask<java.util.List<T>>awaitAll(java.util.List<AsyncTask<T>> promises)Waits for all promises to resolve.<T> AsyncTask<java.util.List<AsyncTask<T>>>awaitAllSettled(java.util.List<AsyncTask<T>> promises)Awaits for all promises to settle (either resolve or reject).<T> AsyncTask<T>awaitAny(java.util.List<AsyncTask<T>> promises)Waits for any promise to resolve.<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.abstract byte[]base64decode(java.lang.String data)java.nio.ByteBufferbase64decodeBuffer(java.lang.String data)abstract java.lang.Stringbase64encode(byte[] data)java.lang.Stringbase64encode(java.nio.ByteBuffer data)voidcallFunction(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 scriptvoidcanCallFunction(java.lang.String function, java.util.function.Consumer<java.lang.Boolean> res)abstract byte[]chacha20(byte[] key, byte[] nonce, byte[] data, boolean forEncryption)java.nio.ByteBufferchacha20(java.nio.ByteBuffer key, java.nio.ByteBuffer nonce, java.nio.ByteBuffer data, boolean forEncryption)protected static byte[]copyRemaining(java.nio.ByteBuffer input)SchnorrSignercreateSchnorrSigner(java.util.function.Supplier<java.nio.ByteBuffer> privateKey)Creates a signer that may prepare public key state once.abstract <T> TfromJSON(java.lang.String json, java.lang.Class<T> claz)Parses JSON trees; objects returned as maps retain JavaScript property order recursively.abstract byte[]generatePrivateKey()java.nio.ByteBuffergeneratePrivateKeyBuffer()Generates a private key using a buffer-oriented representation.abstract byte[]genPubKey(byte[] secKey)java.nio.ByteBuffergenPubKey(java.nio.ByteBuffer secKey)static NGEPlatformget()static BrowserInterceptorgetBrowserInterceptor()abstract VStoregetCacheStore(java.lang.String appName, java.lang.String cacheName)abstract AsyncTask<java.lang.String>getClipboardContent()abstract VStoregetDataStore(java.lang.String appName, java.lang.String storeName)MemoryLimitsgetMemoryLimits()abstract NGEAllocatorgetNativeAllocator()abstract java.lang.StringgetPlatformName()static VStoreInterceptorgetStoreInterceptor()abstract longgetTimestampSeconds()ExecutionQueuegetVStoreQueue()abstract byte[]hkdf_expand(byte[] prk, byte[] info, int length)java.nio.ByteBufferhkdf_expand(java.nio.ByteBuffer prk, java.nio.ByteBuffer info, int length)abstract byte[]hkdf_extract(byte[] salt, byte[] ikm)java.nio.ByteBufferhkdf_extract(java.nio.ByteBuffer salt, java.nio.ByteBuffer ikm)abstract byte[]hmac(byte[] key, byte[] data1, byte[] data2)java.nio.ByteBufferhmac(java.nio.ByteBuffer key, java.nio.ByteBuffer data1, java.nio.ByteBuffer data2)AsyncTask<java.lang.String>httpGet(java.lang.String url, java.time.Duration timeout, java.util.Map<java.lang.String,java.lang.String> headers)AsyncTask<byte[]>httpGetBytes(java.lang.String url, java.time.Duration timeout, java.util.Map<java.lang.String,java.lang.String> headers)Deprecated.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)AsyncTask<NGEHttpResponse>httpRequest(java.lang.String method, java.lang.String inurl, java.nio.ByteBuffer body, java.time.Duration timeout, java.util.Map<java.lang.String,java.lang.String> headers)Buffer-oriented overload ofhttpRequest(String, String, byte[], Duration, Map).AsyncTask<NGEHttpResponse>httpRequest(java.lang.String method, java.lang.String inurl, java.time.Duration timeout, java.util.Map<java.lang.String,java.lang.String> headers)Issues an HTTP request without a request body.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)booleanisLoopbackAddress(java.net.URI uri)Checks if the given URI is a loopback address.static booleanisSet()AsyncExecutornewAsyncExecutor()abstract AsyncExecutornewAsyncExecutor(java.lang.Object hint)abstract <T> java.util.Queue<T>newConcurrentQueue(java.lang.Class<T> claz)ExecutionQueuenewExecutionQueue()ExecutionQueuenewExecutionQueue(AsyncExecutor exc)AsyncExecutornewPoolExecutor()Deprecated.usenewAsyncExecutor(Object)insteadAsyncExecutornewRelayExecutor()Deprecated.usenewAsyncExecutor(Object)insteadabstract RTCTransportnewRTCTransport(java.time.Duration p2pAttemptTimeout, java.lang.String connId, java.util.Collection<java.lang.String> stunServers)AsyncExecutornewSignerExecutor()Deprecated.usenewAsyncExecutor(Object)insteadAsyncExecutornewSubscriptionExecutor()Deprecated.usenewAsyncExecutor(Object)insteadabstract WebsocketTransportnewTransport()abstract java.lang.Stringnfkc(java.lang.String str)abstract voidopenInWebBrowser(java.lang.String url)abstract java.io.InputStreamopenResource(java.lang.String resourceName)voidpanic(java.lang.String err)JsonObjectparseJsonObject(java.lang.String json)Parses an object with typed reads and owned immutable string rows.abstract <T> AsyncTask<T>promisify(java.util.function.BiConsumer<java.util.function.Consumer<T>,java.util.function.Consumer<java.lang.Throwable>> func, AsyncExecutor executor)abstract byte[]randomBytes(int n)java.nio.ByteBufferrandomBytesBuffer(int n)abstract java.lang.RunnableregisterFinalizer(java.lang.Object obj, java.lang.Runnable finalizer)voidrunInThread(java.lang.Thread thread, java.util.function.Consumer<java.lang.Runnable> enqueue, java.lang.Runnable action)abstract java.lang.StringschnorrSign(java.lang.String data, byte[] privKey)java.lang.StringschnorrSign(java.lang.String data, java.nio.ByteBuffer privKey)abstract AsyncTask<java.lang.String>schnorrSignAsync(java.lang.String data, byte[] privKey)AsyncTask<java.lang.String>schnorrSignAsync(java.lang.String data, java.nio.ByteBuffer privKey)abstract booleanschnorrVerify(java.lang.String data, java.lang.String sign, byte[] pubKey)booleanschnorrVerify(java.lang.String data, java.lang.String sign, java.nio.ByteBuffer pubKey)abstract AsyncTask<java.lang.Boolean>schnorrVerifyAsync(java.lang.String data, java.lang.String sign, byte[] pubKey)AsyncTask<java.lang.Boolean>schnorrVerifyAsync(java.lang.String data, java.lang.String sign, java.nio.ByteBuffer pubKey)abstract byte[]scrypt(byte[] P, byte[] S, int N, int r, int p, int dkLen)java.nio.ByteBufferscrypt(java.nio.ByteBuffer password, java.nio.ByteBuffer salt, int n, int r, int p, int dkLen)Buffer convenience for scrypt.abstract booleansecp256k1PrivateKeyVerify(byte[] privateKey)Verifies whether a secp256k1 private key is valid.booleansecp256k1PrivateKeyVerify(java.nio.ByteBuffer privateKey)abstract byte[]secp256k1PublicKeyCreate(byte[] privateKey, boolean compressed)Derives a secp256k1 public key from a private key.java.nio.ByteBuffersecp256k1PublicKeyCreate(java.nio.ByteBuffer privateKey, boolean compressed)abstract booleansecp256k1PublicKeyVerify(byte[] publicKey)Verifies whether a secp256k1 public key is valid.booleansecp256k1PublicKeyVerify(java.nio.ByteBuffer publicKey)abstract byte[]secp256k1RecoverPublicKey(byte[] hash32, byte[] signature64, int recoveryId, boolean compressed)Recovers a secp256k1 public key from hash + recoverable signature.java.nio.ByteBuffersecp256k1RecoverPublicKey(java.nio.ByteBuffer hash32, java.nio.ByteBuffer signature64, int recoveryId, boolean compressed)abstract byte[]secp256k1SharedSecret(byte[] privKey, byte[] pubKey)java.nio.ByteBuffersecp256k1SharedSecret(java.nio.ByteBuffer privKey, java.nio.ByteBuffer pubKey)abstract Secp256k1RecoverableSignaturesecp256k1SignRecoverable(byte[] hash32, byte[] privateKey)Signs a 32-byte hash with ECDSA over secp256k1 and returns a recoverable signature.Secp256k1RecoverableSignaturesecp256k1SignRecoverable(java.nio.ByteBuffer hash32, java.nio.ByteBuffer privateKey)static voidset(NGEPlatform platform)static voidsetBrowserInterceptor(BrowserInterceptor interceptor)abstract voidsetClipboardContent(java.lang.String data)static voidsetStoreInterceptor(VStoreInterceptor interceptor)abstract byte[]sha256(byte[] data)abstract java.lang.Stringsha256(java.lang.String data)java.nio.ByteBuffersha256(java.nio.ByteBuffer data)AsyncTask<java.lang.String>sha256Async(java.lang.String data)java.lang.Stringsha256JSON(java.util.Collection obj)Hashes the UTF-8 JSON representation, allowing native writers to avoid a string round trip.AsyncTask<java.lang.String>sha256JSONAsync(java.util.Collection obj)java.lang.Stringsign(java.lang.String data, byte[] privKey)Deprecated.AsyncTask<java.lang.String>signAsync(java.lang.String data, byte[] privKey)Deprecated.booleansupportsMinimalJSONEscaping()Whether the JSON writer escapes only syntax, control characters and unpaired UTF-16 surrogates, without extra HTML or script escaping.abstract java.lang.StringtoJSON(java.util.Collection obj)Serializes an owned JSON-compatible tree with JSON.stringify semantics.abstract java.lang.StringtoJSON(java.util.Map obj)booleanverify(java.lang.String data, java.lang.String sign, byte[] pubKey)Deprecated.AsyncTask<java.lang.Boolean>verifyAsync(java.lang.String data, java.lang.String sign, byte[] pubKey)Deprecated.protected static java.nio.ByteBufferwrapBinaryResult(byte[] result)abstract <T> AsyncTask<T>wrapPromise(java.util.function.BiConsumer<java.util.function.Consumer<T>,java.util.function.Consumer<java.lang.Throwable>> func)abstract byte[]xchacha20poly1305(byte[] key, byte[] nonce, byte[] data, byte[] associatedData, boolean forEncryption)java.nio.ByteBufferxchacha20poly1305(java.nio.ByteBuffer key, java.nio.ByteBuffer nonce, java.nio.ByteBuffer data, java.nio.ByteBuffer associatedData, boolean forEncryption)
-
-
-
Method Detail
-
set
public static void set(NGEPlatform platform)
-
isSet
public static boolean isSet()
-
get
public static NGEPlatform get()
-
setBrowserInterceptor
public static void setBrowserInterceptor(BrowserInterceptor interceptor)
-
getBrowserInterceptor
public static BrowserInterceptor getBrowserInterceptor()
-
setStoreInterceptor
public static void setStoreInterceptor(VStoreInterceptor interceptor)
-
getStoreInterceptor
public static VStoreInterceptor getStoreInterceptor()
-
generatePrivateKey
public abstract byte[] generatePrivateKey()
-
generatePrivateKeyBuffer
public java.nio.ByteBuffer generatePrivateKeyBuffer()
Generates a private key using a buffer-oriented representation.The default implementation preserves the existing array implementation. Platforms with a native/shared-buffer boundary should override this method.
-
genPubKey
public abstract byte[] genPubKey(byte[] secKey)
-
genPubKey
public java.nio.ByteBuffer genPubKey(java.nio.ByteBuffer secKey)
-
toJSON
public abstract java.lang.String toJSON(java.util.Collection obj)
Serializes an owned JSON-compatible tree with JSON.stringify semantics. Java numbers are converted to JavaScript Numbers (binary64); NaN and infinity become null. Ordered maps preserve string-key insertion order, with array-index keys first in numeric order. Use LinkedHashMap when constructing JSON objects; unordered maps cannot recover insertion history.
-
toJSON
public abstract java.lang.String toJSON(java.util.Map obj)
-
supportsMinimalJSONEscaping
public boolean supportsMinimalJSONEscaping()
Whether the JSON writer escapes only syntax, control characters and unpaired UTF-16 surrogates, without extra HTML or script escaping. Callers must still respect the writer's numeric precision.
-
sha256JSON
public java.lang.String sha256JSON(java.util.Collection obj)
Hashes the UTF-8 JSON representation, allowing native writers to avoid a string round trip.
-
sha256JSONAsync
public AsyncTask<java.lang.String> sha256JSONAsync(java.util.Collection obj)
-
fromJSON
public abstract <T> T fromJSON(java.lang.String json, java.lang.Class<T> claz)Parses JSON trees; objects returned as maps retain JavaScript property order recursively.
-
parseJsonObject
public JsonObject parseJsonObject(java.lang.String json)
Parses an object with typed reads and owned immutable string rows.- Throws:
java.lang.IllegalArgumentException- if the JSON root is not an object
-
secp256k1SharedSecret
public abstract byte[] secp256k1SharedSecret(byte[] privKey, byte[] pubKey)
-
secp256k1SharedSecret
public java.nio.ByteBuffer secp256k1SharedSecret(java.nio.ByteBuffer privKey, java.nio.ByteBuffer 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
-
secp256k1PrivateKeyVerify
public boolean secp256k1PrivateKeyVerify(java.nio.ByteBuffer privateKey)
-
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
-
secp256k1PublicKeyVerify
public boolean secp256k1PublicKeyVerify(java.nio.ByteBuffer publicKey)
-
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), validcompressed- 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
-
secp256k1PublicKeyCreate
public java.nio.ByteBuffer secp256k1PublicKeyCreate(java.nio.ByteBuffer privateKey, boolean compressed)
-
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
-
secp256k1SignRecoverable
public Secp256k1RecoverableSignature secp256k1SignRecoverable(java.nio.ByteBuffer hash32, java.nio.ByteBuffer privateKey)
-
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||srecoveryId- 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
-
secp256k1RecoverPublicKey
public java.nio.ByteBuffer secp256k1RecoverPublicKey(java.nio.ByteBuffer hash32, java.nio.ByteBuffer signature64, int recoveryId, boolean compressed)
-
hmac
public abstract byte[] hmac(byte[] key, byte[] data1, byte[] data2)
-
hmac
public java.nio.ByteBuffer hmac(java.nio.ByteBuffer key, java.nio.ByteBuffer data1, java.nio.ByteBuffer data2)
-
hkdf_extract
public abstract byte[] hkdf_extract(byte[] salt, byte[] ikm)
-
hkdf_extract
public java.nio.ByteBuffer hkdf_extract(java.nio.ByteBuffer salt, java.nio.ByteBuffer ikm)
-
hkdf_expand
public abstract byte[] hkdf_expand(byte[] prk, byte[] info, int length)
-
hkdf_expand
public java.nio.ByteBuffer hkdf_expand(java.nio.ByteBuffer prk, java.nio.ByteBuffer info, int length)
-
base64encode
public abstract java.lang.String base64encode(byte[] data)
-
base64encode
public java.lang.String base64encode(java.nio.ByteBuffer data)
-
base64decode
public abstract byte[] base64decode(java.lang.String data)
-
base64decodeBuffer
public java.nio.ByteBuffer base64decodeBuffer(java.lang.String data)
-
chacha20
public abstract byte[] chacha20(byte[] key, byte[] nonce, byte[] data, boolean forEncryption)
-
chacha20
public java.nio.ByteBuffer chacha20(java.nio.ByteBuffer key, java.nio.ByteBuffer nonce, java.nio.ByteBuffer data, boolean forEncryption)
-
newTransport
public abstract WebsocketTransport newTransport()
-
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)
-
sha256Async
public AsyncTask<java.lang.String> sha256Async(java.lang.String data)
-
sha256
public abstract byte[] sha256(byte[] data)
-
sha256
public java.nio.ByteBuffer sha256(java.nio.ByteBuffer data)
-
schnorrSign
public abstract java.lang.String schnorrSign(java.lang.String data, byte[] privKey) throws FailedToSignException- Throws:
FailedToSignException
-
createSchnorrSigner
public SchnorrSigner createSchnorrSigner(java.util.function.Supplier<java.nio.ByteBuffer> privateKey)
Creates a signer that may prepare public key state once. The supplier is consulted for every signature, so key destruction remains effective. It must supply the same key throughout the signer's lifetime; no private key snapshot is retained by this factory. Platforms without a prepared implementation preserve their existing signing path.
-
schnorrSign
public java.lang.String schnorrSign(java.lang.String data, java.nio.ByteBuffer privKey) throws FailedToSignException- Throws:
FailedToSignException
-
schnorrVerify
public abstract boolean schnorrVerify(java.lang.String data, java.lang.String sign, byte[] pubKey)
-
schnorrVerify
public boolean schnorrVerify(java.lang.String data, java.lang.String sign, java.nio.ByteBuffer pubKey)
-
schnorrSignAsync
public abstract AsyncTask<java.lang.String> schnorrSignAsync(java.lang.String data, byte[] privKey)
-
schnorrSignAsync
public AsyncTask<java.lang.String> schnorrSignAsync(java.lang.String data, java.nio.ByteBuffer privKey)
-
schnorrVerifyAsync
public abstract AsyncTask<java.lang.Boolean> schnorrVerifyAsync(java.lang.String data, java.lang.String sign, byte[] pubKey)
-
schnorrVerifyAsync
public AsyncTask<java.lang.Boolean> schnorrVerifyAsync(java.lang.String data, java.lang.String sign, java.nio.ByteBuffer pubKey)
-
sign
@Deprecated public java.lang.String sign(java.lang.String data, byte[] privKey) throws FailedToSignExceptionDeprecated.This generically named method is deprecated in favor ofschnorrSign(String, byte[])that does the same- Throws:
FailedToSignException
-
verify
@Deprecated public boolean verify(java.lang.String data, java.lang.String sign, byte[] pubKey)Deprecated.This generically named method is deprecated in favor ofschnorrVerify(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 ofschnorrSignAsync(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 ofschnorrVerifyAsync(String, String, byte[])that does the same
-
randomBytes
public abstract byte[] randomBytes(int n)
-
randomBytesBuffer
public java.nio.ByteBuffer randomBytesBuffer(int n)
-
newAsyncExecutor
public final AsyncExecutor newAsyncExecutor()
-
newAsyncExecutor
public abstract AsyncExecutor newAsyncExecutor(java.lang.Object hint)
-
newRelayExecutor
@Deprecated public final AsyncExecutor newRelayExecutor()
Deprecated.usenewAsyncExecutor(Object)instead
-
newSubscriptionExecutor
@Deprecated public final AsyncExecutor newSubscriptionExecutor()
Deprecated.usenewAsyncExecutor(Object)instead
-
newSignerExecutor
@Deprecated public final AsyncExecutor newSignerExecutor()
Deprecated.usenewAsyncExecutor(Object)instead
-
newPoolExecutor
@Deprecated public final AsyncExecutor newPoolExecutor()
Deprecated.usenewAsyncExecutor(Object)instead
-
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 promisesfilter- 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)
-
httpGetBytes
@Deprecated public AsyncTask<byte[]> httpGetBytes(java.lang.String url, java.time.Duration timeout, java.util.Map<java.lang.String,java.lang.String> headers)
Deprecated.
-
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)
-
httpRequest
public AsyncTask<NGEHttpResponse> httpRequest(java.lang.String method, java.lang.String inurl, java.time.Duration timeout, java.util.Map<java.lang.String,java.lang.String> headers)
Issues an HTTP request without a request body.
-
httpRequest
public AsyncTask<NGEHttpResponse> httpRequest(java.lang.String method, java.lang.String inurl, java.nio.ByteBuffer body, java.time.Duration timeout, java.util.Map<java.lang.String,java.lang.String> headers)
Buffer-oriented overload ofhttpRequest(String, String, byte[], Duration, Map). The default implementation adapts to the established array API; platforms with a direct/shared-buffer HTTP boundary should override it.
-
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)
-
scrypt
public java.nio.ByteBuffer scrypt(java.nio.ByteBuffer password, java.nio.ByteBuffer salt, int n, int r, int p, int dkLen)Buffer convenience for scrypt. The default adapter is intentionally used by TeaVM as well: scrypt's cost dominates the small password/salt/output transfers, so a separate direct-buffer asynchronous bridge would add complexity without a meaningful performance benefit.
-
xchacha20poly1305
public abstract byte[] xchacha20poly1305(byte[] key, byte[] nonce, byte[] data, byte[] associatedData, boolean forEncryption)
-
xchacha20poly1305
public java.nio.ByteBuffer xchacha20poly1305(java.nio.ByteBuffer key, java.nio.ByteBuffer nonce, java.nio.ByteBuffer data, java.nio.ByteBuffer 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-256iv- A 16-byte initialization vectordata- The data to encrypt or decryptforEncryption- True for encryption, false for decryption- Returns:
- The encrypted or decrypted data
-
aes256cbc
public java.nio.ByteBuffer aes256cbc(java.nio.ByteBuffer key, java.nio.ByteBuffer iv, java.nio.ByteBuffer data, boolean forEncryption)
-
getVStoreQueue
public ExecutionQueue getVStoreQueue()
-
newExecutionQueue
public ExecutionQueue newExecutionQueue()
-
newExecutionQueue
public ExecutionQueue newExecutionQueue(AsyncExecutor exc)
-
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)
-
getMemoryLimits
public MemoryLimits getMemoryLimits()
-
getNativeAllocator
public abstract NGEAllocator getNativeAllocator()
-
copyRemaining
protected static byte[] copyRemaining(java.nio.ByteBuffer input)
-
wrapBinaryResult
protected static java.nio.ByteBuffer wrapBinaryResult(byte[] result)
-
-