Commit 231ce866 authored by David Burke's avatar David Burke

Updated for libsodium.js 0.7.x compat

parent 4f407455
......@@ -39,4 +39,9 @@ describe("libsodium nativescript wrapper", function() {
let decryptedString = new TextDecoder('utf-8').decode(decrypted);
expect(decryptedString).toEqual(secretMessage);
});
it("fakes the libsodium.js .ready function", function(done) {
const result = Libsodium.ready.then(() => done());
expect(result).toBeTruthy();
});
});
......@@ -5,10 +5,17 @@ export interface IKeyPair {
}
export declare class Common {
static BASE64_FLAGS: number;
static base64_variants: {
ORIGINAL: number;
ORIGINAL_NO_PADDING: number;
URLSAFE: number;
URLSAFE_NO_PADDING: number;
};
static ready: Promise<void>;
private static javaByteArrayToUint8Array(javaBytes);
private static Uint8ArrayToJavaByteArray(inBytes);
static to_base64(aBytes: Uint8Array): string;
static from_base64(sBase64: string): Uint8Array;
static to_base64(aBytes: Uint8Array, variant?: any): string;
static from_base64(sBase64: string, variant?: any): Uint8Array;
static randombytes_buf(length: number): Uint8Array;
static crypto_box_keypair(): IKeyPair;
static crypto_pwhash(keyLength: number, password: string | Uint8Array, salt: Uint8Array, opsLimit: number, memlimit: number, algorithm: number): Uint8Array;
......
......@@ -24,6 +24,13 @@ export interface IKeyPair {
export class Common {
static BASE64_FLAGS = Base64.NO_WRAP | Base64.NO_CLOSE;
static base64_variants = {
ORIGINAL: 1,
ORIGINAL_NO_PADDING: 3,
URLSAFE: 5,
URLSAFE_NO_PADDING: 7
};
static ready = Promise.resolve();
private static javaByteArrayToUint8Array(javaBytes: JavaBytes) {
let out = new Uint8Array(javaBytes.length);
......@@ -38,13 +45,13 @@ export class Common {
return simpleArr;
}
public static to_base64(aBytes: Uint8Array): string {
public static to_base64(aBytes: Uint8Array, variant?: any): string {
let javaArr = this.Uint8ArrayToJavaByteArray(aBytes);
let out = Base64.encodeToString(javaArr, this.BASE64_FLAGS);
return out;
}
public static from_base64(sBase64: string): Uint8Array {
public static from_base64(sBase64: string, variant?: any): Uint8Array {
let out = Base64.decode(sBase64, this.BASE64_FLAGS);
return this.javaByteArrayToUint8Array(out);
}
......
{
"name": "nativescript-libsodium",
"version": "1.0.3",
"version": "1.1.0",
"description": "Use libsodium in Nativescript with libsodium.js like wrappers.",
"main": "libsodium",
"typings": "index.d.ts",
......@@ -17,6 +17,7 @@
"tslint": "cd .. && tslint \"**/*.ts\" --config tslint.json --exclude \"**/node_modules/**\"",
"plugin.link": "npm link && cd ../demo && npm link nativescript-libsodium && cd ../src",
"plugin.tscwatch": "npm run tsc -- -w",
"clean": "cd ../demo && rimraf hooks node_modules platforms && cd ../src && rimraf node_modules && npm run plugin.link",
"demo.ios": "npm i && npm run tsc && cd ../demo && tns run ios --syncAllFiles",
"demo.android": "npm i && npm run tsc && cd ../demo && tns run android --syncAllFiles"
},
......@@ -51,7 +52,7 @@
"typescript": "~2.3.1"
},
"dependencies": {
"text-encoding": "^0.6.3"
"text-encoding": "^0.6.4"
},
"bootstrapper": "nativescript-plugin-seed"
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment