or run

npx @tessl/cli init
Log in

Version

Tile

Overview

Evals

Files

Files

docs

advanced-sha3.mdcore-hashing.mdhmac-operations.mdindex.mdvariant-classes.md
tile.json

variant-classes.mddocs/

0

# Variant-Specific Classes

1

2

Optimized classes for specific SHA variants, designed for smaller bundle sizes when only particular hash algorithms are needed. These classes provide the same functionality as the universal `jsSHA` class but are limited to their respective SHA variants.

3

4

## Capabilities

5

6

### jsSHA1 - SHA-1 Implementation

7

8

Dedicated class for SHA-1 hashing with HMAC support.

9

10

```typescript { .api }

11

/**

12

* SHA-1 implementation for TEXT input format

13

* @param variant - Must be "SHA-1"

14

* @param inputFormat - Must be "TEXT"

15

* @param options - Optional configuration including encoding and HMAC key

16

*/

17

constructor(variant: "SHA-1", inputFormat: "TEXT", options?: FixedLengthOptionsEncodingType);

18

19

/**

20

* SHA-1 implementation for binary input formats

21

* @param variant - Must be "SHA-1"

22

* @param inputFormat - Binary format: HEX, B64, BYTES, ARRAYBUFFER, UINT8ARRAY

23

* @param options - Optional configuration including HMAC key and numRounds

24

*/

25

constructor(variant: "SHA-1", inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);

26

27

/**

28

* Stream input data for hashing

29

* @param input - Input data matching the constructor inputFormat

30

* @returns Reference to this object for method chaining

31

*/

32

update(input: string | ArrayBuffer | Uint8Array): this;

33

34

/**

35

* Get the computed hash in the specified format

36

* @param format - Output format: HEX, B64, BYTES, UINT8ARRAY, ARRAYBUFFER

37

* @param options - Optional formatting options

38

* @returns Hash in the specified format

39

*/

40

getHash(format: "HEX", options?: { outputUpper?: boolean }): string;

41

getHash(format: "B64", options?: { b64Pad?: string }): string;

42

getHash(format: "BYTES"): string;

43

getHash(format: "UINT8ARRAY"): Uint8Array;

44

getHash(format: "ARRAYBUFFER"): ArrayBuffer;

45

46

/**

47

* Set HMAC key (deprecated - use constructor options instead)

48

* @param key - HMAC key

49

* @param inputFormat - Key format

50

* @param options - Optional encoding for TEXT keys

51

*/

52

setHMACKey(key: string, inputFormat: "TEXT", options?: { encoding?: EncodingType }): void;

53

setHMACKey(key: string, inputFormat: "B64" | "HEX" | "BYTES"): void;

54

setHMACKey(key: ArrayBuffer, inputFormat: "ARRAYBUFFER"): void;

55

setHMACKey(key: Uint8Array, inputFormat: "UINT8ARRAY"): void;

56

57

/**

58

* Get HMAC output (deprecated - use getHash instead)

59

* @param format - Output format

60

* @param options - Optional formatting options

61

* @returns HMAC in the specified format

62

*/

63

getHMAC(format: "HEX", options?: { outputUpper?: boolean }): string;

64

getHMAC(format: "B64", options?: { b64Pad?: string }): string;

65

getHMAC(format: "BYTES"): string;

66

getHMAC(format: "UINT8ARRAY"): Uint8Array;

67

getHMAC(format: "ARRAYBUFFER"): ArrayBuffer;

68

69

type FormatNoTextType = "HEX" | "B64" | "BYTES" | "ARRAYBUFFER" | "UINT8ARRAY";

70

type EncodingType = "UTF8" | "UTF16BE" | "UTF16LE";

71

72

interface GenericInputType {

73

value: string;

74

format: "TEXT";

75

encoding?: EncodingType;

76

} | {

77

value: string;

78

format: "B64" | "HEX" | "BYTES";

79

} | {

80

value: ArrayBuffer;

81

format: "ARRAYBUFFER";

82

} | {

83

value: Uint8Array;

84

format: "UINT8ARRAY";

85

}

86

87

interface packedValue {

88

value: number[];

89

binLen: number;

90

}

91

92

interface FixedLengthOptionsEncodingType {

93

hmacKey?: GenericInputType;

94

encoding?: EncodingType;

95

} | {

96

numRounds?: number;

97

encoding?: EncodingType;

98

}

99

100

interface FixedLengthOptionsNoEncodingType {

101

hmacKey?: GenericInputType;

102

} | {

103

numRounds?: number;

104

}

105

106

interface SHAKEOptionsEncodingType {

107

numRounds?: number;

108

encoding?: EncodingType;

109

}

110

111

interface SHAKEOptionsNoEncodingType {

112

numRounds?: number;

113

}

114

115

interface CSHAKEOptionsEncodingType {

116

customization?: GenericInputType;

117

funcName?: GenericInputType;

118

encoding?: EncodingType;

119

}

120

121

interface CSHAKEOptionsNoEncodingType {

122

customization?: GenericInputType;

123

funcName?: GenericInputType;

124

}

125

126

interface KMACOptionsEncodingType {

127

kmacKey: GenericInputType;

128

customization?: GenericInputType;

129

encoding?: EncodingType;

130

}

131

132

interface KMACOptionsNoEncodingType {

133

kmacKey: GenericInputType;

134

customization?: GenericInputType;

135

}

136

```

