@caravan/psbt 1.0.1 → 1.1.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.
@@ -1,5 +1,5 @@
1
1
 
2
- > @caravan/psbt@1.0.1 build
2
+ > @caravan/psbt@1.1.0 build
3
3
  > tsup src/index.ts --format cjs,esm --dts
4
4
 
5
5
  CLI Building entry: src/index.ts
@@ -9,11 +9,11 @@
9
9
  CLI Target: esnext
10
10
  CJS Build start
11
11
  ESM Build start
12
- ESM dist/index.mjs 29.75 KB
13
- ESM ⚡️ Build success in 38ms
14
- CJS dist/index.js 31.42 KB
15
- CJS ⚡️ Build success in 38ms
12
+ CJS dist/index.js 36.78 KB
13
+ CJS ⚡️ Build success in 59ms
14
+ ESM dist/index.mjs 35.12 KB
15
+ ESM ⚡️ Build success in 60ms
16
16
  DTS Build start
17
- DTS ⚡️ Build success in 2270ms
18
- DTS dist/index.d.ts 9.90 KB
19
- DTS dist/index.d.mts 9.90 KB
17
+ DTS ⚡️ Build success in 2379ms
18
+ DTS dist/index.d.ts 11.83 KB
19
+ DTS dist/index.d.mts 11.83 KB
@@ -1,5 +1,5 @@
1
1
 
2
- > @caravan/psbt@1.0.1 lint
2
+ > @caravan/psbt@1.1.0 lint
3
3
  > eslint src
4
4
 
5
5
 
@@ -12,19 +12,24 @@
12
12
  430:13 warning 'signature' is never reassigned. Use 'const' instead prefer-const
13
13
 
14
14
  /home/runner/work/caravan/caravan/packages/caravan-psbt/src/psbtv2/psbtv2.test.ts
15
- 1025:42 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
16
- 1025:53 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
17
- 1082:45 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
18
- 1082:56 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
15
+ 915:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
16
+ 919:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
17
+ 928:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
18
+ 932:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
19
+ 940:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
20
+ 945:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
21
+ 953:14 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
22
+ 1169:42 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
23
+ 1169:53 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
24
+ 1231:45 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
25
+ 1231:56 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
19
26
 
20
27
  /home/runner/work/caravan/caravan/packages/caravan-psbt/src/psbtv2/psbtv2.ts
21
- 129:9 warning 'modifiable' is never reassigned. Use 'const' instead prefer-const
22
- 476:9 warning 'heights' is never reassigned. Use 'const' instead prefer-const
23
- 477:9 warning 'times' is never reassigned. Use 'const' instead prefer-const
24
- 945:9 warning 'txInputs' is never reassigned. Use 'const' instead prefer-const
25
- 945:19 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
26
- 967:9 warning 'txOutputs' is never reassigned. Use 'const' instead prefer-const
27
- 967:20 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
28
+ 132:9 warning 'modifiable' is never reassigned. Use 'const' instead prefer-const
29
+ 676:9 warning 'heights' is never reassigned. Use 'const' instead prefer-const
30
+ 677:9 warning 'times' is never reassigned. Use 'const' instead prefer-const
31
+ 1189:21 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
32
+ 1211:22 warning Unexpected any. Specify a different type @typescript-eslint/no-explicit-any
28
33
 
29
34
  /home/runner/work/caravan/caravan/packages/caravan-psbt/src/psbtv2/types.ts
30
35
  32:3 warning Duplicate enum member value 01 @typescript-eslint/no-duplicate-enum-values
@@ -44,6 +49,6 @@
44
49
  65:3 warning Duplicate enum member value 07 @typescript-eslint/no-duplicate-enum-values
45
50
  66:3 warning Duplicate enum member value fc @typescript-eslint/no-duplicate-enum-values
46
51
 
47
- 33 problems (0 errors, 33 warnings)
48
- 0 errors and 9 warnings potentially fixable with the `--fix` option.
52
+ 38 problems (0 errors, 38 warnings)
53
+ 0 errors and 7 warnings potentially fixable with the `--fix` option.
49
54
 
@@ -1,5 +1,5 @@
1
1
 
2
- > @caravan/psbt@1.0.1 test
2
+ > @caravan/psbt@1.1.0 test
3
3
  > jest src
4
4
 
5
5
  PASS src/psbt.test.ts
@@ -9,62 +9,62 @@ PASS src/psbtv2/psbtv2.test.ts
9
9
  console.warn
10
10
  Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!
11
11
 
12
- 592 | */
13
- 593 | public dangerouslySetGlobalTxVersion1() {
14
- > 594 | console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
12
+ 805 | );
13
+ 806 | }
14
+ > 807 | console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
15
15
  | ^
