Node sdk identity enrollment script does not work

You have

import fs from 'fs';
import ziti from '@openziti/ziti-sdk-nodejs';

const ziti_enroll = async (jwt_path) => {
    return new Promise((resolve, reject) => {
        let rc = ziti.ziti_enroll(jwt_path, (data) => {
            if (data.identity) {
                resolve(data);
            } else {
                reject(data);
            }
        });
    });
};

let jwt_path = process.argv[2];

console.log('Specified Enrollment JWT is (%o)', jwt_path);

let data = await ziti_enroll(jwt_path).catch((data) => {
    console.log('Enroll failed with error (%o)', data);
});

if (data) {
    console.log("data is:\n\n%s", data);

    if (data.identity) {
        fs.writeFileSync('identity.json', data.identity);
    }
}

process.exit(0);

which mixes CJS and ESM so I had to rename it with suffix .mjs but it did not work anyways.

Then I refactored to CJS:

const fs = require('fs');
const ziti = require('@openziti/ziti-sdk-nodejs');

const ziti_enroll = (jwt_path) => {
    return new Promise((resolve, reject) => {
        let rc = ziti.ziti_enroll(jwt_path, (data) => {
            if (data.identity) {
                resolve(data);
            } else {
                reject(data);
            }
        });
    });
};

let jwt_path = process.argv[2];

console.log('Specified Enrollment JWT is (%o)', jwt_path);

ziti_enroll(jwt_path).then((data) => {
    if (data) {
        console.log("data is:\n\n%s", data);

        if (data.identity) {
            fs.writeFileSync('identity.json', data.identity);
        }
    }

    process.exit(0);
}).catch((data) => {
    console.log('Enroll failed with error (%o)', data);
});

It still does not work. I check nfconsole.io and the identity is not registered.
Ziti Desktop Edge is running and here are some screenshots:

I'm trying to follow this: How to Improve NodeJS Application Security

The app I'm trying to make dark is Owasp Juice Shop.

The downloaded client id registered right away when I aded in the Ziti Edge Desktop app but this script is not registering the juiceshop-server-id using the provided script

I'm looking into this. You have encountered an apparent bug in the SDK's enroll flow. I will post back here once the issue has been resolved.

1 Like

@nyck33 I released version 0.17.0 of the NodeJS SDK yesterday (which updated the enroll flow). Please upgrade to this version, and let us know if your issue is resolved. Thanks.

1 Like
yck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ npm list @openziti/ziti-sdk-nodejs
juice-shop@17.0.0 /mnt/d/web/juice-shop
└── @openziti/ziti-sdk-nodejs@0.17.0

nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ node enrollZiti.js juiceshop-server-id.jwt
Specified Enrollment JWT is ('juiceshop-server-id.jwt')
Enroll failed with error: Error: Unable to napi_create_threadsafe_function

  #  node[225016]: napi_status napi_call_threadsafe_function(napi_threadsafe_function, void*, napi_threadsafe_function_call_mode) at ../src/node_api.cc:1382
  #  Assertion failed: (func) != nullptr

