Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@mysten/bcs

Package Overview
Dependencies
Maintainers
4
Versions
522
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@mysten/bcs - npm Package Compare versions

Comparing version 0.0.0-experimental-20240106194601 to 0.0.0-experimental-20240201191544

8

CHANGELOG.md
# Change Log
## 0.0.0-experimental-20240106194601
## 0.0.0-experimental-20240201191544
### Minor Changes
- bae8802fe3: Update base64 encoding to use global `atob` and `btoa` functions.
## 0.10.1
### Patch Changes

@@ -6,0 +12,0 @@

4

dist/cjs/b64.d.ts

@@ -1,2 +0,2 @@

export declare function fromB64(sBase64: string, nBlocksSize?: number): Uint8Array;
export declare function toB64(aBytes: Uint8Array): string;
export declare function fromB64(base64String: string): Uint8Array;
export declare function toB64(bytes: Uint8Array): string;

@@ -25,39 +25,17 @@ "use strict";

module.exports = __toCommonJS(b64_exports);
function b64ToUint6(nChr) {
return nChr > 64 && nChr < 91 ? nChr - 65 : nChr > 96 && nChr < 123 ? nChr - 71 : nChr > 47 && nChr < 58 ? nChr + 4 : nChr === 43 ? 62 : nChr === 47 ? 63 : 0;
function fromB64(base64String) {
return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));
}
function fromB64(sBase64, nBlocksSize) {
var sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, ""), nInLen = sB64Enc.length, nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2, taBytes = new Uint8Array(nOutLen);
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
nMod4 = nInIdx & 3;
nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 6 * (3 - nMod4);
if (nMod4 === 3 || nInLen - nInIdx === 1) {
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
}
nUint24 = 0;
}
const CHUNK_SIZE = 8192;
function toB64(bytes) {
if (bytes.length < CHUNK_SIZE) {
return btoa(String.fromCharCode(...bytes));
}
return taBytes;
}
function uint6ToB64(nUint6) {
return nUint6 < 26 ? nUint6 + 65 : nUint6 < 52 ? nUint6 + 71 : nUint6 < 62 ? nUint6 - 4 : nUint6 === 62 ? 43 : nUint6 === 63 ? 47 : 65;
}
function toB64(aBytes) {
var nMod3 = 2, sB64Enc = "";
for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {
nMod3 = nIdx % 3;
nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24);
if (nMod3 === 2 || aBytes.length - nIdx === 1) {
sB64Enc += String.fromCodePoint(
uint6ToB64(nUint24 >>> 18 & 63),
uint6ToB64(nUint24 >>> 12 & 63),
uint6ToB64(nUint24 >>> 6 & 63),
uint6ToB64(nUint24 & 63)
);
nUint24 = 0;
}
let output = "";
for (var i = 0; i < bytes.length; i += CHUNK_SIZE) {
const chunk = bytes.slice(i, i + CHUNK_SIZE);
output += String.fromCharCode(...chunk);
}
return sB64Enc.slice(0, sB64Enc.length - 2 + nMod3) + (nMod3 === 2 ? "" : nMod3 === 1 ? "=" : "==");
return btoa(output);
}
//# sourceMappingURL=b64.js.map

@@ -1,2 +0,2 @@

export declare function fromB64(sBase64: string, nBlocksSize?: number): Uint8Array;
export declare function toB64(aBytes: Uint8Array): string;
export declare function fromB64(base64String: string): Uint8Array;
export declare function toB64(bytes: Uint8Array): string;

@@ -1,37 +0,15 @@

