@neuraiproject/neurai-assets 1.2.3 → 1.3.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 +45 -0
- package/dist/NeuraiAssets.global.js +473 -275
- package/dist/NeuraiAssets.global.js.map +1 -1
- package/dist/browser.js +473 -275
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +473 -275
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +473 -275
- package/dist/index.js.map +1 -1
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -651,3 +651,48 @@ console.log('Transaction ID:', txid);
|
|
|
651
651
|
For AuthScript wallets, derive addresses externally with `neurai-key`, then initialize
|
|
652
652
|
`NeuraiAssets` with those `nq1...` / `tnq1...` addresses. The recommended network labels
|
|
653
653
|
are `xna` and `xna-test`; `xna-pq` and `xna-pq-test` remain available as compatibility aliases.
|
|
654
|
+
|
|
655
|
+
## Fee estimation (PQ-aware)
|
|
656
|
+
|
|
657
|
+
Asset transactions are usually built with one or two XNA inputs plus, depending on the operation, an owner-token or qualifier UTXO. The library estimates the fee twice per build: a rough pre-estimate to size the initial XNA selection, and a final estimate once the actual UTXOs are known.
|
|
658
|
+
|
|
659
|
+
Both estimates use the helpers in [`src/utils/feeSizing.js`](src/utils/feeSizing.js) and distinguish PQ AuthScript inputs/outputs from legacy P2PKH ones. PQ inputs spend ~977 vbytes vs ~148 for legacy — without this distinction, transactions built from PQ addresses fall under the node's `min relay fee` and are rejected with `code -26: min relay fee not met`.
|
|
660
|
+
|
|
661
|
+
You should not need to call these helpers directly; they are wired into every builder. They are documented here so you can audit the fee math or use the same constants if you compose transactions outside the standard builder flow.
|
|
662
|
+
|
|
663
|
+
```js
|
|
664
|
+
const {
|
|
665
|
+
VBYTES,
|
|
666
|
+
estimateInputVbytes,
|
|
667
|
+
estimateOutputBytes,
|
|
668
|
+
estimateTransactionVbytes,
|
|
669
|
+
isPQAddress,
|
|
670
|
+
isPQScript,
|
|
671
|
+
} = require('@neuraiproject/neurai-assets/src/utils/feeSizing');
|
|
672
|
+
|
|
673
|
+
VBYTES.legacyInputVbytes; // 148
|
|
674
|
+
VBYTES.pqInputVbytes; // 977
|
|
675
|
+
VBYTES.legacyOutputBytes; // 34
|
|
676
|
+
VBYTES.pqOutputBytes; // 43
|
|
677
|
+
|
|
678
|
+
estimateInputVbytes({ script: '5120…' }); // 977
|
|
679
|
+
estimateInputVbytes({ address: 'nq1…' }); // 977
|
|
680
|
+
estimateInputVbytes({ address: 'mgRYHdMq…' }); // 148
|
|
681
|
+
estimateOutputBytes('tnq1…'); // 43
|
|
682
|
+
|
|
683
|
+
const vbytes = estimateTransactionVbytes(
|
|
684
|
+
[{ script: '5120…' }, { address: 'mgRYHdMq…' }], // 1 PQ + 1 legacy input
|
|
685
|
+
['nq1qchange…', 'mgRYHdMqburn…'], // 1 PQ + 1 legacy output
|
|
686
|
+
);
|
|
687
|
+
```
|
|
688
|
+
|
|
689
|
+
The constants mirror those exported from `@neuraiproject/neurai-sign-transaction` (`VBYTES`). They are inlined here on purpose: depending on the full signer would pull `bitcoinjs-lib` and `@noble/post-quantum` into the IIFE / browser bundles, far more weight than these constants need. The signer remains the source of truth — if it ever bumps a vbytes value, this file must follow.
|
|
690
|
+
|
|
691
|
+
### Limitations
|
|
692
|
+
|
|
693
|
+
The estimator assumes the most common spend layout for every input:
|
|
694
|
+
|
|
695
|
+
- legacy inputs → P2PKH `scriptSig` worst case (DER signature + compressed pubkey)
|
|
696
|
+
- PQ inputs → AuthScript v1 with the **default** `OP_TRUE` `witnessScript` and **no** `functionalArgs`
|
|
697
|
+
|
|
698
|
+
That covers all standard asset operations. If you build transactions whose PQ inputs use covenant `witnessScript`s, NoAuth (`authType=0x00`) or Legacy AuthScript (`authType=0x02`) witnesses, compute the witness size yourself and add it to the result of `estimateTransactionVbytes` (or use `estimateVirtualSize` from `@neuraiproject/neurai-sign-transaction` after building the raw transaction, which fills dummy witnesses of the worst-case size and returns the exact post-signing vsize).
|