@neuraiproject/neurai-sign-esp32 0.7.1 → 0.8.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.
package/README.md CHANGED
@@ -677,7 +677,9 @@ oldest release the declarations support).
677
677
 
678
678
  Each UTXO requires the `rawTxHex` field — the full raw hex of the previous
679
679
  transaction. This is needed because P2PKH inputs use `nonWitnessUtxo` in the
680
- PSBT spec. You can get it from your Neurai node:
680
+ PSBT spec. Any Neurai transaction version is accepted, version 3 (NIP-014
681
+ reference inputs) included, and it must hash to the txid the input spends. You
682
+ can get it from your Neurai node:
681
683
 
682
684
  ```javascript
683
685
  const rawTxHex = await rpc("getrawtransaction", [txid]);
@@ -864,6 +866,10 @@ to any Neurai address type. Returns base64 string.
864
866
  Build an unsigned PSBT from an already-created raw unsigned transaction plus
865
867
  input metadata. This is the preferred path when the wallet already handles coin
866
868
  selection, fee calculation, asset outputs, and change outputs externally.
869
+ `inputs[i]` must describe input `i` (`txid:vout`); unlocking data in the raw
870
+ transaction is not carried. Any Neurai transaction version is accepted, and
871
+ `witnessScript` puts the script behind an AuthScript input (a covenant) in the
872
+ PSBT for signers that handle it (Neurai Connect); the device does not.
867
873
 
868
874
  ### `finalizePSBT(base64, network)`
869
875
 
@@ -871,13 +877,24 @@ Finalize a signed PSBT. Returns `{ txHex, txId }`.
871
877
 
872
878
  ### `finalizeSignedPSBT(originalPsbtBase64, signedPsbtBase64, network)`
873
879
 
874
- Merge a signed PSBT returned by the device with the original PSBT and finalize it.
875
- This helper also supports the minimal PSBT format returned by `uNeurai`, and
876
- includes fallback logic for legacy P2PKH finalization used by Neurai.
880
+ Merge a signed PSBT (from the device or another signer) with the original PSBT,
881
+ finalize the inputs it signed and extract the transaction; unsigned inputs are
882
+ left empty. A standard PSBT is combined: a field the two disagree on, or a
883
+ different transaction, is an error. Only an answer that is not a readable PSBT
884
+ is read as the minimal form `uNeurai` writes, and only if its transaction is
885
+ byte for byte the original one. A signature whose sighash byte differs from the
886
+ input's `sighashType` is rejected (it is no longer adjusted).
887
+
888
+ ### `assertDeviceCanSignPSBT(base64)`
889
+
890
+ Throws for what the NeuraiHW firmware cannot sign: a version-3 transaction, a
891
+ version-3 previous transaction, an input with a `witnessScript`.
892
+ `NeuraiESP32.signPsbt` calls it before sending anything to the device.
877
893
 
878
894
  ### `validatePSBT(base64, network)`
879
895
 
880
- Check if a PSBT base64 string is parseable. Returns boolean.
896
+ Check if a PSBT base64 string is readable under the Neurai PSBT profile
897
+ (previous transactions matching their outpoints). Returns boolean.
881
898
 
882
899
  [Check the TypeScript definitions](./dist/index.d.ts) for all the details.
883
900
 
@@ -941,6 +958,46 @@ ArduinoJson parser was checked on the host up to MAX_MONEY; this does not replac
941
958
  an on-device signing and display check of the firmware installed on your ESP32.
942
959
  No global bigint JSON serializer is required.
943
960
 
961
+ ## Upgrading to 0.8.0
962
+
963
+ The PSBT helpers no longer use bitcoinjs-lib's `Psbt`: they are built on the
964
+ PSBT module of `@neuraiproject/neurai-create-transaction` `^0.9.3` (BIP-174
965
+ version 0 whose transactions use the Neurai serialization). Same functions and
966
+ signatures; for the cases 0.7.2 supported (P2PKH and strict ECDSA v3 inputs,
967
+ transactions version 1/2) the PSBTs and transactions are byte for byte the
968
+ same.
969
+
970
+ - `buildPSBTFromRawTransaction` accepts version-3 transactions and the new
971
+ `IPSBTInputMetadata.witnessScript`, for Neurai Connect signers. It now checks
972
+ that each metadata entry describes its input (`txid:vout`).
973
+ - `NeuraiESP32.signPsbt` rejects, before the device is involved, what the
974
+ firmware cannot sign: version-3 transactions or previous transactions, and
975
+ inputs with a `witnessScript` (`assertDeviceCanSignPSBT`, exported).
976
+ - `finalizeSignedPSBT` no longer changes an input's `sighashType` to match the
977
+ returned signature: a mismatch is an error. uNeurai's `PSBT::sign` signs with
978
+ the input's `PSBT_IN_SIGHASH_TYPE` (`SIGHASH_ALL` when absent), so firmware
979
+ answers match the PSBT they were given.
980
+ - `finalizeSignedPSBT` no longer falls back to the minimal-PSBT reader when a
981
+ readable answer conflicts with the original or is for another transaction;
982
+ the minimal reader itself checks the transaction against the original.
983
+ - Error messages of invalid PSBTs come from neurai-create-transaction.
984
+ - `npm run test:package` accepts dependencies not yet on npm as tarballs:
985
+ `NEURAI_PACKAGE_CHECK_TARBALLS=/path/a.tgz,/path/b.tgz`.
986
+
987
+ ## Upgrading to 0.7.2
988
+
989
+ Previous transactions may be Neurai version-3 transactions (privacy pools and
990
+ state threads create them; NIP-014 serializes their reference inputs, even an
991
+ empty list). bitcoinjs-lib cannot read them and failed with "Transaction has
992
+ unexpected data" while building or finalizing a PSBT that spends one of their
993
+ outputs. The PSBT helpers now read every `nonWitnessUtxo` with the codec of
994
+ `@neuraiproject/neurai-create-transaction` (new dependency), check that it
995
+ hashes to the txid the input spends, and finalize inputs without
996
+ `Psbt.finalizeInput`, which would parse it again. A version-3 transaction *to
997
+ sign* is refused with an explicit error: a PSBT has no field for its reference
998
+ inputs. The device firmware (uNeurai) must also parse version-3 previous
999
+ transactions before it can sign such inputs.
1000
+
944
1001
  ## Upgrading to 0.7.1
945
1002
 
946
1003
  0.7.1 requires the published `neurai-depin-msg@3.1.3` for development and