@mailchain/encoding
Advanced tools
| declare function encodeAscii(input: Uint8Array): string; | ||
| declare function decodeAscii(input: string): Uint8Array; | ||
| declare function isAscii(str: string): boolean; | ||
| export { decodeAscii, encodeAscii, isAscii }; |
+10
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5IQZ2WS2js = require('./chunk-5IQZ2WS2.js'); | ||
| exports.decodeAscii = _chunk5IQZ2WS2js.decodeAscii; exports.encodeAscii = _chunk5IQZ2WS2js.encodeAscii; exports.isAscii = _chunk5IQZ2WS2js.isAscii; |
+10
| import { | ||
| decodeAscii, | ||
| encodeAscii, | ||
| isAscii | ||
| } from "./chunk-6F7N6SN5.mjs"; | ||
| export { | ||
| decodeAscii, | ||
| encodeAscii, | ||
| isAscii | ||
| }; |
| declare function decodeBase32(input: string): Uint8Array; | ||
| declare function encodeBase32(input: Uint8Array): string; | ||
| declare function isBase32(input: string): boolean; | ||
| export { decodeBase32, encodeBase32, isBase32 }; |
+10
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkAIY3EMBZjs = require('./chunk-AIY3EMBZ.js'); | ||
| exports.decodeBase32 = _chunkAIY3EMBZjs.decodeBase32; exports.encodeBase32 = _chunkAIY3EMBZjs.encodeBase32; exports.isBase32 = _chunkAIY3EMBZjs.isBase32; |
+10
| import { | ||
| decodeBase32, | ||
| encodeBase32, | ||
| isBase32 | ||
| } from "./chunk-VQTPFEEJ.mjs"; | ||
| export { | ||
| decodeBase32, | ||
| encodeBase32, | ||
| isBase32 | ||
| }; |
| declare function decodeBase58(input: string): Uint8Array; | ||
| declare function encodeBase58(input: Uint8Array): string; | ||
| declare function isBase58(input: string): boolean; | ||
| export { decodeBase58, encodeBase58, isBase58 }; |
+10
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkTOXDKCM7js = require('./chunk-TOXDKCM7.js'); | ||
| exports.decodeBase58 = _chunkTOXDKCM7js.decodeBase58; exports.encodeBase58 = _chunkTOXDKCM7js.encodeBase58; exports.isBase58 = _chunkTOXDKCM7js.isBase58; |
+10
| import { | ||
| decodeBase58, | ||
| encodeBase58, | ||
| isBase58 | ||
| } from "./chunk-SSJ5XBYN.mjs"; | ||
| export { | ||
| decodeBase58, | ||
| encodeBase58, | ||
| isBase58 | ||
| }; |
| declare function decodeBase58Check(input: string): Uint8Array; | ||
| declare function encodeBase58Check(input: Uint8Array): string; | ||
| export { decodeBase58Check, encodeBase58Check }; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkSRPF72BUjs = require('./chunk-SRPF72BU.js'); | ||
| require('./chunk-TOXDKCM7.js'); | ||
| exports.decodeBase58Check = _chunkSRPF72BUjs.decodeBase58Check; exports.encodeBase58Check = _chunkSRPF72BUjs.encodeBase58Check; |
| import { | ||
| decodeBase58Check, | ||
| encodeBase58Check | ||
| } from "./chunk-KSRU7YO7.mjs"; | ||
| import "./chunk-SSJ5XBYN.mjs"; | ||
| export { | ||
| decodeBase58Check, | ||
| encodeBase58Check | ||
| }; |
| declare function decodeBase64(input: string): Uint8Array; | ||
| declare function encodeBase64(input: Uint8Array): string; | ||
| declare function decodeBase64UrlSafe(input: string): Uint8Array; | ||
| declare function encodeBase64UrlSafe(input: Uint8Array): string; | ||
| export { decodeBase64, decodeBase64UrlSafe, encodeBase64, encodeBase64UrlSafe }; |
+12
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk2ZCYWED7js = require('./chunk-2ZCYWED7.js'); | ||
| exports.decodeBase64 = _chunk2ZCYWED7js.decodeBase64; exports.decodeBase64UrlSafe = _chunk2ZCYWED7js.decodeBase64UrlSafe; exports.encodeBase64 = _chunk2ZCYWED7js.encodeBase64; exports.encodeBase64UrlSafe = _chunk2ZCYWED7js.encodeBase64UrlSafe; |
+12
| import { | ||
| decodeBase64, | ||
| decodeBase64UrlSafe, | ||
| encodeBase64, | ||
| encodeBase64UrlSafe | ||
| } from "./chunk-IX5UPKFA.mjs"; | ||
| export { | ||
| decodeBase64, | ||
| decodeBase64UrlSafe, | ||
| encodeBase64, | ||
| encodeBase64UrlSafe | ||
| }; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkSV46MOJDjs = require('./chunk-SV46MOJD.js'); | ||
| var _chunkBUKFPQGEjs = require('./chunk-BUKFPQGE.js'); | ||
| var _chunkAIY3EMBZjs = require('./chunk-AIY3EMBZ.js'); | ||
| var _chunkTOXDKCM7js = require('./chunk-TOXDKCM7.js'); | ||
| var _chunk2ZCYWED7js = require('./chunk-2ZCYWED7.js'); | ||
| var _chunkJ7MIGZHMjs = require('./chunk-J7MIGZHM.js'); | ||
| // src/encoding.ts | ||
| var UnsupportedEncodingError = class extends Error { | ||
| constructor(encoding) { | ||
| super(`Encoding [${encoding}] not supported`); | ||
| } | ||
| }; | ||
| function decode(encoding, src) { | ||
| switch (encoding.toLowerCase()) { | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Base58: | ||
| return _chunkTOXDKCM7js.decodeBase58.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Hex: | ||
| return _chunkSV46MOJDjs.decodeHex.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Hex0xPrefix: | ||
| return _chunkSV46MOJDjs.decodeHexZeroX.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Utf8: | ||
| return _chunkBUKFPQGEjs.decodeUtf8.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Base32: | ||
| return _chunkAIY3EMBZjs.decodeBase32.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.HexAny: | ||
| return _chunkSV46MOJDjs.decodeHexAny.call(void 0, src); | ||
| default: | ||
| throw new UnsupportedEncodingError(encoding); | ||
| } | ||
| } | ||
| function encode(encoding, src) { | ||
| switch (encoding.toLowerCase()) { | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Base58: | ||
| return _chunkTOXDKCM7js.encodeBase58.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Hex: | ||
| return _chunkSV46MOJDjs.encodeHex.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Hex0xPrefix: | ||
| return _chunkSV46MOJDjs.encodeHexZeroX.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Base64: | ||
| return _chunk2ZCYWED7js.encodeBase64UrlSafe.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Utf8: | ||
| return _chunkBUKFPQGEjs.encodeUtf8.call(void 0, src); | ||
| case _chunkJ7MIGZHMjs.EncodingTypes.Base32: | ||
| return _chunkAIY3EMBZjs.encodeBase32.call(void 0, src); | ||
| default: | ||
| throw new UnsupportedEncodingError(encoding); | ||
| } | ||
| } | ||
| exports.decode = decode; exports.encode = encode; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/base64.ts | ||
| function decodeBase64(input) { | ||
| const output = Buffer.from(input, "base64"); | ||
| if (input.length > 0 && output.length === 0) { | ||
| throw new Error("could not decode input"); | ||
| } | ||
| return Uint8Array.from(output); | ||
| } | ||
| function encodeBase64(input) { | ||
| return Buffer.from(input).toString("base64"); | ||
| } | ||
| function decodeBase64UrlSafe(input) { | ||
| let encoded = input.replace("-", "+").replace("_", "/"); | ||
| while (encoded.length % 4) | ||
| encoded += "="; | ||
| const output = Buffer.from(encoded, "base64"); | ||
| if (input.length > 0 && output.length === 0) { | ||
| throw new Error("could not decode input"); | ||
| } | ||
| return Uint8Array.from(output); | ||
| } | ||
| function encodeBase64UrlSafe(input) { | ||
| return Buffer.from(input).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); | ||
| } | ||
| exports.decodeBase64 = decodeBase64; exports.encodeBase64 = encodeBase64; exports.decodeBase64UrlSafe = decodeBase64UrlSafe; exports.encodeBase64UrlSafe = encodeBase64UrlSafe; |
| // src/hex.ts | ||
| function encodeHexZeroX(input) { | ||
| return "0x" + encodeHex(input); | ||
| } | ||
| function decodeHexZeroX(input) { | ||
| if (input === "") { | ||
| throw new RangeError("empty hex string"); | ||
| } | ||
| if (!input.startsWith("0x")) { | ||
| throw new RangeError("must start with '0x'"); | ||
| } | ||
| return decodeHex(input.slice(2)); | ||
| } | ||
| function encodeHex(input) { | ||
| return Buffer.from(input).toString("hex"); | ||
| } | ||
| function decodeHex(input) { | ||
| const output = new Uint8Array(Buffer.from(input, "hex")); | ||
| if (output.length === 0 || input.length === 0) { | ||
| throw RangeError("invalid hex encoding"); | ||
| } | ||
| return output; | ||
| } | ||
| function isHex(input) { | ||
| return new RegExp("^[a-fA-F0-9]+$").test(input); | ||
| } | ||
| function isHexZeroX(input) { | ||
| return new RegExp("^0x[a-fA-F0-9]+$").test(input); | ||
| } | ||
| function isAnyHex(input) { | ||
| if (input.startsWith("0x")) { | ||
| input = input.substring(2); | ||
| } | ||
| return isHex(input); | ||
| } | ||
| function decodeHexAny(input) { | ||
| if (input.startsWith("0x")) { | ||
| input = input.substring(2); | ||
| } | ||
| return decodeHex(input); | ||
| } | ||
| export { | ||
| encodeHexZeroX, | ||
| decodeHexZeroX, | ||
| encodeHex, | ||
| decodeHex, | ||
| isHex, | ||
| isHexZeroX, | ||
| isAnyHex, | ||
| decodeHexAny | ||
| }; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/ascii.ts | ||
| function encodeAscii(input) { | ||
| return Buffer.from(input).toString("ascii"); | ||
| } | ||
| function decodeAscii(input) { | ||
| if (!isAscii(input)) | ||
| throw new Error("Input is not ASCII"); | ||
| return new Uint8Array(Buffer.from(input, "ascii")); | ||
| } | ||
| function isAscii(str) { | ||
| return /^[\x00-\x7F]+$/.test(str); | ||
| } | ||
| exports.encodeAscii = encodeAscii; exports.decodeAscii = decodeAscii; exports.isAscii = isAscii; |
| // src/ascii.ts | ||
| function encodeAscii(input) { | ||
| return Buffer.from(input).toString("ascii"); | ||
| } | ||
| function decodeAscii(input) { | ||
| if (!isAscii(input)) | ||
| throw new Error("Input is not ASCII"); | ||
| return new Uint8Array(Buffer.from(input, "ascii")); | ||
| } | ||
| function isAscii(str) { | ||
| return /^[\x00-\x7F]+$/.test(str); | ||
| } | ||
| export { | ||
| encodeAscii, | ||
| decodeAscii, | ||
| isAscii | ||
| }; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/base32.ts | ||
| var _base = require('@scure/base'); | ||
| var BASE32_ALPHABET = "abcdefghijklmnopqrstuvwxyz234567"; | ||
| var coder = _base.utils.chain( | ||
| // We define our own chain, the default base32 has padding | ||
| _base.utils.radix2(5), | ||
| _base.utils.alphabet(BASE32_ALPHABET), | ||
| { | ||
| decode: (input) => input.split(""), | ||
| encode: (input) => input.join("") | ||
| } | ||
| ); | ||
| function decodeBase32(input) { | ||
| return coder.decode(input); | ||
| } | ||
| function encodeBase32(input) { | ||
| return coder.encode(input); | ||
| } | ||
| function isBase32(input) { | ||
| for (let i = 0; i < input.length; i++) { | ||
| const char = input[i]; | ||
| if (BASE32_ALPHABET.indexOf(char.toLowerCase()) === -1) { | ||
| return false; | ||
| } | ||
| } | ||
| if (input.length % 8 !== 0) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| exports.decodeBase32 = decodeBase32; exports.encodeBase32 = encodeBase32; exports.isBase32 = isBase32; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/utf8.ts | ||
| function encodeUtf8(input) { | ||
| return Buffer.from(input).toString("utf-8"); | ||
| } | ||
| function decodeUtf8(input) { | ||
| return new Uint8Array(Buffer.from(input, "utf-8")); | ||
| } | ||
| exports.encodeUtf8 = encodeUtf8; exports.decodeUtf8 = decodeUtf8; |
| import { | ||
| decodeHex, | ||
| decodeHexAny, | ||
| decodeHexZeroX, | ||
| encodeHex, | ||
| encodeHexZeroX | ||
| } from "./chunk-2ZWIOYKP.mjs"; | ||
| import { | ||
| decodeUtf8, | ||
| encodeUtf8 | ||
| } from "./chunk-HSTTGBPL.mjs"; | ||
| import { | ||
| decodeBase32, | ||
| encodeBase32 | ||
| } from "./chunk-VQTPFEEJ.mjs"; | ||
| import { | ||
| decodeBase58, | ||
| encodeBase58 | ||
| } from "./chunk-SSJ5XBYN.mjs"; | ||
| import { | ||
| encodeBase64UrlSafe | ||
| } from "./chunk-IX5UPKFA.mjs"; | ||
| import { | ||
| EncodingTypes | ||
| } from "./chunk-VA3TULOQ.mjs"; | ||
| // src/encoding.ts | ||
| var UnsupportedEncodingError = class extends Error { | ||
| constructor(encoding) { | ||
| super(`Encoding [${encoding}] not supported`); | ||
| } | ||
| }; | ||
| function decode(encoding, src) { | ||
| switch (encoding.toLowerCase()) { | ||
| case EncodingTypes.Base58: | ||
| return decodeBase58(src); | ||
| case EncodingTypes.Hex: | ||
| return decodeHex(src); | ||
| case EncodingTypes.Hex0xPrefix: | ||
| return decodeHexZeroX(src); | ||
| case EncodingTypes.Utf8: | ||
| return decodeUtf8(src); | ||
| case EncodingTypes.Base32: | ||
| return decodeBase32(src); | ||
| case EncodingTypes.HexAny: | ||
| return decodeHexAny(src); | ||
| default: | ||
| throw new UnsupportedEncodingError(encoding); | ||
| } | ||
| } | ||
| function encode(encoding, src) { | ||
| switch (encoding.toLowerCase()) { | ||
| case EncodingTypes.Base58: | ||
| return encodeBase58(src); | ||
| case EncodingTypes.Hex: | ||
| return encodeHex(src); | ||
| case EncodingTypes.Hex0xPrefix: | ||
| return encodeHexZeroX(src); | ||
| case EncodingTypes.Base64: | ||
| return encodeBase64UrlSafe(src); | ||
| case EncodingTypes.Utf8: | ||
| return encodeUtf8(src); | ||
| case EncodingTypes.Base32: | ||
| return encodeBase32(src); | ||
| default: | ||
| throw new UnsupportedEncodingError(encoding); | ||
| } | ||
| } | ||
| export { | ||
| decode, | ||
| encode | ||
| }; |
| // src/utf8.ts | ||
| function encodeUtf8(input) { | ||
| return Buffer.from(input).toString("utf-8"); | ||
| } | ||
| function decodeUtf8(input) { | ||
| return new Uint8Array(Buffer.from(input, "utf-8")); | ||
| } | ||
| export { | ||
| encodeUtf8, | ||
| decodeUtf8 | ||
| }; |
| // src/base64.ts | ||
| function decodeBase64(input) { | ||
| const output = Buffer.from(input, "base64"); | ||
| if (input.length > 0 && output.length === 0) { | ||
| throw new Error("could not decode input"); | ||
| } | ||
| return Uint8Array.from(output); | ||
| } | ||
| function encodeBase64(input) { | ||
| return Buffer.from(input).toString("base64"); | ||
| } | ||
| function decodeBase64UrlSafe(input) { | ||
| let encoded = input.replace("-", "+").replace("_", "/"); | ||
| while (encoded.length % 4) | ||
| encoded += "="; | ||
| const output = Buffer.from(encoded, "base64"); | ||
| if (input.length > 0 && output.length === 0) { | ||
| throw new Error("could not decode input"); | ||
| } | ||
| return Uint8Array.from(output); | ||
| } | ||
| function encodeBase64UrlSafe(input) { | ||
| return Buffer.from(input).toString("base64").replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, ""); | ||
| } | ||
| export { | ||
| decodeBase64, | ||
| encodeBase64, | ||
| decodeBase64UrlSafe, | ||
| encodeBase64UrlSafe | ||
| }; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/consts.ts | ||
| var EncodingTypes = { | ||
| /** | ||
| * Plain hex encoding value. | ||
| */ | ||
| Hex: "hex/plain", | ||
| /** | ||
| * 0x prefixed hex encoding | ||
| */ | ||
| Hex0xPrefix: "hex/0x-prefix", | ||
| /** | ||
| * With or without 0x prefix | ||
| */ | ||
| HexAny: "hex/any", | ||
| Base32: "base32/plain", | ||
| Base58: "base58/plain", | ||
| Base64: "base64/plain", | ||
| Base62Url: "base64/url", | ||
| Base58SubstrateAddress: "base58/ss58-address", | ||
| Utf8: "text/utf-8" | ||
| }; | ||
| exports.EncodingTypes = EncodingTypes; |
| import { | ||
| decodeBase58, | ||
| encodeBase58 | ||
| } from "./chunk-SSJ5XBYN.mjs"; | ||
| // src/base58Check.ts | ||
| import { sha256 } from "@noble/hashes/sha256"; | ||
| function decodeBase58Check(input) { | ||
| const validatedPayload = validatePayload(decodeBase58(input)); | ||
| if (validatedPayload == null) | ||
| throw new Error("failed input checksum validation"); | ||
| return validatedPayload; | ||
| } | ||
| function encodeBase58Check(input) { | ||
| const checksum = calcChecksum(input).slice(0, 4); | ||
| return encodeBase58(Uint8Array.from([...input, ...checksum])); | ||
| } | ||
| function calcChecksum(payload) { | ||
| return sha256(sha256(payload)); | ||
| } | ||
| function validatePayload(payloadWithChecksum) { | ||
| const payload = payloadWithChecksum.slice(0, -4); | ||
| const payloadChecksum = payloadWithChecksum.slice(-4); | ||
| const checksum = calcChecksum(payload); | ||
| if (payloadChecksum[0] ^ checksum[0] | payloadChecksum[1] ^ checksum[1] | payloadChecksum[2] ^ checksum[2] | payloadChecksum[3] ^ checksum[3]) { | ||
| return null; | ||
| } | ||
| return payload; | ||
| } | ||
| export { | ||
| decodeBase58Check, | ||
| encodeBase58Check | ||
| }; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk2I6RESKUjs = require('./chunk-2I6RESKU.js'); | ||
| // src/ensure.ts | ||
| function ensureDecoded(value, encoding) { | ||
| if (typeof value === "string") { | ||
| return _chunk2I6RESKUjs.decode.call(void 0, encoding, value); | ||
| } | ||
| return value; | ||
| } | ||
| exports.ensureDecoded = ensureDecoded; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkTOXDKCM7js = require('./chunk-TOXDKCM7.js'); | ||
| // src/base58Check.ts | ||
| var _sha256 = require('@noble/hashes/sha256'); | ||
| function decodeBase58Check(input) { | ||
| const validatedPayload = validatePayload(_chunkTOXDKCM7js.decodeBase58.call(void 0, input)); | ||
| if (validatedPayload == null) | ||
| throw new Error("failed input checksum validation"); | ||
| return validatedPayload; | ||
| } | ||
| function encodeBase58Check(input) { | ||
| const checksum = calcChecksum(input).slice(0, 4); | ||
| return _chunkTOXDKCM7js.encodeBase58.call(void 0, Uint8Array.from([...input, ...checksum])); | ||
| } | ||
| function calcChecksum(payload) { | ||
| return _sha256.sha256.call(void 0, _sha256.sha256.call(void 0, payload)); | ||
| } | ||
| function validatePayload(payloadWithChecksum) { | ||
| const payload = payloadWithChecksum.slice(0, -4); | ||
| const payloadChecksum = payloadWithChecksum.slice(-4); | ||
| const checksum = calcChecksum(payload); | ||
| if (payloadChecksum[0] ^ checksum[0] | payloadChecksum[1] ^ checksum[1] | payloadChecksum[2] ^ checksum[2] | payloadChecksum[3] ^ checksum[3]) { | ||
| return null; | ||
| } | ||
| return payload; | ||
| } | ||
| exports.decodeBase58Check = decodeBase58Check; exports.encodeBase58Check = encodeBase58Check; |
| // src/base58.ts | ||
| import { base58 } from "@scure/base"; | ||
| function decodeBase58(input) { | ||
| return base58.decode(input); | ||
| } | ||
| function encodeBase58(input) { | ||
| return base58.encode(input); | ||
| } | ||
| function isBase58(input) { | ||
| return /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(input); | ||
| } | ||
| export { | ||
| decodeBase58, | ||
| encodeBase58, | ||
| isBase58 | ||
| }; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/hex.ts | ||
| function encodeHexZeroX(input) { | ||
| return "0x" + encodeHex(input); | ||
| } | ||
| function decodeHexZeroX(input) { | ||
| if (input === "") { | ||
| throw new RangeError("empty hex string"); | ||
| } | ||
| if (!input.startsWith("0x")) { | ||
| throw new RangeError("must start with '0x'"); | ||
| } | ||
| return decodeHex(input.slice(2)); | ||
| } | ||
| function encodeHex(input) { | ||
| return Buffer.from(input).toString("hex"); | ||
| } | ||
| function decodeHex(input) { | ||
| const output = new Uint8Array(Buffer.from(input, "hex")); | ||
| if (output.length === 0 || input.length === 0) { | ||
| throw RangeError("invalid hex encoding"); | ||
| } | ||
| return output; | ||
| } | ||
| function isHex(input) { | ||
| return new RegExp("^[a-fA-F0-9]+$").test(input); | ||
| } | ||
| function isHexZeroX(input) { | ||
| return new RegExp("^0x[a-fA-F0-9]+$").test(input); | ||
| } | ||
| function isAnyHex(input) { | ||
| if (input.startsWith("0x")) { | ||
| input = input.substring(2); | ||
| } | ||
| return isHex(input); | ||
| } | ||
| function decodeHexAny(input) { | ||
| if (input.startsWith("0x")) { | ||
| input = input.substring(2); | ||
| } | ||
| return decodeHex(input); | ||
| } | ||
| exports.encodeHexZeroX = encodeHexZeroX; exports.decodeHexZeroX = decodeHexZeroX; exports.encodeHex = encodeHex; exports.decodeHex = decodeHex; exports.isHex = isHex; exports.isHexZeroX = isHexZeroX; exports.isAnyHex = isAnyHex; exports.decodeHexAny = decodeHexAny; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/base58.ts | ||
| var _base = require('@scure/base'); | ||
| function decodeBase58(input) { | ||
| return _base.base58.decode(input); | ||
| } | ||
| function encodeBase58(input) { | ||
| return _base.base58.encode(input); | ||
| } | ||
| function isBase58(input) { | ||
| return /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(input); | ||
| } | ||
| exports.decodeBase58 = decodeBase58; exports.encodeBase58 = encodeBase58; exports.isBase58 = isBase58; |
| // src/consts.ts | ||
| var EncodingTypes = { | ||
| /** | ||
| * Plain hex encoding value. | ||
| */ | ||
| Hex: "hex/plain", | ||
| /** | ||
| * 0x prefixed hex encoding | ||
| */ | ||
| Hex0xPrefix: "hex/0x-prefix", | ||
| /** | ||
| * With or without 0x prefix | ||
| */ | ||
| HexAny: "hex/any", | ||
| Base32: "base32/plain", | ||
| Base58: "base58/plain", | ||
| Base64: "base64/plain", | ||
| Base62Url: "base64/url", | ||
| Base58SubstrateAddress: "base58/ss58-address", | ||
| Utf8: "text/utf-8" | ||
| }; | ||
| export { | ||
| EncodingTypes | ||
| }; |
| // src/base32.ts | ||
| import { utils } from "@scure/base"; | ||
| var BASE32_ALPHABET = "abcdefghijklmnopqrstuvwxyz234567"; | ||
| var coder = utils.chain( | ||
| // We define our own chain, the default base32 has padding | ||
| utils.radix2(5), | ||
| utils.alphabet(BASE32_ALPHABET), | ||
| { | ||
| decode: (input) => input.split(""), | ||
| encode: (input) => input.join("") | ||
| } | ||
| ); | ||
| function decodeBase32(input) { | ||
| return coder.decode(input); | ||
| } | ||
| function encodeBase32(input) { | ||
| return coder.encode(input); | ||
| } | ||
| function isBase32(input) { | ||
| for (let i = 0; i < input.length; i++) { | ||
| const char = input[i]; | ||
| if (BASE32_ALPHABET.indexOf(char.toLowerCase()) === -1) { | ||
| return false; | ||
| } | ||
| } | ||
| if (input.length % 8 !== 0) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| export { | ||
| decodeBase32, | ||
| encodeBase32, | ||
| isBase32 | ||
| }; |
| import { | ||
| decode | ||
| } from "./chunk-HIIB3CHB.mjs"; | ||
| // src/ensure.ts | ||
| function ensureDecoded(value, encoding) { | ||
| if (typeof value === "string") { | ||
| return decode(encoding, value); | ||
| } | ||
| return value; | ||
| } | ||
| export { | ||
| ensureDecoded | ||
| }; |
+23
| declare const EncodingTypes: { | ||
| /** | ||
| * Plain hex encoding value. | ||
| */ | ||
| readonly Hex: "hex/plain"; | ||
| /** | ||
| * 0x prefixed hex encoding | ||
| */ | ||
| readonly Hex0xPrefix: "hex/0x-prefix"; | ||
| /** | ||
| * With or without 0x prefix | ||
| */ | ||
| readonly HexAny: "hex/any"; | ||
| readonly Base32: "base32/plain"; | ||
| readonly Base58: "base58/plain"; | ||
| readonly Base64: "base64/plain"; | ||
| readonly Base62Url: "base64/url"; | ||
| readonly Base58SubstrateAddress: "base58/ss58-address"; | ||
| readonly Utf8: "text/utf-8"; | ||
| }; | ||
| type EncodingType = typeof EncodingTypes[keyof typeof EncodingTypes]; | ||
| export { EncodingType, EncodingTypes }; |
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkJ7MIGZHMjs = require('./chunk-J7MIGZHM.js'); | ||
| exports.EncodingTypes = _chunkJ7MIGZHMjs.EncodingTypes; |
| import { | ||
| EncodingTypes | ||
| } from "./chunk-VA3TULOQ.mjs"; | ||
| export { | ||
| EncodingTypes | ||
| }; |
| import { EncodingType } from './consts.js'; | ||
| /** | ||
| * Decode returns the bytes represented by the decoded string src. | ||
| * Decode uses the decode method mapped to kind parameter. | ||
| * | ||
| * If the input is kind is unknown or the input is malformed for the decode method it returns an error. | ||
| * @param encoding | ||
| * @param src | ||
| * @returns | ||
| */ | ||
| declare function decode(encoding: EncodingType, src: string): Uint8Array; | ||
| /** | ||
| * Encode returns the bytes encoded as requested by the encoding parameter. | ||
| * @param encoding | ||
| * @param src | ||
| * @returns encoded value | ||
| */ | ||
| declare function encode(encoding: EncodingType, src: Uint8Array): string; | ||
| export { decode, encode }; |
+14
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk2I6RESKUjs = require('./chunk-2I6RESKU.js'); | ||
| require('./chunk-SV46MOJD.js'); | ||
| require('./chunk-BUKFPQGE.js'); | ||
| require('./chunk-AIY3EMBZ.js'); | ||
| require('./chunk-TOXDKCM7.js'); | ||
| require('./chunk-2ZCYWED7.js'); | ||
| require('./chunk-J7MIGZHM.js'); | ||
| exports.decode = _chunk2I6RESKUjs.decode; exports.encode = _chunk2I6RESKUjs.encode; |
+14
| import { | ||
| decode, | ||
| encode | ||
| } from "./chunk-HIIB3CHB.mjs"; | ||
| import "./chunk-2ZWIOYKP.mjs"; | ||
| import "./chunk-HSTTGBPL.mjs"; | ||
| import "./chunk-VQTPFEEJ.mjs"; | ||
| import "./chunk-SSJ5XBYN.mjs"; | ||
| import "./chunk-IX5UPKFA.mjs"; | ||
| import "./chunk-VA3TULOQ.mjs"; | ||
| export { | ||
| decode, | ||
| encode | ||
| }; |
| import { EncodingType } from './consts.js'; | ||
| declare function ensureDecoded(value: Uint8Array | string | Buffer, encoding: EncodingType): Uint8Array | Buffer; | ||
| export { ensureDecoded }; |
+13
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkM3NOOX65js = require('./chunk-M3NOOX65.js'); | ||
| require('./chunk-2I6RESKU.js'); | ||
| require('./chunk-SV46MOJD.js'); | ||
| require('./chunk-BUKFPQGE.js'); | ||
| require('./chunk-AIY3EMBZ.js'); | ||
| require('./chunk-TOXDKCM7.js'); | ||
| require('./chunk-2ZCYWED7.js'); | ||
| require('./chunk-J7MIGZHM.js'); | ||
| exports.ensureDecoded = _chunkM3NOOX65js.ensureDecoded; |
+13
| import { | ||
| ensureDecoded | ||
| } from "./chunk-YT72IRPH.mjs"; | ||
| import "./chunk-HIIB3CHB.mjs"; | ||
| import "./chunk-2ZWIOYKP.mjs"; | ||
| import "./chunk-HSTTGBPL.mjs"; | ||
| import "./chunk-VQTPFEEJ.mjs"; | ||
| import "./chunk-SSJ5XBYN.mjs"; | ||
| import "./chunk-IX5UPKFA.mjs"; | ||
| import "./chunk-VA3TULOQ.mjs"; | ||
| export { | ||
| ensureDecoded | ||
| }; |
+10
| declare function encodeHexZeroX(input: Uint8Array): string; | ||
| declare function decodeHexZeroX(input: string): Uint8Array; | ||
| declare function encodeHex(input: Uint8Array): string; | ||
| declare function decodeHex(input: string): Uint8Array; | ||
| declare function isHex(input: string): boolean; | ||
| declare function isHexZeroX(input: string): boolean; | ||
| declare function isAnyHex(input: string): boolean; | ||
| declare function decodeHexAny(input: string): Uint8Array; | ||
| export { decodeHex, decodeHexAny, decodeHexZeroX, encodeHex, encodeHexZeroX, isAnyHex, isHex, isHexZeroX }; |
+20
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkSV46MOJDjs = require('./chunk-SV46MOJD.js'); | ||
| exports.decodeHex = _chunkSV46MOJDjs.decodeHex; exports.decodeHexAny = _chunkSV46MOJDjs.decodeHexAny; exports.decodeHexZeroX = _chunkSV46MOJDjs.decodeHexZeroX; exports.encodeHex = _chunkSV46MOJDjs.encodeHex; exports.encodeHexZeroX = _chunkSV46MOJDjs.encodeHexZeroX; exports.isAnyHex = _chunkSV46MOJDjs.isAnyHex; exports.isHex = _chunkSV46MOJDjs.isHex; exports.isHexZeroX = _chunkSV46MOJDjs.isHexZeroX; |
+20
| import { | ||
| decodeHex, | ||
| decodeHexAny, | ||
| decodeHexZeroX, | ||
| encodeHex, | ||
| encodeHexZeroX, | ||
| isAnyHex, | ||
| isHex, | ||
| isHexZeroX | ||
| } from "./chunk-2ZWIOYKP.mjs"; | ||
| export { | ||
| decodeHex, | ||
| decodeHexAny, | ||
| decodeHexZeroX, | ||
| encodeHex, | ||
| encodeHexZeroX, | ||
| isAnyHex, | ||
| isHex, | ||
| isHexZeroX | ||
| }; |
+10
| export { EncodingType, EncodingTypes } from './consts.js'; | ||
| export { ensureDecoded } from './ensure.js'; | ||
| export { decode, encode } from './encoding.js'; | ||
| export { decodeHex, decodeHexAny, decodeHexZeroX, encodeHex, encodeHexZeroX, isAnyHex, isHex, isHexZeroX } from './hex.js'; | ||
| export { decodeBase32, encodeBase32, isBase32 } from './base32.js'; | ||
| export { decodeBase58, encodeBase58, isBase58 } from './base58.js'; | ||
| export { decodeBase58Check, encodeBase58Check } from './base58Check.js'; | ||
| export { decodeBase64, decodeBase64UrlSafe, encodeBase64, encodeBase64UrlSafe } from './base64.js'; | ||
| export { decodeUtf8, encodeUtf8 } from './utf8.js'; | ||
| export { decodeAscii, encodeAscii, isAscii } from './ascii.js'; |
+80
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunk5IQZ2WS2js = require('./chunk-5IQZ2WS2.js'); | ||
| var _chunkSRPF72BUjs = require('./chunk-SRPF72BU.js'); | ||
| var _chunkM3NOOX65js = require('./chunk-M3NOOX65.js'); | ||
| var _chunk2I6RESKUjs = require('./chunk-2I6RESKU.js'); | ||
| var _chunkSV46MOJDjs = require('./chunk-SV46MOJD.js'); | ||
| var _chunkBUKFPQGEjs = require('./chunk-BUKFPQGE.js'); | ||
| var _chunkAIY3EMBZjs = require('./chunk-AIY3EMBZ.js'); | ||
| var _chunkTOXDKCM7js = require('./chunk-TOXDKCM7.js'); | ||
| var _chunk2ZCYWED7js = require('./chunk-2ZCYWED7.js'); | ||
| var _chunkJ7MIGZHMjs = require('./chunk-J7MIGZHM.js'); | ||
| exports.EncodingTypes = _chunkJ7MIGZHMjs.EncodingTypes; exports.decode = _chunk2I6RESKUjs.decode; exports.decodeAscii = _chunk5IQZ2WS2js.decodeAscii; exports.decodeBase32 = _chunkAIY3EMBZjs.decodeBase32; exports.decodeBase58 = _chunkTOXDKCM7js.decodeBase58; exports.decodeBase58Check = _chunkSRPF72BUjs.decodeBase58Check; exports.decodeBase64 = _chunk2ZCYWED7js.decodeBase64; exports.decodeBase64UrlSafe = _chunk2ZCYWED7js.decodeBase64UrlSafe; exports.decodeHex = _chunkSV46MOJDjs.decodeHex; exports.decodeHexAny = _chunkSV46MOJDjs.decodeHexAny; exports.decodeHexZeroX = _chunkSV46MOJDjs.decodeHexZeroX; exports.decodeUtf8 = _chunkBUKFPQGEjs.decodeUtf8; exports.encode = _chunk2I6RESKUjs.encode; exports.encodeAscii = _chunk5IQZ2WS2js.encodeAscii; exports.encodeBase32 = _chunkAIY3EMBZjs.encodeBase32; exports.encodeBase58 = _chunkTOXDKCM7js.encodeBase58; exports.encodeBase58Check = _chunkSRPF72BUjs.encodeBase58Check; exports.encodeBase64 = _chunk2ZCYWED7js.encodeBase64; exports.encodeBase64UrlSafe = _chunk2ZCYWED7js.encodeBase64UrlSafe; exports.encodeHex = _chunkSV46MOJDjs.encodeHex; exports.encodeHexZeroX = _chunkSV46MOJDjs.encodeHexZeroX; exports.encodeUtf8 = _chunkBUKFPQGEjs.encodeUtf8; exports.ensureDecoded = _chunkM3NOOX65js.ensureDecoded; exports.isAnyHex = _chunkSV46MOJDjs.isAnyHex; exports.isAscii = _chunk5IQZ2WS2js.isAscii; exports.isBase32 = _chunkAIY3EMBZjs.isBase32; exports.isBase58 = _chunkTOXDKCM7js.isBase58; exports.isHex = _chunkSV46MOJDjs.isHex; exports.isHexZeroX = _chunkSV46MOJDjs.isHexZeroX; |
+80
| import { | ||
| decodeAscii, | ||
| encodeAscii, | ||
| isAscii | ||
| } from "./chunk-6F7N6SN5.mjs"; | ||
| import { | ||
| decodeBase58Check, | ||
| encodeBase58Check | ||
| } from "./chunk-KSRU7YO7.mjs"; | ||
| import { | ||
| ensureDecoded | ||
| } from "./chunk-YT72IRPH.mjs"; | ||
| import { | ||
| decode, | ||
| encode | ||
| } from "./chunk-HIIB3CHB.mjs"; | ||
| import { | ||
| decodeHex, | ||
| decodeHexAny, | ||
| decodeHexZeroX, | ||
| encodeHex, | ||
| encodeHexZeroX, | ||
| isAnyHex, | ||
| isHex, | ||
| isHexZeroX | ||
| } from "./chunk-2ZWIOYKP.mjs"; | ||
| import { | ||
| decodeUtf8, | ||
| encodeUtf8 | ||
| } from "./chunk-HSTTGBPL.mjs"; | ||
| import { | ||
| decodeBase32, | ||
| encodeBase32, | ||
| isBase32 | ||
| } from "./chunk-VQTPFEEJ.mjs"; | ||
| import { | ||
| decodeBase58, | ||
| encodeBase58, | ||
| isBase58 | ||
| } from "./chunk-SSJ5XBYN.mjs"; | ||
| import { | ||
| decodeBase64, | ||
| decodeBase64UrlSafe, | ||
| encodeBase64, | ||
| encodeBase64UrlSafe | ||
| } from "./chunk-IX5UPKFA.mjs"; | ||
| import { | ||
| EncodingTypes | ||
| } from "./chunk-VA3TULOQ.mjs"; | ||
| export { | ||
| EncodingTypes, | ||
| decode, | ||
| decodeAscii, | ||
| decodeBase32, | ||
| decodeBase58, | ||
| decodeBase58Check, | ||
| decodeBase64, | ||
| decodeBase64UrlSafe, | ||
| decodeHex, | ||
| decodeHexAny, | ||
| decodeHexZeroX, | ||
| decodeUtf8, | ||
| encode, | ||
| encodeAscii, | ||
| encodeBase32, | ||
| encodeBase58, | ||
| encodeBase58Check, | ||
| encodeBase64, | ||
| encodeBase64UrlSafe, | ||
| encodeHex, | ||
| encodeHexZeroX, | ||
| encodeUtf8, | ||
| ensureDecoded, | ||
| isAnyHex, | ||
| isAscii, | ||
| isBase32, | ||
| isBase58, | ||
| isHex, | ||
| isHexZeroX | ||
| }; |
| declare function encodeUtf8(input: Uint8Array): string; | ||
| declare function decodeUtf8(input: string): Uint8Array; | ||
| export { decodeUtf8, encodeUtf8 }; |
+8
| "use strict";Object.defineProperty(exports, "__esModule", {value: true}); | ||
| var _chunkBUKFPQGEjs = require('./chunk-BUKFPQGE.js'); | ||
| exports.decodeUtf8 = _chunkBUKFPQGEjs.decodeUtf8; exports.encodeUtf8 = _chunkBUKFPQGEjs.encodeUtf8; |
+8
| import { | ||
| decodeUtf8, | ||
| encodeUtf8 | ||
| } from "./chunk-HSTTGBPL.mjs"; | ||
| export { | ||
| decodeUtf8, | ||
| encodeUtf8 | ||
| }; |
+101
-30
| { | ||
| "name": "@mailchain/encoding", | ||
| "version": "0.29.0", | ||
| "version": "0.30.0", | ||
| "description": "Mailchain encoding tools", | ||
| "license": "Apache-2.0", | ||
| "type": "commonjs", | ||
| "author": { | ||
@@ -23,47 +24,117 @@ "name": "Mailchain", | ||
| }, | ||
| "types": "./types/index.d.ts", | ||
| "browser": "./browser/index.js", | ||
| "main": "./node/index.js", | ||
| "main": "index.js", | ||
| "module": "index.mjs", | ||
| "types": "index.d.ts", | ||
| "exports": { | ||
| ".": { | ||
| "types": "./types/index.d.ts", | ||
| "import": "./browser/index.js", | ||
| "require": "./node/index.js" | ||
| "./ascii": { | ||
| "require": { | ||
| "types": "./ascii.d.ts", | ||
| "default": "./ascii.js" | ||
| }, | ||
| "import": { | ||
| "types": "./ascii.d.mts", | ||
| "default": "./ascii.mjs" | ||
| } | ||
| }, | ||
| "./base32": { | ||
| "types": "./types/base32.d.ts", | ||
| "import": "./browser/base32.js", | ||
| "require": "./node/base32.js" | ||
| "require": { | ||
| "types": "./base32.d.ts", | ||
| "default": "./base32.js" | ||
| }, | ||
| "import": { | ||
| "types": "./base32.d.mts", | ||
| "default": "./base32.mjs" | ||
| } | ||
| }, | ||
| "./base58": { | ||
| "types": "./types/base58.d.ts", | ||
| "import": "./browser/base58.js", | ||
| "require": "./node/base58.js" | ||
| "require": { | ||
| "types": "./base58.d.ts", | ||
| "default": "./base58.js" | ||
| }, | ||
| "import": { | ||
| "types": "./base58.d.mts", | ||
| "default": "./base58.mjs" | ||
| } | ||
| }, | ||
| "./base58Check": { | ||
| "require": { | ||
| "types": "./base58Check.d.ts", | ||
| "default": "./base58Check.js" | ||
| }, | ||
| "import": { | ||
| "types": "./base58Check.d.mts", | ||
| "default": "./base58Check.mjs" | ||
| } | ||
| }, | ||
| "./base64": { | ||
| "types": "./types/base64.d.ts", | ||
| "import": "./browser/base64.js", | ||
| "require": "./node/base64.js" | ||
| "require": { | ||
| "types": "./base64.d.ts", | ||
| "default": "./base64.js" | ||
| }, | ||
| "import": { | ||
| "types": "./base64.d.mts", | ||
| "default": "./base64.mjs" | ||
| } | ||
| }, | ||
| "./consts": { | ||
| "types": "./types/consts.d.ts", | ||
| "import": "./browser/consts.js", | ||
| "require": "./node/consts.js" | ||
| "require": { | ||
| "types": "./consts.d.ts", | ||
| "default": "./consts.js" | ||
| }, | ||
| "import": { | ||
| "types": "./consts.d.mts", | ||
| "default": "./consts.mjs" | ||
| } | ||
| }, | ||
| "./encoding": { | ||
| "types": "./types/encoding.d.ts", | ||
| "import": "./browser/encoding.js", | ||
| "require": "./node/encoding.js" | ||
| "require": { | ||
| "types": "./encoding.d.ts", | ||
| "default": "./encoding.js" | ||
| }, | ||
| "import": { | ||
| "types": "./encoding.d.mts", | ||
| "default": "./encoding.mjs" | ||
| } | ||
| }, | ||
| "./ensure": { | ||
| "require": { | ||
| "types": "./ensure.d.ts", | ||
| "default": "./ensure.js" | ||
| }, | ||
| "import": { | ||
| "types": "./ensure.d.mts", | ||
| "default": "./ensure.mjs" | ||
| } | ||
| }, | ||
| "./hex": { | ||
| "types": "./types/hex.d.ts", | ||
| "import": "./browser/hex.js", | ||
| "require": "./node/hex.js" | ||
| "require": { | ||
| "types": "./hex.d.ts", | ||
| "default": "./hex.js" | ||
| }, | ||
| "import": { | ||
| "types": "./hex.d.mts", | ||
| "default": "./hex.mjs" | ||
| } | ||
| }, | ||
| ".": { | ||
| "require": { | ||
| "types": "./index.d.ts", | ||
| "default": "./index.js" | ||
| }, | ||
| "import": { | ||
| "types": "./index.d.mts", | ||
| "default": "./index.mjs" | ||
| } | ||
| }, | ||
| "./utf8": { | ||
| "types": "./types/utf8.d.ts", | ||
| "import": "./browser/utf8.js", | ||
| "require": "./node/utf8.js" | ||
| "require": { | ||
| "types": "./utf8.d.ts", | ||
| "default": "./utf8.js" | ||
| }, | ||
| "import": { | ||
| "types": "./utf8.d.mts", | ||
| "default": "./utf8.mjs" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } |
| function encodeAscii(input) { | ||
| return Buffer.from(input).toString('ascii'); | ||
| } | ||
| function decodeAscii(input) { | ||
| if (!isAscii(input)) | ||
| throw new Error('Input is not ASCII'); | ||
| return new Uint8Array(Buffer.from(input, 'ascii')); | ||
| } | ||
| function isAscii(str) { | ||
| // eslint-disable-next-line no-control-regex | ||
| return /^[\x00-\x7F]+$/.test(str); | ||
| } | ||
| export { decodeAscii, encodeAscii, isAscii }; |
| import { utils } from '@scure/base'; | ||
| const BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567'; | ||
| const coder = utils.chain( | ||
| // We define our own chain, the default base32 has padding | ||
| utils.radix2(5), utils.alphabet(BASE32_ALPHABET), { | ||
| decode: (input) => input.split(''), | ||
| encode: (input) => input.join(''), | ||
| }); | ||
| function decodeBase32(input) { | ||
| return coder.decode(input); | ||
| } | ||
| function encodeBase32(input) { | ||
| return coder.encode(input); | ||
| } | ||
| function isBase32(input) { | ||
| // Check that all characters are valid base32 characters | ||
| for (let i = 0; i < input.length; i++) { | ||
| const char = input[i]; | ||
| if (BASE32_ALPHABET.indexOf(char.toLowerCase()) === -1) { | ||
| return false; | ||
| } | ||
| } | ||
| // Check that the input length is a multiple of 8 bits | ||
| if (input.length % 8 !== 0) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| export { decodeBase32, encodeBase32, isBase32 }; |
| import { base58 } from '@scure/base'; | ||
| function decodeBase58(input) { | ||
| return base58.decode(input); | ||
| } | ||
| function encodeBase58(input) { | ||
| return base58.encode(input); | ||
| } | ||
| function isBase58(input) { | ||
| return /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(input); | ||
| } | ||
| export { decodeBase58, encodeBase58, isBase58 }; |
| import { sha256 } from '@noble/hashes/sha256'; | ||
| import { decodeBase58, encodeBase58 } from './base58.js'; | ||
| function decodeBase58Check(input) { | ||
| const validatedPayload = validatePayload(decodeBase58(input)); | ||
| if (validatedPayload == null) | ||
| throw new Error('failed input checksum validation'); | ||
| return validatedPayload; | ||
| } | ||
| function encodeBase58Check(input) { | ||
| const checksum = calcChecksum(input).slice(0, 4); | ||
| return encodeBase58(Uint8Array.from([...input, ...checksum])); | ||
| } | ||
| // Ref: https://github.com/bitcoinjs/bs58check | ||
| function calcChecksum(payload) { | ||
| return sha256(sha256(payload)); | ||
| } | ||
| // Ref: https://github.com/bitcoinjs/bs58check | ||
| function validatePayload(payloadWithChecksum) { | ||
| const payload = payloadWithChecksum.slice(0, -4); | ||
| const payloadChecksum = payloadWithChecksum.slice(-4); | ||
| const checksum = calcChecksum(payload); | ||
| // Compare the checksum bytes with XOR operator | ||
| if ((payloadChecksum[0] ^ checksum[0]) | | ||
| (payloadChecksum[1] ^ checksum[1]) | | ||
| (payloadChecksum[2] ^ checksum[2]) | | ||
| (payloadChecksum[3] ^ checksum[3])) { | ||
| return null; | ||
| } | ||
| return payload; | ||
| } | ||
| export { decodeBase58Check, encodeBase58Check }; |
| function decodeBase64(input) { | ||
| const output = Buffer.from(input, 'base64'); | ||
| if (input.length > 0 && output.length === 0) { | ||
| throw new Error('could not decode input'); | ||
| } | ||
| return Uint8Array.from(output); | ||
| } | ||
| function encodeBase64(input) { | ||
| return Buffer.from(input).toString('base64'); | ||
| } | ||
| function decodeBase64UrlSafe(input) { | ||
| let encoded = input.replace('-', '+').replace('_', '/'); | ||
| while (encoded.length % 4) | ||
| encoded += '='; | ||
| const output = Buffer.from(encoded, 'base64'); | ||
| if (input.length > 0 && output.length === 0) { | ||
| throw new Error('could not decode input'); | ||
| } | ||
| return Uint8Array.from(output); | ||
| } | ||
| function encodeBase64UrlSafe(input) { | ||
| return Buffer.from(input).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); | ||
| } | ||
| export { decodeBase64, decodeBase64UrlSafe, encodeBase64, encodeBase64UrlSafe }; |
| const EncodingTypes = { | ||
| /** | ||
| * Plain hex encoding value. | ||
| */ | ||
| Hex: 'hex/plain', | ||
| /** | ||
| * 0x prefixed hex encoding | ||
| */ | ||
| Hex0xPrefix: 'hex/0x-prefix', | ||
| /** | ||
| * With or without 0x prefix | ||
| */ | ||
| HexAny: 'hex/any', | ||
| Base32: 'base32/plain', | ||
| Base58: 'base58/plain', | ||
| Base64: 'base64/plain', | ||
| Base62Url: 'base64/url', | ||
| Base58SubstrateAddress: 'base58/ss58-address', | ||
| Utf8: 'text/utf-8', | ||
| }; | ||
| export { EncodingTypes }; |
| import { decodeBase32, encodeBase32 } from './base32.js'; | ||
| import { decodeBase58, encodeBase58 } from './base58.js'; | ||
| import { encodeBase64UrlSafe } from './base64.js'; | ||
| import { EncodingTypes } from './consts.js'; | ||
| import { decodeHexAny, decodeHexZeroX, decodeHex, encodeHexZeroX, encodeHex } from './hex.js'; | ||
| import { decodeUtf8, encodeUtf8 } from './utf8.js'; | ||
| class UnsupportedEncodingError extends Error { | ||
| constructor(encoding) { | ||
| super(`Encoding [${encoding}] not supported`); | ||
| } | ||
| } | ||
| /** | ||
| * Decode returns the bytes represented by the decoded string src. | ||
| * Decode uses the decode method mapped to kind parameter. | ||
| * | ||
| * If the input is kind is unknown or the input is malformed for the decode method it returns an error. | ||
| * @param encoding | ||
| * @param src | ||
| * @returns | ||
| */ | ||
| function decode(encoding, src) { | ||
| switch (encoding.toLowerCase()) { | ||
| case EncodingTypes.Base58: | ||
| return decodeBase58(src); | ||
| case EncodingTypes.Hex: | ||
| return decodeHex(src); | ||
| case EncodingTypes.Hex0xPrefix: | ||
| return decodeHexZeroX(src); | ||
| case EncodingTypes.Utf8: | ||
| return decodeUtf8(src); | ||
| case EncodingTypes.Base32: | ||
| return decodeBase32(src); | ||
| case EncodingTypes.HexAny: | ||
| return decodeHexAny(src); | ||
| default: | ||
| throw new UnsupportedEncodingError(encoding); | ||
| } | ||
| } | ||
| /** | ||
| * Encode returns the bytes encoded as requested by the encoding parameter. | ||
| * @param encoding | ||
| * @param src | ||
| * @returns encoded value | ||
| */ | ||
| function encode(encoding, src) { | ||
| switch (encoding.toLowerCase()) { | ||
| case EncodingTypes.Base58: | ||
| return encodeBase58(src); | ||
| case EncodingTypes.Hex: | ||
| return encodeHex(src); | ||
| case EncodingTypes.Hex0xPrefix: | ||
| return encodeHexZeroX(src); | ||
| case EncodingTypes.Base64: | ||
| return encodeBase64UrlSafe(src); | ||
| case EncodingTypes.Utf8: | ||
| return encodeUtf8(src); | ||
| case EncodingTypes.Base32: | ||
| return encodeBase32(src); | ||
| default: | ||
| throw new UnsupportedEncodingError(encoding); | ||
| } | ||
| } | ||
| export { decode, encode }; |
| import { decode } from './encoding.js'; | ||
| function ensureDecoded(value, encoding) { | ||
| if (typeof value === 'string') { | ||
| return decode(encoding, value); | ||
| } | ||
| return value; | ||
| } | ||
| export { ensureDecoded }; |
| // EncodeHexZeroX encodes src into "0x"+hex.Encode. As a convenience, it returns the encoding type used, | ||
| // but this value is always TypeHex0XPrefix. | ||
| // EncodeHexZeroX uses hexadecimal encoding prefixed with "0x". | ||
| function encodeHexZeroX(input) { | ||
| return '0x' + encodeHex(input); | ||
| } | ||
| // DecodeHexZeroX returns the bytes represented by the hexadecimal string src. | ||
| function decodeHexZeroX(input) { | ||
| if (input === '') { | ||
| throw new RangeError('empty hex string'); | ||
| } | ||
| if (!input.startsWith('0x')) { | ||
| throw new RangeError("must start with '0x'"); | ||
| } | ||
| return decodeHex(input.slice(2)); | ||
| } | ||
| // EncodeHex returns the hexadecimal encoding of src. | ||
| function encodeHex(input) { | ||
| return Buffer.from(input).toString('hex'); | ||
| } | ||
| // DecodeHex returns the bytes represented by the hexadecimal string s. | ||
| function decodeHex(input) { | ||
| const output = new Uint8Array(Buffer.from(input, 'hex')); | ||
| if (output.length === 0 || input.length === 0) { | ||
| throw RangeError('invalid hex encoding'); | ||
| } | ||
| return output; | ||
| } | ||
| function isHex(input) { | ||
| return new RegExp('^[a-fA-F0-9]+$').test(input); | ||
| } | ||
| function isHexZeroX(input) { | ||
| return new RegExp('^0x[a-fA-F0-9]+$').test(input); | ||
| } | ||
| function isAnyHex(input) { | ||
| if (input.startsWith('0x')) { | ||
| input = input.substring(2); | ||
| } | ||
| return isHex(input); | ||
| } | ||
| function decodeHexAny(input) { | ||
| if (input.startsWith('0x')) { | ||
| input = input.substring(2); | ||
| } | ||
| return decodeHex(input); | ||
| } | ||
| export { decodeHex, decodeHexAny, decodeHexZeroX, encodeHex, encodeHexZeroX, isAnyHex, isHex, isHexZeroX }; |
| export { EncodingTypes } from './consts.js'; | ||
| export { ensureDecoded } from './ensure.js'; | ||
| export { decode, encode } from './encoding.js'; | ||
| export { decodeHex, decodeHexAny, decodeHexZeroX, encodeHex, encodeHexZeroX, isAnyHex, isHex, isHexZeroX } from './hex.js'; | ||
| export { decodeBase32, encodeBase32, isBase32 } from './base32.js'; | ||
| export { decodeBase58, encodeBase58, isBase58 } from './base58.js'; | ||
| export { decodeBase58Check, encodeBase58Check } from './base58Check.js'; | ||
| export { decodeBase64, decodeBase64UrlSafe, encodeBase64, encodeBase64UrlSafe } from './base64.js'; | ||
| export { decodeUtf8, encodeUtf8 } from './utf8.js'; | ||
| export { decodeAscii, encodeAscii, isAscii } from './ascii.js'; |
| function encodeUtf8(input) { | ||
| return Buffer.from(input).toString('utf-8'); | ||
| } | ||
| function decodeUtf8(input) { | ||
| return new Uint8Array(Buffer.from(input, 'utf-8')); | ||
| } | ||
| export { decodeUtf8, encodeUtf8 }; |
| 'use strict'; | ||
| function encodeAscii(input) { | ||
| return Buffer.from(input).toString('ascii'); | ||
| } | ||
| function decodeAscii(input) { | ||
| if (!isAscii(input)) | ||
| throw new Error('Input is not ASCII'); | ||
| return new Uint8Array(Buffer.from(input, 'ascii')); | ||
| } | ||
| function isAscii(str) { | ||
| // eslint-disable-next-line no-control-regex | ||
| return /^[\x00-\x7F]+$/.test(str); | ||
| } | ||
| exports.decodeAscii = decodeAscii; | ||
| exports.encodeAscii = encodeAscii; | ||
| exports.isAscii = isAscii; |
| 'use strict'; | ||
| var base = require('@scure/base'); | ||
| const BASE32_ALPHABET = 'abcdefghijklmnopqrstuvwxyz234567'; | ||
| const coder = base.utils.chain( | ||
| // We define our own chain, the default base32 has padding | ||
| base.utils.radix2(5), base.utils.alphabet(BASE32_ALPHABET), { | ||
| decode: (input) => input.split(''), | ||
| encode: (input) => input.join(''), | ||
| }); | ||
| function decodeBase32(input) { | ||
| return coder.decode(input); | ||
| } | ||
| function encodeBase32(input) { | ||
| return coder.encode(input); | ||
| } | ||
| function isBase32(input) { | ||
| // Check that all characters are valid base32 characters | ||
| for (let i = 0; i < input.length; i++) { | ||
| const char = input[i]; | ||
| if (BASE32_ALPHABET.indexOf(char.toLowerCase()) === -1) { | ||
| return false; | ||
| } | ||
| } | ||
| // Check that the input length is a multiple of 8 bits | ||
| if (input.length % 8 !== 0) { | ||
| return false; | ||
| } | ||
| return true; | ||
| } | ||
| exports.decodeBase32 = decodeBase32; | ||
| exports.encodeBase32 = encodeBase32; | ||
| exports.isBase32 = isBase32; |
| 'use strict'; | ||
| var base = require('@scure/base'); | ||
| function decodeBase58(input) { | ||
| return base.base58.decode(input); | ||
| } | ||
| function encodeBase58(input) { | ||
| return base.base58.encode(input); | ||
| } | ||
| function isBase58(input) { | ||
| return /^[123456789ABCDEFGHJKLMNPQRSTUVWXYZabcdefghijkmnopqrstuvwxyz]+$/.test(input); | ||
| } | ||
| exports.decodeBase58 = decodeBase58; | ||
| exports.encodeBase58 = encodeBase58; | ||
| exports.isBase58 = isBase58; |
| 'use strict'; | ||
| var sha256 = require('@noble/hashes/sha256'); | ||
| var base58 = require('./base58.js'); | ||
| function decodeBase58Check(input) { | ||
| const validatedPayload = validatePayload(base58.decodeBase58(input)); | ||
| if (validatedPayload == null) | ||
| throw new Error('failed input checksum validation'); | ||
| return validatedPayload; | ||
| } | ||
| function encodeBase58Check(input) { | ||
| const checksum = calcChecksum(input).slice(0, 4); | ||
| return base58.encodeBase58(Uint8Array.from([...input, ...checksum])); | ||
| } | ||
| // Ref: https://github.com/bitcoinjs/bs58check | ||
| function calcChecksum(payload) { | ||
| return sha256.sha256(sha256.sha256(payload)); | ||
| } | ||
| // Ref: https://github.com/bitcoinjs/bs58check | ||
| function validatePayload(payloadWithChecksum) { | ||
| const payload = payloadWithChecksum.slice(0, -4); | ||
| const payloadChecksum = payloadWithChecksum.slice(-4); | ||
| const checksum = calcChecksum(payload); | ||
| // Compare the checksum bytes with XOR operator | ||
| if ((payloadChecksum[0] ^ checksum[0]) | | ||
| (payloadChecksum[1] ^ checksum[1]) | | ||
| (payloadChecksum[2] ^ checksum[2]) | | ||
| (payloadChecksum[3] ^ checksum[3])) { | ||
| return null; | ||
| } | ||
| return payload; | ||
| } | ||
| exports.decodeBase58Check = decodeBase58Check; | ||
| exports.encodeBase58Check = encodeBase58Check; |
| 'use strict'; | ||
| function decodeBase64(input) { | ||
| const output = Buffer.from(input, 'base64'); | ||
| if (input.length > 0 && output.length === 0) { | ||
| throw new Error('could not decode input'); | ||
| } | ||
| return Uint8Array.from(output); | ||
| } | ||
| function encodeBase64(input) { | ||
| return Buffer.from(input).toString('base64'); | ||
| } | ||
| function decodeBase64UrlSafe(input) { | ||
| let encoded = input.replace('-', '+').replace('_', '/'); | ||
| while (encoded.length % 4) | ||
| encoded += '='; | ||
| const output = Buffer.from(encoded, 'base64'); | ||
| if (input.length > 0 && output.length === 0) { | ||
| throw new Error('could not decode input'); | ||
| } | ||
| return Uint8Array.from(output); | ||
| } | ||
| function encodeBase64UrlSafe(input) { | ||
| return Buffer.from(input).toString('base64').replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/, ''); | ||
| } | ||
| exports.decodeBase64 = decodeBase64; | ||
| exports.decodeBase64UrlSafe = decodeBase64UrlSafe; | ||
| exports.encodeBase64 = encodeBase64; | ||
| exports.encodeBase64UrlSafe = encodeBase64UrlSafe; |
| 'use strict'; | ||
| const EncodingTypes = { | ||
| /** | ||
| * Plain hex encoding value. | ||
| */ | ||
| Hex: 'hex/plain', | ||
| /** | ||
| * 0x prefixed hex encoding | ||
| */ | ||
| Hex0xPrefix: 'hex/0x-prefix', | ||
| /** | ||
| * With or without 0x prefix | ||
| */ | ||
| HexAny: 'hex/any', | ||
| Base32: 'base32/plain', | ||
| Base58: 'base58/plain', | ||
| Base64: 'base64/plain', | ||
| Base62Url: 'base64/url', | ||
| Base58SubstrateAddress: 'base58/ss58-address', | ||
| Utf8: 'text/utf-8', | ||
| }; | ||
| exports.EncodingTypes = EncodingTypes; |
| 'use strict'; | ||
| var base32 = require('./base32.js'); | ||
| var base58 = require('./base58.js'); | ||
| var base64 = require('./base64.js'); | ||
| var consts = require('./consts.js'); | ||
| var hex = require('./hex.js'); | ||
| var utf8 = require('./utf8.js'); | ||
| class UnsupportedEncodingError extends Error { | ||
| constructor(encoding) { | ||
| super(`Encoding [${encoding}] not supported`); | ||
| } | ||
| } | ||
| /** | ||
| * Decode returns the bytes represented by the decoded string src. | ||
| * Decode uses the decode method mapped to kind parameter. | ||
| * | ||
| * If the input is kind is unknown or the input is malformed for the decode method it returns an error. | ||
| * @param encoding | ||
| * @param src | ||
| * @returns | ||
| */ | ||
| function decode(encoding, src) { | ||
| switch (encoding.toLowerCase()) { | ||
| case consts.EncodingTypes.Base58: | ||
| return base58.decodeBase58(src); | ||
| case consts.EncodingTypes.Hex: | ||
| return hex.decodeHex(src); | ||
| case consts.EncodingTypes.Hex0xPrefix: | ||
| return hex.decodeHexZeroX(src); | ||
| case consts.EncodingTypes.Utf8: | ||
| return utf8.decodeUtf8(src); | ||
| case consts.EncodingTypes.Base32: | ||
| return base32.decodeBase32(src); | ||
| case consts.EncodingTypes.HexAny: | ||
| return hex.decodeHexAny(src); | ||
| default: | ||
| throw new UnsupportedEncodingError(encoding); | ||
| } | ||
| } | ||
| /** | ||
| * Encode returns the bytes encoded as requested by the encoding parameter. | ||
| * @param encoding | ||
| * @param src | ||
| * @returns encoded value | ||
| */ | ||
| function encode(encoding, src) { | ||
| switch (encoding.toLowerCase()) { | ||
| case consts.EncodingTypes.Base58: | ||
| return base58.encodeBase58(src); | ||
| case consts.EncodingTypes.Hex: | ||
| return hex.encodeHex(src); | ||
| case consts.EncodingTypes.Hex0xPrefix: | ||
| return hex.encodeHexZeroX(src); | ||
| case consts.EncodingTypes.Base64: | ||
| return base64.encodeBase64UrlSafe(src); | ||
| case consts.EncodingTypes.Utf8: | ||
| return utf8.encodeUtf8(src); | ||
| case consts.EncodingTypes.Base32: | ||
| return base32.encodeBase32(src); | ||
| default: | ||
| throw new UnsupportedEncodingError(encoding); | ||
| } | ||
| } | ||
| exports.decode = decode; | ||
| exports.encode = encode; |
| 'use strict'; | ||
| var encoding = require('./encoding.js'); | ||
| function ensureDecoded(value, encoding$1) { | ||
| if (typeof value === 'string') { | ||
| return encoding.decode(encoding$1, value); | ||
| } | ||
| return value; | ||
| } | ||
| exports.ensureDecoded = ensureDecoded; |
-57
| 'use strict'; | ||
| // EncodeHexZeroX encodes src into "0x"+hex.Encode. As a convenience, it returns the encoding type used, | ||
| // but this value is always TypeHex0XPrefix. | ||
| // EncodeHexZeroX uses hexadecimal encoding prefixed with "0x". | ||
| function encodeHexZeroX(input) { | ||
| return '0x' + encodeHex(input); | ||
| } | ||
| // DecodeHexZeroX returns the bytes represented by the hexadecimal string src. | ||
| function decodeHexZeroX(input) { | ||
| if (input === '') { | ||
| throw new RangeError('empty hex string'); | ||
| } | ||
| if (!input.startsWith('0x')) { | ||
| throw new RangeError("must start with '0x'"); | ||
| } | ||
| return decodeHex(input.slice(2)); | ||
| } | ||
| // EncodeHex returns the hexadecimal encoding of src. | ||
| function encodeHex(input) { | ||
| return Buffer.from(input).toString('hex'); | ||
| } | ||
| // DecodeHex returns the bytes represented by the hexadecimal string s. | ||
| function decodeHex(input) { | ||
| const output = new Uint8Array(Buffer.from(input, 'hex')); | ||
| if (output.length === 0 || input.length === 0) { | ||
| throw RangeError('invalid hex encoding'); | ||
| } | ||
| return output; | ||
| } | ||
| function isHex(input) { | ||
| return new RegExp('^[a-fA-F0-9]+$').test(input); | ||
| } | ||
| function isHexZeroX(input) { | ||
| return new RegExp('^0x[a-fA-F0-9]+$').test(input); | ||
| } | ||
| function isAnyHex(input) { | ||
| if (input.startsWith('0x')) { | ||
| input = input.substring(2); | ||
| } | ||
| return isHex(input); | ||
| } | ||
| function decodeHexAny(input) { | ||
| if (input.startsWith('0x')) { | ||
| input = input.substring(2); | ||
| } | ||
| return decodeHex(input); | ||
| } | ||
| exports.decodeHex = decodeHex; | ||
| exports.decodeHexAny = decodeHexAny; | ||
| exports.decodeHexZeroX = decodeHexZeroX; | ||
| exports.encodeHex = encodeHex; | ||
| exports.encodeHexZeroX = encodeHexZeroX; | ||
| exports.isAnyHex = isAnyHex; | ||
| exports.isHex = isHex; | ||
| exports.isHexZeroX = isHexZeroX; |
| 'use strict'; | ||
| var consts = require('./consts.js'); | ||
| var ensure = require('./ensure.js'); | ||
| var encoding = require('./encoding.js'); | ||
| var hex = require('./hex.js'); | ||
| var base32 = require('./base32.js'); | ||
| var base58 = require('./base58.js'); | ||
| var base58Check = require('./base58Check.js'); | ||
| var base64 = require('./base64.js'); | ||
| var utf8 = require('./utf8.js'); | ||
| var ascii = require('./ascii.js'); | ||
| exports.EncodingTypes = consts.EncodingTypes; | ||
| exports.ensureDecoded = ensure.ensureDecoded; | ||
| exports.decode = encoding.decode; | ||
| exports.encode = encoding.encode; | ||
| exports.decodeHex = hex.decodeHex; | ||
| exports.decodeHexAny = hex.decodeHexAny; | ||
| exports.decodeHexZeroX = hex.decodeHexZeroX; | ||
| exports.encodeHex = hex.encodeHex; | ||
| exports.encodeHexZeroX = hex.encodeHexZeroX; | ||
| exports.isAnyHex = hex.isAnyHex; | ||
| exports.isHex = hex.isHex; | ||
| exports.isHexZeroX = hex.isHexZeroX; | ||
| exports.decodeBase32 = base32.decodeBase32; | ||
| exports.encodeBase32 = base32.encodeBase32; | ||
| exports.isBase32 = base32.isBase32; | ||
| exports.decodeBase58 = base58.decodeBase58; | ||
| exports.encodeBase58 = base58.encodeBase58; | ||
| exports.isBase58 = base58.isBase58; | ||
| exports.decodeBase58Check = base58Check.decodeBase58Check; | ||
| exports.encodeBase58Check = base58Check.encodeBase58Check; | ||
| exports.decodeBase64 = base64.decodeBase64; | ||
| exports.decodeBase64UrlSafe = base64.decodeBase64UrlSafe; | ||
| exports.encodeBase64 = base64.encodeBase64; | ||
| exports.encodeBase64UrlSafe = base64.encodeBase64UrlSafe; | ||
| exports.decodeUtf8 = utf8.decodeUtf8; | ||
| exports.encodeUtf8 = utf8.encodeUtf8; | ||
| exports.decodeAscii = ascii.decodeAscii; | ||
| exports.encodeAscii = ascii.encodeAscii; | ||
| exports.isAscii = ascii.isAscii; |
-11
| 'use strict'; | ||
| function encodeUtf8(input) { | ||
| return Buffer.from(input).toString('utf-8'); | ||
| } | ||
| function decodeUtf8(input) { | ||
| return new Uint8Array(Buffer.from(input, 'utf-8')); | ||
| } | ||
| exports.decodeUtf8 = decodeUtf8; | ||
| exports.encodeUtf8 = encodeUtf8; |
-23
| # Mailchain Encoding | ||
| Mailchain is a messaging protocol that lets users communicate across protocols. Using Mailchain you can send messages to any blockchain address on different protocols. | ||
| For full usage examples view the [developer docs](https://docs.mailchain.com). | ||
| ## Installing | ||
| Using npm: | ||
| ```bash | ||
| $ npm install @mailchain/encoding | ||
| ``` | ||
| Using yarn: | ||
| ```bash | ||
| $ yarn add @mailchain/encoding | ||
| ``` | ||
| ## Purpose | ||
| The encoding package is used by `@mailchain/sdk` to support encoding across different blockchain protocols. |
| export declare function encodeAscii(input: Uint8Array): string; | ||
| export declare function decodeAscii(input: string): Uint8Array; | ||
| export declare function isAscii(str: string): boolean; |
| export {}; |
| export declare function decodeBase32(input: string): Uint8Array; | ||
| export declare function encodeBase32(input: Uint8Array): string; | ||
| export declare function isBase32(input: string): boolean; |
| export {}; |
| export declare function decodeBase58(input: string): Uint8Array; | ||
| export declare function encodeBase58(input: Uint8Array): string; | ||
| export declare function isBase58(input: string): boolean; |
| export {}; |
| export declare function decodeBase58Check(input: string): Uint8Array; | ||
| export declare function encodeBase58Check(input: Uint8Array): string; |
| export declare function decodeBase64(input: string): Uint8Array; | ||
| export declare function encodeBase64(input: Uint8Array): string; | ||
| export declare function decodeBase64UrlSafe(input: string): Uint8Array; | ||
| export declare function encodeBase64UrlSafe(input: Uint8Array): string; |
| export {}; |
| export declare const EncodingTypes: { | ||
| /** | ||
| * Plain hex encoding value. | ||
| */ | ||
| readonly Hex: "hex/plain"; | ||
| /** | ||
| * 0x prefixed hex encoding | ||
| */ | ||
| readonly Hex0xPrefix: "hex/0x-prefix"; | ||
| /** | ||
| * With or without 0x prefix | ||
| */ | ||
| readonly HexAny: "hex/any"; | ||
| readonly Base32: "base32/plain"; | ||
| readonly Base58: "base58/plain"; | ||
| readonly Base64: "base64/plain"; | ||
| readonly Base62Url: "base64/url"; | ||
| readonly Base58SubstrateAddress: "base58/ss58-address"; | ||
| readonly Utf8: "text/utf-8"; | ||
| }; | ||
| export type EncodingType = typeof EncodingTypes[keyof typeof EncodingTypes]; |
| import { EncodingType } from './consts'; | ||
| /** | ||
| * Decode returns the bytes represented by the decoded string src. | ||
| * Decode uses the decode method mapped to kind parameter. | ||
| * | ||
| * If the input is kind is unknown or the input is malformed for the decode method it returns an error. | ||
| * @param encoding | ||
| * @param src | ||
| * @returns | ||
| */ | ||
| export declare function decode(encoding: EncodingType, src: string): Uint8Array; | ||
| /** | ||
| * Encode returns the bytes encoded as requested by the encoding parameter. | ||
| * @param encoding | ||
| * @param src | ||
| * @returns encoded value | ||
| */ | ||
| export declare function encode(encoding: EncodingType, src: Uint8Array): string; |
| export {}; |
| /// <reference types="node" /> | ||
| import { EncodingType } from './consts'; | ||
| export declare function ensureDecoded(value: Uint8Array | string | Buffer, encoding: EncodingType): Uint8Array | Buffer; |
| export declare function encodeHexZeroX(input: Uint8Array): string; | ||
| export declare function decodeHexZeroX(input: string): Uint8Array; | ||
| export declare function encodeHex(input: Uint8Array): string; | ||
| export declare function decodeHex(input: string): Uint8Array; | ||
| export declare function isHex(input: string): boolean; | ||
| export declare function isHexZeroX(input: string): boolean; | ||
| export declare function isAnyHex(input: string): boolean; | ||
| export declare function decodeHexAny(input: string): Uint8Array; |
| export {}; |
| export * from './consts'; | ||
| export * from './ensure'; | ||
| export * from './encoding'; | ||
| export * from './hex'; | ||
| export * from './base32'; | ||
| export * from './base58'; | ||
| export * from './base58Check'; | ||
| export * from './base64'; | ||
| export * from './utf8'; | ||
| export * from './ascii'; |
| export declare function encodeUtf8(input: Uint8Array): string; | ||
| export declare function decodeUtf8(input: string): Uint8Array; |
| export {}; |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
31778
25.39%54
28.57%880
31.15%2
100%0
-100%1
Infinity%