-
-
Notifications
You must be signed in to change notification settings - Fork 238
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
[WIP] add rw BigInt64 methods #247
Conversation
This pull request introduces 1 alert when merging d8b7133 into c7f5cd7 - view on LGTM.com new alerts:
|
If we want to continue supporting IE11 that means we can use: But should probably avoid the rest. If we want to use new syntax in the codebase, that would probably let us port code from Node.js more easily, which I like. But then we need to do one of these two options:
|
Why if we add |
@fanatid I meant that we need to do one of those two option. If we start using new syntax without babel then this package stops working in IE11 unless users start transpiling it. So that's a breaking change and we need to publish a new major version. Or, we use new syntax, add |
It might be harder to optimize a transpiled build for performance? |
Yeah, true. I'm happy to just optimize for newer browsers. The current version of |
Thanks for explanation Feross. So, decision is major version bump with new JS features transpiled for supported browsers? 😄 |
I think we should not transpile. Users can do that if they want. We can release a new major version that includes new language features. We shouldn't get carried away, though. Tests should still pass in the last two major versions of every major browser (Chrome, Firefox, Safari, Edge, Safari on iOS, Chrome on Android). |
When do you think we can expect resolution and merge of this PR? |
Sorry, do not have time right now to finish it. Maybe later. |
Heyyy do you have time now? This is a feature I could immediately use! <3 |
Can you describe situations (or show examples) when bn.js fails with Buffer? |
Absolutely, I should definitely be more clear. Sorry @fanatid and @feross .. I apologize. Using the current nodejs LTS + Typescript, typechecking fails because these functions are missing. This isn't just about BN.js but also things like elliptic. Using any Buffer as a parameter will give an error. Here's some examples of type conflicts. All of these I have workarounds for, but most of it is a pretty annoying efficiency hit (like convert from Buffer(node version) to Buffer(js version) or convert to hex before passing to BN etc etc. It would be great if it was a drop-in for the LTS version like it was in the previous LTS version. Here's a file I built just to handle some of these situations... maybe it'll help you see. //Singleton, use getInstance()
export class BinTools {
private static instance:BinTools;
private constructor() {}
static getInstance(): BinTools {
if (!BinTools.instance) {
BinTools.instance = new BinTools();
}
return BinTools.instance;
}
copyFrom(buff:Buffer, start:number, end:number){
return Buffer.from(Uint8Array.prototype.slice.call(buff.slice(start,end)))
}
bufferToB58(buff:Buffer) {
return bs58.encode(Array.prototype.slice.call(buff));
}
fromBufferToArrayBuffer(buff:Buffer) {
let ab = new ArrayBuffer(buff.length);
let view = new Uint8Array(ab);
for (let i = 0; i < buff.length; ++i) {
view[i] = buff[i];
}
return ab;
}
fromArrayBufferToBuffer(ab:ArrayBuffer) {
let buf = Buffer.alloc(ab.byteLength);
let view = new Uint8Array(ab);
for (let i = 0; i < buf.length; ++i) {
buf[i] = view[i];
}
return buf;
}
fromBufferToBN(buff:Buffer){
return new BN(buff.toString("hex"), 16, "be");
}
fromBNToBuffer(bn:BN){
return Buffer.from(bn.toArray("be"));
}
} |
Ah, so it's mostly about TypeScript? |
Yes sorry if that's not a roadmap item, but it likely would fix Typescript issues if this push was put in |
Any updates? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, please someone finish it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM: Could someone with write access approve these changes please?
@feross could you merge this one please? :) |
I'm okay with shipping a new version of @fanatid Do you think this is ready to merge? |
I just tried running the ES6 browser tests and they throw an exception because the way that Can someone figure out the cause of this? If you do, please either update this PR (@fanatid) or send a PR to this PR (anyone else). |
Please! I'm doing so many hokey things to handle Uint64 types lol, and the real barrier here is just getting TypeScript to agree that it's a Buffer class. Without the functions matching, TypeScript balks. Can we make it match the latest nodejs LTS version? Full disclosure: I can get it to work, but standard libraries which depend on Buffer have issues. So I've had to do things like write my own base58 encoder/decoder. |
Sorry, I do not have a time to check/update changes =(. Will be happy if somebody fork PR with required fixes / changes. |
@feross @fanatid Running Please check when you have time |
Released as 6.0.0 |
Original issue #244
This is quick copy code from node. I did not want make everything perfect because have a questions.
Is it ok use let/const/arrow functions/extends/template strings/etc? What if: