diff --git a/target_chains/starknet/sdk/js/package.json b/target_chains/starknet/sdk/js/package.json index f93a4c7fce..85c7f13725 100644 --- a/target_chains/starknet/sdk/js/package.json +++ b/target_chains/starknet/sdk/js/package.json @@ -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": { diff --git a/target_chains/starknet/sdk/js/src/index.ts b/target_chains/starknet/sdk/js/src/index.ts index eef442aa71..23401b3304 100644 --- a/target_chains/starknet/sdk/js/src/index.ts +++ b/target_chains/starknet/sdk/js/src/index.ts @@ -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; @@ -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) {