-
Notifications
You must be signed in to change notification settings - Fork 805
Open
Labels
Type: bugSomething isn't workingSomething isn't working
Description
Describe the bug
A few things about ByteArray
- When compiling to calldata, it does not support non-ASCII string
- When receiving events that contain ByteArray, the parsed string is corrupted
To Reproduce
- calldata
const uint8Array: Uint8Array
const str = Array.from(uint8Array).map(c => String.fromCharCode(c)).join('');
contract.invoke('function_name', str) // error - non-ASCII string
// or
const br = bytearray.byteArrayFromString(str) // error - non-ASCII string
- event
#[derive(Drop, starknet::Event)]
struct MessageEvent {
message: ByteArray,
}
// this is corrupted if message is non-ascii
// some bytes were trimmed and some random bytes were added in the message
const event = contract.parseEvents(receipt)[0]['MessageEvent'].message;
Expected behavior
ByteArray should support actual byte array, not just ascii string.
- for encoding, I suggest support functions like
byteArrayFromUint8Array
,byteArrayFromBuffer
, and probably also make it clear that byteArrayFromString is only for ascii string if that was the intention. - for events decoding/parsing, I suggest support parsing ByteArray into Uint8Array with parsing options like {byteArrayOutputType: 'uint8array'}
- We did not use ByteArray as return type but it may be worth checking too
Desktop (please complete the following information):
- Browser & version
- Node version 23.10.0
- Starknet.js version 7.6.4
- Network devnet
Additional context
tabaktoni
Metadata
Metadata
Assignees
Labels
Type: bugSomething isn't workingSomething isn't working