or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

address.mdbase-encoding.mdcrypto-init.mdethereum.mdhashing.mdindex.mdjson-encryption.mdkey-derivation-pbkdf.mdkey-derivation.mdkeypairs.mdmnemonic.mdrandom.mdsignatures.md

base-encoding.mddocs/

0

# Base Encoding

1

2

Encoding and decoding utilities for Base32, Base58, and Base64 formats with validation and IPFS compatibility options.

3

4

## Capabilities

5

6

### Base58 Encoding

7

8

Base58 encoding commonly used in blockchain addresses and identifiers.

9

10

```typescript { .api }

11

/**

12

* Encode bytes to Base58 string

13

* @param value - Bytes to encode

14

* @param ipfsCompat - Use IPFS-compatible alphabet

15

* @returns Base58 encoded string

16

*/

17

function base58Encode(value: Uint8Array, ipfsCompat?: boolean): string;

18

19

/**

20

* Decode Base58 string to bytes

21

* @param value - Base58 string to decode

22

* @param ipfsCompat - Use IPFS-compatible alphabet

23

* @returns Decoded bytes

24

*/

25

function base58Decode(value: string, ipfsCompat?: boolean): Uint8Array;

26

27

/**

28

* Validate Base58 string format

29

* @param value - String to validate

30

* @returns true if valid Base58

31

*/

32

function base58Validate(value: string): boolean;

33

34

/**

35

* Check if string is Base58 encoded

36

* @param value - String to check

37

* @returns true if Base58 format

38

*/

39

function isBase58(value: string): boolean;

40

```

41

42

### Base64 Encoding

43

44

Standard Base64 encoding with padding utilities.

45

46

```typescript { .api }

47

/**

48

* Encode bytes to Base64 string

49

* @param value - Bytes to encode

50

* @returns Base64 encoded string

51

*/

52

function base64Encode(value: Uint8Array): string;

53

54

/**

55

* Decode Base64 string to bytes

56

* @param value - Base64 string to decode

57

* @returns Decoded bytes

58

*/

59

function base64Decode(value: string): Uint8Array;

60

61

/**

62

* Validate Base64 string format

63

* @param value - String to validate

64

* @returns true if valid Base64

65

*/

66

function base64Validate(value: string): boolean;

67

68

/**

69

* Check if string is Base64 encoded

70

* @param value - String to check

71

* @returns true if Base64 format

72

*/

73

function isBase64(value: string): boolean;

74

75

/**

76

* Add padding to Base64 string

77

* @param value - Base64 string

78

* @returns Padded Base64 string

79

*/

80

function base64Pad(value: string): string;

81

82

/**

83

* Remove padding from Base64 string

84

* @param value - Padded Base64 string

85

* @returns Trimmed Base64 string

86

*/

87

function base64Trim(value: string): string;

88

```

89

90

### Base32 Encoding

91

92

Base32 encoding with IPFS compatibility.

93

94

```typescript { .api }

95

/**

96

* Encode bytes to Base32 string

97

* @param value - Bytes to encode

98

* @param ipfsCompat - Use IPFS-compatible alphabet

99

* @returns Base32 encoded string

100

*/

101

function base32Encode(value: Uint8Array, ipfsCompat?: boolean): string;

102

103

/**

104

* Decode Base32 string to bytes

105

* @param value - Base32 string to decode

106

* @param ipfsCompat - Use IPFS-compatible alphabet

107

* @returns Decoded bytes

108

*/

109

function base32Decode(value: string, ipfsCompat?: boolean): Uint8Array;

110

111

/**

112

* Validate Base32 string format

113

* @param value - String to validate

114

* @returns true if valid Base32

115

*/

116

function base32Validate(value: string): boolean;

117

118

/**

119

* Check if string is Base32 encoded

120

* @param value - String to check

121

* @returns true if Base32 format

122

*/

123

function isBase32(value: string): boolean;

124

```

125

126

## Usage Examples

127

128

```typescript

129

import {

130

base58Encode,

131

base58Decode,

132

base64Encode,

133

base64Decode,

134

base32Encode,

135

base32Decode

136

} from "@polkadot/util-crypto";

137

138

const data = new TextEncoder().encode("Hello World");

139

140

// Base58

141

const base58 = base58Encode(data);

142

const decoded58 = base58Decode(base58);

143

144

// Base64

145

const base64 = base64Encode(data);

146

const decoded64 = base64Decode(base64);

147

148

// Base32

149

const base32 = base32Encode(data);

150

const decoded32 = base32Decode(base32);

151

```