Skip to content

Commit

Permalink
fix(target_chains/starknet): fix ByteBuffer.fromHex and add more conv…
Browse files Browse the repository at this point in the history
…ersions (#1717)
  • Loading branch information
Riateche authored Jun 20, 2024
1 parent 29c5e0f commit 40a63bf
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
2 changes: 1 addition & 1 deletion target_chains/starknet/sdk/js/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@pythnetwork/pyth-starknet-js",
"version": "0.1.0",
"version": "0.2.0",
"description": "Pyth Network Starknet Utilities",
"homepage": "https://pyth.network",
"author": {
Expand Down
14 changes: 12 additions & 2 deletions target_chains/starknet/sdk/js/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ export class ByteBuffer {
data: string[] = [];

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

/** Create a `ByteBuffer` from HEX representation of binary data. */
public static fromHex(hexData: string): ByteBuffer {
const buffer = Buffer.from(hexData, "base64");
return ByteBuffer.fromBuffer(Buffer.from(hexData, "hex"));
}

/** Create a `ByteBuffer` from Base64 representation of binary data. */
public static fromBase64(hexData: string): ByteBuffer {
return ByteBuffer.fromBuffer(Buffer.from(hexData, "base64"));
}

/** Create a `ByteBuffer` from a `Buffer`. */
public static fromBuffer(buffer: Buffer): ByteBuffer {
let pos = 0;
const data = [];
while (pos < buffer.length) {
Expand Down

0 comments on commit 40a63bf

Please sign in to comment.