@smartledger/bsv 5.5.0 → 5.5.2
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 +40 -0
- package/README.md +38 -38
- 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/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
- package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
- package/docs/getting-started/INSTALLATION.md +23 -23
- package/docs/getting-started/QUICK_START.md +7 -7
- package/docs/migration/FROM_BSV_1_5_6.md +5 -5
- package/lib/smart_contract/covenant_helpers.js +3 -3
- package/lib/smart_contract/index.js +4 -5
- package/package.json +5 -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
package/test/networks.js
ADDED
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var expect = require('chai').expect
|
|
4
|
+
var should = require('chai').should()
|
|
5
|
+
var bsv = require('..')
|
|
6
|
+
var networks = bsv.Networks
|
|
7
|
+
|
|
8
|
+
describe('Networks', function () {
|
|
9
|
+
var customnet
|
|
10
|
+
|
|
11
|
+
it('should contain all Networks', function () {
|
|
12
|
+
should.exist(networks.livenet)
|
|
13
|
+
should.exist(networks.testnet)
|
|
14
|
+
should.exist(networks.stn)
|
|
15
|
+
should.exist(networks.defaultNetwork)
|
|
16
|
+
})
|
|
17
|
+
|
|
18
|
+
it('should be able to define a custom Network', function () {
|
|
19
|
+
var custom = {
|
|
20
|
+
name: 'customnet',
|
|
21
|
+
alias: 'mynet',
|
|
22
|
+
pubkeyhash: 0x10,
|
|
23
|
+
privatekey: 0x90,
|
|
24
|
+
scripthash: 0x08,
|
|
25
|
+
xpubkey: 0x0278b20e,
|
|
26
|
+
xprivkey: 0x0278ade4,
|
|
27
|
+
networkMagic: 0xe7beb4d4,
|
|
28
|
+
port: 20001,
|
|
29
|
+
dnsSeeds: [
|
|
30
|
+
'localhost',
|
|
31
|
+
'mynet.localhost'
|
|
32
|
+
]
|
|
33
|
+
}
|
|
34
|
+
networks.add(custom)
|
|
35
|
+
customnet = networks.get('customnet')
|
|
36
|
+
for (var key in custom) {
|
|
37
|
+
if (key !== 'networkMagic') {
|
|
38
|
+
customnet[key].should.equal(custom[key])
|
|
39
|
+
} else {
|
|
40
|
+
var expected = Buffer.from('e7beb4d4', 'hex')
|
|
41
|
+
customnet[key].should.deep.equal(expected)
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
})
|
|
45
|
+
|
|
46
|
+
it('should have network magic for testnet', function () {
|
|
47
|
+
var testnet = networks.get('testnet')
|
|
48
|
+
Buffer.isBuffer(testnet.networkMagic).should.equal(true)
|
|
49
|
+
})
|
|
50
|
+
|
|
51
|
+
it('should have network magic for stn', function () {
|
|
52
|
+
var stn = networks.get('stn')
|
|
53
|
+
Buffer.isBuffer(stn.networkMagic).should.equal(true)
|
|
54
|
+
})
|
|
55
|
+
|
|
56
|
+
it('can remove a custom network', function () {
|
|
57
|
+
networks.remove(customnet)
|
|
58
|
+
var net = networks.get('customnet')
|
|
59
|
+
should.equal(net, undefined)
|
|
60
|
+
})
|
|
61
|
+
|
|
62
|
+
it('should not set a network map for an undefined value', function () {
|
|
63
|
+
var custom = {
|
|
64
|
+
name: 'somenet',
|
|
65
|
+
pubkeyhash: 0x13,
|
|
66
|
+
privatekey: 0x93,
|
|
67
|
+
scripthash: 0x11,
|
|
68
|
+
xpubkey: 0x0278b20f,
|
|
69
|
+
xprivkey: 0x0278ade5,
|
|
70
|
+
networkMagic: 0xe7beb4d5,
|
|
71
|
+
port: 20008,
|
|
72
|
+
dnsSeeds: [
|
|
73
|
+
'somenet.localhost'
|
|
74
|
+
]
|
|
75
|
+
}
|
|
76
|
+
networks.add(custom)
|
|
77
|
+
var network = networks.get(undefined)
|
|
78
|
+
should.not.exist(network)
|
|
79
|
+
var somenet = networks.get('somenet')
|
|
80
|
+
should.exist(somenet)
|
|
81
|
+
somenet.name.should.equal('somenet')
|
|
82
|
+
networks.remove(somenet)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
var constants = ['name', 'alias', 'pubkeyhash', 'scripthash', 'xpubkey', 'xprivkey']
|
|
86
|
+
|
|
87
|
+
constants.forEach(function (key) {
|
|
88
|
+
it('should have constant ' + key + ' for livenet, testnet and stn', function () {
|
|
89
|
+
networks.testnet.hasOwnProperty(key).should.equal(true)
|
|
90
|
+
networks.livenet.hasOwnProperty(key).should.equal(true)
|
|
91
|
+
networks.stn.hasOwnProperty(key).should.equal(true)
|
|
92
|
+
})
|
|
93
|
+
})
|
|
94
|
+
|
|
95
|
+
it('tests only for the specified key', function () {
|
|
96
|
+
expect(networks.get(0x6f, 'pubkeyhash')).to.equal(networks.testnet)
|
|
97
|
+
expect(networks.get(0x6f, 'privatekey')).to.equal(undefined)
|
|
98
|
+
})
|
|
99
|
+
|
|
100
|
+
it('can test for multiple keys', function () {
|
|
101
|
+
expect(networks.get(0x6f, ['pubkeyhash', 'scripthash'])).to.equal(networks.testnet)
|
|
102
|
+
expect(networks.get(0xc4, ['pubkeyhash', 'scripthash'])).to.equal(networks.testnet)
|
|
103
|
+
expect(networks.get(0x6f, ['privatekey', 'port'])).to.equal(undefined)
|
|
104
|
+
})
|
|
105
|
+
|
|
106
|
+
it('should have regtest network', function () {
|
|
107
|
+
expect(networks.get('regtest').name).to.equal('regtest')
|
|
108
|
+
})
|
|
109
|
+
|
|
110
|
+
it('should have testnet network', function () {
|
|
111
|
+
expect(networks.get('testnet').name).to.equal('testnet')
|
|
112
|
+
})
|
|
113
|
+
|
|
114
|
+
it('should have stn network', function () {
|
|
115
|
+
expect(networks.get('stn').name).to.equal('stn')
|
|
116
|
+
})
|
|
117
|
+
|
|
118
|
+
it('should have livenet network', function () {
|
|
119
|
+
expect(networks.get('livenet').name).to.equal('livenet')
|
|
120
|
+
})
|
|
121
|
+
|
|
122
|
+
it('should have bchtest cashAddrPrefix', function () {
|
|
123
|
+
expect(networks.get('testnet').cashAddrPrefix).to.equal('bchtest')
|
|
124
|
+
})
|
|
125
|
+
|
|
126
|
+
it('should have bchreg cashAddrPrefix', function () {
|
|
127
|
+
expect(networks.get('regtest').cashAddrPrefix).to.equal('bchreg')
|
|
128
|
+
})
|
|
129
|
+
|
|
130
|
+
it('should have bchreg cashAddrPrefix after enableRegtest is called', function () {
|
|
131
|
+
var network = networks.get('testnet')
|
|
132
|
+
networks.enableRegtest()
|
|
133
|
+
expect(network.cashAddrPrefix).to.equal('bchreg')
|
|
134
|
+
})
|
|
135
|
+
|
|
136
|
+
it('should have bchtest cashAddrPrefix after disableRegtest is called', function () {
|
|
137
|
+
var network = networks.get('testnet')
|
|
138
|
+
networks.disableRegtest()
|
|
139
|
+
expect(network.cashAddrPrefix).to.equal('bchtest')
|
|
140
|
+
})
|
|
141
|
+
it('should have bsvstn cashAddrPrefix after enableStn is called', function () {
|
|
142
|
+
var network = networks.get('testnet')
|
|
143
|
+
networks.enableStn()
|
|
144
|
+
expect(network.cashAddrPrefix).to.equal('bsvstn')
|
|
145
|
+
})
|
|
146
|
+
|
|
147
|
+
it('should have bchtest cashAddrPrefix after disableStn is called', function () {
|
|
148
|
+
var network = networks.get('testnet')
|
|
149
|
+
networks.disableStn()
|
|
150
|
+
expect(network.cashAddrPrefix).to.equal('bchtest')
|
|
151
|
+
})
|
|
152
|
+
|
|
153
|
+
it('converts to string using the "name" property', function () {
|
|
154
|
+
networks.livenet.toString().should.equal('livenet')
|
|
155
|
+
})
|
|
156
|
+
|
|
157
|
+
it('network object should be immutable', function () {
|
|
158
|
+
expect(networks.testnet.name).to.equal('testnet')
|
|
159
|
+
var fn = function () { networks.testnet.name = 'livenet' }
|
|
160
|
+
expect(fn).to.throw(TypeError)
|
|
161
|
+
})
|
|
162
|
+
})
|
package/test/opcode.js
ADDED
|
@@ -0,0 +1,161 @@
|
|
|
1
|
+
'use strict'
|
|
2
|
+
|
|
3
|
+
var chai = require('chai')
|
|
4
|
+
var should = chai.should()
|
|
5
|
+
var expect = chai.expect
|
|
6
|
+
var bsv = require('..')
|
|
7
|
+
var Opcode = bsv.Opcode
|
|
8
|
+
|
|
9
|
+
describe('Opcode', function () {
|
|
10
|
+
it('should create a new Opcode', function () {
|
|
11
|
+
var opcode = new Opcode(5)
|
|
12
|
+
should.exist(opcode)
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
it('should convert to a string with this handy syntax', function () {
|
|
16
|
+
Opcode(0).toString().should.equal('OP_0')
|
|
17
|
+
Opcode(96).toString().should.equal('OP_16')
|
|
18
|
+
Opcode(97).toString().should.equal('OP_NOP')
|
|
19
|
+
})
|
|
20
|
+
|
|
21
|
+
it('should convert to a number with this handy syntax', function () {
|
|
22
|
+
Opcode('OP_0').toNumber().should.equal(0)
|
|
23
|
+
Opcode('OP_16').toNumber().should.equal(96)
|
|
24
|
+
Opcode('OP_NOP').toNumber().should.equal(97)
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
describe('#fromNumber', function () {
|
|
28
|
+
it('should work for 0', function () {
|
|
29
|
+
Opcode.fromNumber(0).num.should.equal(0)
|
|
30
|
+
})
|
|
31
|
+
it('should fail for non-number', function () {
|
|
32
|
+
Opcode.fromNumber.bind(null, 'a string').should.throw('Invalid Argument')
|
|
33
|
+
})
|
|
34
|
+
})
|
|
35
|
+
|
|
36
|
+
describe('#set', function () {
|
|
37
|
+
it('should work for object', function () {
|
|
38
|
+
Opcode(42).num.should.equal(42)
|
|
39
|
+
})
|
|
40
|
+
it('should fail for empty-object', function () {
|
|
41
|
+
expect(function () {
|
|
42
|
+
Opcode()
|
|
43
|
+
}).to.throw(TypeError)
|
|
44
|
+
})
|
|
45
|
+
})
|
|
46
|
+
|
|
47
|
+
describe('#toNumber', function () {
|
|
48
|
+
it('should work for 0', function () {
|
|
49
|
+
Opcode.fromNumber(0).toNumber().should.equal(0)
|
|
50
|
+
})
|
|
51
|
+
})
|
|
52
|
+
|
|
53
|
+
describe('#buffer', function () {
|
|
54
|
+
it('should correctly input/output a buffer', function () {
|
|
55
|
+
var buf = Buffer.from('a6', 'hex')
|
|
56
|
+
Opcode.fromBuffer(buf).toBuffer().should.deep.equal(buf)
|
|
57
|
+
})
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
describe('#fromString', function () {
|
|
61
|
+
it('should work for OP_0', function () {
|
|
62
|
+
Opcode.fromString('OP_0').num.should.equal(0)
|
|
63
|
+
})
|
|
64
|
+
it('should fail for invalid string', function () {
|
|
65
|
+
Opcode.fromString.bind(null, 'OP_SATOSHI').should.throw('Invalid opcodestr')
|
|
66
|
+
Opcode.fromString.bind(null, 'BANANA').should.throw('Invalid opcodestr')
|
|
67
|
+
})
|
|
68
|
+
it('should fail for non-string', function () {
|
|
69
|
+
Opcode.fromString.bind(null, 123).should.throw('Invalid Argument')
|
|
70
|
+
})
|
|
71
|
+
})
|
|
72
|
+
|
|
73
|
+
describe('#toString', function () {
|
|
74
|
+
it('should work for OP_0', function () {
|
|
75
|
+
Opcode.fromString('OP_0').toString().should.equal('OP_0')
|
|
76
|
+
})
|
|
77
|
+
|
|
78
|
+
it('should not work for non-opcode', function () {
|
|
79
|
+
expect(function () {
|
|
80
|
+
Opcode('OP_NOTACODE').toString()
|
|
81
|
+
}).to.throw('Opcode does not have a string representation')
|
|
82
|
+
})
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
describe('@map', function () {
|
|
86
|
+
it('should have a map containing 121 elements', function () {
|
|
87
|
+
Object.keys(Opcode.map).length.should.equal(121)
|
|
88
|
+
})
|
|
89
|
+
})
|
|
90
|
+
|
|
91
|
+
describe('@reverseMap', function () {
|
|
92
|
+
it('should exist and have op 185', function () {
|
|
93
|
+
should.exist(Opcode.reverseMap)
|
|
94
|
+
Opcode.reverseMap[185].should.equal('OP_NOP7')
|
|
95
|
+
})
|
|
96
|
+
})
|
|
97
|
+
var smallints = [
|
|
98
|
+
Opcode('OP_0'),
|
|
99
|
+
Opcode('OP_1'),
|
|
100
|
+
Opcode('OP_2'),
|
|
101
|
+
Opcode('OP_3'),
|
|
102
|
+
Opcode('OP_4'),
|
|
103
|
+
Opcode('OP_5'),
|
|
104
|
+
Opcode('OP_6'),
|
|
105
|
+
Opcode('OP_7'),
|
|
106
|
+
Opcode('OP_8'),
|
|
107
|
+
Opcode('OP_9'),
|
|
108
|
+
Opcode('OP_10'),
|
|
109
|
+
Opcode('OP_11'),
|
|
110
|
+
Opcode('OP_12'),
|
|
111
|
+
Opcode('OP_13'),
|
|
112
|
+
Opcode('OP_14'),
|
|
113
|
+
Opcode('OP_15'),
|
|
114
|
+
Opcode('OP_16')
|
|
115
|
+
]
|
|
116
|
+
|
|
117
|
+
describe('@smallInt', function () {
|
|
118
|
+
var testSmallInt = function (n, op) {
|
|
119
|
+
Opcode.smallInt(n).toString().should.equal(op.toString())
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
for (var i = 0; i < smallints.length; i++) {
|
|
123
|
+
var op = smallints[i]
|
|
124
|
+
it('should work for small int ' + op, testSmallInt.bind(null, i, op))
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
it('with not number', function () {
|
|
128
|
+
Opcode.smallInt.bind(null, '2').should.throw('Invalid Argument')
|
|
129
|
+
})
|
|
130
|
+
|
|
131
|
+
it('with n equal -1', function () {
|
|
132
|
+
Opcode.smallInt.bind(null, -1).should.throw('Invalid Argument')
|
|
133
|
+
})
|
|
134
|
+
|
|
135
|
+
it('with n equal 17', function () {
|
|
136
|
+
Opcode.smallInt.bind(null, 17).should.throw('Invalid Argument')
|
|
137
|
+
})
|
|
138
|
+
})
|
|
139
|
+
describe('@isSmallIntOp', function () {
|
|
140
|
+
var testIsSmallInt = function (op) {
|
|
141
|
+
Opcode.isSmallIntOp(op).should.equal(true)
|
|
142
|
+
}
|
|
143
|
+
for (var i = 0; i < smallints.length; i++) {
|
|
144
|
+
var op = smallints[i]
|
|
145
|
+
it('should work for small int ' + op, testIsSmallInt.bind(null, op))
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
it('should work for non-small ints', function () {
|
|
149
|
+
Opcode.isSmallIntOp(Opcode('OP_RETURN')).should.equal(false)
|
|
150
|
+
Opcode.isSmallIntOp(Opcode('OP_CHECKSIG')).should.equal(false)
|
|
151
|
+
Opcode.isSmallIntOp(Opcode('OP_IF')).should.equal(false)
|
|
152
|
+
Opcode.isSmallIntOp(Opcode('OP_NOP')).should.equal(false)
|
|
153
|
+
})
|
|
154
|
+
})
|
|
155
|
+
|
|
156
|
+
describe('#inspect', function () {
|
|
157
|
+
it('should output opcode by name, hex, and decimal', function () {
|
|
158
|
+
Opcode.fromString('OP_NOP').inspect().should.equal('<Opcode: OP_NOP, hex: 61, decimal: 97>')
|
|
159
|
+
})
|
|
160
|
+
})
|
|
161
|
+
})
|