@smartledger/bsv 1.5.6-fix1

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 (76) hide show
  1. package/LICENSE +36 -0
  2. package/README.md +305 -0
  3. package/SECURITY.md +75 -0
  4. package/bsv-ecies.min.js +12 -0
  5. package/bsv-message.min.js +10 -0
  6. package/bsv-mnemonic.min.js +12 -0
  7. package/bsv.d.ts +440 -0
  8. package/bsv.min.js +37 -0
  9. package/ecies/index.js +1 -0
  10. package/index.js +101 -0
  11. package/lib/address.js +526 -0
  12. package/lib/block/block.js +277 -0
  13. package/lib/block/blockheader.js +294 -0
  14. package/lib/block/index.js +4 -0
  15. package/lib/block/merkleblock.js +316 -0
  16. package/lib/crypto/bn.js +278 -0
  17. package/lib/crypto/ecdsa.js +330 -0
  18. package/lib/crypto/elliptic-fixed.js +74 -0
  19. package/lib/crypto/hash.browser.js +171 -0
  20. package/lib/crypto/hash.js +2 -0
  21. package/lib/crypto/hash.node.js +171 -0
  22. package/lib/crypto/point.js +217 -0
  23. package/lib/crypto/random.js +37 -0
  24. package/lib/crypto/signature.js +410 -0
  25. package/lib/crypto/smartledger_verify.js +109 -0
  26. package/lib/ecies/bitcore-ecies.js +163 -0
  27. package/lib/ecies/electrum-ecies.js +175 -0
  28. package/lib/ecies/errors.js +16 -0
  29. package/lib/ecies/index.js +1 -0
  30. package/lib/encoding/base58.js +108 -0
  31. package/lib/encoding/base58check.js +112 -0
  32. package/lib/encoding/bufferreader.js +200 -0
  33. package/lib/encoding/bufferwriter.js +150 -0
  34. package/lib/encoding/varint.js +71 -0
  35. package/lib/errors/index.js +57 -0
  36. package/lib/errors/spec.js +184 -0
  37. package/lib/hdprivatekey.js +655 -0
  38. package/lib/hdpublickey.js +509 -0
  39. package/lib/message/index.js +4 -0
  40. package/lib/message/message.js +181 -0
  41. package/lib/mnemonic/errors.js +18 -0
  42. package/lib/mnemonic/index.js +4 -0
  43. package/lib/mnemonic/mnemonic.js +304 -0
  44. package/lib/mnemonic/pbkdf2.js +68 -0
  45. package/lib/mnemonic/words/chinese.js +5 -0
  46. package/lib/mnemonic/words/english.js +5 -0
  47. package/lib/mnemonic/words/french.js +5 -0
  48. package/lib/mnemonic/words/index.js +8 -0
  49. package/lib/mnemonic/words/italian.js +5 -0
  50. package/lib/mnemonic/words/japanese.js +5 -0
  51. package/lib/mnemonic/words/spanish.js +5 -0
  52. package/lib/networks.js +392 -0
  53. package/lib/opcode.js +248 -0
  54. package/lib/privatekey.js +373 -0
  55. package/lib/publickey.js +387 -0
  56. package/lib/script/index.js +3 -0
  57. package/lib/script/interpreter.js +1807 -0
  58. package/lib/script/script.js +1153 -0
  59. package/lib/transaction/index.js +7 -0
  60. package/lib/transaction/input/index.js +6 -0
  61. package/lib/transaction/input/input.js +202 -0
  62. package/lib/transaction/input/multisig.js +220 -0
  63. package/lib/transaction/input/multisigscripthash.js +189 -0
  64. package/lib/transaction/input/publickey.js +96 -0
  65. package/lib/transaction/input/publickeyhash.js +103 -0
  66. package/lib/transaction/output.js +192 -0
  67. package/lib/transaction/sighash.js +288 -0
  68. package/lib/transaction/signature.js +88 -0
  69. package/lib/transaction/transaction.js +1208 -0
  70. package/lib/transaction/unspentoutput.js +97 -0
  71. package/lib/util/_.js +44 -0
  72. package/lib/util/js.js +91 -0
  73. package/lib/util/preconditions.js +34 -0
  74. package/message/index.js +1 -0
  75. package/mnemonic/index.js +1 -0
  76. package/package.json +89 -0
