referenceerror: self is not defined when using in Nodejs
Can we use tink in nodejs?
Help us help you
We are using tink downloaded from npm: https://www.npmjs.com/package/tink-crypto. We are using it from Nodejs
Describe the bug
The whole lib can not initialize. We tried both static and dynamic import and both failed with above error message.
Here is a code sample:
const tinkLoader = () => import('tink-crypto');
tinkLoader().then((tink) => {
tink.hybrid.register();
const keyset = stringToUint8Array(atob(resource_response.data.encoded_key));
tink.binary
.deserializeNoSecretKeyset(keyset)
.getPrimitive(tink.hybrid.HybridEncrypt)
.then((hybridEncrypt) => {
//do some thing
});
});
To Reproduce
just copy above code to any nodejs env
Expected behavior
can use it in node.
Error messages, stack traces, etc.
ReferenceError: self is not defined
at internal/proto.ts:85:23
at node_modules/tink-crypto/bundles/tink-crypto.umd.js:2:68
at Object.
- Language: JS
- Version: 0.1.0
- Environment: node 12
Thanks for your help!
Tink currently doesn't work in Node.js. We're hoping to address this limitation in the future.
We will not be able to address this.