cashscript 0.6.4 → 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 (49) hide show
  1. package/dist/main/Argument.d.ts +2 -2
  2. package/dist/main/Argument.js +19 -19
  3. package/dist/main/Contract.d.ts +4 -4
  4. package/dist/main/Contract.js +15 -15
  5. package/dist/main/Errors.d.ts +6 -2
  6. package/dist/main/Errors.js +10 -2
  7. package/dist/main/SignatureTemplate.d.ts +1 -1
  8. package/dist/main/SignatureTemplate.js +3 -3
  9. package/dist/main/Transaction.d.ts +3 -3
  10. package/dist/main/Transaction.js +40 -42
  11. package/dist/main/index.d.ts +7 -7
  12. package/dist/main/index.js +22 -14
  13. package/dist/main/interfaces.d.ts +2 -1
  14. package/dist/main/interfaces.js +1 -0
  15. package/dist/main/network/BitboxNetworkProvider.d.ts +2 -2
  16. package/dist/main/network/BitcoinRpcNetworkProvider.d.ts +2 -2
  17. package/dist/main/network/ElectrumNetworkProvider.d.ts +2 -2
  18. package/dist/main/network/ElectrumNetworkProvider.js +13 -9
  19. package/dist/main/network/FullStackNetworkProvider.d.ts +2 -2
  20. package/dist/main/network/NetworkProvider.d.ts +1 -1
  21. package/dist/main/network/index.d.ts +5 -5
  22. package/dist/main/network/index.js +8 -8
  23. package/dist/main/utils.d.ts +3 -2
  24. package/dist/main/utils.js +40 -31
  25. package/dist/module/Argument.d.ts +2 -2
  26. package/dist/module/Argument.js +9 -9
  27. package/dist/module/Contract.d.ts +4 -4
  28. package/dist/module/Contract.js +5 -5
  29. package/dist/module/Errors.d.ts +6 -2
  30. package/dist/module/Errors.js +8 -1
  31. package/dist/module/SignatureTemplate.d.ts +1 -1
  32. package/dist/module/SignatureTemplate.js +1 -1
  33. package/dist/module/Transaction.d.ts +3 -3
  34. package/dist/module/Transaction.js +11 -13
  35. package/dist/module/index.d.ts +7 -7
  36. package/dist/module/index.js +6 -6
  37. package/dist/module/interfaces.d.ts +2 -1
  38. package/dist/module/interfaces.js +1 -0
  39. package/dist/module/network/BitboxNetworkProvider.d.ts +2 -2
  40. package/dist/module/network/BitcoinRpcNetworkProvider.d.ts +2 -2
  41. package/dist/module/network/ElectrumNetworkProvider.d.ts +2 -2
  42. package/dist/module/network/ElectrumNetworkProvider.js +7 -3
  43. package/dist/module/network/FullStackNetworkProvider.d.ts +2 -2
  44. package/dist/module/network/NetworkProvider.d.ts +1 -1
  45. package/dist/module/network/index.d.ts +5 -5
  46. package/dist/module/network/index.js +4 -4
  47. package/dist/module/utils.d.ts +3 -2
  48. package/dist/module/utils.js +11 -3
  49. package/package.json +3 -3
@@ -1,3 +1,3 @@
1
- import SignatureTemplate from './SignatureTemplate';
2
- export declare type Argument = number | boolean | string | Uint8Array | SignatureTemplate;
1
+ import SignatureTemplate from './SignatureTemplate.js';
2
+ export declare type Argument = number | bigint | boolean | string | Uint8Array | SignatureTemplate;
3
3
  export declare function encodeArgument(argument: Argument, typeStr: string): Uint8Array | SignatureTemplate;
