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