----- Native stack trace -----

 1: 0xca5430 node::Abort() [node]
 2: 0xca54b0 node::errors::SetPrepareStackTraceCallback(v8::FunctionCallbackInfo<v8::Value> const&) [node]
 3: 0xc678b2 napi_call_threadsafe_function [node]
 4: 0x7fa1e3a68f8f on_ziti_enroll [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 5: 0x7fa1e3a789e1  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 6: 0x7fa1e3a79e3a  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 7: 0x7fa1e3a7aed8  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 8: 0x7fa1e3a9fdb5  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 9: 0x1eda7c1 llhttp__internal_execute [node]
10: 0x7fa1e3aa0249 http_req_process [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
11: 0x7fa1e3a9d496  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
12: 0x7fa1e3a9aeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
13: 0x7fa1e3aa1627  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
14: 0x7fa1e3a9aeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
15: 0x1897715  [node]
16: 0x1897a40  [node]
17: 0x189f41b  [node]
18: 0x188b757 uv_run [node]
19: 0xbbbb83 node::SpinEventLoopInternal(node::Environment*) [node]
20: 0xcf4d25  [node]
21: 0xcf56ed node::NodeMainInstance::Run() [node]
22: 0xc5f367 node::Start(int, char**) [node]
23: 0x7fa21a9ced90  [/usr/lib/x86_64-linux-gnu/libc.so.6]
24: 0x7fa21a9cee40 __libc_start_main [/usr/lib/x86_64-linux-gnu/libc.so.6]
25: 0xbb8d7e _start [node]
FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope
----- Native stack trace -----

 1: 0xca5430 node::Abort() [node]
 2: 0xb77f85 node::OOMErrorHandler(char const*, v8::OOMDetails const&) [node]
 3: 0xec9c86 v8::Utils::ReportApiFailure(char const*, char const*) [node]
 4: 0x1070002 v8::internal::HandleScope::Extend(v8::internal::Isolate*) [node]
 5: 0xecb568 v8::EscapableHandleScope::EscapableHandleScope(v8::Isolate*) [node]
 6: 0xca53d6 node::GetCurrentStackTrace(v8::Isolate*, int) [node]
 7: 0xc00c1b node::DumpJavaScriptBacktrace(_IO_FILE*) [node]
 8: 0xca543c node::Abort() [node]
 9: 0xca54b0 node::errors::SetPrepareStackTraceCallback(v8::FunctionCallbackInfo<v8::Value> const&) [node]
10: 0xc678b2 napi_call_threadsafe_function [node]
11: 0x7fa1e3a68f8f on_ziti_enroll [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
12: 0x7fa1e3a789e1  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
13: 0x7fa1e3a79e3a  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
14: 0x7fa1e3a7aed8  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
15: 0x7fa1e3a9fdb5  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
16: 0x1eda7c1 llhttp__internal_execute [node]
17: 0x7fa1e3aa0249 http_req_process [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
18: 0x7fa1e3a9d496  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
19: 0x7fa1e3a9aeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
20: 0x7fa1e3aa1627  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
21: 0x7fa1e3a9aeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
22: 0x1897715  [node]
23: 0x1897a40  [node]
24: 0x189f41b  [node]
25: 0x188b757 uv_run [node]
26: 0xbbbb83 node::SpinEventLoopInternal(node::Environment*) [node]
27: 0xcf4d25  [node]
28: 0xcf56ed node::NodeMainInstance::Run() [node]
29: 0xc5f367 node::Start(int, char**) [node]
30: 0x7fa21a9ced90  [/usr/lib/x86_64-linux-gnu/libc.so.6]
31: 0x7fa21a9cee40 __libc_start_main [/usr/lib/x86_64-linux-gnu/libc.so.6]
32: 0xbb8d7e _start [node]
Aborted
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ nvm use 18
N/A: version "v18" is not yet installed.

You need to run `nvm install 18` to install and use it.
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ nvm install 18
Downloading and installing node v18.20.3...
Downloading https://nodejs.org/dist/v18.20.3/node-v18.20.3-linux-x64.tar.xz...
################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v18.20.3 (npm v10.7.0)
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ node enrollZiti.js juiceshop-server-id.jwt
Specified Enrollment JWT is ('juiceshop-server-id.jwt')
Enroll failed with error: Error: Unable to napi_create_threadsafe_function
(226128)[        6.547]   ERROR ziti-sdk:ziti_ctrl.c:164 ctrl_resp_cb() ctrl[00aacfc0-a5c2-4d1b-96bf-1cb7e6679879.production.netfoundry.io] request failed: -4095(end of file)
(226128)[        6.547]   ERROR ziti-sdk:ziti_enroll.c:221 well_known_certs_cb() /home/runner/work/ziti-sdk-nodejs/ziti-sdk-nodejs/deps/ziti-sdk-c/library/ziti_enroll.c:139 - ZITI_JWT_VERIFICATION_FAILED => -7 (JWT verification failed)
node[226128]: ../src/node_api.cc:1387:napi_status napi_call_threadsafe_function(napi_threadsafe_function, void*, napi_threadsafe_function_call_mode): Assertion `(func) != nullptr' failed.
 1: 0xb9c310 node::Abort() [node]
 2: 0xb9c38e  [node]
 3: 0xb60972 napi_call_threadsafe_function [node]
 4: 0x7f5406265f8f on_ziti_enroll [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 5: 0x7f5406275d08  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 6: 0x7f5406276e3a  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 7: 0x7f5406277250  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 8: 0x7f5406299481  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 9: 0x7f540629a3bb  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
10: 0x7f5406297eb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
11: 0x7f540629e6f2  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
12: 0x7f5406297eb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
13: 0x16819a7  [node]
14: 0x16821e0  [node]
15: 0x1687f84  [node]
16: 0x167637e uv_run [node]
17: 0xad9a4a node::SpinEventLoop(node::Environment*) [node]
18: 0xbe1924 node::NodeMainInstance::Run() [node]
19: 0xb54de8 node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResult const*) [node]
20: 0xb58a4f node::Start(int, char**) [node]
21: 0x7f540d74dd90  [/usr/lib/x86_64-linux-gnu/libc.so.6]
22: 0x7f540d74de40 __libc_start_main [/usr/lib/x86_64-linux-gnu/libc.so.6]
23: 0xad789e _start [node]
Aborted
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ nvm use 16
Now using node v16.20.2 (npm v8.19.4)
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ node enrollZiti.js juiceshop-server-id.jwt
Specified Enrollment JWT is ('juiceshop-server-id.jwt')
Enroll failed with error: Error: Unable to napi_create_threadsafe_function
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ nvm install 21
Downloading and installing node v21.7.3...
Downloading https://nodejs.org/dist/v21.7.3/node-v21.7.3-linux-x64.tar.xz...
################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v21.7.3 (npm v10.5.0)
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ node enrollZiti.js juiceshop-server-id.jwt
Specified Enrollment JWT is ('juiceshop-server-id.jwt')
Enroll failed with error: Error: Unable to napi_create_threadsafe_function
(226963)[        2.411]   ERROR ziti-sdk:ziti_enroll.c:233 enroll_cb() failed to enroll with controller: https://00aacfc0-a5c2-4d1b-96bf-1cb7e6679879.production.netfoundry.io:443 INVALID_ENROLLMENT_TOKEN (The supplied token is not valid)

  #  node[226963]: napi_status napi_call_threadsafe_function(napi_threadsafe_function, void*, napi_threadsafe_function_call_mode) at ../src/node_api.cc:1392
  #  Assertion failed: (func) != nullptr

----- Native stack trace -----

 1: 0xe2fcd7 node::Assert(node::AssertionInfo const&) [node]
 2: 0xddc4c2 napi_call_threadsafe_function [node]
 3: 0x7f9540ecdf8f on_ziti_enroll [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 4: 0x7f9540edd882  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 5: 0x7f9540edee3a  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 6: 0x7f9540edfed8  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 7: 0x7f9540f04db5  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 8: 0x2123496 llhttp__internal_execute [node]
 9: 0x7f9540f05249 http_req_process [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
10: 0x7f9540f02496  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
11: 0x7f9540effeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
12: 0x7f9540f06627  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
13: 0x7f9540effeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
14: 0x1aaa525  [node]
15: 0x1aaa850  [node]
16: 0x1ab2224  [node]
17: 0x1a9e217 uv_run [node]
18: 0xd29bd6 node::SpinEventLoopInternal(node::Environment*) [node]
19: 0xe80121  [node]
20: 0xe80b8d node::NodeMainInstance::Run() [node]
21: 0xdd3bef node::Start(int, char**) [node]
22: 0x7f9543d20d90  [/usr/lib/x86_64-linux-gnu/libc.so.6]
23: 0x7f9543d20e40 __libc_start_main [/usr/lib/x86_64-linux-gnu/libc.so.6]
24: 0xd2717e _start [node]
FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope
----- Native stack trace -----

 1: 0xcd8aba node::OnFatalError(char const*, char const*) [node]
 2: 0x10aebb6 v8::Utils::ReportApiFailure(char const*, char const*) [node]
 3: 0x1256172 v8::internal::HandleScope::Extend(v8::internal::Isolate*) [node]
 4: 0x10afc68 v8::EscapableHandleScope::EscapableHandleScope(v8::Isolate*) [node]
 5: 0xe2fc26 node::GetCurrentStackTrace(v8::Isolate*, int) [node]
 6: 0xd712ab node::DumpJavaScriptBacktrace(_IO_FILE*) [node]
 7: 0xe2fce3 node::Assert(node::AssertionInfo const&) [node]
 8: 0xddc4c2 napi_call_threadsafe_function [node]
 9: 0x7f9540ecdf8f on_ziti_enroll [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
10: 0x7f9540edd882  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
11: 0x7f9540edee3a  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
12: 0x7f9540edfed8  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
13: 0x7f9540f04db5  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
14: 0x2123496 llhttp__internal_execute [node]
15: 0x7f9540f05249 http_req_process [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
16: 0x7f9540f02496  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
17: 0x7f9540effeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
18: 0x7f9540f06627  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
19: 0x7f9540effeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
20: 0x1aaa525  [node]
21: 0x1aaa850  [node]
22: 0x1ab2224  [node]
23: 0x1a9e217 uv_run [node]
24: 0xd29bd6 node::SpinEventLoopInternal(node::Environment*) [node]
25: 0xe80121  [node]
26: 0xe80b8d node::NodeMainInstance::Run() [node]
27: 0xdd3bef node::Start(int, char**) [node]
28: 0x7f9543d20d90  [/usr/lib/x86_64-linux-gnu/libc.so.6]
29: 0x7f9543d20e40 __libc_start_main [/usr/lib/x86_64-linux-gnu/libc.so.6]
30: 0xd2717e _start [node]
Aborted
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ nvm install 19
Downloading and installing node v19.9.0...
Downloading https://nodejs.org/dist/v19.9.0/node-v19.9.0-linux-x64.tar.xz...
################################################## 100.0%
Computing checksum with sha256sum
Checksums matched!
Now using node v19.9.0 (npm v9.6.3)
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ node enrollZiti.js juiceshop-server-id.jwt
Specified Enrollment JWT is ('juiceshop-server-id.jwt')
Enroll failed with error: Error: Unable to napi_create_threadsafe_function
(227484)[        2.246]   ERROR ziti-sdk:ziti_enroll.c:233 enroll_cb() failed to enroll with controller: https://00aacfc0-a5c2-4d1b-96bf-1cb7e6679879.production.netfoundry.io:443 INVALID_ENROLLMENT_TOKEN (The supplied token is not valid)
node[227484]: ../src/node_api.cc:1319:napi_status napi_call_threadsafe_function(napi_threadsafe_function, void*, napi_threadsafe_function_call_mode): Assertion `(func) != nullptr' failed.
 1: 0xbf9890 node::Abort() [node]
 2: 0xbf990e  [node]
 3: 0xbbf372 napi_call_threadsafe_function [node]
 4: 0x7fae8c9b8f8f on_ziti_enroll [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 5: 0x7fae8c9c8882  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 6: 0x7fae8c9c9e3a  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 7: 0x7fae8c9caed8  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 8: 0x7fae8c9efdb5  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 9: 0x1ddc22b llhttp__internal_execute [node]
10: 0x7fae8c9f0249 http_req_process [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
11: 0x7fae8c9ed496  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
12: 0x7fae8c9eaeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
13: 0x7fae8c9f1627  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
14: 0x7fae8c9eaeb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
15: 0x17a6017  [node]
16: 0x17a6840  [node]
17: 0x17ac5e4  [node]
18: 0x179aa0e uv_run [node]
19: 0xb2bbad node::SpinEventLoopInternal(node::Environment*) [node]
20: 0xc3ffc4 node::NodeMainInstance::Run() [node]
21: 0xbb3ceb node::LoadSnapshotDataAndRun(node::SnapshotData const**, node::InitializationResultImpl const*) [node]
22: 0xbb7a29 node::Start(int, char**) [node]
23: 0x7fae8f98cd90  [/usr/lib/x86_64-linux-gnu/libc.so.6]
24: 0x7fae8f98ce40 __libc_start_main [/usr/lib/x86_64-linux-gnu/libc.so.6]
25: 0xb2950e _start [node]
Aborted
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ touch enrollZitiOriginal.js
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ node enrollZitiOriginal.js juiceshop-server-id.jwt
(node:227950) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/mnt/d/web/juice-shop/enrollZitiOriginal.js:1
import fs from 'fs';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:73:18)
    at wrapSafe (node:internal/modules/cjs/loader:1195:20)
    at Module._compile (node:internal/modules/cjs/loader:1239:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1329:10)
    at Module.load (node:internal/modules/cjs/loader:1133:32)
    at Module._load (node:internal/modules/cjs/loader:972:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:83:12)
    at node:internal/main/run_main_module:23:47

Node.js v19.9.0
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ nvm use 21
Now using node v21.7.3 (npm v10.5.0)
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ node enrollZitiOriginal.js juiceshop-server-id.jwt
(node:228232) Warning: To load an ES module, set "type": "module" in the package.json or use the .mjs extension.
(Use `node --trace-warnings ...` to show where the warning was created)
/mnt/d/web/juice-shop/enrollZitiOriginal.js:1
import fs from 'fs';
^^^^^^

SyntaxError: Cannot use import statement outside a module
    at internalCompileFunction (node:internal/vm:128:18)
    at wrapSafe (node:internal/modules/cjs/loader:1279:20)
    at Module._compile (node:internal/modules/cjs/loader:1331:27)
    at Module._extensions..js (node:internal/modules/cjs/loader:1426:10)
    at Module.load (node:internal/modules/cjs/loader:1205:32)
    at Module._load (node:internal/modules/cjs/loader:1021:12)
    at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:142:12)
    at node:internal/main/run_main_module:28:49

Node.js v21.7.3
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ mv enrollZit
iOriginal.js enrollZitiOriginal.mjs
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ node enrollZitiOriginal.mjs juiceshop-server-id.jwt
Specified Enrollment JWT is ('juiceshop-server-id.jwt')
Enroll failed with error (Error: Unable to napi_create_threadsafe_function
    at file:///mnt/d/web/juice-shop/enrollZitiOriginal.mjs:6:23
    at new Promise (<anonymous>)
    at ziti_enroll (file:///mnt/d/web/juice-shop/enrollZitiOriginal.mjs:5:12)
    at file:///mnt/d/web/juice-shop/enrollZitiOriginal.mjs:20:18
    at ModuleJob.run (node:internal/modules/esm/module_job:222:25)
    at async ModuleLoader.import (node:internal/modules/esm/loader:323:24)
    at async loadESM (node:internal/process/esm_loader:28:7)
    at async handleMainPromise (node:internal/modules/run_main:120:12) {
  [stack]: [Getter/Setter],
  [message]: 'Unable to napi_create_threadsafe_function'
})
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ node enrollZiti.js juiceshop-server-id.jwt
Specified Enrollment JWT is ('juiceshop-server-id.jwt')
Enroll failed with error: Error: Unable to napi_create_threadsafe_function
(228657)[        2.495]   ERROR ziti-sdk:ziti_enroll.c:233 enroll_cb() failed to enroll with controller: https://00aacfc0-a5c2-4d1b-96bf-1cb7e6679879.production.netfoundry.io:443 INVALID_ENROLLMENT_TOKEN (The supplied token is not valid)

  #  node[228657]: napi_status napi_call_threadsafe_function(napi_threadsafe_function, void*, napi_threadsafe_function_call_mode) at ../src/node_api.cc:1392
  #  Assertion failed: (func) != nullptr

----- Native stack trace -----

 1: 0xe2fcd7 node::Assert(node::AssertionInfo const&) [node]
 2: 0xddc4c2 napi_call_threadsafe_function [node]
 3: 0x7ff7e9672f8f on_ziti_enroll [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 4: 0x7ff7e9682882  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 5: 0x7ff7e9683e3a  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 6: 0x7ff7e9684ed8  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 7: 0x7ff7e96a9db5  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
 8: 0x2123496 llhttp__internal_execute [node]
 9: 0x7ff7e96aa249 http_req_process [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
10: 0x7ff7e96a7496  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
11: 0x7ff7e96a4eb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
12: 0x7ff7e96ab627  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
13: 0x7ff7e96a4eb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
14: 0x1aaa525  [node]
15: 0x1aaa850  [node]
16: 0x1ab2224  [node]
17: 0x1a9e217 uv_run [node]
18: 0xd29bd6 node::SpinEventLoopInternal(node::Environment*) [node]
19: 0xe80121  [node]
20: 0xe80b8d node::NodeMainInstance::Run() [node]
21: 0xdd3bef node::Start(int, char**) [node]
22: 0x7ff7ec4c5d90  [/usr/lib/x86_64-linux-gnu/libc.so.6]
23: 0x7ff7ec4c5e40 __libc_start_main [/usr/lib/x86_64-linux-gnu/libc.so.6]
24: 0xd2717e _start [node]
FATAL ERROR: v8::HandleScope::CreateHandle() Cannot create a handle without a HandleScope
----- Native stack trace -----

 1: 0xcd8aba node::OnFatalError(char const*, char const*) [node]
 2: 0x10aebb6 v8::Utils::ReportApiFailure(char const*, char const*) [node]
 3: 0x1256172 v8::internal::HandleScope::Extend(v8::internal::Isolate*) [node]
 4: 0x10afc68 v8::EscapableHandleScope::EscapableHandleScope(v8::Isolate*) [node]
 5: 0xe2fc26 node::GetCurrentStackTrace(v8::Isolate*, int) [node]
 6: 0xd712ab node::DumpJavaScriptBacktrace(_IO_FILE*) [node]
 7: 0xe2fce3 node::Assert(node::AssertionInfo const&) [node]
 8: 0xddc4c2 napi_call_threadsafe_function [node]
 9: 0x7ff7e9672f8f on_ziti_enroll [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
10: 0x7ff7e9682882  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
11: 0x7ff7e9683e3a  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
12: 0x7ff7e9684ed8  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
13: 0x7ff7e96a9db5  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
14: 0x2123496 llhttp__internal_execute [node]
15: 0x7ff7e96aa249 http_req_process [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
16: 0x7ff7e96a7496  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
17: 0x7ff7e96a4eb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
18: 0x7ff7e96ab627  [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
19: 0x7ff7e96a4eb2 uv_link_propagate_read_cb [/mnt/d/web/juice-shop/node_modules/@openziti/ziti-sdk-nodejs/build/Release/ziti_sdk_nodejs.node]
20: 0x1aaa525  [node]
21: 0x1aaa850  [node]
22: 0x1ab2224  [node]
23: 0x1a9e217 uv_run [node]
24: 0xd29bd6 node::SpinEventLoopInternal(node::Environment*) [node]
25: 0xe80121  [node]
26: 0xe80b8d node::NodeMainInstance::Run() [node]
27: 0xdd3bef node::Start(int, char**) [node]
28: 0x7ff7ec4c5d90  [/usr/lib/x86_64-linux-gnu/libc.so.6]
29: 0x7ff7ec4c5e40 __libc_start_main [/usr/lib/x86_64-linux-gnu/libc.so.6]
30: 0xd2717e _start [node]
Aborted
nyck33@lenovo-gtx1650:/mnt/d/web/juice-shop$ 

I tried a few different node versions and both the original version of the code renamed with suffix .mjs and my version.

I am unable to reproduce the napi_create_threadsafe_function error locally. Is there any chance you can send me a JWT from your system (juiceshop-server-id.jwt or similar) so I can try it from here? If so, send it to me via a private DM.

tried to copy and paste into a DM @curt but getting network error