137

138

**Usage Examples:**

139

140

```typescript

141

import jsSHA1 from "jssha/sha1";

142

143

// Basic SHA-1 hashing

144

const sha1 = new jsSHA1("SHA-1", "TEXT", { encoding: "UTF8" });

145

sha1.update("Hello, World!");

146

const hash = sha1.getHash("HEX");

147

148

// SHA-1 with HMAC

149

const hmacSha1 = new jsSHA1("SHA-1", "TEXT", {

150

hmacKey: { value: "secret", format: "TEXT" }

151

});

152

hmacSha1.update("Message to authenticate");

153

const hmac = hmacSha1.getHash("B64");

154

155

// SHA-1 with hex input

156

const sha1Hex = new jsSHA1("SHA-1", "HEX");

157

sha1Hex.update("48656c6c6f"); // "Hello" in hex

158

const result = sha1Hex.getHash("UINT8ARRAY");

159

```

160

161

### jsSHA256 - SHA-224/256 Implementation

162

163

Dedicated class for SHA-224 and SHA-256 hashing with HMAC support.

164

165

```typescript { .api }

166

/**

167

* SHA-224/256 implementation for TEXT input format

168

* @param variant - SHA variant: "SHA-224" or "SHA-256"

169

* @param inputFormat - Must be "TEXT"

170

* @param options - Optional configuration including encoding and HMAC key

171

*/

172

constructor(variant: "SHA-224" | "SHA-256", inputFormat: "TEXT", options?: FixedLengthOptionsEncodingType);

173

174

/**

175

* SHA-224/256 implementation for binary input formats

176

* @param variant - SHA variant: "SHA-224" or "SHA-256"

177

* @param inputFormat - Binary format: HEX, B64, BYTES, ARRAYBUFFER, UINT8ARRAY

178

* @param options - Optional configuration including HMAC key and numRounds

179

*/

180

constructor(variant: "SHA-224" | "SHA-256", inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);

181

182

// Methods are identical to jsSHA1

183

update(input: string | ArrayBuffer | Uint8Array): this;

184

getHash(format: "HEX", options?: { outputUpper?: boolean }): string;

185

getHash(format: "B64", options?: { b64Pad?: string }): string;

186

getHash(format: "BYTES"): string;

187

getHash(format: "UINT8ARRAY"): Uint8Array;

188

getHash(format: "ARRAYBUFFER"): ArrayBuffer;

189

setHMACKey(key: string, inputFormat: "TEXT", options?: { encoding?: EncodingType }): void;

190

setHMACKey(key: string, inputFormat: "B64" | "HEX" | "BYTES"): void;

191

setHMACKey(key: ArrayBuffer, inputFormat: "ARRAYBUFFER"): void;

192

setHMACKey(key: Uint8Array, inputFormat: "UINT8ARRAY"): void;

193

getHMAC(format: "HEX", options?: { outputUpper?: boolean }): string;

194

getHMAC(format: "B64", options?: { b64Pad?: string }): string;

195

getHMAC(format: "BYTES"): string;

196

getHMAC(format: "UINT8ARRAY"): Uint8Array;

197

getHMAC(format: "ARRAYBUFFER"): ArrayBuffer;

198

```

199

200

**Usage Examples:**

201

202