@@ -6,53 +6,53 @@ 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
- if (typeof argument !== 'number') {
21
- throw new Errors_1.TypeError(typeof argument, type);
20
+ if (typeof argument !== 'number' && typeof argument !== 'bigint') {
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`);
42
42
  }
43
43
  // Redefine SIG as a bytes65 so it is included in the size checks below
44
44
  // Note that ONLY Schnorr signatures are accepted
45
- if (type === utils_1.PrimitiveType.SIG) {
45
+ if (type === utils_1.PrimitiveType.SIG && argument.byteLength !== 0) {
46
46
  type = new utils_1.BytesType(65);
47
47
  }
48
- // TODO: Set DATASIG to 64 bytes (enforcing Schnorr) in a new MINOR version upgrade
49
- // (backwards incompatible)
50
- // if (type === PrimitiveType.DATASIG) {
51
- // type = new BytesType(64);
52
- // }
48
+ // Redefine SIG as a bytes64 so it is included in the size checks below
49
+ // Note that ONLY Schnorr signatures are accepted
50
+ if (type === utils_1.PrimitiveType.DATASIG && argument.byteLength !== 0) {
51
+ type = new utils_1.BytesType(64);
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
  }
@@ -2,6 +2,9 @@ import { Type } from '@cashscript/utils';
2
2
  export declare class TypeError extends Error {
3
3
  constructor(actual: string, expected: Type);
4
4
  }
5
+ export declare class OutputSatoshisTooSmallError extends Error {
6
+ constructor(satoshis: number);
7
+ }
5
8
  export declare class FailedTransactionError extends Error {
6
9
  reason: string;
7
10
  meep: string;
@@ -28,7 +31,7 @@ export declare enum Reason {
28
31
  SIG_COUNT = "Signature count negative or greater than pubkey count",
29
32
  PUBKEY_COUNT = "Pubkey count negative or limit exceeded",
30
33
  INVALID_OPERAND_SIZE = "Invalid operand size",
31
- INVALID_NUMBER_RANGE = "Given operand is not a number within the valid range [-2^31...2^31]",
34
+ INVALID_NUMBER_RANGE = "Given operand is not a number within the valid range",
32
35
  IMPOSSIBLE_ENCODING = "The requested encoding is impossible to satisfy",
33
36
  INVALID_SPLIT_RANGE = "Invalid OP_SPLIT range",
34
37
  INVALID_BIT_COUNT = "Invalid number of bit set in OP_CHECKMULTISIG",
@@ -58,5 +61,6 @@ export declare enum Reason {
58
61
  CLEANSTACK = "Script did not clean its stack",
59
62
  NONCOMPRESSED_PUBKEY = "Using non-compressed public key",
60
63
  ILLEGAL_FORKID = "Illegal use of SIGHASH_FORKID",
61
- MUST_USE_FORKID = "Signature must use SIGHASH_FORKID"
64
+ MUST_USE_FORKID = "Signature must use SIGHASH_FORKID",
65
+ UNKNOWN = "unknown error"
62
66
  }
@@ -1,12 +1,19 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.Reason = exports.FailedSigCheckError = exports.FailedTimeCheckError = exports.FailedRequireError = exports.FailedTransactionError = exports.TypeError = void 0;
3
+ exports.Reason = exports.FailedSigCheckError = exports.FailedTimeCheckError = exports.FailedRequireError = exports.FailedTransactionError = exports.OutputSatoshisTooSmallError = exports.TypeError = void 0;
4
+ const constants_js_1 = require("./constants.js");
4
5
  class TypeError extends Error {
5
6
  constructor(actual, expected) {
6
7
  super(`Found type '${actual}' where type '${expected.toString()}' was expected`);
7
8
  }
8
9
  }
9
10
  exports.TypeError = TypeError;
11
+ class OutputSatoshisTooSmallError extends Error {
12
+ constructor(satoshis) {
13
+ super(`Tried to add an output with ${satoshis} satoshis, which is less than the DUST limit (${constants_js_1.DUST_LIMIT})`);
14
+ }
15
+ }
16
+ exports.OutputSatoshisTooSmallError = OutputSatoshisTooSmallError;
10
17
  class FailedTransactionError extends Error {
11
18
  constructor(reason, meep) {
12
19
  super(`Transaction failed with reason: ${reason}\n${meep}`);
@@ -41,7 +48,7 @@ var Reason;
41
48
  Reason["SIG_COUNT"] = "Signature count negative or greater than pubkey count";
42
49
  Reason["PUBKEY_COUNT"] = "Pubkey count negative or limit exceeded";
43
50
  Reason["INVALID_OPERAND_SIZE"] = "Invalid operand size";
44
- Reason["INVALID_NUMBER_RANGE"] = "Given operand is not a number within the valid range [-2^31...2^31]";
51
+ Reason["INVALID_NUMBER_RANGE"] = "Given operand is not a number within the valid range";
45
52
  Reason["IMPOSSIBLE_ENCODING"] = "The requested encoding is impossible to satisfy";
46
53
  Reason["INVALID_SPLIT_RANGE"] = "Invalid OP_SPLIT range";
47
54
  Reason["INVALID_BIT_COUNT"] = "Invalid number of bit set in OP_CHECKMULTISIG";
@@ -72,5 +79,6 @@ var Reason;
72
79
  Reason["NONCOMPRESSED_PUBKEY"] = "Using non-compressed public key";
73
80
  Reason["ILLEGAL_FORKID"] = "Illegal use of SIGHASH_FORKID";
74
81
  Reason["MUST_USE_FORKID"] = "Signature must use SIGHASH_FORKID";
82
+ Reason["UNKNOWN"] = "unknown error";
75
83
  })(Reason = exports.Reason || (exports.Reason = {}));
76
84
  //# sourceMappingURL=Errors.js.map
@@ -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)) {
@@ -52,18 +52,17 @@ class Transaction {
52
52
  }
53
53
  to(toOrOutputs, amount) {
54
54
  if (typeof toOrOutputs === 'string' && typeof amount === 'number') {
55
- this.outputs.push({ to: toOrOutputs, amount });
55
+ return this.to([{ to: toOrOutputs, amount }]);
56
56
  }
57
- else if (Array.isArray(toOrOutputs) && amount === undefined) {
57
+ if (Array.isArray(toOrOutputs) && amount === undefined) {
58
+ toOrOutputs.forEach(utils_js_1.validateRecipient);
58
59
  this.outputs = this.outputs.concat(toOrOutputs);
60
+ return this;
59
61
  }
60
- else {
61
- throw new Error('Incorrect arguments passed to function \'to\'');
62
- }
63
- return this;
62
+ throw new Error('Incorrect arguments passed to function \'to\'');
64
63
  }
65
64
  withOpReturn(chunks) {
66
- this.outputs.push(utils_2.createOpReturnOutput(chunks));
65
+ this.outputs.push((0, utils_js_1.createOpReturnOutput)(chunks));
67
66
  return this;
68
67
  }
69
68
  withAge(age) {
@@ -94,19 +93,19 @@ class Transaction {
94
93
  return __awaiter(this, void 0, void 0, function* () {
95
94
  this.locktime = (_a = this.locktime) !== null && _a !== void 0 ? _a : yield this.provider.getBlockHeight();
96
95
  yield this.setInputsAndOutputs();
97
- const secp256k1 = yield libauth_1.instantiateSecp256k1();
98
- const bytecode = utils_1.scriptToBytecode(this.redeemScript);
96
+ const secp256k1 = yield (0, libauth_1.instantiateSecp256k1)();
97
+ const bytecode = (0, utils_1.scriptToBytecode)(this.redeemScript);
99
98
  const inputs = this.inputs.map((utxo) => ({
100
99
  outpointIndex: utxo.vout,
101
- outpointTransactionHash: libauth_1.hexToBin(utxo.txid),
100
+ outpointTransactionHash: (0, libauth_1.hexToBin)(utxo.txid),
102
101
  sequenceNumber: this.sequence,
103
102
  unlockingBytecode: new Uint8Array(),
104
103
  }));
105
104
  const outputs = this.outputs.map((output) => {
106
105
  const lockingBytecode = typeof output.to === 'string'
107
- ? utils_2.addressToLockScript(output.to)
106
+ ? (0, utils_js_1.addressToLockScript)(output.to)
108
107
  : output.to;
109
- const satoshis = libauth_1.bigIntToBinUint64LE(BigInt(output.amount));
108
+ const satoshis = (0, libauth_1.bigIntToBinUint64LE)(BigInt(output.amount));
110
109
  return { lockingBytecode, satoshis };
111
110
  });
112
111
  const transaction = {
@@ -118,40 +117,40 @@ class Transaction {
118
117
  const inputScripts = [];
119
118
  this.inputs.forEach((utxo, i) => {
120
119
  // UTXO's with signature templates are signed using P2PKH
121
- if (interfaces_1.isSignableUtxo(utxo)) {
120
+ if ((0, interfaces_js_1.isSignableUtxo)(utxo)) {
122
121
  const pubkey = utxo.template.getPublicKey(secp256k1);
123
- const pubkeyHash = utils_1.hash160(pubkey);
122
+ const pubkeyHash = (0, utils_1.hash160)(pubkey);
124
123
  const addressContents = { payload: pubkeyHash, type: libauth_1.AddressType.p2pkh };
125
- const prevOutScript = libauth_1.addressContentsToLockingBytecode(addressContents);
124
+ const prevOutScript = (0, libauth_1.addressContentsToLockingBytecode)(addressContents);
126
125
  const hashtype = utxo.template.getHashType();
127
- const preimage = utils_2.createSighashPreimage(transaction, utxo, i, prevOutScript, hashtype);
128
- 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);
129
128
  const signature = utxo.template.generateSignature(sighash, secp256k1);
130
- const inputScript = utils_1.scriptToBytecode([signature, pubkey]);
129
+ const inputScript = (0, utils_1.scriptToBytecode)([signature, pubkey]);
131
130
  inputScripts.push(inputScript);
132
131
  return;
133
132
  }
134
133
  let covenantHashType = -1;
135
134
  const completeArgs = this.args.map((arg) => {
136
- if (!(arg instanceof SignatureTemplate_1.default))
135
+ if (!(arg instanceof SignatureTemplate_js_1.default))
137
136
  return arg;
138
137
  // First signature is used for sighash preimage (maybe not the best way)
139
138
  if (covenantHashType < 0)
140
139
  covenantHashType = arg.getHashType();
141
- const preimage = utils_2.createSighashPreimage(transaction, utxo, i, bytecode, arg.getHashType());
142
- 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);
143
142
  return arg.generateSignature(sighash, secp256k1);
144
143
  });
145
144
  const preimage = this.abiFunction.covenant
146
- ? utils_2.createSighashPreimage(transaction, utxo, i, bytecode, covenantHashType)
145
+ ? (0, utils_js_1.createSighashPreimage)(transaction, utxo, i, bytecode, covenantHashType)
147
146
  : undefined;
148
- 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);
149
148
  inputScripts.push(inputScript);
150
149
  });
151
150
  inputScripts.forEach((script, i) => {
152
151
  transaction.inputs[i].unlockingBytecode = script;
153
152
  });
154
- return libauth_1.binToHex(libauth_1.encodeTransaction(transaction));
153
+ return (0, libauth_1.binToHex)((0, libauth_1.encodeTransaction)(transaction));
155
154
  });
156
155
  }
157
156
  send(raw) {
@@ -164,19 +163,19 @@ class Transaction {
164
163
  }
165
164
  catch (e) {
166
165
  const reason = (_a = e.error) !== null && _a !== void 0 ? _a : e.message;
167
- 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));
168
167
  }
169
168
  });
170
169
  }
171
170
  getTxDetails(txid, raw) {
172
171
  return __awaiter(this, void 0, void 0, function* () {
173
172
  for (let retries = 0; retries < 1200; retries += 1) {
174
- yield delay_1.default(500);
173
+ yield (0, delay_1.default)(500);
175
174
  try {
176
175
  const hex = yield this.provider.getRawTransaction(txid);
177
176
  if (raw)
178
177
  return hex;
179
- const libauthTransaction = libauth_1.decodeTransaction(libauth_1.hexToBin(hex));
178
+ const libauthTransaction = (0, libauth_1.decodeTransaction)((0, libauth_1.hexToBin)(hex));
180
179
  return Object.assign(Object.assign({}, libauthTransaction), { txid, hex });
181
180
  }
182
181
  catch (ignored) {
@@ -190,30 +189,29 @@ class Transaction {
190
189
  meep() {
191
190
  return __awaiter(this, void 0, void 0, function* () {
192
191
  const tx = yield this.build();
193
- return utils_2.meep(tx, this.inputs, this.redeemScript);
192
+ return (0, utils_js_1.meep)(tx, this.inputs, this.redeemScript);
194
193
  });
195
194
  }
196
195
  setInputsAndOutputs() {
196
+ var _a;
197
197
  return __awaiter(this, void 0, void 0, function* () {
198
198
  if (this.outputs.length === 0) {
199
199
  throw Error('Attempted to build a transaction without outputs');
200
200
  }
201
201
  // Replace all SignatureTemplate with 65-length placeholder Uint8Arrays
202
- 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));
203
203
  // Create a placeholder preimage of the correct size
204
204
  const placeholderPreimage = this.abiFunction.covenant
205
- ? 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)))
206
206
  : undefined;
207
207
  // Create a placeholder input script for size calculation using the placeholder
208
208
  // arguments and correctly sized placeholder preimage
209
- 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);
210
210
  // Add one extra byte per input to over-estimate tx-in count
211
- const inputSize = utils_2.getInputSize(placeholderScript) + 1;
211
+ const inputSize = (0, utils_js_1.getInputSize)(placeholderScript) + 1;
212
212
  // Calculate amount to send and base fee (excluding additional fees per UTXO)
213
213
  const amount = this.outputs.reduce((acc, output) => acc + output.amount, 0);
214
- let fee = this.hardcodedFee
215
- ? this.hardcodedFee
216
- : 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;
217
215
  // Select and gather UTXOs and calculate fees and available funds
218
216
  let satsAvailable = 0;
219
217
  if (this.inputs.length > 0) {
@@ -247,10 +245,10 @@ class Transaction {
247
245
  }
248
246
  // Account for the fee of a change output
249
247
  if (!this.hardcodedFee) {
250
- change -= constants_1.P2SH_OUTPUT_SIZE;
248
+ change -= constants_js_1.P2SH_OUTPUT_SIZE;
251
249
  }
252
250
  // Add a change output if applicable
253
- if (change >= constants_1.DUST_LIMIT && change >= this.minChange) {
251
+ if (change >= constants_js_1.DUST_LIMIT && change >= this.minChange) {
254
252
  this.outputs.push({ to: this.address, amount: change });
255
253
  }
256
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;
@@ -30,6 +30,7 @@ export declare enum HashType {
30
30
  export declare const Network: {
31
31
  MAINNET: "mainnet";
32
32
  TESTNET: "testnet";
33
+ STAGING: "staging";
33
34
  REGTEST: "regtest";
34
35
  };
35
36
  export declare type Network = (typeof Network)[keyof typeof Network];
@@ -23,6 +23,7 @@ const literal = (l) => l;
23
23
  exports.Network = {
24
24
  MAINNET: literal('mainnet'),
25
25
  TESTNET: literal('testnet'),
26
+ STAGING: literal('staging'),
26
27
  REGTEST: literal('regtest'),
27
28
  };
28
29
  //# sourceMappingURL=interfaces.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 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?;