-
Notifications
You must be signed in to change notification settings - Fork 143
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
Migrate wasm-themis to TypeScript #792
Merged
Merged
Changes from 3 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
e5cc867
Modularize wasm themis
maxammann f3a1a89
Change extensions
maxammann 9336d39
Translate plain js to typescript
maxammann dada873
Add typescript and esbuild dependencies
maxammann f17c73c
Add tsconfig and script to build library
maxammann 81a2d25
Fix tests by making undefined a valid value
maxammann ccfa90f
Add ts-mocha package
maxammann 232d64e
Make wasmPath optional for node environment
maxammann d14fcd5
Fix gitignore
maxammann f7113d6
Move declaration into sepratate file
maxammann be2ad37
Remove esbuild and setup library creation
maxammann b250394
Run npm install
maxammann d1a3f3c
Update lock file
maxammann 2da6cb9
Switch target to es6, else tests fail
maxammann 70712b9
Fix compile commands
maxammann d50be05
Update node code in tools/
maxammann 3403cbc
Set target for tests to es5
maxammann efd516b
Remove extends; this is not allowed with ES5
maxammann d2147b9
Fix tests for adapted api and es5
maxammann ac0bf2d
Merge branch 'master' into typescript
maxammann b49c385
Readd test
maxammann a4e84ee
Upgrade package
maxammann File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
["_malloc","dynamicAlloc"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,232 @@ | ||
import { ThemisErrorCode } from "./themis_error"; | ||
import { KeyKind } from "./secure_keygen"; | ||
|
||
export interface YourOwnEmscriptenModule extends EmscriptenModule { | ||
writeArrayToMemory: typeof writeArrayToMemory; | ||
_memset: (buffer: number, offer: number, length: number) => void; | ||
setValue: typeof setValue; | ||
getValue: typeof getValue; | ||
|
||
_secure_comparator_create(): number; | ||
|
||
_secure_comparator_destroy(ptr: number): ThemisErrorCode; | ||
|
||
_secure_comparator_append_secret( | ||
comparatorPtr: number, | ||
secret_ptr: number, | ||
secret_length: number | ||
): ThemisErrorCode; | ||
|
||
_secure_comparator_proceed_compare( | ||
comparatorPtr: number, | ||
request_ptr: number, | ||
request_length: number, | ||
reply_ptr: number | null, | ||
reply_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_secure_comparator_begin_compare( | ||
comparatorPtr: number, | ||
message_ptr: number | null, | ||
message_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_gen_sym_key( | ||
key_ptr: number | null, | ||
key_len_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_gen_ec_key_pair( | ||
private_ptr: number | null, | ||
private_len_ptr: number, | ||
public_ptr: number | null, | ||
public_len_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_get_asym_key_kind(buffer_ptr: number, buffer_len: number): KeyKind; | ||
|
||
_themis_is_valid_asym_key( | ||
buffer_ptr: number, | ||
buffer_len: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_cell_encrypt_context_imprint( | ||
master_key_ptr: number, | ||
master_key_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
context_ptr: number, | ||
context_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_cell_decrypt_context_imprint( | ||
master_key_ptr: number, | ||
master_key_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
context_ptr: number, | ||
context_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_cell_encrypt_seal( | ||
master_key_ptr: number, | ||
master_key_length: number, | ||
context_ptr: number, | ||
context_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_cell_decrypt_seal( | ||
master_key_ptr: number, | ||
master_key_length: number, | ||
context_ptr: number, | ||
context_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_cell_encrypt_seal_with_passphrase( | ||
master_key_ptr: number, | ||
master_key_length: number, | ||
context_ptr: number, | ||
context_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_cell_decrypt_seal_with_passphrase( | ||
master_key_ptr: number, | ||
master_key_length: number, | ||
context_ptr: number, | ||
context_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_cell_encrypt_token_protect( | ||
master_key_ptr: number, | ||
master_key_length: number, | ||
context_ptr: number, | ||
context_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
token_ptr: number | null, | ||
token_length_ptr: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_cell_decrypt_token_protect( | ||
master_key_ptr: number, | ||
master_key_length: number, | ||
context_ptr: number, | ||
context_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
token_ptr: number, | ||
token_length_ptr: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_message_encrypt( | ||
private_key_ptr: number, | ||
privateKey_length: number, | ||
public_key_ptr: number, | ||
publicKey_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_message_decrypt( | ||
private_key_ptr: number, | ||
privateKey_length: number, | ||
public_key_ptr: number, | ||
publicKey_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_message_sign( | ||
private_key_ptr: number, | ||
privateKey_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_themis_secure_message_verify( | ||
public_key_ptr: number, | ||
public_key_length: number, | ||
message_ptr: number, | ||
message_length: number, | ||
result_ptr: number | null, | ||
result_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_secure_session_create( | ||
session_id_ptr: number, | ||
sessionID_length: number, | ||
private_key_ptr: number, | ||
privateKey_length: number, | ||
callbacks_ptr: number | ||
): number; | ||
|
||
_secure_session_destroy(sessionPtr: number): ThemisErrorCode; | ||
|
||
_secure_session_is_established(sessionPtr: ThemisErrorCode): number; | ||
|
||
_secure_comparator_get_result(comparatorPtr: number): ThemisErrorCode; | ||
|
||
_secure_session_generate_connect_request( | ||
sessionPtr: number, | ||
request_ptr: number | null, | ||
request_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_secure_session_unwrap( | ||
sessionPtr: number, | ||
message_ptr: number, | ||
message_length: number, | ||
reply_ptr: number | null, | ||
reply_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
_secure_session_wrap( | ||
sessionPtr: number, | ||
message_ptr: number, | ||
message_length: number, | ||
wrapped_ptr: number | null, | ||
wrapped_length_ptr: number | ||
): ThemisErrorCode; | ||
|
||
allocate: ( | ||
slab: number[] | ArrayBufferView | number | ArrayBuffer, | ||
allocator: number, | ||
ptr?: number | ||
) => number; | ||
ALLOC_STACK: typeof ALLOC_STACK; | ||
addFunction: typeof addFunction; | ||
} | ||
|
||
const context: { libthemis?: YourOwnEmscriptenModule } = {}; | ||
|
||
export default context; |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
// Copyright (c) 2019 Cossack Labs Limited | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
import context, { YourOwnEmscriptenModule } from "./context"; | ||
import libthemisFn from "./libthemis.js"; | ||
|
||
export { SecureCellSeal } from "./secure_cell_seal"; | ||
export { SecureCellTokenProtect } from "./secure_cell_token_protect"; | ||
export { SecureCellContextImprint } from "./secure_cell_context_imprint"; | ||
export { ThemisError, ThemisErrorCode } from "./themis_error"; | ||
export { | ||
SecureMessageSign, | ||
SecureMessage, | ||
SecureMessageVerify, | ||
} from "./secure_message"; | ||
export { SecureSession } from "./secure_session"; | ||
export { KeyPair, PrivateKey, PublicKey, SymmetricKey } from "./secure_keygen"; | ||
export { SecureComparator } from "./secure_comparator"; | ||
|
||
export const initialize = async (wasmPath: string) => { | ||
const libthemis = await libthemisFn({ | ||
onRuntimeInitialized: function () {}, | ||
locateFile: function () { | ||
return wasmPath; | ||
}, | ||
}); | ||
|
||
context.libthemis = libthemis as YourOwnEmscriptenModule; | ||
return libthemis; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Regarding the formatting change from "no semicolons and 4-space indents with single quotes" to "use semicolons with 2-space indents and double quotes". Most of the codebase uses 4-space indents, unless there is a strong preference for a particular style in the language (e.g., tabs in Go, 2-space indents in Ruby). Is there such thing in TypeScript ecosystem as a whole?
I don't really mind the style changing, given that all these lines are still going to change anyway with added typing and strict checks. But it would be nice to make it less of a cowboy and more organized. It would be cool to throw in code formatter to ensure that all newly added code is consistent with the new style. (Not in this PR. But maybe some time later.)
(Admittedly, existing JavaScript code is a mess right now. JsThemis tests, for example, use 2, 4, 8-space indents and a bunch of tabs in different places.)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree, I already throught about throwing in prettier.
Pretter works across IDEs and is the defacto standard for formating. I add this to the todo list.