@smartledger/bsv 5.5.0 → 5.5.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.
- package/.mocharc.json +5 -0
- package/CHANGELOG.md +20 -0
- package/bsv-covenant.min.js +2 -2
- package/bsv-gdaf.min.js +2 -2
- package/bsv-ltp.min.js +2 -2
- package/bsv-smartcontract.min.js +2 -2
- package/bsv.bundle.js +2 -2
- package/bsv.min.js +2 -2
- package/lib/smart_contract/covenant_helpers.js +3 -3
- package/lib/smart_contract/index.js +4 -5
- package/package.json +3 -1
- package/test/address.js +629 -0
- package/test/block/block.js +239 -0
- package/test/block/blockheader.js +270 -0
- package/test/block/merkleblock.js +207 -0
- package/test/cli/smoke.js +261 -0
- package/test/credentials-test.js +329 -0
- package/test/crypto/bn.js +168 -0
- package/test/crypto/ecdsa.js +328 -0
- package/test/crypto/elliptic-fixed.js +61 -0
- package/test/crypto/hash.browser.js +121 -0
- package/test/crypto/hash.js +122 -0
- package/test/crypto/point.js +193 -0
- package/test/crypto/random.js +32 -0
- package/test/crypto/security.js +127 -0
- package/test/crypto/shamir.js +169 -0
- package/test/crypto/signature.js +318 -0
- package/test/data/bip69.json +215 -0
- package/test/data/bitcoind/base58_keys_invalid.json +152 -0
- package/test/data/bitcoind/base58_keys_valid.json +452 -0
- package/test/data/bitcoind/blocks.json +27 -0
- package/test/data/bitcoind/script_tests.json +2244 -0
- package/test/data/bitcoind/sig_canonical.json +7 -0
- package/test/data/bitcoind/sig_noncanonical.json +22 -0
- package/test/data/bitcoind/tx_invalid.json +177 -0
- package/test/data/bitcoind/tx_valid.json +224 -0
- package/test/data/blk86756-testnet.dat +0 -0
- package/test/data/blk86756-testnet.js +12 -0
- package/test/data/blk86756-testnet.json +684 -0
- package/test/data/ecdsa.json +230 -0
- package/test/data/merkleblocks.js +486 -0
- package/test/data/messages.json +22 -0
- package/test/data/sighash.json +1004 -0
- package/test/data/tx_creation.json +85 -0
- package/test/ecies/bitcore-ecies.js +170 -0
- package/test/ecies/electrum-ecies.js +206 -0
- package/test/encoding/base58.js +131 -0
- package/test/encoding/base58check.js +136 -0
- package/test/encoding/bufferreader.js +328 -0
- package/test/encoding/bufferwriter.js +160 -0
- package/test/encoding/varint.js +104 -0
- package/test/gdaf/canonicalize.js +140 -0
- package/test/hdkeys.js +365 -0
- package/test/hdprivatekey.js +330 -0
- package/test/hdpublickey.js +293 -0
- package/test/index.js +16 -0
- package/test/ltp/right.js +198 -0
- package/test/message/message.js +190 -0
- package/test/mnemonic/data/fixtures.json +300 -0
- package/test/mnemonic/mnemonic.js +245 -0
- package/test/mnemonic/mocha.opts +1 -0
- package/test/mnemonic/pbkdf2.test.js +43 -0
- package/test/networks.js +162 -0
- package/test/opcode.js +161 -0
- package/test/privatekey.js +430 -0
- package/test/publickey.js +411 -0
- package/test/script/genesis_limits.js +80 -0
- package/test/script/interpreter.js +723 -0
- package/test/script/script.js +1256 -0
- package/test/script/string_ops.js +72 -0
- package/test/smart_contract/covenants.js +247 -0
- package/test/smart_contract/dsl_debugger.js +103 -0
- package/test/smart_contract/token_generalized.js +187 -0
- package/test/transaction/deserialize.js +33 -0
- package/test/transaction/input/input.js +92 -0
- package/test/transaction/input/multisig.js +174 -0
- package/test/transaction/input/multisigscripthash.js +111 -0
- package/test/transaction/input/publickey.js +68 -0
- package/test/transaction/input/publickeyhash.js +59 -0
- package/test/transaction/output.js +185 -0
- package/test/transaction/sighash.js +71 -0
- package/test/transaction/signature.js +127 -0
- package/test/transaction/transaction.js +1299 -0
- package/test/transaction/unspentoutput.js +92 -0
- package/test/util/js.js +76 -0
- package/test/util/preconditions.js +79 -0
- package/test/vcjwt/interop.js +126 -0
|
@@ -0,0 +1,71 @@
|
|
|
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
|
+
var nhashtype = vector[3]
|
|
36
|
+
var sighashbuf = buffer.Buffer.from(vector[4], 'hex')
|
|
37
|
+
var tx = new Transaction(txbuf)
|
|
38
|
+
|
|
39
|
+
// make sure transacion to/from buffer is isomorphic
|
|
40
|
+
tx.uncheckedSerialize().should.equal(txbuf.toString('hex'));
|
|
41
|
+
|
|
42
|
+
// sighash ought to be correct
|
|
43
|
+
(function () {
|
|
44
|
+
sighash.sighash(tx, nhashtype, nin, subscript).toString('hex').should.equal(sighashbuf.toString('hex'))
|
|
45
|
+
}).should.throw('Invalid Argument')
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
var zeroBN = BN.Zero
|
|
49
|
+
vectorsSighash.forEach(function (vector, i) {
|
|
50
|
+
if (i === 0 || !vector[4]) {
|
|
51
|
+
// First element is just a row describing the next ones
|
|
52
|
+
return
|
|
53
|
+
}
|
|
54
|
+
it('test vector from bitcoind #' + i + ' (' + vector[4].substring(0, 16) + ')', function () {
|
|
55
|
+
var txbuf = buffer.Buffer.from(vector[0], 'hex')
|
|
56
|
+
var scriptbuf = buffer.Buffer.from(vector[1], 'hex')
|
|
57
|
+
var subscript = Script(scriptbuf)
|
|
58
|
+
var nin = vector[2]
|
|
59
|
+
var nhashtype = vector[3]
|
|
60
|
+
// var nhashtype = vector[3]>>>0;
|
|
61
|
+
var sighashbuf = buffer.Buffer.from(vector[4], 'hex')
|
|
62
|
+
var tx = new Transaction(txbuf)
|
|
63
|
+
|
|
64
|
+
// make sure transacion to/from buffer is isomorphic
|
|
65
|
+
tx.uncheckedSerialize().should.equal(txbuf.toString('hex'))
|
|
66
|
+
|
|
67
|
+
// sighash ought to be correct
|
|
68
|
+
sighash.sighash(tx, nhashtype, nin, subscript, zeroBN).toString('hex').should.equal(sighashbuf.toString('hex'))
|
|
69
|
+
})
|
|
70
|
+
})
|
|
71
|
+
})
|
|
@@ -0,0 +1,127 @@
|
|
|
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
|
+
})
|