@bsv/sdk 1.0.4 → 1.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (52) hide show
  1. package/dist/cjs/src/primitives/BigNumber.js +1 -1
  2. package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
  3. package/dist/cjs/src/primitives/SymmetricKey.js +1 -1
  4. package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -1
  5. package/dist/cjs/src/script/Spend.js +3 -2
  6. package/dist/cjs/src/script/Spend.js.map +1 -1
  7. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  8. package/dist/esm/src/primitives/BigNumber.js +1 -1
  9. package/dist/esm/src/primitives/BigNumber.js.map +1 -1
  10. package/dist/esm/src/primitives/SymmetricKey.js +1 -1
  11. package/dist/esm/src/primitives/SymmetricKey.js.map +1 -1
  12. package/dist/esm/src/script/Spend.js +3 -2
  13. package/dist/esm/src/script/Spend.js.map +1 -1
  14. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  15. package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -1
  16. package/dist/types/src/script/Spend.d.ts.map +1 -1
  17. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  18. package/docs/examples/EXAMPLE_BUILDING_CUSTOM_TX_BROADCASTER.md +89 -0
  19. package/docs/examples/EXAMPLE_COMPLEX_TX.md +164 -0
  20. package/docs/examples/EXAMPLE_ECIES.md +37 -0
  21. package/docs/examples/EXAMPLE_ENCRYPT_DECRYPT_MESSAGE.md +52 -0
  22. package/docs/examples/EXAMPLE_FEE_MODELING.md +199 -0
  23. package/docs/examples/EXAMPLE_HD_WALLETS.md +71 -0
  24. package/docs/examples/EXAMPLE_MESSAGE_SIGNING.md +63 -0
  25. package/docs/examples/EXAMPLE_PULSE_HEADERS.md +140 -0
  26. package/docs/examples/EXAMPLE_SCRIPT_TEMPLATES.md +170 -0
  27. package/docs/examples/EXAMPLE_SIMPLE_TX.md +64 -0
  28. package/docs/examples/EXAMPLE_TYPE_42.md +108 -0
  29. package/docs/examples/EXAMPLE_VERIFYING_BEEF.md +55 -0
  30. package/docs/examples/EXAMPLE_VERIFYING_SPENDS.md +69 -0
  31. package/docs/examples/GETTING_STARTED_NODE_CJS.md +73 -0
  32. package/docs/examples/GETTING_STARTED_REACT.md +121 -0
  33. package/docs/examples/README.md +19 -0
  34. package/docs/low-level/README.md +6 -0
  35. package/docs/low-level/TX_SIG.md +129 -0
  36. package/docs/low-level/TYPE_42.md +0 -0
  37. package/docs/primitives.md +585 -562
  38. package/docs/script.md +4 -4
  39. package/package.json +1 -1
  40. package/src/primitives/BigNumber.ts +2 -1
  41. package/src/primitives/Hash.ts +118 -64
  42. package/src/primitives/PrivateKey.ts +28 -1
  43. package/src/primitives/PublicKey.ts +24 -2
  44. package/src/primitives/SymmetricKey.ts +17 -3
  45. package/src/primitives/__tests/HMAC.test.ts +2 -2
  46. package/src/primitives/__tests/Hash.test.ts +2 -2
  47. package/src/primitives/index.ts +1 -0
  48. package/src/primitives/utils.ts +3 -3
  49. package/src/script/__tests/Script.test.ts +34 -0
  50. package/src/script/__tests/Spend.test.ts +7 -7
  51. package/src/script/templates/P2PKH.ts +13 -4
  52. package/src/transaction/__tests/Transaction.test.ts +1 -1
@@ -3586,7 +3586,7 @@ Returns
3586
3586
  Example
3587
3587
 
3588
3588
  ```ts
3589
- const bn = new BigNumber('000000", 2, "be");
3589
+ const bn = new BigNumber("000000", 2, "be");
3590
3590
  bn.strip();
3591
3591
  // bn now represents 0
3592
3592
  ```
@@ -4392,343 +4392,353 @@ const product = montMethod.mul(a, b);
4392
4392
  Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4393
4393
 
4394
4394
  ---
4395
- ### Class: RIPEMD160
4395
+ ### Class: BasePoint
4396
4396
 
4397
- An implementation of RIPEMD160 cryptographic hash function. Extends the BaseHash class.
4398
- It provides a way to compute a 'digest' for any kind of input data; transforming the data
4399
- into a unique output of fixed size. The output is deterministic; it will always be
4400
- the same for the same input.
4397
+ Base class for Point (affine coordinates) and JacobianPoint classes,
4398
+ defining their curve and type.
4399
+
4400
+ ```ts
4401
+ export default abstract class BasePoint {
4402
+ curve: Curve;
4403
+ type: "affine" | "jacobian";
4404
+ precomputed: {
4405
+ doubles: {
4406
+ step: number;
4407
+ points: any[];
4408
+ } | undefined;
4409
+ naf: {
4410
+ wnd: any;
4411
+ points: any[];
4412
+ } | undefined;
4413
+ beta: BasePoint | null | undefined;
4414
+ } | null;
4415
+ constructor(type: "affine" | "jacobian")
4416
+ }
4417
+ ```
4418
+
4419
+ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4420
+
4421
+ ---
4422
+ ### Class: JacobianPoint
4423
+
4424
+ The `JacobianPoint` class extends the `BasePoint` class for handling Jacobian coordinates on an Elliptic Curve.
4425
+ This class defines the properties and the methods needed to work with points in Jacobian coordinates.
4426
+
4427
+ The Jacobian coordinates represent a point (x, y, z) on an Elliptic Curve such that the usual (x, y) coordinates are given by (x/z^2, y/z^3).
4401
4428
 
4402
4429
  Example
4403
4430
 
4404
4431
  ```ts
4405
- const ripemd160 = new RIPEMD160();
4432
+ const pointJ = new JacobianPoint('3', '4', '1');
4406
4433
  ```
4407
4434
 
4408
4435
  ```ts
4409
- export class RIPEMD160 extends BaseHash {
4410
- h: number[];
4411
- constructor()
4412
- _update(msg: number[], start: number): void
4413
- _digest(enc?: "hex"): string | number[]
4436
+ export default class JacobianPoint extends BasePoint {
4437
+ x: BigNumber;
4438
+ y: BigNumber;
4439
+ z: BigNumber;
4440
+ zOne: boolean;
4441
+ constructor(x: string | BigNumber | null, y: string | BigNumber | null, z: string | BigNumber | null)
4442
+ toP(): Point
4443
+ neg(): JacobianPoint
4444
+ add(p: JacobianPoint): JacobianPoint
4445
+ mixedAdd(p: Point): JacobianPoint
4446
+ dblp(pow: number): JacobianPoint
4447
+ dbl(): JacobianPoint
4448
+ eq(p: Point | JacobianPoint): boolean
4449
+ eqXToP(x: BigNumber): boolean
4450
+ inspect(): string
4451
+ isInfinity(): boolean
4414
4452
  }
4415
4453
  ```
4416
4454
 
4417
4455
  <details>
4418
4456
 
4419
- <summary>Class RIPEMD160 Details</summary>
4457
+ <summary>Class JacobianPoint Details</summary>
4420
4458
 
4421
- #### Property h
4459
+ #### Constructor
4422
4460
 
4423
- Array that is updated iteratively as part of hashing computation.
4461
+ Constructs a new `JacobianPoint` instance.
4424
4462
 
4425
4463
  ```ts
4426
- h: number[]
4464
+ constructor(x: string | BigNumber | null, y: string | BigNumber | null, z: string | BigNumber | null)
4427
4465
  ```
4428
4466
 
4429
- </details>
4430
-
4431
- Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4432
-
4433
- ---
4434
- ### Class: SHA256
4467
+ Argument Details
4435
4468
 
