@neuraiproject/neurai-scripts 0.7.2 → 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/dist/index.d.ts CHANGED
@@ -7,5 +7,5 @@ export type { AuthType, AuthScriptWitnessLegacyInput, AuthScriptWitnessPQInput,
7
7
  export { encodeSellerScriptPubKey } from './address.js';
8
8
  export type { SellerAddressKind, SellerScriptPubKey } from './address.js';
9
9
  export { splitAssetWrappedScriptPubKey } from './asset-wrapper.js';
10
- export type { AssetTransferPayload, SplitAssetWrappedResult } from './asset-wrapper.js';
10
+ export type { AssetMarker, AssetTransferPayload, SplitAssetWrappedResult } from './asset-wrapper.js';
11
11
  export { buildPartialFillScript, buildPartialFillScriptHex, buildFillScriptSig, buildFillScriptSigHex, buildCancelScriptSig, buildCancelScriptSigHex, parsePartialFillScript, buildPartialFillScriptPQ, buildPartialFillScriptPQHex, buildCancelScriptSigPQ, buildCancelScriptSigPQHex, parsePartialFillScriptPQ, isPartialFillScriptPQ, DEFAULT_PQ_TXHASH_SELECTOR, buildFillWitnessStack, buildCancelWitnessStack, buildCancelWitnessStackPQ } from './covenants/index.js';
package/dist/index.js CHANGED
@@ -1607,11 +1607,16 @@ function encodeSellerScriptPubKey(address) {
1607
1607
  * AuthScript witness v1, or a bare covenant such as the partial-fill sell
1608
1608
  * order), and `payload` serializes a `CAssetTransfer`:
1609
1609
  *
1610
- * payload = rvn_prefix (0x72 0x76 0x6e) || type_marker (0x74 transfer)
1610
+ * payload = marker ("rvn" 0x72 0x76 0x6e | "xna" 0x78 0x6e 0x61)
1611
+ * || type_marker (0x74 transfer)
1611
1612
  * || VarStr(assetName)
1612
1613
  * || int64LE(amountRaw)
1613
1614
  * [ || messageRef (optional) || int64LE(expireTime) (optional) ]
1614
1615
  *
1616
+ * NIP-040: mainnet still emits the Ravencoin-inherited "rvn" marker;
1617
+ * testnet/regtest emit "xna" after activation. Both are accepted when
1618
+ * reading — the detected marker is surfaced on the parsed payload.
1619
+ *
1615
1620
  * This helper separates the two halves so consumers can validate the prefix
1616
1621
  * (e.g. feed it to `parsePartialFillScript`) while independently reading the
1617
1622
  * asset data displayed to the user. The optional payload tail
@@ -1621,7 +1626,10 @@ function encodeSellerScriptPubKey(address) {
1621
1626
  * Bare (non-wrapped) scriptPubKeys round-trip through this helper by
1622
1627
  * returning `prefixHex === input` and `assetTransfer === null`.
1623
1628
  */
1624
- const RVN_MAGIC = Uint8Array.from([0x72, 0x76, 0x6e]); // "rvn"
1629
+ const ASSET_MAGICS = [
1630
+ { marker: 'rvn', bytes: Uint8Array.from([0x72, 0x76, 0x6e]) },
1631
+ { marker: 'xna', bytes: Uint8Array.from([0x78, 0x6e, 0x61]) },
1632
+ ];
1625
1633
  const TRANSFER_TYPE = 0x74;
1626
1634
  /**
1627
1635
  * Walk the script one opcode at a time, skipping pushdata payload bytes,
@@ -1727,16 +1735,20 @@ function readPayloadPush(bytes, start) {
1727
1735
  }
1728
1736
  throw new Error(`splitAssetWrappedScriptPubKey: asset payload push opcode 0x${op.toString(16)} not accepted (expected 0x01..0x4b or PUSHDATA1)`);
1729
1737
  }
1738
+ function detectAssetMarker(payload) {
1739
+ for (const { marker, bytes } of ASSET_MAGICS) {
1740
+ if (payload[0] === bytes[0] && payload[1] === bytes[1] && payload[2] === bytes[2]) {
1741
+ return marker;
1742
+ }
1743
+ }
1744
+ throw new Error(`splitAssetWrappedScriptPubKey: asset payload magic mismatch — expected "rvn" or "xna" got 0x${payload[0].toString(16)} 0x${payload[1].toString(16)} 0x${payload[2].toString(16)}`);
1745
+ }
1730
1746
  function parseAssetTransferPayload(payload) {
1731
1747
  if (payload.length < 4 + 1 + 8) {
1732
1748
  // 4 magic+type, 1 varstr length, 8 int64LE amount
1733
1749
  throw new Error(`splitAssetWrappedScriptPubKey: asset payload of ${payload.length} bytes is too short`);
1734
1750
  }
1735
- for (let i = 0; i < 3; i += 1) {
1736
- if (payload[i] !== RVN_MAGIC[i]) {
1737
- throw new Error(`splitAssetWrappedScriptPubKey: asset payload magic mismatch — expected "rvn" got 0x${payload[0].toString(16)} 0x${payload[1].toString(16)} 0x${payload[2].toString(16)}`);
1738
- }
1739
- }
1751
+ const marker = detectAssetMarker(payload);
1740
1752
  if (payload[3] !== TRANSFER_TYPE) {
1741
1753
  throw new Error(`splitAssetWrappedScriptPubKey: asset payload type marker 0x${payload[3].toString(16)} is not a transfer (0x74)`);
1742
1754
  }
@@ -1758,7 +1770,7 @@ function parseAssetTransferPayload(payload) {
1758
1770
  // expireTime). We intentionally ignore them in this first version; the
1759
1771
  // raw payload remains available via `payloadHex` if a consumer later
1760
1772
  // needs to inspect them.
1761
- return { assetName, amountRaw };
1773
+ return { assetName, amountRaw, marker };
1762
1774
  }
1763
1775
  /**
1764
1776
  * Parse an asset-transfer-wrapped scriptPubKey. Accepts both wrapped and
@@ -1783,12 +1795,13 @@ function splitAssetWrappedScriptPubKey(spkHex) {
1783
1795
  if (after + 1 !== bytes.length) {
1784
1796
  throw new Error(`splitAssetWrappedScriptPubKey: ${bytes.length - after - 1} trailing bytes after OP_DROP`);
1785
1797
  }
1786
- const { assetName, amountRaw } = parseAssetTransferPayload(payload);
1798
+ const { assetName, amountRaw, marker } = parseAssetTransferPayload(payload);
1787
1799
  return {
1788
1800
  prefixHex: bytesToHex(prefix),
1789
1801
  assetTransfer: {
1790
1802
  assetName,
1791
1803
  amountRaw,
1804
+ marker,
1792
1805
  payloadHex: bytesToHex(payload),
1793
1806
  },
1794
1807
  };