16
- 595 | const bw = new BufferWriter();
17
- 596 | bw.writeI32(1);
18
- 597 | this.globalMap.set(KeyType.PSBT_GLOBAL_TX_VERSION, bw.render());
16
+ 808 | const bw = new BufferWriter();
17
+ 809 | bw.writeI32(1);
18
+ 810 | this.globalMap.set(KeyType.PSBT_GLOBAL_TX_VERSION, bw.render());
19
19
 
20
- at PsbtV2.dangerouslySetGlobalTxVersion1 (src/psbtv2/psbtv2.ts:594:13)
21
- at Function.FromV0 (src/psbtv2/psbtv2.ts:928:14)
22
- at t (src/psbtv2/psbtv2.test.ts:947:34)
20
+ at PsbtV2.dangerouslySetGlobalTxVersion1 (src/psbtv2/psbtv2.ts:807:13)
21
+ at Function.FromV0 (src/psbtv2/psbtv2.ts:1173:14)
22
+ at t (src/psbtv2/psbtv2.test.ts:1091:34)
23
23
  at Object.<anonymous> (../../node_modules/expect/build/toThrowMatchers.js:74:11)
24
24
  at Object.throwingMatcher [as toThrow] (../../node_modules/expect/build/index.js:320:21)
25
- at src/psbtv2/psbtv2.test.ts:948:25
25
+ at src/psbtv2/psbtv2.test.ts:1092:25
26
26
 
27
27
  console.warn
28
28
  Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!
29
29
 
30
- 592 | */
31
- 593 | public dangerouslySetGlobalTxVersion1() {
32
- > 594 | console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
30
+ 805 | );
31
+ 806 | }
32
+ > 807 | console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
33
33
  | ^
34
- 595 | const bw = new BufferWriter();
35
- 596 | bw.writeI32(1);
36
- 597 | this.globalMap.set(KeyType.PSBT_GLOBAL_TX_VERSION, bw.render());
34
+ 808 | const bw = new BufferWriter();
35
+ 809 | bw.writeI32(1);
36
+ 810 | this.globalMap.set(KeyType.PSBT_GLOBAL_TX_VERSION, bw.render());
37
37
 
38
- at PsbtV2.dangerouslySetGlobalTxVersion1 (src/psbtv2/psbtv2.ts:594:13)
39
- at Function.FromV0 (src/psbtv2/psbtv2.ts:928:14)
40
- at t (src/psbtv2/psbtv2.test.ts:947:34)
38
+ at PsbtV2.dangerouslySetGlobalTxVersion1 (src/psbtv2/psbtv2.ts:807:13)
39
+ at Function.FromV0 (src/psbtv2/psbtv2.ts:1173:14)
40
+ at t (src/psbtv2/psbtv2.test.ts:1091:34)
41
41
  at Object.<anonymous> (../../node_modules/expect/build/toThrowMatchers.js:74:11)
42
42
  at Object.throwingMatcher [as toThrow] (../../node_modules/expect/build/index.js:320:21)
43
- at src/psbtv2/psbtv2.test.ts:948:25
43
+ at src/psbtv2/psbtv2.test.ts:1092:25
44
44
 
45
45
  console.warn
46
46
  Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!
47
47
 
48
- 592 | */
49
- 593 | public dangerouslySetGlobalTxVersion1() {
50
- > 594 | console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
48
+ 805 | );
49
+ 806 | }
50
+ > 807 | console.warn("Dangerously setting PsbtV2.PSBT_GLOBAL_TX_VERSION to 1!");
51
51
  | ^
52
- 595 | const bw = new BufferWriter();
53
- 596 | bw.writeI32(1);
54
- 597 | this.globalMap.set(KeyType.PSBT_GLOBAL_TX_VERSION, bw.render());
52
+ 808 | const bw = new BufferWriter();
53
+ 809 | bw.writeI32(1);
54
+ 810 | this.globalMap.set(KeyType.PSBT_GLOBAL_TX_VERSION, bw.render());
55
55
 
56
- at PsbtV2.dangerouslySetGlobalTxVersion1 (src/psbtv2/psbtv2.ts:594:13)
57
- at Function.FromV0 (src/psbtv2/psbtv2.ts:928:14)
58
- at src/psbtv2/psbtv2.test.ts:959:25
56
+ at PsbtV2.dangerouslySetGlobalTxVersion1 (src/psbtv2/psbtv2.ts:807:13)
57
+ at Function.FromV0 (src/psbtv2/psbtv2.ts:1173:14)
58
+ at src/psbtv2/psbtv2.test.ts:1103:25
59
59
 
60
60
  console.error
61
61
  Error:
62
- at PsbtV2.<anonymous> (/home/runner/work/caravan/caravan/packages/caravan-psbt/src/psbtv2/psbtv2.test.ts:1044:13)
62
+ at PsbtV2.<anonymous> (/home/runner/work/caravan/caravan/packages/caravan-psbt/src/psbtv2/psbtv2.test.ts:1193:13)
63
63
  at /home/runner/work/caravan/caravan/node_modules/jest-mock/build/index.js:397:39