4436
- An implementation of SHA256 cryptographic hash function. Extends the BaseHash class.
4437
- It provides a way to compute a 'digest' for any kind of input data; transforming the data
4438
- into a unique output of fixed size. The output is deterministic; it will always be
4439
- the same for the same input.
4469
+ + **x**
4470
+ + If `null`, the x-coordinate will default to the curve's defined 'one' constant.
4471
+ If `x` is not a BigNumber, `x` will be converted to a `BigNumber` assuming it is a hex string.
4472
+ + **y**
4473
+ + If `null`, the y-coordinate will default to the curve's defined 'one' constant.
4474
+ If `y` is not a BigNumber, `y` will be converted to a `BigNumber` assuming it is a hex string.
4475
+ + **z**
4476
+ + If `null`, the z-coordinate will default to 0.
4477
+ If `z` is not a BigNumber, `z` will be converted to a `BigNumber` assuming it is a hex string.
4440
4478
 
4441
4479
  Example
4442
4480
 
4443
4481
  ```ts
4444
- const sha256 = new SHA256();
4482
+ const pointJ1 = new JacobianPoint(null, null, null); // creates point at infinity
4483
+ const pointJ2 = new JacobianPoint('3', '4', '1'); // creates point (3, 4, 1)
4445
4484
  ```
4446
4485
 
4486
+ #### Property x
4487
+
4488
+ The `x` coordinate of the point in the Jacobian form.
4489
+
4447
4490
  ```ts
4448
- export class SHA256 extends BaseHash {
4449
- h: number[];
4450
- W: number[];
4451
- k: number[];
4452
- constructor()
4453
- _update(msg: number[], start?: number): void
4454
- ;
4455
- _digest(enc?: "hex"): number[] | string
4456
- }
4491
+ x: BigNumber
4457
4492
  ```
4458
4493
 
4459
- <details>
4494
+ #### Property y
4460
4495
 
4461
- <summary>Class SHA256 Details</summary>
4496
+ The `y` coordinate of the point in the Jacobian form.
4462
4497
 
4463
- #### Property W
4498
+ ```ts
4499
+ y: BigNumber
4500
+ ```
4464
4501
 
4465
- Provides a way to recycle usage of the array memory.
4502
+ #### Property z
4503
+
4504
+ The `z` coordinate of the point in the Jacobian form.
4466
4505
 
4467
4506
  ```ts
4468
- W: number[]
4507
+ z: BigNumber
4469
4508
  ```
4470
4509
 
4471
- #### Property h
4510
+ #### Property zOne
4472
4511
 
4473
- The initial hash constants
4512
+ Flag that indicates if the `z` coordinate is one.
4474
4513
 
4475
4514
  ```ts
4476
- h: number[]
4515
+ zOne: boolean
4477
4516
  ```
4478
4517
 
4479
- #### Property k
4518
+ #### Method add
4480
4519
 
4481
- The round constants used for each round of SHA-256
4520
+ Addition operation in the Jacobian coordinates. It takes a Jacobian point as an argument
4521
+ and returns a new Jacobian point as a result of the addition. In the special cases,
4522
+ when either one of the points is the point at infinity, it will return the other point.
4482
4523
 
4483
4524
  ```ts
4484
- k: number[]
4525
+ add(p: JacobianPoint): JacobianPoint
4485
4526
  ```
4486
4527
 
4487
- </details>
4528
+ Returns
4488
4529
 
4489
- Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4530
+ Returns a new Jacobian point as the result of the addition.
4490
4531
 
4491
- ---
4492
- ### Class: SHA1
4532
+ Argument Details
4493
4533
 
4494
- An implementation of SHA1 cryptographic hash function. Extends the BaseHash class.
4495
- It provides a way to compute a 'digest' for any kind of input data; transforming the data
4496
- into a unique output of fixed size. The output is deterministic; it will always be
4497
- the same for the same input.
4534
+ + **p**
4535
+ + The Jacobian point to be added.
4498
4536
 
4499
4537
  Example
4500
4538
 
4501
4539
  ```ts
4502
- const sha1 = new SHA1();
4503
- ```
4504
-
4505
- ```ts
4506
- export class SHA1 extends BaseHash {
4507
- h: number[];
4508
- W: number[];
4509
- k: number[];
4510
- constructor()
4511
- _update(msg: number[], start?: number): void
4512
- _digest(enc?: "hex"): number[] | string
4513
- }
4540
+ const p1 = new JacobianPoint(x1, y1, z1)
4541
+ const p2 = new JacobianPoint(x2, y2, z2)
4542
+ const result = p1.add(p2)
4514
4543
  ```
4515
4544
 
4516
- <details>
4517
-
4518
- <summary>Class SHA1 Details</summary>
4519
-
4520
- #### Property W
4545
+ #### Method dbl
4521
4546
 
4522
- Provides a way to recycle usage of the array memory.
4547
+ Point doubling operation in the Jacobian coordinates. A special case is when the point is the point at infinity, in this case, this function will return the point itself.
4523
4548
 
4524
4549
  ```ts
4525
- W: number[]
4550
+ dbl(): JacobianPoint
4526
4551
  ```
4527
4552
 
4528
- #### Property h
4553
+ Returns
4529
4554
 
4530
- The initial hash constants.
4555
+ Returns a new Jacobian point as the result of the doubling.
4556
+
4557
+ Example
4531
4558
 
4532
4559
  ```ts
4533
- h: number[]
4560
+ const jp = new JacobianPoint(x, y, z)
4561
+ const result = jp.dbl()
4534
4562
  ```
4535
4563
 
4536
- #### Property k
4564
+ #### Method dblp
4537
4565
 
4538
- The round constants used for each round of SHA-1.
4566
+ Multiple doubling operation. It doubles the Jacobian point as many times as the pow parameter specifies. If pow is 0 or the point is the point at infinity, it will return the point itself.
4539
4567
 
4540
4568
  ```ts
4541
- k: number[]
4569
+ dblp(pow: number): JacobianPoint
4542
4570
  ```
4543
4571
 
4544
- </details>
4572
+ Returns
4545
4573
 
4546
- Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4574
+ Returns a new Jacobian point as the result of multiple doublings.
4547
4575
 
4548
- ---
4549
- ### Class: SHA512
4576
+ Argument Details
4550
4577
 
4551
- An implementation of SHA512 cryptographic hash function. Extends the BaseHash class.
4552
- It provides a way to compute a 'digest' for any kind of input data; transforming the data
4553
- into a unique output of fixed size. The output is deterministic; it will always be
4554
- the same for the same input.
4578
+ + **pow**
4579
+ + The number of times the point should be doubled.
4555
4580
 
4556
4581
  Example
4557
4582
 
4558
4583
  ```ts
4559
- const sha512 = new SHA512();
4584
+ const jp = new JacobianPoint(x, y, z)
4585
+ const result = jp.dblp(3)
4560
4586
  ```
4561
4587
 
4588
+ #### Method eq
4589
+
4590
+ Equality check operation. It checks whether the affine or Jacobian point is equal to this Jacobian point.
4591
+
4562
4592
  ```ts
4563
- export class SHA512 extends BaseHash {
4564
- h: number[];
4565
- W: number[];
4566
- k: number[];
4567
- constructor()
4568
- _prepareBlock(msg, start)
4569
- _update(msg, start)
4570
- _digest(enc)
4571
- }
4593
+ eq(p: Point | JacobianPoint): boolean
4572
4594
  ```
4573
4595
 
4574
- <details>
4596
+ Returns
4575
4597
 
4576
- <summary>Class SHA512 Details</summary>
4598
+ Returns true if the points are equal, otherwise returns false.
4577
4599
 
4578
- #### Property W
4600
+ Argument Details
4579
4601
 
4580
- Provides a way to recycle usage of the array memory.
4602
+ + **p**
4603
+ + The affine or Jacobian point to compare with.
4604
+
4605
+ Example
4581
4606
 
4582
4607
  ```ts
4583
- W: number[]
4608
+ const jp1 = new JacobianPoint(x1, y1, z1)
4609
+ const jp2 = new JacobianPoint(x2, y2, z2)
4610
+ const areEqual = jp1.eq(jp2)
4584
4611
  ```
