@xylabs/hex 3.6.5 → 3.6.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address.js'\nexport * from './hash.js'\nexport * from './hex/index.js'\n","export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACfO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACVO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACG3B,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,MAAI,QAAQ,cAAc,UAAa,oBAAoB,cAAc,QAAQ,SAAS,EAAG,QAAO;AAGpG,SAAO,QAAQ,SAAS,mBAAmB,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;AAC9E;;;ACXO,IAAM,mBAAmB,CAAC,OAAe,SAAoB,CAAC,MAAW;AAC9E,QAAM,EAAE,SAAS,OAAO,WAAW,EAAE,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F,QAAI,cAAkC;AAGtC,YAAQ,OAAO,OAAO;AAAA,MACpB,KAAK,UAAU;AACb,sBAAc,iBAAiB,OAAO,EAAE,QAAQ,MAAM,CAAC;AACvD;AAAA,MACF;AAAA,MACA,SAAS;AACP,eAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,MACrF;AAAA,IACF;AACA,WAAO,UAAU,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,4BAA4B,KAAK,GAAG;AAAA,EAC/G,SAAS,IAAI;AACX,UAAM,QAAQ;AACd,WAAO,YAAY,QAAW,QAAQ,MAAM,OAAO;AAAA,EACrD;AACF;;;AChCO,IAAM,gBAAiC,CAAC,IAAI,IAAI,KAAK,KAAK,KAAK,MAAM,MAAM,IAAI;AAE/E,IAAM,kBAAkB,CAAC,UAA2C;AACzE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,KAAsB;AACnF;AAGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAGtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address.js'\nexport * from './hash.js'\nexport * from './hex/index.js'\n","export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,U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;AC/BO,IAAM,gBAAiC,CAAC,IAAI,IAAI,KAAK,KAAK,KAAK,MAAM,MAAM,IAAI;AAE/E,IAAM,kBAAkB,CAAC,UAA2C;AACzE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,KAAsB;AACnF;AAGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACfO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACVO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACG3B,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SA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c,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
1
+ {"version":3,"sources":["../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,m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,MAAM,OAAO;AAAA,EACrD;AACF;;;AC/BO,IAAM,gBAAiC,CAAC,IAAI,IAAI,KAAK,KAAK,KAAK,MAAM,MAAM,IAAI;AAE/E,IAAM,kBAAkB,CAAC,UAA2C;AACzE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,KAAsB;AACnF;AAGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/index.ts","../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address.js'\nexport * from './hash.js'\nexport * from './hex/index.js'\n","export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACfO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OA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,QAAyC;AAC9E,MAAI,cAAkC;AAGtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address.js'\nexport * from './hash.js'\nexport * from './hex/index.js'\n","export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACfO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACVO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACG3B,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,MAAI,QAAQ,cAAc,UAAa,oBAAoB,cAAc,QAAQ,SAAS,EAAG,QAAO;AAGpG,SAAO,QAAQ,SAAS,mBAAmB,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK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/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAA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,CAAC,IAAI,IAAI,KAAK,KAAK,KAAK,MAAM,MAAM,IAAI;AAE/E,IAAM,kBAAkB,CAAC,UAA2C;AACzE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,KAAsB;AACnF;AAGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAGtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
1
+ {"version":3,"sources":["../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACfO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACVO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACG3B,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,QAAM,kBAAkB,QAAQ,SAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,MAAI,QAAQ,cAAc,UAAa,oBAAoB,cAAc,QAAQ,SAAS,EAAG,QAAO;AAGpG,SAAO,QAAQ,SAAS,mBAAmB,KA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ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address.js'\nexport * from './hash.js'\nexport * from './hex/index.js'\n","export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";;;;;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,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,MACrF;AAAA,IACF;AACA,WAAO,UAAU,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,4BAA4B,KAAK,GAAG;AAAA,EAC/G,SAAS,IAAI;AACX,UAAM,QAAQ;AACd,WAAO,YAAY,QAAW,QAAQ,MAAM,OAAO;AAAA,EACrD;AACF;;;AChCO,IAAM,gBAAiC,CAAC,IAAI,IAAI,KAAK,KAAK,KAAK,MAAM,MAAM,IAAI;AAE/E,IAAM,kBAAkB,CAAC,UAA2C;AACzE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,KAAsB;AACnF;AAGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAGtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
1
+ {"version":3,"sources":["../../src/index.ts","../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export * from './address.js'\nexport * from './hash.js'\nexport * from './hex/index.js'\n","export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;;;ACIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF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AGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
@@ -1 +1 @@
1
- {"version":3,"sources":["../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n // eslint-disable-next-line sonarjs/no-small-switch\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,OAAO,iBAAiB,YAAY;AAAA,IACvE;AAAA,EACF;AAEA,SAAO;AACT;;;ACfO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,QAAM,UAAU,SAAS;AACzB,MAAI,UAAU,WAAW,EAAG,OAAM,IAAI,MAAM,qCAAqC;AACjF,SAAO;AACT;AAGO,IAAM,gBAAgB,CAAC,UAA0B;AACtD,SAAO,SAAS;AAClB;;;ACVO,IAAM,WAAW;AACjB,IAAM,qBAAqB;;;ACG3B,IAAM,QAAQ,CAAC,OAAgB,WAAqC;AAEzE,MAAI,OAAO,UAAU,SAAU,QAAO;AAEtC,QAAM,mBAAkB,iCAAQ,UAAS,MAAM,SAAS,IAAI,MAAM;AAGlE,OAAI,iCAAQ,eAAc,UAAa,oBAAoB,cAAc,iCAAQ,SAAS,EAAG,QAAO;AAGpG,UAAO,iCAAQ,UAAS,mBAAmB,KAAK,KAAK,IAAI,SAAS,KAAK,KAAK;AAC9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5C,SAAO,MAAM,OAAO,EAAE,WAAW,OAAO,CAAC;AAC3C;AAIO,SAAS,UAAU,OAAgB,QAA4C;AACpF,MAAI;AACF,QAAI,cAAkC;AAGtC,YAAQ,OAAO,OAAO;AAAA,MACpB,KAAK,UAAU;AACb,sBAAc,iBAAiB,OAAO,EAAE,QAAQ,MAAM,CAAC;AACvD;AAAA,MACF;AAAA,MACA,SAAS;AACP,eAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,MACrF;AAAA,IACF;AACA,WAAO,UAAU,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,4BAA4B,KAAK,GAAG;AAAA,EAC/G,SAAS,IAAI;AACX,UAAM,QAAQ;AACd,WAAO,YAAY,QAAW,QAAQ,MAAM,OAAO;AAAA,EACrD;AACF;;;AChCO,IAAM,gBAAiC,CAAC,IAAI,IAAI,KAAK,KAAK,KAAK,MAAM,MAAM,IAAI;AAE/E,IAAM,kBAAkB,CAAC,UAA2C;AACzE,SAAO,OAAO,UAAU,YAAY,cAAc,SAAS,KAAsB;AACnF;AAGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAGtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
1
+ {"version":3,"sources":["../../src/assert.ts","../../src/hex/nibble.ts","../../src/hex/regex.ts","../../src/hex/is.ts","../../src/hex/from/fromHexString.ts","../../src/hex/from/fromArrayBuffer.ts","../../src/hex/from/fromBigInt.ts","../../src/hex/from/fromNumber.ts","../../src/hex/from/from.ts","../../src/hex/as.ts","../../src/hex/isHexZero.ts","../../src/hex/legacy.ts","../../src/hex/to.ts","../../src/address.ts","../../src/hash.ts"],"sourcesContent":["export type AssertCallback = (value: unknown, message: string) => string | boolean\n\nexport type AssertConfig = string | AssertCallback | boolean\n\nexport const assertError = (value: unknown, assert: AssertConfig | undefined, defaultMessage: string) => {\n if (assert) {\n const assertString =\n typeof assert === 'string' ? assert\n : typeof assert === 'boolean' ? defaultMessage\n : assert(value, defaultMessage)\n if (assertString) {\n throw new Error(assertString === true ? defaultMessage : assertString)\n }\n }\n // eslint-disable-next-line unicorn/no-useless-undefined\n return undefined\n}\n","//determine the number of nibbles for a given number of bits\nexport const bitsToNibbles = (value: number): number => {\n const nibbles = value >> 2\n if (value !== nibbles << 2) throw new Error('Bits for nibbles must multiple of 4')\n return nibbles\n}\n\n//determine the number of nibbles for a given number of bits\nexport const nibblesToBits = (value: number): number => {\n return value << 2\n}\n","export const hexRegex = /^[\\da-f]+$/i\nexport const hexRegexWithPrefix = /0x[\\da-f]+$/i\n","import { Hex, HexConfig } from './model.js'\nimport { bitsToNibbles } from './nibble.js'\nimport { hexRegex, hexRegexWithPrefix } from './regex.js'\n\nexport const isHex = (value: unknown, config?: HexConfig): value is Hex => {\n //Is it a string?\n if (typeof value !== 'string') return false\n\n const valueCharLength = config?.prefix ? value.length - 2 : value.length\n\n //If a bitLength specified, does it conform?\n if (config?.bitLength !== undefined && valueCharLength !== bitsToNibbles(config?.bitLength)) return false\n\n //Does it only has hex values?\n return config?.prefix ? hexRegexWithPrefix.test(value) : hexRegex.test(value)\n}\n","import { isHex } from '../is.js'\nimport { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\n\nexport const hexFromHexString = (value: string, config: HexConfig = {}): Hex => {\n const { prefix = false, byteSize = 8 } = config\n const nibbleBoundary = bitsToNibbles(byteSize)\n const unPadded = (value.startsWith('0x') ? value.slice(2) : value).toLowerCase()\n if (isHex(unPadded)) {\n const padded = unPadded.padStart(unPadded.length + (unPadded.length % nibbleBoundary), '0')\n return (prefix ? `0x${padded}` : padded).toLowerCase() as Hex\n } else {\n throw new Error('Received string is not a value hex')\n }\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert an ArrayBuffer to a hex string */\nexport const hexFromArrayBuffer = (\n /** The buffer to be converted */\n buffer: ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n const unPadded = [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n return hexFromHexString(unPadded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { bitsToNibbles } from '../nibble.js'\nimport { hexFromHexString } from './fromHexString.js'\n\n/** Convert a bigint to a hex string */\nexport const hexFromBigInt = (\n /** The bigint to be converted */\n value: bigint,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n): Hex => {\n const { bitLength } = config\n const unPadded = value.toString(16)\n const padded = bitLength === undefined ? unPadded : unPadded.padStart(bitsToNibbles(bitLength), '0')\n return hexFromHexString(padded, config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromBigInt } from './fromBigInt.js'\n\nexport const hexFromNumber = (value: number, config?: HexConfig): Hex => {\n return hexFromBigInt(BigInt(value), config)\n}\n","import { Hex, HexConfig } from '../model.js'\nimport { hexFromArrayBuffer } from './fromArrayBuffer.js'\nimport { hexFromBigInt } from './fromBigInt.js'\nimport { hexFromHexString } from './fromHexString.js'\nimport { hexFromNumber } from './fromNumber.js'\n\n/** Takes unknown value and tries our best to convert it to a hex string */\nexport const hexFrom = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config?: HexConfig,\n): Hex => {\n switch (typeof value) {\n case 'string': {\n return hexFromHexString(value, config)\n }\n case 'bigint': {\n return hexFromBigInt(value, config)\n }\n case 'number': {\n return hexFromNumber(value, config)\n }\n case 'object': {\n return hexFromArrayBuffer(value, config)\n }\n default: {\n throw new Error(`Invalid type: ${typeof value}`)\n }\n }\n}\n","import { AssertConfig, assertError } from '../assert.js'\nimport { hexFromHexString } from './from/index.js'\nimport { isHex } from './is.js'\nimport { Hex } from './model.js'\n\nexport function asHex(value: unknown): Hex | undefined\nexport function asHex(value: unknown, assert: AssertConfig): Hex\nexport function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assertError(value, assert, `Unsupported type [${typeof value}]`)\n }\n }\n\n return isHex(stringValue) ? stringValue : assertError(value, assert, `Value is not Hex [${value}]`)\n}\n","import { hexFromHexString } from './from/index.js'\n\nexport const isHexZero = (value?: string) => {\n return value ? BigInt(hexFromHexString(value, { prefix: true })) === 0n : undefined\n}\n","export const toHexLegacy = (buffer: ArrayBuffer) => {\n return [...new Uint8Array(buffer)].map((x) => x.toString(16).padStart(2, '0')).join('')\n}\n","import { hexFrom } from './from/index.js'\nimport { HexConfig } from './model.js'\n\n/** takes any value and tries our best to convert it to a hex string */\nexport const toHex = (\n /** Supported types are string, number, bigint, and ArrayBuffer */\n value: string | number | bigint | ArrayBuffer,\n /** Configuration of output format and validation */\n config: HexConfig = {},\n) => {\n const { prefix = false } = config\n return hexFrom(value, { prefix, ...config })\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, HexConfig, hexFrom, hexFromHexString, isHex } from './hex/index.js'\n\nexport type Address = Exclude<Hex, 'reserved-address-value'>\n\nexport const toAddress = (value: string | number | bigint | ArrayBuffer, config: HexConfig = {}) => {\n const { bitLength = 160, prefix = false } = config\n return hexFrom(value, { bitLength, prefix, ...config })\n}\n\nexport const isAddress = (value: unknown, config: HexConfig = {}): value is Address => {\n const { bitLength = 160, prefix = false } = config\n return isHex(value, { bitLength, prefix })\n}\n\nexport function asAddress(value: unknown): Address | undefined\nexport function asAddress(value: unknown, assert: AssertConfig): Address\nexport function asAddress(value: unknown, assert?: AssertConfig): Address | undefined {\n try {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value, { prefix: false })\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isAddress(stringValue) ? stringValue : assertError(value, assert, `Value is not an Address [${value}]`)\n } catch (ex) {\n const error = ex as Error\n return assertError(undefined, assert, error.message)\n }\n}\n","import { AssertConfig, assertError } from './assert.js'\nimport { Hex, hexFromHexString, isHex } from './hex/index.js'\n\nexport type HashBitLength = 32 | 64 | 128 | 256 | 512 | 1024 | 2048 | 4096\nexport const HashBitLength: HashBitLength[] = [32, 64, 128, 256, 512, 1024, 2048, 4096]\n\nexport const isHashBitLength = (value: unknown): value is HashBitLength => {\n return typeof value === 'number' && HashBitLength.includes(value as HashBitLength)\n}\n\nexport type Hash = Exclude<Hex, 'reserved-hash-value'>\nexport const isHash = (value: unknown, bitLength: HashBitLength = 256): value is Hash => {\n return isHex(value, { bitLength })\n}\n\nexport function asHash(value: unknown): Hash | undefined\nexport function asHash(value: unknown, assert: AssertConfig): Hash\nexport function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {\n let stringValue: string | undefined = undefined\n\n switch (typeof value) {\n case 'string': {\n stringValue = hexFromHexString(value)\n break\n }\n default: {\n return assert ? assertError(value, assert, `Unsupported type [${typeof value}]`) : undefined\n }\n }\n return isHash(stringValue) ? stringValue : assertError(value, assert, `Value is not a Hash [${value}]`)\n}\n"],"mappings":";AAIO,IAAM,cAAc,CAAC,OAAgB,QAAkC,mBAA2B;AACvG,MAAI,QAAQ;AACV,UAAM,eACJ,OAAO,WAAW,WAAW,SAC3B,OAAO,WAAW,YAAY,iBAC9B,OAAO,OAAO,cAAc;AAChC,QAAI,cAAc;AAChB,YAAM,IAAI,MAAM,iBAAiB,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AO,UAAU,YAAY,cAAc,SAAS,KAAsB;AACnF;AAGO,IAAM,SAAS,CAAC,OAAgB,YAA2B,QAAuB;AACvF,SAAO,MAAM,OAAO,EAAE,UAAU,CAAC;AACnC;AAIO,SAAS,OAAO,OAAgB,QAAyC;AAC9E,MAAI,cAAkC;AAEtC,UAAQ,OAAO,OAAO;AAAA,IACpB,KAAK,UAAU;AACb,oBAAc,iBAAiB,KAAK;AACpC;AAAA,IACF;AAAA,IACA,SAAS;AACP,aAAO,SAAS,YAAY,OAAO,QAAQ,qBAAqB,OAAO,KAAK,GAAG,IAAI;AAAA,IACrF;AAAA,EACF;AACA,SAAO,OAAO,WAAW,IAAI,cAAc,YAAY,OAAO,QAAQ,wBAAwB,KAAK,GAAG;AACxG;","names":[]}
package/package.json CHANGED
@@ -39,8 +39,8 @@
39
39
  "esm"
40
40
  ],
41
41
  "devDependencies": {
42
- "@xylabs/ts-scripts-yarn3": "^3.12.4",
43
- "@xylabs/tsconfig": "^3.12.4",
42
+ "@xylabs/ts-scripts-yarn3": "^3.14.1",
43
+ "@xylabs/tsconfig": "^3.14.1",
44
44
  "typescript": "^5.5.4"
45
45
  },
46
46
  "engines": {
@@ -54,6 +54,6 @@
54
54
  "url": "https://github.com/xylabs/sdk-js.git"
55
55
  },
56
56
  "sideEffects": false,
57
- "version": "3.6.5",
57
+ "version": "3.6.6",
58
58
  "type": "module"
59
59
  }
package/src/address.ts CHANGED
@@ -19,7 +19,6 @@ export function asAddress(value: unknown, assert?: AssertConfig): Address | unde
19
19
  try {
20
20
  let stringValue: string | undefined = undefined
21
21
 
22
- // eslint-disable-next-line sonarjs/no-small-switch
23
22
  switch (typeof value) {
24
23
  case 'string': {
25
24
  stringValue = hexFromHexString(value, { prefix: false })
package/src/hash.ts CHANGED
@@ -18,7 +18,6 @@ export function asHash(value: unknown, assert: AssertConfig): Hash
18
18
  export function asHash(value: unknown, assert?: AssertConfig): Hash | undefined {
19
19
  let stringValue: string | undefined = undefined
20
20
 
21
- // eslint-disable-next-line sonarjs/no-small-switch
22
21
  switch (typeof value) {
23
22
  case 'string': {
24
23
  stringValue = hexFromHexString(value)
package/src/hex/as.ts CHANGED
@@ -8,7 +8,6 @@ export function asHex(value: unknown, assert: AssertConfig): Hex
8
8
  export function asHex(value: unknown, assert?: AssertConfig): Hex | undefined {
9
9
  let stringValue: string | undefined = undefined
10
10
 
11
- // eslint-disable-next-line sonarjs/no-small-switch
12
11
  switch (typeof value) {
13
12
  case 'string': {
14
13
  stringValue = hexFromHexString(value)