cashscript 0.7.0-next.0 → 0.7.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 (45) hide show
  1. package/dist/main/Argument.d.ts +1 -1
  2. package/dist/main/Argument.js +12 -12
  3. package/dist/main/Contract.d.ts +4 -4
  4. package/dist/main/Contract.js +15 -15
  5. package/dist/main/Errors.js +2 -2
  6. package/dist/main/SignatureTemplate.d.ts +1 -1
  7. package/dist/main/SignatureTemplate.js +3 -3
  8. package/dist/main/Transaction.d.ts +3 -3
  9. package/dist/main/Transaction.js +36 -37
  10. package/dist/main/index.d.ts +7 -7
  11. package/dist/main/index.js +22 -14
  12. package/dist/main/interfaces.d.ts +1 -1
  13. package/dist/main/network/BitboxNetworkProvider.d.ts +2 -2
  14. package/dist/main/network/BitcoinRpcNetworkProvider.d.ts +2 -2
  15. package/dist/main/network/ElectrumNetworkProvider.d.ts +2 -2
  16. package/dist/main/network/ElectrumNetworkProvider.js +9 -9
  17. package/dist/main/network/FullStackNetworkProvider.d.ts +2 -2
  18. package/dist/main/network/NetworkProvider.d.ts +1 -1
  19. package/dist/main/network/index.d.ts +5 -5
  20. package/dist/main/network/index.js +8 -8
  21. package/dist/main/utils.d.ts +2 -2
  22. package/dist/main/utils.js +33 -33
  23. package/dist/module/Argument.d.ts +1 -1
  24. package/dist/module/Argument.js +2 -2
  25. package/dist/module/Contract.d.ts +4 -4
  26. package/dist/module/Contract.js +5 -5
  27. package/dist/module/Errors.js +1 -1
  28. package/dist/module/SignatureTemplate.d.ts +1 -1
  29. package/dist/module/SignatureTemplate.js +1 -1
  30. package/dist/module/Transaction.d.ts +3 -3
  31. package/dist/module/Transaction.js +6 -7
  32. package/dist/module/index.d.ts +7 -7
  33. package/dist/module/index.js +6 -6
  34. package/dist/module/interfaces.d.ts +1 -1
  35. package/dist/module/network/BitboxNetworkProvider.d.ts +2 -2
  36. package/dist/module/network/BitcoinRpcNetworkProvider.d.ts +2 -2
  37. package/dist/module/network/ElectrumNetworkProvider.d.ts +2 -2
  38. package/dist/module/network/ElectrumNetworkProvider.js +2 -2
  39. package/dist/module/network/FullStackNetworkProvider.d.ts +2 -2
  40. package/dist/module/network/NetworkProvider.d.ts +1 -1
  41. package/dist/module/network/index.d.ts +5 -5
  42. package/dist/module/network/index.js +4 -4
  43. package/dist/module/utils.d.ts +2 -2
  44. package/dist/module/utils.js +3 -3
  45. package/package.json +3 -3
@@ -1,3 +1,3 @@
1
- import SignatureTemplate from './SignatureTemplate';
1
+ import SignatureTemplate from './SignatureTemplate.js';
2
2
  export declare type Argument = number | bigint | boolean | string | Uint8Array | SignatureTemplate;
3
3
  export declare function encodeArgument(argument: Argument, typeStr: string): Uint8Array | SignatureTemplate;
@@ -6,36 +6,36 @@ Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.encodeArgument = void 0;
7
7
  const libauth_1 = require("@bitauth/libauth");
8
8
  const utils_1 = require("@cashscript/utils");