4585
4612
 
4586
- #### Property h
4613
+ #### Method eqXToP
4587
4614
 
4588
- The initial hash constants.
4615
+ Equality check operation in relation to an x coordinate of a point in projective coordinates.
4616
+ It checks whether the x coordinate of the Jacobian point is equal to the provided x coordinate
4617
+ of a point in projective coordinates.
4589
4618
 
4590
4619
  ```ts
4591
- h: number[]
4620
+ eqXToP(x: BigNumber): boolean
4592
4621
  ```
4593
4622
 
4594
- #### Property k
4623
+ Returns
4595
4624
 
4596
- The round constants used for each round of SHA-512.
4625
+ Returns true if the x coordinates are equal, otherwise returns false.
4626
+
4627
+ Argument Details
4628
+
4629
+ + **x**
4630
+ + The x coordinate of a point in projective coordinates.
4631
+
4632
+ Example
4597
4633
 
4598
4634
  ```ts
4599
- k: number[]
4635
+ const jp = new JacobianPoint(x1, y1, z1)
4636
+ const isXEqual = jp.eqXToP(x2)
4600
4637
  ```
4601
4638
 
4602
- </details>
4639
+ #### Method inspect
4603
4640
 
4604
- Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4605
-
4606
- ---
4607
- ### Class: SHA256HMAC
4608
-
4609
- The `SHA256HMAC` class is used to create Hash-based Message Authentication Code (HMAC) using the SHA-256 cryptographic hash function.
4610
-
4611
- HMAC is a specific type of MAC involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authenticity of a message.
4612
-
4613
- This class also uses the SHA-256 cryptographic hash algorithm that produces a 256-bit (32-byte) hash value.
4641
+ Returns the string representation of the JacobianPoint instance.
4614
4642
 
4615
4643
  ```ts
4616
- export class SHA256HMAC {
4617
- inner: SHA256;
4618
- outer: SHA256;
4619
- blockSize = 64;
4620
- outSize = 32;
4621
- constructor(key: number[] | string)
4622
- update(msg: number[] | string, enc?: "hex"): SHA256HMAC
4623
- digest(enc?: "hex"): number[] | string
4624
- }
4644
+ inspect(): string
4625
4645
  ```
4626
4646
 
4627
- <details>
4628
-
4629
- <summary>Class SHA256HMAC Details</summary>
4630
-
4631
- #### Constructor
4647
+ Returns
4632
4648
 
4633
- The constructor for the `SHA256HMAC` class.
4649
+ Returns the string description of the JacobianPoint. If the JacobianPoint represents a point at infinity, the return value of this function is '<EC JPoint Infinity>'. For a normal point, it returns the string description format as '<EC JPoint x: x-coordinate y: y-coordinate z: z-coordinate>'.
4634
4650
 
4635
- It initializes the `SHA256HMAC` object and sets up the inner and outer padded keys.
4636
- If the key size is larger than the blockSize, it is digested using SHA-256.
4637
- If the key size is less than the blockSize, it is padded with zeroes.
4651
+ Example
4638
4652
 
4639
4653
  ```ts
4640
- constructor(key: number[] | string)
4654
+ const point = new JacobianPoint('5', '6', '1');
4655
+ console.log(point.inspect()); // Output: '<EC JPoint x: 5 y: 6 z: 1>'
4641
4656
  ```
4642
4657
 
4643
- Argument Details
4644
-
4645
- + **key**
4646
- + The key to use to create the HMAC. Can be a number array or a string in hexadecimal format.
4658
+ #### Method isInfinity
4647
4659
 
4648
- Example
4660
+ Checks whether the JacobianPoint instance represents a point at infinity.
4649
4661
 
4650
4662
  ```ts
4651
- const myHMAC = new SHA256HMAC('deadbeef');
4663
+ isInfinity(): boolean
4652
4664
  ```
4653
4665
 
4654
- #### Property blockSize
4666
+ Returns
4655
4667
 
4656
- The block size for the SHA-256 hash function, in bytes. It's set to 64 bytes.
4668
+ Returns true if the JacobianPoint's z-coordinate equals to zero (which represents the point at infinity in Jacobian coordinates). Returns false otherwise.
4669
+
4670
+ Example
4657
4671
 
4658
4672
  ```ts
4659
- blockSize = 64
4673
+ const point = new JacobianPoint('5', '6', '0');
4674
+ console.log(point.isInfinity()); // Output: true
4660
4675
  ```
4661
4676
 
4662
- #### Property inner
4677
+ #### Method mixedAdd
4663
4678
 
4664
- Represents the inner hash of SHA-256.
4679
+ Mixed addition operation. This function combines the standard point addition with
4680
+ the transformation from the affine to Jacobian coordinates. It first converts
4681
+ the affine point to Jacobian, and then preforms the addition.
4665
4682
 
4666
4683
  ```ts
4667
- inner: SHA256
4684
+ mixedAdd(p: Point): JacobianPoint
4668
4685
  ```
4669
4686
 
4670
- #### Property outSize
4687
+ Returns
4671
4688
 
4672
- The output size of the SHA-256 hash function, in bytes. It's set to 32 bytes.
4689
+ Returns the result of the mixed addition as a new Jacobian point.
4673
4690
 
4674
- ```ts
4675
- outSize = 32
4676
- ```
4691
+ Argument Details
4677
4692
 
4678
- #### Property outer
4693
+ + **p**
4694
+ + The affine point to be added.
4679
4695
 
4680
- Represents the outer hash of SHA-256.
4696
+ Example
4681
4697
 
4682
4698
  ```ts
4683
- outer: SHA256
4699
+ const jp = new JacobianPoint(x1, y1, z1)
4700
+ const ap = new Point(x2, y2)
4701
+ const result = jp.mixedAdd(ap)
4684
4702
  ```
4685
4703
 
4686
- #### Method digest
4704
+ #### Method neg
4687
4705
 
4688
- Finalizes the HMAC computation and returns the resultant hash.
4706
+ Negation operation. It returns the additive inverse of the Jacobian point.
4689
4707
 
4690
4708
  ```ts
4691
- digest(enc?: "hex"): number[] | string
4709
+ neg(): JacobianPoint
4692
4710
  ```
4693
4711
 
4694
4712
  Returns
4695
4713
 
4696
- Returns the digest of the hashed data. Can be a number array or a string.
4697
-
4698
- Argument Details
4699
-
4700
- + **enc**
4701
- + If 'hex', then the output is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
4714
+ Returns a new Jacobian point as the result of the negation.
4702
4715
 
4703
4716
  Example
4704
4717
 
4705
4718
  ```ts
4706
- let hashedMessage = myHMAC.digest('hex');
4719
+ const jp = new JacobianPoint(x, y, z)
4720
+ const result = jp.neg()
4707
4721
  ```
4708
4722
 
4709
- #### Method update
4723
+ #### Method toP
4710
4724
 
4711
- Updates the `SHA256HMAC` object with part of the message to be hashed.
4725
+ Converts the `JacobianPoint` object instance to standard affine `Point` format and returns `Point` type.
4712
4726
 
4713
4727
  ```ts
4714
- update(msg: number[] | string, enc?: "hex"): SHA256HMAC
4728
+ toP(): Point
4715
4729
  ```
4716
4730
 
4717
4731
  Returns
4718
4732
 
4719
- Returns the instance of `SHA256HMAC` for chaining calls.
4720
-
4721
- Argument Details
4733
+ The `Point`(affine) object representing the same point as the original `JacobianPoint`.
4722
4734
 
4723
- + **msg**
4724
- + Part of the message to hash. Can be a number array or a string.
4725
- + **enc**
4726
- + If 'hex', then the input is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
4735
+ If the initial `JacobianPoint` represents point at infinity, an instance of `Point` at infinity is returned.
4727
4736
 
4728
4737
  Example
4729
4738
 
4730
4739
  ```ts
4731
- myHMAC.update('deadbeef', 'hex');
4740
+ const pointJ = new JacobianPoint('3', '4', '1');
4741
+ const pointP = pointJ.toP(); // The point in affine coordinates.
4732
4742
  ```
