@bsv/sdk 1.0.0 → 1.0.1

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 (123) hide show
  1. package/README.md +25 -3
  2. package/package.json +9 -5
  3. package/.github/ISSUE_TEMPLATE/bug_report.md +0 -40
  4. package/.github/ISSUE_TEMPLATE/discussion.md +0 -24
  5. package/.github/PULL_REQUEST_TEMPLATE/pull_request_template.md +0 -23
  6. package/CHANGELOG.md +0 -72
  7. package/CONTRIBUTING.md +0 -85
  8. package/ROADMAP.md +0 -3
  9. package/docs/getting-started/COMMONJS.md +0 -94
  10. package/docs/getting-started/REACT-TS.md +0 -131
  11. package/docs/getting-started/TS-NODE.md +0 -106
  12. package/docs/getting-started/VUE.md +0 -103
  13. package/jest.config.js +0 -6
  14. package/mod.ts +0 -8
  15. package/src/compat/BSM.ts +0 -51
  16. package/src/compat/ECIES.ts +0 -557
  17. package/src/compat/HD.ts +0 -348
  18. package/src/compat/Mnemonic.ts +0 -295
  19. package/src/compat/__tests/BSM.test.ts +0 -38
  20. package/src/compat/__tests/ECIES.test.ts +0 -90
  21. package/src/compat/__tests/HD.test.ts +0 -405
  22. package/src/compat/__tests/Mnemonic.test.ts +0 -177
  23. package/src/compat/__tests/Mnemonic.vectors.ts +0 -172
  24. package/src/compat/bip-39-wordlist-en.ts +0 -2053
  25. package/src/compat/index.ts +0 -4
  26. package/src/messages/EncryptedMessage.ts +0 -70
  27. package/src/messages/SignedMessage.ts +0 -87
  28. package/src/messages/__tests/EncryptedMessage.test.ts +0 -36
  29. package/src/messages/__tests/SignedMessage.test.ts +0 -53
  30. package/src/messages/index.ts +0 -2
  31. package/src/primitives/AESGCM.ts +0 -479
  32. package/src/primitives/BasePoint.ts +0 -21
  33. package/src/primitives/BigNumber.ts +0 -4619
  34. package/src/primitives/Curve.ts +0 -1163
  35. package/src/primitives/DRBG.ts +0 -102
  36. package/src/primitives/ECDSA.ts +0 -164
  37. package/src/primitives/Hash.ts +0 -1420
  38. package/src/primitives/JacobianPoint.ts +0 -410
  39. package/src/primitives/K256.ts +0 -116
  40. package/src/primitives/Mersenne.ts +0 -123
  41. package/src/primitives/MontgomoryMethod.ts +0 -160
  42. package/src/primitives/Point.ts +0 -852
  43. package/src/primitives/PrivateKey.ts +0 -195
  44. package/src/primitives/PublicKey.ts +0 -154
  45. package/src/primitives/Random.ts +0 -55
  46. package/src/primitives/ReductionContext.ts +0 -528
  47. package/src/primitives/Signature.ts +0 -235
  48. package/src/primitives/SymmetricKey.ts +0 -75
  49. package/src/primitives/TransactionSignature.ts +0 -189
  50. package/src/primitives/__tests/AESGCM.test.ts +0 -338
  51. package/src/primitives/__tests/BRC42.private.vectors.ts +0 -33
  52. package/src/primitives/__tests/BRC42.public.vectors.ts +0 -33
  53. package/src/primitives/__tests/BigNumber.arithmatic.test.ts +0 -572
  54. package/src/primitives/__tests/BigNumber.binary.test.ts +0 -203
  55. package/src/primitives/__tests/BigNumber.constructor.test.ts +0 -176
  56. package/src/primitives/__tests/BigNumber.dhGroup.test.ts +0 -18
  57. package/src/primitives/__tests/BigNumber.fixtures.ts +0 -264
  58. package/src/primitives/__tests/BigNumber.serializers.test.ts +0 -157
  59. package/src/primitives/__tests/BigNumber.utils.test.ts +0 -347
  60. package/src/primitives/__tests/Curve.unit.test.ts +0 -192
  61. package/src/primitives/__tests/DRBG.test.ts +0 -18
  62. package/src/primitives/__tests/DRBG.vectors.ts +0 -167
  63. package/src/primitives/__tests/ECDH.test.ts +0 -31
  64. package/src/primitives/__tests/ECDSA.test.ts +0 -58
  65. package/src/primitives/__tests/HMAC.test.ts +0 -59
  66. package/src/primitives/__tests/Hash.test.ts +0 -121
  67. package/src/primitives/__tests/PBKDF2.vectors.ts +0 -119
  68. package/src/primitives/__tests/PrivateKey.test.ts +0 -17
  69. package/src/primitives/__tests/PublicKey.test.ts +0 -66
  70. package/src/primitives/__tests/Random.test.ts +0 -14
  71. package/src/primitives/__tests/Reader.test.ts +0 -296
  72. package/src/primitives/__tests/ReductionContext.test.ts +0 -279
  73. package/src/primitives/__tests/SymmetricKey.test.ts +0 -58
  74. package/src/primitives/__tests/SymmetricKey.vectors.ts +0 -40
  75. package/src/primitives/__tests/Writer.test.ts +0 -198
  76. package/src/primitives/__tests/sighash.vectors.ts +0 -3503
  77. package/src/primitives/__tests/utils.test.ts +0 -108
  78. package/src/primitives/index.ts +0 -8
  79. package/src/primitives/utils.ts +0 -665
  80. package/src/script/LockingScript.ts +0 -30
  81. package/src/script/OP.ts +0 -219
  82. package/src/script/Script.ts +0 -426
  83. package/src/script/ScriptChunk.ts +0 -7
  84. package/src/script/ScriptTemplate.ts +0 -36
  85. package/src/script/Spend.ts +0 -1379
  86. package/src/script/UnlockingScript.ts +0 -30
  87. package/src/script/__tests/Script.test.ts +0 -369
  88. package/src/script/__tests/Spend.test.ts +0 -248
  89. package/src/script/__tests/script.invalid.vectors.ts +0 -925
  90. package/src/script/__tests/script.valid.vectors.ts +0 -1120
  91. package/src/script/__tests/scriptFromVector.ts +0 -42
  92. package/src/script/__tests/spend.valid.vectors.ts +0 -2288
  93. package/src/script/index.ts +0 -7
  94. package/src/script/templates/P2PKH.ts +0 -109
  95. package/src/script/templates/RPuzzle.ts +0 -140
  96. package/src/script/templates/index.ts +0 -2
  97. package/src/transaction/Broadcaster.ts +0 -42
  98. package/src/transaction/ChainTracker.ts +0 -22
  99. package/src/transaction/FeeModel.ts +0 -13
  100. package/src/transaction/MerklePath.ts +0 -259
  101. package/src/transaction/Transaction.ts +0 -602
  102. package/src/transaction/TransactionInput.ts +0 -63
  103. package/src/transaction/TransactionOutput.ts +0 -37
  104. package/src/transaction/__tests/MerklePath.test.ts +0 -181
  105. package/src/transaction/__tests/Transaction.test.ts +0 -413
  106. package/src/transaction/__tests/bigtx.vectors.ts +0 -4
  107. package/src/transaction/__tests/bump.invalid.vectors.ts +0 -8
  108. package/src/transaction/__tests/bump.valid.vectors.ts +0 -4
  109. package/src/transaction/__tests/tx.invalid.vectors.ts +0 -281
  110. package/src/transaction/__tests/tx.valid.vectors.ts +0 -364
  111. package/src/transaction/broadcasters/ARC.ts +0 -106
  112. package/src/transaction/broadcasters/__tests/ARC.test.ts +0 -115
  113. package/src/transaction/broadcasters/index.ts +0 -1
  114. package/src/transaction/fee-models/SatoshisPerKilobyte.ts +0 -71
  115. package/src/transaction/fee-models/index.ts +0 -1
  116. package/src/transaction/index.ts +0 -6
  117. package/ts2md.json +0 -5
  118. package/tsconfig.base.json +0 -26
  119. package/tsconfig.cjs.json +0 -11
  120. package/tsconfig.eslint.json +0 -12
  121. package/tsconfig.esm.json +0 -9
  122. package/tsconfig.json +0 -17
  123. package/tsconfig.types.json +0 -11
