@mysten/bcs
Advanced tools
Comparing version 0.0.0-experimental-20240806174754 to 0.0.0-experimental-20240926213518
# Change Log | ||
## 0.0.0-experimental-20240806174754 | ||
## 0.0.0-experimental-20240926213518 | ||
### Minor Changes | ||
- 489f421: Updated hex, base64, and base58 utility names for better consistency | ||
All existing methods will continue to work, but the following methods have been deprecated and | ||
replaced with methods with improved names: | ||
- `toHEX` -> `toHEX` | ||
- `fromHEX` -> `fromHex` | ||
- `toB64` -> `toBase64` | ||
- `fromB64` -> `fromBase64` | ||
- `toB58` -> `toBase58` | ||
- `fromB58` -> `fromBase58` | ||
## 1.0.4 | ||
### Patch Changes | ||
@@ -6,0 +22,0 @@ |
@@ -0,2 +1,6 @@ | ||
export declare const toBase58: (buffer: Uint8Array) => string; | ||
export declare const fromBase58: (str: string) => Uint8Array; | ||
/** @deprecated use toBase58 instead */ | ||
export declare const toB58: (buffer: Uint8Array) => string; | ||
/** @deprecated use fromBase58 instead */ | ||
export declare const fromB58: (str: string) => Uint8Array; |
@@ -32,8 +32,12 @@ "use strict"; | ||
fromB58: () => fromB58, | ||
toB58: () => toB58 | ||
fromBase58: () => fromBase58, | ||
toB58: () => toB58, | ||
toBase58: () => toBase58 | ||
}); | ||
module.exports = __toCommonJS(b58_exports); | ||
var import_bs58 = __toESM(require("bs58")); | ||
const toB58 = (buffer) => import_bs58.default.encode(buffer); | ||
const fromB58 = (str) => import_bs58.default.decode(str); | ||
const toBase58 = (buffer) => import_bs58.default.encode(buffer); | ||
const fromBase58 = (str) => import_bs58.default.decode(str); | ||
const toB58 = toBase58; | ||
const fromB58 = fromBase58; | ||
//# sourceMappingURL=b58.js.map |
@@ -1,2 +0,6 @@ | ||
export declare function fromB64(base64String: string): Uint8Array; | ||
export declare function toB64(bytes: Uint8Array): string; | ||
export declare function fromBase64(base64String: string): Uint8Array; | ||
export declare function toBase64(bytes: Uint8Array): string; | ||
/** @deprecated use toBase64 instead */ | ||
export declare const toB64: typeof toBase64; | ||
/** @deprecated use fromBase64 instead */ | ||
export declare const fromB64: typeof fromBase64; |
@@ -22,10 +22,12 @@ "use strict"; | ||
fromB64: () => fromB64, | ||
toB64: () => toB64 | ||
fromBase64: () => fromBase64, | ||
toB64: () => toB64, | ||
toBase64: () => toBase64 | ||
}); | ||
module.exports = __toCommonJS(b64_exports); | ||
function fromB64(base64String) { | ||
function fromBase64(base64String) { | ||
return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0)); | ||
} | ||
const CHUNK_SIZE = 8192; | ||
function toB64(bytes) { | ||
function toBase64(bytes) { | ||
if (bytes.length < CHUNK_SIZE) { | ||
@@ -41,2 +43,4 @@ return btoa(String.fromCharCode(...bytes)); | ||
} | ||
const toB64 = toBase64; | ||
const fromB64 = fromBase64; | ||
//# sourceMappingURL=b64.js.map |
@@ -78,9 +78,9 @@ "use strict"; | ||
fromHex(hex) { | ||
return this.parse((0, import_hex.fromHEX)(hex)); | ||
return this.parse((0, import_hex.fromHex)(hex)); | ||
} | ||
fromBase58(b64) { | ||
return this.parse((0, import_b58.fromB58)(b64)); | ||
return this.parse((0, import_b58.fromBase58)(b64)); | ||
} | ||
fromBase64(b64) { | ||
return this.parse((0, import_b64.fromB64)(b64)); | ||
return this.parse((0, import_b64.fromBase64)(b64)); | ||
} | ||
@@ -129,9 +129,9 @@ transform({ | ||
toHex() { | ||
return (0, import_hex.toHEX)(__privateGet(this, _bytes)); | ||
return (0, import_hex.toHex)(__privateGet(this, _bytes)); | ||
} | ||
toBase64() { | ||
return (0, import_b64.toB64)(__privateGet(this, _bytes)); | ||
return (0, import_b64.toBase64)(__privateGet(this, _bytes)); | ||
} | ||
toBase58() { | ||
return (0, import_b58.toB58)(__privateGet(this, _bytes)); | ||
return (0, import_b58.toBase58)(__privateGet(this, _bytes)); | ||
} | ||
@@ -138,0 +138,0 @@ parse() { |
@@ -1,2 +0,6 @@ | ||
export declare function fromHEX(hexStr: string): Uint8Array; | ||
export declare function toHEX(bytes: Uint8Array): string; | ||
export declare function fromHex(hexStr: string): Uint8Array; | ||
export declare function toHex(bytes: Uint8Array): string; | ||
/** @deprecated use toHex instead */ | ||
export declare const toHEX: typeof toHex; | ||
/** @deprecated use fromHex instead */ | ||
export declare const fromHEX: typeof fromHex; |
@@ -22,6 +22,8 @@ "use strict"; | ||
fromHEX: () => fromHEX, | ||
toHEX: () => toHEX | ||
fromHex: () => fromHex, | ||
toHEX: () => toHEX, | ||
toHex: () => toHex | ||
}); | ||
module.exports = __toCommonJS(hex_exports); | ||
function fromHEX(hexStr) { | ||
function fromHex(hexStr) { | ||
const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr; | ||
@@ -32,5 +34,7 @@ const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}}`; | ||
} | ||
function toHEX(bytes) { | ||
function toHex(bytes) { | ||
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), ""); | ||
} | ||
const toHEX = toHex; | ||
const fromHEX = fromHex; | ||
//# sourceMappingURL=hex.js.map |
@@ -1,7 +0,7 @@ | ||
import { fromB58, toB58 } from './b58.js'; | ||
import { fromB64, toB64 } from './b64.js'; | ||
import { fromB58, fromBase58, toB58, toBase58 } from './b58.js'; | ||
import { fromB64, fromBase64, toB64, toBase64 } from './b64.js'; | ||
import type { BcsTypeOptions } from './bcs-type.js'; | ||
import { BcsType, isSerializedBcs, SerializedBcs } from './bcs-type.js'; | ||
import { bcs } from './bcs.js'; | ||
import { fromHEX, toHEX } from './hex.js'; | ||
import { fromHEX, fromHex, toHEX, toHex } from './hex.js'; | ||
import { BcsReader } from './reader.js'; | ||
@@ -12,2 +12,2 @@ import type { EnumInputShape, EnumOutputShape, EnumOutputShapeWithKeys, InferBcsInput, InferBcsType } from './types.js'; | ||
import { BcsWriter } from './writer.js'; | ||
export { bcs, BcsType, type BcsTypeOptions, SerializedBcs, isSerializedBcs, toB58, fromB58, toB64, fromB64, fromHEX, toHEX, encodeStr, decodeStr, splitGenericParameters, BcsReader, BcsWriter, type BcsWriterOptions, type InferBcsInput, type InferBcsType, type EnumOutputShape, type EnumInputShape, type EnumOutputShapeWithKeys, }; | ||
export { bcs, BcsType, type BcsTypeOptions, SerializedBcs, isSerializedBcs, toB58, fromB58, toBase58, fromBase58, toB64, fromB64, toBase64, fromBase64, fromHEX, toHEX, toHex, fromHex, encodeStr, decodeStr, splitGenericParameters, BcsReader, BcsWriter, type BcsWriterOptions, type InferBcsInput, type InferBcsType, type EnumOutputShape, type EnumInputShape, type EnumOutputShapeWithKeys, }; |
@@ -30,3 +30,6 @@ "use strict"; | ||
fromB64: () => import_b64.fromB64, | ||
fromBase58: () => import_b58.fromBase58, | ||
fromBase64: () => import_b64.fromBase64, | ||
fromHEX: () => import_hex.fromHEX, | ||
fromHex: () => import_hex.fromHex, | ||
isSerializedBcs: () => import_bcs_type.isSerializedBcs, | ||
@@ -36,3 +39,6 @@ splitGenericParameters: () => import_utils.splitGenericParameters, | ||
toB64: () => import_b64.toB64, | ||
toHEX: () => import_hex.toHEX | ||
toBase58: () => import_b58.toBase58, | ||
toBase64: () => import_b64.toBase64, | ||
toHEX: () => import_hex.toHEX, | ||
toHex: () => import_hex.toHex | ||
}); | ||
@@ -39,0 +45,0 @@ module.exports = __toCommonJS(src_exports); |
@@ -32,7 +32,7 @@ "use strict"; | ||
case "base58": | ||
return (0, import_b58.toB58)(data); | ||
return (0, import_b58.toBase58)(data); | ||
case "base64": | ||
return (0, import_b64.toB64)(data); | ||
return (0, import_b64.toBase64)(data); | ||
case "hex": | ||
return (0, import_hex.toHEX)(data); | ||
return (0, import_hex.toHex)(data); | ||
default: | ||
@@ -45,7 +45,7 @@ throw new Error("Unsupported encoding, supported values are: base64, hex"); | ||
case "base58": | ||
return (0, import_b58.fromB58)(data); | ||
return (0, import_b58.fromBase58)(data); | ||
case "base64": | ||
return (0, import_b64.fromB64)(data); | ||
return (0, import_b64.fromBase64)(data); | ||
case "hex": | ||
return (0, import_hex.fromHEX)(data); | ||
return (0, import_hex.fromHex)(data); | ||
default: | ||
@@ -52,0 +52,0 @@ throw new Error("Unsupported encoding, supported values are: base64, hex"); |
@@ -0,2 +1,6 @@ | ||
export declare const toBase58: (buffer: Uint8Array) => string; | ||
export declare const fromBase58: (str: string) => Uint8Array; | ||
/** @deprecated use toBase58 instead */ | ||
export declare const toB58: (buffer: Uint8Array) => string; | ||
/** @deprecated use fromBase58 instead */ | ||
export declare const fromB58: (str: string) => Uint8Array; |
import bs58 from "bs58"; | ||
const toB58 = (buffer) => bs58.encode(buffer); | ||
const fromB58 = (str) => bs58.decode(str); | ||
const toBase58 = (buffer) => bs58.encode(buffer); | ||
const fromBase58 = (str) => bs58.decode(str); | ||
const toB58 = toBase58; | ||
const fromB58 = fromBase58; | ||
export { | ||
fromB58, | ||
toB58 | ||
fromBase58, | ||
toB58, | ||
toBase58 | ||
}; | ||
//# sourceMappingURL=b58.js.map |
@@ -1,2 +0,6 @@ | ||
export declare function fromB64(base64String: string): Uint8Array; | ||
export declare function toB64(bytes: Uint8Array): string; | ||
export declare function fromBase64(base64String: string): Uint8Array; | ||
export declare function toBase64(bytes: Uint8Array): string; | ||
/** @deprecated use toBase64 instead */ | ||
export declare const toB64: typeof toBase64; | ||
/** @deprecated use fromBase64 instead */ | ||
export declare const fromB64: typeof fromBase64; |
@@ -1,6 +0,6 @@ | ||
function fromB64(base64String) { | ||
function fromBase64(base64String) { | ||
return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0)); | ||
} | ||
const CHUNK_SIZE = 8192; | ||
function toB64(bytes) { | ||
function toBase64(bytes) { | ||
if (bytes.length < CHUNK_SIZE) { | ||
@@ -16,6 +16,10 @@ return btoa(String.fromCharCode(...bytes)); | ||
} | ||
const toB64 = toBase64; | ||
const fromB64 = fromBase64; | ||
export { | ||
fromB64, | ||
toB64 | ||
fromBase64, | ||
toB64, | ||
toBase64 | ||
}; | ||
//# sourceMappingURL=b64.js.map |
@@ -9,5 +9,5 @@ var __typeError = (msg) => { | ||
var _write, _serialize, _schema, _bytes; | ||
import { fromB58, toB58 } from "./b58.js"; | ||
import { fromB64, toB64 } from "./b64.js"; | ||
import { fromHEX, toHEX } from "./hex.js"; | ||
import { fromBase58, toBase58 } from "./b58.js"; | ||
import { fromBase64, toBase64 } from "./b64.js"; | ||
import { fromHex, toHex } from "./hex.js"; | ||
import { BcsReader } from "./reader.js"; | ||
@@ -48,9 +48,9 @@ import { ulebEncode } from "./uleb.js"; | ||
fromHex(hex) { | ||
return this.parse(fromHEX(hex)); | ||
return this.parse(fromHex(hex)); | ||
} | ||
fromBase58(b64) { | ||
return this.parse(fromB58(b64)); | ||
return this.parse(fromBase58(b64)); | ||
} | ||
fromBase64(b64) { | ||
return this.parse(fromB64(b64)); | ||
return this.parse(fromBase64(b64)); | ||
} | ||
@@ -99,9 +99,9 @@ transform({ | ||
toHex() { | ||
return toHEX(__privateGet(this, _bytes)); | ||
return toHex(__privateGet(this, _bytes)); | ||
} | ||
toBase64() { | ||
return toB64(__privateGet(this, _bytes)); | ||
return toBase64(__privateGet(this, _bytes)); | ||
} | ||
toBase58() { | ||
return toB58(__privateGet(this, _bytes)); | ||
return toBase58(__privateGet(this, _bytes)); | ||
} | ||
@@ -108,0 +108,0 @@ parse() { |
@@ -1,2 +0,6 @@ | ||
export declare function fromHEX(hexStr: string): Uint8Array; | ||
export declare function toHEX(bytes: Uint8Array): string; | ||
export declare function fromHex(hexStr: string): Uint8Array; | ||
export declare function toHex(bytes: Uint8Array): string; | ||
/** @deprecated use toHex instead */ | ||
export declare const toHEX: typeof toHex; | ||
/** @deprecated use fromHex instead */ | ||
export declare const fromHEX: typeof fromHex; |
@@ -1,2 +0,2 @@ | ||
function fromHEX(hexStr) { | ||
function fromHex(hexStr) { | ||
const normalized = hexStr.startsWith("0x") ? hexStr.slice(2) : hexStr; | ||
@@ -7,9 +7,13 @@ const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}}`; | ||
} | ||
function toHEX(bytes) { | ||
function toHex(bytes) { | ||
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, "0"), ""); | ||
} | ||
const toHEX = toHex; | ||
const fromHEX = fromHex; | ||
export { | ||
fromHEX, | ||
toHEX | ||
fromHex, | ||
toHEX, | ||
toHex | ||
}; | ||
//# sourceMappingURL=hex.js.map |
@@ -1,7 +0,7 @@ | ||
import { fromB58, toB58 } from './b58.js'; | ||
import { fromB64, toB64 } from './b64.js'; | ||
import { fromB58, fromBase58, toB58, toBase58 } from './b58.js'; | ||
import { fromB64, fromBase64, toB64, toBase64 } from './b64.js'; | ||
import type { BcsTypeOptions } from './bcs-type.js'; | ||
import { BcsType, isSerializedBcs, SerializedBcs } from './bcs-type.js'; | ||
import { bcs } from './bcs.js'; | ||
import { fromHEX, toHEX } from './hex.js'; | ||
import { fromHEX, fromHex, toHEX, toHex } from './hex.js'; | ||
import { BcsReader } from './reader.js'; | ||
@@ -12,2 +12,2 @@ import type { EnumInputShape, EnumOutputShape, EnumOutputShapeWithKeys, InferBcsInput, InferBcsType } from './types.js'; | ||
import { BcsWriter } from './writer.js'; | ||
export { bcs, BcsType, type BcsTypeOptions, SerializedBcs, isSerializedBcs, toB58, fromB58, toB64, fromB64, fromHEX, toHEX, encodeStr, decodeStr, splitGenericParameters, BcsReader, BcsWriter, type BcsWriterOptions, type InferBcsInput, type InferBcsType, type EnumOutputShape, type EnumInputShape, type EnumOutputShapeWithKeys, }; | ||
export { bcs, BcsType, type BcsTypeOptions, SerializedBcs, isSerializedBcs, toB58, fromB58, toBase58, fromBase58, toB64, fromB64, toBase64, fromBase64, fromHEX, toHEX, toHex, fromHex, encodeStr, decodeStr, splitGenericParameters, BcsReader, BcsWriter, type BcsWriterOptions, type InferBcsInput, type InferBcsType, type EnumOutputShape, type EnumInputShape, type EnumOutputShapeWithKeys, }; |
@@ -1,6 +0,6 @@ | ||
import { fromB58, toB58 } from "./b58.js"; | ||
import { fromB64, toB64 } from "./b64.js"; | ||
import { fromB58, fromBase58, toB58, toBase58 } from "./b58.js"; | ||
import { fromB64, fromBase64, toB64, toBase64 } from "./b64.js"; | ||
import { BcsType, isSerializedBcs, SerializedBcs } from "./bcs-type.js"; | ||
import { bcs } from "./bcs.js"; | ||
import { fromHEX, toHEX } from "./hex.js"; | ||
import { fromHEX, fromHex, toHEX, toHex } from "./hex.js"; | ||
import { BcsReader } from "./reader.js"; | ||
@@ -19,3 +19,6 @@ import { decodeStr, encodeStr, splitGenericParameters } from "./utils.js"; | ||
fromB64, | ||
fromBase58, | ||
fromBase64, | ||
fromHEX, | ||
fromHex, | ||
isSerializedBcs, | ||
@@ -25,4 +28,7 @@ splitGenericParameters, | ||
toB64, | ||
toHEX | ||
toBase58, | ||
toBase64, | ||
toHEX, | ||
toHex | ||
}; | ||
//# sourceMappingURL=index.js.map |
@@ -1,12 +0,12 @@ | ||
import { fromB58, toB58 } from "./b58.js"; | ||
import { fromB64, toB64 } from "./b64.js"; | ||
import { fromHEX, toHEX } from "./hex.js"; | ||
import { fromBase58, toBase58 } from "./b58.js"; | ||
import { fromBase64, toBase64 } from "./b64.js"; | ||
import { fromHex, toHex } from "./hex.js"; | ||
function encodeStr(data, encoding) { | ||
switch (encoding) { | ||
case "base58": | ||
return toB58(data); | ||
return toBase58(data); | ||
case "base64": | ||
return toB64(data); | ||
return toBase64(data); | ||
case "hex": | ||
return toHEX(data); | ||
return toHex(data); | ||
default: | ||
@@ -19,7 +19,7 @@ throw new Error("Unsupported encoding, supported values are: base64, hex"); | ||
case "base58": | ||
return fromB58(data); | ||
return fromBase58(data); | ||
case "base64": | ||
return fromB64(data); | ||
return fromBase64(data); | ||
case "hex": | ||
return fromHEX(data); | ||
return fromHex(data); | ||
default: | ||
@@ -26,0 +26,0 @@ throw new Error("Unsupported encoding, supported values are: base64, hex"); |
{ | ||
"name": "@mysten/bcs", | ||
"version": "0.0.0-experimental-20240806174754", | ||
"version": "0.0.0-experimental-20240926213518", | ||
"description": "BCS - Canonical Binary Serialization implementation for JavaScript", | ||
@@ -5,0 +5,0 @@ "license": "Apache-2.0", |
@@ -19,8 +19,8 @@ # BCS - Binary Canonical Serialization | ||
```ts | ||
import { bcs } from '@mysten/bcs'; | ||
import { bcs, fromHex, toHex } from '@mysten/bcs'; | ||
// define UID as a 32-byte array, then add a transform to/from hex strings | ||
const UID = bcs.fixedArray(32, bcs.u8()).transform({ | ||
input: (id: string) => fromHEX(id), | ||
output: (id) => toHEX(Uint8Array.from(id)), | ||
input: (id: string) => fromHex(id), | ||
output: (id) => toHex(Uint8Array.from(id)), | ||
}); | ||
@@ -118,5 +118,5 @@ | ||
// Arrays | ||
const intArray = bcs.array(4, bcs.u8()).serialize([1, 2, 3, 4]).toBytes(); | ||
const stringArray = bcs.array(3, bcs.string()).serialize(['a', 'b', 'c']).toBytes(); | ||
// Fixed length Arrays | ||
const intArray = bcs.fixedArray(4, bcs.u8()).serialize([1, 2, 3, 4]).toBytes(); | ||
const stringArray = bcs.fixedArray(3, bcs.string()).serialize(['a', 'b', 'c']).toBytes(); | ||
@@ -132,3 +132,3 @@ // Option | ||
String: bcs.string(), | ||
Array: bcs.array(3, bcs.u8()), | ||
Array: bcs.fixedArray(3, bcs.u8()), | ||
}); | ||
@@ -169,4 +169,4 @@ | ||
// Arrays | ||
const parsedIntArray = bcs.array(4, bcs.u8()).parse(intArray); | ||
// Fixed length Arrays | ||
const parsedIntArray = bcs.fixedArray(4, bcs.u8()).parse(intArray); | ||
@@ -249,6 +249,8 @@ // Option | ||
```ts | ||
import { bcs, toHex } from '@mysten/bcs'; | ||
const Address = bcs.bytes(32).transform({ | ||
// To change the input type, you need to provide a type definition for the input | ||
input: (val: string) => fromHEX(val), | ||
output: (val) => toHEX(val), | ||
input: (val: string) => fromHex(val), | ||
output: (val) => toHex(val), | ||
}); | ||
@@ -314,3 +316,3 @@ | ||
```ts | ||
import { bcs, fromB58, fromB64, fromHex } from '@mysten/bcs'; | ||
import { bcs, fromBase58, fromBase64, fromHex } from '@mysten/bcs'; | ||
@@ -332,4 +334,4 @@ const serializedString = bcs.string().serialize('this is a string'); | ||
const str2 = bcs.string().parse(fromHex(hex)); | ||
const str3 = bcs.string().parse(fromB64(base64)); | ||
const str4 = bcs.string().parse(fromB58(base58)); | ||
const str3 = bcs.string().parse(fromBase64(base64)); | ||
const str4 = bcs.string().parse(fromBase58(base58)); | ||
@@ -336,0 +338,0 @@ console.assert((str1 == str2) == (str3 == str4), 'Result is the same'); |
@@ -6,3 +6,9 @@ // Copyright (c) Mysten Labs, Inc. | ||
export const toB58 = (buffer: Uint8Array) => bs58.encode(buffer); | ||
export const fromB58 = (str: string) => bs58.decode(str); | ||
export const toBase58 = (buffer: Uint8Array) => bs58.encode(buffer); | ||
export const fromBase58 = (str: string) => bs58.decode(str); | ||
/** @deprecated use toBase58 instead */ | ||
export const toB58 = toBase58; | ||
/** @deprecated use fromBase58 instead */ | ||
export const fromB58 = fromBase58; |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
export function fromB64(base64String: string): Uint8Array { | ||
export function fromBase64(base64String: string): Uint8Array { | ||
return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0)); | ||
@@ -9,3 +9,3 @@ } | ||
const CHUNK_SIZE = 8192; | ||
export function toB64(bytes: Uint8Array): string { | ||
export function toBase64(bytes: Uint8Array): string { | ||
// Special-case the simple case for speed's sake. | ||
@@ -24,1 +24,7 @@ if (bytes.length < CHUNK_SIZE) { | ||
} | ||
/** @deprecated use toBase64 instead */ | ||
export const toB64 = toBase64; | ||
/** @deprecated use fromBase64 instead */ | ||
export const fromB64 = fromBase64; |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { fromB58, toB58 } from './b58.js'; | ||
import { fromB64, toB64 } from './b64.js'; | ||
import { fromHEX, toHEX } from './hex.js'; | ||
import { fromBase58, toBase58 } from './b58.js'; | ||
import { fromBase64, toBase64 } from './b64.js'; | ||
import { fromHex, toHex } from './hex.js'; | ||
import { BcsReader } from './reader.js'; | ||
@@ -71,11 +71,11 @@ import { ulebEncode } from './uleb.js'; | ||
fromHex(hex: string) { | ||
return this.parse(fromHEX(hex)); | ||
return this.parse(fromHex(hex)); | ||
} | ||
fromBase58(b64: string) { | ||
return this.parse(fromB58(b64)); | ||
return this.parse(fromBase58(b64)); | ||
} | ||
fromBase64(b64: string) { | ||
return this.parse(fromB64(b64)); | ||
return this.parse(fromBase64(b64)); | ||
} | ||
@@ -131,11 +131,11 @@ | ||
toHex() { | ||
return toHEX(this.#bytes); | ||
return toHex(this.#bytes); | ||
} | ||
toBase64() { | ||
return toB64(this.#bytes); | ||
return toBase64(this.#bytes); | ||
} | ||
toBase58() { | ||
return toB58(this.#bytes); | ||
return toBase58(this.#bytes); | ||
} | ||
@@ -142,0 +142,0 @@ |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
export function fromHEX(hexStr: string): Uint8Array { | ||
export function fromHex(hexStr: string): Uint8Array { | ||
const normalized = hexStr.startsWith('0x') ? hexStr.slice(2) : hexStr; | ||
@@ -12,4 +12,10 @@ const padded = normalized.length % 2 === 0 ? normalized : `0${normalized}}`; | ||
export function toHEX(bytes: Uint8Array): string { | ||
export function toHex(bytes: Uint8Array): string { | ||
return bytes.reduce((str, byte) => str + byte.toString(16).padStart(2, '0'), ''); | ||
} | ||
/** @deprecated use toHex instead */ | ||
export const toHEX = toHex; | ||
/** @deprecated use fromHex instead */ | ||
export const fromHEX = fromHex; |
@@ -14,8 +14,8 @@ // Copyright (c) Mysten Labs, Inc. | ||
import { fromB58, toB58 } from './b58.js'; | ||
import { fromB64, toB64 } from './b64.js'; | ||
import { fromB58, fromBase58, toB58, toBase58 } from './b58.js'; | ||
import { fromB64, fromBase64, toB64, toBase64 } from './b64.js'; | ||
import type { BcsTypeOptions } from './bcs-type.js'; | ||
import { BcsType, isSerializedBcs, SerializedBcs } from './bcs-type.js'; | ||
import { bcs } from './bcs.js'; | ||
import { fromHEX, toHEX } from './hex.js'; | ||
import { fromHEX, fromHex, toHEX, toHex } from './hex.js'; | ||
import { BcsReader } from './reader.js'; | ||
@@ -42,6 +42,12 @@ import type { | ||
fromB58, | ||
toBase58, | ||
fromBase58, | ||
toB64, | ||
fromB64, | ||
toBase64, | ||
fromBase64, | ||
fromHEX, | ||
toHEX, | ||
toHex, | ||
fromHex, | ||
encodeStr, | ||
@@ -48,0 +54,0 @@ decodeStr, |
// Copyright (c) Mysten Labs, Inc. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import { fromB58, toB58 } from './b58.js'; | ||
import { fromB64, toB64 } from './b64.js'; | ||
import { fromHEX, toHEX } from './hex.js'; | ||
import { fromBase58, toBase58 } from './b58.js'; | ||
import { fromBase64, toBase64 } from './b64.js'; | ||
import { fromHex, toHex } from './hex.js'; | ||
import type { Encoding } from './types.js'; | ||
@@ -19,7 +19,7 @@ | ||
case 'base58': | ||
return toB58(data); | ||
return toBase58(data); | ||
case 'base64': | ||
return toB64(data); | ||
return toBase64(data); | ||
case 'hex': | ||
return toHEX(data); | ||
return toHex(data); | ||
default: | ||
@@ -40,7 +40,7 @@ throw new Error('Unsupported encoding, supported values are: base64, hex'); | ||
case 'base58': | ||
return fromB58(data); | ||
return fromBase58(data); | ||
case 'base64': | ||
return fromB64(data); | ||
return fromBase64(data); | ||
case 'hex': | ||
return fromHEX(data); | ||
return fromHex(data); | ||
default: | ||
@@ -47,0 +47,0 @@ throw new Error('Unsupported encoding, supported values are: base64, hex'); |
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
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
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
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
355038
4948
359