@bsv/sdk 1.0.5 → 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.
Files changed (58) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/primitives/BigNumber.js +2 -2
  3. package/dist/cjs/src/primitives/BigNumber.js.map +1 -1
  4. package/dist/cjs/src/primitives/Hash.js +98 -56
  5. package/dist/cjs/src/primitives/Hash.js.map +1 -1
  6. package/dist/cjs/src/primitives/PrivateKey.js +23 -0
  7. package/dist/cjs/src/primitives/PrivateKey.js.map +1 -1
  8. package/dist/cjs/src/primitives/PublicKey.js +19 -1
  9. package/dist/cjs/src/primitives/PublicKey.js.map +1 -1
  10. package/dist/cjs/src/primitives/SymmetricKey.js +13 -0
  11. package/dist/cjs/src/primitives/SymmetricKey.js.map +1 -1
  12. package/dist/cjs/src/primitives/index.js +3 -1
  13. package/dist/cjs/src/primitives/index.js.map +1 -1
  14. package/dist/cjs/src/primitives/utils.js +3 -3
  15. package/dist/cjs/src/primitives/utils.js.map +1 -1
  16. package/dist/cjs/src/script/Spend.js +2 -3
  17. package/dist/cjs/src/script/Spend.js.map +1 -1
  18. package/dist/cjs/src/script/templates/P2PKH.js +14 -3
  19. package/dist/cjs/src/script/templates/P2PKH.js.map +1 -1
  20. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  21. package/dist/esm/src/primitives/BigNumber.js +2 -2
  22. package/dist/esm/src/primitives/BigNumber.js.map +1 -1
  23. package/dist/esm/src/primitives/Hash.js +98 -56
  24. package/dist/esm/src/primitives/Hash.js.map +1 -1
  25. package/dist/esm/src/primitives/PrivateKey.js +23 -0
  26. package/dist/esm/src/primitives/PrivateKey.js.map +1 -1
  27. package/dist/esm/src/primitives/PublicKey.js +19 -1
  28. package/dist/esm/src/primitives/PublicKey.js.map +1 -1
  29. package/dist/esm/src/primitives/SymmetricKey.js +13 -0
  30. package/dist/esm/src/primitives/SymmetricKey.js.map +1 -1
  31. package/dist/esm/src/primitives/index.js +1 -0
  32. package/dist/esm/src/primitives/index.js.map +1 -1
  33. package/dist/esm/src/primitives/utils.js +3 -3
  34. package/dist/esm/src/primitives/utils.js.map +1 -1
  35. package/dist/esm/src/script/Spend.js +2 -3
  36. package/dist/esm/src/script/Spend.js.map +1 -1
  37. package/dist/esm/src/script/templates/P2PKH.js +14 -3
  38. package/dist/esm/src/script/templates/P2PKH.js.map +1 -1
  39. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  40. package/dist/types/src/primitives/BigNumber.d.ts +1 -1
  41. package/dist/types/src/primitives/BigNumber.d.ts.map +1 -1
  42. package/dist/types/src/primitives/Hash.d.ts +73 -34
  43. package/dist/types/src/primitives/Hash.d.ts.map +1 -1
  44. package/dist/types/src/primitives/PrivateKey.d.ts +16 -1
  45. package/dist/types/src/primitives/PrivateKey.d.ts.map +1 -1
  46. package/dist/types/src/primitives/PublicKey.d.ts +14 -2
  47. package/dist/types/src/primitives/PublicKey.d.ts.map +1 -1
  48. package/dist/types/src/primitives/SymmetricKey.d.ts +11 -0
  49. package/dist/types/src/primitives/SymmetricKey.d.ts.map +1 -1
  50. package/dist/types/src/primitives/index.d.ts +1 -0
  51. package/dist/types/src/primitives/index.d.ts.map +1 -1
  52. package/dist/types/src/primitives/utils.d.ts +2 -2
  53. package/dist/types/src/script/Spend.d.ts.map +1 -1
  54. package/dist/types/src/script/templates/P2PKH.d.ts +3 -3
  55. package/dist/types/src/script/templates/P2PKH.d.ts.map +1 -1
  56. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  57. package/docs/primitives.md +132 -42
  58. package/package.json +1 -1
@@ -4764,7 +4764,8 @@ export class RIPEMD160 extends BaseHash {
4764
4764
  h: number[];
4765
4765
  constructor()
4766
4766
  _update(msg: number[], start: number): void
4767
- _digest(enc?: "hex"): string | number[]
4767
+ _digest(): number[]
4768
+ _digestHex(): string
4768
4769
  }
