@neuraiproject/neurai-sign-esp32 0.8.1 → 0.8.2

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
@@ -44,7 +44,7 @@ asset name, transferred amount, destination address, and fee more clearly.
44
44
 
45
45
  Before supplying UTXOs or PSBT inputs to this signing library, the host
46
46
  application must verify `getblockhash(0)` against
47
- `0000008b384aeffecdab182575dc4e86c9f07f90318c65088532660ed9a8a021`.
47
+ `000000c710413a4265a996d30c86043aedef6a563900f1bc43fea61d5b2dc77d`.
48
48
  The device does not query the chain. Discard UTXOs and PSBTs assembled from
49
49
  the previous testnet. All three AuthScript address families activate on the
50
50
  reset testnet at block 10; outputs included earlier have no AuthScript spend
@@ -958,6 +958,18 @@ ArduinoJson parser was checked on the host up to MAX_MONEY; this does not replac
958
958
  an on-device signing and display check of the firmware installed on your ESP32.
959
959
  No global bigint JSON serializer is required.
960
960
 
961
+ ## Upgrading to 0.8.2
962
+
963
+ Previous transactions are read with `@neuraiproject/neurai-create-transaction`
964
+ `^0.10.0`, which follows the node's NIP-014 encoding (Neurai DePIN-Test
965
+ `d4ff4ef`, live on the testnet reset of 2026-11-05): reference inputs are
966
+ announced by flag `0x02` of the extended format, and a version 3 transaction
967
+ without them has the plain layout. With 0.8.1 a PSBT whose previous
968
+ transaction is version 3 in that encoding is unreadable. Version 3
969
+ transactions of the previous testnet (an empty reference list after the
970
+ outputs) no longer read. What the device signs does not change: NeuraiHW still
971
+ refuses a version 3 transaction or previous transaction.
972
+
961
973
  ## Upgrading to 0.8.1
962
974
 
963
975
  React Native (Hermes): Buffer methods are no longer called on `subarray()`
