Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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