Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

'import' syntax compatible and TypeScript declaration file #1038

Merged
merged 31 commits into from
Nov 28, 2023
Merged
Show file tree
Hide file tree
Changes from 17 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
7cafa69
exports
radetsky Nov 22, 2023
abe6207
Add TypeScript declaration file (index.d.ts)
radetsky Nov 22, 2023
a1cdad8
Remove non-existent methods
radetsky Nov 23, 2023
473401d
Add example for TypeScript
radetsky Nov 23, 2023
4864b00
Add flow for NodeJS with Typescript example
radetsky Nov 23, 2023
dfc73ca
restore test-nodejs.yaml
radetsky Nov 23, 2023
ede00cd
add test-nodejs-openssl3.yaml
radetsky Nov 23, 2023
c1d4275
update test-nodejs-openssl3.yaml
radetsky Nov 23, 2023
c0694b3
update test-nodejs-openssl3.yaml
radetsky Nov 23, 2023
688a7dc
update test-nodejs-openssl3.yaml
radetsky Nov 23, 2023
2bfd34a
update test-nodejs-openssl3.yaml
radetsky Nov 23, 2023
b19cc94
update test-nodejs-openssl3.yaml
radetsky Nov 23, 2023
671fc81
update test-nodejs-openssl3.yaml
radetsky Nov 23, 2023
91a1275
remove failed test-nodejs-openssl3.yaml
radetsky Nov 24, 2023
a8c0865
move TS examples to another PR
radetsky Nov 24, 2023
dcc1182
restore previous test-nodejs.yaml
radetsky Nov 24, 2023
f7c1f2d
CHANGELOG.md updated
radetsky Nov 24, 2023
57cc538
added two constructors
radetsky Nov 24, 2023
a7f1af8
added import_module.mjs and test
radetsky Nov 27, 2023
5f12c5b
remove not needed string
radetsky Nov 27, 2023
576c69a
Merge pull request #1 from radetsky/rad/import_module_mjs
radetsky Nov 27, 2023
2c35b56
ts tests 1
radetsky Nov 27, 2023
5040c7b
update workflow
radetsky Nov 27, 2023
8fde76e
update workflow
radetsky Nov 27, 2023
dddc4ca
update workflow
radetsky Nov 27, 2023
1072e0f
update workflow
radetsky Nov 27, 2023
a9d0a5e
downgrade typescript to 4.4 to be compatible with node 12
radetsky Nov 27, 2023
8457223
update workflow
radetsky Nov 27, 2023
3afd6af
update workflow
radetsky Nov 27, 2023
a393159
Merge pull request #2 from radetsky/rad/ts_tests
radetsky Nov 27, 2023
1f28271
delete secure_cell.js from ts/
radetsky Nov 28, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,11 @@

Changes that are currently in development and have not been released yet.

## [0.15.2](https://github.com/cossacklabs/themis/releases/tag/0.15.2), October 03 2023
## [0.15.2](https://github.com/cossacklabs/themis/releases/tag/0.15.2), November 24 2023

### JsThemis wrapper
- Added the ability to use the `import` syntax for the jsthemis module.
- Added a declaration file for TypeScript.

### Android, ReactNative wrappers
Updated versions of dependencies. New minimum versions of iOS, Android are set.
Expand Down
58 changes: 58 additions & 0 deletions src/wrappers/themis/jsthemis/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
export declare class KeyPair {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you write this file manually or somehow generated from the sources?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Manually. I did not find the tool that can read .node file to make a declaration file.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need constructor() here too similar to SymmetricKey? KeyPair looks like has constructor too -

void KeyPair::New(const Nan::FunctionCallbackInfo<v8::Value>& args)

And not obvious that it constructed from public + private

public(): Uint8Array;
private(): Uint8Array;
}

export declare class SymmetricKey {
constructor();
}

export declare class SecureCellSeal {
static withKey(key: SymmetricKey): SecureCellSeal;
static withPassphrase(passphrase: string): SecureCellSeal;
encrypt(plaintext: Uint8Array, context?: Uint8Array): Uint8Array;
decrypt(encrypted: Uint8Array, context?: Uint8Array): Uint8Array;
}

export declare interface SecureCellTokenProtectResult {
data: Uint8Array;
token: Uint8Array;
}

export declare class SecureCellTokenProtect {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like TokenProtect has constructor that expects key too -


or somehow used as WithKey.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've checked. We do not announce that we can do it, but construction with new SecureCellTokenProtect(masterkey) will also work the same as SecureCellTokenProtect.withKey(masterKey). It wraps one function into a constructor.
I'm adding the constructor declaration.

static withKey(key: SymmetricKey): SecureCellTokenProtect;
encrypt(plaintext: Uint8Array, context?: Uint8Array): SecureCellTokenProtectResult;
decrypt(encrypted: Uint8Array, token: Uint8Array, context?: Uint8Array): Uint8Array;
}

export declare class SecureCellContextImprint {
static withKey(key: SymmetricKey): SecureCellContextImprint;
encrypt(plaintext: Uint8Array, context: Uint8Array): Uint8Array;
decrypt(encrypted: Uint8Array, context: Uint8Array): Uint8Array;
}

export declare class SecureMessage {
constructor(privateKey: Uint8Array | null, publicKey: Uint8Array | null);
sign(message: Uint8Array): Uint8Array;
verify(message: Uint8Array): Uint8Array;
encrypt(message: Uint8Array): Uint8Array;
decrypt(message: Uint8Array): Uint8Array;
}

type GetPublicKeyCallback = (peerID: Uint8Array) => Uint8Array | null;

export declare class SecureSession {
constructor(peerID: Uint8Array, privateKey: Uint8Array, getPublicKeyCallback: GetPublicKeyCallback);
isEstablished(): boolean;
connectRequest(): Uint8Array;
wrap(message: Uint8Array): Uint8Array;
unwrap(message: Uint8Array): Uint8Array;
}

export declare class SecureComparator {
constructor(sharedSecret: Uint8Array);
beginCompare(): Uint8Array;
proceedCompare(request: Uint8Array): Uint8Array;
isCompareComplete(): boolean;
isMatch(): boolean;
}
4 changes: 4 additions & 0 deletions src/wrappers/themis/jsthemis/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
module.exports = {
...require('./build/Release/jsthemis.node')
};

4 changes: 2 additions & 2 deletions src/wrappers/themis/jsthemis/package.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"name": "jsthemis",
"version": "0.15.0",
"version": "0.15.2",
"description": "Themis is a convenient cryptographic library for data protection.",
"main": "build/Release/jsthemis.node",
"main": "index.js",
"scripts": {
"test": "mocha",
"preuninstall": "rm -rf build/*",
Expand Down
Loading