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

Issue with error concatUint8Array: Data must be in the form of a Uint8Array using OpenPGP #51

Open
CyberClarence opened this issue Jan 16, 2025 · 3 comments

Comments

@CyberClarence
Copy link

Hello,

First of all, thank you for your amazing work on OpenPGP! I'm currently developing an app that integrates OpenPGP, but I encountered an issue that I haven't been able to resolve.

Issue

I'm getting the following error when trying to parse an armored public key string:

concatUint8Array: Data must be in the form of a Uint8Array

Context

In a Next.js server action, I attempt to read a public key like this:

"use server";

import * as openpgp from "openpgp";
// and i also tried with
import * as openpgp from "openpgp/lightweight";

// ... some code
const userPublicKey = await openpgp.readKey({
  armoredKey: publicKeyString, // Confirmed to be a valid string
});
// ... some code

Despite ensuring that publicKeyString is a valid armored key string, the error persists.

What I've Tried

I have tested this across multiple configurations, including:

  • Next.js versions: 14 and 15 (with TypeScript)
  • Runtimes: Bun (1.1.26), Node.js (v22.12.0)
  • OpenPGP versions: 5 and 6
  • Bundlers: Webpack and Turbopack
  • Runtimes: Edge and the vanilla Next.js runtime
    None of these changes resolved the issue.

Investigation

From stack tracing, the error originates from:

node_modules/@openpgp/web-stream-tools/lib/util.js line 50
function isUint8Array(input) {
  return Uint8Array.prototype.isPrototypeOf(input);
}

It seems that something in my environment is affecting this function’s behavior, but I’m unsure what could be causing it.

Request

Could you provide any insights into what might be causing this issue? Is there a potential workaround or fix?

Any help would be greatly appreciated !

Best regards
Clarence

@twiss
Copy link
Member

twiss commented Jan 17, 2025

This sounds a bit similar to #23; you could try whether one of the solutions listed there fixes the issue?
If there are multiple environments with an issue like that, we might also want to consider merging that PR or something like it, after all..

@CyberClarence
Copy link
Author

Hello,

I finally managed to resolved this issue yesterday
To deploy a quick fix for my project I forked this repo and republished my diff under @cyberclarence/web-stream-tools
and published @cyberclarence/openpgp to use it as a depency

isUint8Array code is incorrect and trigger a false negative depending on the environment

I will do a pull request when i have time next week

Thank you for your time
Clarence

@larabr
Copy link
Collaborator

larabr commented Jan 20, 2025

I have bumped into the same error when testing with Jest & JSDom, and the solution there was to overwrite the globals in the JSDOM environment. I assume Next.js could be affected in a similar way.

I think there could be a risk in accepting/mixing different TypedArray implementations; use-cases seem quite varied, looking at the Firefox case in the issue Daniel linked, versus the case for JSDom, Next.js & co. that try and simulate a different env.
And I am not sure about accommodating for the latter case tbh. The reason is that I'd expect the problem to be addressable in their configs, and I am worried that changing the Uint8Array check could cause side-effects, and our CI testing won't really help assess the consequences in the different contexts, since we only target browsers and vanilla Node.js .

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

3 participants