@opcat-labs/opcat 1.0.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.
- package/.mocharc.yaml +3 -0
- package/index.d.ts +1541 -0
- package/index.js +74 -0
- package/lib/address.js +478 -0
- package/lib/block/block.js +277 -0
- package/lib/block/blockheader.js +295 -0
- package/lib/block/index.js +4 -0
- package/lib/block/merkleblock.js +323 -0
- package/lib/bn.js +3423 -0
- package/lib/crypto/bn.js +278 -0
- package/lib/crypto/ecdsa.js +339 -0
- package/lib/crypto/hash.browser.js +171 -0
- package/lib/crypto/hash.js +2 -0
- package/lib/crypto/hash.node.js +171 -0
- package/lib/crypto/point.js +221 -0
- package/lib/crypto/random.browser.js +28 -0
- package/lib/crypto/random.js +2 -0
- package/lib/crypto/random.node.js +11 -0
- package/lib/crypto/signature.js +325 -0
- package/lib/encoding/base58.js +111 -0
- package/lib/encoding/base58check.js +121 -0
- package/lib/encoding/bufferreader.js +212 -0
- package/lib/encoding/bufferwriter.js +140 -0
- package/lib/encoding/decode-asm.js +24 -0
- package/lib/encoding/decode-hex.js +32 -0
- package/lib/encoding/decode-script-chunks.js +43 -0
- package/lib/encoding/encode-hex.js +284 -0
- package/lib/encoding/is-hex.js +7 -0
- package/lib/encoding/varint.js +75 -0
- package/lib/errors/index.js +54 -0
- package/lib/errors/spec.js +314 -0
- package/lib/hash-cache.js +50 -0
- package/lib/hdprivatekey.js +678 -0
- package/lib/hdpublickey.js +525 -0
- package/lib/message/message.js +191 -0
- package/lib/mnemonic/mnemonic.js +303 -0
- package/lib/mnemonic/pbkdf2.browser.js +68 -0
- package/lib/mnemonic/pbkdf2.js +2 -0
- package/lib/mnemonic/pbkdf2.node.js +68 -0
- package/lib/mnemonic/words/chinese.js +2054 -0
- package/lib/mnemonic/words/english.js +2054 -0
- package/lib/mnemonic/words/french.js +2054 -0
- package/lib/mnemonic/words/index.js +8 -0
- package/lib/mnemonic/words/italian.js +2054 -0
- package/lib/mnemonic/words/japanese.js +2054 -0
- package/lib/mnemonic/words/spanish.js +2054 -0
- package/lib/networks.js +379 -0
- package/lib/opcode.js +255 -0
- package/lib/privatekey.js +374 -0
- package/lib/publickey.js +386 -0
- package/lib/script/index.js +5 -0
- package/lib/script/interpreter.js +1834 -0
- package/lib/script/script.js +1074 -0
- package/lib/script/stack.js +109 -0
- package/lib/script/write-i32-le.js +17 -0
- package/lib/script/write-push-data.js +35 -0
- package/lib/script/write-u16-le.js +12 -0
- package/lib/script/write-u32-le.js +16 -0
- package/lib/script/write-u64-le.js +24 -0
- package/lib/script/write-u8-le.js +8 -0
- package/lib/script/write-varint.js +46 -0
- package/lib/transaction/index.js +7 -0
- package/lib/transaction/input/index.js +5 -0
- package/lib/transaction/input/input.js +354 -0
- package/lib/transaction/input/multisig.js +242 -0
- package/lib/transaction/input/publickey.js +100 -0
- package/lib/transaction/input/publickeyhash.js +118 -0
- package/lib/transaction/output.js +231 -0
- package/lib/transaction/sighash.js +167 -0
- package/lib/transaction/signature.js +97 -0
- package/lib/transaction/transaction.js +1639 -0
- package/lib/transaction/unspentoutput.js +113 -0
- package/lib/util/_.js +47 -0
- package/lib/util/js.js +90 -0
- package/lib/util/preconditions.js +33 -0
- package/package.json +26 -0
- package/test/address.js +509 -0
- package/test/block/block.js +251 -0
- package/test/block/blockheader.js +275 -0
- package/test/block/merklebloack.js +211 -0
- package/test/crypto/bn.js +177 -0
- package/test/crypto/ecdsa.js +391 -0
- package/test/crypto/hash.browser.js +135 -0
- package/test/crypto/hash.js +136 -0
- package/test/crypto/point.js +224 -0
- package/test/crypto/random.js +32 -0
- package/test/crypto/signature.js +409 -0
- package/test/data/bip69.json +215 -0
- package/test/data/bitcoind/base58_keys_invalid.json +52 -0
- package/test/data/bitcoind/base58_keys_valid.json +335 -0
- package/test/data/bitcoind/blocks.json +22 -0
- package/test/data/bitcoind/script_tests.json +3822 -0
- package/test/data/bitcoind/sig_canonical.json +7 -0
- package/test/data/bitcoind/sig_noncanonical.json +36 -0
- package/test/data/bitcoind/tx_invalid.json +445 -0
- package/test/data/bitcoind/tx_valid.json +44 -0
- package/test/data/blk86756-testnet.dat +0 -0
- package/test/data/blk86756-testnet.js +14 -0
- package/test/data/blk86756-testnet.json +684 -0
- package/test/data/block.hex +1 -0
- package/test/data/ecdsa.json +230 -0
- package/test/data/merkleblocks.js +488 -0
- package/test/data/messages.json +22 -0
- package/test/data/sighash.json +12 -0
- package/test/data/tx_creation.json +95 -0
- package/test/encoding/base58.js +131 -0
- package/test/encoding/base58check.js +136 -0
- package/test/encoding/bufferreader.js +337 -0
- package/test/encoding/bufferwriter.js +172 -0
- package/test/encoding/varint.js +104 -0
- package/test/hashCache.js +67 -0
- package/test/hdkeys.js +445 -0
- package/test/hdprivatekey.js +332 -0
- package/test/hdpublickey.js +304 -0
- package/test/index.js +16 -0
- package/test/message/message.js +204 -0
- package/test/mnemonic/data/fixtures.json +300 -0
- package/test/mnemonic/mnemonic.js +259 -0
- package/test/mnemonic/mocha.opts +1 -0
- package/test/mnemonic/pbkdf2.test.js +59 -0
- package/test/networks.js +159 -0
- package/test/opcode.js +161 -0
- package/test/privatekey.js +439 -0
- package/test/publickey.js +554 -0
- package/test/script/interpreter.js +734 -0
- package/test/script/script.js +1437 -0
- package/test/transaction/deserialize.js +34 -0
- package/test/transaction/input/input.js +90 -0
- package/test/transaction/input/multisig.js +90 -0
- package/test/transaction/input/publickey.js +68 -0
- package/test/transaction/input/publickeyhash.js +51 -0
- package/test/transaction/output.js +185 -0
- package/test/transaction/sighash.js +65 -0
- package/test/transaction/signature.js +114 -0
- package/test/transaction/transaction.js +1109 -0
- package/test/transaction/unspentoutput.js +110 -0
- package/test/util/js.js +76 -0
- package/test/util/preconditions.js +79 -0
|
@@ -0,0 +1,314 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var docsURL = 'https://docs.moneybutton.com/';
|
|
4
|
+
|
|
5
|
+
module.exports = [
|
|
6
|
+
{
|
|
7
|
+
name: 'InvalidB58Char',
|
|
8
|
+
message: 'Invalid Base58 character: {0} in {1}',
|
|
9
|
+
},
|
|
10
|
+
{
|
|
11
|
+
name: 'InvalidB58Checksum',
|
|
12
|
+
message: 'Invalid Base58 checksum for {0}',
|
|
13
|
+
},
|
|
14
|
+
{
|
|
15
|
+
name: 'InvalidNetwork',
|
|
16
|
+
message: 'Invalid version for network: got {0}',
|
|
17
|
+
},
|
|
18
|
+
{
|
|
19
|
+
name: 'InvalidState',
|
|
20
|
+
message: 'Invalid state: {0}',
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
name: 'NotImplemented',
|
|
24
|
+
message: 'Function {0} was not implemented yet',
|
|
25
|
+
},
|
|
26
|
+
{
|
|
27
|
+
name: 'InvalidNetworkArgument',
|
|
28
|
+
message: 'Invalid network: must be "livenet" or "testnet", got {0}',
|
|
29
|
+
},
|
|
30
|
+
{
|
|
31
|
+
name: 'InvalidArgument',
|
|
32
|
+
message: function () {
|
|
33
|
+
return (
|
|
34
|
+
'Invalid Argument' +
|
|
35
|
+
(arguments[0] ? ': ' + arguments[0] : '') +
|
|
36
|
+
(arguments[1] ? ' Documentation: ' + docsURL + arguments[1] : '')
|
|
37
|
+
);
|
|
38
|
+
},
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
name: 'AbstractMethodInvoked',
|
|
42
|
+
message: 'Abstract Method Invocation: {0}',
|
|
43
|
+
},
|
|
44
|
+
{
|
|
45
|
+
name: 'InvalidArgumentType',
|
|
46
|
+
message: function () {
|
|
47
|
+
return (
|
|
48
|
+
'Invalid Argument for ' +
|
|
49
|
+
arguments[2] +
|
|
50
|
+
', expected ' +
|
|
51
|
+
arguments[1] +
|
|
52
|
+
' but got ' +
|
|
53
|
+
typeof arguments[0]
|
|
54
|
+
);
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
{
|
|
58
|
+
name: 'Unit',
|
|
59
|
+
message: 'Internal Error on Unit {0}',
|
|
60
|
+
errors: [
|
|
61
|
+
{
|
|
62
|
+
name: 'UnknownCode',
|
|
63
|
+
message: 'Unrecognized unit code: {0}',
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
name: 'InvalidRate',
|
|
67
|
+
message: 'Invalid exchange rate: {0}',
|
|
68
|
+
},
|
|
69
|
+
],
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
name: 'MerkleBlock',
|
|
73
|
+
message: 'Internal Error on MerkleBlock {0}',
|
|
74
|
+
errors: [
|
|
75
|
+
{
|
|
76
|
+
name: 'InvalidMerkleTree',
|
|
77
|
+
message: 'This MerkleBlock contain an invalid Merkle Tree',
|
|
78
|
+
},
|
|
79
|
+
],
|
|
80
|
+
},
|
|
81
|
+
{
|
|
82
|
+
name: 'Transaction',
|
|
83
|
+
message: 'Internal Error on Transaction {0}',
|
|
84
|
+
errors: [
|
|
85
|
+
{
|
|
86
|
+
name: 'Input',
|
|
87
|
+
message: 'Internal Error on Input {0}',
|
|
88
|
+
errors: [
|
|
89
|
+
{
|
|
90
|
+
name: 'MissingScript',
|
|
91
|
+
message: 'Need a script to create an input',
|
|
92
|
+
},
|
|
93
|
+
{
|
|
94
|
+
name: 'UnsupportedScript',
|
|
95
|
+
message: 'Unsupported input script type: {0}',
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
name: 'MissingPreviousOutput',
|
|
99
|
+
message: 'No previous output information.',
|
|
100
|
+
},
|
|
101
|
+
{
|
|
102
|
+
name: 'MissingInput',
|
|
103
|
+
message: 'Invalid inputIndex.',
|
|
104
|
+
},
|
|
105
|
+
{
|
|
106
|
+
name: 'InvalidParams',
|
|
107
|
+
message: 'Invalid params: {0}.',
|
|
108
|
+
},
|
|
109
|
+
],
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
name: 'NeedMoreInfo',
|
|
113
|
+
message: '{0}',
|
|
114
|
+
},
|
|
115
|
+
{
|
|
116
|
+
name: 'InvalidSorting',
|
|
117
|
+
message:
|
|
118
|
+
'The sorting function provided did not return the change output as one of the array elements',
|
|
119
|
+
},
|
|
120
|
+
{
|
|
121
|
+
name: 'InvalidOutputAmountSum',
|
|
122
|
+
message: '{0}',
|
|
123
|
+
},
|
|
124
|
+
{
|
|
125
|
+
name: 'MissingSignatures',
|
|
126
|
+
message: 'Some inputs have not been fully signed',
|
|
127
|
+
},
|
|
128
|
+
{
|
|
129
|
+
name: 'InvalidIndex',
|
|
130
|
+
message: 'Invalid index: {0} is not between 0, {1}',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
name: 'UnableToVerifySignature',
|
|
134
|
+
message: 'Unable to verify signature: {0}',
|
|
135
|
+
},
|
|
136
|
+
{
|
|
137
|
+
name: 'DustOutputs',
|
|
138
|
+
message: 'Dust amount detected in one output',
|
|
139
|
+
},
|
|
140
|
+
{
|
|
141
|
+
name: 'MissingOutput',
|
|
142
|
+
message: 'Output not found',
|
|
143
|
+
},
|
|
144
|
+
{
|
|
145
|
+
name: 'InvalidSatoshis',
|
|
146
|
+
message: 'Output satoshis are invalid',
|
|
147
|
+
},
|
|
148
|
+
{
|
|
149
|
+
name: 'FeeError',
|
|
150
|
+
message: 'Internal Error on Fee {0}',
|
|
151
|
+
errors: [
|
|
152
|
+
{
|
|
153
|
+
name: 'TooSmall',
|
|
154
|
+
message: 'Fee is too small: {0}',
|
|
155
|
+
},
|
|
156
|
+
{
|
|
157
|
+
name: 'TooLarge',
|
|
158
|
+
message: 'Fee is too large: {0}',
|
|
159
|
+
},
|
|
160
|
+
{
|
|
161
|
+
name: 'Different',
|
|
162
|
+
message: 'Unspent value is different from specified fee: {0}',
|
|
163
|
+
},
|
|
164
|
+
],
|
|
165
|
+
},
|
|
166
|
+
{
|
|
167
|
+
name: 'ChangeAddressMissing',
|
|
168
|
+
message: 'Change address is missing',
|
|
169
|
+
},
|
|
170
|
+
{
|
|
171
|
+
name: 'BlockHeightTooHigh',
|
|
172
|
+
message: 'Block Height can be at most 2^32 -1',
|
|
173
|
+
},
|
|
174
|
+
{
|
|
175
|
+
name: 'NLockTimeOutOfRange',
|
|
176
|
+
message: 'Block Height can only be between 0 and 499 999 999',
|
|
177
|
+
},
|
|
178
|
+
{
|
|
179
|
+
name: 'LockTimeTooEarly',
|
|
180
|
+
message: "Lock Time can't be earlier than UNIX date 500 000 000",
|
|
181
|
+
},
|
|
182
|
+
{
|
|
183
|
+
name: 'TransactionAlreadySealed',
|
|
184
|
+
message: 'Cannot update sealed transaction',
|
|
185
|
+
},
|
|
186
|
+
],
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
name: 'Script',
|
|
190
|
+
message: 'Internal Error on Script {0}',
|
|
191
|
+
errors: [
|
|
192
|
+
{
|
|
193
|
+
name: 'UnrecognizedAddress',
|
|
194
|
+
message: 'Expected argument {0} to be an address',
|
|
195
|
+
},
|
|
196
|
+
{
|
|
197
|
+
name: 'CantDeriveAddress',
|
|
198
|
+
message:
|
|
199
|
+
"Can't derive address associated with script {0}, needs to be p2pkh in, p2pkh out, p2sh in, or p2sh out.",
|
|
200
|
+
},
|
|
201
|
+
{
|
|
202
|
+
name: 'InvalidBuffer',
|
|
203
|
+
message: "Invalid script buffer: can't parse valid script from given buffer {0}",
|
|
204
|
+
},
|
|
205
|
+
{
|
|
206
|
+
name: 'InvalidOpcode',
|
|
207
|
+
message: 'Invalid Opcode: got "{0}"',
|
|
208
|
+
},
|
|
209
|
+
],
|
|
210
|
+
},
|
|
211
|
+
{
|
|
212
|
+
name: 'HDPrivateKey',
|
|
213
|
+
message: 'Internal Error on HDPrivateKey {0}',
|
|
214
|
+
errors: [
|
|
215
|
+
{
|
|
216
|
+
name: 'InvalidDerivationArgument',
|
|
217
|
+
message: 'Invalid derivation argument {0}, expected string, or number and boolean',
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
name: 'InvalidEntropyArgument',
|
|
221
|
+
message: 'Invalid entropy: must be an hexa string or binary buffer, got {0}',
|
|
222
|
+
errors: [
|
|
223
|
+
{
|
|
224
|
+
name: 'TooMuchEntropy',
|
|
225
|
+
message: 'Invalid entropy: more than 512 bits is non standard, got "{0}"',
|
|
226
|
+
},
|
|
227
|
+
{
|
|
228
|
+
name: 'NotEnoughEntropy',
|
|
229
|
+
message: 'Invalid entropy: at least 128 bits needed, got "{0}"',
|
|
230
|
+
},
|
|
231
|
+
],
|
|
232
|
+
},
|
|
233
|
+
{
|
|
234
|
+
name: 'InvalidLength',
|
|
235
|
+
message: 'Invalid length for xprivkey string in {0}',
|
|
236
|
+
},
|
|
237
|
+
{
|
|
238
|
+
name: 'InvalidPath',
|
|
239
|
+
message: 'Invalid derivation path: {0}',
|
|
240
|
+
},
|
|
241
|
+
{
|
|
242
|
+
name: 'UnrecognizedArgument',
|
|
243
|
+
message:
|
|
244
|
+
'Invalid argument: creating a HDPrivateKey requires a string, buffer, json or object, got "{0}"',
|
|
245
|
+
},
|
|
246
|
+
],
|
|
247
|
+
},
|
|
248
|
+
{
|
|
249
|
+
name: 'HDPublicKey',
|
|
250
|
+
message: 'Internal Error on HDPublicKey {0}',
|
|
251
|
+
errors: [
|
|
252
|
+
{
|
|
253
|
+
name: 'ArgumentIsPrivateExtended',
|
|
254
|
+
message: 'Argument is an extended private key: {0}',
|
|
255
|
+
},
|
|
256
|
+
{
|
|
257
|
+
name: 'InvalidDerivationArgument',
|
|
258
|
+
message: 'Invalid derivation argument: got {0}',
|
|
259
|
+
},
|
|
260
|
+
{
|
|
261
|
+
name: 'InvalidLength',
|
|
262
|
+
message: 'Invalid length for xpubkey: got "{0}"',
|
|
263
|
+
},
|
|
264
|
+
{
|
|
265
|
+
name: 'InvalidPath',
|
|
266
|
+
message: 'Invalid derivation path, it should look like: "m/1/100", got "{0}"',
|
|
267
|
+
},
|
|
268
|
+
{
|
|
269
|
+
name: 'InvalidIndexCantDeriveHardened',
|
|
270
|
+
message: 'Invalid argument: creating a hardened path requires an HDPrivateKey',
|
|
271
|
+
},
|
|
272
|
+
{
|
|
273
|
+
name: 'MustSupplyArgument',
|
|
274
|
+
message: 'Must supply an argument to create a HDPublicKey',
|
|
275
|
+
},
|
|
276
|
+
{
|
|
277
|
+
name: 'UnrecognizedArgument',
|
|
278
|
+
message: 'Invalid argument for creation, must be string, json, buffer, or object',
|
|
279
|
+
},
|
|
280
|
+
],
|
|
281
|
+
},
|
|
282
|
+
{
|
|
283
|
+
name: 'ECIES',
|
|
284
|
+
message: 'Internal Error on opcat-ecies Module {0}',
|
|
285
|
+
errors: [
|
|
286
|
+
{
|
|
287
|
+
name: 'DecryptionError',
|
|
288
|
+
message: 'Invalid Message: {0}',
|
|
289
|
+
},
|
|
290
|
+
{
|
|
291
|
+
name: 'UnsupportAlgorithm',
|
|
292
|
+
message: 'Unsupport Algorithm: {0}',
|
|
293
|
+
},
|
|
294
|
+
],
|
|
295
|
+
},
|
|
296
|
+
{
|
|
297
|
+
name: 'Mnemonic',
|
|
298
|
+
message: 'Internal Error on opcat-mnemonic module {0}',
|
|
299
|
+
errors: [
|
|
300
|
+
{
|
|
301
|
+
name: 'InvalidEntropy',
|
|
302
|
+
message: 'Entropy length must be an even multiple of 11 bits: {0}',
|
|
303
|
+
},
|
|
304
|
+
{
|
|
305
|
+
name: 'UnknownWordlist',
|
|
306
|
+
message: 'Could not detect the used word list: {0}',
|
|
307
|
+
},
|
|
308
|
+
{
|
|
309
|
+
name: 'InvalidMnemonic',
|
|
310
|
+
message: 'Mnemonic string is invalid: {0}',
|
|
311
|
+
},
|
|
312
|
+
],
|
|
313
|
+
},
|
|
314
|
+
];
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Hash Cache
|
|
3
|
+
* ==========
|
|
4
|
+
*
|
|
5
|
+
* For use in sighash.
|
|
6
|
+
*/
|
|
7
|
+
'use strict';
|
|
8
|
+
|
|
9
|
+
class HashCache {
|
|
10
|
+
constructor(prevoutsHashBuf, sequenceHashBuf, outputsHashBuf) {
|
|
11
|
+
this.prevoutsHashBuf = prevoutsHashBuf;
|
|
12
|
+
this.sequenceHashBuf = sequenceHashBuf;
|
|
13
|
+
this.outputsHashBuf = outputsHashBuf;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
static fromBuffer(buf) {
|
|
17
|
+
return HashCache.fromJSON(JSON.parse(buf.toString()));
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
toBuffer() {
|
|
21
|
+
return Buffer.from(JSON.stringify(this.toJSON()));
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
static fromJSON(json) {
|
|
25
|
+
return new HashCache(
|
|
26
|
+
json.prevoutsHashBuf ? Buffer.from(json.prevoutsHashBuf, 'hex') : undefined,
|
|
27
|
+
json.sequenceHashBuf ? Buffer.from(json.sequenceHashBuf, 'hex') : undefined,
|
|
28
|
+
json.outputsHashBuf ? Buffer.from(json.outputsHashBuf, 'hex') : undefined,
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
toJSON() {
|
|
33
|
+
return {
|
|
34
|
+
prevoutsHashBuf: this.prevoutsHashBuf ? this.prevoutsHashBuf.toString('hex') : undefined,
|
|
35
|
+
sequenceHashBuf: this.sequenceHashBuf ? this.sequenceHashBuf.toString('hex') : undefined,
|
|
36
|
+
outputsHashBuf: this.outputsHashBuf ? this.outputsHashBuf.toString('hex') : undefined,
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
toHex() {
|
|
41
|
+
return this.toBuffer().toString('hex');
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
static fromHex(hex) {
|
|
45
|
+
const buf = Buffer.from(hex, 'hex');
|
|
46
|
+
return HashCache.fromBuffer(buf);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
module.exports = HashCache;
|