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

@blockfrost/blockfrost-utils

Package Overview
Dependencies
Maintainers
3
Versions
50
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@blockfrost/blockfrost-utils - npm Package Compare versions

Comparing version 2.1.0 to 2.1.1-beta.0

11

lib/cip68.d.ts

@@ -6,2 +6,13 @@ /// <reference types="node" />

}
/**
* https://github.com/websockets/utf-8-validate/blob/master/fallback.js
* Checks if a given buffer contains only correct UTF-8.
* Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
* Markus Kuhn.
*
* @param {Buffer} buf The buffer to check
* @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
* @public
*/
export declare const isValidUTF8: (buf: Buffer) => boolean;
export declare const toUTF8OrHex: (hexOrBuffer: string | Buffer) => string;

@@ -8,0 +19,0 @@ export declare const toLabel: (number_: number) => string;

66

lib/cip68.js

@@ -29,6 +29,5 @@ "use strict";

Object.defineProperty(exports, "__esModule", { value: true });
exports.getMetadataFromOutputDatum = exports.getReferenceNFT = exports.toCip68Assets = exports.fromLabel = exports.toLabel = exports.toUTF8OrHex = void 0;
exports.getMetadataFromOutputDatum = exports.getReferenceNFT = exports.toCip68Assets = exports.fromLabel = exports.toLabel = exports.toUTF8OrHex = exports.isValidUTF8 = void 0;
const CardanoWasm = __importStar(require("@emurgo/cardano-serialization-lib-nodejs"));
const crc8_1 = __importDefault(require("crc/crc8"));
const utf_8_validate_1 = __importDefault(require("utf-8-validate"));
const cbor_1 = __importDefault(require("cbor"));

@@ -40,2 +39,63 @@ const ASSET_NAME_LABELS = {

};
/**
* https://github.com/websockets/utf-8-validate/blob/master/fallback.js
* Checks if a given buffer contains only correct UTF-8.
* Ported from https://www.cl.cam.ac.uk/%7Emgk25/ucs/utf8_check.c by
* Markus Kuhn.
*
* @param {Buffer} buf The buffer to check
* @return {Boolean} `true` if `buf` contains only correct UTF-8, else `false`
* @public
*/
const isValidUTF8 = (buf) => {
const len = buf.length;
let i = 0;
while (i < len) {
if ((buf[i] & 0x80) === 0x00) {
// 0xxxxxxx
i++;
}
else if ((buf[i] & 0xe0) === 0xc0) {
// 110xxxxx 10xxxxxx
if (i + 1 === len ||
(buf[i + 1] & 0xc0) !== 0x80 ||
(buf[i] & 0xfe) === 0xc0 // overlong
) {
return false;
}
i += 2;
}
else if ((buf[i] & 0xf0) === 0xe0) {
// 1110xxxx 10xxxxxx 10xxxxxx
if (i + 2 >= len ||
(buf[i + 1] & 0xc0) !== 0x80 ||
(buf[i + 2] & 0xc0) !== 0x80 ||
(buf[i] === 0xe0 && (buf[i + 1] & 0xe0) === 0x80) || // overlong
(buf[i] === 0xed && (buf[i + 1] & 0xe0) === 0xa0) // surrogate (U+D800 - U+DFFF)
) {
return false;
}
i += 3;
}
else if ((buf[i] & 0xf8) === 0xf0) {
// 11110xxx 10xxxxxx 10xxxxxx 10xxxxxx
if (i + 3 >= len ||
(buf[i + 1] & 0xc0) !== 0x80 ||
(buf[i + 2] & 0xc0) !== 0x80 ||
(buf[i + 3] & 0xc0) !== 0x80 ||
(buf[i] === 0xf0 && (buf[i + 1] & 0xf0) === 0x80) || // overlong
(buf[i] === 0xf4 && buf[i + 1] > 0x8f) ||
buf[i] > 0xf4 // > U+10FFFF
) {
return false;
}
i += 4;
}
else {
return false;
}
}
return true;
};
exports.isValidUTF8 = isValidUTF8;
const hexToString = (input) => {

@@ -68,3 +128,3 @@ const hex = input.toString();

: Buffer.from(hexOrBuffer, 'hex');
return (0, utf_8_validate_1.default)(buffer) ? buffer.toString('utf8') : buffer.toString('hex');
return (0, exports.isValidUTF8)(buffer) ? buffer.toString('utf8') : buffer.toString('hex');
};

@@ -71,0 +131,0 @@ exports.toUTF8OrHex = toUTF8OrHex;

3

package.json
{
"name": "@blockfrost/blockfrost-utils",
"version": "2.1.0",
"version": "2.1.1-beta.0",
"repository": "git@github.com:blockfrost/blockfrost-utils.git",

@@ -26,3 +26,2 @@ "license": "Apache-2.0",

"crc": "^4.2.0",
"utf-8-validate": "^5.0.10",
"yaml": "^2.1.1"

@@ -29,0 +28,0 @@ },

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