{"id":27401268,"url":"https://github.com/edjcase/motoko_base_x","last_synced_at":"2026-01-22T07:33:00.652Z","repository":{"id":287070855,"uuid":"962940011","full_name":"edjCase/motoko_base_x","owner":"edjCase","description":"A text/binary encoding library for base64, 16 (Hex), 58, etc...","archived":false,"fork":false,"pushed_at":"2025-09-06T18:50:37.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-09-06T20:37:48.116Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Motoko","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/edjCase.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-04-08T23:00:47.000Z","updated_at":"2025-09-06T18:50:41.000Z","dependencies_parsed_at":"2025-04-09T20:38:05.017Z","dependency_job_id":"0a934c2d-cdbb-4658-ba1c-5353a4562f7e","html_url":"https://github.com/edjCase/motoko_base_x","commit_stats":null,"previous_names":["edjcase/motoko_base_x"],"tags_count":0,"template":false,"template_full_name":"edjCase/motoko-library-template","purl":"pkg:github/edjCase/motoko_base_x","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_base_x","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_base_x/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_base_x/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_base_x/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/edjCase","download_url":"https://codeload.github.com/edjCase/motoko_base_x/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/edjCase%2Fmotoko_base_x/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28658107,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-22T01:17:37.254Z","status":"online","status_checked_at":"2026-01-22T02:00:07.137Z","response_time":144,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-04-14T03:54:35.880Z","updated_at":"2026-01-22T07:33:00.641Z","avatar_url":"https://github.com/edjCase.png","language":"Motoko","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Motoko Base-X Encoder\n\n[![MOPS](https://img.shields.io/badge/MOPS-base--x--encoder-blue)](https://mops.one/base-x-encoder)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](https://github.com/yourusername/base-x-encoder/blob/main/LICENSE)\n\nA Motoko library for encoding and decoding data in various base formats including Base64, Base32, Base16 (Hex), and Base58.\n\n## Package\n\n### MOPS\n\n```bash\nmops add base-x-encoder\n```\n\nTo set up MOPS package manager, follow the instructions from the [MOPS Site](https://mops.one)\n\n## Quick Start\n\n### Example 1: Base64 Encoding\n\n```motoko\nimport BaseX \"mo:base-x-encoder\";\nimport Blob \"mo:core/Blob\";\nimport Debug \"mo:core/Debug\";\n\n// Example data\nlet data = [0x48, 0x65, 0x6C, 0x6C, 0x6F].vals(); // \"Hello\" in ASCII\n\n// Encode to Base64\nlet encoded = BaseX.toBase64(data, false);\nDebug.print(encoded); // Output: \"SGVsbG8=\"\n\n// URI-safe encoding (no padding)\nlet uriSafe = BaseX.toBase64(data, true);\nDebug.print(uriSafe); // Output: \"SGVsbG8\"\n```\n\n### Example 2: Base64 Decoding\n\n```motoko\nimport BaseX \"mo:base-x-encoder\";\nimport Result \"mo:core/Result\";\nimport Debug \"mo:core/Debug\";\n\n// Decode Base64 string\nlet base64 = \"SGVsbG8=\"; // \"Hello\" in Base64\nlet result = BaseX.fromBase64(base64);\n\nswitch (result) {\n  case (#ok(bytes)) {\n    // bytes is [0x48, 0x65, 0x6C, 0x6C, 0x6F] (ASCII for \"Hello\")\n    Debug.print(\"Decoded successfully!\");\n  };\n  case (#err(error)) {\n    Debug.print(\"Error: \" # error);\n  };\n};\n```\n\n### Example 3: Hexadecimal Encoding\n\n```motoko\nimport BaseX \"mo:base-x-encoder\";\nimport Debug \"mo:core/Debug\";\n\n// Example data\nlet data = [0xA1, 0xB2, 0xC3].vals();\n\n// Format with uppercase hex and 0x prefix\nlet format1 = {\n  isUpper = true;\n  prefix = #single(\"0x\")\n};\nlet hex1 = BaseX.toHex(data, format1);\nDebug.print(hex1); // Output: \"0xA1B2C3\"\n\n// Format with lowercase hex and per-byte prefix\nlet format2 = {\n  isUpper = false;\n  prefix = #perByte(\"\\\\x\")\n};\nlet hex2 = BaseX.toHex(data, format2);\nDebug.print(hex2); // Output: \"\\xa1\\xb2\\xc3\"\n```\n\n### Example 4: Hexadecimal Decoding\n\n```motoko\nimport BaseX \"mo:base-x-encoder\";\nimport Result \"mo:core/Result\";\nimport Debug \"mo:core/Debug\";\n\n// Decode hex with 0x prefix\nlet hex = \"0xA1B2C3\";\nlet format = { prefix = #single(\"0x\") };\nlet result = BaseX.fromHex(hex, format);\n\nswitch (result) {\n  case (#ok(bytes)) {\n    // bytes is [0xA1, 0xB2, 0xC3]\n    Debug.print(\"Decoded successfully!\");\n  };\n  case (#err(error)) {\n    Debug.print(\"Error: \" # error);\n  };\n};\n```\n\n### Example 5: Base58 Encoding and Decoding\n\n```motoko\nimport BaseX \"mo:base-x-encoder\";\nimport Result \"mo:core/Result\";\nimport Debug \"mo:core/Debug\";\n\n// Example data\nlet data = [0x00, 0x01, 0x02].vals();\n\n// Encode to Base58\nlet encoded = BaseX.toBase58(data);\nDebug.print(encoded);\n\n// Decode from Base58\nlet result = BaseX.fromBase58(encoded);\nswitch (result) {\n  case (#ok(bytes)) {\n    // bytes should match the original data\n    Debug.print(\"Decoded successfully!\");\n  };\n  case (#err(error)) {\n    Debug.print(\"Error: \" # error);\n  };\n};\n```\n\n## API Reference\n\n### Types\n\n```motoko\npublic type HexInputFormat = {\n    prefix : HexPrefixKind;\n};\n\npublic type HexOutputFormat = {\n    isUpper : Bool;\n    prefix : HexPrefixKind;\n};\n\npublic type HexPrefixKind = {\n    #none;\n    #single : Text; // '0x' -\u003e 0xABCD\n    #perByte : Text; // '\\x' -\u003e \\xAB\\xCD\n};\n\npublic type Base64OutputFormat = {\n    #standard; // RFC 4648 Base64, with padding\n    #url; // RFC 4648 URL-safe Base64, no padding\n    #urlWithPadding; // RFC 4648 URL-safe Base64, with padding\n};\n\npublic type Base32OutputFormat = {\n    #standard : { isUpper : Bool }; // RFC 4648, A-Z + 2-7, with padding\n    #extendedHex : { isUpper : Bool }; // RFC 4648, 0-9 + A-V, with padding\n};\n\npublic type Base32InputFormat = {\n    #standard; // RFC 4648, A-Z + 2-7, with padding\n    #extendedHex; // RFC 4648, 0-9 + A-V, with padding\n};\n```\n\n### Base64 Functions\n\n```motoko\n// Convert bytes to Base64 string\npublic func toBase64(data : Iter.Iter\u003cNat8\u003e, format : Base64OutputFormat) : Text;\n\n// Decode Base64 string to bytes\npublic func fromBase64(text : Text) : Result.Result\u003c[Nat8], Text\u003e;\n```\n\n### Base32 Functions\n\n```motoko\n// Convert bytes to Base32 string\npublic func toBase32(data : Iter.Iter\u003cNat8\u003e, format: Base32OutputFormat) : Text;\n\n// Decode Base64 string to bytes\npublic func fromBase32(text : Text, format: Base32InputFormat) : Result.Result\u003c[Nat8], Text\u003e;\n```\n\n### Hexadecimal Functions\n\n```motoko\n// Convert bytes to hexadecimal string\npublic func toHex(data : Iter.Iter\u003cNat8\u003e, format : HexOutputFormat) : Text;\npublic func toBase16(data : Iter.Iter\u003cNat8\u003e, format : HexOutputFormat) : Text; // Alias for toHex\n\n// Decode hexadecimal string to bytes\npublic func fromHex(hex : Text, format : HexInputFormat) : Result.Result\u003c[Nat8], Text\u003e;\npublic func fromBase16(base16 : Text, format : HexInputFormat) : Result.Result\u003c[Nat8], Text\u003e; // Alias for fromHex\n```\n\n### Base58 Functions\n\n```motoko\n// Convert bytes to Base58 string\npublic func toBase58(bytes : Iter.Iter\u003cNat8\u003e) : Text;\n\n// Decode Base58 string to bytes\npublic func fromBase58(text : Text) : Result.Result\u003c[Nat8], Text\u003e;\n```\n\n## License\n\nThis project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Fmotoko_base_x","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fedjcase%2Fmotoko_base_x","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fedjcase%2Fmotoko_base_x/lists"}