```typescript

203

import jsSHA256 from "jssha/sha256";

204

205

// SHA-256 hashing

206

const sha256 = new jsSHA256("SHA-256", "TEXT", { encoding: "UTF8" });

207

sha256.update("Hello, World!");

208

const hash256 = sha256.getHash("HEX");

209

210

// SHA-224 hashing

211

const sha224 = new jsSHA256("SHA-224", "TEXT");

212

sha224.update("Hello, World!");

213

const hash224 = sha224.getHash("HEX");

214

215

// SHA-256 with HMAC

216

const hmac256 = new jsSHA256("SHA-256", "TEXT", {

217

hmacKey: { value: "secret-key", format: "TEXT" }

218

});

219

hmac256.update("Authenticated message");

220

const authHash = hmac256.getHash("B64");

221

222

// Multiple rounds

223

const multiRound = new jsSHA256("SHA-256", "TEXT", { numRounds: 3 });

224

multiRound.update("Repeated hashing");

225

const repeatedHash = multiRound.getHash("HEX");

226

```

227

228

### jsSHA512 - SHA-384/512 Implementation

229

230

Dedicated class for SHA-384 and SHA-512 hashing with HMAC support.

231

232

```typescript { .api }

233

/**

234

* SHA-384/512 implementation for TEXT input format

235

* @param variant - SHA variant: "SHA-384" or "SHA-512"

236

* @param inputFormat - Must be "TEXT"

237

* @param options - Optional configuration including encoding and HMAC key

238

*/

239

constructor(variant: "SHA-384" | "SHA-512", inputFormat: "TEXT", options?: FixedLengthOptionsEncodingType);

240

241

/**

242

* SHA-384/512 implementation for binary input formats

243

* @param variant - SHA variant: "SHA-384" or "SHA-512"

244

* @param inputFormat - Binary format: HEX, B64, BYTES, ARRAYBUFFER, UINT8ARRAY

245

* @param options - Optional configuration including HMAC key and numRounds

246

*/

247

constructor(variant: "SHA-384" | "SHA-512", inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);

248

249

// Methods are identical to jsSHA1 and jsSHA256

250

update(input: string | ArrayBuffer | Uint8Array): this;

251

getHash(format: "HEX", options?: { outputUpper?: boolean }): string;

252

getHash(format: "B64", options?: { b64Pad?: string }): string;

253

getHash(format: "BYTES"): string;

254

getHash(format: "UINT8ARRAY"): Uint8Array;

255

getHash(format: "ARRAYBUFFER"): ArrayBuffer;

256

setHMACKey(key: string, inputFormat: "TEXT", options?: { encoding?: EncodingType }): void;

257

setHMACKey(key: string, inputFormat: "B64" | "HEX" | "BYTES"): void;

258

setHMACKey(key: ArrayBuffer, inputFormat: "ARRAYBUFFER"): void;

259

setHMACKey(key: Uint8Array, inputFormat: "UINT8ARRAY"): void;

260

getHMAC(format: "HEX", options?: { outputUpper?: boolean }): string;

261

getHMAC(format: "B64", options?: { b64Pad?: string }): string;

262

getHMAC(format: "BYTES"): string;

263

getHMAC(format: "UINT8ARRAY"): Uint8Array;

264

getHMAC(format: "ARRAYBUFFER"): ArrayBuffer;

265

```

266

267

**Usage Examples:**

268

269

```typescript

270

import jsSHA512 from "jssha/sha512";

271

272

// SHA-512 hashing

273

const sha512 = new jsSHA512("SHA-512", "TEXT", { encoding: "UTF8" });

274

sha512.update("Hello, World!");

275

const hash512 = sha512.getHash("HEX");

276

277

// SHA-384 hashing

278

const sha384 = new jsSHA512("SHA-384", "TEXT");

279

sha384.update("Hello, World!");

280

const hash384 = sha384.getHash("HEX");

281

282

// SHA-512 with ArrayBuffer input

283

const sha512Buffer = new jsSHA512("SHA-512", "ARRAYBUFFER");

284

const buffer = new TextEncoder().encode("Hello").buffer;

285

sha512Buffer.update(buffer);

286

const bufferHash = sha512Buffer.getHash("UINT8ARRAY");

287

288

// SHA-384 HMAC with Uint8Array key

289

const keyArray = new TextEncoder().encode("secret-key");

290

const hmac384 = new jsSHA512("SHA-384", "TEXT", {

291

hmacKey: { value: keyArray, format: "UINT8ARRAY" }

292

});

293

hmac384.update("Message for HMAC");

294

const hmacResult = hmac384.getHash("ARRAYBUFFER");

295

```

