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.
- package/LICENSE +36 -0
- package/README.md +305 -0
- package/SECURITY.md +75 -0
- package/bsv-ecies.min.js +12 -0
- package/bsv-message.min.js +10 -0
- package/bsv-mnemonic.min.js +12 -0
- package/bsv.d.ts +440 -0
- package/bsv.min.js +37 -0
- package/ecies/index.js +1 -0
- package/index.js +101 -0
- package/lib/address.js +526 -0
- package/lib/block/block.js +277 -0
- package/lib/block/blockheader.js +294 -0
- package/lib/block/index.js +4 -0
- package/lib/block/merkleblock.js +316 -0
- package/lib/crypto/bn.js +278 -0
- package/lib/crypto/ecdsa.js +330 -0
- package/lib/crypto/elliptic-fixed.js +74 -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 +217 -0
- package/lib/crypto/random.js +37 -0
- package/lib/crypto/signature.js +410 -0
- package/lib/crypto/smartledger_verify.js +109 -0
- package/lib/ecies/bitcore-ecies.js +163 -0
- package/lib/ecies/electrum-ecies.js +175 -0
- package/lib/ecies/errors.js +16 -0
- package/lib/ecies/index.js +1 -0
- package/lib/encoding/base58.js +108 -0
- package/lib/encoding/base58check.js +112 -0
- package/lib/encoding/bufferreader.js +200 -0
- package/lib/encoding/bufferwriter.js +150 -0
- package/lib/encoding/varint.js +71 -0
- package/lib/errors/index.js +57 -0
- package/lib/errors/spec.js +184 -0
- package/lib/hdprivatekey.js +655 -0
- package/lib/hdpublickey.js +509 -0
- package/lib/message/index.js +4 -0
- package/lib/message/message.js +181 -0
- package/lib/mnemonic/errors.js +18 -0
- package/lib/mnemonic/index.js +4 -0
- package/lib/mnemonic/mnemonic.js +304 -0
- package/lib/mnemonic/pbkdf2.js +68 -0
- package/lib/mnemonic/words/chinese.js +5 -0
- package/lib/mnemonic/words/english.js +5 -0
- package/lib/mnemonic/words/french.js +5 -0
- package/lib/mnemonic/words/index.js +8 -0
- package/lib/mnemonic/words/italian.js +5 -0
- package/lib/mnemonic/words/japanese.js +5 -0
- package/lib/mnemonic/words/spanish.js +5 -0
- package/lib/networks.js +392 -0
- package/lib/opcode.js +248 -0
- package/lib/privatekey.js +373 -0
- package/lib/publickey.js +387 -0
- package/lib/script/index.js +3 -0
- package/lib/script/interpreter.js +1807 -0
- package/lib/script/script.js +1153 -0
- package/lib/transaction/index.js +7 -0
- package/lib/transaction/input/index.js +6 -0
- package/lib/transaction/input/input.js +202 -0
- package/lib/transaction/input/multisig.js +220 -0
- package/lib/transaction/input/multisigscripthash.js +189 -0
- package/lib/transaction/input/publickey.js +96 -0
- package/lib/transaction/input/publickeyhash.js +103 -0
- package/lib/transaction/output.js +192 -0
- package/lib/transaction/sighash.js +288 -0
- package/lib/transaction/signature.js +88 -0
- package/lib/transaction/transaction.js +1208 -0
- package/lib/transaction/unspentoutput.js +97 -0
- package/lib/util/_.js +44 -0
- package/lib/util/js.js +91 -0
- package/lib/util/preconditions.js +34 -0
- package/message/index.js +1 -0
- package/mnemonic/index.js +1 -0
- 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
|