4733
4743
 
4734
4744
  </details>
@@ -4736,131 +4746,96 @@ myHMAC.update('deadbeef', 'hex');
4736
4746
  Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4737
4747
 
4738
4748
  ---
4739
- ### Class: SHA512HMAC
4740
-
4741
- The `SHA512HMAC` class is used to create Hash-based Message Authentication Code (HMAC) using the SHA-512 cryptographic hash function.
4742
-
4743
- HMAC is a specific type of MAC involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authenticity of a message.
4744
-
4745
- This class also uses the SHA-512 cryptographic hash algorithm that produces a 512-bit (64-byte) hash value.
4746
-
4747
- ```ts
4748
- export class SHA512HMAC {
4749
- inner: SHA512;
4750
- outer: SHA512;
4751
- blockSize = 128;
4752
- outSize = 32;
4753
- constructor(key: number[] | string)
4754
- update(msg: number[] | string, enc?: "hex"): SHA512HMAC
4755
- digest(enc?: "hex"): number[] | string
4756
- }
4757
- ```
4758
-
4759
- <details>
4760
-
4761
- <summary>Class SHA512HMAC Details</summary>
4762
-
4763
- #### Constructor
4749
+ ### Class: RIPEMD160
4764
4750
 
4765
- The constructor for the `SHA512HMAC` class.
4751
+ An implementation of RIPEMD160 cryptographic hash function. Extends the BaseHash class.
4752
+ It provides a way to compute a 'digest' for any kind of input data; transforming the data
4753
+ into a unique output of fixed size. The output is deterministic; it will always be
4754
+ the same for the same input.
4766
4755
 
4767
- It initializes the `SHA512HMAC` object and sets up the inner and outer padded keys.
4768
- If the key size is larger than the blockSize, it is digested using SHA-512.
4769
- If the key size is less than the blockSize, it is padded with zeroes.
4756
+ Example
4770
4757
 
4771
4758
  ```ts
4772
- constructor(key: number[] | string)
4759
+ const ripemd160 = new RIPEMD160();
4773
4760
  ```
4774
4761
 
4775
- Argument Details
4776
-
4777
- + **key**
4778
- + The key to use to create the HMAC. Can be a number array or a string in hexadecimal format.
4779
-
4780
- Example
4781
-
4782
4762
  ```ts
4783
- const myHMAC = new SHA512HMAC('deadbeef');
4763
+ export class RIPEMD160 extends BaseHash {
4764
+ h: number[];
4765
+ constructor()
4766
+ _update(msg: number[], start: number): void
4767
+ _digest(enc?: "hex"): string | number[]
4768
+ }
4784
4769
  ```
4785
4770
 
4786
- #### Property blockSize
4787
-
4788
- The block size for the SHA-512 hash function, in bytes. It's set to 128 bytes.
4771
+ <details>
4789
4772
 
4790
- ```ts
4791
- blockSize = 128
4792
- ```
4773
+ <summary>Class RIPEMD160 Details</summary>
4793
4774
 
4794
- #### Property inner
4775
+ #### Property h
4795
4776
 
4796
- Represents the inner hash of SHA-512.
4777
+ Array that is updated iteratively as part of hashing computation.
4797
4778
 
4798
4779
  ```ts
4799
- inner: SHA512
4780
+ h: number[]
4800
4781
  ```
4801
4782
 
4802
- #### Property outSize
4783
+ </details>
4803
4784
 
4804
- The output size of the SHA-512 hash function, in bytes. It's set to 64 bytes.
4785
+ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4805
4786
 
4806
- ```ts
4807
- outSize = 32
4808
- ```
4787
+ ---
4788
+ ### Class: SHA256
4809
4789
 
4810
- #### Property outer
4790
+ An implementation of SHA256 cryptographic hash function. Extends the BaseHash class.
4791
+ It provides a way to compute a 'digest' for any kind of input data; transforming the data
4792
+ into a unique output of fixed size. The output is deterministic; it will always be
4793
+ the same for the same input.
4811
4794
 
4812
- Represents the outer hash of SHA-512.
4795
+ Example
4813
4796
 
4814
4797
  ```ts
4815
- outer: SHA512
4798
+ const sha256 = new SHA256();
4816
4799
  ```
4817
4800
 
4818
- #### Method digest
4819
-
4820
- Finalizes the HMAC computation and returns the resultant hash.
4821
-
4822
4801
  ```ts
4823
- digest(enc?: "hex"): number[] | string
4802
+ export class SHA256 extends BaseHash {
4803
+ h: number[];
4804
+ W: number[];
4805
+ k: number[];
4806
+ constructor()
4807
+ _update(msg: number[], start?: number): void
4808
+ ;
4809
+ _digest(enc?: "hex"): number[] | string
4810
+ }
4824
4811
  ```
4825
4812
 
4826
- Returns
4827
-
4828
- Returns the digest of the hashed data. Can be a number array or a string.
4813
+ <details>
4829
4814
 
4830
- Argument Details
4815
+ <summary>Class SHA256 Details</summary>
4831
4816
 
4832
- + **enc**
4833
- + If 'hex', then the output is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
4817
+ #### Property W
4834
4818
 
4835
- Example
4819
+ Provides a way to recycle usage of the array memory.
4836
4820
 
4837
4821
  ```ts
4838
- let hashedMessage = myHMAC.digest('hex');
4822
+ W: number[]
4839
4823
  ```
4840
4824
 
4841
- #### Method update
4825
+ #### Property h
4842
4826
 
4843
- Updates the `SHA512HMAC` object with part of the message to be hashed.
4827
+ The initial hash constants
4844
4828
 
4845
4829
  ```ts
4846
- update(msg: number[] | string, enc?: "hex"): SHA512HMAC
4830
+ h: number[]
4847
4831
  ```
4848
4832
 
4849
- Returns
4850
-
4851
- Returns the instance of `SHA512HMAC` for chaining calls.
4852
-
4853
- Argument Details
4854
-
4855
- + **msg**
4856
- + Part of the message to hash. Can be a number array or a string.
4857
- + **enc**
4858
- + If 'hex', then the input is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
4833
+ #### Property k
4859
4834
 
4860
- Example
4835
+ The round constants used for each round of SHA-256
4861
4836
 
4862
4837
  ```ts
4863
- myHMAC.update('deadbeef', 'hex');
4838
+ k: number[]
4864
4839
  ```
4865
4840
 
4866
4841
  </details>
@@ -4868,489 +4843,446 @@ myHMAC.update('deadbeef', 'hex');
4868
4843
  Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4869
4844
 
4870
4845
  ---
4871
- ### Class: Writer
4872
-
4873
- ```ts
4874
- export class Writer {
4875
- public bufs: number[][];
4876
- constructor(bufs?: number[][])
4877
- getLength(): number
4878
- toArray(): number[]
4879
- write(buf: number[]): Writer
4880
- writeReverse(buf: number[]): Writer
4881
- writeUInt8(n: number): Writer
4882
- writeInt8(n: number): Writer
4883
- writeUInt16BE(n: number): Writer
4884
- writeInt16BE(n: number): Writer
4885
- writeUInt16LE(n: number): Writer
4886
- writeInt16LE(n: number): Writer
4887
- writeUInt32BE(n: number): Writer
4888
- writeInt32BE(n: number): Writer
4889
- writeUInt32LE(n: number): Writer
4890
- writeInt32LE(n: number): Writer
4891
- writeUInt64BEBn(bn: BigNumber): Writer
4892
- writeUInt64LEBn(bn: BigNumber): Writer
4893
- writeUInt64LE(n: number): Writer
4894
- writeVarIntNum(n: number): Writer
4895
- writeVarIntBn(bn: BigNumber): Writer
4896
- static varIntNum(n: number): number[]
4897
- static varIntBn(bn: BigNumber): number[]
4898
- }
4899
- ```
4846
+ ### Class: SHA1
4900
4847
 
