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

Method scope 'this' undefined when destructuring methods from SubtleCrypto instance #84

Open
TJKoury opened this issue May 20, 2021 · 0 comments
Assignees

Comments

@TJKoury
Copy link
Contributor

TJKoury commented May 20, 2021

In Node >=15.x, the WebCrypto API allows destructuring of SubtleCrypto methods:

import { webcrypto } from 'crypto';
...
let { importKey, exportKey } = webcrypto.subtle;
const keys = await importKey(...);

However, doing this using the liner throws errors (methods and properties called on 'undefined').

A quick workaround is to bind this when destructuring:

import { crypto } from "webcrypto-liner";
...
let { importKey } = crypto.subtle;
importKey = importKey.bind(crypto.subtle);

Bad code smell though, and side-effects unknown.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants