@mysten/bcs
Advanced tools
Comparing version 0.0.0-experimental-20241126214925 to 0.0.0-experimental-20241209193009
# Change Log | ||
## 0.0.0-experimental-20241126214925 | ||
## 0.0.0-experimental-20241209193009 | ||
### Minor Changes | ||
- ad24b95: Verify hex string is valid hex in `fromHex` | ||
## 1.1.1 | ||
### Patch Changes | ||
@@ -6,0 +12,0 @@ |
@@ -29,4 +29,7 @@ "use strict"; | ||
const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr; | ||
const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}}`; | ||
const intArr = padded.match(/.{2}/g)?.map((byte) => parseInt(byte, 16)) ?? []; | ||
const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`; | ||
const intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? []; | ||
if (intArr.length !== padded.length / 2) { | ||
throw new Error(`Invalid hex string ${hexStr}`); | ||
} | ||
return Uint8Array.from(intArr); | ||
@@ -33,0 +36,0 @@ } |
function fromHex(hexStr) { | ||
const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr; | ||
const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}}`; | ||
const intArr = padded.match(/.{2}/g)?.map((byte) => parseInt(byte, 16)) ?? []; | ||
const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`; | ||
const intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? []; | ||
if (intArr.length !== padded.length / 2) { | ||
throw new Error(`Invalid hex string ${hexStr}`); | ||
} | ||
return Uint8Array.from(intArr); | ||
@@ -6,0 +9,0 @@ } |
{ | ||
"name": "@mysten/bcs", | ||
"version": "0.0.0-experimental-20241126214925", | ||
"version": "0.0.0-experimental-20241209193009", | ||
"description": "BCS - Canonical Binary Serialization implementation for JavaScript", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -6,5 +6,9 @@ // Copyright (c) Mysten Labs, Inc. | ||
const normalized = hexStr.startsWith('0x') ? hexStr.slice(2) : hexStr; | ||
const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}}`; | ||
const intArr = padded.match(/.{2}/g)?.map((byte) => parseInt(byte, 16)) ?? []; | ||
const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}`; | ||
const intArr = padded.match(/[0-9a-fA-F]{2}/g)?.map((byte) => parseInt(byte, 16)) ?? []; | ||
if (intArr.length !== padded.length / 2) { | ||
throw new Error(`Invalid hex string ${hexStr}`); | ||
} | ||
return Uint8Array.from(intArr); | ||
@@ -11,0 +15,0 @@ } |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
356303
4960