@bsv/sdk 2.0.12 → 2.0.13

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 (77) hide show
  1. package/dist/cjs/package.json +1 -1
  2. package/dist/cjs/src/auth/clients/__tests__/AuthFetch.additional.test.js +827 -0
  3. package/dist/cjs/src/auth/clients/__tests__/AuthFetch.additional.test.js.map +1 -0
  4. package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js +654 -0
  5. package/dist/cjs/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js.map +1 -0
  6. package/dist/cjs/src/transaction/MerklePath.js +132 -0
  7. package/dist/cjs/src/transaction/MerklePath.js.map +1 -1
  8. package/dist/cjs/tsconfig.cjs.tsbuildinfo +1 -1
  9. package/dist/esm/src/auth/clients/__tests__/AuthFetch.additional.test.js +825 -0
  10. package/dist/esm/src/auth/clients/__tests__/AuthFetch.additional.test.js.map +1 -0
  11. package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js +619 -0
  12. package/dist/esm/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.js.map +1 -0
  13. package/dist/esm/src/transaction/MerklePath.js +132 -0
  14. package/dist/esm/src/transaction/MerklePath.js.map +1 -1
  15. package/dist/esm/tsconfig.esm.tsbuildinfo +1 -1
  16. package/dist/types/src/auth/clients/__tests__/AuthFetch.additional.test.d.ts +21 -0
  17. package/dist/types/src/auth/clients/__tests__/AuthFetch.additional.test.d.ts.map +1 -0
  18. package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.d.ts +2 -0
  19. package/dist/types/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.d.ts.map +1 -0
  20. package/dist/types/src/transaction/MerklePath.d.ts +27 -0
  21. package/dist/types/src/transaction/MerklePath.d.ts.map +1 -1
  22. package/dist/types/tsconfig.types.tsbuildinfo +1 -1
  23. package/dist/umd/bundle.js +1 -1
  24. package/dist/umd/bundle.js.map +1 -1
  25. package/docs/reference/storage.md +1 -1
  26. package/docs/reference/transaction.md +40 -0
  27. package/package.json +1 -1
  28. package/src/auth/clients/__tests__/AuthFetch.additional.test.ts +1131 -0
  29. package/src/auth/transports/__tests__/SimplifiedFetchTransport.additional.test.ts +770 -0
  30. package/src/compat/__tests/Mnemonic.additional.test.ts +64 -0
  31. package/src/identity/__tests/IdentityClient.additional.test.ts +767 -0
  32. package/src/kvstore/__tests/LocalKVStore.additional.test.ts +611 -0
  33. package/src/kvstore/__tests/kvStoreInterpreter.test.ts +327 -0
  34. package/src/overlay-tools/__tests/HostReputationTracker.additional.test.ts +561 -0
  35. package/src/overlay-tools/__tests/LookupResolver.additional.test.ts +612 -0
  36. package/src/overlay-tools/__tests/withDoubleSpendRetry.test.ts +278 -0
  37. package/src/primitives/__tests/BigNumber.additional.test.ts +79 -0
  38. package/src/primitives/__tests/Curve.additional.test.ts +208 -0
  39. package/src/primitives/__tests/ECDSA.additional.test.ts +122 -0
  40. package/src/primitives/__tests/Hash.additional.test.ts +59 -0
  41. package/src/primitives/__tests/JacobianPoint.test.ts +308 -0
  42. package/src/primitives/__tests/Point.additional.test.ts +503 -0
  43. package/src/primitives/__tests/PublicKey.additional.test.ts +383 -0
  44. package/src/primitives/__tests/Random.additional.test.ts +262 -0
  45. package/src/primitives/__tests/Signature.test.ts +333 -0
  46. package/src/primitives/__tests/TransactionSignature.additional.test.ts +241 -0
  47. package/src/registry/__tests/RegistryClient.additional.test.ts +750 -0
  48. package/src/remittance/__tests/BasicBRC29.additional.test.ts +657 -0
  49. package/src/remittance/__tests/RemittanceManager.additional.test.ts +1272 -0
  50. package/src/script/__tests/LockingUnlockingScript.test.ts +79 -0
  51. package/src/script/__tests/Script.additional.test.ts +100 -0
  52. package/src/script/__tests/ScriptEvaluationError.test.ts +98 -0
  53. package/src/script/__tests/Spend.additional.test.ts +837 -0
  54. package/src/script/templates/__tests/RPuzzle.test.ts +134 -0
  55. package/src/transaction/MerklePath.ts +155 -0
  56. package/src/transaction/__tests/BeefParty.additional.test.ts +22 -0
  57. package/src/transaction/__tests/Broadcaster.test.ts +159 -0
  58. package/src/transaction/__tests/MerklePath.bench.test.ts +105 -0
  59. package/src/transaction/__tests/MerklePath.test.ts +80 -0
  60. package/src/transaction/__tests/Transaction.additional.test.ts +225 -0
  61. package/src/transaction/broadcasters/__tests/ARC.additional.test.ts +585 -0
  62. package/src/transaction/broadcasters/__tests/Teranode.test.ts +349 -0
  63. package/src/transaction/chaintrackers/__tests/BlockHeadersService.test.ts +253 -0
  64. package/src/transaction/chaintrackers/__tests/DefaultChainTracker.test.ts +44 -0
  65. package/src/transaction/chaintrackers/__tests/WhatsOnChain.additional.test.ts +193 -0
  66. package/src/transaction/fee-models/__tests/SatoshisPerKilobyte.test.ts +262 -0
  67. package/src/transaction/http/__tests/BinaryFetchClient.test.ts +212 -0
  68. package/src/transaction/http/__tests/DefaultHttpClient.additional.test.ts +192 -0
  69. package/src/transaction/http/__tests/DefaultHttpClient.test.ts +71 -0
  70. package/src/wallet/__tests/ProtoWallet.additional.test.ts +134 -0
  71. package/src/wallet/__tests/WERR.test.ts +212 -0
  72. package/src/wallet/__tests/WalletClient.additional.test.ts +699 -0
  73. package/src/wallet/__tests/WalletClient.substrate.test.ts +759 -0
  74. package/src/wallet/__tests/WalletError.test.ts +290 -0
  75. package/src/wallet/__tests/validationHelpers.test.ts +1218 -0
  76. package/src/wallet/substrates/__tests/HTTPWalletJSON.test.ts +496 -0
  77. package/src/wallet/substrates/__tests/HTTPWalletWire.test.ts +273 -0
