@caravan/psbt 1.9.1 → 1.9.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -253,22 +253,6 @@ Then copy the resulting built code (ends up in the lib directory) into the vendo
253
253
  we just use the asmjs build to avoid wasm complications in
254
254
  the build system.
255
255
 
256
- ### Experimental VM Modules
257
- This is related to the tiny-secp256k1 library which has difficulties importing in different environments.
258
-
259
- Note that the jest configs and the special prefix in the npm test scripts were needed
260
- to let jest understand the esmodule imports from the tiny-secp256k1 library.
261
-
262
- The npm script prefix in particular may result in a console warning when running tests:
263
-
264
- ```
265
- ExperimentalWarning: VM Modules is an experimental feature and might change at any time
266
- ```
267
-
268
- This can be safely ignored. See the [documentation in jest](https://jestjs.io/docs/ecmascript-modules)
269
- for more information on running with `--experimental-vm-modules`.
270
-
271
-
272
256
  ### What's with the `bitcoinjs-lib-v6` dependency?
273
257
 
274
258
  npm workspaces and maybe vite have issues with nested dependencies with
package/dist/index.d.ts CHANGED
@@ -99,9 +99,7 @@ declare class PsbtV2 extends PsbtV2Maps {
99
99
  get PSBT_GLOBAL_FALLBACK_LOCKTIME(): number | null;
100
100
  set PSBT_GLOBAL_FALLBACK_LOCKTIME(locktime: number | null);
101
101
  get PSBT_GLOBAL_INPUT_COUNT(): number;
102
- set PSBT_GLOBAL_INPUT_COUNT(count: number);
103
102
  get PSBT_GLOBAL_OUTPUT_COUNT(): number;
104
- set PSBT_GLOBAL_OUTPUT_COUNT(count: number);
105
103
  get PSBT_GLOBAL_TX_MODIFIABLE(): PsbtGlobalTxModifiableBits[];
106
104
  set PSBT_GLOBAL_TX_MODIFIABLE(modifiable: PsbtGlobalTxModifiableBits[]);
107
105
  get PSBT_GLOBAL_VERSION(): number;
@@ -402,6 +400,14 @@ declare class PsbtV2 extends PsbtV2Maps {
402
400
  * this PSBTv2. Accepts optional desired format as a string (default base64).
403
401
  */
404
402
  toV0(format?: "base64" | "hex"): string;
403
+ /**
404
+ * Updates the PSBT_GLOBAL_INPUT_COUNT field in the global map.
405
+ */
406
+ private updateGlobalInputCount;
407
+ /**
408
+ * Updates the PSBT_GLOBAL_OUTPUT_COUNT field in the global map.
409
+ */
410
+ private updateGlobalOutputCount;
405
411
  }
406
412
 
407
413
  interface PsbtInput {
package/dist/index.js CHANGED
@@ -1,3 +1,14 @@
1
+
2
+ if (typeof self === 'undefined') {
3
+ var self;
4
+ if (typeof window !== 'undefined') {
5
+ self = window;
6
+ } else if (typeof globalThis !== 'undefined') {
7
+ self = globalThis;
8
+ } else {
9
+ self = {}
10
+ }
11
+ }
1
12
  "use strict";
2
13
  var __create = Object.create;
3
14
  var __defProp = Object.defineProperty;
@@ -415,11 +426,6 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
415
426
  }
416
427
  return val.readUInt8(0);
417
428
  }
418
- set PSBT_GLOBAL_INPUT_COUNT(count) {
419
- const bw = new import_bufio3.BufferWriter();
420
- bw.writeU8(count);
421
- this.globalMap.set("04" /* PSBT_GLOBAL_INPUT_COUNT */, bw.render());
422
- }
423
429
  get PSBT_GLOBAL_OUTPUT_COUNT() {
424
430
  const val = this.globalMap.get("05" /* PSBT_GLOBAL_OUTPUT_COUNT */);
425
431
  if (val === void 0) {
@@ -427,11 +433,6 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
427
433
  }
428
434
  return val.readUInt8(0);
429
435
  }
430
- set PSBT_GLOBAL_OUTPUT_COUNT(count) {
431
- const bw = new import_bufio3.BufferWriter();
432
- bw.writeU8(count);
433
- this.globalMap.set("05" /* PSBT_GLOBAL_OUTPUT_COUNT */, bw.render());
434
- }
435
436
  get PSBT_GLOBAL_TX_MODIFIABLE() {
436
437
  const val = this.globalMap.get("06" /* PSBT_GLOBAL_TX_MODIFIABLE */)?.readUInt8(0) || 0;
437
438
  const modifiable = [];
@@ -863,8 +864,8 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
863
864
  create() {
864
865
  this.PSBT_GLOBAL_VERSION = 2;
865
866
  this.PSBT_GLOBAL_TX_VERSION = 2;
866
- this.PSBT_GLOBAL_INPUT_COUNT = 0;
867
- this.PSBT_GLOBAL_OUTPUT_COUNT = 0;
867
+ this.updateGlobalInputCount();
868
+ this.updateGlobalOutputCount();
868
869
  this.PSBT_GLOBAL_FALLBACK_LOCKTIME = 0;
869
870
  this.PSBT_GLOBAL_TX_MODIFIABLE = [
870
871
  "INPUTS" /* INPUTS */,
@@ -1091,7 +1092,8 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1091
1092
  bw.writeU32(sighashType);
1092
1093
  map.set("03" /* PSBT_IN_SIGHASH_TYPE */, bw.render());
1093
1094
  }
1094
- this.PSBT_GLOBAL_INPUT_COUNT = this.inputMaps.push(map);
1095
+ this.inputMaps.push(map);
1096
+ this.updateGlobalInputCount();
1095
1097
  }
1096
1098
  addOutput({
1097
1099
  amount,
@@ -1135,7 +1137,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1135
1137
  }
1136
1138
  }
1137
1139
  this.outputMaps.push(map);
1138
- this.PSBT_GLOBAL_OUTPUT_COUNT = this.outputMaps.length;
1140
+ this.updateGlobalOutputCount();
1139
1141
  }
1140
1142
  /**
1141
1143
  * Updater/Signer Methods
@@ -1156,7 +1158,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1156
1158
  }
1157
1159
  const newInputs = this.inputMaps.filter((_4, i6) => i6 !== index);
1158
1160
  this.inputMaps = newInputs;
1159
- this.PSBT_GLOBAL_INPUT_COUNT = this.inputMaps.length;
1161
+ this.updateGlobalInputCount();
1160
1162
  }
1161
1163
  /**
1162
1164
  * Removes an output-map from outputMaps.
@@ -1177,7 +1179,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1177
1179
  this.removePartialSig(index);
1178
1180
  }
1179
1181
  this.outputMaps = newOutputs;
1180
- this.PSBT_GLOBAL_OUTPUT_COUNT = this.outputMaps.length;
1182
+ this.updateGlobalOutputCount();
1181
1183
  }
1182
1184
  /**
1183
1185
  * Checks that all provided flags are present in PSBT_GLOBAL_TX_MODIFIABLE.
@@ -1431,6 +1433,22 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1431
1433
  converterMap.convertToV0();
1432
1434
  return converterMap.serialize(format2);
1433
1435
  }
1436
+ /**
1437
+ * Updates the PSBT_GLOBAL_INPUT_COUNT field in the global map.
1438
+ */
1439
+ updateGlobalInputCount() {
1440
+ const bw = new import_bufio3.BufferWriter();
1441
+ bw.writeU8(this.inputMaps.length);
1442
+ this.globalMap.set("04" /* PSBT_GLOBAL_INPUT_COUNT */, bw.render());
1443
+ }
1444
+ /**
1445
+ * Updates the PSBT_GLOBAL_OUTPUT_COUNT field in the global map.
1446
+ */
1447
+ updateGlobalOutputCount() {
1448
+ const bw = new import_bufio3.BufferWriter();
1449
+ bw.writeU8(this.outputMaps.length);
1450
+ this.globalMap.set("05" /* PSBT_GLOBAL_OUTPUT_COUNT */, bw.render());
1451
+ }
1434
1452
  };
