@0xsequence/utils
Advanced tools
Comparing version 0.0.0-20240829183049 to 0.0.0-20240903183150
@@ -29,2 +29,26 @@ 'use strict'; | ||
const base64Encode = val => { | ||
return jsBase64.Base64.encode(val, true); | ||
}; | ||
const base64EncodeObject = obj => { | ||
return jsBase64.Base64.encode(JSON.stringify(obj), true); | ||
}; | ||
const base64Decode = encodedString => { | ||
if (encodedString === null || encodedString === undefined) { | ||
return undefined; | ||
} | ||
return jsBase64.Base64.decode(encodedString); | ||
}; | ||
const base64DecodeObject = encodedObject => { | ||
if (encodedObject === null || encodedObject === undefined) { | ||
return undefined; | ||
} | ||
return JSON.parse(jsBase64.Base64.decode(encodedObject)); | ||
}; | ||
// Monkey patch toJSON on BigInt to return a string | ||
BigInt.prototype.toJSON = function () { | ||
return this.toString(); | ||
}; | ||
const MAX_UINT_256 = BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); | ||
@@ -89,44 +113,2 @@ | ||
// JSON.stringify doesn't handle BigInts, so we need to replace them with objects | ||
const bigintReplacer = (key, value) => { | ||
if (typeof value === 'bigint') { | ||
return { | ||
$bigint: value.toString() | ||
}; | ||
} | ||
return value; | ||
}; | ||
// JSON.parse will need to convert our serialized bigints back into BigInt | ||
const bigintReviver = (key, value) => { | ||
if (value !== null && typeof value === 'object' && '$bigint' in value && typeof value.$bigint === 'string') { | ||
return BigInt(value.$bigint); | ||
} | ||
// BigNumber compatibility with older versions of sequence.js with ethers v5 | ||
if (value !== null && typeof value === 'object' && value.type === 'BigNumber' && ethers.ethers.isHexString(value.hex)) { | ||
return BigInt(value.hex); | ||
} | ||
return value; | ||
}; | ||
const base64Encode = val => { | ||
return jsBase64.Base64.encode(val, true); | ||
}; | ||
const base64EncodeObject = obj => { | ||
return jsBase64.Base64.encode(JSON.stringify(obj, bigintReplacer), true); | ||
}; | ||
const base64Decode = encodedString => { | ||
if (encodedString === null || encodedString === undefined) { | ||
return undefined; | ||
} | ||
return jsBase64.Base64.decode(encodedString); | ||
}; | ||
const base64DecodeObject = encodedObject => { | ||
if (encodedObject === null || encodedObject === undefined) { | ||
return undefined; | ||
} | ||
return JSON.parse(jsBase64.Base64.decode(encodedObject), bigintReviver); | ||
}; | ||
const encodeMessageDigest = message => { | ||
@@ -701,4 +683,2 @@ if (typeof message === 'string') { | ||
exports.base64EncodeObject = base64EncodeObject; | ||
exports.bigintReplacer = bigintReplacer; | ||
exports.bigintReviver = bigintReviver; | ||
exports.configureLogger = configureLogger; | ||
@@ -705,0 +685,0 @@ exports.defineProperties = defineProperties; |
@@ -29,2 +29,26 @@ 'use strict'; | ||
const base64Encode = val => { | ||
return jsBase64.Base64.encode(val, true); | ||
}; | ||
const base64EncodeObject = obj => { | ||
return jsBase64.Base64.encode(JSON.stringify(obj), true); | ||
}; | ||
const base64Decode = encodedString => { | ||
if (encodedString === null || encodedString === undefined) { | ||
return undefined; | ||
} | ||
return jsBase64.Base64.decode(encodedString); | ||
}; | ||
const base64DecodeObject = encodedObject => { | ||
if (encodedObject === null || encodedObject === undefined) { | ||
return undefined; | ||
} | ||
return JSON.parse(jsBase64.Base64.decode(encodedObject)); | ||
}; | ||
// Monkey patch toJSON on BigInt to return a string | ||
BigInt.prototype.toJSON = function () { | ||
return this.toString(); | ||
}; | ||
const MAX_UINT_256 = BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); | ||
@@ -89,44 +113,2 @@ | ||
// JSON.stringify doesn't handle BigInts, so we need to replace them with objects | ||
const bigintReplacer = (key, value) => { | ||
if (typeof value === 'bigint') { | ||
return { | ||
$bigint: value.toString() | ||
}; | ||
} | ||
return value; | ||
}; | ||
// JSON.parse will need to convert our serialized bigints back into BigInt | ||
const bigintReviver = (key, value) => { | ||
if (value !== null && typeof value === 'object' && '$bigint' in value && typeof value.$bigint === 'string') { | ||
return BigInt(value.$bigint); | ||
} | ||
// BigNumber compatibility with older versions of sequence.js with ethers v5 | ||
if (value !== null && typeof value === 'object' && value.type === 'BigNumber' && ethers.ethers.isHexString(value.hex)) { | ||
return BigInt(value.hex); | ||
} | ||
return value; | ||
}; | ||
const base64Encode = val => { | ||
return jsBase64.Base64.encode(val, true); | ||
}; | ||
const base64EncodeObject = obj => { | ||
return jsBase64.Base64.encode(JSON.stringify(obj, bigintReplacer), true); | ||
}; | ||
const base64Decode = encodedString => { | ||
if (encodedString === null || encodedString === undefined) { | ||
return undefined; | ||
} | ||
return jsBase64.Base64.decode(encodedString); | ||
}; | ||
const base64DecodeObject = encodedObject => { | ||
if (encodedObject === null || encodedObject === undefined) { | ||
return undefined; | ||
} | ||
return JSON.parse(jsBase64.Base64.decode(encodedObject), bigintReviver); | ||
}; | ||
const encodeMessageDigest = message => { | ||
@@ -701,4 +683,2 @@ if (typeof message === 'string') { | ||
exports.base64EncodeObject = base64EncodeObject; | ||
exports.bigintReplacer = bigintReplacer; | ||
exports.bigintReviver = bigintReviver; | ||
exports.configureLogger = configureLogger; | ||
@@ -705,0 +685,0 @@ exports.defineProperties = defineProperties; |
@@ -25,2 +25,26 @@ import { Base64 } from 'js-base64'; | ||
const base64Encode = val => { | ||
return Base64.encode(val, true); | ||
}; | ||
const base64EncodeObject = obj => { | ||
return Base64.encode(JSON.stringify(obj), true); | ||
}; | ||
const base64Decode = encodedString => { | ||
if (encodedString === null || encodedString === undefined) { | ||
return undefined; | ||
} | ||
return Base64.decode(encodedString); | ||
}; | ||
const base64DecodeObject = encodedObject => { | ||
if (encodedObject === null || encodedObject === undefined) { | ||
return undefined; | ||
} | ||
return JSON.parse(Base64.decode(encodedObject)); | ||
}; | ||
// Monkey patch toJSON on BigInt to return a string | ||
BigInt.prototype.toJSON = function () { | ||
return this.toString(); | ||
}; | ||
const MAX_UINT_256 = BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff'); | ||
@@ -85,44 +109,2 @@ | ||
// JSON.stringify doesn't handle BigInts, so we need to replace them with objects | ||
const bigintReplacer = (key, value) => { | ||
if (typeof value === 'bigint') { | ||
return { | ||
$bigint: value.toString() | ||
}; | ||
} | ||
return value; | ||
}; | ||
// JSON.parse will need to convert our serialized bigints back into BigInt | ||
const bigintReviver = (key, value) => { | ||
if (value !== null && typeof value === 'object' && '$bigint' in value && typeof value.$bigint === 'string') { | ||
return BigInt(value.$bigint); | ||
} | ||
// BigNumber compatibility with older versions of sequence.js with ethers v5 | ||
if (value !== null && typeof value === 'object' && value.type === 'BigNumber' && ethers.isHexString(value.hex)) { | ||
return BigInt(value.hex); | ||
} | ||
return value; | ||
}; | ||
const base64Encode = val => { | ||
return Base64.encode(val, true); | ||
}; | ||
const base64EncodeObject = obj => { | ||
return Base64.encode(JSON.stringify(obj, bigintReplacer), true); | ||
}; | ||
const base64Decode = encodedString => { | ||
if (encodedString === null || encodedString === undefined) { | ||
return undefined; | ||
} | ||
return Base64.decode(encodedString); | ||
}; | ||
const base64DecodeObject = encodedObject => { | ||
if (encodedObject === null || encodedObject === undefined) { | ||
return undefined; | ||
} | ||
return JSON.parse(Base64.decode(encodedObject), bigintReviver); | ||
}; | ||
const encodeMessageDigest = message => { | ||
@@ -689,2 +671,2 @@ if (typeof message === 'string') { | ||
export { Logger, MAX_UINT_256, MerkleTreeGenerator, PromiseCache, base64Decode, base64DecodeObject, base64Encode, base64EncodeObject, bigintReplacer, bigintReviver, configureLogger, defineProperties, encodeMessageDigest, encodeTypedDataDigest, encodeTypedDataHash, extractProjectIdFromAccessKey, formatEther, formatUnits, getFetchRequest, getRandomInt, getSaleItemsLeaf, isBigNumberish, isBrowser, isNode, jwtDecodeClaims, logger, packMessageData, parseEther, parseUnits, promisify, queryStringFromObject, queryStringToObject, resolveProperties, sanitizeAlphanumeric, sanitizeHost, sanitizeNumberString, sleep, subDigestOf, toHexString, urlClean }; | ||
export { Logger, MAX_UINT_256, MerkleTreeGenerator, PromiseCache, base64Decode, base64DecodeObject, base64Encode, base64EncodeObject, configureLogger, defineProperties, encodeMessageDigest, encodeTypedDataDigest, encodeTypedDataHash, extractProjectIdFromAccessKey, formatEther, formatUnits, getFetchRequest, getRandomInt, getSaleItemsLeaf, isBigNumberish, isBrowser, isNode, jwtDecodeClaims, logger, packMessageData, parseEther, parseUnits, promisify, queryStringFromObject, queryStringToObject, resolveProperties, sanitizeAlphanumeric, sanitizeHost, sanitizeNumberString, sleep, subDigestOf, toHexString, urlClean }; |
import { ethers } from 'ethers'; | ||
declare global { | ||
interface BigInt { | ||
toJSON(): string; | ||
} | ||
} | ||
export declare const MAX_UINT_256: bigint; | ||
@@ -9,3 +14,1 @@ export declare const isBigNumberish: (value: any) => value is ethers.BigNumberish; | ||
export declare const formatEther: (value: bigint) => string; | ||
export declare const bigintReplacer: (key: string, value: any) => any; | ||
export declare const bigintReviver: (key: string, value: any) => any; |
{ | ||
"name": "@0xsequence/utils", | ||
"version": "0.0.0-20240829183049", | ||
"version": "0.0.0-20240903183150", | ||
"description": "utils sub-package for Sequence", | ||
@@ -5,0 +5,0 @@ "repository": "https://github.com/0xsequence/sequence.js/tree/master/packages/utils", |
import { Base64 } from 'js-base64' | ||
import { bigintReplacer, bigintReviver } from './bigint' | ||
@@ -9,3 +8,3 @@ export const base64Encode = (val: string): string => { | ||
export const base64EncodeObject = (obj: any): string => { | ||
return Base64.encode(JSON.stringify(obj, bigintReplacer), true) | ||
return Base64.encode(JSON.stringify(obj), true) | ||
} | ||
@@ -24,3 +23,3 @@ | ||
} | ||
return JSON.parse(Base64.decode(encodedObject), bigintReviver) as T | ||
return JSON.parse(Base64.decode(encodedObject)) as T | ||
} |
import { ethers } from 'ethers' | ||
// Monkey patch toJSON on BigInt to return a string | ||
declare global { | ||
interface BigInt { | ||
toJSON(): string | ||
} | ||
} | ||
BigInt.prototype.toJSON = function () { | ||
return this.toString() | ||
} | ||
export const MAX_UINT_256 = BigInt('0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff') | ||
@@ -85,24 +97,1 @@ | ||
export const formatEther = (value: bigint): string => formatUnits(value, 18) | ||
// JSON.stringify doesn't handle BigInts, so we need to replace them with objects | ||
export const bigintReplacer = (key: string, value: any): any => { | ||
if (typeof value === 'bigint') { | ||
return { $bigint: value.toString() } | ||
} | ||
return value | ||
} | ||
// JSON.parse will need to convert our serialized bigints back into BigInt | ||
export const bigintReviver = (key: string, value: any): any => { | ||
if (value !== null && typeof value === 'object' && '$bigint' in value && typeof value.$bigint === 'string') { | ||
return BigInt(value.$bigint) | ||
} | ||
// BigNumber compatibility with older versions of sequence.js with ethers v5 | ||
if (value !== null && typeof value === 'object' && value.type === 'BigNumber' && ethers.isHexString(value.hex)) { | ||
return BigInt(value.hex) | ||
} | ||
return value | ||
} |
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
109707
2865