smartledger-bsv 3.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.
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 +86 -0
@@ -0,0 +1,88 @@
1
+ 'use strict'
2
+
3
+ var _ = require('../util/_')
4
+ var $ = require('../util/preconditions')
5
+ var inherits = require('inherits')
6
+ var JSUtil = require('../util/js')
7
+
8
+ var PublicKey = require('../publickey')
9
+ var errors = require('../errors')
10
+ var Signature = require('../crypto/signature')
11
+
12
+ /**
13
+ * @desc
14
+ * Wrapper around Signature with fields related to signing a transaction specifically
15
+ *
16
+ * @param {Object|string|TransactionSignature} arg
17
+ * @constructor
18
+ */
19
+ function TransactionSignature (arg) {
20
+ if (!(this instanceof TransactionSignature)) {
21
+ return new TransactionSignature(arg)
22
+ }
23
+ if (arg instanceof TransactionSignature) {
24
+ return arg
25
+ }
26
+ if (_.isObject(arg)) {
27
+ return this._fromObject(arg)
28
+ }
29
+ throw new errors.InvalidArgument('TransactionSignatures must be instantiated from an object')
30
+ }
31
+ inherits(TransactionSignature, Signature)
32
+
33
+ TransactionSignature.prototype._fromObject = function (arg) {
34
+ this._checkObjectArgs(arg)
35
+ this.publicKey = new PublicKey(arg.publicKey)
36
+ this.prevTxId = Buffer.isBuffer(arg.prevTxId) ? arg.prevTxId : Buffer.from(arg.prevTxId, 'hex')
37
+ this.outputIndex = arg.outputIndex
38
+ this.inputIndex = arg.inputIndex
39
+ this.signature = (arg.signature instanceof Signature) ? arg.signature
40
+ : Buffer.isBuffer(arg.signature) ? Signature.fromBuffer(arg.signature)
41
+ : Signature.fromString(arg.signature)
42
+ this.sigtype = arg.sigtype
43
+ return this
44
+ }
45
+
46
+ TransactionSignature.prototype._checkObjectArgs = function (arg) {
47
+ $.checkArgument(PublicKey(arg.publicKey), 'publicKey')
48
+ $.checkArgument(!_.isUndefined(arg.inputIndex), 'inputIndex')
49
+ $.checkArgument(!_.isUndefined(arg.outputIndex), 'outputIndex')
50
+ $.checkState(_.isNumber(arg.inputIndex), 'inputIndex must be a number')
51
+ $.checkState(_.isNumber(arg.outputIndex), 'outputIndex must be a number')
52
+ $.checkArgument(arg.signature, 'signature')
53
+ $.checkArgument(arg.prevTxId, 'prevTxId')
54
+ $.checkState(arg.signature instanceof Signature ||
55
+ Buffer.isBuffer(arg.signature) ||
56
+ JSUtil.isHexa(arg.signature), 'signature must be a buffer or hexa value')
57
+ $.checkState(Buffer.isBuffer(arg.prevTxId) ||
58
+ JSUtil.isHexa(arg.prevTxId), 'prevTxId must be a buffer or hexa value')
59
+ $.checkArgument(arg.sigtype, 'sigtype')
60
+ $.checkState(_.isNumber(arg.sigtype), 'sigtype must be a number')
61
+ }
62
+
63
+ /**
64
+ * Serializes a transaction to a plain JS object
65
+ * @return {Object}
66
+ */
67
+ TransactionSignature.prototype.toObject = TransactionSignature.prototype.toJSON = function toObject () {
68
+ return {
69
+ publicKey: this.publicKey.toString(),
70
+ prevTxId: this.prevTxId.toString('hex'),
71
+ outputIndex: this.outputIndex,
72
+ inputIndex: this.inputIndex,
73
+ signature: this.signature.toString(),
74
+ sigtype: this.sigtype
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Builds a TransactionSignature from an object
80
+ * @param {Object} object
81
+ * @return {TransactionSignature}
82
+ */
83
+ TransactionSignature.fromObject = function (object) {
84
+ $.checkArgument(object)
85
+ return new TransactionSignature(object)
86
+ }
87
+
88
+ module.exports = TransactionSignature