1435
1453
 
1436
1454
  // src/psbtv0/psbt.ts
package/dist/index.mjs CHANGED
@@ -1,3 +1,14 @@
1
+
2
+ if (typeof self === 'undefined') {
3
+ var self;
4
+ if (typeof window !== 'undefined') {
5
+ self = window;
6
+ } else if (typeof globalThis !== 'undefined') {
7
+ self = globalThis;
8
+ } else {
9
+ self = {}
10
+ }
11
+ }
1
12
  var __defProp = Object.defineProperty;
2
13
  var __export = (target, all) => {
3
14
  for (var name in all)
@@ -374,11 +385,6 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
374
385
  }
375
386
  return val.readUInt8(0);
376
387
  }
377
- set PSBT_GLOBAL_INPUT_COUNT(count) {
378
- const bw = new BufferWriter3();
379
- bw.writeU8(count);
380
- this.globalMap.set("04" /* PSBT_GLOBAL_INPUT_COUNT */, bw.render());
381
- }
382
388
  get PSBT_GLOBAL_OUTPUT_COUNT() {
383
389
  const val = this.globalMap.get("05" /* PSBT_GLOBAL_OUTPUT_COUNT */);
384
390
  if (val === void 0) {
@@ -386,11 +392,6 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
386
392
  }
387
393
  return val.readUInt8(0);
388
394
  }