4769
4770
  ```
4770
4771
 
@@ -4806,7 +4807,8 @@ export class SHA256 extends BaseHash {
4806
4807
  constructor()
4807
4808
  _update(msg: number[], start?: number): void
4808
4809
  ;
4809
- _digest(enc?: "hex"): number[] | string
4810
+ _digest(): number[]
4811
+ _digestHex(): string
4810
4812
  }
4811
4813
  ```
4812
4814
 
@@ -4863,7 +4865,8 @@ export class SHA1 extends BaseHash {
4863
4865
  k: number[];
4864
4866
  constructor()
4865
4867
  _update(msg: number[], start?: number): void
4866
- _digest(enc?: "hex"): number[] | string
4868
+ _digest(): number[]
4869
+ _digestHex(): string
4867
4870
  }
4868
4871
  ```
4869
4872
 
@@ -4921,7 +4924,8 @@ export class SHA512 extends BaseHash {
4921
4924
  constructor()
4922
4925
  _prepareBlock(msg, start)
4923
4926
  _update(msg, start)
4924
- _digest(enc)
4927
+ _digest()
4928
+ _digestHex()
4925
4929
  }
4926
4930
  ```
4927
4931
 
@@ -4974,7 +4978,8 @@ export class SHA256HMAC {
4974
4978
  outSize = 32;
4975
4979
  constructor(key: number[] | string)
4976
4980
  update(msg: number[] | string, enc?: "hex"): SHA256HMAC
4977
- digest(enc?: "hex"): number[] | string
4981
+ digest(): number[]
4982
+ digestHex(): string
4978
4983
  }
4979
4984
  ```
4980
4985
 
@@ -5042,22 +5047,35 @@ outer: SHA256
5042
5047
  Finalizes the HMAC computation and returns the resultant hash.
5043
5048
 
5044
5049
  ```ts
5045
- digest(enc?: "hex"): number[] | string
5050
+ digest(): number[]
5046
5051
  ```
5047
5052
 
5048
5053
  Returns
5049
5054
 
5050
5055
  Returns the digest of the hashed data. Can be a number array or a string.
5051
5056
 
5052
- Argument Details
5057
+ Example
5053
5058
 
5054
- + **enc**
5055
- + If 'hex', then the output is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
5059
+ ```ts
5060
+ let hashedMessage = myHMAC.digest();
5061
+ ```
5062
+
5063
+ #### Method digestHex
5064
+
5065
+ Finalizes the HMAC computation and returns the resultant hash as a hex string.
5066
+
5067
+ ```ts
5068
+ digestHex(): string
5069
+ ```
5070
+
5071
+ Returns
5072
+
5073
+ Returns the digest of the hashed data as a hex string
5056
5074
 
5057
5075
  Example
5058
5076
 
5059
5077
  ```ts
5060
- let hashedMessage = myHMAC.digest('hex');
5078
+ let hashedMessage = myHMAC.digestHex();
5061
5079
  ```
5062
5080
 
5063
5081
  #### Method update
@@ -5105,8 +5123,9 @@ export class SHA512HMAC {
5105
5123
  blockSize = 128;
5106
5124
  outSize = 32;
5107
5125
  constructor(key: number[] | string)
5108
- update(msg: number[] | string, enc?: "hex"): SHA512HMAC
5109
- digest(enc?: "hex"): number[] | string
5126
+ update(msg: number[] | string, enc?: "hex" | "utf8"): SHA512HMAC
5127
+ digest(): number[]
5128
+ digestHex(): string
5110
5129
  }
5111
5130
  ```
5112
5131
 
@@ -5174,22 +5193,35 @@ outer: SHA512
5174
5193
  Finalizes the HMAC computation and returns the resultant hash.
5175
5194
 
5176
5195
  ```ts
5177
- digest(enc?: "hex"): number[] | string
5196
+ digest(): number[]
5178
5197
  ```
5179
5198
 
5180
5199
  Returns
5181
5200
 
5182
- Returns the digest of the hashed data. Can be a number array or a string.
5201
+ Returns the digest of the hashed data as a number array.
5183
5202
 
5184
- Argument Details
5203
+ Example
5185
5204
 
5186
- + **enc**
5187
- + If 'hex', then the output is encoded as hexadecimal. If undefined or not 'hex', then no encoding is performed.
5205
+ ```ts
5206
+ let hashedMessage = myHMAC.digest();
5207
+ ```
5208
+
5209
+ #### Method digestHex
5210
+
5211
+ Finalizes the HMAC computation and returns the resultant hash as a hex string.
5212
+
5213
+ ```ts
5214
+ digestHex(): string
5215
+ ```
5216
+
5217
+ Returns
5218
+
5219
+ Returns the digest of the hashed data as a hex string
5188
5220
 
5189
5221
  Example
5190
5222
 
5191
5223
  ```ts
5192
- let hashedMessage = myHMAC.digest('hex');
5224
+ let hashedMessage = myHMAC.digestHex();
5193
5225
  ```