4901
- Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4848
+ An implementation of SHA1 cryptographic hash function. Extends the BaseHash class.
4849
+ It provides a way to compute a 'digest' for any kind of input data; transforming the data
4850
+ into a unique output of fixed size. The output is deterministic; it will always be
4851
+ the same for the same input.
4902
4852
 
4903
- ---
4904
- ### Class: Reader
4853
+ Example
4905
4854
 
4906
4855
  ```ts
4907
- export class Reader {
4908
- public bin: number[];
4909
- public pos: number;
4910
- constructor(bin: number[] = [], pos: number = 0)
4911
- public eof(): boolean
4912
- public read(len = this.bin.length): number[]
4913
- public readReverse(len = this.bin.length): number[]
4914
- public readUInt8(): number
4915
- public readInt8(): number
4916
- public readUInt16BE(): number
4917
- public readInt16BE(): number
4918
- public readUInt16LE(): number
4919
- public readInt16LE(): number
4920
- public readUInt32BE(): number
4921
- public readInt32BE(): number
4922
- public readUInt32LE(): number
4923
- public readInt32LE(): number
4924
- public readUInt64BEBn(): BigNumber
4925
- public readUInt64LEBn(): BigNumber
4926
- public readVarIntNum(): number
4927
- public readVarInt(): number[]
4928
- public readVarIntBn(): BigNumber
4929
- }
4856
+ const sha1 = new SHA1();
4930
4857
  ```
4931
-
4932
- Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4933
-
4934
- ---
4935
- ### Class: Curve
4936
-
4937
- ```ts
4938
- export default class Curve {
4939
- p: BigNumber;
4940
- red: ReductionContext;
4941
- redN: BigNumber | null;
4942
- zero: BigNumber;
4943
- one: BigNumber;
4944
- two: BigNumber;
4945
- g: Point;
4946
- n: BigNumber;
4947
- a: BigNumber;
4948
- b: BigNumber;
4949
- tinv: BigNumber;
4950
- zeroA: boolean;
4951
- threeA: boolean;
4952
- endo: any;
4953
- _endoWnafT1: any[];
4954
- _endoWnafT2: any[];
4955
- _wnafT1: any[];
4956
- _wnafT2: any[];
4957
- _wnafT3: any[];
4958
- _wnafT4: any[];
4959
- _bitLength: number;
4960
- static assert(expression: unknown, message: string = "Elliptic curve assertion failed"): void
4961
- getNAF(num: BigNumber, w: number, bits: number): number[]
4962
- getJSF(k1: BigNumber, k2: BigNumber): number[][]
4963
- static cachedProperty(obj, name: string, computer): void
4964
- static parseBytes(bytes: string | number[]): number[]
4965
- static intFromLE(bytes: number[]): BigNumber
4966
- constructor()
4967
- _getEndomorphism(conf): {
4968
- beta: BigNumber;
4969
- lambda: BigNumber;
4970
- basis: Array<{
4971
- a: BigNumber;
4972
- b: BigNumber;
4973
- }>;
4974
- } | undefined
4975
- ;
4976
- _getEndoRoots(num: BigNumber): [
4977
- BigNumber,
4978
- BigNumber
4979
- ]
4980
- ;
4981
- _getEndoBasis(lambda: BigNumber): [
4982
- {
4983
- a: BigNumber;
4984
- b: BigNumber;
4985
- },
4986
- {
4987
- a: BigNumber;
4988
- b: BigNumber;
4989
- }
4990
- ]
4991
- _endoSplit(k: BigNumber): {
4992
- k1: BigNumber;
4993
- k2: BigNumber;
4994
- }
4995
- validate(point: Point): boolean
4996
- ;
4858
+
4859
+ ```ts
4860
+ export class SHA1 extends BaseHash {
4861
+ h: number[];
4862
+ W: number[];
4863
+ k: number[];
4864
+ constructor()
4865
+ _update(msg: number[], start?: number): void
4866
+ _digest(enc?: "hex"): number[] | string
4997
4867
  }
4998
4868
  ```
4999
4869
 
5000
- Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4870
+ <details>
5001
4871
 
5002
- ---
5003
- ### Class: BasePoint
4872
+ <summary>Class SHA1 Details</summary>
5004
4873
 
5005
- Base class for Point (affine coordinates) and JacobianPoint classes,
5006
- defining their curve and type.
4874
+ #### Property W
4875
+
4876
+ Provides a way to recycle usage of the array memory.
5007
4877
 
5008
4878
  ```ts
5009
- export default abstract class BasePoint {
5010
- curve: Curve;
5011
- type: "affine" | "jacobian";
5012
- precomputed: {
5013
- doubles: {
5014
- step: number;
5015
- points: any[];
5016
- } | undefined;
5017
- naf: {
5018
- wnd: any;
5019
- points: any[];
5020
- } | undefined;
5021
- beta: BasePoint | null | undefined;
5022
- } | null;
5023
- constructor(type: "affine" | "jacobian")
5024
- }
4879
+ W: number[]
4880
+ ```
4881
+
4882
+ #### Property h
4883
+
4884
+ The initial hash constants.
4885
+
4886
+ ```ts
4887
+ h: number[]
4888
+ ```
4889
+
4890
+ #### Property k
4891
+
4892
+ The round constants used for each round of SHA-1.
4893
+
4894
+ ```ts
4895
+ k: number[]
5025
4896
  ```
5026
4897
 
4898
+ </details>
4899
+
5027
4900
  Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
5028
4901
 
5029
4902
  ---
5030
- ### Class: JacobianPoint
5031
-
5032
- The `JacobianPoint` class extends the `BasePoint` class for handling Jacobian coordinates on an Elliptic Curve.
5033
- This class defines the properties and the methods needed to work with points in Jacobian coordinates.
4903
+ ### Class: SHA512
5034
4904
 
5035
- The Jacobian coordinates represent a point (x, y, z) on an Elliptic Curve such that the usual (x, y) coordinates are given by (x/z^2, y/z^3).
4905
+ An implementation of SHA512 cryptographic hash function. Extends the BaseHash class.
4906
+ It provides a way to compute a 'digest' for any kind of input data; transforming the data
4907
+ into a unique output of fixed size. The output is deterministic; it will always be
4908
+ the same for the same input.
5036
4909
 
5037
4910
  Example
5038
4911
 
5039
4912
  ```ts
5040
- const pointJ = new JacobianPoint('3', '4', '1');
4913
+ const sha512 = new SHA512();
5041
4914
  ```
5042
4915
 
5043
4916
  ```ts