64
64
  at PsbtV2.<anonymous> (/home/runner/work/caravan/caravan/node_modules/jest-mock/build/index.js:404:13)
65
65
  at PsbtV2.mockConstructor [as handleSighashType] (/home/runner/work/caravan/caravan/node_modules/jest-mock/build/index.js:148:19)
66
- at PsbtV2.addPartialSig (/home/runner/work/caravan/caravan/packages/caravan-psbt/src/psbtv2/psbtv2.ts:833:12)
67
- at Object.<anonymous> (/home/runner/work/caravan/caravan/packages/caravan-psbt/src/psbtv2/psbtv2.test.ts:1049:10)
66
+ at PsbtV2.addPartialSig (/home/runner/work/caravan/caravan/packages/caravan-psbt/src/psbtv2/psbtv2.ts:1077:12)
67
+ at Object.<anonymous> (/home/runner/work/caravan/caravan/packages/caravan-psbt/src/psbtv2/psbtv2.test.ts:1198:10)
68
68
  at Promise.then.completed (/home/runner/work/caravan/caravan/node_modules/jest-circus/build/utils.js:298:28)
69
69
  at new Promise (<anonymous>)
70
70
  at callAsyncCircusFn (/home/runner/work/caravan/caravan/node_modules/jest-circus/build/utils.js:231:10)
@@ -80,20 +80,20 @@ PASS src/psbtv2/psbtv2.test.ts
80
80
  at runTest (/home/runner/work/caravan/caravan/node_modules/jest-runner/build/runTest.js:444:34)
81
81
  at Object.worker (/home/runner/work/caravan/caravan/node_modules/jest-runner/build/testWorker.js:106:12)
82
82
 
