Research
Security News
Quasar RAT Disguised as an npm Package for Detecting Vulnerabilities in Ethereum Smart Contracts
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
@nrk/nativebridge
Advanced tools
Native Bridge is a lightweight and efficient bridge between webview and native app. It's primary use case is to share state between native apps and javascript in webviews.
Native Bridge is a lightweight and efficient bridge between webview and native app. It's primary use case is to share state between native apps and javascript in webviews.
Tested on Android 4.4.4+ | iOS 10.2+ |
Used as a producer/consumer-interface for passing messages to/from native app (iOs/Android). Following an EventEmitter
interface (on/once/off/emit). In addition an RPC-interface makes calling native methods a breeze.
nativebridge.emit('test', { foo: 'bar' }) // Emit 'test' event with data (must be object) to native
nativebridge.on('test', (data) => {}) // Bind handler to 'test' event emitted from native
nativebridge.once('test', (data) => {}) // Bind handler to 'test' (one time only) event emitted from native
nativebridge.off('test') // Unbind all handlers for 'test' event
nativebridge.off('test', (data) => {}) // Unbind specific handler for 'test' event
Make a remote procedure call (RPC) using nativebridge interfaces as described above. Resolves with data on completion, or rejects with error details from the app (or timeout).
// Auto-bind handlers (once/emit) to complete an RPC-call to native
nativeBridge.rpc({
topic: 'test', // using 'test' as event
data: {}, // with data (args)
resolve: (data) => {}, // using callback on success
reject: (err) => {}, // or rejection on error
timeout: 1000 // with a timeout threshold
})
npm install @nrk/nativebridge --save
import nativebridge from '@nrk/nativebridge'
<script src="https://static.nrk.no/nativebridge/X.X.X/nativebridge.min.js"></script>
<!-- window.nativebridge is now defined -->
require(['https://static.nrk.no/nativebridge/X.X.X/nativebridge.min.js'], function(nativebridge) {
/* code here */
});
A data object is sent using topic
as topic to an exposed method on either:
window.webkit.messageHandlers.nativebridgeiOS.postMessage({topic: "test", data: {foo: "bar"}})
window.NativeBridgeAndroid.send(JSON.stringify({topic: "test", data: {foo: "bar"}}))
Topic-handlers are mapped to native functions, using data-object as an argument e.g topicHandler({topic: "test", data: {foo: "bar"}})
. The app injects a js-snippet to dispatch a message back to the webpage using CustomEvents:
window.dispatchEvent(new CustomEvent('nativebridge', { detail: {topic, data} }))
The CustomEvent dispatched from the native app is ran using attached callback-handlers on the given topic.
If an error occurs in the native app, an Error object will be rejected, eg.
err.message = '[{message: "no handler available", errorCode: 100}]'
The RPC-method is made to simplify on/off/emit-logistics. In addition it supports a timeout, which will throw an error if timeout is reached:
err.message = 'RPC for test using {} timed out after 1000ms'
First clone @nrk/nativebridge
and install its dependencies:
git clone git@github.com:nrkno/nativebridge.git
cd nativebridge
npm install && npm start
After having applied changes, remember to build before pushing the changes upstream.
git checkout -b feature/my-changes
# update the source code
npm run build
git commit -am "Add my changes"
git push origin feature/my-changes
# then make a PR to the master branch,
# and assign another developer to review your code
NOTE! Please also make sure to keep commits small and clean (that the commit message actually refers to the updated files).
Stylistically, make sure the commit message is Capitalized and starts with a verb in the present tense (for exampleAdd minification support
).
FAQs
Native Bridge is a lightweight and efficient bridge between webview and native app. It's primary use case is to share state between native apps and javascript in webviews.
The npm package @nrk/nativebridge receives a total of 11 weekly downloads. As such, @nrk/nativebridge popularity was classified as not popular.
We found that @nrk/nativebridge demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 95 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Research
Security News
Socket researchers uncover a malicious npm package posing as a tool for detecting vulnerabilities in Etherium smart contracts.
Security News
Research
A supply chain attack on Rspack's npm packages injected cryptomining malware, potentially impacting thousands of developers.
Research
Security News
Socket researchers discovered a malware campaign on npm delivering the Skuld infostealer via typosquatted packages, exposing sensitive data.