389
- set PSBT_GLOBAL_OUTPUT_COUNT(count) {
390
- const bw = new BufferWriter3();
391
- bw.writeU8(count);
392
- this.globalMap.set("05" /* PSBT_GLOBAL_OUTPUT_COUNT */, bw.render());
393
- }
394
395
  get PSBT_GLOBAL_TX_MODIFIABLE() {
395
396
  const val = this.globalMap.get("06" /* PSBT_GLOBAL_TX_MODIFIABLE */)?.readUInt8(0) || 0;
396
397
  const modifiable = [];
@@ -822,8 +823,8 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
822
823
  create() {
823
824
  this.PSBT_GLOBAL_VERSION = 2;
824
825
  this.PSBT_GLOBAL_TX_VERSION = 2;
825
- this.PSBT_GLOBAL_INPUT_COUNT = 0;
826
- this.PSBT_GLOBAL_OUTPUT_COUNT = 0;
826
+ this.updateGlobalInputCount();
827
+ this.updateGlobalOutputCount();
827
828
  this.PSBT_GLOBAL_FALLBACK_LOCKTIME = 0;
828
829
  this.PSBT_GLOBAL_TX_MODIFIABLE = [
829
830
  "INPUTS" /* INPUTS */,
@@ -1050,7 +1051,8 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1050
1051
  bw.writeU32(sighashType);
1051
1052
  map.set("03" /* PSBT_IN_SIGHASH_TYPE */, bw.render());
1052
1053
  }
1053
- this.PSBT_GLOBAL_INPUT_COUNT = this.inputMaps.push(map);
1054
+ this.inputMaps.push(map);
1055
+ this.updateGlobalInputCount();
1054
1056
  }
1055
1057
  addOutput({
1056
1058
  amount,
@@ -1094,7 +1096,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1094
1096
  }
1095
1097
  }
1096
1098
  this.outputMaps.push(map);
1097
- this.PSBT_GLOBAL_OUTPUT_COUNT = this.outputMaps.length;
1099
+ this.updateGlobalOutputCount();
1098
1100
  }