83
- 833 | this.handleSighashType(sig);
84
- 834 | } catch (err) {
85
- > 835 | console.error(err);
86
- | ^
87
- 836 | // To remain atomic, attempt to reset everything to the way it was.
88
- 837 | this.inputMaps[inputIndex].delete(key);
89
- 838 | this.PSBT_GLOBAL_TX_MODIFIABLE = modBackup;
83
+ 1077 | this.handleSighashType(sig);
84
+ 1078 | } catch (err) {
85
+ > 1079 | console.error(err);
86
+ | ^
87
+ 1080 | // To remain atomic, attempt to reset everything to the way it was.
88
+ 1081 | this.inputMaps[inputIndex].delete(key);
89
+ 1082 | this.PSBT_GLOBAL_TX_MODIFIABLE = modBackup;
90
90
 
91
- at PsbtV2.addPartialSig (src/psbtv2/psbtv2.ts:835:15)
92
- at Object.<anonymous> (src/psbtv2/psbtv2.test.ts:1049:10)
91
+ at PsbtV2.addPartialSig (src/psbtv2/psbtv2.ts:1079:15)
92
+ at Object.<anonymous> (src/psbtv2/psbtv2.test.ts:1198:10)
93
93
 
94
94
 
95
95
  Test Suites: 2 passed, 2 total
96
- Tests: 177 passed, 177 total
96
+ Tests: 192 passed, 192 total
97
97
  Snapshots: 0 total
98
- Time: 5.102 s
98
+ Time: 5.211 s
99
99
  Ran all test suites matching /src/i.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @caravan/psbt
2
2
 
3
+ ## 1.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#65](https://github.com/caravan-bitcoin/caravan/pull/65) [`514b72f`](https://github.com/caravan-bitcoin/caravan/commit/514b72fe071ee39db833d4d6b6c4a95df288008e) Thanks [@Shadouts](https://github.com/Shadouts)! - PsbtV2 operator role validation getters are added to provide a way for validating role readiness. These getters are used in some Constructor and Signer methods. For example, an error will be thrown if `addPartialSig` is called when the PsbtV2 is not ready for a Signer.
8
+
3
9
  ## 1.0.1
4
10
 
5
11
  ### Patch Changes
package/README.md CHANGED
@@ -19,6 +19,12 @@ A set of utilities for working with PSBTs.
19
19
  - [PSBTv2](#psbtv2)
20
20
  - [Exports](#psbtv2-exports)
21
21
  - [`class PsbtV2`](#class-psbtv2)
22
+ - [`get isReadyForConstructor`](#get-isreadyforconstructor)
23
+ - [`get isReadyForUpdater`](#get-isreadyforupdater)
24
+ - [`get isReadyForSigner`](#get-isreadyforsigner)
25
+ - [`get isReadyForCombiner`](#get-isreadyforcombiner)
26
+ - [`get isReadyForInputFinalizer`](#get-isreadyforinputfinalizer)
27
+ - [`get isReadyForTransactionExtractor`](#get-isreadyfortransactionextractor)
22
28
  - [`get nLockTime`](#get-nlocktime)
23
29
  - [`public dangerouslySetGlobalTxVersion1`](#public-dangerouslysetglobaltxversion1)
24
30
  - [`public addGlobalXpub`](#public-addglobalxpub)
@@ -30,8 +36,6 @@ A set of utilities for working with PSBTs.
30
36
  - [`public removePartialSig`](#public-removepartialsig)
31
37
  - [`static PsbtV2.FromV0`](#static-psbtv2fromv0)
32
38
  - [`function getPsbtVersionNumber`](#function-getpsbtversionnumber)
33
- - [`abstract class PsbtV2Maps`](#abstract-class-psbtv2maps)
34
- - [`public copy`](#public-copy)
35
39
  - [Concepts](#concepts)
36
40
  - [The operator role saga](#the-operator-role-saga)
37
41
  - [TODO](#todo)
@@ -104,6 +108,56 @@ An object class representing a PSBTv2 and its current state. While not yet compl
104
108
 
105
109
  Getters and setters are provided for the keytypes defined in [BIP 174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki) and [BIP 370](https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki). These getters/setters are named after the keytype in ALL_CAPS_SNAKE like `PsbtV2.PSBT_GLOBAL_VERSION`. Additional getters/setters may be listed in the following API documentation.
106
110
 
111
+ ##### `get isReadyForConstructor`
112
+
113
+ A getter to check readiness for an operator role. Operator roles are defined in [BIP 174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#user-content-Roles) and [BIP 370](https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#user-content-Roles).
114
+
115
+ Returns `true` if the PsbtV2 is ready for an operator taking the Constructor role.
116
+
117
+ This check assumes that the Creator used this class's constructor method to initialize the PsbtV2 without passing a psbt (constructor defaults were set).
118
+
119
+ ##### `get isReadyForUpdater`
120
+
121
+ A getter to check readiness for an operator role. Operator roles are defined in [BIP 174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#user-content-Roles) and [BIP 370](https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#user-content-Roles).
122
+
123
+ Returns `true` if the PsbtV2 is ready for an operator taking the Updater role.
124
+
125
+ Before signatures are added, but after an input is added, a PsbtV2 is likely to be ready for Constructor, ready for Updater, and ready for Signer simultaneously.
126
+
127
+ According to BIP370, the Updater can modify the sequence number, but it is unclear if the Updater retains permissions provided in psbtv0 (BIP174). It is likely not the case that the Updater has the same permissions as previously because it seems to now be the realm of the Constructor to add inputs and outputs.
128
+
129
+ ##### `get isReadyForSigner`
130
+
131
+ A getter to check readiness for an operator role. Operator roles are defined in [BIP 174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#user-content-Roles) and [BIP 370](https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#user-content-Roles).
132
+
133
+ Returns `true` if the PsbtV2 is ready for an operator taking the Signer role.
134
+
135
+ Right now, this method only checks for two things: There is an input for signing and `this.isReadyForTransactionExtractor === false`. The point of the latter is to check that the PsbtV2 has not been finalized.
136
+
137
+ A future improvement to this method might be to more thoroughly check inputs to determine if the PsbtV2 does or does not need to collect more signatures.
138
+
139
+ ##### `get isReadyForCombiner`
140
+
141
+ A getter to check readiness for an operator role. Operator roles are defined in [BIP 174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#user-content-Roles) and [BIP 370](https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#user-content-Roles).
142
+
143
+ Returns `true` if the PsbtV2 is ready for an operator taking the Combiner role.
144
+
145
+ Since a Combiner can potentially provide everything needed to a mostly blank PsbtV2, instances of a PsbtV2 are likely to return true as long as inputs have not been finalized.
146
+
147
+ ##### `get isReadyForInputFinalizer`
148
+
149
+ A getter to check readiness for an operator role. Operator roles are defined in [BIP 174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#user-content-Roles) and [BIP 370](https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#user-content-Roles).
150
+
151
+ Callable, but unimplemented. Returns `undefined`.
152
+
153
+ ##### `get isReadyForTransactionExtractor`
154
+
155
+ A getter to check readiness for an operator role. Operator roles are defined in [BIP 174](https://github.com/bitcoin/bips/blob/master/bip-0174.mediawiki#user-content-Roles) and [BIP 370](https://github.com/bitcoin/bips/blob/master/bip-0370.mediawiki#user-content-Roles).
156
+
157
+ Returns `true` if the PsbtV2 is ready for an operator taking the Transaction Extractor role.
158
+
159
+ If all the inputs have been finalized, then the psbt is ready for the Transaction Extractor. According to BIP 174, it's the responsibility of the Input Finalizer to add scriptSigs or scriptWitnesses and then remove other details besides the UTXO. This getter checks that the Input Finalizer has finished its job.
160
+
107
161
  ##### `get nLockTime`
108
162
 
109
163
  Returns the `nLockTime` field for the psbt as if it were a bitcoin transaction.
@@ -114,7 +168,7 @@ From BIP 370:
114
168
 
115
169
  ##### `public dangerouslySetGlobalTxVersion1`
116
170
 
117
- A helper method for compatibility, but seems to no-longer be required.
171
+ A helper method for compatibility. Some devices require a psbtV2 configured with a transaction version of 1. BIP370 leaves room for this if the Creator is also the Constructor.
118
172
 
119
173
  ##### `public addGlobalXpub`
120
174
 
@@ -171,27 +225,28 @@ Attempts to return a `PsbtV2` by converting from a PSBTv0 string or Buffer
171
225
 
172
226
  Attempts to extract the version number as uint32LE from raw psbt regardless of psbt validity.
173
227
 
174
- #### `abstract class PsbtV2Maps`
228
+ ## Concepts
175
229
 
176
- This is provided for utility for compatibility and to allow for mapping, map copying, and serialization operations for psbts. This does almost no validation, so do not rely on it for ensuring a valid psbt.
230
+ ### The operator role saga
177
231
 
178
- ##### `public copy`
232
+ The PSBT is a resource which may be passed between several operators or services. It's best to look at the operator roles as stages of a saga. The next valid operator role(s) can be determined by the state of the PSBT. The actions allowed for a PSBT are determined by which operator role the PSBT can be now and which role it could be next. See the following blog article at Unchained for a more detailed illustration: [Operator roles: Life stages in the saga of a PSBT](https://unchained.com/blog/operator-roles-life-stages-in-the-saga-of-a-psbt/)
179
233
 
180
- Copies the maps in this PsbtV2 object to another PsbtV2 object.
234
+ ### TODO
181
235
 
182
- NOTE: This copy method is made available to achieve parity with the PSBT api required by `ledger-bitcoin` for creating merklized PSBTs. HOWEVER, it is not recommended to use this when avoidable as copying maps bypasses the validation defined in the constructor, so it could create a psbtv2 in an invalid psbt state. PsbtV2.serialize is preferable whenever possible.
236
+ #### PsbtV2
183
237
 
184
- ## Concepts
238
+ ##### Operator role validation
185
239
 
186
- ### The operator role saga
240
+ Work remains for determining readiness for operator roles Input Finalizer and Transaction Extractor. The getters responsible for these checks are `isReadyForInputFinalizer` and `isReadyForTransactionExtractor`. Work also remains to expand the PsbtV2 method functionality beyond the Signer role. A huge benefit might be gained from building methods aimed at the Combiner role.
187
241
 
188
- The PSBT is a resource which may be passed between several operators or services. It's best to look at the operator roles as stages of a saga. The next valid operator role(s) can be determined by the state of the PSBT. The actions allowed for a PSBT are determined by which operator role the PSBT can be now and which role it could be next. See the following blog article at Unchained for a more detailed illustration: [Operator roles: Life stages in the saga of a PSBT](https://unchained.com/blog/operator-roles-life-stages-in-the-saga-of-a-psbt/)
242
+ ##### Class constructor
189
243
 
190
- ### TODO
244
+ The constructor must be able to handle values which the Creator role is responsible for. Currently, the constructor can only accept an optional psbt which it parses to configure itself. It would be ideal if a fresh PsbtV2 instance could be initialized with minimal arguments for which the Creator role is responsible. See `private create()`.
245
+
246
+ ##### Add input timelocks
191
247
 
192
- Work remains on PSBTv2 for determining the next valid operator role(s) and restricting actions based on PSBT state. In other words, if the state of the PSBT suggests the PSBT might be in role A and is ready for role B, it should only allow actions within the context of role A or B.
248
+ The `public addInput` must be able to properly handle input locktimes which interact with the global value.
193
249
 
194
- The following list is a non-comprehensive list of validation checks which must be performed:
250
+ ##### Add input sighash_single
195
251
 
196
- - Check ready for Updater role on `addInput`, `addOutput`, `deleteInput`, and `deleteOuput`.
197
- - Check ready for Signer role on `addPartialSig`.
252
+ The `public addInput` must be able to properly handle new inputs when the psbt has a `SIGHASH_SINGLE` flag on `PSBT_GLOBAL_TX_MODIFIABLE`.
package/dist/index.d.mts CHANGED
@@ -74,7 +74,7 @@ declare class PsbtV2 extends PsbtV2Maps {
74
74
  /**
75
75
  * Globals Getters/Setters
76
76
  */
77
- get PSBT_GLOBAL_XPUB(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
77
+ get PSBT_GLOBAL_XPUB(): NonUniqueKeyTypeValue[];
78
78
  get PSBT_GLOBAL_TX_VERSION(): number;
79
79
  set PSBT_GLOBAL_TX_VERSION(version: number);
80
80
  get PSBT_GLOBAL_FALLBACK_LOCKTIME(): number | null;
@@ -87,7 +87,7 @@ declare class PsbtV2 extends PsbtV2Maps {
87
87
  set PSBT_GLOBAL_TX_MODIFIABLE(modifiable: PsbtGlobalTxModifiableBits[]);
88
88
  get PSBT_GLOBAL_VERSION(): number;
89
89
  set PSBT_GLOBAL_VERSION(version: number);
90
- get PSBT_GLOBAL_PROPRIETARY(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
90
+ get PSBT_GLOBAL_PROPRIETARY(): NonUniqueKeyTypeValue[];
91
91
  /**
92
92
  * Input Getters/Setters
93
93
  */
@@ -97,23 +97,23 @@ declare class PsbtV2 extends PsbtV2Maps {
97
97
  get PSBT_IN_SIGHASH_TYPE(): (number | null)[];
98
98
  get PSBT_IN_REDEEM_SCRIPT(): (string | null)[];
99
99
  get PSBT_IN_WITNESS_SCRIPT(): (string | null)[];
100
- get PSBT_IN_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
100
+ get PSBT_IN_BIP32_DERIVATION(): NonUniqueKeyTypeValue[][];
101
101
  get PSBT_IN_FINAL_SCRIPTSIG(): (string | null)[];
102
102
  get PSBT_IN_FINAL_SCRIPTWITNESS(): (string | null)[];
103
103
  get PSBT_IN_POR_COMMITMENT(): (string | null)[];
104
- get PSBT_IN_RIPEMD160(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
105
- get PSBT_IN_SHA256(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
106
- get PSBT_IN_HASH160(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
107
- get PSBT_IN_HASH256(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
104
+ get PSBT_IN_RIPEMD160(): NonUniqueKeyTypeValue[][];
105
+ get PSBT_IN_SHA256(): NonUniqueKeyTypeValue[][];
106
+ get PSBT_IN_HASH160(): NonUniqueKeyTypeValue[][];
107
+ get PSBT_IN_HASH256(): NonUniqueKeyTypeValue[][];
108
108
  get PSBT_IN_PREVIOUS_TXID(): string[];
109
109
  get PSBT_IN_OUTPUT_INDEX(): number[];
110
110
  get PSBT_IN_SEQUENCE(): (number | null)[];
111
111
  get PSBT_IN_REQUIRED_TIME_LOCKTIME(): (number | null)[];
112
112
  get PSBT_IN_REQUIRED_HEIGHT_LOCKTIME(): (number | null)[];
113
113
  get PSBT_IN_TAP_KEY_SIG(): (string | null)[];
114
- get PSBT_IN_TAP_SCRIPT_SIG(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
115
- get PSBT_IN_TAP_LEAF_SCRIPT(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
116
- get PSBT_IN_TAP_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
114
+ get PSBT_IN_TAP_SCRIPT_SIG(): NonUniqueKeyTypeValue[][];
115
+ get PSBT_IN_TAP_LEAF_SCRIPT(): NonUniqueKeyTypeValue[][];
116
+ get PSBT_IN_TAP_BIP32_DERIVATION(): NonUniqueKeyTypeValue[][];
117
117
  get PSBT_IN_TAP_INTERNAL_KEY(): (string | null)[];
118
118
  get PSBT_IN_TAP_MERKLE_ROOT(): (string | null)[];
119
119
  get PSBT_IN_PROPRIETARY(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
@@ -129,6 +129,57 @@ declare class PsbtV2 extends PsbtV2Maps {
129
129
  get PSBT_OUT_TAP_TREE(): (string | null)[];
130
130
  get PSBT_OUT_TAP_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
131
131
  get PSBT_OUT_PROPRIETARY(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
132
+ /**
133
+ * Operator Role Validation Getters
134
+ */
135
+ /**
136
+ * Returns true if the PsbtV2 is ready for an operator taking the Constructor
137
+ * role.
138
+ *
139
+ * This check assumes that the Creator used this class's constructor method to
140
+ * initialize the PsbtV2 without passing a psbt (constructor defaults were
141
+ * set).
142
+ */
143
+ get isReadyForConstructor(): boolean;
144
+ /**
145
+ * Returns true if the PsbtV2 is ready for an operator taking the Updater
146
+ * role.
147
+ *
148
+ * Before signatures are added, but after an input is added, a PsbtV2 is
149
+ * likely to be ready for Constructor, ready for Updater, and ready for Signer
150
+ * simultaneously.
151
+ *
152
+ * According to BIP370, the Updater can modify the sequence number, but it is
153
+ * unclear if the Updater retains permissions provided in psbtv0 (BIP174). It
154
+ * is likely not the case that the Updater has the same permissions as
155
+ * previously because it seems to now be the realm of the Constructor to add
156
+ * inputs and outputs.
157
+ */
158
+ get isReadyForUpdater(): boolean;
159
+ /**
160
+ * Returns true if the PsbtV2 is ready for an operator taking the Signer role.
161
+ */
162
+ get isReadyForSigner(): boolean;
163
+ /**
164
+ * Returns true if the PsbtV2 is ready for an operator taking the Combiner
165
+ * role.
166
+ */
167
+ get isReadyForCombiner(): boolean;
168
+ /**
169
+ * Unimplemented. Returns false.
170
+ */
171
+ get isReadyForInputFinalizer(): boolean;
172
+ /**
173
+ * Returns true if the PsbtV2 is ready for an operator taking the Transaction
174
+ * Extractor role.
175
+ *
176
+ * If all the inputs have been finalized, then the psbt is ready for the
177
+ * Transaction Extractor. According to BIP 174, it's the responsibility of the
178
+ * Input Finalizer to add scriptSigs or scriptWitnesses and then remove other
179
+ * details besides the UTXO. This getter checks that the Input Finalizer has
180
+ * finished its job.
181
+ */
182
+ get isReadyForTransactionExtractor(): boolean;
132
183
  /**
133
184
  * Other Getters/Setters
134
185
  */
@@ -205,7 +256,7 @@ declare class PsbtV2 extends PsbtV2Maps {
205
256
  */
206
257
  deleteOutput(index: number): void;
207
258
  /**
208
- * Checks that provided flags are present in PSBT_GLOBAL_TX_MODIFIABLE.
259
+ * Checks that all provided flags are present in PSBT_GLOBAL_TX_MODIFIABLE.
209
260
  */
210
261
  private isModifiable;
211
262
  /**
@@ -234,7 +285,11 @@ declare class PsbtV2 extends PsbtV2Maps {
234
285
  */
235
286
  private handleSighashType;
236
287
  /**
237
- * Attempts to return a PsbtV2 by converting from a PsbtV0 string or Buffer
288
+ * Attempts to return a PsbtV2 by converting from a PsbtV0 string or Buffer.
289
+ *
290
+ * This method first starts with a fresh PsbtV2 having just been created. It
291
+ * then takes the PsbtV2 through its operator saga through the Signer role. In
292
+ * this sense validation for each operator role will be performed.
238
293
  */
239
294
  static FromV0(psbt: string | Buffer, allowTxnVersion1?: boolean): PsbtV2;
240
295
  }
package/dist/index.d.ts CHANGED
@@ -74,7 +74,7 @@ declare class PsbtV2 extends PsbtV2Maps {
74
74
  /**
75
75
  * Globals Getters/Setters
76
76
  */
77
- get PSBT_GLOBAL_XPUB(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
77
+ get PSBT_GLOBAL_XPUB(): NonUniqueKeyTypeValue[];
78
78
  get PSBT_GLOBAL_TX_VERSION(): number;
79
79
  set PSBT_GLOBAL_TX_VERSION(version: number);
80
80
  get PSBT_GLOBAL_FALLBACK_LOCKTIME(): number | null;
@@ -87,7 +87,7 @@ declare class PsbtV2 extends PsbtV2Maps {
87
87
  set PSBT_GLOBAL_TX_MODIFIABLE(modifiable: PsbtGlobalTxModifiableBits[]);
88
88
  get PSBT_GLOBAL_VERSION(): number;
89
89
  set PSBT_GLOBAL_VERSION(version: number);
90
- get PSBT_GLOBAL_PROPRIETARY(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
90
+ get PSBT_GLOBAL_PROPRIETARY(): NonUniqueKeyTypeValue[];
91
91
  /**
92
92
  * Input Getters/Setters
93
93
  */
@@ -97,23 +97,23 @@ declare class PsbtV2 extends PsbtV2Maps {
97
97
  get PSBT_IN_SIGHASH_TYPE(): (number | null)[];
98
98
  get PSBT_IN_REDEEM_SCRIPT(): (string | null)[];
99
99
  get PSBT_IN_WITNESS_SCRIPT(): (string | null)[];
100
- get PSBT_IN_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
100
+ get PSBT_IN_BIP32_DERIVATION(): NonUniqueKeyTypeValue[][];
101
101
  get PSBT_IN_FINAL_SCRIPTSIG(): (string | null)[];
102
102
  get PSBT_IN_FINAL_SCRIPTWITNESS(): (string | null)[];
103
103
  get PSBT_IN_POR_COMMITMENT(): (string | null)[];
104
- get PSBT_IN_RIPEMD160(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
105
- get PSBT_IN_SHA256(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
106
- get PSBT_IN_HASH160(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
107
- get PSBT_IN_HASH256(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
104
+ get PSBT_IN_RIPEMD160(): NonUniqueKeyTypeValue[][];
105
+ get PSBT_IN_SHA256(): NonUniqueKeyTypeValue[][];
106
+ get PSBT_IN_HASH160(): NonUniqueKeyTypeValue[][];
107
+ get PSBT_IN_HASH256(): NonUniqueKeyTypeValue[][];
108
108
  get PSBT_IN_PREVIOUS_TXID(): string[];
109
109
  get PSBT_IN_OUTPUT_INDEX(): number[];
110
110
  get PSBT_IN_SEQUENCE(): (number | null)[];
111
111
  get PSBT_IN_REQUIRED_TIME_LOCKTIME(): (number | null)[];
112
112
  get PSBT_IN_REQUIRED_HEIGHT_LOCKTIME(): (number | null)[];
113
113
  get PSBT_IN_TAP_KEY_SIG(): (string | null)[];
114
- get PSBT_IN_TAP_SCRIPT_SIG(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
115
- get PSBT_IN_TAP_LEAF_SCRIPT(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
116
- get PSBT_IN_TAP_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
114
+ get PSBT_IN_TAP_SCRIPT_SIG(): NonUniqueKeyTypeValue[][];
115
+ get PSBT_IN_TAP_LEAF_SCRIPT(): NonUniqueKeyTypeValue[][];
116
+ get PSBT_IN_TAP_BIP32_DERIVATION(): NonUniqueKeyTypeValue[][];
117
117
  get PSBT_IN_TAP_INTERNAL_KEY(): (string | null)[];
118
118
  get PSBT_IN_TAP_MERKLE_ROOT(): (string | null)[];
119
119
  get PSBT_IN_PROPRIETARY(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
@@ -129,6 +129,57 @@ declare class PsbtV2 extends PsbtV2Maps {
129
129
  get PSBT_OUT_TAP_TREE(): (string | null)[];
130
130
  get PSBT_OUT_TAP_BIP32_DERIVATION(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
131
131
  get PSBT_OUT_PROPRIETARY(): NonUniqueKeyTypeValue[] | NonUniqueKeyTypeValue[][];
132
+ /**
133
+ * Operator Role Validation Getters
134
+ */
135
+ /**
136
+ * Returns true if the PsbtV2 is ready for an operator taking the Constructor
137
+ * role.
138
+ *
139
+ * This check assumes that the Creator used this class's constructor method to
140
+ * initialize the PsbtV2 without passing a psbt (constructor defaults were
141
+ * set).
142
+ */
143
+ get isReadyForConstructor(): boolean;
144
+ /**
145
+ * Returns true if the PsbtV2 is ready for an operator taking the Updater
146
+ * role.
147
+ *
148
+ * Before signatures are added, but after an input is added, a PsbtV2 is
149
+ * likely to be ready for Constructor, ready for Updater, and ready for Signer
150
+ * simultaneously.
151
+ *
152
+ * According to BIP370, the Updater can modify the sequence number, but it is
153
+ * unclear if the Updater retains permissions provided in psbtv0 (BIP174). It
154
+ * is likely not the case that the Updater has the same permissions as
155
+ * previously because it seems to now be the realm of the Constructor to add
156
+ * inputs and outputs.
157
+ */
158
+ get isReadyForUpdater(): boolean;
159
+ /**
160
+ * Returns true if the PsbtV2 is ready for an operator taking the Signer role.
161
+ */
162
+ get isReadyForSigner(): boolean;
163
+ /**
164
+ * Returns true if the PsbtV2 is ready for an operator taking the Combiner
165
+ * role.
166
+ */
167
+ get isReadyForCombiner(): boolean;
168
+ /**
169
+ * Unimplemented. Returns false.
170
+ */
171
+ get isReadyForInputFinalizer(): boolean;
172
+ /**
173
+ * Returns true if the PsbtV2 is ready for an operator taking the Transaction
174
+ * Extractor role.
175
+ *
176
+ * If all the inputs have been finalized, then the psbt is ready for the
177
+ * Transaction Extractor. According to BIP 174, it's the responsibility of the
178
+ * Input Finalizer to add scriptSigs or scriptWitnesses and then remove other
179
+ * details besides the UTXO. This getter checks that the Input Finalizer has
180
+ * finished its job.
181
+ */
182
+ get isReadyForTransactionExtractor(): boolean;
132
183
  /**
133
184
  * Other Getters/Setters
134
185
  */
@@ -205,7 +256,7 @@ declare class PsbtV2 extends PsbtV2Maps {
205
256
  */
206
257
  deleteOutput(index: number): void;
207
258
  /**
208
- * Checks that provided flags are present in PSBT_GLOBAL_TX_MODIFIABLE.
259
+ * Checks that all provided flags are present in PSBT_GLOBAL_TX_MODIFIABLE.
209
260
  */
210
261
  private isModifiable;
211
262
  /**
@@ -234,7 +285,11 @@ declare class PsbtV2 extends PsbtV2Maps {
234
285
  */
235
286
  private handleSighashType;
236
287
  /**
237
- * Attempts to return a PsbtV2 by converting from a PsbtV0 string or Buffer
288
+ * Attempts to return a PsbtV2 by converting from a PsbtV0 string or Buffer.
289
+ *
290
+ * This method first starts with a fresh PsbtV2 having just been created. It
291
+ * then takes the PsbtV2 through its operator saga through the Signer role. In
292
+ * this sense validation for each operator role will be performed.
238
293
  */
239
294
  static FromV0(psbt: string | Buffer, allowTxnVersion1?: boolean): PsbtV2;
240
295
  }