You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Some of our code is a bit brittle because of the loosely thrown around primitive strings. Some libraries use checksum addresses and others use lowercase. We should make this uniform across the project so to avoid these ugly little fixes.
This change is a bit ugly and is a result of having to "normalize" hex strings. We should probably find a global/universal solution to this problem instead of having to make conversions all the time.
An approach proposed by @tukantje on slack is as follows:
typeNominal<Textendsstring,K>={_type: Tvalue: K}typeAddress=Nominal<"Address",string>constaddressRegex=newRegExp("^0x[a-fA-F0-9]{40}$/")functionisAddressString(value: string){returnaddressRegex.test(value)}functionisAddress(nominal: Nominal<string,any>): nominal is Address{returnisAddressString(nominal.value)}functionmakeAddress(text: string): Address{if(!isAddressString(text)){// Could also return null, depends on your usecase.thrownewError(`Invalid text supplied: can't make an address out of ${text}`)}returnObject.freeze({value: text,_type: "Address"})}constaddress=makeAddress("0x23233222");// Expected to fail, not a valid address.
Some of our code is a bit brittle because of the loosely thrown around primitive strings. Some libraries use checksum addresses and others use lowercase. We should make this uniform across the project so to avoid these ugly little fixes.
This change is a bit ugly and is a result of having to "normalize" hex strings. We should probably find a global/universal solution to this problem instead of having to make conversions all the time.
Originally posted by @bh2smith in #231 (comment)
The text was updated successfully, but these errors were encountered: