@bsv/sdk 1.1.13 → 1.1.14
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/Point.js +28 -8
- package/dist/cjs/src/primitives/Point.js.map +1 -1
- package/dist/cjs/src/primitives/Polynomial.js +81 -0
- package/dist/cjs/src/primitives/Polynomial.js.map +1 -0
- package/dist/cjs/src/primitives/PrivateKey.js +165 -0
- package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
- package/dist/cjs/src/primitives/PublicKey.js +16 -2
- package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
- package/dist/cjs/src/primitives/index.js +5 -1
- package/dist/cjs/src/primitives/index.js.map +1 -1
- package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
- package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
- package/dist/cjs/src/transaction/broadcasters/ARC.js +4 -4
- package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
- package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +3 -3
- package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
- package/dist/cjs/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
- package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js +2 -2
- package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
- package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js +2 -2
- package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/FetchHttpClient.js +2 -2
- package/dist/cjs/src/transaction/http/FetchHttpClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/NodejsHttpClient.js +2 -2
- package/dist/cjs/src/transaction/http/NodejsHttpClient.js.map +1 -1
- package/dist/cjs/src/transaction/http/index.js.map +1 -1
- package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
- package/dist/esm/src/primitives/Point.js +28 -8
- package/dist/esm/src/primitives/Point.js.map +1 -1
- package/dist/esm/src/primitives/Polynomial.js +77 -0
- package/dist/esm/src/primitives/Polynomial.js.map +1 -0
- package/dist/esm/src/primitives/PrivateKey.js +143 -0
- package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
- package/dist/esm/src/primitives/PublicKey.js +16 -2
- package/dist/esm/src/primitives/PublicKey.js.map +1 -1
- package/dist/esm/src/primitives/index.js +2 -1
- package/dist/esm/src/primitives/index.js.map +1 -1
- package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
- package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
- package/dist/esm/src/transaction/broadcasters/ARC.js +7 -7
- package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
- package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
- package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +4 -4
- package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
- package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js +1 -1
- package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
- package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js +3 -3
- package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
- package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
- package/dist/esm/src/transaction/http/DefaultHttpClient.js +2 -2
- package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
- package/dist/esm/src/transaction/http/FetchHttpClient.js +2 -2
- package/dist/esm/src/transaction/http/FetchHttpClient.js.map +1 -1
- package/dist/esm/src/transaction/http/NodejsHttpClient.js +2 -2
- package/dist/esm/src/transaction/http/NodejsHttpClient.js.map +1 -1
- package/dist/esm/src/transaction/http/index.js.map +1 -1
- package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
- package/dist/types/src/primitives/Point.d.ts +19 -1
- package/dist/types/src/primitives/Point.d.ts.map +1 -1
- package/dist/types/src/primitives/Polynomial.d.ts +32 -0
- package/dist/types/src/primitives/Polynomial.d.ts.map +1 -0
- package/dist/types/src/primitives/PrivateKey.d.ts +72 -0
- package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
- package/dist/types/src/primitives/PublicKey.d.ts +12 -1
- package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
- package/dist/types/src/primitives/index.d.ts +2 -1
- package/dist/types/src/primitives/index.d.ts.map +1 -1
- package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
- package/dist/types/src/transaction/broadcasters/ARC.d.ts +1 -1
- package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
- package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts +1 -1
- package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
- package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts +1 -1
- package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts.map +1 -1
- package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts +1 -1
- package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts.map +1 -1
- package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts +2 -2
- package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts.map +1 -1
- package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -1
- package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/FetchHttpClient.d.ts +7 -9
- package/dist/types/src/transaction/http/FetchHttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/HttpClient.d.ts +5 -5
- package/dist/types/src/transaction/http/HttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/NodejsHttpClient.d.ts +5 -6
- package/dist/types/src/transaction/http/NodejsHttpClient.d.ts.map +1 -1
- package/dist/types/src/transaction/http/index.d.ts.map +1 -1
- package/dist/types/tsconfig.types.tsbuildinfo +1 -1
- package/docs/primitives.md +231 -16
- package/docs/transaction.md +38 -37
- package/package.json +1 -1
- package/src/compat/__tests/BSM.test.ts +37 -37
- package/src/compat/__tests/ECIES.test.ts +71 -71
- package/src/compat/__tests/HD.test.ts +362 -362
- package/src/compat/__tests/Mnemonic.test.ts +147 -148
- package/src/compat/__tests/Mnemonic.vectors.ts +170 -170
- package/src/messages/__tests/EncryptedMessage.test.ts +16 -16
- package/src/primitives/Point.ts +29 -10
- package/src/primitives/Polynomial.ts +89 -0
- package/src/primitives/PrivateKey.ts +147 -1
- package/src/primitives/PublicKey.ts +17 -2
- package/src/primitives/__tests/AESGCM.test.ts +20 -20
- package/src/primitives/__tests/Hash.test.ts +2 -2
- package/src/primitives/__tests/PBKDF2.vectors.ts +93 -93
- package/src/primitives/__tests/PrivateKey.split.test.ts +70 -0
- package/src/primitives/__tests/PublicKey.test.ts +14 -1
- package/src/primitives/__tests/bug-31.test.ts +24 -26
- package/src/primitives/__tests/utils.test.ts +13 -13
- package/src/primitives/index.ts +2 -1
- package/src/script/__tests/Script.test.ts +1 -1
- package/src/script/__tests/SpendComplex.test.ts +6 -6
- package/src/script/__tests/script.invalid.vectors.ts +1464 -1464
- package/src/script/__tests/script.valid.vectors.ts +1962 -1962
- package/src/script/__tests/spend.valid.vectors.ts +1369 -1369
- package/src/script/templates/P2PKH.ts +6 -6
- package/src/script/templates/RPuzzle.ts +1 -1
- package/src/transaction/__tests/Transaction.test.ts +5 -5
- package/src/transaction/__tests/bump.invalid.vectors.ts +1 -1
- package/src/transaction/__tests/bump.valid.vectors.ts +3 -3
- package/src/transaction/broadcasters/ARC.ts +20 -21
- package/src/transaction/broadcasters/DefaultBroadcaster.ts +3 -3
- package/src/transaction/broadcasters/WhatsOnChainBroadcaster.ts +10 -10
- package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +7 -10
- package/src/transaction/chaintrackers/DefaultChainTracker.ts +3 -3
- package/src/transaction/chaintrackers/WhatsOnChain.ts +10 -12
- package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +13 -17
- package/src/transaction/fee-models/SatoshisPerKilobyte.ts +2 -2
- package/src/transaction/http/DefaultHttpClient.ts +13 -13
- package/src/transaction/http/FetchHttpClient.ts +14 -16
- package/src/transaction/http/HttpClient.ts +22 -23
- package/src/transaction/http/NodejsHttpClient.ts +23 -25
- package/src/transaction/http/index.ts +6 -6
package/docs/primitives.md
CHANGED
|
@@ -6,20 +6,17 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
6
6
|
|
|
7
7
|
## Classes
|
|
8
8
|
|
|
9
|
-
| | |
|
|
10
|
-
| --- | --- |
|
|
11
|
-
| [BasePoint](#class-basepoint) | [
|
|
12
|
-
| [BigNumber](#class-bignumber) | [
|
|
13
|
-
| [Curve](#class-curve) | [
|
|
14
|
-
| [DRBG](#class-drbg) | [
|
|
15
|
-
| [JacobianPoint](#class-jacobianpoint) | [
|
|
16
|
-
| [K256](#class-k256) | [
|
|
17
|
-
| [
|
|
18
|
-
| [
|
|
19
|
-
| [
|
|
20
|
-
| [PrivateKey](#class-privatekey) | [SymmetricKey](#class-symmetrickey) |
|
|
21
|
-
| [PublicKey](#class-publickey) | [TransactionSignature](#class-transactionsignature) |
|
|
22
|
-
| [RIPEMD160](#class-ripemd160) | [Writer](#class-writer) |
|
|
9
|
+
| | | |
|
|
10
|
+
| --- | --- | --- |
|
|
11
|
+
| [BasePoint](#class-basepoint) | [Point](#class-point) | [SHA1HMAC](#class-sha1hmac) |
|
|
12
|
+
| [BigNumber](#class-bignumber) | [PointInFiniteField](#class-pointinfinitefield) | [SHA256](#class-sha256) |
|
|
13
|
+
| [Curve](#class-curve) | [Polynomial](#class-polynomial) | [SHA256HMAC](#class-sha256hmac) |
|
|
14
|
+
| [DRBG](#class-drbg) | [PrivateKey](#class-privatekey) | [SHA512](#class-sha512) |
|
|
15
|
+
| [JacobianPoint](#class-jacobianpoint) | [PublicKey](#class-publickey) | [SHA512HMAC](#class-sha512hmac) |
|
|
16
|
+
| [K256](#class-k256) | [RIPEMD160](#class-ripemd160) | [Signature](#class-signature) |
|
|
17
|
+
| [KeyShares](#class-keyshares) | [Reader](#class-reader) | [SymmetricKey](#class-symmetrickey) |
|
|
18
|
+
| [Mersenne](#class-mersenne) | [ReductionContext](#class-reductioncontext) | [TransactionSignature](#class-transactionsignature) |
|
|
19
|
+
| [MontgomoryMethod](#class-montgomorymethod) | [SHA1](#class-sha1) | [Writer](#class-writer) |
|
|
23
20
|
|
|
24
21
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
25
22
|
|
|
@@ -5349,6 +5346,7 @@ export default class Point extends BasePoint {
|
|
|
5349
5346
|
x: BigNumber | null;
|
|
5350
5347
|
y: BigNumber | null;
|
|
5351
5348
|
inf: boolean;
|
|
5349
|
+
static fromDER(bytes: number[]): Point
|
|
5352
5350
|
static fromString(str: string): Point
|
|
5353
5351
|
static fromX(x: BigNumber | number | number[] | string, odd: boolean): Point
|
|
5354
5352
|
static fromJSON(obj: string | any[], isRed: boolean): Point
|
|
@@ -5562,6 +5560,38 @@ const p2 = new Point(5, 20);
|
|
|
5562
5560
|
const areEqual = p1.eq(p2); // returns true
|
|
5563
5561
|
```
|
|
5564
5562
|
|
|
5563
|
+
#### Method fromDER
|
|
5564
|
+
|
|
5565
|
+
Creates a point object from a given Array. These numbers can represent coordinates in hex format, or points
|
|
5566
|
+
in multiple established formats.
|
|
5567
|
+
The function verifies the integrity of the provided data and throws errors if inconsistencies are found.
|
|
5568
|
+
|
|
5569
|
+
```ts
|
|
5570
|
+
static fromDER(bytes: number[]): Point
|
|
5571
|
+
```
|
|
5572
|
+
|
|
5573
|
+
Returns
|
|
5574
|
+
|
|
5575
|
+
Returns a new point representing the given string.
|
|
5576
|
+
|
|
5577
|
+
Argument Details
|
|
5578
|
+
|
|
5579
|
+
+ **bytes**
|
|
5580
|
+
+ The point representation number array.
|
|
5581
|
+
|
|
5582
|
+
Throws
|
|
5583
|
+
|
|
5584
|
+
`Error` If the point number[] value has a wrong length.
|
|
5585
|
+
|
|
5586
|
+
`Error` If the point format is unknown.
|
|
5587
|
+
|
|
5588
|
+
Example
|
|
5589
|
+
|
|
5590
|
+
```ts
|
|
5591
|
+
const derPoint = [ 2, 18, 123, 108, 125, 83, 1, 251, 164, 214, 16, 119, 200, 216, 210, 193, 251, 193, 129, 67, 97, 146, 210, 216, 77, 254, 18, 6, 150, 190, 99, 198, 128 ];
|
|
5592
|
+
const point = Point.fromDER(derPoint);
|
|
5593
|
+
```
|
|
5594
|
+
|
|
5565
5595
|
#### Method fromJSON
|
|
5566
5596
|
|
|
5567
5597
|
Generates a point from a serialized JSON object. The function accounts for different options in the JSON object,
|
|
@@ -6368,6 +6398,85 @@ const isVerified = signature.verify(msg, publicKey);
|
|
|
6368
6398
|
|
|
6369
6399
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
6370
6400
|
|
|
6401
|
+
---
|
|
6402
|
+
### Class: PointInFiniteField
|
|
6403
|
+
|
|
6404
|
+
```ts
|
|
6405
|
+
export class PointInFiniteField {
|
|
6406
|
+
x: BigNumber;
|
|
6407
|
+
y: BigNumber;
|
|
6408
|
+
constructor(x: BigNumber, y: BigNumber)
|
|
6409
|
+
toString(): string
|
|
6410
|
+
static fromString(str: string): PointInFiniteField
|
|
6411
|
+
}
|
|
6412
|
+
```
|
|
6413
|
+
|
|
6414
|
+
<details>
|
|
6415
|
+
|
|
6416
|
+
<summary>Class PointInFiniteField Details</summary>
|
|
6417
|
+
|
|
6418
|
+
#### Method toString
|
|
6419
|
+
|
|
6420
|
+
function toString() { [native code] }
|
|
6421
|
+
|
|
6422
|
+
```ts
|
|
6423
|
+
toString(): string
|
|
6424
|
+
```
|
|
6425
|
+
|
|
6426
|
+
</details>
|
|
6427
|
+
|
|
6428
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
6429
|
+
|
|
6430
|
+
---
|
|
6431
|
+
### Class: Polynomial
|
|
6432
|
+
|
|
6433
|
+
Polynomial class
|
|
6434
|
+
|
|
6435
|
+
This class is used to create a polynomial with a given threshold and a private key.
|
|
6436
|
+
The polynomial is used to create shares of the private key.
|
|
6437
|
+
|
|
6438
|
+
Example
|
|
6439
|
+
|
|
6440
|
+
```ts
|
|
6441
|
+
const key = new PrivateKey()
|
|
6442
|
+
const threshold = 2
|
|
6443
|
+
const polynomial = new Polynomial(key, threshold)
|
|
6444
|
+
```
|
|
6445
|
+
|
|
6446
|
+
```ts
|
|
6447
|
+
export default class Polynomial {
|
|
6448
|
+
readonly points: PointInFiniteField[];
|
|
6449
|
+
readonly threshold: number;
|
|
6450
|
+
constructor(points: PointInFiniteField[], threshold?: number)
|
|
6451
|
+
static fromPrivateKey(key: PrivateKey, threshold: number): Polynomial
|
|
6452
|
+
valueAt(x: BigNumber): BigNumber
|
|
6453
|
+
}
|
|
6454
|
+
```
|
|
6455
|
+
|
|
6456
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
6457
|
+
|
|
6458
|
+
---
|
|
6459
|
+
### Class: KeyShares
|
|
6460
|
+
|
|
6461
|
+
Example
|
|
6462
|
+
|
|
6463
|
+
```ts
|
|
6464
|
+
const key = PrivateKey.fromShares(shares)
|
|
6465
|
+
```
|
|
6466
|
+
|
|
6467
|
+
```ts
|
|
6468
|
+
export class KeyShares {
|
|
6469
|
+
points: PointInFiniteField[];
|
|
6470
|
+
threshold: number;
|
|
6471
|
+
integrity: string;
|
|
6472
|
+
constructor(points: PointInFiniteField[], threshold: number, integrity: string)
|
|
6473
|
+
static fromBackupFormat(shares: string[]): KeyShares
|
|
6474
|
+
toBackupFormat()
|
|
6475
|
+
}
|
|
6476
|
+
```
|
|
6477
|
+
|
|
6478
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
6479
|
+
|
|
6371
6480
|
---
|
|
6372
6481
|
### Class: PrivateKey
|
|
6373
6482
|
|
|
@@ -6394,6 +6503,10 @@ export default class PrivateKey extends BigNumber {
|
|
|
6394
6503
|
toAddress(prefix: number[] | string = [0]): string
|
|
6395
6504
|
deriveSharedSecret(key: PublicKey): Point
|
|
6396
6505
|
deriveChild(publicKey: PublicKey, invoiceNumber: string): PrivateKey
|
|
6506
|
+
toKeyShares(threshold: number, totalShares: number): KeyShares
|
|
6507
|
+
toBackupShares(threshold: number, totalShares: number): string[]
|
|
6508
|
+
static fromBackupShares(shares: string[]): PrivateKey
|
|
6509
|
+
static fromKeyShares(keyShares: KeyShares): PrivateKey
|
|
6397
6510
|
}
|
|
6398
6511
|
```
|
|
6399
6512
|
|
|
@@ -6489,6 +6602,43 @@ const publicKey = privateKey.toPublicKey();
|
|
|
6489
6602
|
const sharedSecret = privateKey.deriveSharedSecret(publicKey);
|
|
6490
6603
|
```
|
|
6491
6604
|
|
|
6605
|
+
#### Method fromBackupShares
|
|
6606
|
+
|
|
6607
|
+
```ts
|
|
6608
|
+
static fromBackupShares(shares: string[]): PrivateKey
|
|
6609
|
+
```
|
|
6610
|
+
|
|
6611
|
+
Returns
|
|
6612
|
+
|
|
6613
|
+
PrivateKey
|
|
6614
|
+
|
|
6615
|
+
#### Method fromKeyShares
|
|
6616
|
+
|
|
6617
|
+
Combines shares to reconstruct the private key.
|
|
6618
|
+
|
|
6619
|
+
```ts
|
|
6620
|
+
static fromKeyShares(keyShares: KeyShares): PrivateKey
|
|
6621
|
+
```
|
|
6622
|
+
|
|
6623
|
+
Returns
|
|
6624
|
+
|
|
6625
|
+
The reconstructed private key.
|
|
6626
|
+
|
|
6627
|
+
Argument Details
|
|
6628
|
+
|
|
6629
|
+
+ **shares**
|
|
6630
|
+
+ An array of points (shares) to be used to reconstruct the private key.
|
|
6631
|
+
+ **threshold**
|
|
6632
|
+
+ The minimum number of shares required to reconstruct the private key.
|
|
6633
|
+
|
|
6634
|
+
Example
|
|
6635
|
+
|
|
6636
|
+
```ts
|
|
6637
|
+
const share1 = '2NWeap6SDBTL5jVnvk9yUxyfLqNrDs2Bw85KNDfLJwRT.4yLtSm327NApsbuP7QXVW3CWDuBRgmS6rRiFkAkTukic'
|
|
6638
|
+
const share2 = '7NbgGA8iAsxg2s6mBLkLFtGKQrnc4aCbooHJJV31cWs4.GUgXtudthawE3Eevc1waT3Atr1Ft7j1XxdUguVo3B7x3'
|
|
6639
|
+
const reconstructedKey = PrivateKey.fromKeyShares({ shares: [share1, share2], threshold: 2, integrity: '23409547' })
|
|
6640
|
+
```
|
|
6641
|
+
|
|
6492
6642
|
#### Method fromRandom
|
|
6493
6643
|
|
|
6494
6644
|
Generates a private key randomly.
|
|
@@ -6620,6 +6770,47 @@ const testnetAddress = privkey.toAddress([0x6f])
|
|
|
6620
6770
|
const testnetAddress = privkey.toAddress('testnet')
|
|
6621
6771
|
```
|
|
6622
6772
|
|
|
6773
|
+
#### Method toBackupShares
|
|
6774
|
+
|
|
6775
|
+
```ts
|
|
6776
|
+
toBackupShares(threshold: number, totalShares: number): string[]
|
|
6777
|
+
```
|
|
6778
|
+
|
|
6779
|
+
Argument Details
|
|
6780
|
+
|
|
6781
|
+
+ **threshold**
|
|
6782
|
+
+ The number of shares which will be required to reconstruct the private key.
|
|
6783
|
+
+ **totalShares**
|
|
6784
|
+
+ The number of shares to generate for distribution.
|
|
6785
|
+
|
|
6786
|
+
#### Method toKeyShares
|
|
6787
|
+
|
|
6788
|
+
Splits the private key into shares using Shamir's Secret Sharing Scheme.
|
|
6789
|
+
|
|
6790
|
+
```ts
|
|
6791
|
+
toKeyShares(threshold: number, totalShares: number): KeyShares
|
|
6792
|
+
```
|
|
6793
|
+
|
|
6794
|
+
Returns
|
|
6795
|
+
|
|
6796
|
+
An array of shares.
|
|
6797
|
+
|
|
6798
|
+
Argument Details
|
|
6799
|
+
|
|
6800
|
+
+ **threshold**
|
|
6801
|
+
+ The minimum number of shares required to reconstruct the private key.
|
|
6802
|
+
+ **totalShares**
|
|
6803
|
+
+ The total number of shares to generate.
|
|
6804
|
+
+ **prime**
|
|
6805
|
+
+ The prime number to be used in Shamir's Secret Sharing Scheme.
|
|
6806
|
+
|
|
6807
|
+
Example
|
|
6808
|
+
|
|
6809
|
+
```ts
|
|
6810
|
+
const key = PrivateKey.fromRandom()
|
|
6811
|
+
const shares = key.toKeyShares(2, 5)
|
|
6812
|
+
```
|
|
6813
|
+
|
|
6623
6814
|
#### Method toPublicKey
|
|
6624
6815
|
|
|
6625
6816
|
Converts the private key to its corresponding public key.
|
|
@@ -6716,10 +6907,11 @@ The class comes with static methods to generate PublicKey instances from private
|
|
|
6716
6907
|
export default class PublicKey extends Point {
|
|
6717
6908
|
static fromPrivateKey(key: PrivateKey): PublicKey
|
|
6718
6909
|
static fromString(str: string): PublicKey
|
|
6910
|
+
static fromDER(bytes: number[]): PublicKey
|
|
6719
6911
|
constructor(x: Point | BigNumber | number | number[] | string | null, y: BigNumber | number | number[] | string | null = null, isRed: boolean = true)
|
|
6720
6912
|
deriveSharedSecret(priv: PrivateKey): Point
|
|
6721
6913
|
verify(msg: number[] | string, sig: Signature, enc?: "hex" | "utf8"): boolean
|
|
6722
|
-
toDER(): string
|
|
6914
|
+
toDER(enc?: "hex" | undefined): string
|
|
6723
6915
|
toHash(enc?: "hex"): number[] | string
|
|
6724
6916
|
toAddress(prefix: number[] | string = [0]): string
|
|
6725
6917
|
deriveChild(privateKey: PrivateKey, invoiceNumber: string): PublicKey
|
|
@@ -6801,6 +6993,29 @@ const myPrivKey = new PrivateKey(...)
|
|
|
6801
6993
|
const sharedSecret = myPubKey.deriveSharedSecret(myPrivKey)
|
|
6802
6994
|
```
|
|
6803
6995
|
|
|
6996
|
+
#### Method fromDER
|
|
6997
|
+
|
|
6998
|
+
Static factory method to create a PublicKey instance from a number array.
|
|
6999
|
+
|
|
7000
|
+
```ts
|
|
7001
|
+
static fromDER(bytes: number[]): PublicKey
|
|
7002
|
+
```
|
|
7003
|
+
|
|
7004
|
+
Returns
|
|
7005
|
+
|
|
7006
|
+
Returns the PublicKey created from the number array.
|
|
7007
|
+
|
|
7008
|
+
Argument Details
|
|
7009
|
+
|
|
7010
|
+
+ **bytes**
|
|
7011
|
+
+ A number array representing a public key.
|
|
7012
|
+
|
|
7013
|
+
Example
|
|
7014
|
+
|
|
7015
|
+
```ts
|
|
7016
|
+
const myPubKey = PublicKey.fromString("03....")
|
|
7017
|
+
```
|
|
7018
|
+
|
|
6804
7019
|
#### Method fromMsgHashAndCompactSignature
|
|
6805
7020
|
|
|
6806
7021
|
Takes an array of numbers or a string and returns a new PublicKey instance.
|
|
@@ -6913,7 +7128,7 @@ const testnetAddress = pubkey.toAddress('testnet')
|
|
|
6913
7128
|
Encode the public key to DER (Distinguished Encoding Rules) format.
|
|
6914
7129
|
|
|
6915
7130
|
```ts
|
|
6916
|
-
toDER(): string
|
|
7131
|
+
toDER(enc?: "hex" | undefined): string
|
|
6917
7132
|
```
|
|
6918
7133
|
|
|
6919
7134
|
Returns
|
package/docs/transaction.md
CHANGED
|
@@ -6,14 +6,14 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
6
6
|
|
|
7
7
|
| | |
|
|
8
8
|
| --- | --- |
|
|
9
|
-
| [ArcConfig](#interface-arcconfig) | [
|
|
10
|
-
| [BroadcastFailure](#interface-broadcastfailure) | [
|
|
11
|
-
| [BroadcastResponse](#interface-broadcastresponse) | [
|
|
12
|
-
| [Broadcaster](#interface-broadcaster) | [
|
|
13
|
-
| [ChainTracker](#interface-chaintracker) | [
|
|
14
|
-
| [FeeModel](#interface-feemodel) | [
|
|
15
|
-
| [Fetch](#interface-fetch) | [TransactionOutput](#interface-transactionoutput) |
|
|
9
|
+
| [ArcConfig](#interface-arcconfig) | [HttpClientRequestOptions](#interface-httpclientrequestoptions) |
|
|
10
|
+
| [BroadcastFailure](#interface-broadcastfailure) | [HttpsNodejs](#interface-httpsnodejs) |
|
|
11
|
+
| [BroadcastResponse](#interface-broadcastresponse) | [MerklePathLeaf](#interface-merklepathleaf) |
|
|
12
|
+
| [Broadcaster](#interface-broadcaster) | [NodejsHttpClientRequest](#interface-nodejshttpclientrequest) |
|
|
13
|
+
| [ChainTracker](#interface-chaintracker) | [TransactionInput](#interface-transactioninput) |
|
|
14
|
+
| [FeeModel](#interface-feemodel) | [TransactionOutput](#interface-transactionoutput) |
|
|
16
15
|
| [FetchOptions](#interface-fetchoptions) | [WhatsOnChainConfig](#interface-whatsonchainconfig) |
|
|
16
|
+
| [HttpClient](#interface-httpclient) | |
|
|
17
17
|
|
|
18
18
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
19
19
|
|
|
@@ -195,7 +195,7 @@ An interface for HTTP client used to make HTTP requests.
|
|
|
195
195
|
|
|
196
196
|
```ts
|
|
197
197
|
export interface HttpClient {
|
|
198
|
-
request<T = any, D = any>(url: string, options: HttpClientRequestOptions<D>)
|
|
198
|
+
request: <T = any, D = any>(url: string, options: HttpClientRequestOptions<D>) => Promise<HttpClientResponse<T>>;
|
|
199
199
|
}
|
|
200
200
|
```
|
|
201
201
|
|
|
@@ -203,21 +203,14 @@ export interface HttpClient {
|
|
|
203
203
|
|
|
204
204
|
<summary>Interface HttpClient Details</summary>
|
|
205
205
|
|
|
206
|
-
####
|
|
206
|
+
#### Property request
|
|
207
207
|
|
|
208
208
|
Makes a request to the server.
|
|
209
209
|
|
|
210
210
|
```ts
|
|
211
|
-
request<T = any, D = any>(url: string, options: HttpClientRequestOptions<D>)
|
|
211
|
+
request: <T = any, D = any>(url: string, options: HttpClientRequestOptions<D>) => Promise<HttpClientResponse<T>>
|
|
212
212
|
```
|
|
213
213
|
|
|
214
|
-
Argument Details
|
|
215
|
-
|
|
216
|
-
+ **url**
|
|
217
|
-
+ The URL to make the request to.
|
|
218
|
-
+ **options**
|
|
219
|
-
+ The request configuration.
|
|
220
|
-
|
|
221
214
|
</details>
|
|
222
215
|
|
|
223
216
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
@@ -274,7 +267,7 @@ Node.js Https module interface limited to options needed by ts-sdk
|
|
|
274
267
|
|
|
275
268
|
```ts
|
|
276
269
|
export interface HttpsNodejs {
|
|
277
|
-
request(url: string, options: HttpClientRequestOptions, callback: (res: any) => void)
|
|
270
|
+
request: (url: string, options: HttpClientRequestOptions, callback: (res: any) => void) => NodejsHttpClientRequest;
|
|
278
271
|
}
|
|
279
272
|
```
|
|
280
273
|
|
|
@@ -287,23 +280,9 @@ Nodejs result of the Node.js https.request call limited to options needed by ts-
|
|
|
287
280
|
|
|
288
281
|
```ts
|
|
289
282
|
export interface NodejsHttpClientRequest {
|
|
290
|
-
write(chunk: string)
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
end(): void;
|
|
294
|
-
}
|
|
295
|
-
```
|
|
296
|
-
|
|
297
|
-
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
298
|
-
|
|
299
|
-
---
|
|
300
|
-
### Interface: Fetch
|
|
301
|
-
|
|
302
|
-
fetch function interface limited to options needed by ts-sdk
|
|
303
|
-
|
|
304
|
-
```ts
|
|
305
|
-
export interface Fetch {
|
|
306
|
-
(url: string, options: FetchOptions): Promise<Response>;
|
|
283
|
+
write: (chunk: string) => void;
|
|
284
|
+
on: (event: string, callback: (data: any) => void) => void;
|
|
285
|
+
end: (() => void) & (() => void);
|
|
307
286
|
}
|
|
308
287
|
```
|
|
309
288
|
|
|
@@ -723,7 +702,7 @@ Adapter for Node.js Https module to be used as HttpClient
|
|
|
723
702
|
|
|
724
703
|
```ts
|
|
725
704
|
export class NodejsHttpClient implements HttpClient {
|
|
726
|
-
constructor(private https: HttpsNodejs)
|
|
705
|
+
constructor(private readonly https: HttpsNodejs)
|
|
727
706
|
async request(url: string, requestOptions: HttpClientRequestOptions): Promise<HttpClientResponse>
|
|
728
707
|
}
|
|
729
708
|
```
|
|
@@ -737,7 +716,7 @@ Adapter for Node.js Https module to be used as HttpClient
|
|
|
737
716
|
|
|
738
717
|
```ts
|
|
739
718
|
export class FetchHttpClient implements HttpClient {
|
|
740
|
-
constructor(private fetch: Fetch)
|
|
719
|
+
constructor(private readonly fetch: Fetch)
|
|
741
720
|
async request<D>(url: string, options: HttpClientRequestOptions): Promise<HttpClientResponse<D>>
|
|
742
721
|
}
|
|
743
722
|
```
|
|
@@ -1397,6 +1376,15 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
|
|
|
1397
1376
|
---
|
|
1398
1377
|
## Types
|
|
1399
1378
|
|
|
1379
|
+
| |
|
|
1380
|
+
| --- |
|
|
1381
|
+
| [Fetch](#type-fetch) |
|
|
1382
|
+
| [HttpClientResponse](#type-httpclientresponse) |
|
|
1383
|
+
|
|
1384
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1385
|
+
|
|
1386
|
+
---
|
|
1387
|
+
|
|
1400
1388
|
### Type: HttpClientResponse
|
|
1401
1389
|
|
|
1402
1390
|
An interface for the response returned by the request method.
|
|
@@ -1417,6 +1405,19 @@ export type HttpClientResponse<T = any> = {
|
|
|
1417
1405
|
|
|
1418
1406
|
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1419
1407
|
|
|
1408
|
+
---
|
|
1409
|
+
### Type: Fetch
|
|
1410
|
+
|
|
1411
|
+
fetch function interface limited to options needed by ts-sdk
|
|
1412
|
+
|
|
1413
|
+
Makes a request to the server.
|
|
1414
|
+
|
|
1415
|
+
```ts
|
|
1416
|
+
export type Fetch = (url: string, options: FetchOptions) => Promise<Response>
|
|
1417
|
+
```
|
|
1418
|
+
|
|
1419
|
+
Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](#functions), [Types](#types), [Variables](#variables)
|
|
1420
|
+
|
|
1420
1421
|
---
|
|
1421
1422
|
## Variables
|
|
1422
1423
|
|
package/package.json
CHANGED
|
@@ -6,44 +6,44 @@ import Signature from '../../../dist/cjs/src/primitives/Signature'
|
|
|
6
6
|
import BigNumber from '../../../dist/cjs/src/primitives/BigNumber'
|
|
7
7
|
|
|
8
8
|
describe('BSM', () => {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
})
|
|
9
|
+
describe('magicHash', () => {
|
|
10
|
+
it('should return a hash', () => {
|
|
11
|
+
const buf = toArray('001122', 'hex')
|
|
12
|
+
const hashBuf = magicHash(buf)
|
|
13
|
+
expect(hashBuf.length).toEqual(32)
|
|
15
14
|
})
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
15
|
+
})
|
|
16
|
+
describe('sign', () => {
|
|
17
|
+
const messageBuf = toArray('this is my message', 'utf8')
|
|
18
|
+
const privateKey = new PrivateKey(42)
|
|
19
|
+
it('should return a signature', () => {
|
|
20
|
+
const sig = sign(messageBuf, privateKey).toDER()
|
|
21
|
+
expect(sig.length).toEqual(70)
|
|
23
22
|
})
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
23
|
+
})
|
|
24
|
+
describe('verify', () => {
|
|
25
|
+
const messageBuf = toArray('this is my message', 'utf8')
|
|
26
|
+
const privateKey = new PrivateKey(42)
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
})
|
|
32
|
-
it('Should verify a signed message in base64', () => {
|
|
33
|
-
const message = toArray("Texas", 'utf8')
|
|
34
|
-
const signature = Signature.fromCompact('IAV89EkfHSzAIA8cEWbbKHUYzJqcShkpWaXGJ5+mf4+YIlf3XNlr0bj9X60sNe1A7+x9qyk+zmXropMDY4370n8=', 'base64')
|
|
35
|
-
const publicKey = PublicKey.fromString('03d4d1a6c5d8c03b0e671bc1891b69afaecb40c0686188fe9019f93581b43e8334')
|
|
36
|
-
expect(verify(message, signature, publicKey)).toBe(true)
|
|
37
|
-
})
|
|
38
|
-
it('Should be able to calculate the recovery number for a signature and public key', () => {
|
|
39
|
-
const message = toArray("Texas", 'utf8')
|
|
40
|
-
const signature = Signature.fromCompact('IAV89EkfHSzAIA8cEWbbKHUYzJqcShkpWaXGJ5+mf4+YIlf3XNlr0bj9X60sNe1A7+x9qyk+zmXropMDY4370n8=', 'base64')
|
|
41
|
-
const publicKey = PublicKey.fromString('03d4d1a6c5d8c03b0e671bc1891b69afaecb40c0686188fe9019f93581b43e8334')
|
|
42
|
-
const msgHash = new BigNumber(magicHash(message))
|
|
43
|
-
const recovery = signature.CalculateRecoveryFactor(publicKey, msgHash)
|
|
44
|
-
expect(recovery).toBe(1)
|
|
45
|
-
const recoveredPubkey = signature.RecoverPublicKey(recovery, msgHash) as PublicKey
|
|
46
|
-
expect(recoveredPubkey.toDER()).toEqual(publicKey.toDER())
|
|
47
|
-
})
|
|
28
|
+
it('should verify a signed message', () => {
|
|
29
|
+
const sig = sign(messageBuf, privateKey)
|
|
30
|
+
expect(verify(messageBuf, sig, privateKey.toPublicKey())).toEqual(true)
|
|
48
31
|
})
|
|
49
|
-
|
|
32
|
+
it('Should verify a signed message in base64', () => {
|
|
33
|
+
const message = toArray('Texas', 'utf8')
|
|
34
|
+
const signature = Signature.fromCompact('IAV89EkfHSzAIA8cEWbbKHUYzJqcShkpWaXGJ5+mf4+YIlf3XNlr0bj9X60sNe1A7+x9qyk+zmXropMDY4370n8=', 'base64')
|
|
35
|
+
const publicKey = PublicKey.fromString('03d4d1a6c5d8c03b0e671bc1891b69afaecb40c0686188fe9019f93581b43e8334')
|
|
36
|
+
expect(verify(message, signature, publicKey)).toBe(true)
|
|
37
|
+
})
|
|
38
|
+
it('Should be able to calculate the recovery number for a signature and public key', () => {
|
|
39
|
+
const message = toArray('Texas', 'utf8')
|
|
40
|
+
const signature = Signature.fromCompact('IAV89EkfHSzAIA8cEWbbKHUYzJqcShkpWaXGJ5+mf4+YIlf3XNlr0bj9X60sNe1A7+x9qyk+zmXropMDY4370n8=', 'base64')
|
|
41
|
+
const publicKey = PublicKey.fromString('03d4d1a6c5d8c03b0e671bc1891b69afaecb40c0686188fe9019f93581b43e8334')
|
|
42
|
+
const msgHash = new BigNumber(magicHash(message))
|
|
43
|
+
const recovery = signature.CalculateRecoveryFactor(publicKey, msgHash)
|
|
44
|
+
expect(recovery).toBe(1)
|
|
45
|
+
const recoveredPubkey = signature.RecoverPublicKey(recovery, msgHash) as PublicKey
|
|
46
|
+
expect(recoveredPubkey.toDER()).toEqual(publicKey.toDER())
|
|
47
|
+
})
|
|
48
|
+
})
|
|
49
|
+
})
|