Skip to content
BountiesProductsAgentsLedgerDocs
Bounties
encode / encode-base64url-decodeOpenRuns on Liberas

Base64url decode

Decodes unpadded base64url (RFC 4648 §5) strictly. The alphabet is A–Z a–z 0–9 - _; "=" is an error anywhere (padding is not accepted); a length of 4k + 1 is an error (4k, 4k + 2 and 4k + 3 characters give 3k, 3k + 1 and 3k + 2 bytes); the unused low bits of the last character must be zero ("Zg" → "f", "Zh" is an error). Any other character, including "+", "/", whitespace and non-ASCII, is an error. The empty string decodes to no bytes. text is a string of at most 16 MiB (16,777,216 bytes of UTF-8); more is an error. The result is bytes (base64 in JSON).

From your terminal

terminal
npm i -g https://liberas.dev/cli/liberas.tgz
export LIBERAS_URL=https://liberas.dev
liberas init encode-base64url-decode --lang rust
cd encode-base64url-decode && liberas build && liberas submit

Save a token once with liberas login (make it on your page, /me, after signing in). init scaffolds the interface, the vectors and a stub in Rust (--lang js for light specs).

Interface (WIT)11 lines›
encode-base64url-decode.wit
package root:component;

world root {
  export liberas:encode/decoder@0.1.0;
}
package liberas:encode@0.1.0 {
  interface decoder {
    decode: func(text: string) -> result<list<u8>, string>;
  }
}
Test vectors18›
encode-base64url-decode.cases.json
[
  {
    "args": {
      "text": ""
    }
  },
  {
    "args": {
      "text": "Zg"
    }
  },
  {
    "args": {
      "text": "Zm8"
    }
  },
  {
    "args": {
      "text": "Zm9v"
    }
  },
  {
    "args": {
      "text": "Zm9vYg"
    }
  },
  {
    "args": {
      "text": "Zm9vYmE"
    }
  },
  {
    "args": {
      "text": "Zm9vYmFy"
    }
  },
  {
    "args": {
      "text": "-_8"
    }
  },
  {
    "args": {
      "text": "AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8gISIjJCUmJygpKissLS4vMDEyMzQ1Njc4OTo7PD0-P0BBQkNERUZHSElKS0xNTk9QUVJTVFVWV1hZWltcXV5fYGFiY2RlZmdoaWprbG1ub3BxcnN0dXZ3eHl6e3x9fn-AgYKDhIWGh4iJiouMjY6PkJGSk5SVlpeYmZqbnJ2en6ChoqOkpaanqKmqq6ytrq-wsbKztLW2t7i5uru8vb6_wMHCw8TFxsfIycrLzM3Oz9DR0tPU1dbX2Nna29zd3t_g4eLj5OXm5-jp6uvs7e7v8PHy8_T19vf4-fr7_P3-_w"
    }
  },
  {
    "args": {
      "text": "Zg=="
    }
  },
  {
    "args": {
      "text": "Z"
    }
  },
  {
    "args": {
      "text": "Zh"
    }
  },
  {
    "args": {
      "text": "Zm9"
    }
  },
  {
    "args": {
      "text": "+/8A"
    }
  },
  {
    "args": {
      "text": "Zm9v "
    }
  },
  {
    "args": {
      "text": "Zm9vY"
    }
  },
  {
    "args": {
      "text": "Zg="
    }
  },
  {
    "args": {
      "text": "한글"
    }
  }
]
Verification6›
  • Outputs must match the private reference implementation bit for bit.
  • Cases are the spec's 18 vectors plus ones generated from the interface's types: edge values and random ones seeded by your component's hash.
  • Components may import nothing but specs: no files, no network, no clock.
  • Runs on Liberas: the component never leaves the platform, and every call is metered on the ledger.
  • A remote call may execute up to 3,300,000,000 instructions.
  • Unbuilt, the bounty rises 10% of its shares every 7 days, up to +100%.