@arcblock/forge-util
Advanced tools
Comparing version 0.38.0 to 0.38.4
@@ -15,4 +15,3 @@ // Generate by [js2dts@0.3.3](https://github.com/whxaxes/js2dts#readme) | ||
* | ||
* @param {buffer|base58|hex|Uint8Array} v | ||
* @param {boolean} [autoHex=false] | ||
* @param {buffer|base58|hex|Uint8Array|string} v | ||
* @param {boolean} [enforceStrictHex=false] | ||
@@ -22,3 +21,3 @@ * @returns {Uint8Array} | ||
*/ | ||
declare function toUint8Array(v: any, autoHex?: boolean, enforceStrictHex?: boolean): Uint8Array; | ||
declare function toUint8Array(v: any, enforceStrictHex?: boolean): Uint8Array; | ||
/** | ||
@@ -28,3 +27,2 @@ * Convert input to Buffer on best effort | ||
* @param {buffer|base58|hex|Uint8Array} v | ||
* @param {boolean} [autoHex=false] | ||
* @param {boolean} [enforceStrictHex=false] | ||
@@ -34,3 +32,3 @@ * @returns {buffer} | ||
*/ | ||
declare function toBuffer(v: any, autoHex?: boolean, enforceStrictHex?: boolean): any; | ||
declare function toBuffer(v: any, enforceStrictHex?: boolean): any; | ||
/** | ||
@@ -40,3 +38,2 @@ * Convert input to base58btc format on best effort | ||
* @param {buffer|base58|hex|Uint8Array} v | ||
* @param {boolean} [autoHex=false] | ||
* @param {boolean} [enforceStrictHex=false] | ||
@@ -46,3 +43,3 @@ * @returns {string} | ||
*/ | ||
declare function toBase58(v: any, autoHex?: boolean, enforceStrictHex?: boolean): string; | ||
declare function toBase58(v: any, enforceStrictHex?: boolean): string; | ||
/** | ||
@@ -56,2 +53,19 @@ * Decode base58 string | ||
/** | ||
* Convert input to base64 format | ||
* | ||
* @param {buffer|base58|hex|Uint8Array} v | ||
* @param {escape} [escape=true] | ||
* @param {boolean} [enforceStrictHex=false] | ||
* @returns {string} | ||
* @throws {Error} | ||
*/ | ||
declare function toBase64(v: any, escape?: typeof escape, enforceStrictHex?: boolean): string; | ||
/** | ||
* Decode base64 string to buffer | ||
* | ||
* @param {string} v | ||
* @returns {buffer} | ||
*/ | ||
declare function fromBase64(v: string): any; | ||
/** | ||
* Generate a random UUID | ||
@@ -113,2 +127,4 @@ * | ||
fromBase58: typeof fromBase58; | ||
toBase64: typeof toBase64; | ||
fromBase64: typeof fromBase64; | ||
UUID: typeof UUID; | ||
@@ -115,0 +131,0 @@ isUUID: typeof isUUID; |
@@ -18,2 +18,3 @@ /* eslint-disable no-bitwise */ | ||
const utf8 = require('utf8'); | ||
const base64 = require('base64-url'); | ||
const BN = require('bn.js'); | ||
@@ -513,4 +514,3 @@ | ||
* | ||
* @param {buffer|base58|hex|Uint8Array} v | ||
* @param {boolean} [autoHex=false] | ||
* @param {buffer|base58|hex|Uint8Array|string} v | ||
* @param {boolean} [enforceStrictHex=false] | ||
@@ -520,3 +520,3 @@ * @returns {Uint8Array} | ||
*/ | ||
function toUint8Array(v, autoHex = false, enforceStrictHex = false) { | ||
function toUint8Array(v, enforceStrictHex = false) { | ||
let vb = null; | ||
@@ -541,11 +541,7 @@ if (Buffer.isBuffer(v)) { | ||
vb = Uint8Array.from(multibase.decode(v)); | ||
} else if (autoHex) { | ||
// eslint-disable-next-line no-console | ||
console.warn( | ||
'It seems you provided an non-supported input to toUint8Array, its converted to hex implicitly' | ||
); | ||
} else if (typeof v === 'string') { | ||
vb = Uint8Array.from(hexToBytes(toHex(v))); | ||
} else { | ||
throw new Error( | ||
'Unsupported input type detected for toBuffer, only Uint8Array/Buffer/Hex/Base58 supported' | ||
`Unsupported input type ${typeof v} detected for toBuffer, only Uint8Array/Buffer/Hex/Base58 supported` | ||
); | ||
@@ -561,3 +557,2 @@ } | ||
* @param {buffer|base58|hex|Uint8Array} v | ||
* @param {boolean} [autoHex=false] | ||
* @param {boolean} [enforceStrictHex=false] | ||
@@ -567,4 +562,4 @@ * @returns {buffer} | ||
*/ | ||
function toBuffer(v, autoHex = false, enforceStrictHex = false) { | ||
return Buffer.from(toUint8Array(v, autoHex, enforceStrictHex)); | ||
function toBuffer(v, enforceStrictHex = false) { | ||
return Buffer.from(toUint8Array(v, enforceStrictHex)); | ||
} | ||
@@ -576,3 +571,2 @@ | ||
* @param {buffer|base58|hex|Uint8Array} v | ||
* @param {boolean} [autoHex=false] | ||
* @param {boolean} [enforceStrictHex=false] | ||
@@ -582,4 +576,4 @@ * @returns {string} | ||
*/ | ||
function toBase58(v, autoHex = false, enforceStrictHex = false) { | ||
return multibase.encode('base58btc', toBuffer(v, autoHex, enforceStrictHex)).toString(); | ||
function toBase58(v, enforceStrictHex = false) { | ||
return multibase.encode('base58btc', toBuffer(v, enforceStrictHex)).toString(); | ||
} | ||
@@ -602,2 +596,29 @@ | ||
/** | ||
* Convert input to base64 format | ||
* | ||
* @param {buffer|base58|hex|Uint8Array} v | ||
* @param {escape} [escape=true] | ||
* @param {boolean} [enforceStrictHex=false] | ||
* @returns {string} | ||
* @throws {Error} | ||
*/ | ||
function toBase64(v, escape = true, enforceStrictHex = false) { | ||
const encoded = base64.encode(toBuffer(v, enforceStrictHex)); | ||
return escape ? base64.escape(encoded) : encoded; | ||
} | ||
/** | ||
* Decode base64 string to buffer | ||
* | ||
* @param {string} v | ||
* @returns {buffer} | ||
*/ | ||
function fromBase64(v) { | ||
if (typeof v !== 'string') { | ||
throw new Error('fromBase64 requires input to be a string'); | ||
} | ||
return Buffer.from(base64.unescape(v), 'base64'); | ||
} | ||
/** | ||
* Convert did to address: remove `did:abt:` prefix if exists | ||
@@ -650,2 +671,4 @@ * | ||
fromBase58, | ||
toBase64, | ||
fromBase64, | ||
UUID, | ||
@@ -652,0 +675,0 @@ isUUID, |
{ | ||
"name": "@arcblock/forge-util", | ||
"version": "0.38.0", | ||
"version": "0.38.4", | ||
"description": "utils shared across mutlipe forge js libs, works in both node.js and browser", | ||
@@ -16,2 +16,3 @@ "keywords": [ | ||
"dependencies": { | ||
"base64-url": "^2.3.2", | ||
"bn.js": "4.11.6", | ||
@@ -57,3 +58,3 @@ "lodash": "^4.17.14", | ||
}, | ||
"gitHead": "95052cc8a2af7e06daaebd8a57dfca3e282f8f7c" | ||
"gitHead": "d9e6b54cbe74e3d682598f491e43f551d9e8c84d" | ||
} |
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
22268
719
6
+ Addedbase64-url@^2.3.2
+ Addedbase64-url@2.3.3(transitive)