diff --git a/ark/type/__tests__/integration/allConfig.ts b/ark/type/__tests__/integration/allConfig.ts index 2208e49f04..b9ba6e89d7 100644 --- a/ark/type/__tests__/integration/allConfig.ts +++ b/ark/type/__tests__/integration/allConfig.ts @@ -107,6 +107,9 @@ configure({ "string.hex": { description: "configured" }, + "string.base58": { + description: "configured" + }, "string.base64.url": { description: "configured" }, diff --git a/ark/type/__tests__/keywords/string.test.ts b/ark/type/__tests__/keywords/string.test.ts index 06fd5ae464..cf7b21bb72 100644 --- a/ark/type/__tests__/keywords/string.test.ts +++ b/ark/type/__tests__/keywords/string.test.ts @@ -34,6 +34,19 @@ contextualize(() => { ) }) + it("base58", () => { + const Base58 = type("string.base58") + attest(Base58("5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ")).snap( + "5HueCGU8rMjxEXxiPuD5BDku4MkFqeZyd4dZ1jvhTVqvbTLvyTJ" + ) + attest(Base58("abc123")).snap("abc123") + attest(Base58("0").toString()).snap('must be base58-encoded (was "0")') + attest(Base58("O").toString()).snap('must be base58-encoded (was "O")') + attest(Base58("I").toString()).snap('must be base58-encoded (was "I")') + attest(Base58("l").toString()).snap('must be base58-encoded (was "l")') + attest(Base58("").toString()).snap('must be base58-encoded (was "")') + }) + it("base64", () => { const B64 = type("string.base64") attest(B64("fn5+")).snap("fn5+") diff --git a/ark/type/keywords/string.ts b/ark/type/keywords/string.ts index 05064933b5..ab00af8d91 100644 --- a/ark/type/keywords/string.ts +++ b/ark/type/keywords/string.ts @@ -80,6 +80,8 @@ export declare namespace stringInteger { const hex = regexStringNode(/^[\dA-Fa-f]+$/, "hex characters only") +const base58 = regexStringNode(/^[1-9A-HJ-NP-Za-km-z]+$/, "base58-encoded") + const base64 = Scope.module( { root: regexStringNode( @@ -911,6 +913,7 @@ export const string = Scope.module( "only letters and digits 0-9" ), hex, + base58, base64, capitalize, creditCard, @@ -945,6 +948,7 @@ export declare namespace string { alpha: string alphanumeric: string hex: string + base58: string base64: base64.submodule capitalize: capitalize.submodule creditCard: string