@smartledger/bsv 8.3.1 → 9.1.0

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 (169) hide show
  1. package/CHANGELOG.md +228 -0
  2. package/README.md +152 -1031
  3. package/STABILITY.md +134 -0
  4. package/bsv-gdaf.min.js +58 -53
  5. package/bsv-ltp.min.js +23 -18
  6. package/bsv-script-helper.min.js +1 -1
  7. package/bsv-smartcontract.min.js +21 -21
  8. package/bsv.bundle.js +58 -53
  9. package/bsv.d.ts +0 -4
  10. package/bsv.min.js +58 -53
  11. package/docs/BRC220_BATCH_LEAF_AMENDMENT.md +82 -7
  12. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  13. package/docs/README.md +2 -1
  14. package/docs/THREAT_MODEL.md +10 -2
  15. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  16. package/docs/getting-started/INSTALLATION.md +23 -23
  17. package/docs/getting-started/QUICK_START.md +7 -7
  18. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  19. package/docs/proposals/10.0.0-package-split.md +131 -0
  20. package/index.js +15 -26
  21. package/lib/block/merkleblock.js +19 -5
  22. package/lib/covenant/helpers.js +34 -35
  23. package/lib/covenant/pushtx.js +2 -2
  24. package/lib/custom-script-helper.js +0 -16
  25. package/lib/hdprivatekey.js +15 -0
  26. package/lib/ordinals/ordlock.js +1 -1
  27. package/lib/script/interpreter.js +109 -1
  28. package/lib/smart_contract/builder.js +14 -0
  29. package/lib/smart_contract/debugger.js +2 -2
  30. package/lib/smart_contract/dsl.js +2 -2
  31. package/lib/smart_contract/index.js +0 -3
  32. package/lib/smart_contract/locks.js +1 -41
  33. package/lib/smart_contract/pels.js +1 -1
  34. package/lib/smart_contract/token.js +1 -1
  35. package/lib/util/deprecate.js +159 -0
  36. package/package.json +19 -82
  37. package/tools/gen-brc220-batch-vector.js +205 -0
  38. package/version.js +1 -1
  39. package/.mocharc.json +0 -5
  40. package/test/address.js +0 -629
  41. package/test/block/block.js +0 -239
  42. package/test/block/blockheader.js +0 -270
  43. package/test/block/merkleblock.js +0 -207
  44. package/test/build/bundle_crypto_shim.js +0 -104
  45. package/test/build/bundle_externals.js +0 -125
  46. package/test/build/bundle_smoke.js +0 -55
  47. package/test/build/esbuild_main.js +0 -65
  48. package/test/build/esm_wrapper.js +0 -73
  49. package/test/build/exports_resolution.js +0 -84
  50. package/test/build/version_sync.js +0 -14
  51. package/test/cli/smoke.js +0 -261
  52. package/test/consensus/base58-vectors.js +0 -120
  53. package/test/consensus/sv-script-vectors.js +0 -81
  54. package/test/consensus/sv-sighash-vectors.js +0 -51
  55. package/test/consensus/sv-tx-vectors.js +0 -48
  56. package/test/credentials-test.js +0 -332
  57. package/test/crypto/backend_selection.js +0 -126
  58. package/test/crypto/bn.js +0 -168
  59. package/test/crypto/ecdsa.js +0 -426
  60. package/test/crypto/elliptic-fixed.js +0 -61
  61. package/test/crypto/hash.browser.js +0 -121
  62. package/test/crypto/hash.js +0 -122
  63. package/test/crypto/point.js +0 -193
  64. package/test/crypto/random.js +0 -105
  65. package/test/crypto/security.js +0 -176
  66. package/test/crypto/shamir.js +0 -177
  67. package/test/crypto/shamir_rngcap.js +0 -29
  68. package/test/crypto/signature.js +0 -399
  69. package/test/data/bip69.json +0 -215
  70. package/test/data/bitcoin-sv/README.md +0 -170
  71. package/test/data/bitcoin-sv/base58_encode_decode.json +0 -14
  72. package/test/data/bitcoin-sv/base58_keys_invalid.json +0 -152
  73. package/test/data/bitcoin-sv/base58_keys_valid.json +0 -452
  74. package/test/data/bitcoin-sv/script_tests.json +0 -2591
  75. package/test/data/bitcoin-sv/sighash.json +0 -1003
  76. package/test/data/bitcoin-sv/tx_invalid.json +0 -285
  77. package/test/data/bitcoin-sv/tx_valid.json +0 -367
  78. package/test/data/bitcoind/base58_keys_invalid.json +0 -152
  79. package/test/data/bitcoind/base58_keys_valid.json +0 -452
  80. package/test/data/bitcoind/blocks.json +0 -27
  81. package/test/data/bitcoind/script_tests.json +0 -2244
  82. package/test/data/bitcoind/sig_canonical.json +0 -7
  83. package/test/data/bitcoind/sig_noncanonical.json +0 -22
  84. package/test/data/bitcoind/tx_invalid.json +0 -177
  85. package/test/data/bitcoind/tx_valid.json +0 -224
  86. package/test/data/blk86756-testnet.dat +0 -0
  87. package/test/data/blk86756-testnet.js +0 -12
  88. package/test/data/blk86756-testnet.json +0 -684
  89. package/test/data/ecdsa.json +0 -230
  90. package/test/data/merkleblocks.js +0 -486
  91. package/test/data/messages.json +0 -22
  92. package/test/data/sighash.json +0 -1004
  93. package/test/data/tx_creation.json +0 -85
  94. package/test/didweb/relationships.js +0 -144
  95. package/test/ecies/bitcore-ecies.js +0 -178
  96. package/test/ecies/electrum-ecies.js +0 -206
  97. package/test/encoding/base58.js +0 -131
  98. package/test/encoding/base58check.js +0 -145
  99. package/test/encoding/bufferreader.js +0 -328
  100. package/test/encoding/bufferwriter.js +0 -160
  101. package/test/encoding/varint.js +0 -104
  102. package/test/gdaf/anchor_no_key_leak.js +0 -146
  103. package/test/gdaf/anchor_spv.js +0 -163
  104. package/test/gdaf/canonicalization.js +0 -106
  105. package/test/gdaf/canonicalize.js +0 -140
  106. package/test/gdaf/zk_prover.js +0 -204
  107. package/test/hdkeys.js +0 -365
  108. package/test/hdprivatekey.js +0 -339
  109. package/test/hdpublickey.js +0 -293
  110. package/test/index.js +0 -16
  111. package/test/ltp/ids.js +0 -74
  112. package/test/ltp/right.js +0 -198
  113. package/test/ltp/verify_failclosed.js +0 -134
  114. package/test/message/message.js +0 -190
  115. package/test/mnemonic/data/fixtures.json +0 -300
  116. package/test/mnemonic/mnemonic.js +0 -277
  117. package/test/mnemonic/mocha.opts +0 -1
  118. package/test/mnemonic/pbkdf2.test.js +0 -43
  119. package/test/networks.js +0 -207
  120. package/test/notaryhash/batch_leaf.js +0 -140
  121. package/test/notaryhash/certificate.js +0 -249
  122. package/test/notaryhash/encoding.js +0 -186
  123. package/test/notaryhash/interop.js +0 -112
  124. package/test/notaryhash/merkle.js +0 -181
  125. package/test/notaryhash/script.js +0 -270
  126. package/test/notaryhash/verify.js +0 -342
  127. package/test/opcode.js +0 -186
  128. package/test/ordinals/bsv20.js +0 -337
  129. package/test/ordinals/inscription.js +0 -319
  130. package/test/ordinals/ordlock.js +0 -613
  131. package/test/privatekey.js +0 -540
  132. package/test/publickey.js +0 -411
  133. package/test/regressions.js +0 -215
  134. package/test/script/chronicle.js +0 -543
  135. package/test/script/defaults.js +0 -160
  136. package/test/script/genesis_limits.js +0 -203
  137. package/test/script/interpreter.js +0 -776
  138. package/test/script/script.js +0 -1259
  139. package/test/script/string_ops.js +0 -88
  140. package/test/security/fail_closed_contracts.js +0 -104
  141. package/test/security/threat_model_coverage.js +0 -31
  142. package/test/smart_contract/covenants.js +0 -245
  143. package/test/smart_contract/dsl_debugger.js +0 -101
  144. package/test/smart_contract/extract_field.js +0 -61
  145. package/test/smart_contract/nonenforcing_guard.js +0 -44
  146. package/test/smart_contract/ordinal_transfer.js +0 -81
  147. package/test/smart_contract/preimage.js +0 -98
  148. package/test/smart_contract/sighash_marketplace.js +0 -108
  149. package/test/smart_contract/token_generalized.js +0 -185
  150. package/test/spv/headerchain.js +0 -86
  151. package/test/spv/merkleproof.js +0 -133
  152. package/test/statuslist/failclosed.js +0 -78
  153. package/test/transaction/deserialize.js +0 -33
  154. package/test/transaction/input/input.js +0 -92
  155. package/test/transaction/input/multisig.js +0 -174
  156. package/test/transaction/input/multisigscripthash.js +0 -111
  157. package/test/transaction/input/publickey.js +0 -68
  158. package/test/transaction/input/publickeyhash.js +0 -59
  159. package/test/transaction/output.js +0 -185
  160. package/test/transaction/sighash.js +0 -91
  161. package/test/transaction/signature.js +0 -127
  162. package/test/transaction/transaction.js +0 -1299
  163. package/test/transaction/unspentoutput.js +0 -97
  164. package/test/types/dts_drift.js +0 -124
  165. package/test/types/surface_honesty.js +0 -102
  166. package/test/util/id.js +0 -72
  167. package/test/util/js.js +0 -76
  168. package/test/util/preconditions.js +0 -79
  169. package/test/vcjwt/interop.js +0 -126