296

297

### jsSHA3 - SHA3/SHAKE/cSHAKE/KMAC Implementation

298

299

Comprehensive class for all SHA-3 family algorithms including fixed-length SHA3 variants, variable-length SHAKE algorithms, customizable cSHAKE, and KMAC authentication.

300

301

```typescript { .api }

302

/**

303

* SHA3 fixed-length variants for TEXT input format

304

* @param variant - SHA3 variant: "SHA3-224", "SHA3-256", "SHA3-384", "SHA3-512"

305

* @param inputFormat - Must be "TEXT"

306

* @param options - Optional configuration including encoding and HMAC key

307

*/

308

constructor(variant: "SHA3-224" | "SHA3-256" | "SHA3-384" | "SHA3-512", inputFormat: "TEXT", options?: FixedLengthOptionsEncodingType);

309

310

/**

311

* SHA3 fixed-length variants for binary input formats

312

* @param variant - SHA3 variant: "SHA3-224", "SHA3-256", "SHA3-384", "SHA3-512"

313

* @param inputFormat - Binary format: HEX, B64, BYTES, ARRAYBUFFER, UINT8ARRAY

314

* @param options - Optional configuration including HMAC key and numRounds

315

*/

316

constructor(variant: "SHA3-224" | "SHA3-256" | "SHA3-384" | "SHA3-512", inputFormat: FormatNoTextType, options?: FixedLengthOptionsNoEncodingType);

317

318

/**

319

* SHAKE variants for TEXT input format

320

* @param variant - SHAKE variant: "SHAKE128" or "SHAKE256"

321

* @param inputFormat - Must be "TEXT"

322

* @param options - Optional configuration including encoding and numRounds

323

*/

324

constructor(variant: "SHAKE128" | "SHAKE256", inputFormat: "TEXT", options?: SHAKEOptionsEncodingType);

325

326

/**

327

* SHAKE variants for binary input formats

328

* @param variant - SHAKE variant: "SHAKE128" or "SHAKE256"

329

* @param inputFormat - Binary format: HEX, B64, BYTES, ARRAYBUFFER, UINT8ARRAY

330

* @param options - Optional configuration including numRounds

331

*/

332

constructor(variant: "SHAKE128" | "SHAKE256", inputFormat: FormatNoTextType, options?: SHAKEOptionsNoEncodingType);

333

334

/**

335

* cSHAKE variants for TEXT input format

336

* @param variant - cSHAKE variant: "CSHAKE128" or "CSHAKE256"

337

* @param inputFormat - Must be "TEXT"

338

* @param options - Optional customization including funcName and customization

339

*/

340

constructor(variant: "CSHAKE128" | "CSHAKE256", inputFormat: "TEXT", options?: CSHAKEOptionsEncodingType);

341

342

/**

343

* cSHAKE variants for binary input formats

344

* @param variant - cSHAKE variant: "CSHAKE128" or "CSHAKE256"

345

* @param inputFormat - Binary format: HEX, B64, BYTES, ARRAYBUFFER, UINT8ARRAY

346

* @param options - Optional customization including funcName and customization

347

*/

348

constructor(variant: "CSHAKE128" | "CSHAKE256", inputFormat: FormatNoTextType, options?: CSHAKEOptionsNoEncodingType);

349

350

/**

351

* KMAC variants for TEXT input format

352

* @param variant - KMAC variant: "KMAC128" or "KMAC256"

353

* @param inputFormat - Must be "TEXT"

354

* @param options - Required kmacKey and optional customization

355

*/

356

constructor(variant: "KMAC128" | "KMAC256", inputFormat: "TEXT", options: KMACOptionsEncodingType);

357

358

/**

359

* KMAC variants for binary input formats

360

* @param variant - KMAC variant: "KMAC128" or "KMAC256"

361

* @param inputFormat - Binary format: HEX, B64, BYTES, ARRAYBUFFER, UINT8ARRAY

362

* @param options - Required kmacKey and optional customization

363

*/

364

constructor(variant: "KMAC128" | "KMAC256", inputFormat: FormatNoTextType, options: KMACOptionsNoEncodingType);

365

366

// Standard methods

367

update(input: string | ArrayBuffer | Uint8Array): this;

368

getHash(format: "HEX", options?: { outputUpper?: boolean; outputLen?: number; shakeLen?: number }): string;

369

getHash(format: "B64", options?: { b64Pad?: string; outputLen?: number; shakeLen?: number }): string;

370

getHash(format: "BYTES", options?: { outputLen?: number; shakeLen?: number }): string;

371

getHash(format: "UINT8ARRAY", options?: { outputLen?: number; shakeLen?: number }): Uint8Array;

372

getHash(format: "ARRAYBUFFER", options?: { outputLen?: number; shakeLen?: number }): ArrayBuffer;

373

setHMACKey(key: string, inputFormat: "TEXT", options?: { encoding?: EncodingType }): void;

374

setHMACKey(key: string, inputFormat: "B64" | "HEX" | "BYTES"): void;

375

setHMACKey(key: ArrayBuffer, inputFormat: "ARRAYBUFFER"): void;

376

setHMACKey(key: Uint8Array, inputFormat: "UINT8ARRAY"): void;

377

getHMAC(format: "HEX", options?: { outputUpper?: boolean }): string;

378

getHMAC(format: "B64", options?: { b64Pad?: string }): string;

379

getHMAC(format: "BYTES"): string;

380

getHMAC(format: "UINT8ARRAY"): Uint8Array;

381

getHMAC(format: "ARRAYBUFFER"): ArrayBuffer;

382

383

// SHA3-specific protected methods (not typically used directly)

384

protected _initializeCSHAKE(options?: CSHAKEOptionsNoEncodingType, funcNameOverride?: packedValue): number;

385

protected _initializeKMAC(options: KMACOptionsNoEncodingType): void;

386

protected _getKMAC(options: { outputLen: number }): number[];

387

```

