@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.
Files changed (136) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/primitives/Point.js +28 -8
  3. package/dist/cjs/src/primitives/Point.js.map +1 -1
  4. package/dist/cjs/src/primitives/Polynomial.js +81 -0
  5. package/dist/cjs/src/primitives/Polynomial.js.map +1 -0
  6. package/dist/cjs/src/primitives/PrivateKey.js +165 -0
  7. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
  8. package/dist/cjs/src/primitives/PublicKey.js +16 -2
  9. package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
  10. package/dist/cjs/src/primitives/index.js +5 -1
  11. package/dist/cjs/src/primitives/index.js.map +1 -1
  12. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
  13. package/dist/cjs/src/script/templates/RPuzzle.js.map +1 -1
  14. package/dist/cjs/src/transaction/broadcasters/ARC.js +4 -4
  15. package/dist/cjs/src/transaction/broadcasters/ARC.js.map +1 -1
  16. package/dist/cjs/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  17. package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +3 -3
  18. package/dist/cjs/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  19. package/dist/cjs/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
  20. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js +2 -2
  21. package/dist/cjs/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  22. package/dist/cjs/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  23. package/dist/cjs/src/transaction/http/DefaultHttpClient.js +2 -2
  24. package/dist/cjs/src/transaction/http/DefaultHttpClient.js.map +1 -1
  25. package/dist/cjs/src/transaction/http/FetchHttpClient.js +2 -2
  26. package/dist/cjs/src/transaction/http/FetchHttpClient.js.map +1 -1
  27. package/dist/cjs/src/transaction/http/NodejsHttpClient.js +2 -2
  28. package/dist/cjs/src/transaction/http/NodejsHttpClient.js.map +1 -1
  29. package/dist/cjs/src/transaction/http/index.js.map +1 -1
  30. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  31. package/dist/esm/src/primitives/Point.js +28 -8
  32. package/dist/esm/src/primitives/Point.js.map +1 -1
  33. package/dist/esm/src/primitives/Polynomial.js +77 -0
  34. package/dist/esm/src/primitives/Polynomial.js.map +1 -0
  35. package/dist/esm/src/primitives/PrivateKey.js +143 -0
  36. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  37. package/dist/esm/src/primitives/PublicKey.js +16 -2
  38. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  39. package/dist/esm/src/primitives/index.js +2 -1
  40. package/dist/esm/src/primitives/index.js.map +1 -1
  41. package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
  42. package/dist/esm/src/script/templates/RPuzzle.js.map +1 -1
  43. package/dist/esm/src/transaction/broadcasters/ARC.js +7 -7
  44. package/dist/esm/src/transaction/broadcasters/ARC.js.map +1 -1
  45. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js +1 -1
  46. package/dist/esm/src/transaction/broadcasters/DefaultBroadcaster.js.map +1 -1
  47. package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js +4 -4
  48. package/dist/esm/src/transaction/broadcasters/WhatsOnChainBroadcaster.js.map +1 -1
  49. package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js +1 -1
  50. package/dist/esm/src/transaction/chaintrackers/DefaultChainTracker.js.map +1 -1
  51. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js +3 -3
  52. package/dist/esm/src/transaction/chaintrackers/WhatsOnChain.js.map +1 -1
  53. package/dist/esm/src/transaction/fee-models/SatoshisPerKilobyte.js.map +1 -1
  54. package/dist/esm/src/transaction/http/DefaultHttpClient.js +2 -2
  55. package/dist/esm/src/transaction/http/DefaultHttpClient.js.map +1 -1
  56. package/dist/esm/src/transaction/http/FetchHttpClient.js +2 -2
  57. package/dist/esm/src/transaction/http/FetchHttpClient.js.map +1 -1
  58. package/dist/esm/src/transaction/http/NodejsHttpClient.js +2 -2
  59. package/dist/esm/src/transaction/http/NodejsHttpClient.js.map +1 -1
  60. package/dist/esm/src/transaction/http/index.js.map +1 -1
  61. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  62. package/dist/types/src/primitives/Point.d.ts +19 -1
  63. package/dist/types/src/primitives/Point.d.ts.map +1 -1
  64. package/dist/types/src/primitives/Polynomial.d.ts +32 -0
  65. package/dist/types/src/primitives/Polynomial.d.ts.map +1 -0
  66. package/dist/types/src/primitives/PrivateKey.d.ts +72 -0
  67. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
  68. package/dist/types/src/primitives/PublicKey.d.ts +12 -1
  69. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
  70. package/dist/types/src/primitives/index.d.ts +2 -1
  71. package/dist/types/src/primitives/index.d.ts.map +1 -1
  72. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
  73. package/dist/types/src/transaction/broadcasters/ARC.d.ts +1 -1
  74. package/dist/types/src/transaction/broadcasters/ARC.d.ts.map +1 -1
  75. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts +1 -1
  76. package/dist/types/src/transaction/broadcasters/DefaultBroadcaster.d.ts.map +1 -1
  77. package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts +1 -1
  78. package/dist/types/src/transaction/broadcasters/WhatsOnChainBroadcaster.d.ts.map +1 -1
  79. package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts +1 -1
  80. package/dist/types/src/transaction/chaintrackers/DefaultChainTracker.d.ts.map +1 -1
  81. package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts +2 -2
  82. package/dist/types/src/transaction/chaintrackers/WhatsOnChain.d.ts.map +1 -1
  83. package/dist/types/src/transaction/fee-models/SatoshisPerKilobyte.d.ts.map +1 -1
  84. package/dist/types/src/transaction/http/DefaultHttpClient.d.ts.map +1 -1
  85. package/dist/types/src/transaction/http/FetchHttpClient.d.ts +7 -9
  86. package/dist/types/src/transaction/http/FetchHttpClient.d.ts.map +1 -1
  87. package/dist/types/src/transaction/http/HttpClient.d.ts +5 -5
  88. package/dist/types/src/transaction/http/HttpClient.d.ts.map +1 -1
  89. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts +5 -6
  90. package/dist/types/src/transaction/http/NodejsHttpClient.d.ts.map +1 -1
  91. package/dist/types/src/transaction/http/index.d.ts.map +1 -1
  92. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  93. package/docs/primitives.md +231 -16
  94. package/docs/transaction.md +38 -37
  95. package/package.json +1 -1
  96. package/src/compat/__tests/BSM.test.ts +37 -37
  97. package/src/compat/__tests/ECIES.test.ts +71 -71
  98. package/src/compat/__tests/HD.test.ts +362 -362
  99. package/src/compat/__tests/Mnemonic.test.ts +147 -148
  100. package/src/compat/__tests/Mnemonic.vectors.ts +170 -170
  101. package/src/messages/__tests/EncryptedMessage.test.ts +16 -16
  102. package/src/primitives/Point.ts +29 -10
  103. package/src/primitives/Polynomial.ts +89 -0
  104. package/src/primitives/PrivateKey.ts +147 -1
  105. package/src/primitives/PublicKey.ts +17 -2
  106. package/src/primitives/__tests/AESGCM.test.ts +20 -20
  107. package/src/primitives/__tests/Hash.test.ts +2 -2
  108. package/src/primitives/__tests/PBKDF2.vectors.ts +93 -93
  109. package/src/primitives/__tests/PrivateKey.split.test.ts +70 -0
  110. package/src/primitives/__tests/PublicKey.test.ts +14 -1
  111. package/src/primitives/__tests/bug-31.test.ts +24 -26
  112. package/src/primitives/__tests/utils.test.ts +13 -13
  113. package/src/primitives/index.ts +2 -1
  114. package/src/script/__tests/Script.test.ts +1 -1
  115. package/src/script/__tests/SpendComplex.test.ts +6 -6
  116. package/src/script/__tests/script.invalid.vectors.ts +1464 -1464
  117. package/src/script/__tests/script.valid.vectors.ts +1962 -1962
  118. package/src/script/__tests/spend.valid.vectors.ts +1369 -1369
  119. package/src/script/templates/P2PKH.ts +6 -6
  120. package/src/script/templates/RPuzzle.ts +1 -1
  121. package/src/transaction/__tests/Transaction.test.ts +5 -5
  122. package/src/transaction/__tests/bump.invalid.vectors.ts +1 -1
  123. package/src/transaction/__tests/bump.valid.vectors.ts +3 -3
  124. package/src/transaction/broadcasters/ARC.ts +20 -21
  125. package/src/transaction/broadcasters/DefaultBroadcaster.ts +3 -3
  126. package/src/transaction/broadcasters/WhatsOnChainBroadcaster.ts +10 -10
  127. package/src/transaction/broadcasters/__tests/WhatsOnChainBroadcaster.test.ts +7 -10
  128. package/src/transaction/chaintrackers/DefaultChainTracker.ts +3 -3
  129. package/src/transaction/chaintrackers/WhatsOnChain.ts +10 -12
  130. package/src/transaction/chaintrackers/__tests/WhatsOnChainChainTracker.test.ts +13 -17
  131. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +2 -2
  132. package/src/transaction/http/DefaultHttpClient.ts +13 -13
  133. package/src/transaction/http/FetchHttpClient.ts +14 -16
  134. package/src/transaction/http/HttpClient.ts +22 -23
  135. package/src/transaction/http/NodejsHttpClient.ts +23 -25
  136. package/src/transaction/http/index.ts +6 -6