1099
1101
  /**
1100
1102
  * Updater/Signer Methods
@@ -1115,7 +1117,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1115
1117
  }
1116
1118
  const newInputs = this.inputMaps.filter((_4, i6) => i6 !== index);
1117
1119
  this.inputMaps = newInputs;
1118
- this.PSBT_GLOBAL_INPUT_COUNT = this.inputMaps.length;
1120
+ this.updateGlobalInputCount();
1119
1121
  }
1120
1122
  /**
1121
1123
  * Removes an output-map from outputMaps.
@@ -1136,7 +1138,7 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1136
1138
  this.removePartialSig(index);
1137
1139
  }
1138
1140
  this.outputMaps = newOutputs;
1139
- this.PSBT_GLOBAL_OUTPUT_COUNT = this.outputMaps.length;
1141
+ this.updateGlobalOutputCount();
1140
1142
  }
1141
1143
  /**
1142
1144
  * Checks that all provided flags are present in PSBT_GLOBAL_TX_MODIFIABLE.
@@ -1390,6 +1392,22 @@ var PsbtV2 = class _PsbtV2 extends PsbtV2Maps {
1390
1392
  converterMap.convertToV0();
1391
1393
  return converterMap.serialize(format2);
1392
1394
  }
1395
+ /**
1396
+ * Updates the PSBT_GLOBAL_INPUT_COUNT field in the global map.
1397
+ */
1398
+ updateGlobalInputCount() {
1399
+ const bw = new BufferWriter3();
1400
+ bw.writeU8(this.inputMaps.length);
1401
+ this.globalMap.set("04" /* PSBT_GLOBAL_INPUT_COUNT */, bw.render());
1402
+ }
1403
+ /**
1404
+ * Updates the PSBT_GLOBAL_OUTPUT_COUNT field in the global map.
1405
+ */
1406
+ updateGlobalOutputCount() {
1407
+ const bw = new BufferWriter3();
1408
+ bw.writeU8(this.outputMaps.length);
1409
+ this.globalMap.set("05" /* PSBT_GLOBAL_OUTPUT_COUNT */, bw.render());
1410
+ }
1393
1411
  };
1394
1412
 
1395
1413
  // src/psbtv0/psbt.ts
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@caravan/psbt",
3
- "version": "1.9.1",
3
+ "version": "1.9.3",
4
4
  "description": "typescript library for working with PSBTs",
5
5
  "main": "./dist/index.js",
6
6
  "types": "./dist/index.d.ts",
@@ -12,9 +12,9 @@
12
12
  ],
13
13
  "exports": {
14
14
  ".": {
15
+ "types": "./dist/index.d.ts",
15
16
  "import": "./dist/index.mjs",
16
- "require": "./dist/index.js",
17
- "types": "./dist/index.d.ts"
17
+ "require": "./dist/index.js"
18
18
  }
19
19
  },
20
20
  "engines": {
@@ -28,11 +28,12 @@
28
28
  "scripts": {
29
29
  "build": "tsup src/index.ts --format cjs,esm --dts",
30
30
  "dev": "npm run build -- --watch",
31
- "test": "NODE_OPTIONS=--experimental-vm-modules npx jest src",
32
- "lint": "eslint src",
31
+ "test": "vitest run",
32
+ "test:watch": "vitest watch",
33
+ "lint": "eslint src/",
34
+ "lint:fix": "eslint --fix src/",
33
35
  "ci": "npm run lint && npm run test",
34
- "test:watch": "npm run test -- --watch",
35
- "test:debug": "node --inspect-brk ../../node_modules/.bin/jest --runInBand"
36
+ "test:debug": "node --inspect-brk ../../node_modules/.bin/vitest run"
36
37
  },
37
38
  "keywords": [
38
39
  "bitcoin",
@@ -55,16 +56,9 @@
55
56
  "@caravan/eslint-config": "*",
56
57
  "@caravan/multisig": "*",
57
58
  "@caravan/typescript-config": "*",
58
- "@inrupt/jest-jsdom-polyfills": "^3.2.1",
59
- "@jest/globals": "^29.7.0",
60
- "@types/jest": "^29.5.12",
61
59
  "eslint-plugin-prettier": "^5.1.3",
62
- "jest": "^29.4.1",
63
- "jsdom": "24.0.0",
64
- "jsdom-global": "3.0.2",
65
60
  "lodash": "^4.17.21",
66
61
  "react-silence": "^1.0.4",
67
- "ts-jest": "^29.1.2",
68
62
  "ts-node": "^10.9.2",
69
63
  "tsup": "^7.2.0",
70
64
  "typescript": "^5.2.2"