388

389

**Usage Examples:**

390

391

```typescript

392

import jsSHA3 from "jssha/sha3";

393

394

// SHA3-256 hashing

395

const sha3_256 = new jsSHA3("SHA3-256", "TEXT", { encoding: "UTF8" });

396

sha3_256.update("Hello, SHA3!");

397

const sha3Hash = sha3_256.getHash("HEX");

398

399

// SHAKE128 with variable output

400

const shake128 = new jsSHA3("SHAKE128", "TEXT");

401

shake128.update("Hello, SHAKE!");

402

const shake256bit = shake128.getHash("HEX", { outputLen: 256 });

403

const shake512bit = shake128.getHash("HEX", { outputLen: 512 });

404

405

// cSHAKE256 with customization

406

const cshake = new jsSHA3("CSHAKE256", "TEXT", {

407

customization: { value: "MyApp", format: "TEXT" },

408

funcName: { value: "KeyGen", format: "TEXT" }

409

});

410

cshake.update("Key material");

411

const customHash = cshake.getHash("B64", { outputLen: 384 });

412

413

// KMAC128 for authentication

414

const kmac = new jsSHA3("KMAC128", "TEXT", {

415

kmacKey: { value: "authentication-key", format: "TEXT" },

416

customization: { value: "APIAuth", format: "TEXT" }

417

});

418

kmac.update("Message to authenticate");

419

const mac = kmac.getHash("HEX", { outputLen: 256 });

420

421

// SHA3-512 with hex input

422

const sha3Hex = new jsSHA3("SHA3-512", "HEX");

423

sha3Hex.update("deadbeefcafebabe");

424

const hexResult = sha3Hex.getHash("UINT8ARRAY");

425

```

426

427

## Bundle Size Optimization

428

429

Using variant-specific classes can significantly reduce bundle size when only specific algorithms are needed:

430

431

```typescript

432

// Large bundle - includes all SHA variants

433

import jsSHA from "jssha"; // ~23KB (full library)

434

435

// Smaller bundles - only specific variants

436

import jsSHA1 from "jssha/sha1"; // ~10KB (SHA-1 only)

437

import jsSHA256 from "jssha/sha256"; // ~11KB (SHA-224/256 only)

438

import jsSHA512 from "jssha/sha512"; // ~14KB (SHA-384/512 only)

439

import jsSHA3 from "jssha/sha3"; // ~13KB (SHA3/SHAKE/cSHAKE/KMAC only)

440

441

// Example: Application only needs SHA-256

442

import jsSHA256 from "jssha/sha256";

443

444

const hash = new jsSHA256("SHA-256", "TEXT");

445

hash.update("Only need SHA-256");

446

const result = hash.getHash("HEX");

447

```

448

449

