-
Notifications
You must be signed in to change notification settings - Fork 44
Bite.ts 41/update t encrypt structure #300
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
base: develop
Are you sure you want to change the base?
Changes from all commits
dcc1ec5
cd2650e
4bdf63b
993fd2e
f584e27
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,56 @@ | ||
| import { createRequire } from 'module'; | ||
| import { fileURLToPath } from 'url'; | ||
| const require = createRequire(import.meta.url); | ||
| const ModuleFactory = require('./encrypt_node.js'); | ||
| let ModulePromise = null; | ||
| function resolveModuleAssetPath(filename) { | ||
| if (typeof filename !== 'string' || filename.length === 0) { | ||
| throw new TypeError('filename must be a non-empty string'); | ||
| } | ||
| const resolvedPath = fileURLToPath(new URL(filename, import.meta.url)); | ||
| if (typeof resolvedPath !== 'string' || resolvedPath.length === 0) { | ||
| throw new Error('Failed to resolve module asset path'); | ||
| } | ||
| return resolvedPath; | ||
| } | ||
| function getModule() { | ||
| if (!ModulePromise) { | ||
| ModulePromise = ModuleFactory({ | ||
| locateFile: (filename) => { | ||
| return resolveModuleAssetPath(filename); | ||
| } | ||
| }); | ||
| } | ||
| return ModulePromise; | ||
| } | ||
|
|
||
| export async function encryptMessage(txData, publicKey, aadTE = '', aadAES = '') { | ||
| const Module = await getModule(); | ||
| return Module.ccall( | ||
| 'encryptMessage', | ||
| 'string', | ||
| ['string', 'string', 'string', 'string'], | ||
| [txData, publicKey, aadTE, aadAES] | ||
| ); | ||
| } | ||
|
|
||
| export async function encryptMessageDualKey( | ||
| txData, firstPublicKey, secondPublicKey, aadTE = '', aadAES = '') { | ||
| const Module = await getModule(); | ||
| return Module.ccall( | ||
| 'encryptMessageDualKey', | ||
| 'string', | ||
| ['string', 'string', 'string', 'string', 'string'], | ||
| [txData, firstPublicKey, secondPublicKey, aadTE, aadAES] | ||
| ); | ||
| } | ||
|
|
||
| export async function encryptMessageMockup(txData) { | ||
| const Module = await getModule(); | ||
| return Module.ccall( | ||
| 'encryptMessageMockup', | ||
| 'string', | ||
| ['string'], | ||
| [txData] | ||
| ); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -144,11 +144,39 @@ if (NOT EMSCRIPTEN) | |
| endif() | ||
|
|
||
| if (EMSCRIPTEN) | ||
| add_executable(encrypt ../threshold_encryption/encryptMessage.cpp ../tools/utils.cpp) | ||
| set_target_properties(encrypt PROPERTIES LINK_FLAGS "-s EXIT_RUNTIME=1 -s USE_PTHREADS=0 -s MODULARIZE -s ALLOW_MEMORY_GROWTH=1 -s NO_DISABLE_EXCEPTION_CATCHING=1 -s EXPORTED_RUNTIME_METHODS='[\"ccall\"]' -s EXPORTED_FUNCTIONS='[\"_encryptMessage\", \"_encryptMessageDualKey\",\"_encryptMessageMockup\"]' -s ENVIRONMENT='node,web' -s SINGLE_FILE=1") | ||
| target_include_directories(encrypt SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${THIRD_PARTY_DIR}) | ||
| target_compile_definitions(encrypt PRIVATE MCL=1) | ||
| target_link_libraries(encrypt PRIVATE te) | ||
| set(ENCRYPT_SOURCES ../threshold_encryption/encryptMessage.cpp ../tools/utils.cpp) | ||
| set(ENCRYPT_LINK_FLAGS "-s EXIT_RUNTIME=1 -s USE_PTHREADS=0 -s MODULARIZE -s ALLOW_MEMORY_GROWTH=1 -s NO_DISABLE_EXCEPTION_CATCHING=1 -s EXPORTED_RUNTIME_METHODS='[\"ccall\"]' -s EXPORTED_FUNCTIONS='[\"_encryptMessage\", \"_encryptMessageDualKey\",\"_encryptMessageMockup\"]'") | ||
|
|
||
| # encrypt_node (for Node.js) | ||
| add_executable(encrypt_node ${ENCRYPT_SOURCES}) | ||
| target_include_directories(encrypt_node SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${THIRD_PARTY_DIR}) | ||
| target_compile_definitions(encrypt_node PRIVATE MCL=1) | ||
| target_link_libraries(encrypt_node PRIVATE te) | ||
| set_target_properties(encrypt_node PROPERTIES | ||
| OUTPUT_NAME "encrypt_node" | ||
| LINK_FLAGS "${ENCRYPT_LINK_FLAGS} -s ENVIRONMENT='node'" | ||
| ) | ||
|
|
||
| # encrypt_web (for Browser / Vite / Webpack 5 / native ESM consumers) | ||
| add_executable(encrypt_web ${ENCRYPT_SOURCES}) | ||
| target_include_directories(encrypt_web SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${THIRD_PARTY_DIR}) | ||
| target_compile_definitions(encrypt_web PRIVATE MCL=1) | ||
| target_link_libraries(encrypt_web PRIVATE te) | ||
| set_target_properties(encrypt_web PROPERTIES | ||
| OUTPUT_NAME "encrypt_web" | ||
| LINK_FLAGS "${ENCRYPT_LINK_FLAGS} -s ENVIRONMENT='web' -s EXPORT_ES6=1" | ||
| ) | ||
|
|
||
| add_custom_command(TARGET encrypt_node POST_BUILD | ||
| COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/encrypt_node.js ${CMAKE_SOURCE_DIR}/node/encrypt_node.js | ||
| COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/encrypt_node.wasm ${CMAKE_SOURCE_DIR}/node/encrypt_node.wasm | ||
| COMMENT "Copying encrypt_node to node package folder" | ||
| ) | ||
| add_custom_command(TARGET encrypt_web POST_BUILD | ||
| COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/encrypt_web.js ${CMAKE_SOURCE_DIR}/node/encrypt_web.js | ||
| COMMAND ${CMAKE_COMMAND} -E copy ${CMAKE_CURRENT_BINARY_DIR}/encrypt_web.wasm ${CMAKE_SOURCE_DIR}/node/encrypt_web.wasm | ||
| COMMENT "Copying encrypt_web to node package folder" | ||
|
Comment on lines
+175
to
+178
|
||
| ) | ||
|
|
||
| add_executable(encrypt_message ../test/encryptMessageJS.cpp ../tools/utils.cpp) | ||
| target_include_directories(encrypt_message SYSTEM PRIVATE ${CMAKE_CURRENT_SOURCE_DIR} ${THIRD_PARTY_DIR}) | ||
|
|
||
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.
The POST_BUILD steps copy generated artifacts into
${CMAKE_SOURCE_DIR}/node, which mutates the source tree and can break read-only source checkouts or multi-config/out-of-tree builds (multiple build dirs racing to overwrite the same files). Prefer copying into an install/package staging directory (e.g., viainstall(FILES ...)+cpack, or a dedicatedpackage_nodetarget that writes under${CMAKE_CURRENT_BINARY_DIR}) and have the publish step pull from that output.