@@ -1,160 +0,0 @@
1
- import ReductionContext from './ReductionContext.js'
2
- import BigNumber from './BigNumber.js'
3
-
4
- /**
5
- * Represents a Montgomery reduction context, which is a mathematical method
6
- * for performing modular multiplication without division.
7
- *
8
- * Montgomery reduction is an algorithm used mainly in cryptography which can
9
- * help to speed up calculations in contexts where there are many repeated
10
- * computations.
11
- *
12
- * This class extends the `ReductionContext` class.
13
- *
14
- * @class MontgomoryMethod
15
- * @extends {ReductionContext}
16
- *
17
- * @property shift - The number of bits in the modulus.
18
- * @property r - The 2^shift, shifted left by the bit length of modulus `m`.
19
- * @property r2 - The square of `r` modulo `m`.
20
- * @property rinv - The modular multiplicative inverse of `r` mod `m`.
21
- * @property minv - The modular multiplicative inverse of `m` mod `r`.
22
- */
23
- export default class MontgomoryMethod extends ReductionContext {
24
- shift: number
25
- r: BigNumber
26
- r2: BigNumber
27
- rinv: BigNumber
28
- minv: BigNumber
29
-
30
- /**
31
- * @constructor
32
- * @param m - The modulus to be used for the Montgomery method reductions.
33
- */
34
- constructor (m: BigNumber | 'k256') {
35
- super(m)
36
-
37
- this.shift = this.m.bitLength()
38
- if (this.shift % 26 !== 0) {
39
- this.shift += 26 - (this.shift % 26)
40
- }
41
-
42
- this.r = new BigNumber(1).iushln(this.shift)
43
- this.r2 = this.imod(this.r.sqr())
44
- this.rinv = this.r._invmp(this.m)
45
-
46
- this.minv = this.rinv.mul(this.r).isubn(1).div(this.m)
47
- this.minv = this.minv.umod(this.r)
48
- this.minv = this.r.sub(this.minv)
49
- }
50
-
51
- /**
52
- * Converts a number into the Montgomery domain.
53
- *
54
- * @method convertTo
55
- * @param num - The number to be converted into the Montgomery domain.
56
- * @returns The result of the conversion into the Montgomery domain.
57
- *
58
- * @example
59
- * const montMethod = new MontgomoryMethod(m);
60
- * const convertedNum = montMethod.convertTo(num);
61
- */
62
- convertTo (num: BigNumber): BigNumber {
63
- return this.imod(num.ushln(this.shift))
64
- }
65
-
66
- /**
67
- * Converts a number from the Montgomery domain back to the original domain.
68
- *
69
- * @method convertFrom
70
- * @param num - The number to be converted from the Montgomery domain.
71
- * @returns The result of the conversion from the Montgomery domain.
72
- *
73
- * @example
74
- * const montMethod = new MontgomoryMethod(m);
75
- * const convertedNum = montMethod.convertFrom(num);
76
- */
77
- convertFrom (num: BigNumber): BigNumber {
78
- const r = this.imod(num.mul(this.rinv))
79
- r.red = null
80
- return r
81
- }
82
-
83
- /**
84
- * Performs an in-place multiplication of two numbers in the Montgomery domain.
85
- *
86
- * @method imul
87
- * @param a - The first number to multiply.
88
- * @param b - The second number to multiply.
89
- * @returns The result of the in-place multiplication.
90
- *
91
- * @example
92
- * const montMethod = new MontgomoryMethod(m);
93
- * const product = montMethod.imul(a, b);
94
- */
95
- imul (a: BigNumber, b: BigNumber): BigNumber {
96
- if (a.isZero() || b.isZero()) {
97
- a.words[0] = 0
98
- a.length = 1
99
- return a
100
- }
101
-
102
- const t = a.imul(b)
103
- const c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m)
104
- const u = t.isub(c).iushrn(this.shift)
105
- let res = u
106
-
107
- if (u.cmp(this.m) >= 0) {
108
- res = u.isub(this.m)
109
- } else if (u.cmpn(0) < 0) {
110
- res = u.iadd(this.m)
111
- }
112
-
113
- return res.forceRed(this)
114
- }
115
-
116
- /**
117
- * Performs the multiplication of two numbers in the Montgomery domain.
118
- *
119
- * @method mul
120
- * @param a - The first number to multiply.
121
- * @param b - The second number to multiply.
122
- * @returns The result of the multiplication.
123
- *
124
- * @example
125
- * const montMethod = new MontgomoryMethod(m);
126
- * const product = montMethod.mul(a, b);
127
- */
128
- mul (a: BigNumber, b: BigNumber): BigNumber {
129
- if (a.isZero() || b.isZero()) return new BigNumber(0).forceRed(this)
130
-
131
- const t = a.mul(b)
132
- const c = t.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m)
133
- const u = t.isub(c).iushrn(this.shift)
134
- let res = u
135
- if (u.cmp(this.m) >= 0) {
136
- res = u.isub(this.m)
137
- } else if (u.cmpn(0) < 0) {
138
- res = u.iadd(this.m)
139
- }
140
-
141
- return res.forceRed(this)
142
- }
143
-
144
- /**
145
- * Calculates the modular multiplicative inverse of a number in the Montgomery domain.
146
- *
147
- * @method invm
148
- * @param a - The number to compute the modular multiplicative inverse of.
149
- * @returns The modular multiplicative inverse of 'a'.
150
- *
151
- * @example
152
- * const montMethod = new MontgomoryMethod(m);
153
- * const inverse = montMethod.invm(a);
154
- */
155
- invm (a: BigNumber): BigNumber {
156
- // (AR)^-1 * R^2 = (A^-1 * R^-1) * R^2 = A^-1 * R
157
- const res = this.imod(a._invmp(this.m).mul(this.r2))
158
- return res.forceRed(this)
159
- }
160
- }