## Module Loading Patterns

450

451

### ES Modules (Recommended)

452

453

```typescript

454

// Modern ES module imports

455

import jsSHA1 from "jssha/sha1";

456

import jsSHA256 from "jssha/sha256";

457

import jsSHA512 from "jssha/sha512";

458

import jsSHA3 from "jssha/sha3";

459

460

// Use specific variant

461

const sha256 = new jsSHA256("SHA-256", "TEXT");

462

```

463

464

### CommonJS (Node.js)

465

466

```javascript

467

// CommonJS imports (Node.js v13+ with subpath exports)

468

const jsSHA1 = require("jssha/sha1");

469

const jsSHA256 = require("jssha/sha256");

470

const jsSHA512 = require("jssha/sha512");

471

const jsSHA3 = require("jssha/sha3");

472

473

// For older Node.js versions without subpath exports

474

const jsSHA1 = require("jssha/dist/sha1");

475

const jsSHA256 = require("jssha/dist/sha256");

476

const jsSHA512 = require("jssha/dist/sha512");

477

const jsSHA3 = require("jssha/dist/sha3");

478

```

479

480

### Browser Script Tags

481

482

```html

483

<!-- Individual variant files -->

484

<script src="path/to/sha1.js"></script>

485

<script src="path/to/sha256.js"></script>

486

<script src="path/to/sha512.js"></script>

487

<script src="path/to/sha3.js"></script>

488

489

<script>

490

// Classes are available globally

491

const sha256 = new jsSHA("SHA-256", "TEXT");

492

</script>

493

```

494

495

## Compatibility and Interoperability

496

497

### Type Compatibility

498

499

All variant-specific classes implement the same core interface as the universal `jsSHA` class:

500

501

```typescript

502

// These are functionally equivalent for SHA-256

503

import jsSHA from "jssha";

504

import jsSHA256 from "jssha/sha256";

505

506

const universal = new jsSHA("SHA-256", "TEXT");

507

const specific = new jsSHA256("SHA-256", "TEXT");

508

509

// Both produce identical results

510

universal.update("test");

511

specific.update("test");

512

513

console.log(universal.getHash("HEX") === specific.getHash("HEX")); // true

514

```

515

516

### Performance Characteristics

517

518

- **Bundle Size**: Variant-specific classes have smaller bundle sizes

519

- **Runtime Performance**: Similar performance to universal class for the same algorithms

520

- **Memory Usage**: Slightly lower memory footprint due to unused code elimination

521

- **Tree Shaking**: Better tree-shaking support in modern bundlers

522

523

## Use Case Recommendations

524

525

### When to Use Universal jsSHA Class

526

527

- Need multiple SHA variants in the same application

528

- Algorithm choice is determined at runtime

529

- Bundle size is not a primary concern

530

- Want maximum flexibility and feature coverage

531

532

### When to Use Variant-Specific Classes

533

534

- Only need specific SHA algorithms

535

- Bundle size optimization is important

536

- Building lightweight applications or libraries

537

- Know exact algorithm requirements at build time

538

539

### Hybrid Approach

540

541

```typescript

542

// Use specific classes for known requirements

543

import jsSHA256 from "jssha/sha256";

544

import jsSHA3 from "jssha/sha3";

545

546

// SHA-256 for file hashing

547

function hashFile(content: string): string {

548

const sha256 = new jsSHA256("SHA-256", "TEXT");

549

sha256.update(content);

550

return sha256.getHash("HEX");

551

}

552

553

// SHAKE256 for key derivation

554

function deriveKey(seed: string, length: number): Uint8Array {

555

const shake = new jsSHA3("SHAKE256", "TEXT");

556

shake.update(seed);

557

return shake.getHash("UINT8ARRAY", { outputLen: length * 8 });

558

}

559

```

560

561

## Error Handling

562

563

Variant-specific classes have the same error handling behavior as the universal class:

564

565

```typescript

566

import jsSHA256 from "jssha/sha256";

567

568

// This will throw an error - SHA-1 not supported by jsSHA256

569

try {

570

const invalid = new jsSHA256("SHA-1", "TEXT"); // Error!

571

} catch (error) {

572

console.error("jsSHA256 only supports SHA-224 and SHA-256");

573

}

574

575

// This works correctly

576

const valid = new jsSHA256("SHA-256", "TEXT");

577

valid.update("Hello");

578

const result = valid.getHash("HEX");

579

```