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
I would like to propose using custom Classes for each Cairo-type representation in JS.
We discussed this also for Abi One as the extension for the js type system.
For now, leave a naive approach for existing types (without classes with opinionated conversion)
for prototype:
.compile() // compile from internal JS to Api format (HexString[]) // will be used in requestParser
.decompile(data: HexString[]) // convert Api format to JS Data representation depending on data type // will be used in responseParser
.constructor(....) // per class implementation depending on type
.value() // default representation of the data
Goal
Preserve distinction for data after parsing. One can know that it was X type (ex. ByteArray) in Cairo and not Y (ex. Felt*) or some other type
Preserve knowledge on how to compile and decompile it.
Preserve un-opinionated value as data.
When doing static compile without abi we can distinguish Cairo-defined types instead of complex detection with ever-groving cairo custom types.
When doing with Abi compile we can easily validate provided data to Abi and reorder parameters.
Can we achieve a default return value the same as the Number or String class does?
bytes31
represent 31 bytes data. In JS this can be stored as Uint8Array(31)
Abi Cairo format: Cairo primitive: core::bytes_31::bytes31
Can be created from HexString, number, BigInt, TextString
Can have internal validation
classBytes31{publicdata: Uint8Array(31)constructor(agr?: HexString|number|BigInt|TextString)publiccompile(): HexString[]publicdecompile(args: HexString[])publictoSring(): stringpublicvalue()// opinionated what should be the default value? string?}
ByteArray
represent Array of bytes31. In JS this can be stored as Bytes31[]
Can be created from which types of data? TextString, Bytes31[], ByteArrayStruct, HexString[]
classByteArray{publicdata: Bytes31[]constructor(agr?: HexString|number|BigInt|TextString)publiccompile(): HexString[]publicdecompile(args: HexString[])publictoSring(): stringpublicvalue()// opinionated what should be the default value? string?}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
I would like to propose using custom Classes for each Cairo-type representation in JS.
We discussed this also for Abi One as the extension for the js type system.
For now, leave a naive approach for existing types (without classes with opinionated conversion)
for prototype:
.compile() // compile from internal JS to Api format (HexString[]) // will be used in requestParser
.decompile(data: HexString[]) // convert Api format to JS Data representation depending on data type // will be used in responseParser
.constructor(....) // per class implementation depending on type
.value() // default representation of the data
Goal
bytes31
[length, data0, data1, data2, ...dataX, pending_word, pending_word_len]
core::bytes_31::bytes31
ByteArray
[length, data0, data1, data2, ...dataX, pending_word, pending_word_len]
Beta Was this translation helpful? Give feedback.
All reactions