jedisct1 / libsodium.js

libsodium compiled to Webassembly and pure JavaScript, with convenient wrappers.
Other
981 stars 140 forks source link

Any interest in typescript type definitions? #80

Closed bufke closed 6 years ago

bufke commented 7 years ago

Type definitions can help noobs like myself understand the library while also catching type related errors. I'm starting some type defs. If anyone else is interested I'm happy to share and collaborate.

Sample of what I was thinking. Modify libsodium.js so that tsc can read it (basically remove the top header section. Generate the functions (that have mostly any). Manually make types and start replacing those any's. One challenge is supporting the outputFormat param that causes the type of the return to change.

I'm happy both contributing the d.ts file to libsodium.js directly or just maintaining it separately myself.

declare module "libsodium-wrappers-sumo" {
    type OutputFormat = "uint8array" | "text" | "hex" | "base64";
    type StringOutputFormat = "text" | "hex" | "base64";
    export interface IStringKeyPair {
        keyType: string;
        privateKey: string;
        publicKey: string;
     }
    export interface IKeyPair {
        keyType: string;
        privateKey: Uint8Array;
        publicKey: Uint8Array;
     }

    function to_base64(aBytes: Uint8Array, noNewLine?: any): string;
    function stringToUTF8Array(str: any, outU8Array: any, outIdx: any, maxBytesToWrite: any): number;

    function crypto_box_keypair(outputFormat: StringOutputFormat): IStringKeyPair;
    function crypto_box_keypair(outputFormat?: "uint8array"): IKeyPair;
    function crypto_box_easy(message: any, nonce: any, publicKey: any, secretKey: any, outputFormat?: OutputFormat): any;
    function crypto_box_open_easy(ciphertext: any, nonce: any, publicKey: any, secretKey: any, outputFormat?: OutputFormat): any;
}
jedisct1 commented 7 years ago

Yes, yes, yes, type definitions using flow and/or typescript would be really useful!

bufke commented 7 years ago

Here is a preview of it.

I'm not familiar with Buffer as seen in the readme Buffer.from.

let nonce = sodium.randombytes_buf(sodium.crypto_box_NONCEBYTES);
console.log(nonce);
console.log(Buffer.from(nonce));

Both console.log as Uint8Array. I set type DefaultBinary = Uint8Array; and am using that in many places. Does that sound right?

Are there any "private" functions that shouldn't be included? Here is a raw generated libsodium.d.ts file. I'm just copying from there and filling in any's as much as I can. I am manually adding in constants as they don't appear in my generated file.

jedisct1 commented 7 years ago

Looks pretty good!

bufke commented 7 years ago

Here's something. I have all the functions and constants defined for sumo. There are still lots of any's. Do you want to include the type defs in this repo and npm package? That advantage of that is the types will "just work" when someone is using typescript. The disadvantage is probably that you'd be taking more ownership since it's coming from the official repo here. An alternative would be to publish a @types/libsodium.js npm package that contains just the types.

todos:

  1. Make non sumo version
  2. Figure out how to publish
  3. Replace more any's
bufke commented 7 years ago

Should I open a pull request or try to submit to @types/libsodium.js (the later doesn't require you do to anything).

buu700 commented 7 years ago

To add on to this, I've been using a custom type definition for the subset of libsodium that my code depends on for a while. May or may not be helpful here: https://gist.github.com/buu700/039601a7b410474f0edba9977a8c6393

Your general structure is probably a bit more idiomatic, but maybe some of what's in mine can help fill in the anys. Also, crypto_stream_chacha20 is actually only in this because my project adds it in a custom build, so you can ignore that unless it gets added to libsodium.js's default build at some point.

bufke commented 7 years ago

I updated them. I could probably guess on a lot of the any's but just putting in what I confirmed for myself and your additions. The output format could be updated to be more consistent.

ffflorian commented 7 years ago

@bufke I'd like to contribute to your work but unfortunately your project visibility is set to private:

404

The page could not be found or you don't have permission to view it.

bufke commented 7 years ago

ah I moved the repo. It's here.

I could make it it's own project if you'd like.

bufke commented 7 years ago

Also it needs updated for the 0.7.x release

ffflorian commented 7 years ago

I could make it it's own project if you'd like.

Yes, that would be great! I can start working on the 0.7.x release then.

bufke commented 7 years ago

https://gitlab.com/burke-software/libsodium.js-types

Open to ideas on project structure. Ideally it would have some form of test and either get merged into this project or @types on npm. The tests I've seen for type defs are just using the code and being able to compile without errors. I'm unfortunately not familiar with how to submit to @types.

bennycode commented 6 years ago

Hey @bufke! Is there any update on the type definitions? Our cryptography implementation at Wire is strongly based on libsodium and as avid TypeScript coders we would welcome type definitions a lot. πŸ€—

To publish your definitions you could use a tool like Microsoft's types-publisher. Microsoft also provides guidelines on how to publish for @types.

Happy to see that you are working on it!

Best, Benny

bufke commented 6 years ago

Hello @bennyn this is still something I want to do - just time always is limited. Thanks for the links. I use wire actually so glad to be of any assistance.

I wonder - do you care about supporting the OutputFormat param? It makes the type defs a bit harder. It should be possible to support it using generics - I just need to figure out how to actually do that. Ideally passing the param like "base64" would let typescript infer the return will be string. While leaving it default would be Uint8Array Alternatively we could just default Uint8Array and document that if you use output format to pass in the return type generic like doSomething<string>(etc).

Without handling the output format param - I can't tell what the function should return or I have to make a possibly wrong assumption or return a union of types that will probably confuse people more than anything else.

jedisct1 commented 6 years ago

outputFormat is an unusual and confusing hack. You can probably stick to a single return type.

buu700 commented 6 years ago

On mobile so I can't test this right now, but I'm pretty sure you can do something like this:

balls (input: Uint8Array, outputFormat?: 'uint8array') : Uint8Array;

balls (input: Uint8Array, outputFormat: 'base64'|'hex'|'text') : string;
bennycode commented 6 years ago

I use wire actually so glad to be of any assistance.

Very pleased to hear that you are using Wire. 😍 And even happier about the fact that you like to help the crypto community! This is just great!

I wonder - do you care about supporting the OutputFormat param?

Answering your question, we are not making use of the OutputFormat. Here are some exemplary calls which we make with sodium:

const cipherText = sodium.crypto_stream_chacha20_xor(plainText, typedNonce, typedKeyMaterial, 'uint8array');
const cipherTextInHex = sodium.to_hex(cipherText);
const aliceKeyPair = sodium.crypto_sign_keypair();
const curve25519_pk = sodium.crypto_sign_ed25519_pk_to_curve25519(aliceKeyPair.publicKey);
const curve25519_sk = sodium.crypto_sign_ed25519_sk_to_curve25519(aliceKeyPair.privateKey);
bufke commented 6 years ago

Can someone review this before I mimic it more?

type DefaultBinary = Uint8Array;
type Uint8ArrayOutputFormat = 'uint8array';
type StringOutputFormat = 'text' | 'hex' | 'base64';

function crypto_pwhash(keyLength: number, password: string, salt: DefaultBinary, opsLimit: number, memLimit: number, algorithm: number, outputFormat?: Uint8ArrayOutputFormat): DefaultBinary;
function crypto_pwhash(keyLength: number, password: string, salt: DefaultBinary, opsLimit: number, memLimit: number, algorithm: number, outputFormat: StringOutputFormat): string;

Test code

let hash: Uint8Array = sodium.crypto_pwhash(sodium.crypto_box_SEEDBYTES, password, salt, OPSLIMIT, MEMLIMIT, ALG);
hash = sodium.crypto_pwhash(sodium.crypto_box_SEEDBYTES, password, salt, OPSLIMIT, MEMLIMIT, ALG, 'uint8array');
const hashString: string = sodium.crypto_pwhash(sodium.crypto_box_SEEDBYTES, password, salt, OPSLIMIT, MEMLIMIT, ALG, 'text');
bennycode commented 6 years ago

@bufke Thanks for pushing this forward!

We have a libsodium.js performance benchmark. The code of this benchmark can be easily converted to TypeScript to test the compatibility with your type definitions.

If time allows, we can kick-off a test already next week. πŸ˜ƒ

ffflorian commented 6 years ago

Thanks for your work on the typings @bufke! At Wire we are in the progress of rewriting most of our libraries to TypeScript and thus rely strongly on typings for libsodium.js. Since programmers are lazy, instead of maintaining the typings for libsodium, I wrote a type generator (which uses libsodium's symbol files to create the typings) to make things easier. Of course this is quite hacky because the symbol files are not streamlined and sometimes really unclear - and e.g. for now the interfaces are just hardcoded and not generated from libsodium's symbols. And I was able to understand libsodium's symbols only with your help, so thanks! :slightly_smiling_face:

It would be awesome if we could work together with @jedisct1 to make parsing the functions easier (by streamlining the symbol files for example).

Anyway, feel free to fork and improve the tool - also looking forward to any kind of feedback! :+1:

image

As an example, here is the latest generated libsodium.d.ts for the sumo version:

Open me ```ts // Type definitions for libsodium-wrappers-sumo 0.7.3 // Project: https://github.com/jedisct1/libsodium.js // Definitions by: Florian Keller declare module 'libsodium-wrappers-sumo' { type Uint8ArrayOutputFormat = 'uint8array'; type StringOutputFormat = 'text' | 'hex' | 'base64'; type KeyType = 'curve25519' | 'ed25519' | 'x25519'; enum base64_variants { ORIGINAL, ORIGINAL_NO_PADDING, URLSAFE, URLSAFE_NO_PADDING, } interface CryptoBox { ciphertext: Uint8Array; mac: Uint8Array; } interface StringCryptoBox { ciphertext: string; mac: string; } interface CryptoKX { sharedRx: Uint8Array; sharedTx: Uint8Array; } interface StringCryptoKX { sharedRx: string; sharedTx: string; } interface KeyPair { keyType: KeyType; privateKey: Uint8Array; publicKey: Uint8Array; } interface StringKeyPair { keyType: KeyType; privateKey: string; publicKey: string; } interface SecretBox { cipher: Uint8Array; mac: Uint8Array; } interface StringSecretBox { cipher: string; mac: string; } interface generichash_state_address { name: string; } interface onetimeauth_state_address { name: string; } interface state_address { name: string; } interface secretstream_xchacha20poly1305_state_address { name: string; } interface sign_state_address { name: string; } const SODIUM_LIBRARY_VERSION_MAJOR: number; const SODIUM_LIBRARY_VERSION_MINOR: number; const SODIUM_VERSION_STRING: string; const crypto_aead_chacha20poly1305_ABYTES: number; const crypto_aead_chacha20poly1305_KEYBYTES: number; const crypto_aead_chacha20poly1305_MESSAGEBYTES_MAX: number; const crypto_aead_chacha20poly1305_NPUBBYTES: number; const crypto_aead_chacha20poly1305_NSECBYTES: number; const crypto_aead_chacha20poly1305_ietf_ABYTES: number; const crypto_aead_chacha20poly1305_ietf_KEYBYTES: number; const crypto_aead_chacha20poly1305_ietf_MESSAGEBYTES_MAX: number; const crypto_aead_chacha20poly1305_ietf_NPUBBYTES: number; const crypto_aead_chacha20poly1305_ietf_NSECBYTES: number; const crypto_aead_xchacha20poly1305_ietf_ABYTES: number; const crypto_aead_xchacha20poly1305_ietf_KEYBYTES: number; const crypto_aead_xchacha20poly1305_ietf_MESSAGEBYTES_MAX: number; const crypto_aead_xchacha20poly1305_ietf_NPUBBYTES: number; const crypto_aead_xchacha20poly1305_ietf_NSECBYTES: number; const crypto_auth_BYTES: number; const crypto_auth_KEYBYTES: number; const crypto_auth_hmacsha256_BYTES: number; const crypto_auth_hmacsha256_KEYBYTES: number; const crypto_auth_hmacsha512_BYTES: number; const crypto_auth_hmacsha512_KEYBYTES: number; const crypto_box_BEFORENMBYTES: number; const crypto_box_MACBYTES: number; const crypto_box_MESSAGEBYTES_MAX: number; const crypto_box_NONCEBYTES: number; const crypto_box_PUBLICKEYBYTES: number; const crypto_box_SEALBYTES: number; const crypto_box_SECRETKEYBYTES: number; const crypto_box_SEEDBYTES: number; const crypto_core_hchacha20_CONSTBYTES: number; const crypto_core_hchacha20_INPUTBYTES: number; const crypto_core_hchacha20_KEYBYTES: number; const crypto_core_hchacha20_OUTPUTBYTES: number; const crypto_generichash_BYTES: number; const crypto_generichash_BYTES_MAX: number; const crypto_generichash_BYTES_MIN: number; const crypto_generichash_KEYBYTES: number; const crypto_generichash_KEYBYTES_MAX: number; const crypto_generichash_KEYBYTES_MIN: number; const crypto_hash_BYTES: number; const crypto_hash_sha256_BYTES: number; const crypto_hash_sha512_BYTES: number; const crypto_kdf_BYTES_MAX: number; const crypto_kdf_BYTES_MIN: number; const crypto_kdf_CONTEXTBYTES: number; const crypto_kdf_KEYBYTES: number; const crypto_kx_PUBLICKEYBYTES: number; const crypto_kx_SECRETKEYBYTES: number; const crypto_kx_SEEDBYTES: number; const crypto_kx_SESSIONKEYBYTES: number; const crypto_onetimeauth_BYTES: number; const crypto_onetimeauth_KEYBYTES: number; const crypto_pwhash_ALG_ARGON2I13: number; const crypto_pwhash_ALG_ARGON2ID13: number; const crypto_pwhash_ALG_DEFAULT: number; const crypto_pwhash_BYTES_MAX: number; const crypto_pwhash_BYTES_MIN: number; const crypto_pwhash_MEMLIMIT_INTERACTIVE: number; const crypto_pwhash_MEMLIMIT_MAX: number; const crypto_pwhash_MEMLIMIT_MIN: number; const crypto_pwhash_MEMLIMIT_MODERATE: number; const crypto_pwhash_MEMLIMIT_SENSITIVE: number; const crypto_pwhash_OPSLIMIT_INTERACTIVE: number; const crypto_pwhash_OPSLIMIT_MAX: number; const crypto_pwhash_OPSLIMIT_MIN: number; const crypto_pwhash_OPSLIMIT_MODERATE: number; const crypto_pwhash_OPSLIMIT_SENSITIVE: number; const crypto_pwhash_PASSWD_MAX: number; const crypto_pwhash_PASSWD_MIN: number; const crypto_pwhash_SALTBYTES: number; const crypto_pwhash_STRBYTES: number; const crypto_pwhash_STRPREFIX: string; const crypto_pwhash_STR_VERIFY: number; const crypto_pwhash_scryptsalsa208sha256_BYTES_MAX: number; const crypto_pwhash_scryptsalsa208sha256_BYTES_MIN: number; const crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_INTERACTIVE: number; const crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MAX: number; const crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_MIN: number; const crypto_pwhash_scryptsalsa208sha256_MEMLIMIT_SENSITIVE: number; const crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_INTERACTIVE: number; const crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MAX: number; const crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_MIN: number; const crypto_pwhash_scryptsalsa208sha256_OPSLIMIT_SENSITIVE: number; const crypto_pwhash_scryptsalsa208sha256_SALTBYTES: number; const crypto_pwhash_scryptsalsa208sha256_STRBYTES: number; const crypto_pwhash_scryptsalsa208sha256_STRPREFIX: string; const crypto_pwhash_scryptsalsa208sha256_STR_VERIFY: number; const crypto_scalarmult_BYTES: number; const crypto_scalarmult_SCALARBYTES: number; const crypto_secretbox_KEYBYTES: number; const crypto_secretbox_MACBYTES: number; const crypto_secretbox_MESSAGEBYTES_MAX: number; const crypto_secretbox_NONCEBYTES: number; const crypto_secretstream_xchacha20poly1305_ABYTES: number; const crypto_secretstream_xchacha20poly1305_HEADERBYTES: number; const crypto_secretstream_xchacha20poly1305_KEYBYTES: number; const crypto_secretstream_xchacha20poly1305_MESSAGEBYTES_MAX: number; const crypto_secretstream_xchacha20poly1305_MESSAGESBYTES_MAX: number; const crypto_secretstream_xchacha20poly1305_NPUBBYTES: number; const crypto_secretstream_xchacha20poly1305_TAG_FINAL: number; const crypto_secretstream_xchacha20poly1305_TAG_MESSAGE: number; const crypto_secretstream_xchacha20poly1305_TAG_PUSH: number; const crypto_secretstream_xchacha20poly1305_TAG_REKEY: number; const crypto_shorthash_BYTES: number; const crypto_shorthash_KEYBYTES: number; const crypto_shorthash_siphashx24_BYTES: number; const crypto_shorthash_siphashx24_KEYBYTES: number; const crypto_sign_BYTES: number; const crypto_sign_MESSAGEBYTES_MAX: number; const crypto_sign_PUBLICKEYBYTES: number; const crypto_sign_SECRETKEYBYTES: number; const crypto_sign_SEEDBYTES: number; const crypto_stream_KEYBYTES: number; const crypto_stream_MESSAGEBYTES_MAX: number; const crypto_stream_NONCEBYTES: number; const crypto_stream_chacha20_KEYBYTES: number; const crypto_stream_chacha20_NONCEBYTES: number; const crypto_stream_chacha20_ietf_KEYBYTES: number; const crypto_stream_chacha20_ietf_MESSAGEBYTES_MAX: number; const crypto_stream_chacha20_ietf_NONCEBYTES: number; const crypto_stream_xchacha20_KEYBYTES: number; const crypto_stream_xchacha20_MESSAGEBYTES_MAX: number; const crypto_stream_xchacha20_NONCEBYTES: number; const randombytes_SEEDBYTES: number; function add(a: Uint8Array, b: Uint8Array): void; function compare(b1: Uint8Array, b2: Uint8Array): number; function crypto_aead_chacha20poly1305_decrypt(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_chacha20poly1305_decrypt(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_aead_chacha20poly1305_decrypt_detached(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, mac: Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_chacha20poly1305_decrypt_detached(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, mac: Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_aead_chacha20poly1305_encrypt(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_chacha20poly1305_encrypt(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_aead_chacha20poly1305_encrypt_detached(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): CryptoBox; function crypto_aead_chacha20poly1305_encrypt_detached(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): StringCryptoBox; function crypto_aead_chacha20poly1305_ietf_decrypt(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_chacha20poly1305_ietf_decrypt(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_aead_chacha20poly1305_ietf_decrypt_detached(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, mac: Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_chacha20poly1305_ietf_decrypt_detached(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, mac: Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_aead_chacha20poly1305_ietf_encrypt(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_chacha20poly1305_ietf_encrypt(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): CryptoBox; function crypto_aead_chacha20poly1305_ietf_encrypt_detached(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): StringCryptoBox; function crypto_aead_chacha20poly1305_ietf_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_chacha20poly1305_ietf_keygen(outputFormat: StringOutputFormat): string; function crypto_aead_chacha20poly1305_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_chacha20poly1305_keygen(outputFormat: StringOutputFormat): string; function crypto_aead_xchacha20poly1305_ietf_decrypt(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_xchacha20poly1305_ietf_decrypt(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_aead_xchacha20poly1305_ietf_decrypt_detached(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, mac: Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_xchacha20poly1305_ietf_decrypt_detached(secret_nonce: string | Uint8Array | null, ciphertext: string | Uint8Array, mac: Uint8Array, additional_data: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_aead_xchacha20poly1305_ietf_encrypt(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_xchacha20poly1305_ietf_encrypt(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): CryptoBox; function crypto_aead_xchacha20poly1305_ietf_encrypt_detached(message: string | Uint8Array, additional_data: string | Uint8Array | null, secret_nonce: string | Uint8Array | null, public_nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): StringCryptoBox; function crypto_aead_xchacha20poly1305_ietf_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_aead_xchacha20poly1305_ietf_keygen(outputFormat: StringOutputFormat): string; function crypto_auth(message: string | Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_auth(message: string | Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_auth_hmacsha256(message: string | Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_auth_hmacsha256(message: string | Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_auth_hmacsha256_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_auth_hmacsha256_keygen(outputFormat: StringOutputFormat): string; function crypto_auth_hmacsha256_verify(tag: Uint8Array, message: string | Uint8Array, key: Uint8Array): boolean; function crypto_auth_hmacsha512(message: string | Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_auth_hmacsha512(message: string | Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_auth_hmacsha512_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_auth_hmacsha512_keygen(outputFormat: StringOutputFormat): string; function crypto_auth_hmacsha512_verify(tag: Uint8Array, message: string | Uint8Array, key: Uint8Array): boolean; function crypto_auth_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_auth_keygen(outputFormat: StringOutputFormat): string; function crypto_auth_verify(tag: Uint8Array, message: string | Uint8Array, key: Uint8Array): boolean; function crypto_box_beforenm(publicKey: Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_box_beforenm(publicKey: Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_box_detached(message: string | Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): CryptoBox; function crypto_box_detached(message: string | Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): StringCryptoBox; function crypto_box_easy(message: string | Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_box_easy(message: string | Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_box_easy_afternm(message: string | Uint8Array, nonce: Uint8Array, sharedKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_box_easy_afternm(message: string | Uint8Array, nonce: Uint8Array, sharedKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_box_keypair(outputFormat?: Uint8ArrayOutputFormat): KeyPair; function crypto_box_keypair(outputFormat: StringOutputFormat): StringKeyPair; function crypto_box_open_detached(ciphertext: string | Uint8Array, mac: Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_box_open_detached(ciphertext: string | Uint8Array, mac: Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_box_open_easy(ciphertext: string | Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_box_open_easy(ciphertext: string | Uint8Array, nonce: Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_box_open_easy_afternm(ciphertext: string | Uint8Array, nonce: Uint8Array, sharedKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_box_open_easy_afternm(ciphertext: string | Uint8Array, nonce: Uint8Array, sharedKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_box_seal(message: string | Uint8Array, publicKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_box_seal(message: string | Uint8Array, publicKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_box_seal_open(ciphertext: string | Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_box_seal_open(ciphertext: string | Uint8Array, publicKey: Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_box_seed_keypair(seed: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): KeyPair; function crypto_box_seed_keypair(seed: Uint8Array, outputFormat: StringOutputFormat): StringKeyPair; function crypto_generichash(hash_length: number, message: string | Uint8Array, key: string | Uint8Array | null, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_generichash(hash_length: number, message: string | Uint8Array, key: string | Uint8Array | null, outputFormat: StringOutputFormat): string; function crypto_generichash_final(state_address: generichash_state_address, hash_length: number, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_generichash_final(state_address: generichash_state_address, hash_length: number, outputFormat: StringOutputFormat): string; function crypto_generichash_init(key: string | Uint8Array | null, hash_length: number): state_address; function crypto_generichash_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_generichash_keygen(outputFormat: StringOutputFormat): string; function crypto_generichash_update(state_address: generichash_state_address, message_chunk: string | Uint8Array): void; function crypto_hash(message: string | Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_hash(message: string | Uint8Array, outputFormat: StringOutputFormat): string; function crypto_hash_sha256(message: string | Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_hash_sha256(message: string | Uint8Array, outputFormat: StringOutputFormat): string; function crypto_hash_sha512(message: string | Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_hash_sha512(message: string | Uint8Array, outputFormat: StringOutputFormat): string; function crypto_kdf_derive_from_key(subkey_len: number, subkey_id: number, ctx: string, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_kdf_derive_from_key(subkey_len: number, subkey_id: number, ctx: string, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_kdf_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_kdf_keygen(outputFormat: StringOutputFormat): string; function crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): CryptoKX; function crypto_kx_client_session_keys(clientPublicKey: Uint8Array, clientSecretKey: Uint8Array, serverPublicKey: Uint8Array, outputFormat: StringOutputFormat): StringCryptoKX; function crypto_kx_keypair(outputFormat?: Uint8ArrayOutputFormat): KeyPair; function crypto_kx_keypair(outputFormat: StringOutputFormat): StringKeyPair; function crypto_kx_seed_keypair(seed: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): KeyPair; function crypto_kx_seed_keypair(seed: Uint8Array, outputFormat: StringOutputFormat): StringKeyPair; function crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): CryptoKX; function crypto_kx_server_session_keys(serverPublicKey: Uint8Array, serverSecretKey: Uint8Array, clientPublicKey: Uint8Array, outputFormat: StringOutputFormat): StringCryptoKX; function crypto_onetimeauth(message: string | Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_onetimeauth(message: string | Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_onetimeauth_final(state_address: onetimeauth_state_address, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_onetimeauth_final(state_address: onetimeauth_state_address, outputFormat: StringOutputFormat): string; function crypto_onetimeauth_init(key: string | Uint8Array | null): state_address; function crypto_onetimeauth_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_onetimeauth_keygen(outputFormat: StringOutputFormat): string; function crypto_onetimeauth_update(state_address: onetimeauth_state_address, message_chunk: string | Uint8Array): void; function crypto_onetimeauth_verify(hash: Uint8Array, message: string | Uint8Array, key: Uint8Array): boolean; function crypto_pwhash(keyLength: number, password: string | Uint8Array, salt: Uint8Array, opsLimit: number, memLimit: number, algorithm: number, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_pwhash(keyLength: number, password: string | Uint8Array, salt: Uint8Array, opsLimit: number, memLimit: number, algorithm: number, outputFormat: StringOutputFormat): string; function crypto_pwhash_scryptsalsa208sha256(keyLength: number, password: string | Uint8Array, salt: Uint8Array, opsLimit: number, memLimit: number, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_pwhash_scryptsalsa208sha256(keyLength: number, password: string | Uint8Array, salt: Uint8Array, opsLimit: number, memLimit: number, outputFormat: StringOutputFormat): string; function crypto_pwhash_scryptsalsa208sha256_ll(password: string | Uint8Array, salt: string | Uint8Array, opsLimit: number, r: number, p: number, keyLength: number, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_pwhash_scryptsalsa208sha256_ll(password: string | Uint8Array, salt: string | Uint8Array, opsLimit: number, r: number, p: number, keyLength: number, outputFormat: StringOutputFormat): string; function crypto_pwhash_scryptsalsa208sha256_str(password: string | Uint8Array, opsLimit: number, memLimit: number): string; function crypto_pwhash_scryptsalsa208sha256_str_verify(hashed_password: string, password: string | Uint8Array): boolean; function crypto_pwhash_str(password: string | Uint8Array, opsLimit: number, memLimit: number): string; function crypto_pwhash_str_verify(hashed_password: string, password: string | Uint8Array): boolean; function crypto_scalarmult(privateKey: Uint8Array, publicKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_scalarmult(privateKey: Uint8Array, publicKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_scalarmult_base(privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_scalarmult_base(privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_secretbox_detached(message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): SecretBox; function crypto_secretbox_detached(message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): StringSecretBox; function crypto_secretbox_easy(message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_secretbox_easy(message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_secretbox_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_secretbox_keygen(outputFormat: StringOutputFormat): string; function crypto_secretbox_open_detached(ciphertext: string | Uint8Array, mac: Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_secretbox_open_detached(ciphertext: string | Uint8Array, mac: Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_secretbox_open_easy(ciphertext: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_secretbox_open_easy(ciphertext: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_secretstream_xchacha20poly1305_init_pull(header: Uint8Array, key: Uint8Array): state_address; function crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_secretstream_xchacha20poly1305_init_push(key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_secretstream_xchacha20poly1305_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_secretstream_xchacha20poly1305_keygen(outputFormat: StringOutputFormat): string; function crypto_secretstream_xchacha20poly1305_pull(state_address: secretstream_xchacha20poly1305_state_address, cipher: string | Uint8Array, ad: string | Uint8Array | null, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_secretstream_xchacha20poly1305_pull(state_address: secretstream_xchacha20poly1305_state_address, cipher: string | Uint8Array, ad: string | Uint8Array | null, outputFormat: StringOutputFormat): string; function crypto_secretstream_xchacha20poly1305_push(state_address: secretstream_xchacha20poly1305_state_address, message_chunk: string | Uint8Array, ad: string | Uint8Array | null, tag: number, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_secretstream_xchacha20poly1305_push(state_address: secretstream_xchacha20poly1305_state_address, message_chunk: string | Uint8Array, ad: string | Uint8Array | null, tag: number, outputFormat: StringOutputFormat): string; function crypto_secretstream_xchacha20poly1305_rekey(state_address: secretstream_xchacha20poly1305_state_address): true; function crypto_shorthash(message: string | Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_shorthash(message: string | Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_shorthash_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_shorthash_keygen(outputFormat: StringOutputFormat): string; function crypto_shorthash_siphashx24(message: string | Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_shorthash_siphashx24(message: string | Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_sign(message: string | Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_sign(message: string | Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_sign_detached(message: string | Uint8Array, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_sign_detached(message: string | Uint8Array, privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_sign_ed25519_pk_to_curve25519(edPk: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_sign_ed25519_pk_to_curve25519(edPk: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_sign_ed25519_sk_to_curve25519(edSk: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_sign_ed25519_sk_to_curve25519(edSk: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_sign_ed25519_sk_to_pk(privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_sign_ed25519_sk_to_pk(privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_sign_ed25519_sk_to_seed(privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_sign_ed25519_sk_to_seed(privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_sign_final_create(state_address: sign_state_address, privateKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_sign_final_create(state_address: sign_state_address, privateKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_sign_final_verify(state_address: sign_state_address, signature: Uint8Array, publicKey: Uint8Array): boolean; function crypto_sign_init(): state_address; function crypto_sign_keypair(outputFormat?: Uint8ArrayOutputFormat): KeyPair; function crypto_sign_keypair(outputFormat: StringOutputFormat): StringKeyPair; function crypto_sign_open(signedMessage: string | Uint8Array, publicKey: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_sign_open(signedMessage: string | Uint8Array, publicKey: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_sign_seed_keypair(seed: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): KeyPair; function crypto_sign_seed_keypair(seed: Uint8Array, outputFormat: StringOutputFormat): StringKeyPair; function crypto_sign_update(state_address: sign_state_address, message_chunk: string | Uint8Array): void; function crypto_sign_verify_detached(signature: Uint8Array, message: string | Uint8Array, publicKey: Uint8Array): boolean; function crypto_stream_chacha20_ietf_xor(input_message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_stream_chacha20_ietf_xor(input_message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_stream_chacha20_ietf_xor_ic(input_message: string | Uint8Array, nonce: Uint8Array, nonce_increment: number, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_stream_chacha20_ietf_xor_ic(input_message: string | Uint8Array, nonce: Uint8Array, nonce_increment: number, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_stream_chacha20_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_stream_chacha20_keygen(outputFormat: StringOutputFormat): string; function crypto_stream_chacha20_xor(input_message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_stream_chacha20_xor(input_message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_stream_chacha20_xor_ic(input_message: string | Uint8Array, nonce: Uint8Array, nonce_increment: number, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_stream_chacha20_xor_ic(input_message: string | Uint8Array, nonce: Uint8Array, nonce_increment: number, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_stream_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_stream_keygen(outputFormat: StringOutputFormat): string; function crypto_stream_xchacha20_keygen(outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_stream_xchacha20_keygen(outputFormat: StringOutputFormat): string; function crypto_stream_xchacha20_xor(input_message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_stream_xchacha20_xor(input_message: string | Uint8Array, nonce: Uint8Array, key: Uint8Array, outputFormat: StringOutputFormat): string; function crypto_stream_xchacha20_xor_ic(input_message: string | Uint8Array, nonce: Uint8Array, nonce_increment: number, key: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function crypto_stream_xchacha20_xor_ic(input_message: string | Uint8Array, nonce: Uint8Array, nonce_increment: number, key: Uint8Array, outputFormat: StringOutputFormat): string; function from_base64(input: string, variant: base64_variants): Uint8Array; function from_hex(input: string): string; function from_string(str: string): Uint8Array; function increment(bytes: Uint8Array): void; function is_zero(bytes: Uint8Array): boolean; function memcmp(b1: Uint8Array, b2: Uint8Array): boolean; function memzero(bytes: Uint8Array): void; function pad(buf: Uint8Array, blocksize: number): Uint8Array; function randombytes_buf(length: number, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function randombytes_buf(length: number, outputFormat: StringOutputFormat): string; function randombytes_buf_deterministic(length: number, seed: Uint8Array, outputFormat?: Uint8ArrayOutputFormat): Uint8Array; function randombytes_buf_deterministic(length: number, seed: Uint8Array, outputFormat: StringOutputFormat): string; function randombytes_close(): void; function randombytes_random(): number; function randombytes_set_implementation(implementation: Uint8Array): void; function randombytes_stir(): void; function randombytes_uniform(upper_bound: number): number; function ready(): Promise; function sodium_version_string(): string; function to_base64(input: string | Uint8Array, variant: base64_variants): string; function to_hex(input: string | Uint8Array): string; function to_string(bytes: Uint8Array): string; function unpad(buf: Uint8Array, blocksize: number): Uint8Array; } ```
ffflorian commented 6 years ago

Hi @jedisct1 and @bufke, did you have a chance to test out my definitions file?

At Wire, we are using it already at wire-web-proteus and it works pretty well so far. Nevertheless, I'd like to read a second review before I publish it to DefinitelyTyped.

webmaster128 commented 6 years ago

@ffflorian in libsodium.d.ts .ready is a function instead of a simple Promise object. I think is is a definition bug, isn't it? And big thanks for doing this BTW

buu700 commented 6 years ago

Nice work! One other comment: it'd be convenient if all the union types that include null also included undefined, as that could cause headaches with strict null checks.

Along the same lines, doesn't matter much to me, but it may also be worth making null a possible type of all the optional arguments β€” e.g. outputFormat?: Uint8ArrayOutputFormat -> outputFormat?: Uint8ArrayOutputFormat|null.

ffflorian commented 6 years ago

@webmaster128 You are right, thanks. I fixed it in https://github.com/ffflorian/libsodium-type-generator/commit/96afcec2f9cc8606366afb0c0eb583a1437b9d42.

@buu700 Thanks for the hints. Unfortunately I can't change a function like

function crypto_generichash_init(key: Uint8Array | null, hash_length: number): state_address;

to

function crypto_generichash_init(key?: Uint8Array | null, hash_length: number): state_address;

because hash_length is required and a required argument can't follow an optional argument.

I fixed this by making key mandatory but allowing it to be null in https://github.com/ffflorian/libsodium-type-generator/compare/96afcec2f9cc8606366afb0c0eb583a1437b9d42...c3f97b2bc8f8d00a5661e2d4febbb535b1750413.

Please see version 1.0.9 for the updated declaration file.

buu700 commented 6 years ago

I know a required argument can't follow an optional one; what I was suggesting was to explicitly add undefined as an accepted input type. In that example, it would look like:

function crypto_generichash_init(key: Uint8Array | null | undefined, hash_length: number): state_address;
ffflorian commented 6 years ago

@buu700 Oh, of course. Thanks! Fixed in https://github.com/ffflorian/libsodium-type-generator/commit/24cfd62eddf6877335f8fc3132d5750a53a03681 and updated the declaration file in v1.0.10.

buu700 commented 6 years ago

Awesome, thanks for the quick fix!

bufke commented 6 years ago

@ffflorian I was able to drop in your generated d.ts to my project and it works without any TS errors. Thanks, great work!

buu700 commented 6 years ago

I haven't tested this myself yet, but just noticed something else: shouldn't all the instances of outputFormat?: StringOutputFormat actually be required arguments (since calling a function with the output unspecified returns a byte array)?

NullVoxPopuli commented 6 years ago

Slightly more up to date type defs: https://gitlab.com/NullVoxPopuli/emberclear/blob/master/packages/frontend/types/emberclear/libsodium.d.ts

webmaster128 commented 6 years ago

@NullVoxPopuli Did you really check @ffflorian's latest work here https://github.com/ffflorian/libsodium-type-generator/releases? He does an incredibly great job with the types and responses very quickly and competent to the few edge case issues that may be left. You might want to contribute to his repo for the benefit of everyone

buu700 commented 6 years ago

Speaking of which, is that ready for general use yet? And are there any plans to integrate it into either the main libsodium packages or separate @types packages, @ffflorian and @jedisct1?

webmaster128 commented 6 years ago

I am happily using @ffflorian's types in two different projects by manually downloading the definition file from the release page into my project. The generator itself is not needed by users.

buu700 commented 6 years ago

Awesome, that's great to hear.

ffflorian commented 6 years ago

@buu700 the types are - in my opinion - ready to use, but I didn't really find a good solution yet for the sumo version to include only the types for the extra functions.

Sooner or later I will create a PR here or @types, depending on how @jedisct1 sees it.

buu700 commented 6 years ago

As in a way of having in the generated libsodium-wrappers-sumo definition extend libsodium-wrappers?

Either way is probably fine IMO since it's just generated code anyway, but from a quick test it should work if you explicitly add export to everything (e.g. export const SODIUM_LIBRARY_VERSION_MAJOR: number;) and then add export * from 'libsodium-wrappers'; to libsodium-wrappers-sumo.

ffflorian commented 6 years ago

@buu700 Thank you for your input, I'll try adding it in the next days.

ffflorian commented 6 years ago

https://github.com/DefinitelyTyped/DefinitelyTyped/pull/27447

NullVoxPopuli commented 6 years ago

the types don't define a sodium method, so I had to do this:

image

webmaster128 commented 6 years ago

@NullVoxPopuli your import statement imports a default export, but there is no default export in the module.

What you want to do is either import * as libsodiumWrapper from 'libsodium-wrappers' or import sodium = require("libsodium-wrappers");. I use the later because I was having problems with the first one (maybe related to https://github.com/jedisct1/libsodium.js/issues/148).

NullVoxPopuli commented 6 years ago

@webmaster128 I'm currently using broccoli for my js importer, so I've assigned everything to a default export. So, my typing issue was somewhat on me. lol

bufke commented 6 years ago

Should we close this at this point? Any issues with types could just be their own issue. I've been using the types for many months without issue.

NullVoxPopuli commented 6 years ago

I'd say so.