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

Do you need TextEncoder? #49

Closed
madeken opened this issue May 23, 2023 · 2 comments
Closed

Do you need TextEncoder? #49

madeken opened this issue May 23, 2023 · 2 comments

Comments

@madeken
Copy link

madeken commented May 23, 2023

First of all, great work with your library you've done an amazing job.

I'm using it from a pure v8 runtime, and the only issue I have is the use of TextEncoder. I have patched your library to:

Replace the line:
https://github.com/paulmillr/noble-curves/blob/79dd7d342636f421d36acbf3dbe2014ad7ba7ece/src/abstract/utils.ts#LL118C8-L118C8

With:

let uint8Array = new Uint8Array(str.length);
for (var i = 0; i < str.length; i++) {
    let charCode = str.charCodeAt(i);
    if (charCode > 127) {
        throw new Error('Not ascii. Text must be in ascii encoding');
    }
    uint8Array[i] = charCode;
}
return uint8Array;

And I haven't had any issues. I would assume my use-case is not really supported, but I guess if you wanted to you could create a method asciiToUint8Array which you use internally which AFAICT is all you need. That said, TextEncoder seems like a pretty reasonable dependency, so makes sense if you want to leave it how it is.

@paulmillr
Copy link
Owner

I'm using it from a pure v8 runtime

What's that? Can you describe why?

Text Encoder is used in sister repositories, such as scure-base and noble-hashes and i'm positive charCodeAt is not 1:1 replacement.

@madeken
Copy link
Author

madeken commented May 23, 2023

What's that? Can you describe why?

It's just because I'm using it from within an app that embeds v8 for the purpose of making plugins. Then I'm simply using your library to validate some digital signatures to make sure they're valid

Text Encoder is used in sister repositories, such as scure-base and noble-hashes and i'm positive charCodeAt is not 1:1 replacement.

Yeah, I think it only works for ascii. I think that's all you need for nobel-curves (cause it's just some of the hardcoded DST strings and what not, I think). But since you need it anyway for the other libraries, it is probably not reasonable for you to try avoid using TextEncoder just for my esoteric usecase. Actually the fact you always use utf8ToBytes instead of using TextEncoder throughout the code base makes it super easy to maintain a patch, so I shouldn't complain 👍

@madeken madeken closed this as completed May 23, 2023
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