@bsv/sdk 1.0.4 → 1.0.6
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.
- package/dist/cjs/package.json +1 -1
- package/dist/cjs/src/primitives/BigNumber.js +1 -1
- package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
- package/dist/cjs/src/primitives/Hash.js +98 -56
- package/dist/cjs/src/primitives/Hash.js.map +1 -1
- package/dist/cjs/src/primitives/PrivateKey.js +23 -0
- package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
- package/dist/cjs/src/primitives/PublicKey.js +19 -1
- package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
- package/dist/cjs/src/primitives/SymmetricKey.js +14 -1
- package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -1
- package/dist/cjs/src/primitives/index.js +3 -1
- package/dist/cjs/src/primitives/index.js.map +1 -1
- package/dist/cjs/src/primitives/utils.js +3 -3
- package/dist/cjs/src/primitives/utils.js.map +1 -1
- package/dist/cjs/src/script/templates/P2PKH.js +14 -3
- package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/primitives/BigNumber.js +1 -1
- package/dist/esm/src/primitives/BigNumber.js.map +1 -1
- package/dist/esm/src/primitives/Hash.js +98 -56
- package/dist/esm/src/primitives/Hash.js.map +1 -1
- package/dist/esm/src/primitives/PrivateKey.js +23 -0
- package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
- package/dist/esm/src/primitives/PublicKey.js +19 -1
- package/dist/esm/src/primitives/PublicKey.js.map +1 -1
- package/dist/esm/src/primitives/SymmetricKey.js +14 -1
- package/dist/esm/src/primitives/SymmetricKey.js.map +1 -1
- package/dist/esm/src/primitives/index.js +1 -0
- package/dist/esm/src/primitives/index.js.map +1 -1
- package/dist/esm/src/primitives/utils.js +3 -3
- package/dist/esm/src/primitives/utils.js.map +1 -1
- package/dist/esm/src/script/templates/P2PKH.js +14 -3
- package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/primitives/BigNumber.d.ts +1 -1
- package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
- package/dist/types/src/primitives/Hash.d.ts +73 -34
- package/dist/types/src/primitives/Hash.d.ts.map +1 -1
- package/dist/types/src/primitives/PrivateKey.d.ts +16 -1
- package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
- package/dist/types/src/primitives/PublicKey.d.ts +14 -2
- package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
- package/dist/types/src/primitives/SymmetricKey.d.ts +11 -0
- package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -1
- package/dist/types/src/primitives/index.d.ts +1 -0
- package/dist/types/src/primitives/index.d.ts.map +1 -1
- package/dist/types/src/primitives/utils.d.ts +2 -2
- package/dist/types/src/script/templates/P2PKH.d.ts +3 -3
- package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docs/examples/EXAMPLE_BUILDING_CUSTOM_TX_BROADCASTER.md +89 -0
- package/docs/examples/EXAMPLE_COMPLEX_TX.md +164 -0
- package/docs/examples/EXAMPLE_ECIES.md +37 -0
- package/docs/examples/EXAMPLE_ENCRYPT_DECRYPT_MESSAGE.md +52 -0
- package/docs/examples/EXAMPLE_FEE_MODELING.md +199 -0
- package/docs/examples/EXAMPLE_HD_WALLETS.md +71 -0
- package/docs/examples/EXAMPLE_MESSAGE_SIGNING.md +63 -0
- package/docs/examples/EXAMPLE_PULSE_HEADERS.md +140 -0
- package/docs/examples/EXAMPLE_SCRIPT_TEMPLATES.md +170 -0
- package/docs/examples/EXAMPLE_SIMPLE_TX.md +64 -0
- package/docs/examples/EXAMPLE_TYPE_42.md +108 -0
- package/docs/examples/EXAMPLE_VERIFYING_BEEF.md +55 -0
- package/docs/examples/EXAMPLE_VERIFYING_SPENDS.md +69 -0
- package/docs/examples/GETTING_STARTED_NODE_CJS.md +73 -0
- package/docs/examples/GETTING_STARTED_REACT.md +121 -0
- package/docs/examples/README.md +19 -0
- package/docs/low-level/README.md +6 -0
- package/docs/low-level/TX_SIG.md +129 -0
- package/docs/low-level/TYPE_42.md +0 -0
- package/docs/primitives.md +679 -566
- package/docs/script.md +4 -4
- package/package.json +1 -1
- package/src/primitives/BigNumber.ts +2 -1
- package/src/primitives/Hash.ts +118 -64
- package/src/primitives/PrivateKey.ts +28 -1
- package/src/primitives/PublicKey.ts +24 -2
- package/src/primitives/SymmetricKey.ts +17 -3
- package/src/primitives/__tests/HMAC.test.ts +2 -2
- package/src/primitives/__tests/Hash.test.ts +2 -2
- package/src/primitives/index.ts +1 -0
- package/src/primitives/utils.ts +3 -3
- package/src/script/__tests/Script.test.ts +34 -0
- package/src/script/__tests/Spend.test.ts +7 -7
- package/src/script/templates/P2PKH.ts +13 -4
- package/src/transaction/__tests/Transaction.test.ts +1 -1
package/docs/primitives.md
CHANGED
|
@@ -3586,7 +3586,7 @@ Returns
|
|
|
3586
3586
|
Example
|
|
3587
3587
|
|
|
3588
3588
|
```ts
|
|
3589
|
-
const bn = new BigNumber(
|
|
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:
|
|
4395
|
+
### Class: BasePoint
|
|
4396
4396
|
|
|
4397
|
-
|
|
4398
|
-
|
|
4399
|
-
|
|
4400
|
-
|
|
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
|
|
4432
|
+
const pointJ = new JacobianPoint('3', '4', '1');
|
|
4406
4433
|
```
|
|
4407
4434
|
|
|
4408
4435
|
```ts
|
|
4409
|
-
export class
|
|
4410
|
-
|
|
4411
|
-
|
|
4412
|
-
|
|
4413
|
-
|
|
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
|
|
4457
|
+
<summary>Class JacobianPoint Details</summary>
|
|
4420
4458
|
|
|
4421
|
-
####
|
|
4459
|
+
#### Constructor
|
|
4422
4460
|
|
|
4423
|
-
|
|
4461
|
+
Constructs a new `JacobianPoint` instance.
|
|
4424
4462
|
|
|
4425
4463
|
```ts
|
|
4426
|
-
|
|
4464
|
+
constructor(x: string | BigNumber | null, y: string | BigNumber | null, z: string | BigNumber | null)
|
|
4427
4465
|
```
|
|
4428
4466
|
|
|
4429
|
-
|
|
4430
|
-
|
|
4431
|
-
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
4432
|
-
|
|
4433
|
-
---
|
|
4434
|
-
### Class: SHA256
|
|
4467
|
+
Argument Details
|
|
4435
4468
|
|
|
4436
|
-
|
|
4437
|
-
|
|
4438
|
-
|
|
4439
|
-
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
4494
|
+
#### Property y
|
|
4460
4495
|
|
|
4461
|
-
|
|
4496
|
+
The `y` coordinate of the point in the Jacobian form.
|
|
4462
4497
|
|
|
4463
|
-
|
|
4498
|
+
```ts
|
|
4499
|
+
y: BigNumber
|
|
4500
|
+
```
|
|
4464
4501
|
|
|
4465
|
-
|
|
4502
|
+
#### Property z
|
|
4503
|
+
|
|
4504
|
+
The `z` coordinate of the point in the Jacobian form.
|
|
4466
4505
|
|
|
4467
4506
|
```ts
|
|
4468
|
-
|
|
4507
|
+
z: BigNumber
|
|
4469
4508
|
```
|
|
4470
4509
|
|
|
4471
|
-
#### Property
|
|
4510
|
+
#### Property zOne
|
|
4472
4511
|
|
|
4473
|
-
|
|
4512
|
+
Flag that indicates if the `z` coordinate is one.
|
|
4474
4513
|
|
|
4475
4514
|
```ts
|
|
4476
|
-
|
|
4515
|
+
zOne: boolean
|
|
4477
4516
|
```
|
|
4478
4517
|
|
|
4479
|
-
####
|
|
4518
|
+
#### Method add
|
|
4480
4519
|
|
|
4481
|
-
|
|
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
|
-
|
|
4525
|
+
add(p: JacobianPoint): JacobianPoint
|
|
4485
4526
|
```
|
|
4486
4527
|
|
|
4487
|
-
|
|
4528
|
+
Returns
|
|
4488
4529
|
|
|
4489
|
-
|
|
4530
|
+
Returns a new Jacobian point as the result of the addition.
|
|
4490
4531
|
|
|
4491
|
-
|
|
4492
|
-
### Class: SHA1
|
|
4532
|
+
Argument Details
|
|
4493
4533
|
|
|
4494
|
-
|
|
4495
|
-
|
|
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
|
|
4540
|
+
const p1 = new JacobianPoint(x1, y1, z1)
|
|
4541
|
+
const p2 = new JacobianPoint(x2, y2, z2)
|
|
4542
|
+
const result = p1.add(p2)
|
|
4503
4543
|
```
|
|
4504
4544
|
|
|
4545
|
+
#### Method dbl
|
|
4546
|
+
|
|
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.
|
|
4548
|
+
|
|
4505
4549
|
```ts
|
|
4506
|
-
|
|
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
|
-
}
|
|
4550
|
+
dbl(): JacobianPoint
|
|
4514
4551
|
```
|
|
4515
4552
|
|
|
4516
|
-
|
|
4553
|
+
Returns
|
|
4517
4554
|
|
|
4518
|
-
|
|
4555
|
+
Returns a new Jacobian point as the result of the doubling.
|
|
4519
4556
|
|
|
4520
|
-
|
|
4557
|
+
Example
|
|
4521
4558
|
|
|
4522
|
-
|
|
4559
|
+
```ts
|
|
4560
|
+
const jp = new JacobianPoint(x, y, z)
|
|
4561
|
+
const result = jp.dbl()
|
|
4562
|
+
```
|
|
4563
|
+
|
|
4564
|
+
#### Method dblp
|
|
4565
|
+
|
|
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.
|
|
4523
4567
|
|
|
4524
4568
|
```ts
|
|
4525
|
-
|
|
4569
|
+
dblp(pow: number): JacobianPoint
|
|
4526
4570
|
```
|
|
4527
4571
|
|
|
4528
|
-
|
|
4572
|
+
Returns
|
|
4529
4573
|
|
|
4530
|
-
|
|
4574
|
+
Returns a new Jacobian point as the result of multiple doublings.
|
|
4575
|
+
|
|
4576
|
+
Argument Details
|
|
4577
|
+
|
|
4578
|
+
+ **pow**
|
|
4579
|
+
+ The number of times the point should be doubled.
|
|
4580
|
+
|
|
4581
|
+
Example
|
|
4531
4582
|
|
|
4532
4583
|
```ts
|
|
4533
|
-
|
|
4584
|
+
const jp = new JacobianPoint(x, y, z)
|
|
4585
|
+
const result = jp.dblp(3)
|
|
4534
4586
|
```
|
|
4535
4587
|
|
|
4536
|
-
####
|
|
4588
|
+
#### Method eq
|
|
4537
4589
|
|
|
4538
|
-
|
|
4590
|
+
Equality check operation. It checks whether the affine or Jacobian point is equal to this Jacobian point.
|
|
4539
4591
|
|
|
4540
4592
|
```ts
|
|
4541
|
-
|
|
4593
|
+
eq(p: Point | JacobianPoint): boolean
|
|
4542
4594
|
```
|
|
4543
4595
|
|
|
4544
|
-
|
|
4596
|
+
Returns
|
|
4545
4597
|
|
|
4546
|
-
|
|
4598
|
+
Returns true if the points are equal, otherwise returns false.
|
|
4547
4599
|
|
|
4548
|
-
|
|
4549
|
-
### Class: SHA512
|
|
4600
|
+
Argument Details
|
|
4550
4601
|
|
|
4551
|
-
|
|
4552
|
-
|
|
4553
|
-
into a unique output of fixed size. The output is deterministic; it will always be
|
|
4554
|
-
the same for the same input.
|
|
4602
|
+
+ **p**
|
|
4603
|
+
+ The affine or Jacobian point to compare with.
|
|
4555
4604
|
|
|
4556
4605
|
Example
|
|
4557
4606
|
|
|
4558
4607
|
```ts
|
|
4559
|
-
const
|
|
4608
|
+
const jp1 = new JacobianPoint(x1, y1, z1)
|
|
4609
|
+
const jp2 = new JacobianPoint(x2, y2, z2)
|
|
4610
|
+
const areEqual = jp1.eq(jp2)
|
|
4560
4611
|
```
|
|
4561
4612
|
|
|
4613
|
+
#### Method eqXToP
|
|
4614
|
+
|
|
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.
|
|
4618
|
+
|
|
4562
4619
|
```ts
|
|
4563
|
-
|
|
4564
|
-
h: number[];
|
|
4565
|
-
W: number[];
|
|
4566
|
-
k: number[];
|
|
4567
|
-
constructor()
|
|
4568
|
-
_prepareBlock(msg, start)
|
|
4569
|
-
_update(msg, start)
|
|
4570
|
-
_digest(enc)
|
|
4571
|
-
}
|
|
4620
|
+
eqXToP(x: BigNumber): boolean
|
|
4572
4621
|
```
|
|
4573
4622
|
|
|
4574
|
-
|
|
4623
|
+
Returns
|
|
4575
4624
|
|
|
4576
|
-
|
|
4625
|
+
Returns true if the x coordinates are equal, otherwise returns false.
|
|
4577
4626
|
|
|
4578
|
-
|
|
4627
|
+
Argument Details
|
|
4579
4628
|
|
|
4580
|
-
|
|
4629
|
+
+ **x**
|
|
4630
|
+
+ The x coordinate of a point in projective coordinates.
|
|
4631
|
+
|
|
4632
|
+
Example
|
|
4581
4633
|
|
|
4582
4634
|
```ts
|
|
4583
|
-
|
|
4635
|
+
const jp = new JacobianPoint(x1, y1, z1)
|
|
4636
|
+
const isXEqual = jp.eqXToP(x2)
|
|
4584
4637
|
```
|
|
4585
4638
|
|
|
4586
|
-
####
|
|
4639
|
+
#### Method inspect
|
|
4587
4640
|
|
|
4588
|
-
|
|
4641
|
+
Returns the string representation of the JacobianPoint instance.
|
|
4589
4642
|
|
|
4590
4643
|
```ts
|
|
4591
|
-
|
|
4644
|
+
inspect(): string
|
|
4592
4645
|
```
|
|
4593
4646
|
|
|
4594
|
-
|
|
4647
|
+
Returns
|
|
4595
4648
|
|
|
4596
|
-
|
|
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>'.
|
|
4650
|
+
|
|
4651
|
+
Example
|
|
4597
4652
|
|
|
4598
4653
|
```ts
|
|
4599
|
-
|
|
4600
|
-
|
|
4601
|
-
|
|
4602
|
-
</details>
|
|
4603
|
-
|
|
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.
|
|
4614
|
-
|
|
4615
|
-
```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
|
-
}
|
|
4654
|
+
const point = new JacobianPoint('5', '6', '1');
|
|
4655
|
+
console.log(point.inspect()); // Output: '<EC JPoint x: 5 y: 6 z: 1>'
|
|
4625
4656
|
```
|
|
4626
4657
|
|
|
4627
|
-
|
|
4628
|
-
|
|
4629
|
-
<summary>Class SHA256HMAC Details</summary>
|
|
4630
|
-
|
|
4631
|
-
#### Constructor
|
|
4632
|
-
|
|
4633
|
-
The constructor for the `SHA256HMAC` class.
|
|
4658
|
+
#### Method isInfinity
|
|
4634
4659
|
|
|
4635
|
-
|
|
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.
|
|
4660
|
+
Checks whether the JacobianPoint instance represents a point at infinity.
|
|
4638
4661
|
|
|
4639
4662
|
```ts
|
|
4640
|
-
|
|
4663
|
+
isInfinity(): boolean
|
|
4641
4664
|
```
|
|
4642
4665
|
|
|
4643
|
-
|
|
4666
|
+
Returns
|
|
4644
4667
|
|
|
4645
|
-
|
|
4646
|
-
+ The key to use to create the HMAC. Can be a number array or a string in hexadecimal format.
|
|
4668
|
+
Returns true if the JacobianPoint's z-coordinate equals to zero (which represents the point at infinity in Jacobian coordinates). Returns false otherwise.
|
|
4647
4669
|
|
|
4648
4670
|
Example
|
|
4649
4671
|
|
|
4650
4672
|
```ts
|
|
4651
|
-
const
|
|
4652
|
-
|
|
4653
|
-
|
|
4654
|
-
#### Property blockSize
|
|
4655
|
-
|
|
4656
|
-
The block size for the SHA-256 hash function, in bytes. It's set to 64 bytes.
|
|
4657
|
-
|
|
4658
|
-
```ts
|
|
4659
|
-
blockSize = 64
|
|
4673
|
+
const point = new JacobianPoint('5', '6', '0');
|
|
4674
|
+
console.log(point.isInfinity()); // Output: true
|
|
4660
4675
|
```
|
|
4661
4676
|
|
|
4662
|
-
####
|
|
4677
|
+
#### Method mixedAdd
|
|
4663
4678
|
|
|
4664
|
-
|
|
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
|
-
|
|
4684
|
+
mixedAdd(p: Point): JacobianPoint
|
|
4668
4685
|
```
|
|
4669
4686
|
|
|
4670
|
-
|
|
4687
|
+
Returns
|
|
4671
4688
|
|
|
4672
|
-
|
|
4689
|
+
Returns the result of the mixed addition as a new Jacobian point.
|
|
4673
4690
|
|
|
4674
|
-
|
|
4675
|
-
outSize = 32
|
|
4676
|
-
```
|
|
4691
|
+
Argument Details
|
|
4677
4692
|
|
|
4678
|
-
|
|
4693
|
+
+ **p**
|
|
4694
|
+
+ The affine point to be added.
|
|
4679
4695
|
|
|
4680
|
-
|
|
4696
|
+
Example
|
|
4681
4697
|
|
|
4682
4698
|
```ts
|
|
4683
|
-
|
|
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
|
|
4704
|
+
#### Method neg
|
|
4687
4705
|
|
|
4688
|
-
|
|
4706
|
+
Negation operation. It returns the additive inverse of the Jacobian point.
|
|
4689
4707
|
|
|
4690
4708
|
```ts
|
|
4691
|
-
|
|
4709
|
+
neg(): JacobianPoint
|
|
4692
4710
|
```
|
|
4693
4711
|
|
|
4694
4712
|
Returns
|
|
4695
4713
|
|
|
4696
|
-
Returns
|
|
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
|
-
|
|
4719
|
+
const jp = new JacobianPoint(x, y, z)
|
|
4720
|
+
const result = jp.neg()
|
|
4707
4721
|
```
|
|
4708
4722
|
|
|
4709
|
-
#### Method
|
|
4723
|
+
#### Method toP
|
|
4710
4724
|
|
|
4711
|
-
|
|
4725
|
+
Converts the `JacobianPoint` object instance to standard affine `Point` format and returns `Point` type.
|
|
4712
4726
|
|
|
4713
4727
|
```ts
|
|
4714
|
-
|
|
4728
|
+
toP(): Point
|
|
4715
4729
|
```
|
|
4716
4730
|
|
|
4717
4731
|
Returns
|
|
4718
4732
|
|
|
4719
|
-
|
|
4720
|
-
|
|
4721
|
-
Argument Details
|
|
4733
|
+
The `Point`(affine) object representing the same point as the original `JacobianPoint`.
|
|
4722
4734
|
|
|
4723
|
-
|
|
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
|
-
|
|
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,621 +4746,575 @@ myHMAC.update('deadbeef', 'hex');
|
|
|
4736
4746
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
4737
4747
|
|
|
4738
4748
|
---
|
|
4739
|
-
### Class:
|
|
4749
|
+
### Class: RIPEMD160
|
|
4740
4750
|
|
|
4741
|
-
|
|
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.
|
|
4742
4755
|
|
|
4743
|
-
|
|
4756
|
+
Example
|
|
4744
4757
|
|
|
4745
|
-
|
|
4758
|
+
```ts
|
|
4759
|
+
const ripemd160 = new RIPEMD160();
|
|
4760
|
+
```
|
|
4746
4761
|
|
|
4747
4762
|
```ts
|
|
4748
|
-
export class
|
|
4749
|
-
|
|
4750
|
-
|
|
4751
|
-
|
|
4752
|
-
|
|
4753
|
-
|
|
4754
|
-
update(msg: number[] | string, enc?: "hex"): SHA512HMAC
|
|
4755
|
-
digest(enc?: "hex"): number[] | string
|
|
4763
|
+
export class RIPEMD160 extends BaseHash {
|
|
4764
|
+
h: number[];
|
|
4765
|
+
constructor()
|
|
4766
|
+
_update(msg: number[], start: number): void
|
|
4767
|
+
_digest(): number[]
|
|
4768
|
+
_digestHex(): string
|
|
4756
4769
|
}
|
|
4757
4770
|
```
|
|
4758
4771
|
|
|
4759
4772
|
<details>
|
|
4760
4773
|
|
|
4761
|
-
<summary>Class
|
|
4762
|
-
|
|
4763
|
-
#### Constructor
|
|
4774
|
+
<summary>Class RIPEMD160 Details</summary>
|
|
4764
4775
|
|
|
4765
|
-
|
|
4776
|
+
#### Property h
|
|
4766
4777
|
|
|
4767
|
-
|
|
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.
|
|
4778
|
+
Array that is updated iteratively as part of hashing computation.
|
|
4770
4779
|
|
|
4771
4780
|
```ts
|
|
4772
|
-
|
|
4781
|
+
h: number[]
|
|
4773
4782
|
```
|
|
4774
4783
|
|
|
4775
|
-
|
|
4784
|
+
</details>
|
|
4776
4785
|
|
|
4777
|
-
|
|
4778
|
-
|
|
4786
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
4787
|
+
|
|
4788
|
+
---
|
|
4789
|
+
### Class: SHA256
|
|
4790
|
+
|
|
4791
|
+
An implementation of SHA256 cryptographic hash function. Extends the BaseHash class.
|
|
4792
|
+
It provides a way to compute a 'digest' for any kind of input data; transforming the data
|
|
4793
|
+
into a unique output of fixed size. The output is deterministic; it will always be
|
|
4794
|
+
the same for the same input.
|
|
4779
4795
|
|
|
4780
4796
|
Example
|
|
4781
4797
|
|
|
4782
4798
|
```ts
|
|
4783
|
-
const
|
|
4799
|
+
const sha256 = new SHA256();
|
|
4784
4800
|
```
|
|
4785
4801
|
|
|
4786
|
-
#### Property blockSize
|
|
4787
|
-
|
|
4788
|
-
The block size for the SHA-512 hash function, in bytes. It's set to 128 bytes.
|
|
4789
|
-
|
|
4790
4802
|
```ts
|
|
4791
|
-
|
|
4803
|
+
export class SHA256 extends BaseHash {
|
|
4804
|
+
h: number[];
|
|
4805
|
+
W: number[];
|
|
4806
|
+
k: number[];
|
|
4807
|
+
constructor()
|
|
4808
|
+
_update(msg: number[], start?: number): void
|
|
4809
|
+
;
|
|
4810
|
+
_digest(): number[]
|
|
4811
|
+
_digestHex(): string
|
|
4812
|
+
}
|
|
4792
4813
|
```
|
|
4793
4814
|
|
|
4794
|
-
|
|
4795
|
-
|
|
4796
|
-
Represents the inner hash of SHA-512.
|
|
4815
|
+
<details>
|
|
4797
4816
|
|
|
4798
|
-
|
|
4799
|
-
inner: SHA512
|
|
4800
|
-
```
|
|
4817
|
+
<summary>Class SHA256 Details</summary>
|
|
4801
4818
|
|
|
4802
|
-
#### Property
|
|
4819
|
+
#### Property W
|
|
4803
4820
|
|
|
4804
|
-
|
|
4821
|
+
Provides a way to recycle usage of the array memory.
|
|
4805
4822
|
|
|
4806
4823
|
```ts
|
|
4807
|
-
|
|
4824
|
+
W: number[]
|
|
4808
4825
|
```
|
|
4809
4826
|
|
|
4810
|
-
#### Property
|
|
4827
|
+
#### Property h
|
|
4811
4828
|
|
|
4812
|
-
|
|
4829
|
+
The initial hash constants
|
|
4813
4830
|
|
|
4814
4831
|
```ts
|
|
4815
|
-
|
|
4832
|
+
h: number[]
|
|
4816
4833
|
```
|
|
4817
4834
|
|
|
4818
|
-
####
|
|
4835
|
+
#### Property k
|
|
4819
4836
|
|
|
4820
|
-
|
|
4837
|
+
The round constants used for each round of SHA-256
|
|
4821
4838
|
|
|
4822
4839
|
```ts
|
|
4823
|
-
|
|
4840
|
+
k: number[]
|
|
4824
4841
|
```
|
|
4825
4842
|
|
|
4826
|
-
|
|
4843
|
+
</details>
|
|
4827
4844
|
|
|
4828
|
-
|
|
4845
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
4829
4846
|
|
|
4830
|
-
|
|
4847
|
+
---
|
|
4848
|
+
### Class: SHA1
|
|
4831
4849
|
|
|
4832
|
-
|
|
4833
|
-
|
|
4850
|
+
An implementation of SHA1 cryptographic hash function. Extends the BaseHash class.
|
|
4851
|
+
It provides a way to compute a 'digest' for any kind of input data; transforming the data
|
|
4852
|
+
into a unique output of fixed size. The output is deterministic; it will always be
|
|
4853
|
+
the same for the same input.
|
|
4834
4854
|
|
|
4835
4855
|
Example
|
|
4836
4856
|
|
|
4837
4857
|
```ts
|
|
4838
|
-
|
|
4858
|
+
const sha1 = new SHA1();
|
|
4839
4859
|
```
|
|
4840
4860
|
|
|
4841
|
-
#### Method update
|
|
4842
|
-
|
|
4843
|
-
Updates the `SHA512HMAC` object with part of the message to be hashed.
|
|
4844
|
-
|
|
4845
4861
|
```ts
|
|
4846
|
-
|
|
4862
|
+
export class SHA1 extends BaseHash {
|
|
4863
|
+
h: number[];
|
|
4864
|
+
W: number[];
|
|
4865
|
+
k: number[];
|
|
4866
|
+
constructor()
|
|
4867
|
+
_update(msg: number[], start?: number): void
|
|
4868
|
+
_digest(): number[]
|
|
4869
|
+
_digestHex(): string
|
|
4870
|
+
}
|
|
4847
4871
|
```
|
|
4848
4872
|
|
|
4849
|
-
|
|
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.
|
|
4859
|
-
|
|
4860
|
-
Example
|
|
4861
|
-
|
|
4862
|
-
```ts
|
|
4863
|
-
myHMAC.update('deadbeef', 'hex');
|
|
4864
|
-
```
|
|
4873
|
+
<details>
|
|
4865
4874
|
|
|
4866
|
-
</
|
|
4875
|
+
<summary>Class SHA1 Details</summary>
|
|
4867
4876
|
|
|
4868
|
-
|
|
4877
|
+
#### Property W
|
|
4869
4878
|
|
|
4870
|
-
|
|
4871
|
-
### Class: Writer
|
|
4879
|
+
Provides a way to recycle usage of the array memory.
|
|
4872
4880
|
|
|
4873
4881
|
```ts
|
|
4874
|
-
|
|
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
|
-
}
|
|
4882
|
+
W: number[]
|
|
4899
4883
|
```
|
|
4900
4884
|
|
|
4901
|
-
|
|
4885
|
+
#### Property h
|
|
4902
4886
|
|
|
4903
|
-
|
|
4904
|
-
### Class: Reader
|
|
4887
|
+
The initial hash constants.
|
|
4905
4888
|
|
|
4906
4889
|
```ts
|
|
4907
|
-
|
|
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
|
-
}
|
|
4890
|
+
h: number[]
|
|
4930
4891
|
```
|
|
4931
4892
|
|
|
4932
|
-
|
|
4893
|
+
#### Property k
|
|
4933
4894
|
|
|
4934
|
-
|
|
4935
|
-
### Class: Curve
|
|
4895
|
+
The round constants used for each round of SHA-1.
|
|
4936
4896
|
|
|
4937
4897
|
```ts
|
|
4938
|
-
|
|
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
|
-
;
|
|
4997
|
-
}
|
|
4898
|
+
k: number[]
|
|
4998
4899
|
```
|
|
4999
4900
|
|
|
4901
|
+
</details>
|
|
4902
|
+
|
|
5000
4903
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
5001
4904
|
|
|
5002
4905
|
---
|
|
5003
|
-
### Class:
|
|
4906
|
+
### Class: SHA512
|
|
5004
4907
|
|
|
5005
|
-
|
|
5006
|
-
|
|
4908
|
+
An implementation of SHA512 cryptographic hash function. Extends the BaseHash class.
|
|
4909
|
+
It provides a way to compute a 'digest' for any kind of input data; transforming the data
|
|
4910
|
+
into a unique output of fixed size. The output is deterministic; it will always be
|
|
4911
|
+
the same for the same input.
|
|
4912
|
+
|
|
4913
|
+
Example
|
|
5007
4914
|
|
|
5008
4915
|
```ts
|
|
5009
|
-
|
|
5010
|
-
|
|
5011
|
-
|
|
5012
|
-
|
|
5013
|
-
|
|
5014
|
-
|
|
5015
|
-
|
|
5016
|
-
|
|
5017
|
-
|
|
5018
|
-
|
|
5019
|
-
|
|
5020
|
-
|
|
5021
|
-
|
|
5022
|
-
} | null;
|
|
5023
|
-
constructor(type: "affine" | "jacobian")
|
|
4916
|
+
const sha512 = new SHA512();
|
|
4917
|
+
```
|
|
4918
|
+
|
|
4919
|
+
```ts
|
|
4920
|
+
export class SHA512 extends BaseHash {
|
|
4921
|
+
h: number[];
|
|
4922
|
+
W: number[];
|
|
4923
|
+
k: number[];
|
|
4924
|
+
constructor()
|
|
4925
|
+
_prepareBlock(msg, start)
|
|
4926
|
+
_update(msg, start)
|
|
4927
|
+
_digest()
|
|
4928
|
+
_digestHex()
|
|
5024
4929
|
}
|
|
5025
4930
|
```
|
|
5026
4931
|
|
|
5027
|
-
|
|
4932
|
+
<details>
|
|
5028
4933
|
|
|
5029
|
-
|
|
5030
|
-
### Class: JacobianPoint
|
|
4934
|
+
<summary>Class SHA512 Details</summary>
|
|
5031
4935
|
|
|
5032
|
-
|
|
5033
|
-
This class defines the properties and the methods needed to work with points in Jacobian coordinates.
|
|
4936
|
+
#### Property W
|
|
5034
4937
|
|
|
5035
|
-
|
|
4938
|
+
Provides a way to recycle usage of the array memory.
|
|
5036
4939
|
|
|
5037
|
-
|
|
4940
|
+
```ts
|
|
4941
|
+
W: number[]
|
|
4942
|
+
```
|
|
4943
|
+
|
|
4944
|
+
#### Property h
|
|
4945
|
+
|
|
4946
|
+
The initial hash constants.
|
|
5038
4947
|
|
|
5039
4948
|
```ts
|
|
5040
|
-
|
|
4949
|
+
h: number[]
|
|
5041
4950
|
```
|
|
5042
4951
|
|
|
4952
|
+
#### Property k
|
|
4953
|
+
|
|
4954
|
+
The round constants used for each round of SHA-512.
|
|
4955
|
+
|
|
5043
4956
|
```ts
|
|
5044
|
-
|
|
5045
|
-
|
|
5046
|
-
|
|
5047
|
-
|
|
5048
|
-
|
|
5049
|
-
|
|
5050
|
-
|
|
5051
|
-
|
|
5052
|
-
|
|
5053
|
-
|
|
5054
|
-
|
|
5055
|
-
|
|
5056
|
-
|
|
5057
|
-
|
|
5058
|
-
|
|
5059
|
-
|
|
4957
|
+
k: number[]
|
|
4958
|
+
```
|
|
4959
|
+
|
|
4960
|
+
</details>
|
|
4961
|
+
|
|
4962
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
4963
|
+
|
|
4964
|
+
---
|
|
4965
|
+
### Class: SHA256HMAC
|
|
4966
|
+
|
|
4967
|
+
The `SHA256HMAC` class is used to create Hash-based Message Authentication Code (HMAC) using the SHA-256 cryptographic hash function.
|
|
4968
|
+
|
|
4969
|
+
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.
|
|
4970
|
+
|
|
4971
|
+
This class also uses the SHA-256 cryptographic hash algorithm that produces a 256-bit (32-byte) hash value.
|
|
4972
|
+
|
|
4973
|
+
```ts
|
|
4974
|
+
export class SHA256HMAC {
|
|
4975
|
+
inner: SHA256;
|
|
4976
|
+
outer: SHA256;
|
|
4977
|
+
blockSize = 64;
|
|
4978
|
+
outSize = 32;
|
|
4979
|
+
constructor(key: number[] | string)
|
|
4980
|
+
update(msg: number[] | string, enc?: "hex"): SHA256HMAC
|
|
4981
|
+
digest(): number[]
|
|
4982
|
+
digestHex(): string
|
|
5060
4983
|
}
|
|
5061
4984
|
```
|
|
5062
4985
|
|
|
5063
4986
|
<details>
|
|
5064
4987
|
|
|
5065
|
-
<summary>Class
|
|
4988
|
+
<summary>Class SHA256HMAC Details</summary>
|
|
5066
4989
|
|
|
5067
4990
|
#### Constructor
|
|
5068
4991
|
|
|
5069
|
-
|
|
4992
|
+
The constructor for the `SHA256HMAC` class.
|
|
4993
|
+
|
|
4994
|
+
It initializes the `SHA256HMAC` object and sets up the inner and outer padded keys.
|
|
4995
|
+
If the key size is larger than the blockSize, it is digested using SHA-256.
|
|
4996
|
+
If the key size is less than the blockSize, it is padded with zeroes.
|
|
5070
4997
|
|
|
5071
4998
|
```ts
|
|
5072
|
-
constructor(
|
|
4999
|
+
constructor(key: number[] | string)
|
|
5073
5000
|
```
|
|
5074
5001
|
|
|
5075
5002
|
Argument Details
|
|
5076
5003
|
|
|
5077
|
-
+ **
|
|
5078
|
-
+
|
|
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.
|
|
5004
|
+
+ **key**
|
|
5005
|
+
+ The key to use to create the HMAC. Can be a number array or a string in hexadecimal format.
|
|
5086
5006
|
|
|
5087
5007
|
Example
|
|
5088
5008
|
|
|
5089
5009
|
```ts
|
|
5090
|
-
const
|
|
5091
|
-
const pointJ2 = new JacobianPoint('3', '4', '1'); // creates point (3, 4, 1)
|
|
5010
|
+
const myHMAC = new SHA256HMAC('deadbeef');
|
|
5092
5011
|
```
|
|
5093
5012
|
|
|
5094
|
-
#### Property
|
|
5013
|
+
#### Property blockSize
|
|
5095
5014
|
|
|
5096
|
-
The
|
|
5015
|
+
The block size for the SHA-256 hash function, in bytes. It's set to 64 bytes.
|
|
5097
5016
|
|
|
5098
5017
|
```ts
|
|
5099
|
-
|
|
5018
|
+
blockSize = 64
|
|
5100
5019
|
```
|
|
5101
5020
|
|
|
5102
|
-
#### Property
|
|
5021
|
+
#### Property inner
|
|
5103
5022
|
|
|
5104
|
-
|
|
5023
|
+
Represents the inner hash of SHA-256.
|
|
5105
5024
|
|
|
5106
5025
|
```ts
|
|
5107
|
-
|
|
5026
|
+
inner: SHA256
|
|
5108
5027
|
```
|
|
5109
5028
|
|
|
5110
|
-
#### Property
|
|
5029
|
+
#### Property outSize
|
|
5111
5030
|
|
|
5112
|
-
The
|
|
5031
|
+
The output size of the SHA-256 hash function, in bytes. It's set to 32 bytes.
|
|
5113
5032
|
|
|
5114
5033
|
```ts
|
|
5115
|
-
|
|
5034
|
+
outSize = 32
|
|
5116
5035
|
```
|
|
5117
5036
|
|
|
5118
|
-
#### Property
|
|
5037
|
+
#### Property outer
|
|
5119
5038
|
|
|
5120
|
-
|
|
5039
|
+
Represents the outer hash of SHA-256.
|
|
5121
5040
|
|
|
5122
5041
|
```ts
|
|
5123
|
-
|
|
5042
|
+
outer: SHA256
|
|
5124
5043
|
```
|
|
5125
5044
|
|
|
5126
|
-
#### Method
|
|
5045
|
+
#### Method digest
|
|
5127
5046
|
|
|
5128
|
-
|
|
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.
|
|
5047
|
+
Finalizes the HMAC computation and returns the resultant hash.
|
|
5131
5048
|
|
|
5132
5049
|
```ts
|
|
5133
|
-
|
|
5050
|
+
digest(): number[]
|
|
5134
5051
|
```
|
|
5135
5052
|
|
|
5136
5053
|
Returns
|
|
5137
5054
|
|
|
5138
|
-
Returns
|
|
5139
|
-
|
|
5140
|
-
Argument Details
|
|
5141
|
-
|
|
5142
|
-
+ **p**
|
|
5143
|
-
+ The Jacobian point to be added.
|
|
5055
|
+
Returns the digest of the hashed data. Can be a number array or a string.
|
|
5144
5056
|
|
|
5145
5057
|
Example
|
|
5146
5058
|
|
|
5147
5059
|
```ts
|
|
5148
|
-
|
|
5149
|
-
const p2 = new JacobianPoint(x2, y2, z2)
|
|
5150
|
-
const result = p1.add(p2)
|
|
5060
|
+
let hashedMessage = myHMAC.digest();
|
|
5151
5061
|
```
|
|
5152
5062
|
|
|
5153
|
-
#### Method
|
|
5063
|
+
#### Method digestHex
|
|
5154
5064
|
|
|
5155
|
-
|
|
5065
|
+
Finalizes the HMAC computation and returns the resultant hash as a hex string.
|
|
5156
5066
|
|
|
5157
5067
|
```ts
|
|
5158
|
-
|
|
5068
|
+
digestHex(): string
|
|
5159
5069
|
```
|
|
5160
5070
|
|
|
5161
5071
|
Returns
|
|
5162
5072
|
|
|
5163
|
-
Returns
|
|
5073
|
+
Returns the digest of the hashed data as a hex string
|
|
5164
5074
|
|
|
5165
5075
|
Example
|
|
5166
5076
|
|
|
5167
5077
|
```ts
|
|
5168
|
-
|
|
5169
|
-
const result = jp.dbl()
|
|
5078
|
+
let hashedMessage = myHMAC.digestHex();
|
|
5170
5079
|
```
|
|
5171
5080
|
|
|
5172
|
-
#### Method
|
|
5081
|
+
#### Method update
|
|
5173
5082
|
|
|
5174
|
-
|
|
5083
|
+
Updates the `SHA256HMAC` object with part of the message to be hashed.
|
|
5175
5084
|
|
|
5176
5085
|
```ts
|
|
5177
|
-
|
|
5086
|
+
update(msg: number[] | string, enc?: "hex"): SHA256HMAC
|
|
5178
5087
|
```
|
|
5179
5088
|
|
|
5180
5089
|
Returns
|
|
5181
5090
|
|
|
5182
|
-
Returns
|
|
5091
|
+
Returns the instance of `SHA256HMAC` for chaining calls.
|
|
5183
5092
|
|
|
5184
5093
|
Argument Details
|
|
5185
5094
|
|
|
5186
|
-
+ **
|
|
5187
|
-
+
|
|
5095
|
+
+ **msg**
|
|
5096
|
+
+ Part of the message to hash. Can be a number array or a string.
|
|
5097
|
+
+ **enc**
|
|
5098
|
+
+ If 'hex', then the input is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
|
|
5188
5099
|
|
|
5189
5100
|
Example
|
|
5190
5101
|
|
|
5191
5102
|
```ts
|
|
5192
|
-
|
|
5193
|
-
const result = jp.dblp(3)
|
|
5103
|
+
myHMAC.update('deadbeef', 'hex');
|
|
5194
5104
|
```
|
|
5195
5105
|
|
|
5196
|
-
|
|
5106
|
+
</details>
|
|
5197
5107
|
|
|
5198
|
-
|
|
5108
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
5109
|
+
|
|
5110
|
+
---
|
|
5111
|
+
### Class: SHA512HMAC
|
|
5112
|
+
|
|
5113
|
+
The `SHA512HMAC` class is used to create Hash-based Message Authentication Code (HMAC) using the SHA-512 cryptographic hash function.
|
|
5114
|
+
|
|
5115
|
+
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.
|
|
5116
|
+
|
|
5117
|
+
This class also uses the SHA-512 cryptographic hash algorithm that produces a 512-bit (64-byte) hash value.
|
|
5199
5118
|
|
|
5200
5119
|
```ts
|
|
5201
|
-
|
|
5120
|
+
export class SHA512HMAC {
|
|
5121
|
+
inner: SHA512;
|
|
5122
|
+
outer: SHA512;
|
|
5123
|
+
blockSize = 128;
|
|
5124
|
+
outSize = 32;
|
|
5125
|
+
constructor(key: number[] | string)
|
|
5126
|
+
update(msg: number[] | string, enc?: "hex" | "utf8"): SHA512HMAC
|
|
5127
|
+
digest(): number[]
|
|
5128
|
+
digestHex(): string
|
|
5129
|
+
}
|
|
5202
5130
|
```
|
|
5203
5131
|
|
|
5204
|
-
|
|
5132
|
+
<details>
|
|
5205
5133
|
|
|
5206
|
-
|
|
5134
|
+
<summary>Class SHA512HMAC Details</summary>
|
|
5207
5135
|
|
|
5208
|
-
|
|
5136
|
+
#### Constructor
|
|
5209
5137
|
|
|
5210
|
-
|
|
5211
|
-
+ The affine or Jacobian point to compare with.
|
|
5138
|
+
The constructor for the `SHA512HMAC` class.
|
|
5212
5139
|
|
|
5213
|
-
|
|
5140
|
+
It initializes the `SHA512HMAC` object and sets up the inner and outer padded keys.
|
|
5141
|
+
If the key size is larger than the blockSize, it is digested using SHA-512.
|
|
5142
|
+
If the key size is less than the blockSize, it is padded with zeroes.
|
|
5214
5143
|
|
|
5215
5144
|
```ts
|
|
5216
|
-
|
|
5217
|
-
const jp2 = new JacobianPoint(x2, y2, z2)
|
|
5218
|
-
const areEqual = jp1.eq(jp2)
|
|
5145
|
+
constructor(key: number[] | string)
|
|
5219
5146
|
```
|
|
5220
5147
|
|
|
5221
|
-
|
|
5148
|
+
Argument Details
|
|
5222
5149
|
|
|
5223
|
-
|
|
5224
|
-
|
|
5225
|
-
|
|
5150
|
+
+ **key**
|
|
5151
|
+
+ The key to use to create the HMAC. Can be a number array or a string in hexadecimal format.
|
|
5152
|
+
|
|
5153
|
+
Example
|
|
5226
5154
|
|
|
5227
5155
|
```ts
|
|
5228
|
-
|
|
5156
|
+
const myHMAC = new SHA512HMAC('deadbeef');
|
|
5229
5157
|
```
|
|
5230
5158
|
|
|
5231
|
-
|
|
5159
|
+
#### Property blockSize
|
|
5232
5160
|
|
|
5233
|
-
|
|
5161
|
+
The block size for the SHA-512 hash function, in bytes. It's set to 128 bytes.
|
|
5234
5162
|
|
|
5235
|
-
|
|
5163
|
+
```ts
|
|
5164
|
+
blockSize = 128
|
|
5165
|
+
```
|
|
5236
5166
|
|
|
5237
|
-
|
|
5238
|
-
+ The x coordinate of a point in projective coordinates.
|
|
5167
|
+
#### Property inner
|
|
5239
5168
|
|
|
5240
|
-
|
|
5169
|
+
Represents the inner hash of SHA-512.
|
|
5241
5170
|
|
|
5242
|
-
```ts
|
|
5243
|
-
|
|
5244
|
-
const isXEqual = jp.eqXToP(x2)
|
|
5171
|
+
```ts
|
|
5172
|
+
inner: SHA512
|
|
5245
5173
|
```
|
|
5246
5174
|
|
|
5247
|
-
####
|
|
5175
|
+
#### Property outSize
|
|
5248
5176
|
|
|
5249
|
-
|
|
5177
|
+
The output size of the SHA-512 hash function, in bytes. It's set to 64 bytes.
|
|
5250
5178
|
|
|
5251
5179
|
```ts
|
|
5252
|
-
|
|
5180
|
+
outSize = 32
|
|
5253
5181
|
```
|
|
5254
5182
|
|
|
5255
|
-
|
|
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>'.
|
|
5183
|
+
#### Property outer
|
|
5258
5184
|
|
|
5259
|
-
|
|
5185
|
+
Represents the outer hash of SHA-512.
|
|
5260
5186
|
|
|
5261
5187
|
```ts
|
|
5262
|
-
|
|
5263
|
-
console.log(point.inspect()); // Output: '<EC JPoint x: 5 y: 6 z: 1>'
|
|
5188
|
+
outer: SHA512
|
|
5264
5189
|
```
|
|
5265
5190
|
|
|
5266
|
-
#### Method
|
|
5191
|
+
#### Method digest
|
|
5267
5192
|
|
|
5268
|
-
|
|
5193
|
+
Finalizes the HMAC computation and returns the resultant hash.
|
|
5269
5194
|
|
|
5270
5195
|
```ts
|
|
5271
|
-
|
|
5196
|
+
digest(): number[]
|
|
5272
5197
|
```
|
|
5273
5198
|
|
|
5274
5199
|
Returns
|
|
5275
5200
|
|
|
5276
|
-
Returns
|
|
5201
|
+
Returns the digest of the hashed data as a number array.
|
|
5277
5202
|
|
|
5278
5203
|
Example
|
|
5279
5204
|
|
|
5280
5205
|
```ts
|
|
5281
|
-
|
|
5282
|
-
console.log(point.isInfinity()); // Output: true
|
|
5206
|
+
let hashedMessage = myHMAC.digest();
|
|
5283
5207
|
```
|
|
5284
5208
|
|
|
5285
|
-
#### Method
|
|
5209
|
+
#### Method digestHex
|
|
5286
5210
|
|
|
5287
|
-
|
|
5288
|
-
the transformation from the affine to Jacobian coordinates. It first converts
|
|
5289
|
-
the affine point to Jacobian, and then preforms the addition.
|
|
5211
|
+
Finalizes the HMAC computation and returns the resultant hash as a hex string.
|
|
5290
5212
|
|
|
5291
5213
|
```ts
|
|
5292
|
-
|
|
5214
|
+
digestHex(): string
|
|
5293
5215
|
```
|
|
5294
5216
|
|
|
5295
5217
|
Returns
|
|
5296
5218
|
|
|
5297
|
-
Returns the
|
|
5298
|
-
|
|
5299
|
-
Argument Details
|
|
5300
|
-
|
|
5301
|
-
+ **p**
|
|
5302
|
-
+ The affine point to be added.
|
|
5219
|
+
Returns the digest of the hashed data as a hex string
|
|
5303
5220
|
|
|
5304
5221
|
Example
|
|
5305
5222
|
|
|
5306
5223
|
```ts
|
|
5307
|
-
|
|
5308
|
-
const ap = new Point(x2, y2)
|
|
5309
|
-
const result = jp.mixedAdd(ap)
|
|
5224
|
+
let hashedMessage = myHMAC.digestHex();
|
|
5310
5225
|
```
|
|
5311
5226
|
|
|
5312
|
-
#### Method
|
|
5227
|
+
#### Method update
|
|
5313
5228
|
|
|
5314
|
-
|
|
5229
|
+
Updates the `SHA512HMAC` object with part of the message to be hashed.
|
|
5315
5230
|
|
|
5316
5231
|
```ts
|
|
5317
|
-
|
|
5232
|
+
update(msg: number[] | string, enc?: "hex" | "utf8"): SHA512HMAC
|
|
5318
5233
|
```
|
|
5319
5234
|
|
|
5320
5235
|
Returns
|
|
5321
5236
|
|
|
5322
|
-
Returns
|
|
5237
|
+
Returns the instance of `SHA512HMAC` for chaining calls.
|
|
5238
|
+
|
|
5239
|
+
Argument Details
|
|
5240
|
+
|
|
5241
|
+
+ **msg**
|
|
5242
|
+
+ Part of the message to hash. Can be a number array or a string.
|
|
5243
|
+
+ **enc**
|
|
5244
|
+
+ If 'hex', then the input is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
|
|
5323
5245
|
|
|
5324
5246
|
Example
|
|
5325
5247
|
|
|
5326
5248
|
```ts
|
|
5327
|
-
|
|
5328
|
-
const result = jp.neg()
|
|
5249
|
+
myHMAC.update('deadbeef', 'hex');
|
|
5329
5250
|
```
|
|
5330
5251
|
|
|
5331
|
-
|
|
5252
|
+
</details>
|
|
5332
5253
|
|
|
5333
|
-
|
|
5254
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
5255
|
+
|
|
5256
|
+
---
|
|
5257
|
+
### Class: Writer
|
|
5334
5258
|
|
|
5335
5259
|
```ts
|
|
5336
|
-
|
|
5260
|
+
export class Writer {
|
|
5261
|
+
public bufs: number[][];
|
|
5262
|
+
constructor(bufs?: number[][])
|
|
5263
|
+
getLength(): number
|
|
5264
|
+
toArray(): number[]
|
|
5265
|
+
write(buf: number[]): Writer
|
|
5266
|
+
writeReverse(buf: number[]): Writer
|
|
5267
|
+
writeUInt8(n: number): Writer
|
|
5268
|
+
writeInt8(n: number): Writer
|
|
5269
|
+
writeUInt16BE(n: number): Writer
|
|
5270
|
+
writeInt16BE(n: number): Writer
|
|
5271
|
+
writeUInt16LE(n: number): Writer
|
|
5272
|
+
writeInt16LE(n: number): Writer
|
|
5273
|
+
writeUInt32BE(n: number): Writer
|
|
5274
|
+
writeInt32BE(n: number): Writer
|
|
5275
|
+
writeUInt32LE(n: number): Writer
|
|
5276
|
+
writeInt32LE(n: number): Writer
|
|
5277
|
+
writeUInt64BEBn(bn: BigNumber): Writer
|
|
5278
|
+
writeUInt64LEBn(bn: BigNumber): Writer
|
|
5279
|
+
writeUInt64LE(n: number): Writer
|
|
5280
|
+
writeVarIntNum(n: number): Writer
|
|
5281
|
+
writeVarIntBn(bn: BigNumber): Writer
|
|
5282
|
+
static varIntNum(n: number): number[]
|
|
5283
|
+
static varIntBn(bn: BigNumber): number[]
|
|
5284
|
+
}
|
|
5337
5285
|
```
|
|
5338
5286
|
|
|
5339
|
-
|
|
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.
|
|
5287
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
5344
5288
|
|
|
5345
|
-
|
|
5289
|
+
---
|
|
5290
|
+
### Class: Reader
|
|
5346
5291
|
|
|
5347
5292
|
```ts
|
|
5348
|
-
|
|
5349
|
-
|
|
5293
|
+
export class Reader {
|
|
5294
|
+
public bin: number[];
|
|
5295
|
+
public pos: number;
|
|
5296
|
+
constructor(bin: number[] = [], pos: number = 0)
|
|
5297
|
+
public eof(): boolean
|
|
5298
|
+
public read(len = this.bin.length): number[]
|
|
5299
|
+
public readReverse(len = this.bin.length): number[]
|
|
5300
|
+
public readUInt8(): number
|
|
5301
|
+
public readInt8(): number
|
|
5302
|
+
public readUInt16BE(): number
|
|
5303
|
+
public readInt16BE(): number
|
|
5304
|
+
public readUInt16LE(): number
|
|
5305
|
+
public readInt16LE(): number
|
|
5306
|
+
public readUInt32BE(): number
|
|
5307
|
+
public readInt32BE(): number
|
|
5308
|
+
public readUInt32LE(): number
|
|
5309
|
+
public readInt32LE(): number
|
|
5310
|
+
public readUInt64BEBn(): BigNumber
|
|
5311
|
+
public readUInt64LEBn(): BigNumber
|
|
5312
|
+
public readVarIntNum(): number
|
|
5313
|
+
public readVarInt(): number[]
|
|
5314
|
+
public readVarIntBn(): BigNumber
|
|
5315
|
+
}
|
|
5350
5316
|
```
|
|
5351
5317
|
|
|
5352
|
-
</details>
|
|
5353
|
-
|
|
5354
5318
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
5355
5319
|
|
|
5356
5320
|
---
|
|
@@ -5934,6 +5898,74 @@ const isValid = aPoint.validate();
|
|
|
5934
5898
|
|
|
5935
5899
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
5936
5900
|
|
|
5901
|
+
---
|
|
5902
|
+
### Class: Curve
|
|
5903
|
+
|
|
5904
|
+
```ts
|
|
5905
|
+
export default class Curve {
|
|
5906
|
+
p: BigNumber;
|
|
5907
|
+
red: ReductionContext;
|
|
5908
|
+
redN: BigNumber | null;
|
|
5909
|
+
zero: BigNumber;
|
|
5910
|
+
one: BigNumber;
|
|
5911
|
+
two: BigNumber;
|
|
5912
|
+
g: Point;
|
|
5913
|
+
n: BigNumber;
|
|
5914
|
+
a: BigNumber;
|
|
5915
|
+
b: BigNumber;
|
|
5916
|
+
tinv: BigNumber;
|
|
5917
|
+
zeroA: boolean;
|
|
5918
|
+
threeA: boolean;
|
|
5919
|
+
endo: any;
|
|
5920
|
+
_endoWnafT1: any[];
|
|
5921
|
+
_endoWnafT2: any[];
|
|
5922
|
+
_wnafT1: any[];
|
|
5923
|
+
_wnafT2: any[];
|
|
5924
|
+
_wnafT3: any[];
|
|
5925
|
+
_wnafT4: any[];
|
|
5926
|
+
_bitLength: number;
|
|
5927
|
+
static assert(expression: unknown, message: string = "Elliptic curve assertion failed"): void
|
|
5928
|
+
getNAF(num: BigNumber, w: number, bits: number): number[]
|
|
5929
|
+
getJSF(k1: BigNumber, k2: BigNumber): number[][]
|
|
5930
|
+
static cachedProperty(obj, name: string, computer): void
|
|
5931
|
+
static parseBytes(bytes: string | number[]): number[]
|
|
5932
|
+
static intFromLE(bytes: number[]): BigNumber
|
|
5933
|
+
constructor()
|
|
5934
|
+
_getEndomorphism(conf): {
|
|
5935
|
+
beta: BigNumber;
|
|
5936
|
+
lambda: BigNumber;
|
|
5937
|
+
basis: Array<{
|
|
5938
|
+
a: BigNumber;
|
|
5939
|
+
b: BigNumber;
|
|
5940
|
+
}>;
|
|
5941
|
+
} | undefined
|
|
5942
|
+
;
|
|
5943
|
+
_getEndoRoots(num: BigNumber): [
|
|
5944
|
+
BigNumber,
|
|
5945
|
+
BigNumber
|
|
5946
|
+
]
|
|
5947
|
+
;
|
|
5948
|
+
_getEndoBasis(lambda: BigNumber): [
|
|
5949
|
+
{
|
|
5950
|
+
a: BigNumber;
|
|
5951
|
+
b: BigNumber;
|
|
5952
|
+
},
|
|
5953
|
+
{
|
|
5954
|
+
a: BigNumber;
|
|
5955
|
+
b: BigNumber;
|
|
5956
|
+
}
|
|
5957
|
+
]
|
|
5958
|
+
_endoSplit(k: BigNumber): {
|
|
5959
|
+
k1: BigNumber;
|
|
5960
|
+
k2: BigNumber;
|
|
5961
|
+
}
|
|
5962
|
+
validate(point: Point): boolean
|
|
5963
|
+
;
|
|
5964
|
+
}
|
|
5965
|
+
```
|
|
5966
|
+
|
|
5967
|
+
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
5968
|
+
|
|
5937
5969
|
---
|
|
5938
5970
|
### Class: DRBG
|
|
5939
5971
|
|
|
@@ -6212,7 +6244,8 @@ export default class PrivateKey extends BigNumber {
|
|
|
6212
6244
|
static fromRandom(): PrivateKey
|
|
6213
6245
|
static fromString(str: string, base: number | "hex"): PrivateKey
|
|
6214
6246
|
static fromWif(wif: string, prefixLength: number = 1): PrivateKey
|
|
6215
|
-
|
|
6247
|
+
constructor(number: BigNumber | number | string | number[] = 0, base: number | "be" | "le" | "hex" = 10, endian: "be" | "le" = "be")
|
|
6248
|
+
sign(msg: number[] | string, enc?: "hex" | "utf8", forceLowS: boolean = true, customK?: Function | BigNumber): Signature
|
|
6216
6249
|
verify(msg: number[] | string, sig: Signature, enc?: "hex"): boolean
|
|
6217
6250
|
toPublicKey(): PublicKey
|
|
6218
6251
|
toWif(prefix: number[] = [128]): string
|
|
@@ -6226,6 +6259,29 @@ export default class PrivateKey extends BigNumber {
|
|
|
6226
6259
|
|
|
6227
6260
|
<summary>Class PrivateKey Details</summary>
|
|
6228
6261
|
|
|
6262
|
+
#### Constructor
|
|
6263
|
+
|
|
6264
|
+
```ts
|
|
6265
|
+
constructor(number: BigNumber | number | string | number[] = 0, base: number | "be" | "le" | "hex" = 10, endian: "be" | "le" = "be")
|
|
6266
|
+
```
|
|
6267
|
+
|
|
6268
|
+
Argument Details
|
|
6269
|
+
|
|
6270
|
+
+ **number**
|
|
6271
|
+
+ The number (various types accepted) to construct a BigNumber from. Default is 0.
|
|
6272
|
+
+ **base**
|
|
6273
|
+
+ The base of number provided. By default is 10. Ignored if number is BigNumber.
|
|
6274
|
+
+ **endian**
|
|
6275
|
+
+ The endianness provided. By default is 'big endian'. Ignored if number is BigNumber.
|
|
6276
|
+
|
|
6277
|
+
Example
|
|
6278
|
+
|
|
6279
|
+
```ts
|
|
6280
|
+
import PrivateKey from './PrivateKey';
|
|
6281
|
+
import BigNumber from './BigNumber';
|
|
6282
|
+
const privKey = new PrivateKey(new BigNumber('123456', 10, 'be'));
|
|
6283
|
+
```
|
|
6284
|
+
|
|
6229
6285
|
#### Method deriveChild
|
|
6230
6286
|
|
|
6231
6287
|
Derives a child key with BRC-42.
|
|
@@ -6343,7 +6399,7 @@ Will throw an error if the string is not a valid WIF.
|
|
|
6343
6399
|
Signs a message using the private key.
|
|
6344
6400
|
|
|
6345
6401
|
```ts
|
|
6346
|
-
sign(msg: number[] | string, enc?: "hex", forceLowS: boolean = true, customK?: Function | BigNumber): Signature
|
|
6402
|
+
sign(msg: number[] | string, enc?: "hex" | "utf8", forceLowS: boolean = true, customK?: Function | BigNumber): Signature
|
|
6347
6403
|
```
|
|
6348
6404
|
|
|
6349
6405
|
Returns
|
|
@@ -6485,8 +6541,9 @@ The class comes with static methods to generate PublicKey instances from private
|
|
|
6485
6541
|
export default class PublicKey extends Point {
|
|
6486
6542
|
static fromPrivateKey(key: PrivateKey): PublicKey
|
|
6487
6543
|
static fromString(str: string): PublicKey
|
|
6544
|
+
constructor(x: Point | BigNumber | number | number[] | string | null, y: BigNumber | number | number[] | string | null = null, isRed: boolean = true)
|
|
6488
6545
|
deriveSharedSecret(priv: PrivateKey): Point
|
|
6489
|
-
verify(msg: number[] | string, sig: Signature, enc?: "hex"): boolean
|
|
6546
|
+
verify(msg: number[] | string, sig: Signature, enc?: "hex" | "utf8"): boolean
|
|
6490
6547
|
toDER(): string
|
|
6491
6548
|
toHash(enc?: "hex"): number[] | string
|
|
6492
6549
|
toAddress(prefix: number[] = [0]): string
|
|
@@ -6498,6 +6555,28 @@ export default class PublicKey extends Point {
|
|
|
6498
6555
|
|
|
6499
6556
|
<summary>Class PublicKey Details</summary>
|
|
6500
6557
|
|
|
6558
|
+
#### Constructor
|
|
6559
|
+
|
|
6560
|
+
```ts
|
|
6561
|
+
constructor(x: Point | BigNumber | number | number[] | string | null, y: BigNumber | number | number[] | string | null = null, isRed: boolean = true)
|
|
6562
|
+
```
|
|
6563
|
+
|
|
6564
|
+
Argument Details
|
|
6565
|
+
|
|
6566
|
+
+ **x**
|
|
6567
|
+
+ A point or the x-coordinate of the point. May be a number, a BigNumber, a string (which will be interpreted as hex), a number array, or null. If null, an "Infinity" point is constructed.
|
|
6568
|
+
+ **y**
|
|
6569
|
+
+ If x is not a point, the y-coordinate of the point, similar to x.
|
|
6570
|
+
+ **isRed**
|
|
6571
|
+
+ A boolean indicating if the point is a member of the field of integers modulo the k256 prime. Default is true.
|
|
6572
|
+
|
|
6573
|
+
Example
|
|
6574
|
+
|
|
6575
|
+
```ts
|
|
6576
|
+
new PublicKey(point1);
|
|
6577
|
+
new PublicKey('abc123', 'def456');
|
|
6578
|
+
```
|
|
6579
|
+
|
|
6501
6580
|
#### Method deriveChild
|
|
6502
6581
|
|
|
6503
6582
|
Derives a child key with BRC-42.
|
|
@@ -6660,7 +6739,7 @@ const publicKeyHash = pubkey.toHash()
|
|
|
6660
6739
|
Verify a signature of a message using this public key.
|
|
6661
6740
|
|
|
6662
6741
|
```ts
|
|
6663
|
-
verify(msg: number[] | string, sig: Signature, enc?: "hex"): boolean
|
|
6742
|
+
verify(msg: number[] | string, sig: Signature, enc?: "hex" | "utf8"): boolean
|
|
6664
6743
|
```
|
|
6665
6744
|
|
|
6666
6745
|
Returns
|
|
@@ -6674,7 +6753,7 @@ Argument Details
|
|
|
6674
6753
|
+ **sig**
|
|
6675
6754
|
+ The Signature of the message that needs verification.
|
|
6676
6755
|
+ **enc**
|
|
6677
|
-
+ The encoding of the message. It defaults to '
|
|
6756
|
+
+ The encoding of the message. It defaults to 'utf8'.
|
|
6678
6757
|
|
|
6679
6758
|
Example
|
|
6680
6759
|
|
|
@@ -6697,6 +6776,7 @@ It leverages the Advanced Encryption Standard Galois/Counter Mode (AES-GCM) for
|
|
|
6697
6776
|
|
|
6698
6777
|
```ts
|
|
6699
6778
|
export default class SymmetricKey extends BigNumber {
|
|
6779
|
+
static fromRandom(): SymmetricKey
|
|
6700
6780
|
encrypt(msg: number[] | string, enc?: "hex"): string | number[]
|
|
6701
6781
|
decrypt(msg: number[] | string, enc?: "hex" | "utf8"): string | number[]
|
|
6702
6782
|
}
|
|
@@ -6766,6 +6846,24 @@ const key = new SymmetricKey(1234);
|
|
|
6766
6846
|
const encryptedMessage = key.encrypt('plainText', 'utf8');
|
|
6767
6847
|
```
|
|
6768
6848
|
|
|
6849
|
+
#### Method fromRandom
|
|
6850
|
+
|
|
6851
|
+
Generates a symmetric key randomly.
|
|
6852
|
+
|
|
6853
|
+
```ts
|
|
6854
|
+
static fromRandom(): SymmetricKey
|
|
6855
|
+
```
|
|
6856
|
+
|
|
6857
|
+
Returns
|
|
6858
|
+
|
|
6859
|
+
The newly generated Symmetric Key.
|
|
6860
|
+
|
|
6861
|
+
Example
|
|
6862
|
+
|
|
6863
|
+
```ts
|
|
6864
|
+
const symmetricKey = SymmetricKey.fromRandom();
|
|
6865
|
+
```
|
|
6866
|
+
|
|
6769
6867
|
</details>
|
|
6770
6868
|
|
|
6771
6869
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
@@ -6790,9 +6888,24 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
6790
6888
|
### Function: toArray
|
|
6791
6889
|
|
|
6792
6890
|
```ts
|
|
6793
|
-
export function toArray(msg: number[] | string, enc?: "hex"): number[]
|
|
6891
|
+
export function toArray(msg: number[] | string, enc?: "hex" | "utf8"): number[]
|
|
6794
6892
|
```
|
|
6795
6893
|
|
|
6894
|
+
<details>
|
|
6895
|
+
|
|
6896
|
+
<summary>Function toArray Details</summary>
|
|
6897
|
+
|
|
6898
|
+
Returns
|
|
6899
|
+
|
|
6900
|
+
array of byte values from msg. If msg is an array, a copy is returned.
|
|
6901
|
+
|
|
6902
|
+
Argument Details
|
|
6903
|
+
|
|
6904
|
+
+ **enc**
|
|
6905
|
+
+ Optional. Encoding to use if msg is string. Default is 'utf8'.
|
|
6906
|
+
|
|
6907
|
+
</details>
|
|
6908
|
+
|
|
6796
6909
|
Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
|
|
6797
6910
|
|
|
6798
6911
|
---
|
|
@@ -6923,8 +7036,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
6923
7036
|
### Variable: ripemd160
|
|
6924
7037
|
|
|
6925
7038
|
```ts
|
|
6926
|
-
ripemd160 = (msg: number[] | string, enc?: "hex"): number[]
|
|
6927
|
-
return new RIPEMD160().update(msg, enc).digest(
|
|
7039
|
+
ripemd160 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
|
|
7040
|
+
return new RIPEMD160().update(msg, enc).digest();
|
|
6928
7041
|
}
|
|
6929
7042
|
```
|
|
6930
7043
|
|
|
@@ -6934,8 +7047,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
6934
7047
|
### Variable: sha1
|
|
6935
7048
|
|
|
6936
7049
|
```ts
|
|
6937
|
-
sha1 = (msg: number[] | string, enc?: "hex"): number[]
|
|
6938
|
-
return new SHA1().update(msg, enc).digest(
|
|
7050
|
+
sha1 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
|
|
7051
|
+
return new SHA1().update(msg, enc).digest();
|
|
6939
7052
|
}
|
|
6940
7053
|
```
|
|
6941
7054
|
|
|
@@ -6945,8 +7058,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
6945
7058
|
### Variable: sha256
|
|
6946
7059
|
|
|
6947
7060
|
```ts
|
|
6948
|
-
sha256 = (msg: number[] | string, enc?: "hex"): number[]
|
|
6949
|
-
return new SHA256().update(msg, enc).digest(
|
|
7061
|
+
sha256 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
|
|
7062
|
+
return new SHA256().update(msg, enc).digest();
|
|
6950
7063
|
}
|
|
6951
7064
|
```
|
|
6952
7065
|
|
|
@@ -6956,8 +7069,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
6956
7069
|
### Variable: sha512
|
|
6957
7070
|
|
|
6958
7071
|
```ts
|
|
6959
|
-
sha512 = (msg: number[] | string, enc?: "hex"): number[]
|
|
6960
|
-
return new SHA512().update(msg, enc).digest(
|
|
7072
|
+
sha512 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
|
|
7073
|
+
return new SHA512().update(msg, enc).digest();
|
|
6961
7074
|
}
|
|
6962
7075
|
```
|
|
6963
7076
|
|
|
@@ -6967,9 +7080,9 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
6967
7080
|
### Variable: hash256
|
|
6968
7081
|
|
|
6969
7082
|
```ts
|
|
6970
|
-
hash256 = (msg: number[] | string, enc?: "hex"): number[]
|
|
7083
|
+
hash256 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
|
|
6971
7084
|
const first = new SHA256().update(msg, enc).digest();
|
|
6972
|
-
return new SHA256().update(first).digest(
|
|
7085
|
+
return new SHA256().update(first).digest();
|
|
6973
7086
|
}
|
|
6974
7087
|
```
|
|
6975
7088
|
|
|
@@ -6979,9 +7092,9 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
6979
7092
|
### Variable: hash160
|
|
6980
7093
|
|
|
6981
7094
|
```ts
|
|
6982
|
-
hash160 = (msg: number[] | string, enc?: "hex"): number[]
|
|
7095
|
+
hash160 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
|
|
6983
7096
|
const first = new SHA256().update(msg, enc).digest();
|
|
6984
|
-
return new RIPEMD160().update(first).digest(
|
|
7097
|
+
return new RIPEMD160().update(first).digest();
|
|
6985
7098
|
}
|
|
6986
7099
|
```
|
|
6987
7100
|
|
|
@@ -6991,8 +7104,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
6991
7104
|
### Variable: sha256hmac
|
|
6992
7105
|
|
|
6993
7106
|
```ts
|
|
6994
|
-
sha256hmac = (key: number[] | string, msg: number[] | string, enc?: "hex"): number[]
|
|
6995
|
-
return new SHA256HMAC(key).update(msg, enc).digest(
|
|
7107
|
+
sha256hmac = (key: number[] | string, msg: number[] | string, enc?: "hex"): number[] => {
|
|
7108
|
+
return new SHA256HMAC(key).update(msg, enc).digest();
|
|
6996
7109
|
}
|
|
6997
7110
|
```
|
|
6998
7111
|
|
|
@@ -7002,8 +7115,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
7002
7115
|
### Variable: sha512hmac
|
|
7003
7116
|
|
|
7004
7117
|
```ts
|
|
7005
|
-
sha512hmac = (key: number[] | string, msg: number[] | string, enc?: "hex"): number[]
|
|
7006
|
-
return new SHA512HMAC(key).update(msg, enc).digest(
|
|
7118
|
+
sha512hmac = (key: number[] | string, msg: number[] | string, enc?: "hex"): number[] => {
|
|
7119
|
+
return new SHA512HMAC(key).update(msg, enc).digest();
|
|
7007
7120
|
}
|
|
7008
7121
|
```
|
|
7009
7122
|
|
|
@@ -7014,7 +7127,7 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
|
|
|
7014
7127
|
|
|
7015
7128
|
```ts
|
|
7016
7129
|
zero2 = (word: string): string => {
|
|
7017
|
-
if (word.length === 1) {
|
|
7130
|
+
if (word.length % 2 === 1) {
|
|
7018
7131
|
return "0" + word;
|
|
7019
7132
|
}
|
|
7020
7133
|
else {
|