@smartledger/bsv 7.8.1 → 7.10.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/CHANGELOG.md +117 -6
  2. package/README.md +38 -38
  3. package/bsv-covenant.min.js +1 -1
  4. package/bsv-ecies.min.js +1 -1
  5. package/bsv-gdaf.min.js +54 -54
  6. package/bsv-ltp.min.js +58 -85
  7. package/bsv-message.min.js +2 -2
  8. package/bsv-mnemonic.min.js +12 -14
  9. package/bsv-script-helper.min.js +1 -1
  10. package/bsv-shamir.min.js +14 -16
  11. package/bsv-smartcontract.min.js +23 -25
  12. package/bsv.bundle.js +54 -54
  13. package/bsv.min.js +54 -54
  14. package/build/esbuild.js +84 -4
  15. package/docs/MODULE_REFERENCE_COMPLETE.md +27 -27
  16. package/docs/advanced/UTXO_MANAGER_GUIDE.md +1 -1
  17. package/docs/getting-started/INSTALLATION.md +23 -23
  18. package/docs/getting-started/QUICK_START.md +7 -7
  19. package/docs/migration/FROM_BSV_1_5_6.md +5 -5
  20. package/index.js +9 -1
  21. package/lib/covenant/helpers.js +146 -0
  22. package/lib/covenant/index.js +21 -0
  23. package/lib/covenant/pushtx.js +243 -0
  24. package/lib/covenant-interface.js +408 -397
  25. package/lib/custom-script-helper.js +44 -38
  26. package/lib/ecies/bitcore-ecies.js +3 -4
  27. package/lib/ecies/electrum-ecies.js +4 -6
  28. package/lib/ecies/errors.js +1 -1
  29. package/lib/gdaf/attestation-signer.js +7 -7
  30. package/lib/gdaf/attestation-verifier.js +5 -6
  31. package/lib/gdaf/did-resolver.js +10 -9
  32. package/lib/gdaf/smartledger-anchor.js +13 -12
  33. package/lib/gdaf/zk-prover.js +8 -8
  34. package/lib/ltp/anchor.js +2 -3
  35. package/lib/ltp/claim.js +2 -3
  36. package/lib/ltp/index.js +2 -3
  37. package/lib/ltp/obligation.js +9 -9
  38. package/lib/ltp/proof.js +7 -7
  39. package/lib/ltp/registry.js +4 -5
  40. package/lib/ltp/right.js +11 -11
  41. package/lib/message/index.js +5 -4
  42. package/lib/message/message.js +11 -11
  43. package/lib/mnemonic/errors.js +1 -1
  44. package/lib/mnemonic/index.js +5 -4
  45. package/lib/mnemonic/mnemonic.js +22 -10
  46. package/lib/ordinals/bsv20.js +4 -4
  47. package/lib/ordinals/inscription.js +8 -12
  48. package/lib/ordinals/ordlock.js +26 -21
  49. package/lib/script/interpreter.js +96 -31
  50. package/lib/smart_contract/authorizers.js +8 -6
  51. package/lib/smart_contract/builder.js +32 -26
  52. package/lib/smart_contract/covenant.js +32 -25
  53. package/lib/smart_contract/covenant_helpers.js +8 -128
  54. package/lib/smart_contract/debugger.js +9 -6
  55. package/lib/smart_contract/dsl.js +5 -6
  56. package/lib/smart_contract/index.js +11 -8
  57. package/lib/smart_contract/locks.js +3 -4
  58. package/lib/smart_contract/opcode_list.js +2 -3
  59. package/lib/smart_contract/pels.js +4 -5
  60. package/lib/smart_contract/preimage.js +11 -7
  61. package/lib/smart_contract/pushtx.js +8 -263
  62. package/lib/smart_contract/script_interpreter.js +112 -105
  63. package/lib/smart_contract/script_tester.js +24 -18
  64. package/lib/smart_contract/script_utils.js +15 -14
  65. package/lib/smart_contract/sighash.js +23 -15
  66. package/lib/smart_contract/stack_examiner.js +70 -63
  67. package/lib/smart_contract/token.js +6 -6
  68. package/lib/smart_contract/utxo_generator.js +21 -15
  69. package/lib/smartutxo.js +27 -21
  70. package/lib/spv/headerchain.js +3 -3
  71. package/lib/spv/merkleproof.js +3 -3
  72. package/package.json +4 -2
  73. package/test/script/chronicle.js +53 -10
  74. package/test/script/interpreter.js +9 -6
  75. package/test/script/string_ops.js +26 -10
  76. package/version.js +1 -1
