@neuraiproject/neurai-scripts 0.8.2 → 0.9.1
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 +59 -8
- package/dist/NeuraiScripts.global.js +209 -43
- package/dist/NeuraiScripts.global.js.map +1 -1
- package/dist/address.d.ts +14 -4
- package/dist/asset-wrapper.d.ts +2 -2
- package/dist/browser.js +206 -44
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +209 -43
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +1194 -0
- package/dist/index.d.ts +2 -2
- package/dist/index.js +206 -44
- package/dist/index.js.map +1 -1
- package/dist/standard/authscript.d.ts +45 -4
- package/dist/standard/index.d.ts +2 -2
- package/dist/types.d.ts +16 -8
- package/package.json +16 -8
package/README.md
CHANGED
|
@@ -22,7 +22,9 @@ and sign with
|
|
|
22
22
|
> are gated by consensus flags active in **testnet / regtest** today.
|
|
23
23
|
> Mainnet activation follows the fork process described in the NIPs. The
|
|
24
24
|
> library accepts both `xna-test` and `xna` networks so the same call sites
|
|
25
|
-
> work once mainnet activates.
|
|
25
|
+
> work once mainnet activates. Here those labels only name the chain
|
|
26
|
+
> (mainnet / testnet-regtest); in neurai-key 5 `xna` also names the ECDSA
|
|
27
|
+
> witness v3 address type.
|
|
26
28
|
|
|
27
29
|
---
|
|
28
30
|
|
|
@@ -211,9 +213,24 @@ const spk = encodeP2WPKHScriptPubKey(pubKeyHash20);
|
|
|
211
213
|
const spk = encodeP2WSHScriptPubKey(sha256(witnessScript));
|
|
212
214
|
```
|
|
213
215
|
|
|
214
|
-
### AuthScript — `encodeAuthScriptScriptPubKey(program32)` + witness builders
|
|
216
|
+
### AuthScript — `encodeAuthScriptScriptPubKey(program32, witnessVersion?)` + witness builders
|
|
215
217
|
|
|
216
|
-
`scriptPubKey` layout: `
|
|
218
|
+
`scriptPubKey` layout: `OP_n 0x20 <32-byte program>`, with the witness
|
|
219
|
+
version of the address family:
|
|
220
|
+
|
|
221
|
+
| Witness | Opcode | Address | Spend |
|
|
222
|
+
|---|---|---|---|
|
|
223
|
+
| v1 (default) | `OP_1` | `nc1p…` / `tnc1p…` | generic: any auth type, any witnessScript (covenants) |
|
|
224
|
+
| v2 | `OP_2` | `pq1z…` / `tpq1z…` | strict PQ: exactly `[0x01, sig, pubKey, OP_TRUE]` |
|
|
225
|
+
| v3 | `OP_3` | `nq1r…` / `tnq1r…` | strict ECDSA: exactly `[0x02, sig, pubKey33, OP_TRUE]` |
|
|
226
|
+
|
|
227
|
+
`buildStrictWitnessPQ({ signature, pubKey })` and
|
|
228
|
+
`buildStrictWitnessECDSA({ signature, pubKey })` build the fixed 4-item stacks
|
|
229
|
+
of the strict families (the PQ key must be the 1313-byte `0x05`-prefixed key,
|
|
230
|
+
the ECDSA key must be compressed). Strict v2 / v3 are active on regtest only
|
|
231
|
+
today; generic v1 on testnet and regtest.
|
|
232
|
+
|
|
233
|
+
Generic AuthScript v1 spend modes, selected by a 1-byte `auth_type` in the witness stack:
|
|
217
234
|
|
|
218
235
|
Four spend modes, selected by a 1-byte `auth_type` in the witness stack:
|
|
219
236
|
|
|
@@ -503,7 +520,7 @@ are active on DePIN-Test testnet.
|
|
|
503
520
|
| Cancel sig scheme | ECDSA secp256k1 | ML-DSA-44 (~2421 B sig, ~1313 B pubkey) |
|
|
504
521
|
| Cancel verifier | `OP_DUP OP_HASH160 <PKH> OP_EQUALVERIFY OP_CHECKSIG` | `OP_DUP OP_SHA256 <commitment> OP_EQUALVERIFY <selector> OP_TXHASH OP_SWAP OP_CHECKSIGFROMSTACK` |
|
|
505
522
|
| What Alice signs | tx sighash (standard) | `SHA256(OP_TXHASH(selector))` — CSFS single-SHA256s the message |
|
|
506
|
-
| Payment destination | P2PKH only | P2PKH **or** AuthScript bech32m (scriptPubKey bytes hardcoded) |
|
|
523
|
+
| Payment destination | P2PKH only | P2PKH **or** any AuthScript bech32m address — `nc1p` v1, `pq1z` v2, `nq1r` v3 (scriptPubKey bytes hardcoded, `OP_1`/`OP_2`/`OP_3` included) |
|
|
507
524
|
|
|
508
525
|
```ts
|
|
509
526
|
import {
|
|
@@ -516,7 +533,7 @@ import {
|
|
|
516
533
|
|
|
517
534
|
const scriptPubKeyHex = buildPartialFillScriptPQHex({
|
|
518
535
|
network: 'xna-test',
|
|
519
|
-
paymentAddress: '
|
|
536
|
+
paymentAddress: 'tpq1z...', // tnc1p… / tpq1z… / tnq1r… bech32m, or legacy "t..." P2PKH
|
|
520
537
|
pubKeyCommitment: sha256(alicePQPubKey), // 32 bytes
|
|
521
538
|
tokenId: 'CAT',
|
|
522
539
|
unitPriceSats: 100_000_000n,
|
|
@@ -552,7 +569,8 @@ OP_ENDIF
|
|
|
552
569
|
## Network handling
|
|
553
570
|
|
|
554
571
|
Builders take address strings (whose prefix already encodes the network:
|
|
555
|
-
`t.../N...` for P2PKH
|
|
572
|
+
`t.../N...` for P2PKH; `tnc1p/nc1p` (v1), `tpq1z/pq1z` (v2) and
|
|
573
|
+
`tnq1r/nq1r` (v3) for AuthScript bech32m) and
|
|
556
574
|
validate them via `decodeAddress` from `neurai-create-transaction`. No
|
|
557
575
|
builder accepts a separate `network` parameter — it would be redundant
|
|
558
576
|
with the address and invite silent mismatches.
|
|
@@ -563,7 +581,8 @@ network*: a legacy covenant is opcodes plus a 20-byte PKH, a PQ covenant
|
|
|
563
581
|
is opcodes plus a 32-byte commitment and raw payment-scriptPubKey bytes,
|
|
564
582
|
and neither payload differs between mainnet and testnet. The parser
|
|
565
583
|
receives `network` purely so the caller can later base58-encode
|
|
566
|
-
`sellerPubKeyHash` against the right version byte
|
|
584
|
+
`sellerPubKeyHash` against the right version byte (a Legacy address,
|
|
585
|
+
neurai-key `xna-legacy` / `xna-legacy-test`), or interpret
|
|
567
586
|
`paymentScriptPubKey` in the correct bech32m/base58 context.
|
|
568
587
|
|
|
569
588
|
Keep this split intact when adding new covenants: builders reject a
|
|
@@ -587,7 +606,7 @@ Keep this split intact when adding new covenants: builders reject a
|
|
|
587
606
|
testnet today — no `-acceptnonstdtxn=1` required. The legacy 80 B cap
|
|
588
607
|
only applies when CSFS is off.
|
|
589
608
|
- **Commitment choice (PQ).** The PQ covenant commits to
|
|
590
|
-
`SHA256(pubKey)`, not the
|
|
609
|
+
`SHA256(pubKey)`, not the bech32m AuthScript program. That keeps the
|
|
591
610
|
covenant decoupled from AuthScript address derivation and lets the
|
|
592
611
|
caller use any PQ key whose SHA256 they can compute.
|
|
593
612
|
|
|
@@ -613,6 +632,38 @@ consumable; callers import directly from the package root.
|
|
|
613
632
|
|
|
614
633
|
---
|
|
615
634
|
|
|
635
|
+
## Version notes
|
|
636
|
+
|
|
637
|
+
### 0.9.1
|
|
638
|
+
|
|
639
|
+
TypeScript declarations for CommonJS. `require()` loads `dist/index.cjs`, but
|
|
640
|
+
the package only published ESM declarations, so a CommonJS file compiled with
|
|
641
|
+
`moduleResolution: "node16"` got `TS1471` and no types. Each condition of
|
|
642
|
+
`exports` now has its own declarations (`import` → `dist/index.d.ts`,
|
|
643
|
+
`require` → `dist/index.d.cts`). No runtime or API change. `npm run
|
|
644
|
+
test:types` compiles ESM, CommonJS and browser consumers against the built
|
|
645
|
+
declarations (NodeNext, Node16, Bundler; `skipLibCheck: false`) and `npm run
|
|
646
|
+
test:package` checks the packed tarball in a clean project, with TypeScript
|
|
647
|
+
4.7 too.
|
|
648
|
+
|
|
649
|
+
### 0.9.0
|
|
650
|
+
|
|
651
|
+
Address types of neurai-key 5 / neurai-create-transaction 0.9.0.
|
|
652
|
+
|
|
653
|
+
- `encodeSellerScriptPubKey` keeps the witness version of the address:
|
|
654
|
+
`pq1z…` payment addresses are hardcoded as `OP_2 <32B>` and `nq1r…` as
|
|
655
|
+
`OP_3 <32B>` (a same-program `OP_1` script would be another destination).
|
|
656
|
+
`SellerAddressKind` gains `'pq'` and `'ecdsa'`, and the result carries
|
|
657
|
+
`witnessVersion`. Code that switched on `kind === 'authscript'` to mean
|
|
658
|
+
"any bech32m destination" must handle the new kinds.
|
|
659
|
+
- Generic AuthScript v1 addresses are `nc1p…` / `tnc1p…`. The pre-5.0
|
|
660
|
+
`nq1p…` / `tnq1p…` strings are rejected (by create-transaction's
|
|
661
|
+
`decodeAddress`), like in the node.
|
|
662
|
+
- `encodeAuthScriptScriptPubKey(program, witnessVersion = 1)`; new
|
|
663
|
+
`buildStrictWitnessPQ` / `buildStrictWitnessECDSA` for the strict families.
|
|
664
|
+
- Requires `@neuraiproject/neurai-create-transaction` `^0.9.0` (breaking
|
|
665
|
+
release, not matched by the previous `^0.8.1` range).
|
|
666
|
+
|
|
616
667
|
## License
|
|
617
668
|
|
|
618
669
|
MIT — same terms as the rest of the `@neuraiproject/*` libraries.
|
|
@@ -580,10 +580,17 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
580
580
|
}
|
|
581
581
|
|
|
582
582
|
/**
|
|
583
|
-
* AuthScript
|
|
583
|
+
* AuthScript scriptPubKey + witness-stack builders.
|
|
584
584
|
*
|
|
585
|
-
* AuthScript outputs encode a 32-byte commitment in a witness
|
|
586
|
-
* scriptPubKey =
|
|
585
|
+
* AuthScript outputs encode a 32-byte commitment in a witness program:
|
|
586
|
+
* scriptPubKey = OP_n 0x20 <32-byte program>
|
|
587
|
+
*
|
|
588
|
+
* OP_1 generic AuthScript v1 (nc1p… / tnc1p…): any auth type, any witnessScript
|
|
589
|
+
* OP_2 strict PQ v2 (pq1z… / tpq1z…): auth type 0x01, witnessScript OP_TRUE
|
|
590
|
+
* OP_3 strict ECDSA v3 (nq1r… / tnq1r…): auth type 0x02, witnessScript OP_TRUE
|
|
591
|
+
*
|
|
592
|
+
* The witness version is also the first byte of the commitment preimage:
|
|
593
|
+
* tagged_hash("NeuraiAuthScript", version || auth_descriptor || SHA256(witnessScript))
|
|
587
594
|
*
|
|
588
595
|
* The program is `HASH160`/`SHA256` over a descriptor that depends on the
|
|
589
596
|
* `auth_type` byte carried as the first witness-stack element at spend time.
|
|
@@ -610,11 +617,24 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
610
617
|
const AUTHSCRIPT_REF = 0x03;
|
|
611
618
|
/** Cap for PQ signature / pubkey pushes under NIP-018 (3072 B). */
|
|
612
619
|
const MAX_PQ_PUSH = 3072;
|
|
613
|
-
|
|
620
|
+
const WITNESS_VERSION_OPCODE = {
|
|
621
|
+
1: OP_1,
|
|
622
|
+
2: OP_2,
|
|
623
|
+
3: OP_3
|
|
624
|
+
};
|
|
625
|
+
/**
|
|
626
|
+
* `OP_n 0x20 <program>` for witness version `n`. Defaults to the generic
|
|
627
|
+
* AuthScript v1 (`OP_1`), which is what every covenant commits to.
|
|
628
|
+
*/
|
|
629
|
+
function encodeAuthScriptScriptPubKey(program, witnessVersion = 1) {
|
|
614
630
|
if (!(program instanceof Uint8Array) || program.length !== 32) {
|
|
615
631
|
throw new Error('AuthScript program must be a 32-byte Uint8Array');
|
|
616
632
|
}
|
|
617
|
-
|
|
633
|
+
const opcode = WITNESS_VERSION_OPCODE[witnessVersion];
|
|
634
|
+
if (opcode === undefined) {
|
|
635
|
+
throw new Error(`AuthScript witness version must be 1, 2 or 3, got ${String(witnessVersion)}`);
|
|
636
|
+
}
|
|
637
|
+
return concatBytes(Uint8Array.of(opcode, 0x20), program);
|
|
618
638
|
}
|
|
619
639
|
function assertWitnessScript(ws) {
|
|
620
640
|
if (!(ws instanceof Uint8Array) || ws.length === 0) {
|
|
@@ -686,6 +706,45 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
686
706
|
input.witnessScript
|
|
687
707
|
];
|
|
688
708
|
}
|
|
709
|
+
/** Length of the versioned ML-DSA-44 pubkey the node expects (0x05 prefix + 1312 B). */
|
|
710
|
+
const STRICT_PQ_PUBKEY_LENGTH = 1313;
|
|
711
|
+
/** Version prefix of an ML-DSA-44 pubkey on the witness stack. */
|
|
712
|
+
const PQ_PUBKEY_PREFIX = 0x05;
|
|
713
|
+
/**
|
|
714
|
+
* Witness stack for spending a strict PQ witness v2 output (`pq1z…`):
|
|
715
|
+
* exactly `[0x01, sig, pubKey, OP_TRUE]`. The node rejects any other
|
|
716
|
+
* shape (extra arguments, another witnessScript) for the strict families.
|
|
717
|
+
*/
|
|
718
|
+
function buildStrictWitnessPQ(input) {
|
|
719
|
+
if (!(input.signature instanceof Uint8Array) || input.signature.length === 0) {
|
|
720
|
+
throw new Error('signature must be a non-empty Uint8Array');
|
|
721
|
+
}
|
|
722
|
+
if (input.signature.length > MAX_PQ_PUSH) {
|
|
723
|
+
throw new Error(`signature of ${input.signature.length} bytes exceeds MAX_PQ_SCRIPT_ELEMENT_SIZE (${MAX_PQ_PUSH})`);
|
|
724
|
+
}
|
|
725
|
+
if (!(input.pubKey instanceof Uint8Array) ||
|
|
726
|
+
input.pubKey.length !== STRICT_PQ_PUBKEY_LENGTH ||
|
|
727
|
+
input.pubKey[0] !== PQ_PUBKEY_PREFIX) {
|
|
728
|
+
throw new Error(`pubKey must be the ${STRICT_PQ_PUBKEY_LENGTH}-byte versioned ML-DSA-44 key (0x05 prefix)`);
|
|
729
|
+
}
|
|
730
|
+
return [Uint8Array.of(AUTHSCRIPT_PQ), input.signature, input.pubKey, Uint8Array.of(OP_TRUE)];
|
|
731
|
+
}
|
|
732
|
+
/**
|
|
733
|
+
* Witness stack for spending a strict ECDSA witness v3 output (`nq1r…`):
|
|
734
|
+
* exactly `[0x02, sig, pubKey33, OP_TRUE]`. The node rejects uncompressed
|
|
735
|
+
* keys for this family.
|
|
736
|
+
*/
|
|
737
|
+
function buildStrictWitnessECDSA(input) {
|
|
738
|
+
if (!(input.signature instanceof Uint8Array) || input.signature.length === 0) {
|
|
739
|
+
throw new Error('signature must be a non-empty Uint8Array');
|
|
740
|
+
}
|
|
741
|
+
if (!(input.pubKey instanceof Uint8Array) ||
|
|
742
|
+
input.pubKey.length !== 33 ||
|
|
743
|
+
(input.pubKey[0] !== 0x02 && input.pubKey[0] !== 0x03)) {
|
|
744
|
+
throw new Error('pubKey must be a compressed (33B) secp256k1 key for strict ECDSA witness v3');
|
|
745
|
+
}
|
|
746
|
+
return [Uint8Array.of(AUTHSCRIPT_LEGACY), input.signature, input.pubKey, Uint8Array.of(OP_TRUE)];
|
|
747
|
+
}
|
|
689
748
|
/**
|
|
690
749
|
* Build the witness stack for a NoAuth AuthScript spend. The spend is gated
|
|
691
750
|
* by the witnessScript alone (covenants, hash-locks, time-locks, ...); no
|
|
@@ -1524,37 +1583,96 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
1524
1583
|
|
|
1525
1584
|
const LEGACY_MAINNET_PREFIX = 53;
|
|
1526
1585
|
const LEGACY_TESTNET_PREFIX = 127;
|
|
1527
|
-
const
|
|
1528
|
-
|
|
1529
|
-
|
|
1530
|
-
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1586
|
+
const WITNESS_FAMILIES = [
|
|
1587
|
+
{
|
|
1588
|
+
type: 'authscript',
|
|
1589
|
+
witnessVersion: 1,
|
|
1590
|
+
hrp: { mainnet: 'nc', testnet: 'tnc' },
|
|
1591
|
+
network: { mainnet: 'xna-authscript', testnet: 'xna-authscript-test' }
|
|
1592
|
+
},
|
|
1593
|
+
{
|
|
1594
|
+
type: 'pq',
|
|
1595
|
+
witnessVersion: 2,
|
|
1596
|
+
hrp: { mainnet: 'pq', testnet: 'tpq' },
|
|
1597
|
+
network: { mainnet: 'xna-pq', testnet: 'xna-pq-test' }
|
|
1598
|
+
},
|
|
1599
|
+
{
|
|
1600
|
+
type: 'ecdsa',
|
|
1601
|
+
witnessVersion: 3,
|
|
1602
|
+
hrp: { mainnet: 'nq', testnet: 'tnq' },
|
|
1603
|
+
network: { mainnet: 'xna', testnet: 'xna-test' }
|
|
1604
|
+
}
|
|
1605
|
+
];
|
|
1606
|
+
/** The family that owns `hrp` (lowercase), with the chain it encodes. */
|
|
1607
|
+
function witnessFamilyByHrp(hrp) {
|
|
1608
|
+
for (const family of WITNESS_FAMILIES) {
|
|
1609
|
+
if (family.hrp.mainnet === hrp)
|
|
1610
|
+
return { family, chain: 'mainnet' };
|
|
1611
|
+
if (family.hrp.testnet === hrp)
|
|
1612
|
+
return { family, chain: 'testnet' };
|
|
1613
|
+
}
|
|
1614
|
+
return undefined;
|
|
1615
|
+
}
|
|
1616
|
+
/** The family encoded by `witnessVersion`, or undefined for any other version. */
|
|
1617
|
+
function witnessFamilyByVersion(witnessVersion) {
|
|
1618
|
+
return WITNESS_FAMILIES.find((family) => family.witnessVersion === witnessVersion);
|
|
1540
1619
|
}
|
|
1541
1620
|
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1545
|
-
|
|
1546
|
-
|
|
1547
|
-
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
1552
|
-
|
|
1553
|
-
|
|
1554
|
-
|
|
1555
|
-
|
|
1621
|
+
// Longest Bech32m string the node's decoder accepts (bech32.cpp).
|
|
1622
|
+
const BECH32M_MAX_LENGTH = 90;
|
|
1623
|
+
const AUTHSCRIPT_PROGRAM_LENGTH = 32;
|
|
1624
|
+
function tryBech32mDecode(address) {
|
|
1625
|
+
try {
|
|
1626
|
+
const { prefix, words } = distExports.bech32m.decode(address, BECH32M_MAX_LENGTH);
|
|
1627
|
+
return { hrp: prefix.toLowerCase(), words };
|
|
1628
|
+
}
|
|
1629
|
+
catch {
|
|
1630
|
+
return null;
|
|
1631
|
+
}
|
|
1632
|
+
}
|
|
1633
|
+
function decodeWitnessAddress(address, parts) {
|
|
1634
|
+
const owner = witnessFamilyByHrp(parts.hrp);
|
|
1635
|
+
if (!owner) {
|
|
1636
|
+
throw new Error(`Unsupported Bech32m prefix "${parts.hrp}" for ${address}`);
|
|
1637
|
+
}
|
|
1638
|
+
if (parts.words.length === 0) {
|
|
1639
|
+
throw new Error(`Empty witness program in ${address}`);
|
|
1640
|
+
}
|
|
1641
|
+
const version = parts.words[0];
|
|
1642
|
+
const { family, chain } = owner;
|
|
1643
|
+
if (version !== family.witnessVersion) {
|
|
1644
|
+
const actual = witnessFamilyByVersion(version);
|
|
1645
|
+
const hint = actual
|
|
1646
|
+
? `; witness v${version} addresses use the "${actual.hrp[chain]}" prefix`
|
|
1647
|
+
: '';
|
|
1648
|
+
const legacyHint = family.type === 'ecdsa' && version === 1
|
|
1649
|
+
? ' Generic AuthScript v1 addresses are now encoded as nc1p… / tnc1p… ' +
|
|
1650
|
+
'(same scriptPubKey): regenerate the address (neurai-key xna-authscript networks).'
|
|
1651
|
+
: '';
|
|
1652
|
+
throw new Error(`Address ${address}: the "${parts.hrp}" prefix only encodes witness v${family.witnessVersion}, ` +
|
|
1653
|
+
`not v${version}${hint}.${legacyHint}`);
|
|
1654
|
+
}
|
|
1655
|
+
let program;
|
|
1656
|
+
try {
|
|
1657
|
+
program = Uint8Array.from(distExports.bech32m.fromWords(parts.words.slice(1)));
|
|
1658
|
+
}
|
|
1659
|
+
catch {
|
|
1660
|
+
throw new Error(`Invalid witness program padding in ${address}`);
|
|
1661
|
+
}
|
|
1662
|
+
if (program.length !== AUTHSCRIPT_PROGRAM_LENGTH) {
|
|
1663
|
+
throw new Error(`Unsupported AuthScript program length ${program.length} for ${address} (expected ${AUTHSCRIPT_PROGRAM_LENGTH})`);
|
|
1556
1664
|
}
|
|
1557
|
-
|
|
1665
|
+
return {
|
|
1666
|
+
address,
|
|
1667
|
+
type: family.type,
|
|
1668
|
+
witnessVersion: family.witnessVersion,
|
|
1669
|
+
network: family.network[chain],
|
|
1670
|
+
program,
|
|
1671
|
+
commitment: program
|
|
1672
|
+
};
|
|
1673
|
+
}
|
|
1674
|
+
function decodeLegacyAddress(address) {
|
|
1675
|
+
const payload = Uint8Array.from(bs58check.decode(address));
|
|
1558
1676
|
if (payload.length !== 21) {
|
|
1559
1677
|
throw new Error(`Unsupported legacy address payload length for ${address}`);
|
|
1560
1678
|
}
|
|
@@ -1563,13 +1681,51 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
1563
1681
|
throw new Error(`Unsupported legacy address prefix ${prefix} for ${address}`);
|
|
1564
1682
|
}
|
|
1565
1683
|
return {
|
|
1566
|
-
address
|
|
1684
|
+
address,
|
|
1567
1685
|
type: 'p2pkh',
|
|
1568
|
-
network:
|
|
1686
|
+
network: prefix === LEGACY_MAINNET_PREFIX ? 'xna-legacy' : 'xna-legacy-test',
|
|
1569
1687
|
program: payload.slice(1),
|
|
1570
1688
|
hash: payload.slice(1)
|
|
1571
1689
|
};
|
|
1572
1690
|
}
|
|
1691
|
+
/**
|
|
1692
|
+
* Decode a Neurai address the way the node does (base58.cpp
|
|
1693
|
+
* `DecodeDestination`): Bech32m first, Base58Check otherwise.
|
|
1694
|
+
*
|
|
1695
|
+
* - Base58 P2PKH → `type: 'p2pkh'`, network `xna-legacy` / `xna-legacy-test`
|
|
1696
|
+
* (an `xna-old-legacy` address is indistinguishable and reports
|
|
1697
|
+
* `xna-legacy`).
|
|
1698
|
+
* - Bech32m → `authscript` (v1, `nc`/`tnc`), `pq` (v2, `pq`/`tpq`) or
|
|
1699
|
+
* `ecdsa` (v3, `nq`/`tnq`), with `witnessVersion` and the 32-byte
|
|
1700
|
+
* commitment. Any other HRP/version pair is rejected, including the old
|
|
1701
|
+
* `nq1p…` / `tnq1p…` encoding of generic AuthScript v1.
|
|
1702
|
+
*
|
|
1703
|
+
* The decoder does not know whether a witness family is active on the
|
|
1704
|
+
* target chain: before activation the node refuses v2/v3 addresses and a
|
|
1705
|
+
* witness output is anyone-can-spend.
|
|
1706
|
+
*/
|
|
1707
|
+
function decodeAddress(address) {
|
|
1708
|
+
const normalized = resolveAddressInput(address);
|
|
1709
|
+
if (!normalized)
|
|
1710
|
+
throw new Error('Address is required');
|
|
1711
|
+
const bech32mParts = tryBech32mDecode(normalized);
|
|
1712
|
+
if (bech32mParts) {
|
|
1713
|
+
return decodeWitnessAddress(normalized, bech32mParts);
|
|
1714
|
+
}
|
|
1715
|
+
try {
|
|
1716
|
+
return decodeLegacyAddress(normalized);
|
|
1717
|
+
}
|
|
1718
|
+
catch (legacyError) {
|
|
1719
|
+
// Not Base58 either. When the string carries a known Bech32m prefix the
|
|
1720
|
+
// Bech32m failure (bad checksum, mixed case…) is the useful diagnosis.
|
|
1721
|
+
const separator = normalized.lastIndexOf('1');
|
|
1722
|
+
const hrp = separator > 0 ? normalized.slice(0, separator).toLowerCase() : '';
|
|
1723
|
+
if (witnessFamilyByHrp(hrp)) {
|
|
1724
|
+
throw new Error(`Invalid Bech32m address ${normalized} (checksum, case or character error)`);
|
|
1725
|
+
}
|
|
1726
|
+
throw legacyError;
|
|
1727
|
+
}
|
|
1728
|
+
}
|
|
1573
1729
|
|
|
1574
1730
|
/**
|
|
1575
1731
|
* Address helpers. Wraps `decodeAddress` from
|
|
@@ -1577,9 +1733,12 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
1577
1733
|
* scriptPubKey bytes a covenant needs to hardcode. The actual
|
|
1578
1734
|
* scriptPubKey encoders live in `./standard/*`; this module delegates.
|
|
1579
1735
|
*
|
|
1580
|
-
*
|
|
1581
|
-
*
|
|
1582
|
-
* -
|
|
1736
|
+
* Every Neurai destination type is supported for the payment output
|
|
1737
|
+
* (output[0]):
|
|
1738
|
+
* - Legacy P2PKH (base58check) → `76a914<20>88ac`
|
|
1739
|
+
* - Generic AuthScript witness v1 (nc1p… / tnc1p…) → `5120<32>`
|
|
1740
|
+
* - Strict PQ witness v2 (pq1z… / tpq1z…) → `5220<32>`
|
|
1741
|
+
* - Strict ECDSA witness v3 (nq1r… / tnq1r…) → `5320<32>`
|
|
1583
1742
|
*/
|
|
1584
1743
|
/**
|
|
1585
1744
|
* Resolve any accepted seller address string into its scriptPubKey.
|
|
@@ -1596,11 +1755,14 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
1596
1755
|
hash
|
|
1597
1756
|
};
|
|
1598
1757
|
}
|
|
1599
|
-
if (decoded.type === 'authscript') {
|
|
1758
|
+
if (decoded.type === 'authscript' || decoded.type === 'pq' || decoded.type === 'ecdsa') {
|
|
1759
|
+
// The witness version is part of the destination: a pq1z… / nq1r…
|
|
1760
|
+
// payment must be hardcoded with OP_2 / OP_3, never with OP_1.
|
|
1600
1761
|
const program = Uint8Array.from(decoded.program);
|
|
1601
1762
|
return {
|
|
1602
|
-
kind:
|
|
1603
|
-
|
|
1763
|
+
kind: decoded.type,
|
|
1764
|
+
witnessVersion: decoded.witnessVersion,
|
|
1765
|
+
bytes: encodeAuthScriptScriptPubKey(program, decoded.witnessVersion),
|
|
1604
1766
|
hash: program
|
|
1605
1767
|
};
|
|
1606
1768
|
}
|
|
@@ -1615,8 +1777,8 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
1615
1777
|
* <prefix scriptPubKey bytes> OP_XNA_ASSET <pushdata(payload)> OP_DROP
|
|
1616
1778
|
*
|
|
1617
1779
|
* where `prefix` is the recipient's standard script (typically a P2PKH, an
|
|
1618
|
-
* AuthScript witness
|
|
1619
|
-
* order), and `payload` serializes a `CAssetTransfer`:
|
|
1780
|
+
* AuthScript `OP_1`/`OP_2`/`OP_3` witness program, or a bare covenant such
|
|
1781
|
+
* as the partial-fill sell order), and `payload` serializes a `CAssetTransfer`:
|
|
1620
1782
|
*
|
|
1621
1783
|
* payload = marker ("rvn" 0x72 0x76 0x6e | "xna" 0x78 0x6e 0x61)
|
|
1622
1784
|
* || type_marker (0x74 transfer)
|
|
@@ -2966,6 +3128,8 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
2966
3128
|
DEFAULT_PQ_TXHASH_SELECTOR: DEFAULT_PQ_TXHASH_SELECTOR,
|
|
2967
3129
|
MULTISIG_MAX_PUBKEYS: MULTISIG_MAX_PUBKEYS,
|
|
2968
3130
|
NULLDATA_STANDARD_MAX_SIZE: NULLDATA_STANDARD_MAX_SIZE,
|
|
3131
|
+
PQ_PUBKEY_PREFIX: PQ_PUBKEY_PREFIX,
|
|
3132
|
+
STRICT_PQ_PUBKEY_LENGTH: STRICT_PQ_PUBKEY_LENGTH,
|
|
2969
3133
|
ScriptBuilder: ScriptBuilder,
|
|
2970
3134
|
buildAuthScriptWitnessLegacy: buildAuthScriptWitnessLegacy,
|
|
2971
3135
|
buildAuthScriptWitnessNoAuth: buildAuthScriptWitnessNoAuth,
|
|
@@ -2984,6 +3148,8 @@ var NeuraiScriptsBundle = (function (exports) {
|
|
|
2984
3148
|
buildPartialFillScriptHex: buildPartialFillScriptHex,
|
|
2985
3149
|
buildPartialFillScriptPQ: buildPartialFillScriptPQ,
|
|
2986
3150
|
buildPartialFillScriptPQHex: buildPartialFillScriptPQHex,
|
|
3151
|
+
buildStrictWitnessECDSA: buildStrictWitnessECDSA,
|
|
3152
|
+
buildStrictWitnessPQ: buildStrictWitnessPQ,
|
|
2987
3153
|
bytesEqual: bytesEqual,
|
|
2988
3154
|
bytesToHex: bytesToHex,
|
|
2989
3155
|
concatBytes: concatBytes,
|