Skip to content

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

@TJKoury

Description

@TJKoury

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.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions