npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nativescript-libsodium

v1.4.0

Published

Use libsodium in Nativescript with libsodium.js like wrappers.

Downloads

9

Readme

Nativescript libsodium

Use native libsodium with nativescript. (mostly) API compatible with libsodium.js wrappers.

Only Android is supported at this time.

Installation

tns plugin add nativescript-libsodium

For Android - libsodium-jni requires either disallowing backup or making the following changes to your AndroidManifest.xml

Don't use backup if you are storing secret keys as they would also get backed up

  • Add tools:replace="android:allowBackup" as an attribute to the application tag.
  • Add xmlns:tools="http://schemas.android.com/tools" asn an attribute to the manifest tag.

Usage

Use it the same way you use libsodium.js including their wrapper functions.

import { Libsodium } from "nativescript-libsodium";
let keypair = Libsodium.crypto_box_keypair();
console.log(keypair.privateKey);  // It's a Uint8Array object

For more examples, check out the unit tests

Contributing

Not all libsodium functions are wrapped in this project. But they are easy to add. Let's see how to add the crypto_box_seal_open function.

Getting familiar

  1. First run the project as is. You may run both the demo and unit tests. Read instructions here
  2. Review docs on the function from libsodium and libsodium.js
  3. Review type definitions for libsodium.js and libsodium-jni

Adding new functions

  • Add your new function (this one already exists actually) to libsodium.common.ts
  • Write function parameters as to match libsodium.js's wrapper.
  • Convert Uint8Array to Native Byte arrays with force_java_bytes
  • Run native function. Review libsodium docs (not .js)
  • Convert back to Uint8Array with javvaByteArrayToUint8Array
  • Add unit test demonstrating functionality.
  • Submit your merge request :)
  public static crypto_box_seal(message: string | Uint8Array, publicKey: Uint8Array): Uint8Array {
    let messageBytes = this.force_java_bytes(message);
    let publicKeyBytes = this.force_java_bytes(publicKey);
    let ciphertext: JavaBytes = Array.create('byte', Sodium.crypto_box_sealbytes() + messageBytes.length);

    Sodium.crypto_box_seal(ciphertext, messageBytes, messageBytes.length, publicKeyBytes);

    return this.javaByteArrayToUint8Array(ciphertext);
  }

Design decisions

  • We wish to maintain as close as possible API compatibility with libsodium.js wrappers. This means converting between JS Uint8Array and Java Byte Arrays. There is some performance penally for this but it allows us to "drop in" nativescript-libsodium in some projects that use libsodium.js.
  • libsodium-jni is not compiled from source but from a build server. You may wish to build it yourself.
  • We do not support libsodium's outputFormat param which complicates type definitions. This could change especially if someone submitted a merge request.
  • Error handling could be improved - it should take the native function's return value and throw an exception if it's unable to perform the crypto.

iOS Support?

Please contribute! You would need to refactor the android specific code to .android files and build a wrapper for the .ios ones.

It might make sense to make a generic class interface and have both Android and iOS implement it to ensure consistency.

Need paid support?

Do you need an iOS version sooner? Or maybe prefer us to add more libsodium functions that are important to you?

Let us know at info AT burke software dot com.

License

Apache License Version 2.0, January 2004