@@ -1,185 +0,0 @@
1
- 'use strict'
2
-
3
- var should = require('chai').should()
4
-
5
- var bsv = require('../..')
6
- var BN = bsv.crypto.BN
7
- var BufferWriter = bsv.encoding.BufferWriter
8
- var BufferReader = bsv.encoding.BufferReader
9
- var Output = bsv.Transaction.Output
10
- var Script = bsv.Script
11
-
12
- describe('Output', function () {
13
- var output = new Output({
14
- satoshis: 0,
15
- script: Script.empty()
16
- })
17
-
18
- it('throws error with unrecognized argument', function () {
19
- (function () {
20
- new Output(12345) //eslint-disable-line
21
- }.should.throw(TypeError))
22
- })
23
-
24
- it('can be assigned a satoshi amount in big number', function () {
25
- var newOutput = new Output({
26
- satoshis: new BN(100),
27
- script: Script.empty()
28
- })
29
- newOutput.satoshis.should.equal(100)
30
- })
31
-
32
- it('can be assigned a satoshi amount with a string', function () {
33
- var newOutput = new Output({
34
- satoshis: '100',
35
- script: Script.empty()
36
- })
37
- newOutput.satoshis.should.equal(100)
38
- })
39
-
40
- describe('will error if output is not a positive integer', function () {
41
- it('-100', function () {
42
- (function () {
43
- new Output({ //eslint-disable-line
44
- satoshis: -100,
45
- script: Script.empty()
46
- })
47
- }.should.throw('Output satoshis is not a natural number'))
48
- })
49
-
50
- it('1.1', function () {
51
- (function () {
52
- new Output({ //eslint-disable-line
53
- satoshis: 1.1,
54
- script: Script.empty()
55
- })
56
- }.should.throw('Output satoshis is not a natural number'))
57
- })
58
-
59
- it('NaN', function () {
60
- (function () {
61
- new Output({ //eslint-disable-line
62
- satoshis: NaN,
63
- script: Script.empty()
64
- })
65
- }.should.throw('Output satoshis is not a natural number'))
66
- })
67
-
68
- it('Infinity', function () {
69
- (function () {
70
- new Output({ //eslint-disable-line
71
- satoshis: Infinity,
72
- script: Script.empty()
73
- })
74
- }.should.throw('Output satoshis is not a natural number'))
75
- })
76
- })
77
-
78
- var expectEqualOutputs = function (a, b) {
79
- a.satoshis.should.equal(b.satoshis)
80
- a.script.toString().should.equal(b.script.toString())
81
- }
82
-
83
- it('deserializes correctly a simple output', function () {
84
- var writer = new BufferWriter()
85
- output.toBufferWriter(writer)
86
- var deserialized = Output.fromBufferReader(
87
- new BufferReader(writer.toBuffer())
88
- )
89
- expectEqualOutputs(output, deserialized)
90
- })
91
-
92
- it('can instantiate from an object', function () {
93
- var out = new Output(output.toObject())
94
- should.exist(out)
95
- })
96
-
97
- it('can set a script from a buffer', function () {
98
- var newOutput = new Output(output.toObject())
99
- newOutput.setScript(Script().add(0).toBuffer())
100
- newOutput.inspect().should.equal('<Output (0 sats) <Script: OP_0>>')
101
- })
102
-
103
- it('has a inspect property', function () {
104
- output.inspect().should.equal('<Output (0 sats) <Script: >>')
105
- })
106
-
107
- var output2 = new Output({
108
- satoshis: 1100000000,
109
- script: new Script(
110
- 'OP_2 21 0x038282263212c609d9ea2a6e3e172de238d8c39' +
111
- 'cabd5ac1ca10646e23fd5f51508 21 0x038282263212c609d9ea2a6e3e172de23' +
112
- '8d8c39cabd5ac1ca10646e23fd5f51508 OP_2 OP_CHECKMULTISIG OP_EQUAL'
113
- )
114
- })
115
-
116
- it('toBufferWriter', function () {
117
- output2
118
- .toBufferWriter()
119
- .toBuffer()
120
- .toString('hex')
121
- .should.equal(
122
- '00ab904100000000485215038282263212c609d9ea2a6e3e172de2' +
123
- '38d8c39cabd5ac1ca10646e23fd5f5150815038282263212c609d9ea2a6e3e172d' +
124
- 'e238d8c39cabd5ac1ca10646e23fd5f5150852ae87'
125
- )
126
- })
127
-
128
- it('roundtrips to/from object', function () {
129
- var newOutput = new Output({
130
- satoshis: 50,
131
- script: new Script().add(0)
132
- })
133
- var otherOutput = new Output(newOutput.toObject())
134
- expectEqualOutputs(newOutput, otherOutput)
135
- })
136
-
137
- it('toObject will handle an invalid (null) script', function () {
138
- // block 000000000000000b7e48f88e86ceee3e97b4df7c139f5411d14735c1b3c36791 (livenet)
139
- // transaction index 2
140
- // txid ebc9fa1196a59e192352d76c0f6e73167046b9d37b8302b6bb6968dfd279b767
141
- var transaction = bsv.Transaction()
142
- transaction.fromString(
143
- '01000000019ac03d5ae6a875d970128ef9086cef276a1919684a6988023cc7254691d97e6d010000006b4830450221009d41dc793ba24e65f571473d40b299b6459087cea1509f0d381740b1ac863cb6022039c425906fcaf51b2b84d8092569fb3213de43abaff2180e2a799d4fcb4dd0aa012102d5ede09a8ae667d0f855ef90325e27f6ce35bbe60a1e6e87af7f5b3c652140fdffffffff080100000000000000010101000000000000000202010100000000000000014c0100000000000000034c02010100000000000000014d0100000000000000044dffff010100000000000000014e0100000000000000064effffffff0100000000'
144
- )
145
- var obj = transaction.toObject()
146
- obj.outputs[2].script.should.equal('4c')
147
- obj.outputs[4].script.should.equal('4d')
148
- obj.outputs[6].script.should.equal('4e')
149
- })
150
-
151
- it('#toObject roundtrip will handle an invalid (null) script', function () {
152
- var invalidOutputScript = Buffer.from('0100000000000000014c', 'hex')
153
- var br = new bsv.encoding.BufferReader(invalidOutputScript)
154
- var output = Output.fromBufferReader(br)
155
- var output2 = new Output(output.toObject())
156
- should.equal(output2.script, null)
157
- should.equal(output2._scriptBuffer.toString('hex'), '4c')
158
- })
159
-
160
- it('inspect will work with an invalid (null) script', function () {
161
- var invalidOutputScript = Buffer.from('0100000000000000014c', 'hex')
162
- var br = new bsv.encoding.BufferReader(invalidOutputScript)
163
- var output = Output.fromBufferReader(br)
164
- output.inspect().should.equal('<Output (1 sats) 4c>')
165
- })
166
-
167
- it('roundtrips to/from JSON', function () {
168
- var json = JSON.stringify(output2)
169
- var o3 = new Output(JSON.parse(json))
170
- JSON.stringify(o3).should.equal(json)
171
- })
172
-
173
- it('setScript fails with invalid input', function () {
174
- var out = new Output(output2.toJSON())
175
- out.setScript.bind(out, 45).should.throw('Invalid argument type: script')
176
- })
177
-
178
- it('sets script to null if it is an InvalidBuffer', function () {
179
- var output = new Output({
180
- satoshis: 1000,
181
- script: Buffer.from('4c', 'hex')
182
- })
183
- should.equal(output.script, null)
184
- })
185
- })
@@ -1,91 +0,0 @@
1
- 'use strict'
2
-
3
- var buffer = require('buffer')
4
-
5
- var chai = require('chai')
6
- chai.should()
7
- var bsv = require('../../')
8
- var Script = bsv.Script
9
- var BN = bsv.crypto.BN
10
- var Transaction = bsv.Transaction
11
- var Signature = bsv.crypto.Signature
12
- var sighash = Transaction.sighash
13
-
14
- var vectorsSighash = require('../data/sighash.json')
15
-
16
- describe('sighash', function () {
17
- it('should be able to compute sighash for a coinbase tx', function () {
18
- var txhex = '02000000010000000000000000000000000000000000000000000000000000000000000000ffffffff2e039b1e1304c0737c5b68747470733a2f2f6769746875622e636f6d2f62636578742f01000001c096020000000000ffffffff014a355009000000001976a91448b20e254c0677e760bab964aec16818d6b7134a88ac00000000'
19
- var tx = new Transaction(txhex)
20
- var sighash = Transaction.Sighash.sighash(
21
- tx,
22
- Signature.SIGHASH_ALL,
23
- 0,
24
- Script.empty()
25
- )
26
- sighash.toString('hex').should.equal('6829f7d44dfd4654749b8027f44c9381527199f78ae9b0d58ffc03fdab3c82f1')
27
- })
28
-
29
- it('Should require amount for sigHash ForkId=0', function () {
30
- var vector = ['3eb87070042d16f9469b0080a3c1fe8de0feae345200beef8b1e0d7c62501ae0df899dca1e03000000066a0065525365ffffffffd14a9a335e8babddd89b5d0b6a0f41dd6b18848050a0fc48ce32d892e11817fd030000000863acac00535200527ff62cf3ad30d9064e180eaed5e6303950121a8086b5266b55156e4f7612f2c7ebf223e0020000000100ffffffff6273ca3aceb55931160fa7a3064682b4790ee016b4a5c0c0d101fd449dff88ba01000000055351ac526aa3b8223d0421f25b0400000000026552f92db70500000000075253516a656a53c4a908010000000000b5192901000000000652525251516aa148ca38', 'acab53', 3, -1325231124, 'fbbc83ed610e416d94dcee2bb3bc35dfea8060b8052c59eabd7e998e3e978328']
31
- var txbuf = buffer.Buffer.from(vector[0], 'hex')
32
- var scriptbuf = buffer.Buffer.from(vector[1], 'hex')
33
- var subscript = Script(scriptbuf)
34
- var nin = vector[2]
35
- // This vector happens to set the Chronicle bit as well. Only BIP-143 needs
36
- // the input's amount, so the bit has to be cleared for its omission to be
37
- // an error at all.
38
- var nhashtype = vector[3] & ~Signature.SIGHASH_CHRONICLE
39
- var sighashbuf = buffer.Buffer.from(vector[4], 'hex')
40
- var tx = new Transaction(txbuf)
41
-
42
- // make sure transacion to/from buffer is isomorphic
43
- tx.uncheckedSerialize().should.equal(txbuf.toString('hex'));
44
-
45
- // sighash ought to be correct
46
- (function () {
47
- sighash.sighash(tx, nhashtype, nin, subscript).toString('hex').should.equal(sighashbuf.toString('hex'))
48
- }).should.throw('Invalid Argument')
49
- })
50
-
51
- var zeroBN = BN.Zero
52
- // These vectors were recorded before Chronicle, when bit 0x20 of the sighash
53
- // type carried no meaning and BIP-143 was selected on the forkid bit alone.
54
- // Chronicle gave 0x20 to SIGHASH_CHRONICLE, which selects the original digest
55
- // even when forkid is present, so for a row setting both bits the recorded
56
- // digest is no longer the answer. Those 251 rows are skipped rather than
57
- // restated: editing a copied corpus costs it the outside-check value it was
58
- // imported for, and the behaviour they used to pin is covered properly by
59
- // test/consensus/sv-sighash-vectors.js, whose vectors come from the Chronicle
60
- // node itself and carry both digests for every row.
61
- function usesChronicleDigest (nhashtype) {
62
- var t = nhashtype >>> 0
63
- return (t & Signature.SIGHASH_FORKID) !== 0 && (t & Signature.SIGHASH_CHRONICLE) !== 0
64
- }
65
-
66
- vectorsSighash.forEach(function (vector, i) {
67
- if (i === 0 || !vector[4]) {
68
- // First element is just a row describing the next ones
69
- return
70
- }
71
- if (usesChronicleDigest(vector[3])) {
72
- return
73
- }
74
- it('test vector from bitcoind #' + i + ' (' + vector[4].substring(0, 16) + ')', function () {
75
- var txbuf = buffer.Buffer.from(vector[0], 'hex')
76
- var scriptbuf = buffer.Buffer.from(vector[1], 'hex')
77
- var subscript = Script(scriptbuf)
78
- var nin = vector[2]
79
- var nhashtype = vector[3]
80
- // var nhashtype = vector[3]>>>0;
81
- var sighashbuf = buffer.Buffer.from(vector[4], 'hex')
82
- var tx = new Transaction(txbuf)
83
-
84
- // make sure transacion to/from buffer is isomorphic
85
- tx.uncheckedSerialize().should.equal(txbuf.toString('hex'))
86
-
87
- // sighash ought to be correct
88
- sighash.sighash(tx, nhashtype, nin, subscript, zeroBN).toString('hex').should.equal(sighashbuf.toString('hex'))
89
- })
90
- })
91
- })
@@ -1,127 +0,0 @@
1
- 'use strict'
2
-
3
- require('chai').should()
4
- var expect = require('chai').expect
5
-
6
- var bsv = require('../..')
7
- var Transaction = bsv.Transaction
8
- var TransactionSignature = bsv.Transaction.Signature
9
- var Script = bsv.Script
10
- var PrivateKey = bsv.PrivateKey
11
- var errors = bsv.errors
12
-
13
- describe('TransactionSignature', function () {
14
- var fromAddress = 'mszYqVnqKoQx4jcTdJXxwKAissE3Jbrrc1'
15
- var privateKey = 'cSBnVM4xvxarwGQuAfQFwqDg9k5tErHUHzgWsEfD4zdwUasvqRVY'
16
- var simpleUtxoWith100000Satoshis = {
17
- address: fromAddress,
18
- txId: 'a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458',
19
- outputIndex: 0,
20
- script: Script.buildPublicKeyHashOut(fromAddress).toString(),
21
- satoshis: 100000
22
- }
23
-
24
- var getSignatureFromTransaction = function () {
25
- var transaction = new Transaction()
26
- transaction.from(simpleUtxoWith100000Satoshis)
27
- return transaction.getSignatures(privateKey)[0]
28
- }
29
-
30
- it('can be created without the `new` keyword', function () {
31
- var signature = getSignatureFromTransaction()
32
- var serialized = signature.toObject()
33
- var nonew = TransactionSignature(serialized)
34
- expect(nonew.toObject()).to.deep.equal(serialized)
35
- })
36
-
37
- it('can be retrieved from Transaction#getSignatures', function () {
38
- var signature = getSignatureFromTransaction()
39
- expect(signature instanceof TransactionSignature).to.equal(true)
40
- })
41
-
42
- it('fails when trying to create from invalid arguments', function () {
43
- expect(function () {
44
- return new TransactionSignature()
45
- }).to.throw(errors.InvalidArgument)
46
- expect(function () {
47
- return new TransactionSignature(1)
48
- }).to.throw(errors.InvalidArgument)
49
- expect(function () {
50
- return new TransactionSignature('hello world')
51
- }).to.throw(errors.InvalidArgument)
52
- })
53
- it('returns the same object if called with a TransactionSignature', function () {
54
- var signature = getSignatureFromTransaction()
55
- expect(new TransactionSignature(signature)).to.equal(signature)
56
- })
57
-
58
- it('gets returned by a P2SH multisig output', function () {
59
- var private1 = new PrivateKey('6ce7e97e317d2af16c33db0b9270ec047a91bff3eff8558afb5014afb2bb5976')
60
- var private2 = new PrivateKey('c9b26b0f771a0d2dad88a44de90f05f416b3b385ff1d989343005546a0032890')
61
- var public1 = private1.publicKey
62
- var public2 = private2.publicKey
63
- var utxo = {
64
- txId: '0000000000000000000000000000000000000000000000000000000000000000', // Not relevant
65
- outputIndex: 0,
66
- script: Script.buildMultisigOut([public1, public2], 2).toScriptHashOut(),
67
- satoshis: 100000
68
- }
69
- var transaction = new Transaction().from(utxo, [public1, public2], 2)
70
- var signatures = transaction.getSignatures(private1)
71
- expect(signatures[0] instanceof TransactionSignature).to.equal(true)
72
- signatures = transaction.getSignatures(private2)
73
- expect(signatures[0] instanceof TransactionSignature).to.equal(true)
74
- })
75
-
76
- it('can be aplied to a Transaction with Transaction#addSignature', function () {
77
- var transaction = new Transaction()
78
- transaction.from(simpleUtxoWith100000Satoshis)
79
- var signature = transaction.getSignatures(privateKey)[0]
80
- var addSignature = function () {
81
- return transaction.applySignature(signature)
82
- }
83
- expect(signature instanceof TransactionSignature).to.equal(true)
84
- expect(addSignature).to.not.throw()
85
- })
86
-
87
- describe('serialization', function () {
88
- it('serializes to an object and roundtrips correctly', function () {
89
- var signature = getSignatureFromTransaction()
90
- var serialized = signature.toObject()
91
- expect(new TransactionSignature(serialized).toObject()).to.deep.equal(serialized)
92
- })
93
-
94
- it('can be deserialized with fromObject', function () {
95
- var signature = getSignatureFromTransaction()
96
- var serialized = signature.toObject()
97
- expect(TransactionSignature.fromObject(serialized).toObject()).to.deep.equal(serialized)
98
- })
99
-
100
- it('can deserialize when signature is a buffer', function () {
101
- var signature = getSignatureFromTransaction()
102
- var serialized = signature.toObject()
103
- serialized.signature = Buffer.from(serialized.signature, 'hex')
104
- expect(TransactionSignature.fromObject(serialized).toObject()).to.deep.equal(signature.toObject())
105
- })
106
-
107
- it('can roundtrip to/from json', function () {
108
- var signature = getSignatureFromTransaction()
109
- var serialized = signature.toObject()
110
- var json = JSON.stringify(signature)
111
- expect(TransactionSignature(JSON.parse(json)).toObject()).to.deep.equal(serialized)
112
- expect(TransactionSignature.fromObject(JSON.parse(json)).toObject()).to.deep.equal(serialized)
113
- })
114
-
115
- it('can parse a previously known json string', function () {
116
- var str = JSON.stringify(TransactionSignature(JSON.parse(testJSON)))
117
- expect(JSON.parse(str)).to.deep.equal(JSON.parse(testJSON))
118
- })
119
-
120
- it('can deserialize a previously known object', function () {
121
- expect(TransactionSignature(testObject).toObject()).to.deep.equal(testObject)
122
- })
123
- })
124
-
125
- var testJSON = '{"publicKey":"0223078d2942df62c45621d209fab84ea9a7a23346201b7727b9b45a29c4e76f5e","prevTxId":"a477af6b2667c29670467e4e0728b685ee07b240235771862318e29ddbe58458","outputIndex":0,"inputIndex":0,"signature":"3045022100c728eac064154edba15d4f3e6cbd9be6da3498f80a783ab3391f992b4d9d71ca0220729eff4564dc06aa1d80ab73100540fe5ebb6f280b4a87bc32399f861a7b2563","sigtype":1}'
126
- var testObject = JSON.parse(testJSON)
127
- })