@@ -3,7 +3,13 @@
3
3
  * Simplified API for custom script development
4
4
  */
5
5
 
6
- const bsv = require('../index.js');
6
+ var sighash = require('./transaction/sighash')
7
+ var Interpreter = require('./script/interpreter')
8
+ var Signature = require('./crypto/signature')
9
+ var BN = require('./crypto/bn')
10
+ var Transaction = require('./transaction')
11
+ var Opcode = require('./opcode')
12
+ var Script = require('./script')
7
13
 
8
14
  class CustomScriptHelper {
9
15
 
@@ -18,15 +24,15 @@ class CustomScriptHelper {
18
24
  * @returns {Buffer} Complete signature with sighash type
19
25
  */
20
26
  static createSignature(transaction, privateKey, inputIndex, lockingScript, satoshis, sighashType = null) {
21
- sighashType = sighashType || (bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID);
27
+ sighashType = sighashType || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID);
22
28
 
23
- const signature = bsv.Transaction.sighash.sign(
29
+ const signature = sighash.sign(
24
30
  transaction,
25
31
  privateKey,
26
32
  sighashType,
27
33
  inputIndex,
28
34
  lockingScript,
29
- new bsv.crypto.BN(satoshis)
35
+ new BN(satoshis)
30
36
  );
31
37
 
32
38
  return Buffer.concat([signature.toDER(), Buffer.from([sighashType])]);
@@ -39,15 +45,15 @@ class CustomScriptHelper {
39
45
  * @returns {Script} Multi-signature locking script
40
46
  */
41
47
  static createMultisigScript(m, publicKeys) {
42
- let script = new bsv.Script().add(bsv.Opcode[`OP_${m}`]);
48
+ let script = new Script().add(Opcode[`OP_${m}`]);
43
49
 
44
50
  for (const pubKey of publicKeys) {
45
51
  script = script.add(pubKey.toBuffer());
46
52
  }
47
53
 
48
54
  return script
49
- .add(bsv.Opcode[`OP_${publicKeys.length}`])
50
- .add(bsv.Opcode.OP_CHECKMULTISIG);
55
+ .add(Opcode[`OP_${publicKeys.length}`])
56
+ .add(Opcode.OP_CHECKMULTISIG);
51
57
  }
52
58
 
53
59
  /**
@@ -56,7 +62,7 @@ class CustomScriptHelper {
56
62
  * @returns {Script} Unlocking script for multisig
57
63
  */
58
64
  static createMultisigUnlocking(signatures) {
59
- let script = new bsv.Script().add(bsv.Opcode.OP_0); // CHECKMULTISIG bug
65
+ let script = new Script().add(Opcode.OP_0); // CHECKMULTISIG bug
60
66
 
61
67
  for (const sig of signatures) {
62
68
  script = script.add(sig);
@@ -74,10 +80,10 @@ class CustomScriptHelper {
74
80
  static createTimelockScript(lockTime, baseScript) {
75
81
  const lockTimeBuffer = Buffer.from(lockTime.toString(16).padStart(8, '0'), 'hex').reverse();
76
82
 
77
- return new bsv.Script()
83
+ return new Script()
78
84
  .add(lockTimeBuffer)
79
- .add(bsv.Opcode.OP_CHECKLOCKTIMEVERIFY)
80
- .add(bsv.Opcode.OP_DROP)
85
+ .add(Opcode.OP_CHECKLOCKTIMEVERIFY)
86
+ .add(Opcode.OP_DROP)
81
87
  .add(baseScript.toBuffer());
82
88
  }
83
89
 
@@ -88,17 +94,17 @@ class CustomScriptHelper {
88
94
  * @returns {Script} Conditional script
89
95
  */
90
96
  static createConditionalScript(ifScript, elseScript = null) {
91
- let script = new bsv.Script()
92
- .add(bsv.Opcode.OP_IF)
97
+ let script = new Script()
98
+ .add(Opcode.OP_IF)
93
99
  .add(ifScript.toBuffer());
94
100
 
95
101
  if (elseScript) {
96
102
  script = script
97
- .add(bsv.Opcode.OP_ELSE)
103
+ .add(Opcode.OP_ELSE)
98
104
  .add(elseScript.toBuffer());
99
105
  }
100
106
 
101
- return script.add(bsv.Opcode.OP_ENDIF);
107
+ return script.add(Opcode.OP_ENDIF);
102
108
  }
103
109
 
104
110
  /**
@@ -107,12 +113,12 @@ class CustomScriptHelper {
107
113
  * @returns {Script} P2PKH locking script
108
114
  */
109
115
  static createP2PKHScript(publicKey) {
110
- return new bsv.Script()
111
- .add(bsv.Opcode.OP_DUP)
112
- .add(bsv.Opcode.OP_HASH160)
116
+ return new Script()
117
+ .add(Opcode.OP_DUP)
118
+ .add(Opcode.OP_HASH160)
113
119
  .add(publicKey.toAddress().hashBuffer)
114
- .add(bsv.Opcode.OP_EQUALVERIFY)
115
- .add(bsv.Opcode.OP_CHECKSIG);
120
+ .add(Opcode.OP_EQUALVERIFY)
121
+ .add(Opcode.OP_CHECKSIG);
116
122
  }
117
123
 
118
124
  /**
@@ -122,7 +128,7 @@ class CustomScriptHelper {
122
128
  * @returns {Script} P2PKH unlocking script
123
129
  */
124
130
  static createP2PKHUnlocking(signature, publicKey) {
125
- return new bsv.Script()
131
+ return new Script()
126
132
  .add(signature)
127
133
  .add(publicKey.toBuffer());
128
134
  }
@@ -137,14 +143,14 @@ class CustomScriptHelper {
137
143
  * @returns {Buffer} Transaction preimage
138
144
  */
139
145
  static getPreimage(transaction, inputIndex, lockingScript, satoshis, sighashType = null) {
140
- sighashType = sighashType || (bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID);
146
+ sighashType = sighashType || (Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID);
141
147
 
142
- return bsv.Transaction.sighash.sighash(
148
+ return sighash.sighash(
143
149
  transaction,
144
150
  sighashType,
145
151
  inputIndex,
146
152
  lockingScript,
147
- new bsv.crypto.BN(satoshis)
153
+ new BN(satoshis)
148
154
  );
149
155
  }
150
156
 
@@ -157,7 +163,7 @@ class CustomScriptHelper {
157
163
  if (typeof data === 'string') {
158
164
  data = Buffer.from(data, 'utf8');
159
165
  }
160
- return new bsv.Script().add(data);
166
+ return new Script().add(data);
161
167
  }
162
168
 
163
169
  /**
@@ -169,9 +175,9 @@ class CustomScriptHelper {
169
175
  if (typeof data === 'string') {
170
176
  data = Buffer.from(data, 'utf8');
171
177
  }
172
- return new bsv.Script()
173
- .add(bsv.Opcode.OP_FALSE)
174
- .add(bsv.Opcode.OP_RETURN)
178
+ return new Script()
179
+ .add(Opcode.OP_FALSE)
180
+ .add(Opcode.OP_RETURN)
175
181
  .add(data);
176
182
  }
177
183
 
@@ -199,17 +205,17 @@ class CustomScriptHelper {
199
205
  */
200
206
  static validateScript(unlockingScript, lockingScript, transaction, inputIndex) {
201
207
  try {
202
- const interpreter = new bsv.Script.Interpreter();
208
+ const interpreter = new Interpreter();
203
209
  return interpreter.verify(
204
210
  unlockingScript,
205
211
  lockingScript,
206
212
  transaction,
207
213
  inputIndex,
208
- bsv.Script.Interpreter.SCRIPT_VERIFY_P2SH |
209
- bsv.Script.Interpreter.SCRIPT_VERIFY_STRICTENC |
210
- bsv.Script.Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID |
211
- bsv.Script.Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES |
212
- bsv.Script.Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES
214
+ Interpreter.SCRIPT_VERIFY_P2SH |
215
+ Interpreter.SCRIPT_VERIFY_STRICTENC |
216
+ Interpreter.SCRIPT_ENABLE_SIGHASH_FORKID |
217
+ Interpreter.SCRIPT_ENABLE_MAGNETIC_OPCODES |
218
+ Interpreter.SCRIPT_ENABLE_MONOLITH_OPCODES
213
219
  );
214
220
  } catch (error) {
215
221
  console.error('Script validation error:', error.message);
@@ -225,7 +231,7 @@ class CustomScriptHelper {
225
231
  * @returns {Transaction} Transaction with ultra-low fees
226
232
  */
227
233
  static createLowFeeTransaction(utxos, outputs, feePerKb = 10) {
228
- let tx = new bsv.Transaction().feePerKb(feePerKb);
234
+ let tx = new Transaction().feePerKb(feePerKb);
229
235
 
230
236
  // Add inputs
231
237
  for (const utxo of utxos) {
@@ -242,8 +248,8 @@ class CustomScriptHelper {
242
248
  }
243
249
 
244
250
  // Common signature hash types
245
- CustomScriptHelper.SIGHASH_ALL = bsv.crypto.Signature.SIGHASH_ALL | bsv.crypto.Signature.SIGHASH_FORKID;
246
- CustomScriptHelper.SIGHASH_NONE = bsv.crypto.Signature.SIGHASH_NONE | bsv.crypto.Signature.SIGHASH_FORKID;
247
- CustomScriptHelper.SIGHASH_SINGLE = bsv.crypto.Signature.SIGHASH_SINGLE | bsv.crypto.Signature.SIGHASH_FORKID;
251
+ CustomScriptHelper.SIGHASH_ALL = Signature.SIGHASH_ALL | Signature.SIGHASH_FORKID;
252
+ CustomScriptHelper.SIGHASH_NONE = Signature.SIGHASH_NONE | Signature.SIGHASH_FORKID;
253
+ CustomScriptHelper.SIGHASH_SINGLE = Signature.SIGHASH_SINGLE | Signature.SIGHASH_FORKID;
248
254
 
249
255
  module.exports = CustomScriptHelper;
@@ -20,10 +20,9 @@ var { sha512, sha256 } = require('@noble/hashes/sha2.js')
20
20
  var { hmac } = require('@noble/hashes/hmac.js')
21
21
  var { cbc } = require('@noble/ciphers/aes.js')
22
22
 
23
- var bsv = require('../../')
24
- var PublicKey = bsv.PublicKey
25
- var $ = bsv.util.preconditions
26
- var Random = bsv.crypto.Random
23
+ var PublicKey = require('../publickey')
24
+ var $ = require('../util/preconditions')
25
+ var Random = require('../crypto/random')
27
26
 
28
27
  function buf (u8) { return Buffer.from(u8.buffer, u8.byteOffset, u8.byteLength) }
29
28
  function hmacSha256 (key, data) { return buf(hmac(sha256, key, data)) }
@@ -4,11 +4,9 @@
4
4
  // and byte-compatible with prior versions (locked by the golden known-answer
5
5
  // vector in test/ecies/electrum-ecies.js).
6
6
 
7
- var bsv = require('../../')
8
-
9
- var PublicKey = bsv.PublicKey
10
- var PrivateKey = bsv.PrivateKey
11
- var $ = bsv.util.preconditions
7
+ var PublicKey = require('../publickey')
8
+ var PrivateKey = require('../privatekey')
9
+ var $ = require('../util/preconditions')
12
10
  var bitcoreECIES = require('./bitcore-ecies')
13
11
  var errors = require('./errors')
14
12
 
@@ -45,7 +43,7 @@ var ECIES = function ECIES (opts, algorithm = 'BIE1') {
45
43
  if (!(this instanceof ECIES)) {
46
44
  return new ECIES(opts, algorithm)
47
45
  }
48
- this._privateKey = new bsv.PrivateKey()
46
+ this._privateKey = new PrivateKey()
49
47
  this.opts = opts || {}
50
48
  this.opts.ephemeralKey = true
51
49
  }
@@ -13,4 +13,4 @@ var spec = {
13
13
  }]
14
14
  }
15
15
 
16
- module.exports = require('../../').errors.extend(spec)
16
+ module.exports = require('../errors').extend(spec)
@@ -1,12 +1,12 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
3
+ var Random = require('../crypto/random')
4
4
  var DIDResolver = require('./did-resolver')
5
- var PrivateKey = bsv.PrivateKey
6
- var Hash = bsv.crypto.Hash
7
- var ECDSA = bsv.crypto.ECDSA
8
- var Signature = bsv.crypto.Signature
9
- var $ = bsv.util.preconditions
5
+ var PrivateKey = require('../privatekey')
6
+ var Hash = require('../crypto/hash')
7
+ var ECDSA = require('../crypto/ecdsa')
8
+ var Signature = require('../crypto/signature')
9
+ var $ = require('../util/preconditions')
10
10
  var _ = require('../util/_')
11
11
 
12
12
  /**
@@ -402,7 +402,7 @@ AttestationSigner.prototype.createOrganizationCredential = function(orgData, opt
402
402
  * @private
403
403
  */
404
404
  AttestationSigner.prototype._generateUUID = function() {
405
- var random = bsv.crypto.Random.getRandomBuffer(16)
405
+ var random = Random.getRandomBuffer(16)
406
406
 
407
407
  // Set version (4) and variant bits
408
408
  random[6] = (random[6] & 0x0f) | 0x40
@@ -1,13 +1,12 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
3
  var DIDResolver = require('./did-resolver')
5
4
  var AttestationSigner = require('./attestation-signer')
6
- var PublicKey = bsv.PublicKey
7
- var Hash = bsv.crypto.Hash
8
- var ECDSA = bsv.crypto.ECDSA
9
- var Signature = bsv.crypto.Signature
10
- var $ = bsv.util.preconditions
5
+ var PublicKey = require('../publickey')
6
+ var Hash = require('../crypto/hash')
7
+ var ECDSA = require('../crypto/ecdsa')
8
+ var Signature = require('../crypto/signature')
9
+ var $ = require('../util/preconditions')
11
10
 
12
11
  /**
13
12
  * AttestationVerifier
@@ -1,11 +1,12 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
- var PublicKey = bsv.PublicKey
5
- var PrivateKey = bsv.PrivateKey
6
- var Hash = bsv.crypto.Hash
7
- var $ = bsv.util.preconditions
8
- var errors = bsv.errors
3
+ var Signature = require('../crypto/signature')
4
+ var ECDSA = require('../crypto/ecdsa')
5
+ var PublicKey = require('../publickey')
6
+ var PrivateKey = require('../privatekey')
7
+ var Hash = require('../crypto/hash')
8
+ var $ = require('../util/preconditions')
9
+ var errors = require('../errors')
9
10
 
10
11
  /**
11
12
  * SmartLedger DID Resolver
@@ -272,8 +273,8 @@ DIDResolver.verifyOwnership = function(did, signature, message) {
272
273
  var publicKey = DIDResolver.getPublicKey(did)
273
274
  var messageHash = Hash.sha256(Buffer.isBuffer(message) ? message : Buffer.from(message, 'utf8'))
274
275
 
275
- var sig = bsv.crypto.Signature.fromString(signature)
276
- var ecdsa = new bsv.crypto.ECDSA()
276
+ var sig = Signature.fromString(signature)
277
+ var ecdsa = new ECDSA()
277
278
  ecdsa.hashbuf = messageHash
278
279
  ecdsa.pubkey = publicKey
279
280
  ecdsa.sig = sig
@@ -295,7 +296,7 @@ DIDResolver.signMessage = function(message, privateKey) {
295
296
 
296
297
  var messageHash = Hash.sha256(Buffer.isBuffer(message) ? message : Buffer.from(message, 'utf8'))
297
298
 
298
- var ecdsa = new bsv.crypto.ECDSA()
299
+ var ecdsa = new ECDSA()
299
300
  ecdsa.hashbuf = messageHash
300
301
  ecdsa.privkey = privateKey
301
302
  ecdsa.pubkey = privateKey.toPublicKey()
@@ -1,13 +1,14 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
- var Transaction = bsv.Transaction
5
- var Script = bsv.Script
6
- var PrivateKey = bsv.PrivateKey
7
- var Address = bsv.Address
8
- var Hash = bsv.crypto.Hash
9
- var SPV = bsv.SPV
10
- var $ = bsv.util.preconditions
3
+ var HDPrivateKey = require('../hdprivatekey')
4
+ var Mnemonic = require('../mnemonic')
5
+ var Transaction = require('../transaction')
6
+ var Script = require('../script')
7
+ var PrivateKey = require('../privatekey')
8
+ var Address = require('../address')
9
+ var Hash = require('../crypto/hash')
10
+ var SPV = require('../spv')
11
+ var $ = require('../util/preconditions')
11
12
 
12
13
  /**
13
14
  * SmartLedgerAnchor
@@ -246,7 +247,7 @@ var AMBIGUOUS_KEYS = ['d', 'seed', 'secret', 'key']
246
247
  function isWIF (str) {
247
248
  if (typeof str !== 'string' || str.length < 50 || str.length > 53) return false
248
249
  try {
249
- bsv.PrivateKey.fromWIF(str)
250
+ PrivateKey.fromWIF(str)
250
251
  return true
251
252
  } catch (e) { return false }
252
253
  }
@@ -255,7 +256,7 @@ function isWIF (str) {
255
256
  function isXprv (str) {
256
257
  if (typeof str !== 'string' || !/^(xprv|tprv)/.test(str)) return false
257
258
  try {
258
- bsv.HDPrivateKey.fromString(str)
259
+ HDPrivateKey.fromString(str)
259
260
  return true
260
261
  } catch (e) { return false }
261
262
  }
@@ -266,7 +267,7 @@ function isMnemonic (str) {
266
267
  var words = str.trim().split(/\s+/)
267
268
  if ([12, 15, 18, 21, 24].indexOf(words.length) === -1) return false
268
269
  try {
269
- return bsv.Mnemonic.isValid(str.trim())
270
+ return Mnemonic.isValid(str.trim())
270
271
  } catch (e) { return false }
271
272
  }
272
273
 
@@ -274,7 +275,7 @@ function isMnemonic (str) {
274
275
  function isHexScalar (str) {
275
276
  if (typeof str !== 'string' || !/^[0-9a-fA-F]{64}$/.test(str)) return false
276
277
  try {
277
- bsv.PrivateKey.fromHex(str)
278
+ PrivateKey.fromHex(str)
278
279
  return true
279
280
  } catch (e) { return false }
280
281
  }
@@ -1,10 +1,10 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
3
+ var Random = require('../crypto/random')
4
4
  var AttestationSigner = require('./attestation-signer')
5
- var Hash = bsv.crypto.Hash
6
- var BN = bsv.crypto.BN
7
- var $ = bsv.util.preconditions
5
+ var Hash = require('../crypto/hash')
6
+ var BN = require('../crypto/bn')
7
+ var $ = require('../util/preconditions')
8
8
 
9
9
  /**
10
10
  * ZKProver
@@ -43,7 +43,7 @@ function ZKProver(options) {
43
43
  * @returns {Object} Merkle tree data
44
44
  */
45
45
  ZKProver.createMerkleTree = function(credential, salt) {
46
- salt = salt || bsv.crypto.Random.getRandomBuffer(32).toString('hex')
46
+ salt = salt || Random.getRandomBuffer(32).toString('hex')
47
47
 
48
48
  $.checkArgument(credential && typeof credential === 'object', 'Invalid credential')
49
49
 
@@ -204,7 +204,7 @@ ZKProver.generateAgeProof = function(birthDate, minimumAge, salt) {
204
204
  $.checkArgument(birthDate instanceof Date, 'Birth date must be Date object')
205
205
  $.checkArgument(typeof minimumAge === 'number', 'Minimum age must be number')
206
206
 
207
- salt = salt || bsv.crypto.Random.getRandomBuffer(32).toString('hex')
207
+ salt = salt || Random.getRandomBuffer(32).toString('hex')
208
208
 
209
209
  var now = new Date()
210
210
  var ageInYears = Math.floor((now - birthDate) / (365.25 * 24 * 60 * 60 * 1000))
@@ -286,7 +286,7 @@ ZKProver.generateRangeProof = function(value, min, max, salt) {
286
286
  $.checkArgument(typeof max === 'number', 'Max must be number')
287
287
  $.checkArgument(value >= min && value <= max, 'Value not in range')
288
288
 
289
- salt = salt || bsv.crypto.Random.getRandomBuffer(32).toString('hex')
289
+ salt = salt || Random.getRandomBuffer(32).toString('hex')
290
290
 
291
291
  // Create commitment to value
292
292
  var commitment = Hash.sha256(Buffer.from(value.toString() + ':' + salt, 'utf8')).toString('hex')
@@ -459,7 +459,7 @@ ZKProver.generateMembershipProof = function(set, value, salt) {
459
459
  $.checkArgument(Array.isArray(set), 'Set must be array')
460
460
  $.checkArgument(set.includes(value), 'Value not in set')
461
461
 
462
- salt = salt || bsv.crypto.Random.getRandomBuffer(32).toString('hex')
462
+ salt = salt || Random.getRandomBuffer(32).toString('hex')
463
463
 
464
464
  // Create commitments to all set members
465
465
  var commitments = set.map(function(member) {
package/lib/ltp/anchor.js CHANGED
@@ -1,8 +1,7 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
- var Hash = bsv.crypto.Hash
5
- var $ = bsv.util.preconditions
3
+ var Hash = require('../crypto/hash')
4
+ var $ = require('../util/preconditions')
6
5
 
7
6
  /**
8
7
  * Legal Token Protocol - Blockchain Anchoring Primitives
package/lib/ltp/claim.js CHANGED
@@ -1,8 +1,7 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
- var Hash = bsv.crypto.Hash
5
- var $ = bsv.util.preconditions
3
+ var Hash = require('../crypto/hash')
4
+ var $ = require('../util/preconditions')
6
5
  var Id = require('../util/id')
7
6
 
8
7
  /**
package/lib/ltp/index.js CHANGED
@@ -7,9 +7,8 @@ var LTPProof = require('./proof')
7
7
  var LTPRegistry = require('./registry')
8
8
  var LTPObligation = require('./obligation')
9
9
 
10
- var bsv = require('../../')
11
- var PrivateKey = bsv.PrivateKey
12
- var $ = bsv.util.preconditions
10
+ var PrivateKey = require('../privatekey')
11
+ var $ = require('../util/preconditions')
13
12
 
14
13
  /**
15
14
  * Legal Token Protocol (LTP) - Main Interface
@@ -1,11 +1,11 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
- var Hash = bsv.crypto.Hash
5
- var ECDSA = bsv.crypto.ECDSA
6
- var Signature = bsv.crypto.Signature
7
- var PrivateKey = bsv.PrivateKey
8
- var $ = bsv.util.preconditions
3
+ var PublicKey = require('../publickey')
4
+ var Hash = require('../crypto/hash')
5
+ var ECDSA = require('../crypto/ecdsa')
6
+ var Signature = require('../crypto/signature')
7
+ var PrivateKey = require('../privatekey')
8
+ var $ = require('../util/preconditions')
9
9
  var Id = require('../util/id')
10
10
 
11
11
  /**
@@ -18,16 +18,16 @@ var Id = require('../util/id')
18
18
  function _resolveIssuerPublicKey (token, options) {
19
19
  options = options || {}
20
20
  if (options.issuerPublicKey) {
21
- return options.issuerPublicKey instanceof bsv.PublicKey
21
+ return options.issuerPublicKey instanceof PublicKey
22
22
  ? options.issuerPublicKey
23
- : bsv.PublicKey.fromString(options.issuerPublicKey)
23
+ : PublicKey.fromString(options.issuerPublicKey)
24
24
  }
25
25
  var did = token && token.issuer
26
26
  if (typeof did !== 'string') return null
27
27
  try {
28
28
  var identifier = did.split('#')[0].split(':')[2] // did:method:<identifier>[:...]
29
29
  if (!identifier) return null
30
- return bsv.PublicKey.fromString(identifier)
30
+ return PublicKey.fromString(identifier)
31
31
  } catch (e) {
32
32
  return null
33
33
  }
package/lib/ltp/proof.js CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
- var Hash = bsv.crypto.Hash
5
- var ECDSA = bsv.crypto.ECDSA
6
- var Signature = bsv.crypto.Signature
7
- var PrivateKey = bsv.PrivateKey
8
- var $ = bsv.util.preconditions
3
+ var PublicKey = require('../publickey')
4
+ var Hash = require('../crypto/hash')
5
+ var ECDSA = require('../crypto/ecdsa')
6
+ var Signature = require('../crypto/signature')
7
+ var PrivateKey = require('../privatekey')
8
+ var $ = require('../util/preconditions')
9
9
 
10
10
  /**
11
11
  * Legal Token Protocol - Proof Generation Primitives
@@ -129,7 +129,7 @@ var LTPProof = {
129
129
  var ecdsa = new ECDSA()
130
130
  ecdsa.hashbuf = tokenHash
131
131
  ecdsa.sig = signature
132
- ecdsa.pubkey = bsv.PublicKey.fromString(publicKey)
132
+ ecdsa.pubkey = PublicKey.fromString(publicKey)
133
133
 
134
134
  var isValid = ecdsa.verify() === true
135
135
 
@@ -1,10 +1,9 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
- var Hash = bsv.crypto.Hash
5
- var Address = bsv.Address
6
- var Transaction = bsv.Transaction
7
- var $ = bsv.util.preconditions
3
+ var Hash = require('../crypto/hash')
4
+ var Address = require('../address')
5
+ var Transaction = require('../transaction')
6
+ var $ = require('../util/preconditions')
8
7
  var Id = require('../util/id')
9
8
 
10
9
  /**
package/lib/ltp/right.js CHANGED
@@ -1,11 +1,11 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
- var Hash = bsv.crypto.Hash
5
- var ECDSA = bsv.crypto.ECDSA
6
- var Signature = bsv.crypto.Signature
7
- var PrivateKey = bsv.PrivateKey
8
- var $ = bsv.util.preconditions
3
+ var PublicKey = require('../publickey')
4
+ var Hash = require('../crypto/hash')
5
+ var ECDSA = require('../crypto/ecdsa')
6
+ var Signature = require('../crypto/signature')
7
+ var PrivateKey = require('../privatekey')
8
+ var $ = require('../util/preconditions')
9
9
  var _ = require('../util/_')
10
10
  var Id = require('../util/id')
11
11
 
@@ -21,16 +21,16 @@ var Id = require('../util/id')
21
21
  function _resolveIssuerPublicKey (token, options) {
22
22
  options = options || {}
23
23
  if (options.issuerPublicKey) {
24
- return options.issuerPublicKey instanceof bsv.PublicKey
24
+ return options.issuerPublicKey instanceof PublicKey
25
25
  ? options.issuerPublicKey
26
- : bsv.PublicKey.fromString(options.issuerPublicKey)
26
+ : PublicKey.fromString(options.issuerPublicKey)
27
27
  }
28
28
  var did = token && token.issuer
29
29
  if (typeof did !== 'string') return null
30
30
  try {
31
31
  var identifier = did.split('#')[0].split(':')[2] // did:method:<identifier>[:...]
32
32
  if (!identifier) return null
33
- return bsv.PublicKey.fromString(identifier)
33
+ return PublicKey.fromString(identifier)
34
34
  } catch (e) {
35
35
  return null
36
36
  }
@@ -647,9 +647,9 @@ var RightToken = {
647
647
  return { valid: false, errors: errors }
648
648
  }
649
649
 
650
- var pubKey = publicKey instanceof bsv.PublicKey
650
+ var pubKey = publicKey instanceof PublicKey
651
651
  ? publicKey
652
- : bsv.PublicKey.fromString(publicKey)
652
+ : PublicKey.fromString(publicKey)
653
653
 
654
654
  // Recompute the canonical hash and confirm integrity.
655
655
  var canonicalToken = this._canonicalizeToken(token)
@@ -1,4 +1,5 @@
1
- var bsv = require('../../')
2
- bsv.Message = require('./message')
3
-
4
- module.exports = bsv.Message
1
+ // Previously this module required the package root and registered itself onto
2
+ // it (`bsv.Message = require('./message')`), which made lib/ depend on index.js.
3
+ // The registration was redundant — index.js assigns bsv.Message itself — so
4
+ // this is now a plain re-export.
5
+ module.exports = require('./message')
@@ -1,16 +1,16 @@
1
1
  'use strict'
2
2
 
3
- var bsv = require('../../')
4
- var _ = bsv.deps._
5
- var PrivateKey = bsv.PrivateKey
6
- var PublicKey = bsv.PublicKey
7
- var Address = bsv.Address
8
- var BufferWriter = bsv.encoding.BufferWriter
9
- var ECDSA = bsv.crypto.ECDSA
10
- var Signature = bsv.crypto.Signature
11
- var sha256sha256 = bsv.crypto.Hash.sha256sha256
12
- var JSUtil = bsv.util.js
13
- var $ = bsv.util.preconditions
3
+ var Hash = require('../crypto/hash')
4
+ var _ = require('../util/_')
5
+ var PrivateKey = require('../privatekey')
6
+ var PublicKey = require('../publickey')
7
+ var Address = require('../address')
8
+ var BufferWriter = require('../encoding/bufferwriter')
9
+ var ECDSA = require('../crypto/ecdsa')
10
+ var Signature = require('../crypto/signature')
11
+ var sha256sha256 = Hash.sha256sha256
12
+ var JSUtil = require('../util/js')
13
+ var $ = require('../util/preconditions')
14
14
 
15
15
  /**
16
16
  * constructs a new message to sign and verify.