package/bsv.d.ts ADDED
@@ -0,0 +1,440 @@
1
+ // Type definitions for bsv 0.30
2
+ // Project: https://github.com/moneybutton/bsv
3
+ // Forked From: https://github.com/bitpay/bitcore-lib
4
+ // Definitions by: Lautaro Dragan <https://github.com/lautarodragan>
5
+ // Definitions extended by: David Case <https://github.com/shruggr>
6
+ // Definitions: https://github.com/DefinitelyTyped/DefinitelyTyped
7
+
8
+ // TypeScript Version: 2.2
9
+
10
+ /// <reference types="node" />
11
+
12
+ declare module 'bsv' {
13
+
14
+ export namespace crypto {
15
+ class BN { }
16
+
17
+ namespace ECDSA {
18
+ function sign(message: Buffer, key: PrivateKey): Signature;
19
+ function verify(hashbuf: Buffer, sig: Signature, pubkey: PublicKey, endian?: 'little'): boolean;
20
+ }
21
+
22
+ namespace Hash {
23
+ function sha1(buffer: Buffer): Buffer;
24
+ function sha256(buffer: Buffer): Buffer;
25
+ function sha256sha256(buffer: Buffer): Buffer;
26
+ function sha256ripemd160(buffer: Buffer): Buffer;
27
+ function sha512(buffer: Buffer): Buffer;
28
+ function ripemd160(buffer: Buffer): Buffer;
29
+
30
+ function sha256hmac(data: Buffer, key: Buffer): Buffer;
31
+ function sha512hmac(data: Buffer, key: Buffer): Buffer;
32
+ }
33
+
34
+ namespace Random {
35
+ function getRandomBuffer(size: number): Buffer;
36
+ }
37
+
38
+ namespace Point { }
39
+
40
+ class Signature {
41
+ static fromDER(sig: Buffer): Signature;
42
+ static fromString(data: string): Signature;
43
+ SIGHASH_ALL: number;
44
+ toString(): string;
45
+ }
46
+ }
47
+
48
+ export namespace Transaction {
49
+ class UnspentOutput {
50
+ static fromObject(o: object): UnspentOutput;
51
+
52
+ readonly address: Address;
53
+ readonly txId: string;
54
+ readonly outputIndex: number;
55
+ readonly script: Script;
56
+ readonly satoshis: number;
57
+ spentTxId: string | null;
58
+
59
+ constructor(data: object);
60
+
61
+ inspect(): string;
62
+ toObject(): this;
63
+ toString(): string;
64
+ }
65
+
66
+ class Output {
67
+ readonly script: Script;
68
+ readonly satoshis: number;
69
+ readonly satoshisBN: crypto.BN;
70
+ spentTxId: string | null;
71
+ constructor(data: object);
72
+
73
+ setScript(script: Script | string | Buffer): this;
74
+ inspect(): string;
75
+ toObject(): object;
76
+ }
77
+
78
+ class Input {
79
+ readonly prevTxId: Buffer;
80
+ readonly outputIndex: number;
81
+ readonly sequenceNumber: number;
82
+ readonly script: Script;
83
+ output?: Output;
84
+ isValidSignature(tx: Transaction, sig: any): boolean;
85
+ }
86
+ }
87
+
88
+ export class Transaction {
89
+ inputs: Transaction.Input[];
90
+ outputs: Transaction.Output[];
91
+ readonly id: string;
92
+ readonly hash: string;
93
+ readonly inputAmount: number;
94
+ readonly outputAmount: number;
95
+ nid: string;
96
+
97
+ constructor(serialized?: any);
98
+
99
+ from(utxos: Transaction.UnspentOutput | Transaction.UnspentOutput[]): this;
100
+ to(address: Address[] | Address | string, amount: number): this;
101
+ change(address: Address | string): this;
102
+ fee(amount: number): this;
103
+ feePerKb(amount: number): this;
104
+ sign(privateKey: PrivateKey | string): this;
105
+ applySignature(sig: crypto.Signature): this;
106
+ addInput(input: Transaction.Input): this;
107
+ addOutput(output: Transaction.Output): this;
108
+ addData(value: Buffer | string): this;
109
+ lockUntilDate(time: Date | number): this;
110
+ lockUntilBlockHeight(height: number): this;
111
+
112
+ hasWitnesses(): boolean;
113
+ getFee(): number;
114
+ getChangeOutput(): Transaction.Output | null;
115
+ getLockTime(): Date | number;
116
+
117
+ verify(): string | boolean;
118
+ isCoinbase(): boolean;
119
+
120
+ enableRBF(): this;
121
+ isRBF(): boolean;
122
+
123
+ inspect(): string;
124
+ serialize(): string;
125
+
126
+ toObject(): any;
127
+ toBuffer(): Buffer;
128
+
129
+ verify(): boolean | string;
130
+ isFullySigned(): boolean;
131
+ }
132
+
133
+ export class ECIES {
134
+ constructor(opts?: any, algorithm?: string);
135
+
136
+ privateKey(privateKey: PrivateKey): ECIES;
137
+ publicKey(publicKey: PublicKey): ECIES;
138
+ encrypt(message: string | Buffer): Buffer;
139
+ decrypt(encbuf: Buffer): Buffer;
140
+ }
141
+ export class Block {
142
+ hash: string;
143
+ height: number;
144
+ transactions: Transaction[];
145
+ header: {
146
+ time: number;
147
+ prevHash: string;
148
+ };
149
+
150
+ constructor(data: Buffer | object);
151
+ }
152
+
153
+ export class PrivateKey {
154
+ constructor(key?: string, network?: Networks.Network);
155
+
156
+ readonly publicKey: PublicKey;
157
+ readonly compressed: boolean;
158
+ readonly network: Networks.Network;
159
+
160
+ toAddress(): Address;
161
+ toPublicKey(): PublicKey;
162
+ toString(): string;
163
+ toObject(): object;
164
+ toJSON(): object;
165
+ toWIF(): string;
166
+ toHex(): string;
167
+ toBigNumber(): any; //BN;
168
+ toBuffer(): Buffer;
169
+ inspect(): string;
170
+
171
+ static fromString(str: string): PrivateKey;
172
+ static fromWIF(str: string): PrivateKey;
173
+ static fromRandom(netowrk?: string): PrivateKey;
174
+ static fromBuffer(buf: Buffer, network: string | Networks.Network): PrivateKey;
175
+ static fromHex(hex: string, network: string | Networks.Network): PrivateKey;
176
+ static getValidationError(data: string): any | null;
177
+ static isValid(data: string): boolean;
178
+ }
179
+
180
+ export class PublicKey {
181
+ constructor(source: string, extra?: object);
182
+
183
+ //readonly point: Point;
184
+ readonly compressed: boolean;
185
+ readonly network: Networks.Network;
186
+
187
+ toDER(): Buffer;
188
+ toObject(): object;
189
+ toBuffer(): Buffer;
190
+ toAddress(network?: string | Networks.Network): Address;
191
+ toString(): string;
192
+ toHex(): string;
193
+ inspect(): string;
194
+
195
+ static fromPrivateKey(privateKey: PrivateKey): PublicKey;
196
+ static fromBuffer(buf: Buffer, strict: boolean): PublicKey;
197
+ static fromDER(buf: Buffer, strict: boolean): PublicKey;
198
+ //static fromPoint(point: Point, compressed: boolean): PublicKey;
199
+ //static fromX(odd: boolean, x: Point): PublicKey;
200
+ static fromString(str: string): PublicKey;
201
+ static fromHex(hex: string): PublicKey;
202
+ static getValidationError(data: string): any | null;
203
+ static isValid(data: string): boolean;
204
+ }
205
+
206
+ export class Message {
207
+ constructor(message: string | Buffer);
208
+
209
+ readonly messageBuffer: Buffer;
210
+
211
+ sign(privateKey: PrivateKey): string;
212
+ verify(address: string | Address, signature: string): boolean;
213
+ toObject(): object;
214
+ toJSON(): string;
215
+ toString(): string;
216
+ inspect(): string;
217
+
218
+ static sign(message: string | Buffer, privateKey: PrivateKey): string;
219
+ static verify(message: string | Buffer, address: string | Address, signature: string): boolean;
220
+ static MAGIC_BYTES: Buffer;
221
+ static magicHash(): string;
222
+ static fromString(str: string): Message;
223
+ static fromJSON(json: string): Message;
224
+ static fromObject(obj: object): Message;
225
+ }
226
+
227
+ export class Mnemonic {
228
+ constructor(data: string | Array<string>, wordList?: Array<string>);
229
+
230
+ readonly wordList: Array<string>;
231
+ readonly phrase: string;
232
+
233
+ toSeed(passphrase?: string): Buffer;
234
+ toHDPrivateKey(passphrase: string, network: string | number): HDPrivateKey;
235
+ toString(): string;
236
+ inspect(): string;
237
+
238
+ static fromRandom(wordlist?: Array<string>): Mnemonic;
239
+ static fromString(mnemonic: String, wordList?: Array<string>): Mnemonic;
240
+ static isValid(mnemonic: String, wordList?: Array<string>): boolean;
241
+ static fromSeed(seed: Buffer, wordlist: Array<string>): Mnemonic
242
+ }
243
+
244
+ export class HDPrivateKey {
245
+ constructor(data?: string | Buffer | object);
246
+
247
+ readonly hdPublicKey: HDPublicKey;
248
+
249
+ readonly xprivkey: Buffer;
250
+ readonly xpubkey: Buffer;
251
+ readonly network: Networks.Network;
252
+ readonly depth: number;
253
+ readonly privateKey: PrivateKey;
254
+ readonly publicKey: PublicKey;
255
+ readonly fingerPrint: Buffer;
256
+
257
+ derive(arg: string | number, hardened?: boolean): HDPrivateKey;
258
+ deriveChild(arg: string | number, hardened?: boolean): HDPrivateKey;
259
+ deriveNonCompliantChild(arg: string | number, hardened?: boolean): HDPrivateKey;
260
+
261
+ toString(): string;
262
+ toObject(): object;
263
+ toJSON(): object;
264
+ toBuffer(): Buffer;
265
+ toHex(): string;
266
+ inspect(): string;
267
+
268
+ static fromRandom(): HDPrivateKey;
269
+ static fromString(str: string): HDPrivateKey;
270
+ static fromObject(obj: object): HDPrivateKey;
271
+ static fromSeed(hexa: string | Buffer, network: string | Networks.Network): HDPrivateKey;
272
+ static fromBuffer(buf: Buffer): HDPrivateKey;
273
+ static fromHex(hex: string): HDPrivateKey;
274
+ static isValidPath(arg: string | number, hardened: boolean): boolean;
275
+ static isValidSerialized(data: string | Buffer, network?: string | Networks.Network): boolean;
276
+ static getSerializedError(data: string | Buffer, network?: string | Networks.Network): any | null;
277
+ }
278
+
279
+ export class HDPublicKey {
280
+ constructor(arg: string | Buffer | object);
281
+
282
+ readonly xpubkey: Buffer;
283
+ readonly network: Networks.Network;
284
+ readonly depth: number;
285
+ readonly publicKey: PublicKey;
286
+ readonly fingerPrint: Buffer;
287
+
288
+ derive(arg: string | number, hardened?: boolean): HDPublicKey;
289
+ deriveChild(arg: string | number, hardened?: boolean): HDPublicKey;
290
+
291
+ toString(): string;
292
+ toObject(): object;
293
+ toJSON(): object;
294
+ toBuffer(): Buffer;
295
+ toHex(): string;
296
+ inspect(): string;
297
+
298
+ static fromString(str: string): HDPublicKey;
299
+ static fromObject(obj: object): HDPublicKey;
300
+ static fromBuffer(buf: Buffer): HDPublicKey;
301
+ static fromHex(hex: string): HDPublicKey;
302
+
303
+ static fromHDPrivateKey(hdPrivateKey: HDPrivateKey): HDPublicKey;
304
+ static isValidPath(arg: string | number): boolean;
305
+ static isValidSerialized(data: string | Buffer, network?: string | Networks.Network): boolean;
306
+ static getSerializedError(data: string | Buffer, network?: string | Networks.Network): any | null;
307
+
308
+ }
309
+
310
+ export namespace Script {
311
+ const types: {
312
+ DATA_OUT: string;
313
+ };
314
+ function buildMultisigOut(publicKeys: PublicKey[], threshold: number, opts: object): Script;
315
+ function buildWitnessMultisigOutFromScript(script: Script): Script;
316
+ function buildMultisigIn(pubkeys: PublicKey[], threshold: number, signatures: Buffer[], opts: object): Script;
317
+ function buildP2SHMultisigIn(pubkeys: PublicKey[], threshold: number, signatures: Buffer[], opts: object): Script;
318
+ function buildPublicKeyHashOut(address: Address): Script;
319
+ function buildPublicKeyOut(pubkey: PublicKey): Script;
320
+ function buildDataOut(data: string | Buffer, encoding?: string): Script;
321
+ function buildScriptHashOut(script: Script): Script;
322
+ function buildPublicKeyIn(signature: crypto.Signature | Buffer, sigtype: number): Script;
323
+ function buildPublicKeyHashIn(publicKey: PublicKey, signature: crypto.Signature | Buffer, sigtype: number): Script;
324
+
325
+ function fromAddress(address: string | Address): Script;
326
+
327
+ function empty(): Script;
328
+ namespace Interpreter {
329
+ const SCRIPT_ENABLE_SIGHASH_FORKID: any;
330
+ }
331
+
332
+ function Interpreter(): {
333
+ verify: (
334
+ inputScript: Script,
335
+ outputScript: Script,
336
+ txn: Transaction,
337
+ nin: Number,
338
+ flags: any,
339
+ satoshisBN: crypto.BN
340
+ ) => boolean
341
+ }
342
+ }
343
+
344
+ export class Script {
345
+ constructor(data: string | object);
346
+
347
+ set(obj: object): this;
348
+
349
+ toBuffer(): Buffer;
350
+ toASM(): string;
351
+ toString(): string;
352
+ toHex(): string;
353
+
354
+ isPublicKeyHashOut(): boolean;
355
+ isPublicKeyHashIn(): boolean;
356
+
357
+ getPublicKey(): Buffer;
358
+ getPublicKeyHash(): Buffer;
359
+
360
+ isPublicKeyOut(): boolean;
361
+ isPublicKeyIn(): boolean;
362
+
363
+ isScriptHashOut(): boolean;
364
+ isWitnessScriptHashOut(): boolean;
365
+ isWitnessPublicKeyHashOut(): boolean;
366
+ isWitnessProgram(): boolean;
367
+ isScriptHashIn(): boolean;
368
+ isMultisigOut(): boolean;
369
+ isMultisigIn(): boolean;
370
+ isDataOut(): boolean;
371
+ isSafeDataOut(): boolean;
372
+
373
+ getData(): Buffer;
374
+ isPushOnly(): boolean;
375
+
376
+ classify(): string;
377
+ classifyInput(): string;
378
+ classifyOutput(): string;
379
+
380
+ isStandard(): boolean;
381
+
382
+ prepend(obj: any): this;
383
+ add(obj: any): this;
384
+
385
+ hasCodeseparators(): boolean;
386
+ removeCodeseparators(): this;
387
+
388
+ equals(script: Script): boolean;
389
+
390
+ getAddressInfo(): Address | boolean;
391
+ findAndDelete(script: Script): this;
392
+ checkMinimalPush(i: number): boolean;
393
+ getSignatureOperationsCount(accurate: boolean): number;
394
+
395
+ toAddress(network?: string): Address;
396
+ }
397
+
398
+ export interface Util {
399
+ readonly buffer: {
400
+ reverse(a: any): any;
401
+ };
402
+ }
403
+
404
+ export namespace Networks {
405
+ interface Network {
406
+ readonly name: string;
407
+ readonly alias: string;
408
+ }
409
+
410
+ const livenet: Network;
411
+ const mainnet: Network;
412
+ const testnet: Network;
413
+
414
+ function add(data: any): Network;
415
+ function remove(network: Network): void;
416
+ function get(args: string | number | Network, keys: string | string[]): Network;
417
+ }
418
+
419
+ export class Address {
420
+ readonly hashBuffer: Buffer;
421
+ readonly network: Networks.Network;
422
+ readonly type: string;
423
+
424
+ constructor(data: Buffer | Uint8Array | string | object, network?: Networks.Network | string, type?: string);
425
+ }
426
+
427
+ export class Unit {
428
+ static fromBTC(amount: number): Unit;
429
+ static fromMilis(amount: number): Unit;
430
+ static fromBits(amount: number): Unit;
431
+ static fromSatoshis(amount: number): Unit;
432
+
433
+ constructor(amount: number, unitPreference: string);
434
+
435
+ toBTC(): number;
436
+ toMilis(): number;
437
+ toBits(): number;
438
+ toSatoshis(): number;
439
+ }
440
+ }