or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

auth.mdcore-protocol.mdcrypto.mdindex.mdrelay.mdsession-management.mdsign-client.md

crypto.mddocs/

0

# Cryptographic Types

1

2

Cryptographic operations and type definitions for WalletConnect Protocol including key management, encryption/decryption, and secure message encoding/decoding.

3

4

## Capabilities

5

6

### Crypto Interface

7

8

Main cryptographic operations interface for key management and secure message handling throughout the protocol.

9

10

```typescript { .api }

11

/**

12

* Cryptographic operations interface for key management, encoding/decoding

13

* Handles all cryptographic operations in the WalletConnect protocol

14

*/

15

interface ICrypto extends IEvents {

16

readonly name: string;

17

readonly context: string;

18

19

/** Initialize the crypto module */

20

init(): Promise<void>;

21

/** Check if keys exist for given tag */

22

hasKeys(tag: string): boolean;

23

/** Get client ID derived from keys */

24

getClientId(): Promise<string>;

25

/** Generate a new key pair and return public key */

26

generateKeyPair(): Promise<string>;

27

/** Generate shared key from self and peer public keys */

28

generateSharedKey(self: string, peer: string, overrideTopic?: string): Promise<string>;

29

/** Set symmetric key with optional topic override */

30

setSymKey(symKey: string, overrideTopic?: string): Promise<string>;

31

/** Delete key pair by public key */

32

deleteKeyPair(publicKey: string): Promise<void>;

33

/** Delete symmetric key by topic */

34

deleteSymKey(topic: string): Promise<void>;

35

/** Encode payload with encryption */

36

encode(topic: string, payload: JsonRpcPayload, opts?: CryptoTypes.EncodeOptions): Promise<string>;

37

/** Decode encrypted message */

38

decode(topic: string, encrypted: string, opts?: CryptoTypes.DecodeOptions): Promise<JsonRpcPayload>;

39

}

40

```

41

42

### Key Management Types

43

44

Type definitions for cryptographic key structures and key pair management.

45

46

```typescript { .api }

47

namespace CryptoTypes {

48

/**

49

* Private/public key pair structure

50

*/

51

interface KeyPair {

52

/** Private key in hex format */

53

privateKey: string;

54

/** Public key in hex format */

55

publicKey: string;

56

}

57

58

/**

59

* Public key holder in cryptographic operations

60

*/

61

interface Participant {

62

/** Public key identifier */

63

publicKey: string;

64

}

65

}

66

```

67

68

### Encryption/Decryption Types

69

70

Parameters and options for encryption and decryption operations with support for different encryption types.

71

72

```typescript { .api }

73

namespace CryptoTypes {

74

/**

75

* Parameters for encryption operations

76

*/

77

interface EncryptParams {

78

/** Message content to encrypt */

79

message: string;

80

/** Symmetric key for encryption */

81

symKey: string;

82

/** Encryption type (optional) */

83

type?: number;

84

/** Initialization vector (optional) */

85

iv?: string;

86

/** Sender's public key for authenticated encryption (optional) */

87

senderPublicKey?: string;

88

}

89

90

/**

91

* Parameters for decryption operations

92

*/

93

interface DecryptParams {

94

/** Symmetric key for decryption */

95

symKey: string;

96

/** Encrypted/encoded message */

97

encoded: string;

98

}

99

100

/**

101

* Type 1 encryption parameters with sender/receiver keys

102

* Used for authenticated encryption with key exchange

103

*/

104

interface TypeOneParams {

105

/** Sender's public key */

106

senderPublicKey: string;

107

/** Receiver's public key */

108

receiverPublicKey: string;

109

}

110

}

111

```

112

113

### Encoding/Decoding Types

114

115

Low-level and high-level encoding/decoding parameters for message serialization and validation.

116

117

```typescript { .api }

118

namespace CryptoTypes {

119

/**

120

* Encoding format options for message serialization

121

*/

122

type EncodingType = "base64pad" | "base64url";

123

124

/**

125

* Low-level encoding parameters with Uint8Arrays

126

*/

127

interface EncodingParams {

128

/** Message as byte array */

129

message: Uint8Array;

130

/** Symmetric key as byte array */

131

symKey: Uint8Array;

132

/** Initialization vector as byte array */

133

iv: Uint8Array;

134

}

135

136

/**

137

* Low-level decoding parameters

138

*/

139

interface DecodingParams {

140

/** Symmetric key as byte array */

141

symKey: Uint8Array;

142

/** Encoded message as byte array */

143

encoded: Uint8Array;

144

}

145

146

/**

147

* High-level encoding options

148

*/

149

interface EncodeOptions {

150

/** Encoding type for output format */

151

type?: EncodingType;

152

/** Sender's public key (optional) */

153

senderPublicKey?: string;

154

/** Receiver's public key (optional) */

155

receiverPublicKey?: string;

156

}

157

158

/**

159

* High-level decoding options

160

*/

161

interface DecodeOptions {

162

/** Receiver's public key (optional) */

163

receiverPublicKey?: string;

164

}

165

166

/**

167

* Validation parameters for encoding operations

168

*/

169

interface EncodingValidation {

170

/** Message content to validate */

171

message: string;

172

/** Symmetric key to validate */

173

symKey: string;

174

}

175

}

176

```

177

178

**Usage Examples:**

179

180

```typescript

181

import { ICrypto, CryptoTypes } from "@walletconnect/types";

182

183

// Generate a key pair

184

const publicKey = await crypto.generateKeyPair();

185

186

// Generate shared key for secure communication

187

const sharedKey = await crypto.generateSharedKey(selfPublicKey, peerPublicKey);

188

189

// Encrypt a message

190

const encrypted = await crypto.encode(topic, {

191

id: 1,

192

jsonrpc: "2.0",

193

method: "wc_sessionPropose",

194

params: proposalParams

195

});

196

197

// Decrypt a message

198

const decrypted = await crypto.decode(topic, encrypted);

199

200

// Key pair structure

201

const keyPair: CryptoTypes.KeyPair = {

202

privateKey: "0x...",

203

publicKey: "0x..."

204

};

205

206

// Encryption parameters

207

const encryptParams: CryptoTypes.EncryptParams = {

208

message: "Hello, WalletConnect!",

209

symKey: "0x...",

210

type: 1,

211

senderPublicKey: "0x..."

212

};

213

```