@@ -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) | [Reader](#class-reader) |
12
- | [BigNumber](#class-bignumber) | [ReductionContext](#class-reductioncontext) |
13
- | [Curve](#class-curve) | [SHA1](#class-sha1) |
14
- | [DRBG](#class-drbg) | [SHA1HMAC](#class-sha1hmac) |
15
- | [JacobianPoint](#class-jacobianpoint) | [SHA256](#class-sha256) |
16
- | [K256](#class-k256) | [SHA256HMAC](#class-sha256hmac) |
17
- | [Mersenne](#class-mersenne) | [SHA512](#class-sha512) |
18
- | [MontgomoryMethod](#class-montgomorymethod) | [SHA512HMAC](#class-sha512hmac) |
19
- | [Point](#class-point) | [Signature](#class-signature) |
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
@@ -6,14 +6,14 @@ Links: [API](#api), [Interfaces](#interfaces), [Classes](#classes), [Functions](
6
6
 
7
7
  | | |
8
8
  | --- | --- |
9
- | [ArcConfig](#interface-arcconfig) | [HttpClient](#interface-httpclient) |
10
- | [BroadcastFailure](#interface-broadcastfailure) | [HttpClientRequestOptions](#interface-httpclientrequestoptions) |
11
- | [BroadcastResponse](#interface-broadcastresponse) | [HttpsNodejs](#interface-httpsnodejs) |
12
- | [Broadcaster](#interface-broadcaster) | [MerklePathLeaf](#interface-merklepathleaf) |
13
- | [ChainTracker](#interface-chaintracker) | [NodejsHttpClientRequest](#interface-nodejshttpclientrequest) |
14
- | [FeeModel](#interface-feemodel) | [TransactionInput](#interface-transactioninput) |
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>): Promise<HttpClientResponse<T>>;
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
- #### Method request
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>): Promise<HttpClientResponse<T>>
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): NodejsHttpClientRequest;
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): void;
291
- end(): void;
292
- on(event: string, callback: (data: any) => void): void;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.1.13",
3
+ "version": "1.1.14",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Software Development Kit",
6
6
  "main": "dist/cjs/mod.js",
@@ -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
- 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)
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
- 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)
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
- describe('verify', () => {
25
- const messageBuf = toArray('this is my message', 'utf8')
26
- const privateKey = new PrivateKey(42)
23
+ })
24
+ describe('verify', () => {
25
+ const messageBuf = toArray('this is my message', 'utf8')
26
+ const privateKey = new PrivateKey(42)
27
27
 
28
- it('should verify a signed message', () => {
29
- const sig = sign(messageBuf, privateKey)
30
- expect(verify(messageBuf, sig, privateKey.toPublicKey())).toEqual(true)
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
+ })