function b64ToUint6(nChr) {
return nChr > 64 && nChr < 91 ? nChr - 65 : nChr > 96 && nChr < 123 ? nChr - 71 : nChr > 47 && nChr < 58 ? nChr + 4 : nChr === 43 ? 62 : nChr === 47 ? 63 : 0;
function fromB64(base64String) {
return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));
}
function fromB64(sBase64, nBlocksSize) {
var sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, ""), nInLen = sB64Enc.length, nOutLen = nBlocksSize ? Math.ceil((nInLen * 3 + 1 >> 2) / nBlocksSize) * nBlocksSize : nInLen * 3 + 1 >> 2, taBytes = new Uint8Array(nOutLen);
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
nMod4 = nInIdx & 3;
nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << 6 * (3 - nMod4);
if (nMod4 === 3 || nInLen - nInIdx === 1) {
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
taBytes[nOutIdx] = nUint24 >>> (16 >>> nMod3 & 24) & 255;
}
nUint24 = 0;
}
const CHUNK_SIZE = 8192;
function toB64(bytes) {
if (bytes.length < CHUNK_SIZE) {
return btoa(String.fromCharCode(...bytes));
}
return taBytes;
}
function uint6ToB64(nUint6) {
return nUint6 < 26 ? nUint6 + 65 : nUint6 < 52 ? nUint6 + 71 : nUint6 < 62 ? nUint6 - 4 : nUint6 === 62 ? 43 : nUint6 === 63 ? 47 : 65;
}
function toB64(aBytes) {
var nMod3 = 2, sB64Enc = "";
for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {
nMod3 = nIdx % 3;
nUint24 |= aBytes[nIdx] << (16 >>> nMod3 & 24);
if (nMod3 === 2 || aBytes.length - nIdx === 1) {
sB64Enc += String.fromCodePoint(
uint6ToB64(nUint24 >>> 18 & 63),
uint6ToB64(nUint24 >>> 12 & 63),
uint6ToB64(nUint24 >>> 6 & 63),
uint6ToB64(nUint24 & 63)
);
nUint24 = 0;
}
let output = "";
for (var i = 0; i < bytes.length; i += CHUNK_SIZE) {
const chunk = bytes.slice(i, i + CHUNK_SIZE);
output += String.fromCharCode(...chunk);
}
return sB64Enc.slice(0, sB64Enc.length - 2 + nMod3) + (nMod3 === 2 ? "" : nMod3 === 1 ? "=" : "==");
return btoa(output);
}

@@ -38,0 +16,0 @@ export {

{
"name": "@mysten/bcs",
"version": "0.0.0-experimental-20240106194601",
"version": "0.0.0-experimental-20240201191544",
"description": "BCS - Canonical Binary Serialization implementation for JavaScript",

@@ -5,0 +5,0 @@ "license": "Apache-2.0",

// Copyright (c) Mysten Labs, Inc.
// SPDX-License-Identifier: Apache-2.0
/*\
|*| Base64 / binary data / UTF-8 strings utilities
|*| https://developer.mozilla.org/en-US/docs/Web/JavaScript/Base64_encoding_and_decoding
\*/
/* Array of bytes to Base64 string decoding */
function b64ToUint6(nChr: number) {
return nChr > 64 && nChr < 91
? nChr - 65
: nChr > 96 && nChr < 123
? nChr - 71
: nChr > 47 && nChr < 58
? nChr + 4
: nChr === 43
? 62
: nChr === 47
? 63
: 0;
export function fromB64(base64String: string): Uint8Array {
return Uint8Array.from(atob(base64String), (char) => char.charCodeAt(0));
}
export function fromB64(sBase64: string, nBlocksSize?: number): Uint8Array {
var sB64Enc = sBase64.replace(/[^A-Za-z0-9+/]/g, ''),
nInLen = sB64Enc.length,
nOutLen = nBlocksSize
? Math.ceil(((nInLen * 3 + 1) >> 2) / nBlocksSize) * nBlocksSize
: (nInLen * 3 + 1) >> 2,
taBytes = new Uint8Array(nOutLen);
for (var nMod3, nMod4, nUint24 = 0, nOutIdx = 0, nInIdx = 0; nInIdx < nInLen; nInIdx++) {
nMod4 = nInIdx & 3;
nUint24 |= b64ToUint6(sB64Enc.charCodeAt(nInIdx)) << (6 * (3 - nMod4));
if (nMod4 === 3 || nInLen - nInIdx === 1) {
for (nMod3 = 0; nMod3 < 3 && nOutIdx < nOutLen; nMod3++, nOutIdx++) {
taBytes[nOutIdx] = (nUint24 >>> ((16 >>> nMod3) & 24)) & 255;
}
nUint24 = 0;
}
const CHUNK_SIZE = 8192;
export function toB64(bytes: Uint8Array): string {
// Special-case the simple case for speed's sake.
if (bytes.length < CHUNK_SIZE) {
return btoa(String.fromCharCode(...bytes));
}
return taBytes;
}
/* Base64 string to array encoding */
function uint6ToB64(nUint6: number) {
return nUint6 < 26
? nUint6 + 65
: nUint6 < 52
? nUint6 + 71
: nUint6 < 62
? nUint6 - 4
: nUint6 === 62
? 43
: nUint6 === 63
? 47
: 65;
}
export function toB64(aBytes: Uint8Array): string {
var nMod3 = 2,
sB64Enc = '';
for (var nLen = aBytes.length, nUint24 = 0, nIdx = 0; nIdx < nLen; nIdx++) {
nMod3 = nIdx % 3;
nUint24 |= aBytes[nIdx] << ((16 >>> nMod3) & 24);
if (nMod3 === 2 || aBytes.length - nIdx === 1) {
sB64Enc += String.fromCodePoint(
uint6ToB64((nUint24 >>> 18) & 63),
uint6ToB64((nUint24 >>> 12) & 63),
uint6ToB64((nUint24 >>> 6) & 63),
uint6ToB64(nUint24 & 63),
);
nUint24 = 0;
}
let output = '';
for (var i = 0; i < bytes.length; i += CHUNK_SIZE) {
const chunk = bytes.slice(i, i + CHUNK_SIZE);
output += String.fromCharCode(...chunk);
}
return (
sB64Enc.slice(0, sB64Enc.length - 2 + nMod3) + (nMod3 === 2 ? '' : nMod3 === 1 ? '=' : '==')
);
return btoa(output);
}

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc