Skip to content

Commit 40a63bf

Browse files
authored
fix(target_chains/starknet): fix ByteBuffer.fromHex and add more conversions (#1717)
1 parent 29c5e0f commit 40a63bf

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

target_chains/starknet/sdk/js/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@pythnetwork/pyth-starknet-js",
3-
"version": "0.1.0",
3+
"version": "0.2.0",
44
"description": "Pyth Network Starknet Utilities",
55
"homepage": "https://pyth.network",
66
"author": {

target_chains/starknet/sdk/js/src/index.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ export class ByteBuffer {
2121
data: string[] = [];
2222

2323
/** Create a `ByteBuffer` from an array of `bytes31`.
24-
* Use `ByteBuffer::fromHex` to create `ByteBuffer` from HEX representation of binary data.
24+
* - Use `ByteBuffer::fromBuffer` to create `ByteBuffer` from a `Buffer`.
25+
* - Use `ByteBuffer::fromBase64` to create `ByteBuffer` from Base64 representation of binary data.
26+
* - Use `ByteBuffer::fromHex` to create `ByteBuffer` from HEX representation of binary data.
2527
*/
2628
constructor(num_last_bytes: number, data: string[]) {
2729
this.num_last_bytes = num_last_bytes;
@@ -30,8 +32,16 @@ export class ByteBuffer {
3032

3133
/** Create a `ByteBuffer` from HEX representation of binary data. */
3234
public static fromHex(hexData: string): ByteBuffer {
33-
const buffer = Buffer.from(hexData, "base64");
35+
return ByteBuffer.fromBuffer(Buffer.from(hexData, "hex"));
36+
}
37+
38+
/** Create a `ByteBuffer` from Base64 representation of binary data. */
39+
public static fromBase64(hexData: string): ByteBuffer {
40+
return ByteBuffer.fromBuffer(Buffer.from(hexData, "base64"));
41+
}
3442

43+
/** Create a `ByteBuffer` from a `Buffer`. */
44+
public static fromBuffer(buffer: Buffer): ByteBuffer {
3545
let pos = 0;
3646
const data = [];
3747
while (pos < buffer.length) {

0 commit comments

Comments
 (0)