9
- const Errors_1 = require("./Errors");
10
- const SignatureTemplate_1 = __importDefault(require("./SignatureTemplate"));
9
+ const Errors_js_1 = require("./Errors.js");
10
+ const SignatureTemplate_js_1 = __importDefault(require("./SignatureTemplate.js"));
11
11
  function encodeArgument(argument, typeStr) {
12
- let type = utils_1.parseType(typeStr);
12
+ let type = (0, utils_1.parseType)(typeStr);
13
13
  if (type === utils_1.PrimitiveType.BOOL) {
14
14
  if (typeof argument !== 'boolean') {
15
- throw new Errors_1.TypeError(typeof argument, type);
15
+ throw new Errors_js_1.TypeError(typeof argument, type);
16
16
  }
17
- return utils_1.encodeBool(argument);
17
+ return (0, utils_1.encodeBool)(argument);
18
18
  }
19
19
  if (type === utils_1.PrimitiveType.INT) {
20
20
  if (typeof argument !== 'number' && typeof argument !== 'bigint') {
21
- throw new Errors_1.TypeError(typeof argument, type);
21
+ throw new Errors_js_1.TypeError(typeof argument, type);
22
22
  }
23
- return utils_1.encodeInt(argument);
23
+ return (0, utils_1.encodeInt)(argument);
24
24
  }
25
25
  if (type === utils_1.PrimitiveType.STRING) {
26
26
  if (typeof argument !== 'string') {
27
- throw new Errors_1.TypeError(typeof argument, type);
27
+ throw new Errors_js_1.TypeError(typeof argument, type);
28
28
  }
29
- return utils_1.encodeString(argument);
29
+ return (0, utils_1.encodeString)(argument);
30
30
  }
31
- if (type === utils_1.PrimitiveType.SIG && argument instanceof SignatureTemplate_1.default)
31
+ if (type === utils_1.PrimitiveType.SIG && argument instanceof SignatureTemplate_js_1.default)
32
32
  return argument;
33
33
  // Convert hex string to Uint8Array
34
34
  if (typeof argument === 'string') {
35
35
  if (argument.startsWith('0x')) {
36
36
  argument = argument.slice(2);
37
37
  }
38
- argument = libauth_1.hexToBin(argument);
38
+ argument = (0, libauth_1.hexToBin)(argument);
39
39
  }
40
40
  if (!(argument instanceof Uint8Array)) {
41
41
  throw Error(`Value for type ${type} should be a Uint8Array or hex string`);
@@ -52,7 +52,7 @@ function encodeArgument(argument, typeStr) {
52
52
  }
53
53
  // Bounded bytes types require a correctly sized argument
54
54
  if (type instanceof utils_1.BytesType && type.bound && argument.byteLength !== type.bound) {
55
- throw new Errors_1.TypeError(`bytes${argument.byteLength}`, type);
55
+ throw new Errors_js_1.TypeError(`bytes${argument.byteLength}`, type);
56
56
  }
57
57
  return argument;
58
58
  }
@@ -1,8 +1,8 @@
1
1
  import { Artifact } from '@cashscript/utils';
2
- import { Transaction } from './Transaction';
3
- import { Argument } from './Argument';
4
- import { Utxo } from './interfaces';
5
- import NetworkProvider from './network/NetworkProvider';
2
+ import { Transaction } from './Transaction.js';
3
+ import { Argument } from './Argument.js';
4
+ import { Utxo } from './interfaces.js';
5
+ import NetworkProvider from './network/NetworkProvider.js';
6
6
  export declare class Contract {
7
7
  private artifact;
8
8
  private provider;
@@ -15,13 +15,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Contract = void 0;
16
16
  const libauth_1 = require("@bitauth/libauth");
17
17
  const utils_1 = require("@cashscript/utils");
18
- const Transaction_1 = require("./Transaction");
19
- const Argument_1 = require("./Argument");
20
- const utils_2 = require("./utils");
21
- const SignatureTemplate_1 = __importDefault(require("./SignatureTemplate"));
22
- const network_1 = require("./network");
18
+ const Transaction_js_1 = require("./Transaction.js");
19
+ const Argument_js_1 = require("./Argument.js");
20
+ const utils_js_1 = require("./utils.js");
21
+ const SignatureTemplate_js_1 = __importDefault(require("./SignatureTemplate.js"));
22
+ const index_js_1 = require("./network/index.js");
23
23
  class Contract {
24
- constructor(artifact, constructorArgs, provider = new network_1.ElectrumNetworkProvider()) {
24
+ constructor(artifact, constructorArgs, provider = new index_js_1.ElectrumNetworkProvider()) {
25
25
  this.artifact = artifact;
26
26
  this.provider = provider;
27
27
  const expectedProperties = ['abi', 'bytecode', 'constructorInputs', 'contractName'];
@@ -33,13 +33,13 @@ class Contract {
33
33
  }
34
34
  // Encode arguments (this also performs type checking)
35
35
  const encodedArgs = constructorArgs
36
- .map((arg, i) => Argument_1.encodeArgument(arg, artifact.constructorInputs[i].type))
36
+ .map((arg, i) => (0, Argument_js_1.encodeArgument)(arg, artifact.constructorInputs[i].type))
37
37
  .reverse();
38
38
  // Check there's no signature templates in the constructor
39
- if (encodedArgs.some((arg) => arg instanceof SignatureTemplate_1.default)) {
39
+ if (encodedArgs.some((arg) => arg instanceof SignatureTemplate_js_1.default)) {
40
40
  throw new Error('Cannot use signatures in constructor');
41
41
  }
42
- this.redeemScript = utils_1.generateRedeemScript(utils_1.asmToScript(this.artifact.bytecode), encodedArgs);
42
+ this.redeemScript = (0, utils_1.generateRedeemScript)((0, utils_1.asmToScript)(this.artifact.bytecode), encodedArgs);
43
43
  // Populate the functions object with the contract's functions
44
44
  // (with a special case for single function, which has no "function selector")
45
45
  this.functions = {};
@@ -53,9 +53,9 @@ class Contract {
53
53
  });
54
54
  }
55
55
  this.name = artifact.contractName;
56
- this.address = utils_2.scriptToAddress(this.redeemScript, this.provider.network);
57
- this.bytesize = utils_1.calculateBytesize(this.redeemScript);
58
- this.opcount = utils_1.countOpcodes(this.redeemScript);
56
+ this.address = (0, utils_js_1.scriptToAddress)(this.redeemScript, this.provider.network);
57
+ this.bytesize = (0, utils_1.calculateBytesize)(this.redeemScript);
58
+ this.opcount = (0, utils_1.countOpcodes)(this.redeemScript);
59
59
  }
60
60
  getBalance() {
61
61
  return __awaiter(this, void 0, void 0, function* () {
@@ -69,7 +69,7 @@ class Contract {
69
69
  });
70
70
  }
71
71
  getRedeemScriptHex() {
72
- return libauth_1.binToHex(utils_1.scriptToBytecode(this.redeemScript));
72
+ return (0, libauth_1.binToHex)((0, utils_1.scriptToBytecode)(this.redeemScript));
73
73
  }
74
74
  createFunction(abiFunction, selector) {
75
75
  return (...args) => {
@@ -78,8 +78,8 @@ class Contract {
78
78
  }
79
79
  // Encode passed args (this also performs type checking)
80
80
  const encodedArgs = args
81
- .map((arg, i) => Argument_1.encodeArgument(arg, abiFunction.inputs[i].type));
82
- return new Transaction_1.Transaction(this.address, this.provider, this.redeemScript, abiFunction, encodedArgs, selector);
81
+ .map((arg, i) => (0, Argument_js_1.encodeArgument)(arg, abiFunction.inputs[i].type));
82
+ return new Transaction_js_1.Transaction(this.address, this.provider, this.redeemScript, abiFunction, encodedArgs, selector);
83
83
  };
84
84
  }
85
85
  }
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Reason = exports.FailedSigCheckError = exports.FailedTimeCheckError = exports.FailedRequireError = exports.FailedTransactionError = exports.OutputSatoshisTooSmallError = exports.TypeError = void 0;
4
- const constants_1 = require("./constants");
4
+ const constants_js_1 = require("./constants.js");
5
5
  class TypeError extends Error {
6
6
  constructor(actual, expected) {
7
7
  super(`Found type '${actual}' where type '${expected.toString()}' was expected`);
@@ -10,7 +10,7 @@ class TypeError extends Error {
10
10
  exports.TypeError = TypeError;
11
11
  class OutputSatoshisTooSmallError extends Error {
12
12
  constructor(satoshis) {
13
- super(`Tried to add an output with ${satoshis} satoshis, which is less than the DUST limit (${constants_1.DUST_LIMIT})`);
13
+ super(`Tried to add an output with ${satoshis} satoshis, which is less than the DUST limit (${constants_js_1.DUST_LIMIT})`);
14
14
  }
15
15
  }
16
16
  exports.OutputSatoshisTooSmallError = OutputSatoshisTooSmallError;
@@ -1,5 +1,5 @@
1
1
  import { Secp256k1 } from '@bitauth/libauth';
2
- import { HashType } from './interfaces';
2
+ import { HashType } from './interfaces.js';
3
3
  export default class SignatureTemplate {
4
4
  private hashtype;
5
5
  private privateKey;
@@ -2,9 +2,9 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const libauth_1 = require("@bitauth/libauth");
4
4
  const utils_1 = require("@cashscript/utils");
5
- const interfaces_1 = require("./interfaces");
5
+ const interfaces_js_1 = require("./interfaces.js");
6
6
  class SignatureTemplate {
7
- constructor(signer, hashtype = interfaces_1.HashType.SIGHASH_ALL) {
7
+ constructor(signer, hashtype = interfaces_js_1.HashType.SIGHASH_ALL) {
8
8
  this.hashtype = hashtype;
9
9
  if (isKeypair(signer)) {
10
10
  const wif = signer.toWIF();
@@ -33,7 +33,7 @@ function isKeypair(obj) {
33
33
  return typeof obj.toWIF === 'function';
34
34
  }
35
35
  function decodeWif(wif) {
36
- const result = libauth_1.decodePrivateKeyWif({ hash: utils_1.sha256 }, wif);
36
+ const result = (0, libauth_1.decodePrivateKeyWif)({ hash: utils_1.sha256 }, wif);
37
37
  if (typeof result === 'string') {
38
38
  throw new Error(result);
39
39
  }
@@ -1,7 +1,7 @@
1
1
  import { AbiFunction, Script } from '@cashscript/utils';
2
- import { Utxo, Recipient, TransactionDetails } from './interfaces';
3
- import NetworkProvider from './network/NetworkProvider';
4
- import SignatureTemplate from './SignatureTemplate';
2
+ import { Utxo, Recipient, TransactionDetails } from './interfaces.js';
3
+ import NetworkProvider from './network/NetworkProvider.js';
4
+ import SignatureTemplate from './SignatureTemplate.js';
5
5
  export declare class Transaction {
6
6
  private address;
7
7
  private provider;
@@ -16,10 +16,10 @@ exports.Transaction = void 0;
16
16
  const libauth_1 = require("@bitauth/libauth");
17
17
  const delay_1 = __importDefault(require("delay"));
18
18
  const utils_1 = require("@cashscript/utils");
19
- const interfaces_1 = require("./interfaces");
20
- const utils_2 = require("./utils");
21
- const constants_1 = require("./constants");
22
- const SignatureTemplate_1 = __importDefault(require("./SignatureTemplate"));
19
+ const interfaces_js_1 = require("./interfaces.js");
20
+ const utils_js_1 = require("./utils.js");
21
+ const constants_js_1 = require("./constants.js");
22
+ const SignatureTemplate_js_1 = __importDefault(require("./SignatureTemplate.js"));
23
23
  const bip68 = require('bip68');
24
24
  class Transaction {
25
25
  constructor(address, provider, redeemScript, abiFunction, args, selector) {
@@ -33,7 +33,7 @@ class Transaction {
33
33
  this.outputs = [];
34
34
  this.sequence = 0xfffffffe;
35
35
  this.feePerByte = 1.0;
36
- this.minChange = constants_1.DUST_LIMIT;
36
+ this.minChange = constants_js_1.DUST_LIMIT;
37
37
  }
38
38
  from(inputOrInputs) {
39
39
  if (!Array.isArray(inputOrInputs)) {
@@ -55,14 +55,14 @@ class Transaction {
55
55
  return this.to([{ to: toOrOutputs, amount }]);
56
56
  }
57
57
  if (Array.isArray(toOrOutputs) && amount === undefined) {
58
- toOrOutputs.forEach(utils_2.validateRecipient);
58
+ toOrOutputs.forEach(utils_js_1.validateRecipient);
59
59
  this.outputs = this.outputs.concat(toOrOutputs);
60
60
  return this;
61
61
  }
62
62
  throw new Error('Incorrect arguments passed to function \'to\'');
63
63
  }
64
64
  withOpReturn(chunks) {
65
- this.outputs.push(utils_2.createOpReturnOutput(chunks));
65
+ this.outputs.push((0, utils_js_1.createOpReturnOutput)(chunks));
66
66
  return this;
67
67
  }
68
68
  withAge(age) {
@@ -93,19 +93,19 @@ class Transaction {
93
93
  return __awaiter(this, void 0, void 0, function* () {
94
94
  this.locktime = (_a = this.locktime) !== null && _a !== void 0 ? _a : yield this.provider.getBlockHeight();
95
95
  yield this.setInputsAndOutputs();
96
- const secp256k1 = yield libauth_1.instantiateSecp256k1();
97
- const bytecode = utils_1.scriptToBytecode(this.redeemScript);
96
+ const secp256k1 = yield (0, libauth_1.instantiateSecp256k1)();
97
+ const bytecode = (0, utils_1.scriptToBytecode)(this.redeemScript);
98
98
  const inputs = this.inputs.map((utxo) => ({
99
99
  outpointIndex: utxo.vout,
100
- outpointTransactionHash: libauth_1.hexToBin(utxo.txid),
100
+ outpointTransactionHash: (0, libauth_1.hexToBin)(utxo.txid),
101
101
  sequenceNumber: this.sequence,
102
102
  unlockingBytecode: new Uint8Array(),
103
103
  }));
104
104
  const outputs = this.outputs.map((output) => {
105
105
  const lockingBytecode = typeof output.to === 'string'
106
- ? utils_2.addressToLockScript(output.to)
106
+ ? (0, utils_js_1.addressToLockScript)(output.to)
107
107
  : output.to;
108
- const satoshis = libauth_1.bigIntToBinUint64LE(BigInt(output.amount));
108
+ const satoshis = (0, libauth_1.bigIntToBinUint64LE)(BigInt(output.amount));
109
109
  return { lockingBytecode, satoshis };
110
110
  });
111
111
  const transaction = {
@@ -117,40 +117,40 @@ class Transaction {
117
117
  const inputScripts = [];
118
118
  this.inputs.forEach((utxo, i) => {
119
119
  // UTXO's with signature templates are signed using P2PKH
120
- if (interfaces_1.isSignableUtxo(utxo)) {
120
+ if ((0, interfaces_js_1.isSignableUtxo)(utxo)) {
121
121
  const pubkey = utxo.template.getPublicKey(secp256k1);
122
- const pubkeyHash = utils_1.hash160(pubkey);
122
+ const pubkeyHash = (0, utils_1.hash160)(pubkey);
123
123
  const addressContents = { payload: pubkeyHash, type: libauth_1.AddressType.p2pkh };
124
- const prevOutScript = libauth_1.addressContentsToLockingBytecode(addressContents);
124
+ const prevOutScript = (0, libauth_1.addressContentsToLockingBytecode)(addressContents);
125
125
  const hashtype = utxo.template.getHashType();
126
- const preimage = utils_2.createSighashPreimage(transaction, utxo, i, prevOutScript, hashtype);
127
- const sighash = utils_1.hash256(preimage);
126
+ const preimage = (0, utils_js_1.createSighashPreimage)(transaction, utxo, i, prevOutScript, hashtype);
127
+ const sighash = (0, utils_1.hash256)(preimage);
128
128
  const signature = utxo.template.generateSignature(sighash, secp256k1);
129
- const inputScript = utils_1.scriptToBytecode([signature, pubkey]);
129
+ const inputScript = (0, utils_1.scriptToBytecode)([signature, pubkey]);
130
130
  inputScripts.push(inputScript);
131
131
  return;
132
132
  }
133
133
  let covenantHashType = -1;
134
134
  const completeArgs = this.args.map((arg) => {
135
- if (!(arg instanceof SignatureTemplate_1.default))
135
+ if (!(arg instanceof SignatureTemplate_js_1.default))
136
136
  return arg;
137
137
  // First signature is used for sighash preimage (maybe not the best way)
138
138
  if (covenantHashType < 0)
139
139
  covenantHashType = arg.getHashType();
140
- const preimage = utils_2.createSighashPreimage(transaction, utxo, i, bytecode, arg.getHashType());
141
- const sighash = utils_1.hash256(preimage);
140
+ const preimage = (0, utils_js_1.createSighashPreimage)(transaction, utxo, i, bytecode, arg.getHashType());
141
+ const sighash = (0, utils_1.hash256)(preimage);
142
142
  return arg.generateSignature(sighash, secp256k1);
143
143
  });
144
144
  const preimage = this.abiFunction.covenant
145
- ? utils_2.createSighashPreimage(transaction, utxo, i, bytecode, covenantHashType)
145
+ ? (0, utils_js_1.createSighashPreimage)(transaction, utxo, i, bytecode, covenantHashType)
146
146
  : undefined;
147
- const inputScript = utils_2.createInputScript(this.redeemScript, completeArgs, this.selector, preimage);
147
+ const inputScript = (0, utils_js_1.createInputScript)(this.redeemScript, completeArgs, this.selector, preimage);
148
148
  inputScripts.push(inputScript);
149
149
  });
150
150
  inputScripts.forEach((script, i) => {
151
151
  transaction.inputs[i].unlockingBytecode = script;
152
152
  });
153
- return libauth_1.binToHex(libauth_1.encodeTransaction(transaction));
153
+ return (0, libauth_1.binToHex)((0, libauth_1.encodeTransaction)(transaction));
154
154
  });
155
155
  }
156
156
  send(raw) {
@@ -163,19 +163,19 @@ class Transaction {
163
163
  }
164
164
  catch (e) {
165
165
  const reason = (_a = e.error) !== null && _a !== void 0 ? _a : e.message;
166
- throw utils_2.buildError(reason, utils_2.meep(tx, this.inputs, this.redeemScript));
166
+ throw (0, utils_js_1.buildError)(reason, (0, utils_js_1.meep)(tx, this.inputs, this.redeemScript));
167
167
  }
168
168
  });
169
169
  }
170
170
  getTxDetails(txid, raw) {
171
171
  return __awaiter(this, void 0, void 0, function* () {
172
172
  for (let retries = 0; retries < 1200; retries += 1) {
173
- yield delay_1.default(500);
173
+ yield (0, delay_1.default)(500);
174
174
  try {
175
175
  const hex = yield this.provider.getRawTransaction(txid);
176
176
  if (raw)
177
177
  return hex;
178
- const libauthTransaction = libauth_1.decodeTransaction(libauth_1.hexToBin(hex));
178
+ const libauthTransaction = (0, libauth_1.decodeTransaction)((0, libauth_1.hexToBin)(hex));
179
179
  return Object.assign(Object.assign({}, libauthTransaction), { txid, hex });
180
180
  }
181
181
  catch (ignored) {
@@ -189,30 +189,29 @@ class Transaction {
189
189
  meep() {
190
190
  return __awaiter(this, void 0, void 0, function* () {
191
191
  const tx = yield this.build();
192
- return utils_2.meep(tx, this.inputs, this.redeemScript);
192
+ return (0, utils_js_1.meep)(tx, this.inputs, this.redeemScript);
193
193
  });
194
194
  }
195
195
  setInputsAndOutputs() {
196
+ var _a;
196
197
  return __awaiter(this, void 0, void 0, function* () {
197
198
  if (this.outputs.length === 0) {
198
199
  throw Error('Attempted to build a transaction without outputs');
199
200
  }
200
201
  // Replace all SignatureTemplate with 65-length placeholder Uint8Arrays
201
- const placeholderArgs = this.args.map((arg) => (arg instanceof SignatureTemplate_1.default ? utils_1.placeholder(65) : arg));
202
+ const placeholderArgs = this.args.map((arg) => (arg instanceof SignatureTemplate_js_1.default ? (0, utils_1.placeholder)(65) : arg));
202
203
  // Create a placeholder preimage of the correct size
203
204
  const placeholderPreimage = this.abiFunction.covenant
204
- ? utils_1.placeholder(utils_2.getPreimageSize(utils_1.scriptToBytecode(this.redeemScript)))
205
+ ? (0, utils_1.placeholder)((0, utils_js_1.getPreimageSize)((0, utils_1.scriptToBytecode)(this.redeemScript)))
205
206
  : undefined;
206
207
  // Create a placeholder input script for size calculation using the placeholder
207
208
  // arguments and correctly sized placeholder preimage
208
- const placeholderScript = utils_2.createInputScript(this.redeemScript, placeholderArgs, this.selector, placeholderPreimage);
209
+ const placeholderScript = (0, utils_js_1.createInputScript)(this.redeemScript, placeholderArgs, this.selector, placeholderPreimage);
209
210
  // Add one extra byte per input to over-estimate tx-in count
210
- const inputSize = utils_2.getInputSize(placeholderScript) + 1;
211
+ const inputSize = (0, utils_js_1.getInputSize)(placeholderScript) + 1;
211
212
  // Calculate amount to send and base fee (excluding additional fees per UTXO)
212
213
  const amount = this.outputs.reduce((acc, output) => acc + output.amount, 0);
213
- let fee = this.hardcodedFee
214
- ? this.hardcodedFee
215
- : utils_2.getTxSizeWithoutInputs(this.outputs) * this.feePerByte;
214
+ let fee = (_a = this.hardcodedFee) !== null && _a !== void 0 ? _a : (0, utils_js_1.getTxSizeWithoutInputs)(this.outputs) * this.feePerByte;
216
215
  // Select and gather UTXOs and calculate fees and available funds
217
216
  let satsAvailable = 0;
218
217
  if (this.inputs.length > 0) {
@@ -246,10 +245,10 @@ class Transaction {
246
245
  }
247
246
  // Account for the fee of a change output
248
247
  if (!this.hardcodedFee) {
249
- change -= constants_1.P2SH_OUTPUT_SIZE;
248
+ change -= constants_js_1.P2SH_OUTPUT_SIZE;
250
249
  }
251
250
  // Add a change output if applicable
252
- if (change >= constants_1.DUST_LIMIT && change >= this.minChange) {
251
+ if (change >= constants_js_1.DUST_LIMIT && change >= this.minChange) {
253
252
  this.outputs.push({ to: this.address, amount: change });
254
253
  }
255
254
  });
@@ -1,9 +1,9 @@
1
- export { Contract } from './Contract';
2
- export { Transaction } from './Transaction';
3
- export { Argument } from './Argument';
4
- export { default as SignatureTemplate } from './SignatureTemplate';
1
+ export { Contract } from './Contract.js';
2
+ export { Transaction } from './Transaction.js';
3
+ export { Argument } from './Argument.js';
4
+ export { default as SignatureTemplate } from './SignatureTemplate.js';
5
5
  export { Artifact, AbiFunction, AbiInput } from '@cashscript/utils';
6
6
  export * as utils from '@cashscript/utils';
7
- export { Utxo, Recipient, SignatureAlgorithm, HashType, Network, } from './interfaces';
8
- export * from './Errors';
9
- export * from './network';
7
+ export { Utxo, Recipient, SignatureAlgorithm, HashType, Network, } from './interfaces.js';
8
+ export * from './Errors.js';
9
+ export { NetworkProvider, BitboxNetworkProvider, BitcoinRpcNetworkProvider, ElectrumNetworkProvider, FullStackNetworkProvider, } from './network/index.js';
@@ -1,7 +1,11 @@
1
1
  "use strict";
2
2
  var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
3
  if (k2 === undefined) k2 = k;
4
- Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } });
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
5
9
  }) : (function(o, m, k, k2) {
6
10
  if (k2 === undefined) k2 = k;
7
11
  o[k2] = m[k];
@@ -25,18 +29,22 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
25
29
  return (mod && mod.__esModule) ? mod : { "default": mod };
26
30
  };
27
31
  Object.defineProperty(exports, "__esModule", { value: true });
28
- exports.Network = exports.HashType = exports.SignatureAlgorithm = exports.utils = exports.SignatureTemplate = exports.Transaction = exports.Contract = void 0;
29
- var Contract_1 = require("./Contract");
30
- Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return Contract_1.Contract; } });
31
- var Transaction_1 = require("./Transaction");
32
- Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return Transaction_1.Transaction; } });
33
- var SignatureTemplate_1 = require("./SignatureTemplate");
34
- Object.defineProperty(exports, "SignatureTemplate", { enumerable: true, get: function () { return __importDefault(SignatureTemplate_1).default; } });
32
+ exports.FullStackNetworkProvider = exports.ElectrumNetworkProvider = exports.BitcoinRpcNetworkProvider = exports.BitboxNetworkProvider = exports.Network = exports.HashType = exports.SignatureAlgorithm = exports.utils = exports.SignatureTemplate = exports.Transaction = exports.Contract = void 0;
33
+ var Contract_js_1 = require("./Contract.js");
34
+ Object.defineProperty(exports, "Contract", { enumerable: true, get: function () { return Contract_js_1.Contract; } });
35
+ var Transaction_js_1 = require("./Transaction.js");
36
+ Object.defineProperty(exports, "Transaction", { enumerable: true, get: function () { return Transaction_js_1.Transaction; } });
37
+ var SignatureTemplate_js_1 = require("./SignatureTemplate.js");
38
+ Object.defineProperty(exports, "SignatureTemplate", { enumerable: true, get: function () { return __importDefault(SignatureTemplate_js_1).default; } });
35
39
  exports.utils = __importStar(require("@cashscript/utils"));
36
- var interfaces_1 = require("./interfaces");
37
- Object.defineProperty(exports, "SignatureAlgorithm", { enumerable: true, get: function () { return interfaces_1.SignatureAlgorithm; } });
38
- Object.defineProperty(exports, "HashType", { enumerable: true, get: function () { return interfaces_1.HashType; } });
39
- Object.defineProperty(exports, "Network", { enumerable: true, get: function () { return interfaces_1.Network; } });
40
- __exportStar(require("./Errors"), exports);
41
- __exportStar(require("./network"), exports);
40
+ var interfaces_js_1 = require("./interfaces.js");
41
+ Object.defineProperty(exports, "SignatureAlgorithm", { enumerable: true, get: function () { return interfaces_js_1.SignatureAlgorithm; } });
42
+ Object.defineProperty(exports, "HashType", { enumerable: true, get: function () { return interfaces_js_1.HashType; } });
43
+ Object.defineProperty(exports, "Network", { enumerable: true, get: function () { return interfaces_js_1.Network; } });
44
+ __exportStar(require("./Errors.js"), exports);
45
+ var index_js_1 = require("./network/index.js");
46
+ Object.defineProperty(exports, "BitboxNetworkProvider", { enumerable: true, get: function () { return index_js_1.BitboxNetworkProvider; } });
47
+ Object.defineProperty(exports, "BitcoinRpcNetworkProvider", { enumerable: true, get: function () { return index_js_1.BitcoinRpcNetworkProvider; } });
48
+ Object.defineProperty(exports, "ElectrumNetworkProvider", { enumerable: true, get: function () { return index_js_1.ElectrumNetworkProvider; } });
49
+ Object.defineProperty(exports, "FullStackNetworkProvider", { enumerable: true, get: function () { return index_js_1.FullStackNetworkProvider; } });
42
50
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import { Transaction } from '@bitauth/libauth';
2
- import SignatureTemplate from './SignatureTemplate';
2
+ import type SignatureTemplate from './SignatureTemplate.js';
3
3
  export interface Utxo {
4
4
  txid: string;
5
5
  vout: number;
@@ -1,5 +1,5 @@
1
- import { Utxo, Network } from '../interfaces';
2
- import NetworkProvider from './NetworkProvider';
1
+ import { Utxo, Network } from '../interfaces.js';
2
+ import NetworkProvider from './NetworkProvider.js';
3
3
  export default class BitboxNetworkProvider implements NetworkProvider {
4
4
  network: Network;
5
5
  private bitbox;
@@ -1,5 +1,5 @@
1
- import { Utxo, Network } from '../interfaces';
2
- import NetworkProvider from './NetworkProvider';
1
+ import { Utxo, Network } from '../interfaces.js';
2
+ import NetworkProvider from './NetworkProvider.js';
3
3
  declare const RpcClientRetry: any;
4
4
  export default class BitcoinRpcNetworkProvider implements NetworkProvider {
5
5
  network: Network;
@@ -1,6 +1,6 @@
1
1
  import { ElectrumCluster } from 'electrum-cash';
2
- import { Utxo, Network } from '../interfaces';
3
- import NetworkProvider from './NetworkProvider';
2
+ import { Utxo, Network } from '../interfaces.js';
3
+ import NetworkProvider from './NetworkProvider.js';
4
4
  export default class ElectrumNetworkProvider implements NetworkProvider {
5
5
  network: Network;
6
6
  private manualConnectionManagement?;
@@ -12,10 +12,10 @@ Object.defineProperty(exports, "__esModule", { value: true });
12
12
  const libauth_1 = require("@bitauth/libauth");
13
13
  const utils_1 = require("@cashscript/utils");
14
14
  const electrum_cash_1 = require("electrum-cash");
15
- const interfaces_1 = require("../interfaces");
16
- const utils_2 = require("../utils");
15
+ const interfaces_js_1 = require("../interfaces.js");
16
+ const utils_js_1 = require("../utils.js");
17
17
  class ElectrumNetworkProvider {
18
- constructor(network = interfaces_1.Network.MAINNET, electrum, manualConnectionManagement) {
18
+ constructor(network = interfaces_js_1.Network.MAINNET, electrum, manualConnectionManagement) {
19
19
  this.network = network;
20
20
  this.manualConnectionManagement = manualConnectionManagement;
21
21
  this.concurrentRequests = 0;
@@ -24,7 +24,7 @@ class ElectrumNetworkProvider {
24
24
  this.electrum = electrum;
25
25
  return;
26
26
  }
27
- if (network === interfaces_1.Network.MAINNET) {
27
+ if (network === interfaces_js_1.Network.MAINNET) {
28
28
  // Initialise a 2-of-3 Electrum Cluster with 6 reliable hardcoded servers
29
29
  // using the first three servers as "priority" servers
30
30
  this.electrum = new electrum_cash_1.ElectrumCluster('CashScript Application', '1.4.1', 2, 3, electrum_cash_1.ClusterOrder.PRIORITY);
@@ -35,7 +35,7 @@ class ElectrumNetworkProvider {
35
35
  this.electrum.addServer('bch.loping.net', 50004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
36
36
  this.electrum.addServer('electrum.imaginary.cash', 50004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
37
37
  }
38
- else if (network === interfaces_1.Network.TESTNET) {
38
+ else if (network === interfaces_js_1.Network.TESTNET) {
39
39
  // Initialise a 1-of-2 Electrum Cluster with 2 hardcoded servers
40
40
  this.electrum = new electrum_cash_1.ElectrumCluster('CashScript Application', '1.4.1', 1, 2, electrum_cash_1.ClusterOrder.PRIORITY);
41
41
  this.electrum.addServer('blackie.c3-soft.com', 60004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
@@ -43,7 +43,7 @@ class ElectrumNetworkProvider {
43
43
  // this.electrum.addServer('bch.loping.net', 60004, ElectrumTransport.WSS.Scheme, false);
44
44
  // this.electrum.addServer('testnet.imaginary.cash', 50004, ElectrumTransport.WSS.Scheme);
45
45
  }
46
- else if (network === interfaces_1.Network.STAGING) {
46
+ else if (network === interfaces_js_1.Network.STAGING) {
47
47
  this.electrum = new electrum_cash_1.ElectrumCluster('CashScript Application', '1.4.1', 1, 1, electrum_cash_1.ClusterOrder.PRIORITY);
48
48
  this.electrum.addServer('testnet4.imaginary.cash', 50004, electrum_cash_1.ElectrumTransport.WSS.Scheme, false);
49
49
  }
@@ -147,12 +147,12 @@ exports.default = ElectrumNetworkProvider;
147
147
  */
148
148
  function addressToElectrumScriptHash(address) {
149
149
  // Retrieve locking script
150
- const lockScript = utils_2.addressToLockScript(address);
150
+ const lockScript = (0, utils_js_1.addressToLockScript)(address);
151
151
  // Hash locking script
152
- const scriptHash = utils_1.sha256(lockScript);
152
+ const scriptHash = (0, utils_1.sha256)(lockScript);
153
153
  // Reverse scripthash
154
154
  scriptHash.reverse();
155
155
  // Return scripthash as a hex string
156
- return libauth_1.binToHex(scriptHash);
156
+ return (0, libauth_1.binToHex)(scriptHash);
157
157
  }
158
158
  //# sourceMappingURL=ElectrumNetworkProvider.js.map
@@ -1,5 +1,5 @@
1
- import { Utxo, Network } from '../interfaces';
2
- import NetworkProvider from './NetworkProvider';
1
+ import { Utxo, Network } from '../interfaces.js';
2
+ import NetworkProvider from './NetworkProvider.js';
3
3
  export default class FullStackNetworkProvider implements NetworkProvider {
4
4
  network: Network;
5
5
  private bchjs;
@@ -1,4 +1,4 @@
1
- import { Utxo, Network } from '../interfaces';
1
+ import { Utxo, Network } from '../interfaces.js';
2
2
  export default interface NetworkProvider {
3
3
  /**
4
4
  * Variable indicating the network that this provider connects to.
@@ -1,5 +1,5 @@
1
- export { default as NetworkProvider } from './NetworkProvider';
2
- export { default as BitboxNetworkProvider } from './BitboxNetworkProvider';
3
- export { default as BitcoinRpcNetworkProvider } from './BitcoinRpcNetworkProvider';
4
- export { default as ElectrumNetworkProvider } from './ElectrumNetworkProvider';
5
- export { default as FullStackNetworkProvider } from './FullStackNetworkProvider';
1
+ export { default as NetworkProvider } from './NetworkProvider.js';
2
+ export { default as BitboxNetworkProvider } from './BitboxNetworkProvider.js';
3
+ export { default as BitcoinRpcNetworkProvider } from './BitcoinRpcNetworkProvider.js';
4
+ export { default as ElectrumNetworkProvider } from './ElectrumNetworkProvider.js';
5
+ export { default as FullStackNetworkProvider } from './FullStackNetworkProvider.js';
@@ -4,12 +4,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.FullStackNetworkProvider = exports.ElectrumNetworkProvider = exports.BitcoinRpcNetworkProvider = exports.BitboxNetworkProvider = void 0;
7
- var BitboxNetworkProvider_1 = require("./BitboxNetworkProvider");
8
- Object.defineProperty(exports, "BitboxNetworkProvider", { enumerable: true, get: function () { return __importDefault(BitboxNetworkProvider_1).default; } });
9
- var BitcoinRpcNetworkProvider_1 = require("./BitcoinRpcNetworkProvider");
10
- Object.defineProperty(exports, "BitcoinRpcNetworkProvider", { enumerable: true, get: function () { return __importDefault(BitcoinRpcNetworkProvider_1).default; } });
11
- var ElectrumNetworkProvider_1 = require("./ElectrumNetworkProvider");
12
- Object.defineProperty(exports, "ElectrumNetworkProvider", { enumerable: true, get: function () { return __importDefault(ElectrumNetworkProvider_1).default; } });
13
- var FullStackNetworkProvider_1 = require("./FullStackNetworkProvider");
14
- Object.defineProperty(exports, "FullStackNetworkProvider", { enumerable: true, get: function () { return __importDefault(FullStackNetworkProvider_1).default; } });
7
+ var BitboxNetworkProvider_js_1 = require("./BitboxNetworkProvider.js");
8
+ Object.defineProperty(exports, "BitboxNetworkProvider", { enumerable: true, get: function () { return __importDefault(BitboxNetworkProvider_js_1).default; } });
9
+ var BitcoinRpcNetworkProvider_js_1 = require("./BitcoinRpcNetworkProvider.js");
10
+ Object.defineProperty(exports, "BitcoinRpcNetworkProvider", { enumerable: true, get: function () { return __importDefault(BitcoinRpcNetworkProvider_js_1).default; } });
11
+ var ElectrumNetworkProvider_js_1 = require("./ElectrumNetworkProvider.js");
12
+ Object.defineProperty(exports, "ElectrumNetworkProvider", { enumerable: true, get: function () { return __importDefault(ElectrumNetworkProvider_js_1).default; } });
13
+ var FullStackNetworkProvider_js_1 = require("./FullStackNetworkProvider.js");
14
+ Object.defineProperty(exports, "FullStackNetworkProvider", { enumerable: true, get: function () { return __importDefault(FullStackNetworkProvider_js_1).default; } });
15
15
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  import { Transaction } from '@bitauth/libauth';
2
2
  import { Script } from '@cashscript/utils';
3
- import { Utxo, Output, Recipient } from './interfaces';
4
- import { FailedTransactionError } from './Errors';
3
+ import { Utxo, Output, Recipient } from './interfaces.js';
4
+ import { FailedTransactionError } from './Errors.js';
5
5
  export declare function validateRecipient(recipient: Recipient): void;
6
6
  export declare function getInputSize(inputScript: Uint8Array): number;
7
7
  export declare function getPreimageSize(script: Uint8Array): number;
@@ -3,13 +3,13 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.getNetworkPrefix = exports.addressToLockScript = exports.scriptToLockingBytecode = exports.scriptToAddress = exports.meep = exports.buildError = exports.createSighashPreimage = exports.createOpReturnOutput = exports.createInputScript = exports.getTxSizeWithoutInputs = exports.getPreimageSize = exports.getInputSize = exports.validateRecipient = void 0;
4
4
  const libauth_1 = require("@bitauth/libauth");
5
5
  const utils_1 = require("@cashscript/utils");
6
- const interfaces_1 = require("./interfaces");
7
- const constants_1 = require("./constants");
8
- const Errors_1 = require("./Errors");
6
+ const interfaces_js_1 = require("./interfaces.js");
7
+ const constants_js_1 = require("./constants.js");
8
+ const Errors_js_1 = require("./Errors.js");
9
9
  // ////////// PARAMETER VALIDATION ////////////////////////////////////////////
10
10
  function validateRecipient(recipient) {
11
- if (recipient.amount < constants_1.DUST_LIMIT) {
12
- throw new Errors_1.OutputSatoshisTooSmallError(recipient.amount);
11
+ if (recipient.amount < constants_js_1.DUST_LIMIT) {
12
+ throw new Errors_js_1.OutputSatoshisTooSmallError(recipient.amount);
13
13
  }
14
14
  }
15
15
  exports.validateRecipient = validateRecipient;
@@ -41,16 +41,16 @@ function getTxSizeWithoutInputs(outputs) {
41
41
  // Script Length(1 ~ 9B)*
42
42
  // Script (?)*
43
43
  // LockTime (4B)
44
- let size = constants_1.VERSION_SIZE + constants_1.LOCKTIME_SIZE;
44
+ let size = constants_js_1.VERSION_SIZE + constants_js_1.LOCKTIME_SIZE;
45
45
  size += outputs.reduce((acc, output) => {
46
46
  if (typeof output.to === 'string') {
47
- return acc + constants_1.P2PKH_OUTPUT_SIZE;
47
+ return acc + constants_js_1.P2PKH_OUTPUT_SIZE;
48
48
  }
49
49
  // Size of an OP_RETURN output = byteLength + 8 (amount) + 2 (scriptSize)
50
50
  return acc + output.to.byteLength + 8 + 2;
51
51
  }, 0);
52
52
  // Add tx-out count (accounting for a potential change output)
53
- size += utils_1.encodeInt(outputs.length + 1).byteLength;
53
+ size += (0, utils_1.encodeInt)(outputs.length + 1).byteLength;
54
54
  return size;
55
55
  }
56
56
  exports.getTxSizeWithoutInputs = getTxSizeWithoutInputs;
@@ -61,10 +61,10 @@ function createInputScript(redeemScript, encodedArgs, selector, preimage) {
61
61
  if (preimage !== undefined)
62
62
  unlockScript.push(preimage);
63
63
  if (selector !== undefined)
64
- unlockScript.push(utils_1.encodeInt(selector));
64
+ unlockScript.push((0, utils_1.encodeInt)(selector));
65
65
  // Create input script and compile it to bytecode
66
- const inputScript = [...unlockScript, utils_1.scriptToBytecode(redeemScript)];
67
- return utils_1.scriptToBytecode(inputScript);
66
+ const inputScript = [...unlockScript, (0, utils_1.scriptToBytecode)(redeemScript)];
67
+ return (0, utils_1.scriptToBytecode)(inputScript);
68
68
  }
69
69
  exports.createInputScript = createInputScript;
70
70
  function createOpReturnOutput(opReturnData) {
@@ -81,12 +81,12 @@ function toBin(output) {
81
81
  return encode(data);
82
82
  }
83
83
  function createSighashPreimage(transaction, input, inputIndex, coveredBytecode, hashtype) {
84
- const state = libauth_1.createTransactionContextCommon({
84
+ const state = (0, libauth_1.createTransactionContextCommon)({
85
85
  inputIndex,
86
- sourceOutput: { satoshis: libauth_1.bigIntToBinUint64LE(BigInt(input.satoshis)) },
86
+ sourceOutput: { satoshis: (0, libauth_1.bigIntToBinUint64LE)(BigInt(input.satoshis)) },
87
87
  spendingTransaction: transaction,
88
88
  });
89
- const sighashPreimage = libauth_1.generateSigningSerializationBCH({
89
+ const sighashPreimage = (0, libauth_1.generateSigningSerializationBCH)({
90
90
  correspondingOutput: state.correspondingOutput,
91
91
  coveredBytecode,
92
92
  forkId: new Uint8Array([0, 0, 0]),
@@ -107,24 +107,24 @@ function createSighashPreimage(transaction, input, inputIndex, coveredBytecode,
107
107
  exports.createSighashPreimage = createSighashPreimage;
108
108
  function buildError(reason, meepStr) {
109
109
  const require = [
110
- Errors_1.Reason.EVAL_FALSE, Errors_1.Reason.VERIFY, Errors_1.Reason.EQUALVERIFY, Errors_1.Reason.CHECKMULTISIGVERIFY,
111
- Errors_1.Reason.CHECKSIGVERIFY, Errors_1.Reason.CHECKDATASIGVERIFY, Errors_1.Reason.NUMEQUALVERIFY,
110
+ Errors_js_1.Reason.EVAL_FALSE, Errors_js_1.Reason.VERIFY, Errors_js_1.Reason.EQUALVERIFY, Errors_js_1.Reason.CHECKMULTISIGVERIFY,
111
+ Errors_js_1.Reason.CHECKSIGVERIFY, Errors_js_1.Reason.CHECKDATASIGVERIFY, Errors_js_1.Reason.NUMEQUALVERIFY,
112
112
  ];
113
- const timeCheck = [Errors_1.Reason.NEGATIVE_LOCKTIME, Errors_1.Reason.UNSATISFIED_LOCKTIME];
113
+ const timeCheck = [Errors_js_1.Reason.NEGATIVE_LOCKTIME, Errors_js_1.Reason.UNSATISFIED_LOCKTIME];
114
114
  const sigCheck = [
115
- Errors_1.Reason.SIG_COUNT, Errors_1.Reason.PUBKEY_COUNT, Errors_1.Reason.SIG_HASHTYPE, Errors_1.Reason.SIG_DER,
116
- Errors_1.Reason.SIG_HIGH_S, Errors_1.Reason.SIG_NULLFAIL, Errors_1.Reason.SIG_BADLENGTH, Errors_1.Reason.SIG_NONSCHNORR,
115
+ Errors_js_1.Reason.SIG_COUNT, Errors_js_1.Reason.PUBKEY_COUNT, Errors_js_1.Reason.SIG_HASHTYPE, Errors_js_1.Reason.SIG_DER,
116
+ Errors_js_1.Reason.SIG_HIGH_S, Errors_js_1.Reason.SIG_NULLFAIL, Errors_js_1.Reason.SIG_BADLENGTH, Errors_js_1.Reason.SIG_NONSCHNORR,
117
117
  ];
118
118
  if (toRegExp(require).test(reason)) {
119
- return new Errors_1.FailedRequireError(reason, meepStr);
119
+ return new Errors_js_1.FailedRequireError(reason, meepStr);
120
120
  }
121
121
  if (toRegExp(timeCheck).test(reason)) {
122
- return new Errors_1.FailedTimeCheckError(reason, meepStr);
122
+ return new Errors_js_1.FailedTimeCheckError(reason, meepStr);
123
123
  }
124
124
  if (toRegExp(sigCheck).test(reason)) {
125
- return new Errors_1.FailedSigCheckError(reason, meepStr);
125
+ return new Errors_js_1.FailedSigCheckError(reason, meepStr);
126
126
  }
127
- return new Errors_1.FailedTransactionError(reason, meepStr);
127
+ return new Errors_js_1.FailedTransactionError(reason, meepStr);
128
128
  }
129
129
  exports.buildError = buildError;
130
130
  function toRegExp(reasons) {
@@ -132,21 +132,21 @@ function toRegExp(reasons) {
132
132
  }
133
133
  // ////////// MISC ////////////////////////////////////////////////////////////
134
134
  function meep(tx, utxos, script) {
135
- const scriptPubkey = libauth_1.binToHex(scriptToLockingBytecode(script));
135
+ const scriptPubkey = (0, libauth_1.binToHex)(scriptToLockingBytecode(script));
136
136
  return `meep debug --tx=${tx} --idx=0 --amt=${utxos[0].satoshis} --pkscript=${scriptPubkey}`;
137
137
  }
138
138
  exports.meep = meep;
139
139
  function scriptToAddress(script, network) {
140
140
  const lockingBytecode = scriptToLockingBytecode(script);
141
141
  const prefix = getNetworkPrefix(network);
142
- const address = libauth_1.lockingBytecodeToCashAddress(lockingBytecode, prefix);
142
+ const address = (0, libauth_1.lockingBytecodeToCashAddress)(lockingBytecode, prefix);
143
143
  return address;
144
144
  }
145
145
  exports.scriptToAddress = scriptToAddress;
146
146
  function scriptToLockingBytecode(script) {
147
- const scriptHash = utils_1.hash160(utils_1.scriptToBytecode(script));
147
+ const scriptHash = (0, utils_1.hash160)((0, utils_1.scriptToBytecode)(script));
148
148
  const addressContents = { payload: scriptHash, type: libauth_1.AddressType.p2sh };
149
- const lockingBytecode = libauth_1.addressContentsToLockingBytecode(addressContents);
149
+ const lockingBytecode = (0, libauth_1.addressContentsToLockingBytecode)(addressContents);
150
150
  return lockingBytecode;
151
151
  }
152
152
  exports.scriptToLockingBytecode = scriptToLockingBytecode;
@@ -158,7 +158,7 @@ exports.scriptToLockingBytecode = scriptToLockingBytecode;
158
158
  * @returns a locking script corresponding to the passed address
159
159
  */
160
160
  function addressToLockScript(address) {
161
- const result = libauth_1.cashAddressToLockingBytecode(address);
161
+ const result = (0, libauth_1.cashAddressToLockingBytecode)(address);
162
162
  if (typeof result === 'string')
163
163
  throw new Error(result);
164
164
  return result.bytecode;
@@ -166,13 +166,13 @@ function addressToLockScript(address) {
166
166
  exports.addressToLockScript = addressToLockScript;
167
167
  function getNetworkPrefix(network) {
168
168
  switch (network) {
169
- case interfaces_1.Network.MAINNET:
169
+ case interfaces_js_1.Network.MAINNET:
170
170
  return 'bitcoincash';
171
- case interfaces_1.Network.STAGING:
171
+ case interfaces_js_1.Network.STAGING:
172
172
  return 'bchtest';
173
- case interfaces_1.Network.TESTNET:
173
+ case interfaces_js_1.Network.TESTNET:
174
174
  return 'bchtest';
175
- case interfaces_1.Network.REGTEST:
175
+ case interfaces_js_1.Network.REGTEST:
176
176
  return 'bchreg';
177
177
  default:
178
178
  return 'bitcoincash';
@@ -182,7 +182,7 @@ exports.getNetworkPrefix = getNetworkPrefix;
182
182
  // ////////////////////////////////////////////////////////////////////////////
183
183
  // For encoding OP_RETURN data (doesn't require BIP62.3 / MINIMALDATA)
184
184
  function encodeNullDataScript(chunks) {
185
- return libauth_1.flattenBinArray(chunks.map((chunk) => {
185
+ return (0, libauth_1.flattenBinArray)(chunks.map((chunk) => {
186
186
  if (typeof chunk === 'number') {
187
187
  return new Uint8Array([chunk]);
188
188
  }
@@ -1,3 +1,3 @@
1
- import SignatureTemplate from './SignatureTemplate';
1
+ import SignatureTemplate from './SignatureTemplate.js';
2
2
  export declare type Argument = number | bigint | boolean | string | Uint8Array | SignatureTemplate;
3
3
  export declare function encodeArgument(argument: Argument, typeStr: string): Uint8Array | SignatureTemplate;
@@ -1,7 +1,7 @@
1
1
  import { hexToBin } from '@bitauth/libauth';
2
2
  import { BytesType, encodeBool, encodeInt, encodeString, parseType, PrimitiveType, } from '@cashscript/utils';
3
- import { TypeError } from './Errors';
4
- import SignatureTemplate from './SignatureTemplate';
3
+ import { TypeError } from './Errors.js';
4
+ import SignatureTemplate from './SignatureTemplate.js';
5
5
  export function encodeArgument(argument, typeStr) {
6
6
  let type = parseType(typeStr);
7
7
  if (type === PrimitiveType.BOOL) {
@@ -1,8 +1,8 @@
1
1
  import { Artifact } from '@cashscript/utils';
2
- import { Transaction } from './Transaction';
3
- import { Argument } from './Argument';
4
- import { Utxo } from './interfaces';
5
- import NetworkProvider from './network/NetworkProvider';
2
+ import { Transaction } from './Transaction.js';
3
+ import { Argument } from './Argument.js';
4
+ import { Utxo } from './interfaces.js';
5
+ import NetworkProvider from './network/NetworkProvider.js';
6
6
  export declare class Contract {
7
7
  private artifact;
8
8
  private provider;
@@ -9,11 +9,11 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
9
9
  };
10
10
  import { binToHex } from '@bitauth/libauth';
11
11
  import { asmToScript, calculateBytesize, countOpcodes, generateRedeemScript, scriptToBytecode, } from '@cashscript/utils';
12
- import { Transaction } from './Transaction';
13
- import { encodeArgument } from './Argument';
14
- import { scriptToAddress, } from './utils';
15
- import SignatureTemplate from './SignatureTemplate';
16
- import { ElectrumNetworkProvider } from './network';
12
+ import { Transaction } from './Transaction.js';
13
+ import { encodeArgument } from './Argument.js';
14
+ import { scriptToAddress, } from './utils.js';
15
+ import SignatureTemplate from './SignatureTemplate.js';
16
+ import { ElectrumNetworkProvider } from './network/index.js';
17
17
  export class Contract {
18
18
  constructor(artifact, constructorArgs, provider = new ElectrumNetworkProvider()) {
19
19
  this.artifact = artifact;
@@ -1,4 +1,4 @@
1
- import { DUST_LIMIT } from './constants';
1
+ import { DUST_LIMIT } from './constants.js';
2
2
  export class TypeError extends Error {
3
3
  constructor(actual, expected) {
4
4
  super(`Found type '${actual}' where type '${expected.toString()}' was expected`);
@@ -1,5 +1,5 @@
1
1
  import { Secp256k1 } from '@bitauth/libauth';
2
- import { HashType } from './interfaces';
2
+ import { HashType } from './interfaces.js';
3
3
  export default class SignatureTemplate {
4
4
  private hashtype;
5
5
  private privateKey;
@@ -1,6 +1,6 @@
1
1
  import { decodePrivateKeyWif, SigningSerializationFlag } from '@bitauth/libauth';
2
2
  import { sha256 } from '@cashscript/utils';
3
- import { HashType } from './interfaces';
3
+ import { HashType } from './interfaces.js';
4
4
  export default class SignatureTemplate {
5
5
  constructor(signer, hashtype = HashType.SIGHASH_ALL) {
6
6
  this.hashtype = hashtype;
@@ -1,7 +1,7 @@
1
1
  import { AbiFunction, Script } from '@cashscript/utils';
2
- import { Utxo, Recipient, TransactionDetails } from './interfaces';
3
- import NetworkProvider from './network/NetworkProvider';
4
- import SignatureTemplate from './SignatureTemplate';
2
+ import { Utxo, Recipient, TransactionDetails } from './interfaces.js';
3
+ import NetworkProvider from './network/NetworkProvider.js';
4
+ import SignatureTemplate from './SignatureTemplate.js';
5
5
  export declare class Transaction {
6
6
  private address;
7
7
  private provider;
@@ -10,10 +10,10 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { bigIntToBinUint64LE, hexToBin, binToHex, encodeTransaction, addressContentsToLockingBytecode, AddressType, decodeTransaction, instantiateSecp256k1, } from '@bitauth/libauth';
11
11
  import delay from 'delay';
12
12
  import { hash160, hash256, placeholder, scriptToBytecode, } from '@cashscript/utils';
13
- import { isSignableUtxo, } from './interfaces';
14
- import { meep, createInputScript, getInputSize, createOpReturnOutput, getTxSizeWithoutInputs, getPreimageSize, buildError, addressToLockScript, createSighashPreimage, validateRecipient, } from './utils';
15
- import { P2SH_OUTPUT_SIZE, DUST_LIMIT } from './constants';
16
- import SignatureTemplate from './SignatureTemplate';
13
+ import { isSignableUtxo, } from './interfaces.js';
14
+ import { meep, createInputScript, getInputSize, createOpReturnOutput, getTxSizeWithoutInputs, getPreimageSize, buildError, addressToLockScript, createSighashPreimage, validateRecipient, } from './utils.js';
15
+ import { P2SH_OUTPUT_SIZE, DUST_LIMIT } from './constants.js';
16
+ import SignatureTemplate from './SignatureTemplate.js';
17
17
  const bip68 = require('bip68');
18
18
  export class Transaction {
19
19
  constructor(address, provider, redeemScript, abiFunction, args, selector) {
@@ -187,6 +187,7 @@ export class Transaction {
187
187
  });
188
188
  }
189
189
  setInputsAndOutputs() {
190
+ var _a;
190
191
  return __awaiter(this, void 0, void 0, function* () {
191
192
  if (this.outputs.length === 0) {
192
193
  throw Error('Attempted to build a transaction without outputs');
@@ -204,9 +205,7 @@ export class Transaction {
204
205
  const inputSize = getInputSize(placeholderScript) + 1;
205
206
  // Calculate amount to send and base fee (excluding additional fees per UTXO)
206
207
  const amount = this.outputs.reduce((acc, output) => acc + output.amount, 0);
207
- let fee = this.hardcodedFee
208
- ? this.hardcodedFee
209
- : getTxSizeWithoutInputs(this.outputs) * this.feePerByte;
208
+ let fee = (_a = this.hardcodedFee) !== null && _a !== void 0 ? _a : getTxSizeWithoutInputs(this.outputs) * this.feePerByte;
210
209
  // Select and gather UTXOs and calculate fees and available funds
211
210
  let satsAvailable = 0;
212
211
  if (this.inputs.length > 0) {
@@ -1,9 +1,9 @@
1
- export { Contract } from './Contract';
2
- export { Transaction } from './Transaction';
3
- export { Argument } from './Argument';
4
- export { default as SignatureTemplate } from './SignatureTemplate';
1
+ export { Contract } from './Contract.js';
2
+ export { Transaction } from './Transaction.js';
3
+ export { Argument } from './Argument.js';
4
+ export { default as SignatureTemplate } from './SignatureTemplate.js';
5
5
  export { Artifact, AbiFunction, AbiInput } from '@cashscript/utils';
6
6
  export * as utils from '@cashscript/utils';
7
- export { Utxo, Recipient, SignatureAlgorithm, HashType, Network, } from './interfaces';
8
- export * from './Errors';
9
- export * from './network';
7
+ export { Utxo, Recipient, SignatureAlgorithm, HashType, Network, } from './interfaces.js';
8
+ export * from './Errors.js';
9
+ export { NetworkProvider, BitboxNetworkProvider, BitcoinRpcNetworkProvider, ElectrumNetworkProvider, FullStackNetworkProvider, } from './network/index.js';
@@ -1,9 +1,9 @@
1
- export { Contract } from './Contract';
2
- export { Transaction } from './Transaction';
3
- export { default as SignatureTemplate } from './SignatureTemplate';
1
+ export { Contract } from './Contract.js';
2
+ export { Transaction } from './Transaction.js';
3
+ export { default as SignatureTemplate } from './SignatureTemplate.js';
4
4
  import * as utils_1 from '@cashscript/utils';
5
5
  export { utils_1 as utils };
6
- export { SignatureAlgorithm, HashType, Network, } from './interfaces';
7
- export * from './Errors';
8
- export * from './network';
6
+ export { SignatureAlgorithm, HashType, Network, } from './interfaces.js';
7
+ export * from './Errors.js';
8
+ export { BitboxNetworkProvider, BitcoinRpcNetworkProvider, ElectrumNetworkProvider, FullStackNetworkProvider, } from './network/index.js';
9
9
  //# sourceMappingURL=index.js.map
@@ -1,5 +1,5 @@
1
1
  import { Transaction } from '@bitauth/libauth';
2
- import SignatureTemplate from './SignatureTemplate';
2
+ import type SignatureTemplate from './SignatureTemplate.js';
3
3
  export interface Utxo {
4
4
  txid: string;
5
5
  vout: number;
@@ -1,5 +1,5 @@
1
- import { Utxo, Network } from '../interfaces';
2
- import NetworkProvider from './NetworkProvider';
1
+ import { Utxo, Network } from '../interfaces.js';
2
+ import NetworkProvider from './NetworkProvider.js';
3
3
  export default class BitboxNetworkProvider implements NetworkProvider {
4
4
  network: Network;
5
5
  private bitbox;
@@ -1,5 +1,5 @@
1
- import { Utxo, Network } from '../interfaces';
2
- import NetworkProvider from './NetworkProvider';
1
+ import { Utxo, Network } from '../interfaces.js';
2
+ import NetworkProvider from './NetworkProvider.js';
3
3
  declare const RpcClientRetry: any;
4
4
  export default class BitcoinRpcNetworkProvider implements NetworkProvider {
5
5
  network: Network;
@@ -1,6 +1,6 @@
1
1
  import { ElectrumCluster } from 'electrum-cash';
2
- import { Utxo, Network } from '../interfaces';
3
- import NetworkProvider from './NetworkProvider';
2
+ import { Utxo, Network } from '../interfaces.js';
3
+ import NetworkProvider from './NetworkProvider.js';
4
4
  export default class ElectrumNetworkProvider implements NetworkProvider {
5
5
  network: Network;
6
6
  private manualConnectionManagement?;
@@ -10,8 +10,8 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
10
10
  import { binToHex } from '@bitauth/libauth';
11
11
  import { sha256 } from '@cashscript/utils';
12
12
  import { ElectrumCluster, ElectrumTransport, ClusterOrder, } from 'electrum-cash';
13
- import { Network } from '../interfaces';
14
- import { addressToLockScript } from '../utils';
13
+ import { Network } from '../interfaces.js';
14
+ import { addressToLockScript } from '../utils.js';
15
15
  export default class ElectrumNetworkProvider {
16
16
  constructor(network = Network.MAINNET, electrum, manualConnectionManagement) {
17
17
  this.network = network;
@@ -1,5 +1,5 @@
1
- import { Utxo, Network } from '../interfaces';
2
- import NetworkProvider from './NetworkProvider';
1
+ import { Utxo, Network } from '../interfaces.js';
2
+ import NetworkProvider from './NetworkProvider.js';
3
3
  export default class FullStackNetworkProvider implements NetworkProvider {
4
4
  network: Network;
5
5
  private bchjs;
@@ -1,4 +1,4 @@
1
- import { Utxo, Network } from '../interfaces';
1
+ import { Utxo, Network } from '../interfaces.js';
2
2
  export default interface NetworkProvider {
3
3
  /**
4
4
  * Variable indicating the network that this provider connects to.
@@ -1,5 +1,5 @@
1
- export { default as NetworkProvider } from './NetworkProvider';
2
- export { default as BitboxNetworkProvider } from './BitboxNetworkProvider';
3
- export { default as BitcoinRpcNetworkProvider } from './BitcoinRpcNetworkProvider';
4
- export { default as ElectrumNetworkProvider } from './ElectrumNetworkProvider';
5
- export { default as FullStackNetworkProvider } from './FullStackNetworkProvider';
1
+ export { default as NetworkProvider } from './NetworkProvider.js';
2
+ export { default as BitboxNetworkProvider } from './BitboxNetworkProvider.js';
3
+ export { default as BitcoinRpcNetworkProvider } from './BitcoinRpcNetworkProvider.js';
4
+ export { default as ElectrumNetworkProvider } from './ElectrumNetworkProvider.js';
5
+ export { default as FullStackNetworkProvider } from './FullStackNetworkProvider.js';
@@ -1,5 +1,5 @@
1
- export { default as BitboxNetworkProvider } from './BitboxNetworkProvider';
2
- export { default as BitcoinRpcNetworkProvider } from './BitcoinRpcNetworkProvider';
3
- export { default as ElectrumNetworkProvider } from './ElectrumNetworkProvider';
4
- export { default as FullStackNetworkProvider } from './FullStackNetworkProvider';
1
+ export { default as BitboxNetworkProvider } from './BitboxNetworkProvider.js';
2
+ export { default as BitcoinRpcNetworkProvider } from './BitcoinRpcNetworkProvider.js';
3
+ export { default as ElectrumNetworkProvider } from './ElectrumNetworkProvider.js';
4
+ export { default as FullStackNetworkProvider } from './FullStackNetworkProvider.js';
5
5
  //# sourceMappingURL=index.js.map
@@ -1,7 +1,7 @@
1
1
  import { Transaction } from '@bitauth/libauth';
2
2
  import { Script } from '@cashscript/utils';
3
- import { Utxo, Output, Recipient } from './interfaces';
4
- import { FailedTransactionError } from './Errors';
3
+ import { Utxo, Output, Recipient } from './interfaces.js';
4
+ import { FailedTransactionError } from './Errors.js';
5
5
  export declare function validateRecipient(recipient: Recipient): void;
6
6
  export declare function getInputSize(inputScript: Uint8Array): number;
7
7
  export declare function getPreimageSize(script: Uint8Array): number;
@@ -1,8 +1,8 @@
1
1
  import { cashAddressToLockingBytecode, AddressType, addressContentsToLockingBytecode, lockingBytecodeToCashAddress, binToHex, createTransactionContextCommon, bigIntToBinUint64LE, generateSigningSerializationBCH, utf8ToBin, hexToBin, flattenBinArray, } from '@bitauth/libauth';
2
2
  import { encodeInt, hash160, Op, scriptToBytecode, sha256, } from '@cashscript/utils';
3
- import { Network, } from './interfaces';
4
- import { P2PKH_OUTPUT_SIZE, VERSION_SIZE, LOCKTIME_SIZE, DUST_LIMIT, } from './constants';
5
- import { OutputSatoshisTooSmallError, Reason, FailedTransactionError, FailedRequireError, FailedTimeCheckError, FailedSigCheckError, } from './Errors';
3
+ import { Network, } from './interfaces.js';
4
+ import { P2PKH_OUTPUT_SIZE, VERSION_SIZE, LOCKTIME_SIZE, DUST_LIMIT, } from './constants.js';
5
+ import { OutputSatoshisTooSmallError, Reason, FailedTransactionError, FailedRequireError, FailedTimeCheckError, FailedSigCheckError, } from './Errors.js';
6
6
  // ////////// PARAMETER VALIDATION ////////////////////////////////////////////
7
7
  export function validateRecipient(recipient) {
8
8
  if (recipient.amount < DUST_LIMIT) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cashscript",
3
- "version": "0.7.0-next.0",
3
+ "version": "0.7.0",
4
4
  "description": "Easily write and interact with Bitcoin Cash contracts",
5
5
  "keywords": [
6
6
  "bitcoin cash",
@@ -42,11 +42,11 @@
42
42
  },
43
43
  "dependencies": {
44
44
  "@bitauth/libauth": "^1.18.1",
45
- "@cashscript/utils": "^0.7.0-next.0",
45
+ "@cashscript/utils": "^0.7.0",
46
46
  "bip68": "^1.0.4",
47
47
  "bitcoin-rpc-promise-retry": "^1.3.0",
48
48
  "delay": "^5.0.0",
49
- "electrum-cash": "^2.0.6"
49
+ "electrum-cash": "^2.0.10"
50
50
  },
51
51
  "devDependencies": {
52
52
  "@psf/bch-js": "^4.15.0",