This library implements 3 most popular encoding schemes: HEX (Base16), Base64, and Urlencode. The latter is extremely useful in building Data URLs with the %-encoding scheme.
Additionally, it implements base64url and a potatoes encoding scheme which is based on the standard HEX encoding but replaces the ABCDEF symbols with POTAES (all unique letters in "potatoes").
mvr add @potatoes/codecTo add this library to your project, add this to your Move.toml file under
[dependencies] section:
# goes into [dependencies] section
codec = { git = "https://github.com/sui-potatoes/app.git", subdir = "packages/codec", rev = "codec@v3" }Exported address of this package is:
codec = "0x..."In your code, import and use the package as:
module my::awesome_project;
use codec::hex;
public fun do() {
let _ = hex::encode("hey y'all");
}All of the modules in this package follow the same signature scheme to make it
intuitive to use. Every module consists of two public functions: encode and
decode, both stay the same in every scheme implementation. The String type
is always std::string::String.
use codec::hex;
use std::string::String;
// while the type annotation is not necessary, we've added it to be explicit
let encoded: String = hex::encode("hello, potato!"); // takes vector<u8>
let decoded: vector<u8> = hex::decode("DEADBEEF"); // takes StringEach encoding is placed into a separate module, here is a full list:
Implements the Base16 encoding scheme. The module is called hex.
use codec::hex;
use std::string::String;
let encoded: String = hex::encode("hello, potato!");
let decoded: vector<u8> = hex::decode("DEADBEEF");Implements the Base64 encoding scheme. The module is called base64.
use codec::base64;
use std::string::String;
let encoded: String = base64::encode("hello, potato!");
let decoded: vector<u8> = base64::decode("SGVsbG8sIHBvdGF0byE=");Implements the Base64url encoding - a URL-friendly modification of base64, using slightly different dictionary and lack of padding ==.
use codec::base64url;
use std::string::String;
let encoded: String = base64url::encode("hello, potato!");
let decoded: vector<u8> = base64url::decode("SGVsbG8sIHBvdGF0byE");Implements the URL encoding scheme. The module is called urlencode.
use codec::urlencode;
use std::string::String;
let encoded: String = urlencode::encode("hello, potato!");
let decoded: vector<u8> = urlencode::decode("hello%2C%20potato%21");Implements the POTAES encoding scheme. The module is called potatoes.
use codec::potatoes;
use std::string::String;
let encoded: String = potatoes::encode("hello, potato!");
let decoded: vector<u8> = potatoes::decode("10potatoes");- adds
base64urlencoding scheme - increases performance of encoding by 5%
- fixes bug in encoding of large values in
base64
- overall performance improvements
Adds encoding schemes:
hex.move- for Base16 (HEX)potatoes.move- for POTAES encoding, derivative of HEXbase64.move- for Base64 encodingurlencode.move- for URL encoding
This package is licensed under MIT.