Closed jochem-brouwer closed 2 days ago
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.
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.