5194
5226
 
5195
5227
  #### Method update
@@ -5197,7 +5229,7 @@ let hashedMessage = myHMAC.digest('hex');
5197
5229
  Updates the `SHA512HMAC` object with part of the message to be hashed.
5198
5230
 
5199
5231
  ```ts
5200
- update(msg: number[] | string, enc?: "hex"): SHA512HMAC
5232
+ update(msg: number[] | string, enc?: "hex" | "utf8"): SHA512HMAC
5201
5233
  ```
5202
5234
 
5203
5235
  Returns
@@ -6213,7 +6245,7 @@ export default class PrivateKey extends BigNumber {
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")
6216
- sign(msg: number[] | string, enc?: "hex", forceLowS: boolean = true, customK?: Function | BigNumber): Signature
6248
+ sign(msg: number[] | string, enc?: "hex" | "utf8", forceLowS: boolean = true, customK?: Function | BigNumber): Signature
6217
6249
  verify(msg: number[] | string, sig: Signature, enc?: "hex"): boolean
6218
6250
  toPublicKey(): PublicKey
6219
6251
  toWif(prefix: number[] = [128]): string
@@ -6245,8 +6277,9 @@ Argument Details
6245
6277
  Example
6246
6278
 
6247
6279
  ```ts
6280
+ import PrivateKey from './PrivateKey';
6248
6281
  import BigNumber from './BigNumber';
6249
- const bn = new BigNumber('123456', 10, 'be');
6282
+ const privKey = new PrivateKey(new BigNumber('123456', 10, 'be'));
6250
6283
  ```
6251
6284
 
6252
6285
  #### Method deriveChild
@@ -6366,7 +6399,7 @@ Will throw an error if the string is not a valid WIF.
6366
6399
  Signs a message using the private key.
6367
6400
 
6368
6401
  ```ts
6369
- 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
6370
6403
  ```
6371
6404
 
6372
6405
  Returns
@@ -6508,8 +6541,9 @@ The class comes with static methods to generate PublicKey instances from private
6508
6541
  export default class PublicKey extends Point {
6509
6542
  static fromPrivateKey(key: PrivateKey): PublicKey
6510
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)
6511
6545
  deriveSharedSecret(priv: PrivateKey): Point
6512
- verify(msg: number[] | string, sig: Signature, enc?: "hex"): boolean
6546
+ verify(msg: number[] | string, sig: Signature, enc?: "hex" | "utf8"): boolean
6513
6547
  toDER(): string
6514
6548
  toHash(enc?: "hex"): number[] | string
6515
6549
  toAddress(prefix: number[] = [0]): string
@@ -6521,6 +6555,28 @@ export default class PublicKey extends Point {
6521
6555
 
6522
6556
  <summary>Class PublicKey Details</summary>
6523
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
+
6524
6580
  #### Method deriveChild
6525
6581
 
6526
6582
  Derives a child key with BRC-42.
@@ -6683,7 +6739,7 @@ const publicKeyHash = pubkey.toHash()
6683
6739
  Verify a signature of a message using this public key.
6684
6740
 
6685
6741
  ```ts
6686
- verify(msg: number[] | string, sig: Signature, enc?: "hex"): boolean
6742
+ verify(msg: number[] | string, sig: Signature, enc?: "hex" | "utf8"): boolean
6687
6743
  ```
6688
6744
 
6689
6745
  Returns
@@ -6697,7 +6753,7 @@ Argument Details
6697
6753
  + **sig**
6698
6754
  + The Signature of the message that needs verification.
6699
6755
  + **enc**
6700
- + The encoding of the message. It defaults to 'hex'.
6756
+ + The encoding of the message. It defaults to 'utf8'.
6701
6757
 
6702
6758
  Example
6703
6759
 
@@ -6720,6 +6776,7 @@ It leverages the Advanced Encryption Standard Galois/Counter Mode (AES-GCM) for
6720
6776
 
6721
6777
  ```ts
6722
6778
  export default class SymmetricKey extends BigNumber {
6779
+ static fromRandom(): SymmetricKey
6723
6780
  encrypt(msg: number[] | string, enc?: "hex"): string | number[]
6724
6781
  decrypt(msg: number[] | string, enc?: "hex" | "utf8"): string | number[]
6725
6782
  }
@@ -6789,6 +6846,24 @@ const key = new SymmetricKey(1234);
6789
6846
  const encryptedMessage = key.encrypt('plainText', 'utf8');
6790
6847
  ```
6791
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
+
6792
6867
  </details>
6793
6868
 
6794
6869
  Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
@@ -6813,9 +6888,24 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
6813
6888
  ### Function: toArray
6814
6889
 
6815
6890
  ```ts
6816
- export function toArray(msg: number[] | string, enc?: "hex"): number[]
6891
+ export function toArray(msg: number[] | string, enc?: "hex" | "utf8"): number[]
6817
6892
  ```
6818
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
+
6819
6909
  Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#variables)
6820
6910
 
6821
6911
  ---
@@ -6946,8 +7036,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
6946
7036
  ### Variable: ripemd160
6947
7037
 
6948
7038
  ```ts
6949
- ripemd160 = (msg: number[] | string, enc?: "hex"): number[] | string => {
6950
- return new RIPEMD160().update(msg, enc).digest(enc);
7039
+ ripemd160 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
7040
+ return new RIPEMD160().update(msg, enc).digest();
6951
7041
  }
6952
7042
  ```
6953
7043
 
@@ -6957,8 +7047,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
6957
7047
  ### Variable: sha1
6958
7048
 
6959
7049
  ```ts
6960
- sha1 = (msg: number[] | string, enc?: "hex"): number[] | string => {
6961
- return new SHA1().update(msg, enc).digest(enc);
7050
+ sha1 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
7051
+ return new SHA1().update(msg, enc).digest();
6962
7052
  }
6963
7053
  ```
6964
7054
 
@@ -6968,8 +7058,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
6968
7058
  ### Variable: sha256
6969
7059
 
6970
7060
  ```ts
6971
- sha256 = (msg: number[] | string, enc?: "hex"): number[] | string => {
6972
- return new SHA256().update(msg, enc).digest(enc);
7061
+ sha256 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
7062
+ return new SHA256().update(msg, enc).digest();
6973
7063
  }
6974
7064
  ```
6975
7065
 
@@ -6979,8 +7069,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
6979
7069
  ### Variable: sha512
6980
7070
 
6981
7071
  ```ts
6982
- sha512 = (msg: number[] | string, enc?: "hex"): number[] | string => {
6983
- return new SHA512().update(msg, enc).digest(enc);
7072
+ sha512 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
7073
+ return new SHA512().update(msg, enc).digest();
6984
7074
  }
6985
7075
  ```
6986
7076
 
@@ -6990,9 +7080,9 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
6990
7080
  ### Variable: hash256
6991
7081
 
6992
7082
  ```ts
6993
- hash256 = (msg: number[] | string, enc?: "hex"): number[] | string => {
7083
+ hash256 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
6994
7084
  const first = new SHA256().update(msg, enc).digest();
6995
- return new SHA256().update(first).digest(enc);
7085
+ return new SHA256().update(first).digest();
6996
7086
  }
6997
7087
  ```
6998
7088
 
@@ -7002,9 +7092,9 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
7002
7092
  ### Variable: hash160
7003
7093
 
7004
7094
  ```ts
7005
- hash160 = (msg: number[] | string, enc?: "hex"): number[] | string => {
7095
+ hash160 = (msg: number[] | string, enc?: "hex" | "utf8"): number[] => {
7006
7096
  const first = new SHA256().update(msg, enc).digest();
7007
- return new RIPEMD160().update(first).digest(enc);
7097
+ return new RIPEMD160().update(first).digest();
7008
7098
  }
7009
7099
  ```
7010
7100
 
@@ -7014,8 +7104,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
7014
7104
  ### Variable: sha256hmac
7015
7105
 
7016
7106
  ```ts
7017
- sha256hmac = (key: number[] | string, msg: number[] | string, enc?: "hex"): number[] | string => {
7018
- return new SHA256HMAC(key).update(msg, enc).digest(enc);
7107
+ sha256hmac = (key: number[] | string, msg: number[] | string, enc?: "hex"): number[] => {
7108
+ return new SHA256HMAC(key).update(msg, enc).digest();
7019
7109
  }
7020
7110
  ```
7021
7111
 
@@ -7025,8 +7115,8 @@ Links: [API](#api), [Classes](#classes), [Functions](#functions), [Variables](#v
7025
7115
  ### Variable: sha512hmac
7026
7116
 
7027
7117
  ```ts
7028
- sha512hmac = (key: number[] | string, msg: number[] | string, enc?: "hex"): number[] | string => {
7029
- return new SHA512HMAC(key).update(msg, enc).digest(enc);
7118
+ sha512hmac = (key: number[] | string, msg: number[] | string, enc?: "hex"): number[] => {
7119
+ return new SHA512HMAC(key).update(msg, enc).digest();
7030
7120
  }
7031
7121
  ```
7032
7122
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bsv/sdk",
3
- "version": "1.0.5",
3
+ "version": "1.0.6",
4
4
  "type": "module",
5
5
  "description": "BSV Blockchain Standard Development Kit",
6
6
  "main": "dist/cjs/mod.js",