@@ -9241,12 +9241,19 @@ var NeuraiSignESP32Bundle = (function () {
9241
9241
  for (let i = 0; i < voutCount; i += 1)
9242
9242
  outputs.push(readOutput(reader));
9243
9243
  }
9244
- // NIP-014: vrefin sits between vout and witness, v3 only (even when empty).
9244
+ // NIP-014: reference inputs sit between vout and witness, announced by flag
9245
+ // 0x02. Without the flag a version 3 transaction reads as 1.0.7 reads it.
9245
9246
  const vrefin = [];
9246
- if (version === 3) {
9247
+ const hasRefInputs = (flags & 2) !== 0;
9248
+ if (hasRefInputs) {
9249
+ flags ^= 2;
9247
9250
  const refCount = reader.readCount(36, 'refinput');
9248
9251
  for (let i = 0; i < refCount; i += 1)
9249
9252
  vrefin.push(readOutpoint(reader));
9253
+ if (vrefin.length === 0) {
9254
+ // One encoding per transaction: the flag means some.
9255
+ throw new Error('Superfluous reference inputs record (flag 0x02 with no reference inputs)');
9256
+ }
9250
9257
  }
9251
9258
  if (flags & 1) {
9252
9259
  flags ^= 1;
@@ -9259,6 +9266,11 @@ var NeuraiSignESP32Bundle = (function () {
9259
9266
  }
9260
9267
  input.witness = stack;
9261
9268
  }
9269
+ if (hasRefInputs && !inputs.some(inputHasWitness)) {
9270
+ // With reference inputs the witness flag means some witness; 1.0.7 reads
9271
+ // an empty witness record without them, and so does the node.
9272
+ throw new Error('Superfluous witness record (flag 0x01 with no witness data)');
9273
+ }
9262
9274
  }
9263
9275
  if (flags) {
9264
9276
  throw new Error(`Unknown transaction optional data (flags 0x${flags.toString(16)})`);
@@ -9296,10 +9308,13 @@ var NeuraiSignESP32Bundle = (function () {
9296
9308
  throw new Error(`vrefin requires transaction version 3 (got version ${tx.version})`);
9297
9309
  }
9298
9310
  const withWitness = (options.includeWitness ?? true) && tx.inputs.some(inputHasWitness);
9311
+ // NIP-014: reference inputs keep the extended format without witnesses too,
9312
+ // because the txid commits to them.
9313
+ const flags = (withWitness ? 1 : 0) | (vrefin.length > 0 ? 2 : 0);
9299
9314
  const parts = [u32LE(tx.version >>> 0)];
9300
- if (withWitness) {
9315
+ if (flags) {
9301
9316
  // Extended format: dummy empty vin + flags byte.
9302
- parts.push(Uint8Array.of(0x00, 0x01));
9317
+ parts.push(Uint8Array.of(0x00, flags));
9303
9318
  }
9304
9319
  parts.push(compactSize(tx.inputs.length));
9305
9320
  for (const input of tx.inputs)
@@ -9307,7 +9322,7 @@ var NeuraiSignESP32Bundle = (function () {
9307
9322
  parts.push(compactSize(tx.outputs.length));
9308
9323
  for (const output of tx.outputs)
9309
9324
  parts.push(serializeCodecOutput(output));
9310
- if (tx.version === 3) {
9325
+ if (flags & 2) {
9311
9326
  parts.push(compactSize(vrefin.length));
9312
9327
  for (const ref of vrefin)
9313
9328
  parts.push(serializeOutpoint(ref));
package/dist/browser.js CHANGED
@@ -9238,12 +9238,19 @@ function parseTransaction(hex) {
9238
9238
  for (let i = 0; i < voutCount; i += 1)
9239
9239
  outputs.push(readOutput(reader));
9240
9240
  }
9241
- // NIP-014: vrefin sits between vout and witness, v3 only (even when empty).
9241
+ // NIP-014: reference inputs sit between vout and witness, announced by flag
9242
+ // 0x02. Without the flag a version 3 transaction reads as 1.0.7 reads it.
9242
9243
  const vrefin = [];
9243
- if (version === 3) {
9244
+ const hasRefInputs = (flags & 2) !== 0;
9245
+ if (hasRefInputs) {
9246
+ flags ^= 2;
9244
9247
  const refCount = reader.readCount(36, 'refinput');
9245
9248
  for (let i = 0; i < refCount; i += 1)
9246
9249
  vrefin.push(readOutpoint(reader));
9250
+ if (vrefin.length === 0) {
9251
+ // One encoding per transaction: the flag means some.
9252
+ throw new Error('Superfluous reference inputs record (flag 0x02 with no reference inputs)');
9253
+ }
9247
9254
  }
9248
9255
  if (flags & 1) {
9249
9256
  flags ^= 1;
@@ -9256,6 +9263,11 @@ function parseTransaction(hex) {
9256
9263
  }
9257
9264
  input.witness = stack;
9258
9265
  }
9266
+ if (hasRefInputs && !inputs.some(inputHasWitness)) {
9267
+ // With reference inputs the witness flag means some witness; 1.0.7 reads
9268
+ // an empty witness record without them, and so does the node.
9269
+ throw new Error('Superfluous witness record (flag 0x01 with no witness data)');
9270
+ }
9259
9271
  }
9260
9272
  if (flags) {
9261
9273
  throw new Error(`Unknown transaction optional data (flags 0x${flags.toString(16)})`);
@@ -9293,10 +9305,13 @@ function serializeTransaction(tx, options = {}) {
9293
9305
  throw new Error(`vrefin requires transaction version 3 (got version ${tx.version})`);
9294
9306
  }
9295
9307
  const withWitness = (options.includeWitness ?? true) && tx.inputs.some(inputHasWitness);
9308
+ // NIP-014: reference inputs keep the extended format without witnesses too,
9309
+ // because the txid commits to them.
9310
+ const flags = (withWitness ? 1 : 0) | (vrefin.length > 0 ? 2 : 0);
9296
9311
  const parts = [u32LE(tx.version >>> 0)];
9297
- if (withWitness) {
9312
+ if (flags) {
9298
9313
  // Extended format: dummy empty vin + flags byte.
9299
- parts.push(Uint8Array.of(0x00, 0x01));
9314
+ parts.push(Uint8Array.of(0x00, flags));
9300
9315
  }
9301
9316
  parts.push(compactSize(tx.inputs.length));
9302
9317
  for (const input of tx.inputs)
@@ -9304,7 +9319,7 @@ function serializeTransaction(tx, options = {}) {
9304
9319
  parts.push(compactSize(tx.outputs.length));
9305
9320
  for (const output of tx.outputs)
9306
9321
  parts.push(serializeCodecOutput(output));
9307
- if (tx.version === 3) {
9322
+ if (flags & 2) {
9308
9323
  parts.push(compactSize(vrefin.length));
9309
9324
  for (const ref of vrefin)
9310
9325
  parts.push(serializeOutpoint(ref));
package/dist/index.cjs CHANGED
@@ -9240,12 +9240,19 @@ function parseTransaction(hex) {
9240
9240
  for (let i = 0; i < voutCount; i += 1)
9241
9241
  outputs.push(readOutput(reader));
9242
9242
  }
9243
- // NIP-014: vrefin sits between vout and witness, v3 only (even when empty).
9243
+ // NIP-014: reference inputs sit between vout and witness, announced by flag
9244
+ // 0x02. Without the flag a version 3 transaction reads as 1.0.7 reads it.
9244
9245
  const vrefin = [];
9245
- if (version === 3) {
9246
+ const hasRefInputs = (flags & 2) !== 0;
9247
+ if (hasRefInputs) {
9248
+ flags ^= 2;
9246
9249
  const refCount = reader.readCount(36, 'refinput');
9247
9250
  for (let i = 0; i < refCount; i += 1)
9248
9251
  vrefin.push(readOutpoint(reader));
9252
+ if (vrefin.length === 0) {
9253
+ // One encoding per transaction: the flag means some.
9254
+ throw new Error('Superfluous reference inputs record (flag 0x02 with no reference inputs)');
9255
+ }
9249
9256
  }
9250
9257
  if (flags & 1) {
9251
9258
  flags ^= 1;
@@ -9258,6 +9265,11 @@ function parseTransaction(hex) {
9258
9265
  }
9259
9266
  input.witness = stack;
9260
9267
  }
9268
+ if (hasRefInputs && !inputs.some(inputHasWitness)) {
9269
+ // With reference inputs the witness flag means some witness; 1.0.7 reads
9270
+ // an empty witness record without them, and so does the node.
9271
+ throw new Error('Superfluous witness record (flag 0x01 with no witness data)');
9272
+ }
9261
9273
  }
9262
9274
  if (flags) {
9263
9275
  throw new Error(`Unknown transaction optional data (flags 0x${flags.toString(16)})`);
@@ -9295,10 +9307,13 @@ function serializeTransaction(tx, options = {}) {
9295
9307
  throw new Error(`vrefin requires transaction version 3 (got version ${tx.version})`);
9296
9308
  }
9297
9309
  const withWitness = (options.includeWitness ?? true) && tx.inputs.some(inputHasWitness);
9310
+ // NIP-014: reference inputs keep the extended format without witnesses too,
9311
+ // because the txid commits to them.
9312
+ const flags = (withWitness ? 1 : 0) | (vrefin.length > 0 ? 2 : 0);
9298
9313
  const parts = [u32LE(tx.version >>> 0)];
9299
- if (withWitness) {
9314
+ if (flags) {
9300
9315
  // Extended format: dummy empty vin + flags byte.
9301
- parts.push(Uint8Array.of(0x00, 0x01));
9316
+ parts.push(Uint8Array.of(0x00, flags));
9302
9317
  }
9303
9318
  parts.push(compactSize(tx.inputs.length));
9304
9319
  for (const input of tx.inputs)
@@ -9306,7 +9321,7 @@ function serializeTransaction(tx, options = {}) {
9306
9321
  parts.push(compactSize(tx.outputs.length));
9307
9322
  for (const output of tx.outputs)
9308
9323
  parts.push(serializeCodecOutput(output));
9309
- if (tx.version === 3) {
9324
+ if (flags & 2) {
9310
9325
  parts.push(compactSize(vrefin.length));
9311
9326
  for (const ref of vrefin)
9312
9327
  parts.push(serializeOutpoint(ref));
package/dist/index.js CHANGED
@@ -9238,12 +9238,19 @@ function parseTransaction(hex) {
9238
9238
  for (let i = 0; i < voutCount; i += 1)
9239
9239
  outputs.push(readOutput(reader));
9240
9240
  }
9241
- // NIP-014: vrefin sits between vout and witness, v3 only (even when empty).
9241
+ // NIP-014: reference inputs sit between vout and witness, announced by flag
9242
+ // 0x02. Without the flag a version 3 transaction reads as 1.0.7 reads it.
9242
9243
  const vrefin = [];
9243
- if (version === 3) {
9244
+ const hasRefInputs = (flags & 2) !== 0;
9245
+ if (hasRefInputs) {
9246
+ flags ^= 2;
9244
9247
  const refCount = reader.readCount(36, 'refinput');
9245
9248
  for (let i = 0; i < refCount; i += 1)
9246
9249
  vrefin.push(readOutpoint(reader));
9250
+ if (vrefin.length === 0) {
9251
+ // One encoding per transaction: the flag means some.
9252
+ throw new Error('Superfluous reference inputs record (flag 0x02 with no reference inputs)');
9253
+ }
9247
9254
  }
9248
9255
  if (flags & 1) {
9249
9256
  flags ^= 1;
@@ -9256,6 +9263,11 @@ function parseTransaction(hex) {
9256
9263
  }
9257
9264
  input.witness = stack;
9258
9265
  }
9266
+ if (hasRefInputs && !inputs.some(inputHasWitness)) {
9267
+ // With reference inputs the witness flag means some witness; 1.0.7 reads
9268
+ // an empty witness record without them, and so does the node.
9269
+ throw new Error('Superfluous witness record (flag 0x01 with no witness data)');
9270
+ }
9259
9271
  }
9260
9272
  if (flags) {
9261
9273
  throw new Error(`Unknown transaction optional data (flags 0x${flags.toString(16)})`);
@@ -9293,10 +9305,13 @@ function serializeTransaction(tx, options = {}) {
9293
9305
  throw new Error(`vrefin requires transaction version 3 (got version ${tx.version})`);
9294
9306
  }
9295
9307
  const withWitness = (options.includeWitness ?? true) && tx.inputs.some(inputHasWitness);
9308
+ // NIP-014: reference inputs keep the extended format without witnesses too,
9309
+ // because the txid commits to them.
9310
+ const flags = (withWitness ? 1 : 0) | (vrefin.length > 0 ? 2 : 0);
9296
9311
  const parts = [u32LE(tx.version >>> 0)];
9297
- if (withWitness) {
9312
+ if (flags) {
9298
9313
  // Extended format: dummy empty vin + flags byte.
9299
- parts.push(Uint8Array.of(0x00, 0x01));
9314
+ parts.push(Uint8Array.of(0x00, flags));
9300
9315
  }
9301
9316
  parts.push(compactSize(tx.inputs.length));
9302
9317
  for (const input of tx.inputs)
@@ -9304,7 +9319,7 @@ function serializeTransaction(tx, options = {}) {
9304
9319
  parts.push(compactSize(tx.outputs.length));
9305
9320
  for (const output of tx.outputs)
9306
9321
  parts.push(serializeCodecOutput(output));
9307
- if (tx.version === 3) {
9322
+ if (flags & 2) {
9308
9323
  parts.push(compactSize(vrefin.length));
9309
9324
  for (const ref of vrefin)
9310
9325
  parts.push(serializeOutpoint(ref));
@@ -9238,12 +9238,19 @@ function parseTransaction(hex) {
9238
9238
  for (let i = 0; i < voutCount; i += 1)
9239
9239
  outputs.push(readOutput(reader));
9240
9240
  }
9241
- // NIP-014: vrefin sits between vout and witness, v3 only (even when empty).
9241
+ // NIP-014: reference inputs sit between vout and witness, announced by flag
9242
+ // 0x02. Without the flag a version 3 transaction reads as 1.0.7 reads it.
9242
9243
  const vrefin = [];
9243
- if (version === 3) {
9244
+ const hasRefInputs = (flags & 2) !== 0;
9245
+ if (hasRefInputs) {
9246
+ flags ^= 2;
9244
9247
  const refCount = reader.readCount(36, 'refinput');
9245
9248
  for (let i = 0; i < refCount; i += 1)
9246
9249
  vrefin.push(readOutpoint(reader));
9250
+ if (vrefin.length === 0) {
9251
+ // One encoding per transaction: the flag means some.
9252
+ throw new Error('Superfluous reference inputs record (flag 0x02 with no reference inputs)');
9253
+ }
9247
9254
  }
9248
9255
  if (flags & 1) {
9249
9256
  flags ^= 1;
@@ -9256,6 +9263,11 @@ function parseTransaction(hex) {
9256
9263
  }
9257
9264
  input.witness = stack;
9258
9265
  }
9266
+ if (hasRefInputs && !inputs.some(inputHasWitness)) {
9267
+ // With reference inputs the witness flag means some witness; 1.0.7 reads
9268
+ // an empty witness record without them, and so does the node.
9269
+ throw new Error('Superfluous witness record (flag 0x01 with no witness data)');
9270
+ }
9259
9271
  }
9260
9272
  if (flags) {
9261
9273
  throw new Error(`Unknown transaction optional data (flags 0x${flags.toString(16)})`);
@@ -9293,10 +9305,13 @@ function serializeTransaction(tx, options = {}) {
9293
9305
  throw new Error(`vrefin requires transaction version 3 (got version ${tx.version})`);
9294
9306
  }
9295
9307
  const withWitness = (options.includeWitness ?? true) && tx.inputs.some(inputHasWitness);
9308
+ // NIP-014: reference inputs keep the extended format without witnesses too,
9309
+ // because the txid commits to them.
9310
+ const flags = (withWitness ? 1 : 0) | (vrefin.length > 0 ? 2 : 0);
9296
9311
  const parts = [u32LE(tx.version >>> 0)];
9297
- if (withWitness) {
9312
+ if (flags) {
9298
9313
  // Extended format: dummy empty vin + flags byte.
9299
- parts.push(Uint8Array.of(0x00, 0x01));
9314
+ parts.push(Uint8Array.of(0x00, flags));
9300
9315
  }
9301
9316
  parts.push(compactSize(tx.inputs.length));
9302
9317
  for (const input of tx.inputs)
@@ -9304,7 +9319,7 @@ function serializeTransaction(tx, options = {}) {
9304
9319
  parts.push(compactSize(tx.outputs.length));
9305
9320
  for (const output of tx.outputs)
9306
9321
  parts.push(serializeCodecOutput(output));
9307
- if (tx.version === 3) {
9322
+ if (flags & 2) {
9308
9323
  parts.push(compactSize(vrefin.length));
9309
9324
  for (const ref of vrefin)
9310
9325
  parts.push(serializeOutpoint(ref));
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@neuraiproject/neurai-sign-esp32",
3
- "version": "0.8.1",
3
+ "version": "0.8.2",
4
4
  "description": "Create and sign PSBTs for Neurai via ESP32 hardware wallet",
5
5
  "type": "module",
6
6
  "main": "dist/index.cjs",
@@ -61,7 +61,7 @@
61
61
  "homepage": "https://github.com/neuraiproject/neurai-sign-esp32#readme",
62
62
  "dependencies": {
63
63
  "@bitcoinerlab/secp256k1": "1.2.0",
64
- "@neuraiproject/neurai-create-transaction": "^0.9.3",
64
+ "@neuraiproject/neurai-create-transaction": "^0.10.0",
65
65
  "bech32": "^2.0.0",
66
66
  "bitcoinjs-lib": "7.0.1",
67
67
  "buffer": "^6.0.3",