5044
- export default class JacobianPoint extends BasePoint {
5045
- x: BigNumber;
5046
- y: BigNumber;
5047
- z: BigNumber;
5048
- zOne: boolean;
5049
- constructor(x: string | BigNumber | null, y: string | BigNumber | null, z: string | BigNumber | null)
5050
- toP(): Point
5051
- neg(): JacobianPoint
5052
- add(p: JacobianPoint): JacobianPoint
5053
- mixedAdd(p: Point): JacobianPoint
5054
- dblp(pow: number): JacobianPoint
5055
- dbl(): JacobianPoint
5056
- eq(p: Point | JacobianPoint): boolean
5057
- eqXToP(x: BigNumber): boolean
5058
- inspect(): string
5059
- isInfinity(): boolean
4917
+ export class SHA512 extends BaseHash {
4918
+ h: number[];
4919
+ W: number[];
4920
+ k: number[];
4921
+ constructor()
4922
+ _prepareBlock(msg, start)
4923
+ _update(msg, start)
4924
+ _digest(enc)
5060
4925
  }
5061
4926
  ```
5062
4927
 
5063
4928
  <details>
5064
4929
 
5065
- <summary>Class JacobianPoint Details</summary>
4930
+ <summary>Class SHA512 Details</summary>
5066
4931
 
5067
- #### Constructor
4932
+ #### Property W
5068
4933
 
5069
- Constructs a new `JacobianPoint` instance.
4934
+ Provides a way to recycle usage of the array memory.
5070
4935
 
5071
4936
  ```ts
5072
- constructor(x: string | BigNumber | null, y: string | BigNumber | null, z: string | BigNumber | null)
4937
+ W: number[]
5073
4938
  ```
5074
4939
 
5075
- Argument Details
4940
+ #### Property h
5076
4941
 
5077
- + **x**
5078
- + If `null`, the x-coordinate will default to the curve's defined 'one' constant.
5079
- If `x` is not a BigNumber, `x` will be converted to a `BigNumber` assuming it is a hex string.
5080
- + **y**
5081
- + If `null`, the y-coordinate will default to the curve's defined 'one' constant.
5082
- If `y` is not a BigNumber, `y` will be converted to a `BigNumber` assuming it is a hex string.
5083
- + **z**
5084
- + If `null`, the z-coordinate will default to 0.
5085
- If `z` is not a BigNumber, `z` will be converted to a `BigNumber` assuming it is a hex string.
4942
+ The initial hash constants.
5086
4943
 
5087
- Example
4944
+ ```ts
4945
+ h: number[]
4946
+ ```
4947
+
4948
+ #### Property k
4949
+
4950
+ The round constants used for each round of SHA-512.
5088
4951
 
5089
4952
  ```ts
5090
- const pointJ1 = new JacobianPoint(null, null, null); // creates point at infinity
5091
- const pointJ2 = new JacobianPoint('3', '4', '1'); // creates point (3, 4, 1)
4953
+ k: number[]
5092
4954
  ```
5093
4955
 
5094
- #### Property x
4956
+ </details>
5095
4957
 
5096
- The `x` coordinate of the point in the Jacobian form.
4958
+ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
4959
+
4960
+ ---
4961
+ ### Class: SHA256HMAC
4962
+
4963
+ The `SHA256HMAC` class is used to create Hash-based Message Authentication Code (HMAC) using the SHA-256 cryptographic hash function.
4964
+
4965
+ HMAC is a specific type of MAC involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authenticity of a message.
4966
+
4967
+ This class also uses the SHA-256 cryptographic hash algorithm that produces a 256-bit (32-byte) hash value.
5097
4968
 
5098
4969
  ```ts
5099
- x: BigNumber
4970
+ export class SHA256HMAC {
4971
+ inner: SHA256;
4972
+ outer: SHA256;
4973
+ blockSize = 64;
4974
+ outSize = 32;
4975
+ constructor(key: number[] | string)
4976
+ update(msg: number[] | string, enc?: "hex"): SHA256HMAC
4977
+ digest(enc?: "hex"): number[] | string
4978
+ }
5100
4979
  ```
5101
4980
 
5102
- #### Property y
4981
+ <details>
5103
4982
 
5104
- The `y` coordinate of the point in the Jacobian form.
4983
+ <summary>Class SHA256HMAC Details</summary>
4984
+
4985
+ #### Constructor
4986
+
4987
+ The constructor for the `SHA256HMAC` class.
4988
+
4989
+ It initializes the `SHA256HMAC` object and sets up the inner and outer padded keys.
4990
+ If the key size is larger than the blockSize, it is digested using SHA-256.
4991
+ If the key size is less than the blockSize, it is padded with zeroes.
5105
4992
 
5106
4993
  ```ts
5107
- y: BigNumber
4994
+ constructor(key: number[] | string)
5108
4995
  ```
5109
4996
 
5110
- #### Property z
4997
+ Argument Details
5111
4998
 
5112
- The `z` coordinate of the point in the Jacobian form.
4999
+ + **key**
5000
+ + The key to use to create the HMAC. Can be a number array or a string in hexadecimal format.
5001
+
5002
+ Example
5113
5003
 
5114
5004
  ```ts
5115
- z: BigNumber
5005
+ const myHMAC = new SHA256HMAC('deadbeef');
5116
5006
  ```
5117
5007
 
5118
- #### Property zOne
5008
+ #### Property blockSize
5119
5009
 
5120
- Flag that indicates if the `z` coordinate is one.
5010
+ The block size for the SHA-256 hash function, in bytes. It's set to 64 bytes.
5121
5011
 
5122
5012
  ```ts
5123
- zOne: boolean
5013
+ blockSize = 64
5124
5014
  ```
5125
5015
 
5126
- #### Method add
5016
+ #### Property inner
5127
5017
 
5128
- Addition operation in the Jacobian coordinates. It takes a Jacobian point as an argument
5129
- and returns a new Jacobian point as a result of the addition. In the special cases,
5130
- when either one of the points is the point at infinity, it will return the other point.
5018
+ Represents the inner hash of SHA-256.
5131
5019
 
5132
5020
  ```ts
5133
- add(p: JacobianPoint): JacobianPoint
5021
+ inner: SHA256
5134
5022
  ```
5135
5023
 
5136
- Returns
5024
+ #### Property outSize
5137
5025
 
5138
- Returns a new Jacobian point as the result of the addition.
5026
+ The output size of the SHA-256 hash function, in bytes. It's set to 32 bytes.
5139
5027
 
5140
- Argument Details
5028
+ ```ts
5029
+ outSize = 32
5030
+ ```
5141
5031
 
5142
- + **p**
5143
- + The Jacobian point to be added.
5032
+ #### Property outer
5144
5033
 
5145
- Example
5034
+ Represents the outer hash of SHA-256.
5146
5035
 
5147
5036
  ```ts
5148
- const p1 = new JacobianPoint(x1, y1, z1)
5149
- const p2 = new JacobianPoint(x2, y2, z2)
5150
- const result = p1.add(p2)
5037
+ outer: SHA256
5151
5038
  ```
5152
5039
 
5153
- #### Method dbl
5040
+ #### Method digest
5154
5041
 
5155
- Point doubling operation in the Jacobian coordinates. A special case is when the point is the point at infinity, in this case, this function will return the point itself.
5042
+ Finalizes the HMAC computation and returns the resultant hash.
5156
5043
 
5157
5044
  ```ts
5158
- dbl(): JacobianPoint
5045
+ digest(enc?: "hex"): number[] | string
5159
5046
  ```
5160
5047
 
5161
5048
  Returns
5162
5049
 
5163
- Returns a new Jacobian point as the result of the doubling.
5050
+ Returns the digest of the hashed data. Can be a number array or a string.
5051
+
5052
+ Argument Details
5053
+
5054
+ + **enc**
5055
+ + If 'hex', then the output is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
5164
5056
 
5165
5057
  Example
5166
5058
 
5167
5059
  ```ts
5168
- const jp = new JacobianPoint(x, y, z)
5169
- const result = jp.dbl()
5060
+ let hashedMessage = myHMAC.digest('hex');
5170
5061
  ```
5171
5062
 
5172
- #### Method dblp
5063
+ #### Method update
5173
5064
 
5174
- Multiple doubling operation. It doubles the Jacobian point as many times as the pow parameter specifies. If pow is 0 or the point is the point at infinity, it will return the point itself.
5065
+ Updates the `SHA256HMAC` object with part of the message to be hashed.
5175
5066
 
5176
5067
  ```ts
5177
- dblp(pow: number): JacobianPoint
5068
+ update(msg: number[] | string, enc?: "hex"): SHA256HMAC
5178
5069
  ```
5179
5070
 
5180
5071
  Returns
5181
5072
 
5182
- Returns a new Jacobian point as the result of multiple doublings.
5073
+ Returns the instance of `SHA256HMAC` for chaining calls.
5183
5074
 
5184
5075
  Argument Details
5185
5076
 
5186
- + **pow**
5187
- + The number of times the point should be doubled.
5077
+ + **msg**
5078
+ + Part of the message to hash. Can be a number array or a string.
5079
+ + **enc**
5080
+ + If 'hex', then the input is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
5188
5081
 
5189
5082
  Example
5190
5083
 
5191
5084
  ```ts
5192
- const jp = new JacobianPoint(x, y, z)
5193
- const result = jp.dblp(3)
5085
+ myHMAC.update('deadbeef', 'hex');
5194
5086
  ```
5195
5087
 
5196
- #### Method eq
5088
+ </details>
5197
5089
 
5198
- Equality check operation. It checks whether the affine or Jacobian point is equal to this Jacobian point.
5090
+ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
5199
5091
 
5200
- ```ts
5201
- eq(p: Point | JacobianPoint): boolean
5202
- ```
5092
+ ---
5093
+ ### Class: SHA512HMAC
5203
5094
 
5204
- Returns
5095
+ The `SHA512HMAC` class is used to create Hash-based Message Authentication Code (HMAC) using the SHA-512 cryptographic hash function.
5205
5096
 
5206
- Returns true if the points are equal, otherwise returns false.
5097
+ HMAC is a specific type of MAC involving a cryptographic hash function and a secret cryptographic key. It may be used to simultaneously verify both the data integrity and the authenticity of a message.
5207
5098
 
5208
- Argument Details
5099
+ This class also uses the SHA-512 cryptographic hash algorithm that produces a 512-bit (64-byte) hash value.
5100
+
5101
+ ```ts
5102
+ export class SHA512HMAC {
5103
+ inner: SHA512;
5104
+ outer: SHA512;
5105
+ blockSize = 128;
5106
+ outSize = 32;
5107
+ constructor(key: number[] | string)
5108
+ update(msg: number[] | string, enc?: "hex"): SHA512HMAC
5109
+ digest(enc?: "hex"): number[] | string
5110
+ }
5111
+ ```
5209
5112
 
5210
- + **p**
5211
- + The affine or Jacobian point to compare with.
5113
+ <details>
5212
5114
 
5213
- Example
5115
+ <summary>Class SHA512HMAC Details</summary>
5214
5116
 
5215
- ```ts
5216
- const jp1 = new JacobianPoint(x1, y1, z1)
5217
- const jp2 = new JacobianPoint(x2, y2, z2)
5218
- const areEqual = jp1.eq(jp2)
5219
- ```
5117
+ #### Constructor
5220
5118
 
5221
- #### Method eqXToP
5119
+ The constructor for the `SHA512HMAC` class.
5222
5120
 
5223
- Equality check operation in relation to an x coordinate of a point in projective coordinates.
5224
- It checks whether the x coordinate of the Jacobian point is equal to the provided x coordinate
5225
- of a point in projective coordinates.
5121
+ It initializes the `SHA512HMAC` object and sets up the inner and outer padded keys.
5122
+ If the key size is larger than the blockSize, it is digested using SHA-512.
5123
+ If the key size is less than the blockSize, it is padded with zeroes.
5226
5124
 
5227
5125
  ```ts
5228
- eqXToP(x: BigNumber): boolean
5126
+ constructor(key: number[] | string)
5229
5127
  ```
5230
5128
 
5231
- Returns
5232
-
5233
- Returns true if the x coordinates are equal, otherwise returns false.
5234
-
5235
5129
  Argument Details
5236
5130
 
5237
- + **x**
5238
- + The x coordinate of a point in projective coordinates.
5131
+ + **key**
5132
+ + The key to use to create the HMAC. Can be a number array or a string in hexadecimal format.
5239
5133
 
5240
5134
  Example
5241
5135
 
5242
5136
  ```ts
5243
- const jp = new JacobianPoint(x1, y1, z1)
5244
- const isXEqual = jp.eqXToP(x2)
5137
+ const myHMAC = new SHA512HMAC('deadbeef');
5245
5138
  ```
5246
5139
 
5247
- #### Method inspect
5140
+ #### Property blockSize
5248
5141
 
5249
- Returns the string representation of the JacobianPoint instance.
5142
+ The block size for the SHA-512 hash function, in bytes. It's set to 128 bytes.
5250
5143
 
5251
5144
  ```ts
5252
- inspect(): string
5145
+ blockSize = 128
5253
5146
  ```
5254
5147
 
5255
- Returns
5256
-
5257
- Returns the string description of the JacobianPoint. If the JacobianPoint represents a point at infinity, the return value of this function is '<EC JPoint Infinity>'. For a normal point, it returns the string description format as '<EC JPoint x: x-coordinate y: y-coordinate z: z-coordinate>'.
5148
+ #### Property inner
5258
5149
 
5259
- Example
5150
+ Represents the inner hash of SHA-512.
5260
5151
 
5261
5152
  ```ts
5262
- const point = new JacobianPoint('5', '6', '1');
5263
- console.log(point.inspect()); // Output: '<EC JPoint x: 5 y: 6 z: 1>'
5153
+ inner: SHA512
5264
5154
  ```
5265
5155
 
5266
- #### Method isInfinity
5156
+ #### Property outSize
5267
5157
 
5268
- Checks whether the JacobianPoint instance represents a point at infinity.
5158
+ The output size of the SHA-512 hash function, in bytes. It's set to 64 bytes.
5269
5159
 
5270
5160
  ```ts
5271
- isInfinity(): boolean
5161
+ outSize = 32
5272
5162
  ```
5273
5163
 
5274
- Returns
5275
-
5276
- Returns true if the JacobianPoint's z-coordinate equals to zero (which represents the point at infinity in Jacobian coordinates). Returns false otherwise.
5164
+ #### Property outer
5277
5165
 
5278
- Example
5166
+ Represents the outer hash of SHA-512.
5279
5167
 
5280
5168
  ```ts
5281
- const point = new JacobianPoint('5', '6', '0');
5282
- console.log(point.isInfinity()); // Output: true
5169
+ outer: SHA512
5283
5170
  ```
5284
5171
 
5285
- #### Method mixedAdd
5172
+ #### Method digest
5286
5173
 
5287
- Mixed addition operation. This function combines the standard point addition with
5288
- the transformation from the affine to Jacobian coordinates. It first converts
5289
- the affine point to Jacobian, and then preforms the addition.
5174
+ Finalizes the HMAC computation and returns the resultant hash.
5290
5175
 
5291
5176
  ```ts
5292
- mixedAdd(p: Point): JacobianPoint
5177
+ digest(enc?: "hex"): number[] | string
5293
5178
  ```
5294
5179
 
5295
5180
  Returns
5296
5181
 
5297
- Returns the result of the mixed addition as a new Jacobian point.
5182
+ Returns the digest of the hashed data. Can be a number array or a string.
5298
5183
 
5299
5184
  Argument Details
5300
5185
 
5301
- + **p**
5302
- + The affine point to be added.
5186
+ + **enc**
5187
+ + If 'hex', then the output is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
5303
5188
 
5304
5189
  Example
5305
5190
 
5306
5191
  ```ts
5307
- const jp = new JacobianPoint(x1, y1, z1)
5308
- const ap = new Point(x2, y2)
5309
- const result = jp.mixedAdd(ap)
5192
+ let hashedMessage = myHMAC.digest('hex');
5310
5193
  ```
5311
5194
 
5312
- #### Method neg
5195
+ #### Method update
5313
5196
 
5314
- Negation operation. It returns the additive inverse of the Jacobian point.
5197
+ Updates the `SHA512HMAC` object with part of the message to be hashed.
5315
5198
 
5316
5199
  ```ts
5317
- neg(): JacobianPoint
5200
+ update(msg: number[] | string, enc?: "hex"): SHA512HMAC
5318
5201
  ```
5319
5202
 
5320
5203
  Returns
5321
5204
 
5322
- Returns a new Jacobian point as the result of the negation.
5205
+ Returns the instance of `SHA512HMAC` for chaining calls.
5206
+
5207
+ Argument Details
5208
+
5209
+ + **msg**
5210
+ + Part of the message to hash. Can be a number array or a string.
5211
+ + **enc**
5212
+ + If 'hex', then the input is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
5323
5213
 
5324
5214
  Example
5325
5215
 
5326
5216
  ```ts
5327
- const jp = new JacobianPoint(x, y, z)
5328
- const result = jp.neg()
5217
+ myHMAC.update('deadbeef', 'hex');
5329
5218
  ```
5330
5219
 
5331
- #### Method toP
5220
+ </details>
5332
5221
 
5333
- Converts the `JacobianPoint` object instance to standard affine `Point` format and returns `Point` type.
5222
+ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
5223
+
5224
+ ---
5225
+ ### Class: Writer
5334
5226
 
5335
5227
  ```ts
5336
- toP(): Point
5228
+ export class Writer {
5229
+ public bufs: number[][];
5230
+ constructor(bufs?: number[][])
5231
+ getLength(): number
5232
+ toArray(): number[]
5233
+ write(buf: number[]): Writer
5234
+ writeReverse(buf: number[]): Writer
5235
+ writeUInt8(n: number): Writer
5236
+ writeInt8(n: number): Writer
5237
+ writeUInt16BE(n: number): Writer
5238
+ writeInt16BE(n: number): Writer
5239
+ writeUInt16LE(n: number): Writer
5240
+ writeInt16LE(n: number): Writer
5241
+ writeUInt32BE(n: number): Writer
5242
+ writeInt32BE(n: number): Writer
5243
+ writeUInt32LE(n: number): Writer
5244
+ writeInt32LE(n: number): Writer
5245
+ writeUInt64BEBn(bn: BigNumber): Writer
5246
+ writeUInt64LEBn(bn: BigNumber): Writer
5247
+ writeUInt64LE(n: number): Writer
5248
+ writeVarIntNum(n: number): Writer
5249
+ writeVarIntBn(bn: BigNumber): Writer
5250
+ static varIntNum(n: number): number[]
5251
+ static varIntBn(bn: BigNumber): number[]
5252
+ }
5337
5253
  ```
5338
5254
 
5339
- Returns
5340
-
5341
- The `Point`(affine) object representing the same point as the original `JacobianPoint`.
5342
-
5343
- If the initial `JacobianPoint` represents point at infinity, an instance of `Point` at infinity is returned.
5255
+ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
5344
5256
 
5345
- Example
5257
+ ---
5258
+ ### Class: Reader
5346
5259
 
5347
5260
  ```ts
5348
- const pointJ = new JacobianPoint('3', '4', '1');
5349
- const pointP = pointJ.toP(); // The point in affine coordinates.
5261
+ export class Reader {
5262
+ public bin: number[];
5263
+ public pos: number;
5264
+ constructor(bin: number[] = [], pos: number = 0)
5265
+ public eof(): boolean
5266
+ public read(len = this.bin.length): number[]
5267
+ public readReverse(len = this.bin.length): number[]
5268
+ public readUInt8(): number
5269
+ public readInt8(): number
5270
+ public readUInt16BE(): number
5271
+ public readInt16BE(): number
5272
+ public readUInt16LE(): number
5273
+ public readInt16LE(): number
5274
+ public readUInt32BE(): number
5275
+ public readInt32BE(): number
5276
+ public readUInt32LE(): number
5277
+ public readInt32LE(): number
5278
+ public readUInt64BEBn(): BigNumber
5279
+ public readUInt64LEBn(): BigNumber
5280
+ public readVarIntNum(): number
5281
+ public readVarInt(): number[]
5282
+ public readVarIntBn(): BigNumber
5283
+ }
5350
5284
  ```
5351
5285
 
5352
- </details>
5353
-
5354
5286
  Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
5355
5287
 
5356
5288
  ---
@@ -5934,6 +5866,74 @@ const isValid = aPoint.validate();
5934
5866
 
5935
5867
  Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
5936
5868
 
5869
+ ---
5870
+ ### Class: Curve
5871
+
5872
+ ```ts
5873
+ export default class Curve {
5874
+ p: BigNumber;
5875
+ red: ReductionContext;
5876
+ redN: BigNumber | null;
5877
+ zero: BigNumber;
5878
+ one: BigNumber;
5879
+ two: BigNumber;
5880
+ g: Point;
5881
+ n: BigNumber;
5882
+ a: BigNumber;
5883
+ b: BigNumber;
5884
+ tinv: BigNumber;
5885
+ zeroA: boolean;
5886
+ threeA: boolean;
5887
+ endo: any;
5888
+ _endoWnafT1: any[];
5889
+ _endoWnafT2: any[];
5890
+ _wnafT1: any[];
5891
+ _wnafT2: any[];
5892
+ _wnafT3: any[];
5893
+ _wnafT4: any[];
5894
+ _bitLength: number;
5895
+ static assert(expression: unknown, message: string = "Elliptic curve assertion failed"): void
5896
+ getNAF(num: BigNumber, w: number, bits: number): number[]
5897
+ getJSF(k1: BigNumber, k2: BigNumber): number[][]
5898
+ static cachedProperty(obj, name: string, computer): void
5899
+ static parseBytes(bytes: string | number[]): number[]
5900
+ static intFromLE(bytes: number[]): BigNumber
5901
+ constructor()
5902
+ _getEndomorphism(conf): {
5903
+ beta: BigNumber;
5904
+ lambda: BigNumber;
5905
+ basis: Array<{
5906
+ a: BigNumber;
5907
+ b: BigNumber;
5908
+ }>;
5909
+ } | undefined
5910
+ ;
5911
+ _getEndoRoots(num: BigNumber): [
5912
+ BigNumber,
5913
+ BigNumber
5914
+ ]
5915
+ ;
5916
+ _getEndoBasis(lambda: BigNumber): [
5917
+ {
5918
+ a: BigNumber;
5919
+ b: BigNumber;
5920
+ },
5921
+ {
5922
+ a: BigNumber;
5923
+ b: BigNumber;
5924
+ }
5925
+ ]
5926
+ _endoSplit(k: BigNumber): {
5927
+ k1: BigNumber;
5928
+ k2: BigNumber;
5929
+ }
5930
+ validate(point: Point): boolean
5931
+ ;
5932
+ }
5933
+ ```
5934
+
5935
+ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
5936
+
5937
5937
  ---
5938
5938
  ### Class: DRBG
5939
5939
 
@@ -6212,6 +6212,7 @@ export default class PrivateKey extends BigNumber {
6212
6212
  static fromRandom(): PrivateKey
6213
6213
  static fromString(str: string, base: number | "hex"): PrivateKey
6214
6214
  static fromWif(wif: string, prefixLength: number = 1): PrivateKey
6215
+ constructor(number: BigNumber | number | string | number[] = 0, base: number | "be" | "le" | "hex" = 10, endian: "be" | "le" = "be")
6215
6216
  sign(msg: number[] | string, enc?: "hex", forceLowS: boolean = true, customK?: Function | BigNumber): Signature
6216
6217
  verify(msg: number[] | string, sig: Signature, enc?: "hex"): boolean
6217
6218
  toPublicKey(): PublicKey
@@ -6226,6 +6227,28 @@ export default class PrivateKey extends BigNumber {
6226
6227
 
6227
6228
  <summary>Class PrivateKey Details</summary>
6228
6229
 
6230
+ #### Constructor
6231
+
6232
+ ```ts
6233
+ constructor(number: BigNumber | number | string | number[] = 0, base: number | "be" | "le" | "hex" = 10, endian: "be" | "le" = "be")
6234
+ ```
6235
+
6236
+ Argument Details
6237
+
6238
+ + **number**
6239
+ + The number (various types accepted) to construct a BigNumber from. Default is 0.
6240
+ + **base**
6241
+ + The base of number provided. By default is 10. Ignored if number is BigNumber.
6242
+ + **endian**
6243
+ + The endianness provided. By default is 'big endian'. Ignored if number is BigNumber.
6244
+
6245
+ Example
6246
+
6247
+ ```ts
6248
+ import BigNumber from './BigNumber';
6249
+ const bn = new BigNumber('123456', 10, 'be');
6250
+ ```
6251
+
6229
6252
  #### Method deriveChild
6230
6253
 
6231
6254
  Derives a child key with BRC-42.
@@ -7014,7 +7037,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
7014
7037
 
7015
7038
  ```ts
7016
7039
  zero2 = (word: string): string => {
7017
- if (word.length === 1) {
7040
+ if (word.length % 2 === 1) {
7018
7041
  return "0" + word;
7019
7042
  }
7020
7043
  else {