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

Tracking issue: Move from Buffer -> Uint8Array #69

Open
jochem-brouwer opened this issue Nov 11, 2020 · 1 comment
Open

Tracking issue: Move from Buffer -> Uint8Array #69

jochem-brouwer opened this issue Nov 11, 2020 · 1 comment

Comments

@jochem-brouwer
Copy link
Member

As mentioned by @ricmoo, the nodejs injected Buffer is insecure and also makes adds a browser dependency of a Buffer implementation. It seems that for (most of?) our use cases, we should use Uint8Array and not Buffer, ideally we remove this "dependency" from our packages.

Tracking issue as this is a long-term issue.

@rumkin
Copy link

rumkin commented Nov 11, 2020

Uint8Array could be used with custom types for Address with ReadOnly util to prevent buffer from modifications in TS:

type ReadOnly<T> = {
    readonly [i: number]: T
}

type Address = ReadOnly<Uint8Array>

Or there could be realized some primitive ancestors of Uint8Array:

class Address extends Uint8Array {
    readonly [n: number]: number;

    static fromString(source: string): Address {
      // ...
    }
}

The first option is type-only solution, what means it costs nothing at runtime. The second allows to implement some utility methods and do instanceof check, but it has some overhead in runtime.

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

No branches or pull requests

2 participants