@@ -0,0 +1,225 @@
1
+ import Transaction from '../Transaction'
2
+ import LockingScript from '../../script/LockingScript'
3
+ import UnlockingScript from '../../script/UnlockingScript'
4
+ import { toArray } from '../../primitives/utils'
5
+
6
+ // Known EF-format transaction hex (BRC-30)
7
+ const KNOWN_EF_HEX =
8
+ '010000000000000000ef01ac4e164f5bc16746bb0868404292ac8318bbac3800e4aad13a014da427adce3e000000006a47304402203a61a2e931612b4bda08d541cfb980885173b8dcf64a3471238ae7abcd368d6402204cbf24f04b9aa2256d8901f0ed97866603d2be8324c2bfb7a37bf8fc90edd5b441210263e2dee22b1ddc5e11f6fab8bcd2378bdd19580d640501ea956ec0e786f93e76ffffffff3e660000000000001976a9146bfd5c7fbe21529d45803dbcf0c87dd3c71efbc288ac013c660000000000001976a9146bfd5c7fbe21529d45803dbcf0c87dd3c71efbc288ac00000000'
9
+
10
+ // Known BEEF V1 hex (non-Atomic, has no atomicTxid)
11
+ const KNOWN_BEEF_V1_HEX =
12
+ '0100beef01fe636d0c0007021400fe507c0c7aa754cef1f7889d5fd395cf1f785dd7de98eed895dbedfe4e5bc70d1502ac4e164f5bc16746bb0868404292ac8318bbac3800e4aad13a014da427adce3e010b00bc4ff395efd11719b277694cface5aa50d085a0bb81f613f70313acd28cf4557010400574b2d9142b8d28b61d88e3b2c3f44d858411356b49a28a4643b6d1a6a092a5201030051a05fc84d531b5d250c23f4f886f6812f9fe3f402d61607f977b4ecd2701c19010000fd781529d58fc2523cf396a7f25440b409857e7e221766c57214b1d38c7b481f01010062f542f45ea3660f86c013ced80534cb5fd4c19d66c56e7e8c5d4bf2d40acc5e010100b121e91836fd7cd5102b654e9f72f3cf6fdbfd0b161c53a9c54b12c841126331020100000001cd4e4cac3c7b56920d1e7655e7e260d31f29d9a388d04910f1bbd72304a79029010000006b483045022100e75279a205a547c445719420aa3138bf14743e3f42618e5f86a19bde14bb95f7022064777d34776b05d816daf1699493fcdf2ef5a5ab1ad710d9c97bfb5b8f7cef3641210263e2dee22b1ddc5e11f6fab8bcd2378bdd19580d640501ea956ec0e786f93e76ffffffff013e660000000000001976a9146bfd5c7fbe21529d45803dbcf0c87dd3c71efbc288ac0000000001000100000001ac4e164f5bc16746bb0868404292ac8318bbac3800e4aad13a014da427adce3e000000006a47304402203a61a2e931612b4bda08d541cfb980885173b8dcf64a3471238ae7abcd368d6402204cbf24f04b9aa2256d8901f0ed97866603d2be8324c2bfb7a37bf8fc90edd5b441210263e2dee22b1ddc5e11f6fab8bcd2378bdd19580d640501ea956ec0e786f93e76ffffffff013c660000000000001976a9146bfd5c7fbe21529d45803dbcf0c87dd3c71efbc288ac0000000000'
13
+
14
+ describe('Transaction – additional coverage', () => {
15
+ describe('fromHexEF', () => {
16
+ it('parses a known EF hex string', () => {
17
+ const tx = Transaction.fromHexEF(KNOWN_EF_HEX)
18
+ expect(tx).toBeInstanceOf(Transaction)
19
+ expect(tx.inputs).toHaveLength(1)
20
+ expect(tx.outputs).toHaveLength(1)
21
+ })
22
+ })
23
+
24
+ describe('fromAtomicBEEF – non-atomic BEEF', () => {
25
+ it('throws when passed a regular BEEF with no atomicTxid', () => {
26
+ const beefBytes = toArray(KNOWN_BEEF_V1_HEX, 'hex')
27
+ expect(() => Transaction.fromAtomicBEEF(beefBytes)).toThrow(
28
+ 'beef must conform to BRC-95 and must contain the subject txid.'
29
+ )
30
+ })
31
+ })
32
+
33
+ describe('addInput', () => {
34
+ it('throws when both sourceTXID and sourceTransaction are undefined', () => {
35
+ const tx = new Transaction()
36
+ expect(() =>
37
+ tx.addInput({
38
+ sourceOutputIndex: 0,
39
+ unlockingScript: new UnlockingScript(),
40
+ sequence: 0xffffffff
41
+ })
42
+ ).toThrow('A reference to an an input transaction is required')
43
+ })
44
+
45
+ it('sets sequence to 0xffffffff when not provided', () => {
46
+ const tx = new Transaction()
47
+ tx.addInput({
48
+ sourceTXID: '00'.repeat(32),
49
+ sourceOutputIndex: 0,
50
+ unlockingScript: new UnlockingScript()
51
+ })
52
+ expect(tx.inputs[0].sequence).toBe(0xffffffff)
53
+ })
54
+ })
55
+
56
+ describe('addOutput', () => {
57
+ it('throws when satoshis is undefined and change is not true', () => {
58
+ const tx = new Transaction()
59
+ expect(() =>
60
+ tx.addOutput({
61
+ lockingScript: new LockingScript()
62
+ })
63
+ ).toThrow('either satoshis must be defined or change must be set to true')
64
+ })
65
+
66
+ it('throws when satoshis is negative', () => {
67
+ const tx = new Transaction()
68
+ expect(() =>
69
+ tx.addOutput({
70
+ lockingScript: new LockingScript(),
71
+ satoshis: -1
72
+ })
73
+ ).toThrow('satoshis must be a positive integer or zero')
74
+ })
75
+
76
+ it('throws when lockingScript is null', () => {
77
+ const tx = new Transaction()
78
+ expect(() =>
79
+ // eslint-disable-next-line @typescript-eslint/no-explicit-any
80
+ tx.addOutput({ satoshis: 100, lockingScript: null as any })
81
+ ).toThrow('lockingScript must be defined')
82
+ })
83
+ })
84
+
85
+ describe('addP2PKHOutput', () => {
86
+ it('adds a change output when satoshis is omitted', () => {
87
+ const tx = new Transaction()
88
+ // Pass a 20-byte hash directly to avoid base58 parsing
89
+ const pubKeyHash = new Array(20).fill(0x01)
90
+ tx.addP2PKHOutput(pubKeyHash)
91
+ expect(tx.outputs).toHaveLength(1)
92
+ expect(tx.outputs[0].change).toBe(true)
93
+ })
94
+ })
95
+
96
+ describe('hash / id', () => {
97
+ it('returns hex string from hash("hex")', () => {
98
+ const tx = new Transaction()
99
+ const h = tx.hash('hex')
100
+ expect(typeof h).toBe('string')
101
+ expect((h as string)).toHaveLength(64)
102
+ })
103
+
104
+ it('returns binary array from id() without enc', () => {
105
+ const tx = new Transaction()
106
+ const id = tx.id()
107
+ expect(Array.isArray(id)).toBe(true)
108
+ expect(id).toHaveLength(32)
109
+ })
110
+ })
111
+
112
+ describe('toHexAtomicBEEF', () => {
113
+ it('produces a hex string from toHexAtomicBEEF()', () => {
114
+ const sourceTx = new Transaction(
115
+ 1,
116
+ [],
117
+ [{ lockingScript: new LockingScript(), satoshis: 1000 }],
118
+ 0
119
+ )
120
+ const tx = new Transaction(1, [], [{ lockingScript: new LockingScript(), satoshis: 900 }], 0)
121
+ tx.addInput({
122
+ sourceTXID: sourceTx.id('hex'),
123
+ sourceTransaction: sourceTx,
124
+ sourceOutputIndex: 0,
125
+ unlockingScript: new UnlockingScript(),
126
+ sequence: 0xffffffff
127
+ })
128
+ const hex = tx.toHexAtomicBEEF()
129
+ expect(typeof hex).toBe('string')
130
+ expect(hex.length).toBeGreaterThan(0)
131
+ })
132
+ })
133
+
134
+ describe('getFee', () => {
135
+ it('throws when an input has no sourceTransaction', () => {
136
+ const tx = new Transaction()
137
+ tx.addInput({
138
+ sourceTXID: '00'.repeat(32),
139
+ sourceOutputIndex: 0,
140
+ unlockingScript: new UnlockingScript()
141
+ })
142
+ expect(() => tx.getFee()).toThrow(
143
+ 'Source transactions or sourceSatoshis are required for all inputs to calculate fee'
144
+ )
145
+ })
146
+ })
147
+
148
+ describe('sign', () => {
149
+ it('throws when an output has undefined satoshis and change is not set', async () => {
150
+ const tx = new Transaction(
151
+ 1,
152
+ [],
153
+ [{ lockingScript: new LockingScript(), satoshis: undefined, change: false }],
154
+ 0
155
+ )
156
+ await expect(tx.sign()).rejects.toThrow(
157
+ 'One or more transaction outputs is missing an amount'
158
+ )
159
+ })
160
+
161
+ it('throws when an output has undefined satoshis and change is true (uncomputed change)', async () => {
162
+ const tx = new Transaction(
163
+ 1,
164
+ [],
165
+ [{ lockingScript: new LockingScript(), satoshis: undefined, change: true }],
166
+ 0
167
+ )
168
+ await expect(tx.sign()).rejects.toThrow(
169
+ 'There are still change outputs with uncomputed amounts'
170
+ )
171
+ })
172
+ })
173
+
174
+ describe('toEF / writeEF error paths', () => {
175
+ it('throws when an input has no sourceTransaction during EF serialization', () => {
176
+ // sourceTXID is defined so addInput passes, but sourceTransaction is undefined
177
+ const tx = new Transaction()
178
+ tx.addInput({
179
+ sourceTXID: '00'.repeat(32),
180
+ sourceOutputIndex: 0,
181
+ unlockingScript: new UnlockingScript()
182
+ })
183
+ expect(() => tx.toEF()).toThrow(
184
+ 'All inputs must have source transactions when serializing to EF format'
185
+ )
186
+ })
187
+ })
188
+
189
+ describe('toBinary / writeTransactionBody error paths', () => {
190
+ it('throws when an input has no sourceTXID and no sourceTransaction', () => {
191
+ // Bypass addInput validation by constructing directly
192
+ const tx = new Transaction(
193
+ 1,
194
+ [
195
+ {
196
+ sourceOutputIndex: 0,
197
+ unlockingScript: new UnlockingScript(),
198
+ sequence: 0xffffffff
199
+ // no sourceTXID, no sourceTransaction
200
+ }
201
+ ],
202
+ [],
203
+ 0
204
+ )
205
+ expect(() => tx.toBinary()).toThrow('sourceTransaction is undefined')
206
+ })
207
+
208
+ it('throws when an input has no unlockingScript during serialization', () => {
209
+ const tx = new Transaction(
210
+ 1,
211
+ [
212
+ {
213
+ sourceTXID: '00'.repeat(32),
214
+ sourceOutputIndex: 0,
215
+ sequence: 0xffffffff
216
+ // no unlockingScript
217
+ }
218
+ ],
219
+ [],
220
+ 0
221
+ )
222
+ expect(() => tx.toBinary()).toThrow('unlockingScript is undefined')
223
+ })
224
+ })
225
+ })