@neuraiproject/neurai-scripts 0.8.1 → 0.9.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 +55 -8
- package/dist/NeuraiScripts.global.js +225 -51
- 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 +222 -52
- package/dist/browser.js.map +1 -1
- package/dist/core/script-builder.d.ts +0 -6
- package/dist/index.cjs +225 -51
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.js +222 -52
- 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 +4 -4
package/dist/index.d.ts
CHANGED
|
@@ -2,8 +2,8 @@ export type { Network, OrderUtxo, ParsedPartialFillOrder, ParsedPartialFillOrder
|
|
|
2
2
|
export { bytesToHex, hexToBytes, concatBytes, bytesEqual, ensureHex } from './core/bytes.js';
|
|
3
3
|
export { ScriptBuilder, encodeScriptNum, pushBytes, pushInt, pushHex } from './core/script-builder.js';
|
|
4
4
|
export * as opcodes from './core/opcodes.js';
|
|
5
|
-
export { encodeP2PKHScriptPubKey, encodeP2WPKHScriptPubKey, encodeP2WSHScriptPubKey, encodeAuthScriptScriptPubKey, buildAuthScriptWitnessLegacy, buildAuthScriptWitnessPQ, buildAuthScriptWitnessNoAuth, buildAuthScriptWitnessRef, AUTHSCRIPT_NOAUTH, AUTHSCRIPT_PQ, AUTHSCRIPT_LEGACY, AUTHSCRIPT_REF, encodeNullDataScript, NULLDATA_STANDARD_MAX_SIZE, encodeMultisigRedeemScript, encodeMultisigRedeemScriptHex, encodeP2SHScriptPubKey, MULTISIG_MAX_PUBKEYS } from './standard/index.js';
|
|
6
|
-
export type { AuthType, AuthScriptWitnessLegacyInput, AuthScriptWitnessPQInput, AuthScriptWitnessNoAuthInput, AuthScriptWitnessRefInput, EncodeNullDataOptions, MultisigParams } from './standard/index.js';
|
|
5
|
+
export { encodeP2PKHScriptPubKey, encodeP2WPKHScriptPubKey, encodeP2WSHScriptPubKey, encodeAuthScriptScriptPubKey, buildAuthScriptWitnessLegacy, buildAuthScriptWitnessPQ, buildAuthScriptWitnessNoAuth, buildAuthScriptWitnessRef, buildStrictWitnessPQ, buildStrictWitnessECDSA, AUTHSCRIPT_NOAUTH, AUTHSCRIPT_PQ, AUTHSCRIPT_LEGACY, AUTHSCRIPT_REF, STRICT_PQ_PUBKEY_LENGTH, PQ_PUBKEY_PREFIX, encodeNullDataScript, NULLDATA_STANDARD_MAX_SIZE, encodeMultisigRedeemScript, encodeMultisigRedeemScriptHex, encodeP2SHScriptPubKey, MULTISIG_MAX_PUBKEYS } from './standard/index.js';
|
|
6
|
+
export type { AuthType, AuthScriptWitnessVersion, AuthScriptWitnessLegacyInput, AuthScriptWitnessPQInput, AuthScriptWitnessNoAuthInput, AuthScriptWitnessRefInput, StrictWitnessPQInput, StrictWitnessECDSAInput, EncodeNullDataOptions, MultisigParams } from './standard/index.js';
|
|
7
7
|
export { encodeSellerScriptPubKey } from './address.js';
|
|
8
8
|
export type { SellerAddressKind, SellerScriptPubKey } from './address.js';
|
|
9
9
|
export { splitAssetWrappedScriptPubKey } from './asset-wrapper.js';
|
package/dist/index.js
CHANGED
|
@@ -41,6 +41,18 @@ function bytesEqual(a, b) {
|
|
|
41
41
|
return true;
|
|
42
42
|
}
|
|
43
43
|
|
|
44
|
+
/** Exact monetary primitives. This module has no runtime dependencies. */
|
|
45
|
+
/** Normalize a raw integer without preserving an already rounded number. */
|
|
46
|
+
function toRawInteger(value, label = 'amount') {
|
|
47
|
+
if (typeof value === 'bigint')
|
|
48
|
+
return value;
|
|
49
|
+
if (typeof value === 'number' && Number.isSafeInteger(value))
|
|
50
|
+
return BigInt(value);
|
|
51
|
+
if (typeof value === 'string' && /^-?\d+$/.test(value) && value.length <= 100)
|
|
52
|
+
return BigInt(value);
|
|
53
|
+
throw new Error(`${label}: expected an exact integer; use bigint or an integer string for large values`);
|
|
54
|
+
}
|
|
55
|
+
|
|
44
56
|
/**
|
|
45
57
|
* Opcode constants for Neurai Script.
|
|
46
58
|
*
|
|
@@ -412,12 +424,6 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
412
424
|
TXHASH_VERSION: TXHASH_VERSION
|
|
413
425
|
});
|
|
414
426
|
|
|
415
|
-
/**
|
|
416
|
-
* Low-level Script assembler. Emits the exact byte layout expected by the
|
|
417
|
-
* Neurai interpreter: pushdata prefixes follow the same rules as Bitcoin
|
|
418
|
-
* (direct push for 1..75 bytes, OP_PUSHDATA1/2/4 otherwise), and integers
|
|
419
|
-
* are minimally-encoded as CScriptNum.
|
|
420
|
-
*/
|
|
421
427
|
/**
|
|
422
428
|
* Minimal CScriptNum encoding (Bitcoin consensus rules).
|
|
423
429
|
*
|
|
@@ -427,7 +433,7 @@ var opcodes = /*#__PURE__*/Object.freeze({
|
|
|
427
433
|
* - otherwise: sign-magnitude little-endian, with a sign bit on the last byte
|
|
428
434
|
*/
|
|
429
435
|
function encodeScriptNum(value) {
|
|
430
|
-
let n =
|
|
436
|
+
let n = toRawInteger(value, 'ScriptNum');
|
|
431
437
|
if (n === 0n)
|
|
432
438
|
return new Uint8Array();
|
|
433
439
|
const negative = n < 0n;
|
|
@@ -481,7 +487,7 @@ function pushBytes(data) {
|
|
|
481
487
|
* when available to match how the node's own templates look on the wire.
|
|
482
488
|
*/
|
|
483
489
|
function pushInt(value) {
|
|
484
|
-
const n =
|
|
490
|
+
const n = toRawInteger(value, 'ScriptNum');
|
|
485
491
|
if (n === -1n)
|
|
486
492
|
return Uint8Array.of(OP_1NEGATE);
|
|
487
493
|
if (n === 0n)
|
|
@@ -571,10 +577,17 @@ function encodeP2WSHScriptPubKey(witnessScriptSha256) {
|
|
|
571
577
|
}
|
|
572
578
|
|
|
573
579
|
/**
|
|
574
|
-
* AuthScript
|
|
580
|
+
* AuthScript scriptPubKey + witness-stack builders.
|
|
575
581
|
*
|
|
576
|
-
* AuthScript outputs encode a 32-byte commitment in a witness
|
|
577
|
-
* scriptPubKey =
|
|
582
|
+
* AuthScript outputs encode a 32-byte commitment in a witness program:
|
|
583
|
+
* scriptPubKey = OP_n 0x20 <32-byte program>
|
|
584
|
+
*
|
|
585
|
+
* OP_1 generic AuthScript v1 (nc1p… / tnc1p…): any auth type, any witnessScript
|
|
586
|
+
* OP_2 strict PQ v2 (pq1z… / tpq1z…): auth type 0x01, witnessScript OP_TRUE
|
|
587
|
+
* OP_3 strict ECDSA v3 (nq1r… / tnq1r…): auth type 0x02, witnessScript OP_TRUE
|
|
588
|
+
*
|
|
589
|
+
* The witness version is also the first byte of the commitment preimage:
|
|
590
|
+
* tagged_hash("NeuraiAuthScript", version || auth_descriptor || SHA256(witnessScript))
|
|
578
591
|
*
|
|
579
592
|
* The program is `HASH160`/`SHA256` over a descriptor that depends on the
|
|
580
593
|
* `auth_type` byte carried as the first witness-stack element at spend time.
|
|
@@ -601,11 +614,24 @@ const AUTHSCRIPT_LEGACY = 0x02;
|
|
|
601
614
|
const AUTHSCRIPT_REF = 0x03;
|
|
602
615
|
/** Cap for PQ signature / pubkey pushes under NIP-018 (3072 B). */
|
|
603
616
|
const MAX_PQ_PUSH = 3072;
|
|
604
|
-
|
|
617
|
+
const WITNESS_VERSION_OPCODE = {
|
|
618
|
+
1: OP_1,
|
|
619
|
+
2: OP_2,
|
|
620
|
+
3: OP_3
|
|
621
|
+
};
|
|
622
|
+
/**
|
|
623
|
+
* `OP_n 0x20 <program>` for witness version `n`. Defaults to the generic
|
|
624
|
+
* AuthScript v1 (`OP_1`), which is what every covenant commits to.
|
|
625
|
+
*/
|
|
626
|
+
function encodeAuthScriptScriptPubKey(program, witnessVersion = 1) {
|
|
605
627
|
if (!(program instanceof Uint8Array) || program.length !== 32) {
|
|
606
628
|
throw new Error('AuthScript program must be a 32-byte Uint8Array');
|
|
607
629
|
}
|
|
608
|
-
|
|
630
|
+
const opcode = WITNESS_VERSION_OPCODE[witnessVersion];
|
|
631
|
+
if (opcode === undefined) {
|
|
632
|
+
throw new Error(`AuthScript witness version must be 1, 2 or 3, got ${String(witnessVersion)}`);
|
|
633
|
+
}
|
|
634
|
+
return concatBytes(Uint8Array.of(opcode, 0x20), program);
|
|
609
635
|
}
|
|
610
636
|
function assertWitnessScript(ws) {
|
|
611
637
|
if (!(ws instanceof Uint8Array) || ws.length === 0) {
|
|
@@ -677,6 +703,45 @@ function buildAuthScriptWitnessPQ(input) {
|
|
|
677
703
|
input.witnessScript
|
|
678
704
|
];
|
|
679
705
|
}
|
|
706
|
+
/** Length of the versioned ML-DSA-44 pubkey the node expects (0x05 prefix + 1312 B). */
|
|
707
|
+
const STRICT_PQ_PUBKEY_LENGTH = 1313;
|
|
708
|
+
/** Version prefix of an ML-DSA-44 pubkey on the witness stack. */
|
|
709
|
+
const PQ_PUBKEY_PREFIX = 0x05;
|
|
710
|
+
/**
|
|
711
|
+
* Witness stack for spending a strict PQ witness v2 output (`pq1z…`):
|
|
712
|
+
* exactly `[0x01, sig, pubKey, OP_TRUE]`. The node rejects any other
|
|
713
|
+
* shape (extra arguments, another witnessScript) for the strict families.
|
|
714
|
+
*/
|
|
715
|
+
function buildStrictWitnessPQ(input) {
|
|
716
|
+
if (!(input.signature instanceof Uint8Array) || input.signature.length === 0) {
|
|
717
|
+
throw new Error('signature must be a non-empty Uint8Array');
|
|
718
|
+
}
|
|
719
|
+
if (input.signature.length > MAX_PQ_PUSH) {
|
|
720
|
+
throw new Error(`signature of ${input.signature.length} bytes exceeds MAX_PQ_SCRIPT_ELEMENT_SIZE (${MAX_PQ_PUSH})`);
|
|
721
|
+
}
|
|
722
|
+
if (!(input.pubKey instanceof Uint8Array) ||
|
|
723
|
+
input.pubKey.length !== STRICT_PQ_PUBKEY_LENGTH ||
|
|
724
|
+
input.pubKey[0] !== PQ_PUBKEY_PREFIX) {
|
|
725
|
+
throw new Error(`pubKey must be the ${STRICT_PQ_PUBKEY_LENGTH}-byte versioned ML-DSA-44 key (0x05 prefix)`);
|
|
726
|
+
}
|
|
727
|
+
return [Uint8Array.of(AUTHSCRIPT_PQ), input.signature, input.pubKey, Uint8Array.of(OP_TRUE)];
|
|
728
|
+
}
|
|
729
|
+
/**
|
|
730
|
+
* Witness stack for spending a strict ECDSA witness v3 output (`nq1r…`):
|
|
731
|
+
* exactly `[0x02, sig, pubKey33, OP_TRUE]`. The node rejects uncompressed
|
|
732
|
+
* keys for this family.
|
|
733
|
+
*/
|
|
734
|
+
function buildStrictWitnessECDSA(input) {
|
|
735
|
+
if (!(input.signature instanceof Uint8Array) || input.signature.length === 0) {
|
|
736
|
+
throw new Error('signature must be a non-empty Uint8Array');
|
|
737
|
+
}
|
|
738
|
+
if (!(input.pubKey instanceof Uint8Array) ||
|
|
739
|
+
input.pubKey.length !== 33 ||
|
|
740
|
+
(input.pubKey[0] !== 0x02 && input.pubKey[0] !== 0x03)) {
|
|
741
|
+
throw new Error('pubKey must be a compressed (33B) secp256k1 key for strict ECDSA witness v3');
|
|
742
|
+
}
|
|
743
|
+
return [Uint8Array.of(AUTHSCRIPT_LEGACY), input.signature, input.pubKey, Uint8Array.of(OP_TRUE)];
|
|
744
|
+
}
|
|
680
745
|
/**
|
|
681
746
|
* Build the witness stack for a NoAuth AuthScript spend. The spend is gated
|
|
682
747
|
* by the witnessScript alone (covenants, hash-locks, time-locks, ...); no
|
|
@@ -798,6 +863,8 @@ function encodeP2SHScriptPubKey(redeemScriptHash160) {
|
|
|
798
863
|
return concatBytes(Uint8Array.of(OP_HASH160, 0x14), redeemScriptHash160, Uint8Array.of(OP_EQUAL));
|
|
799
864
|
}
|
|
800
865
|
|
|
866
|
+
/** Exact monetary primitives. This module has no runtime dependencies. */
|
|
867
|
+
|
|
801
868
|
// base-x encoding / decoding
|
|
802
869
|
// Copyright (c) 2018 base-x contributors
|
|
803
870
|
// Copyright (c) 2014-2018 The Bitcoin Core developers (base58.cpp)
|
|
@@ -1513,37 +1580,96 @@ function resolveAddressInput(address) {
|
|
|
1513
1580
|
|
|
1514
1581
|
const LEGACY_MAINNET_PREFIX = 53;
|
|
1515
1582
|
const LEGACY_TESTNET_PREFIX = 127;
|
|
1516
|
-
const
|
|
1517
|
-
|
|
1518
|
-
|
|
1519
|
-
|
|
1520
|
-
|
|
1521
|
-
|
|
1522
|
-
|
|
1523
|
-
|
|
1524
|
-
|
|
1525
|
-
|
|
1526
|
-
|
|
1527
|
-
|
|
1528
|
-
|
|
1583
|
+
const WITNESS_FAMILIES = [
|
|
1584
|
+
{
|
|
1585
|
+
type: 'authscript',
|
|
1586
|
+
witnessVersion: 1,
|
|
1587
|
+
hrp: { mainnet: 'nc', testnet: 'tnc' },
|
|
1588
|
+
network: { mainnet: 'xna-authscript', testnet: 'xna-authscript-test' }
|
|
1589
|
+
},
|
|
1590
|
+
{
|
|
1591
|
+
type: 'pq',
|
|
1592
|
+
witnessVersion: 2,
|
|
1593
|
+
hrp: { mainnet: 'pq', testnet: 'tpq' },
|
|
1594
|
+
network: { mainnet: 'xna-pq', testnet: 'xna-pq-test' }
|
|
1595
|
+
},
|
|
1596
|
+
{
|
|
1597
|
+
type: 'ecdsa',
|
|
1598
|
+
witnessVersion: 3,
|
|
1599
|
+
hrp: { mainnet: 'nq', testnet: 'tnq' },
|
|
1600
|
+
network: { mainnet: 'xna', testnet: 'xna-test' }
|
|
1601
|
+
}
|
|
1602
|
+
];
|
|
1603
|
+
/** The family that owns `hrp` (lowercase), with the chain it encodes. */
|
|
1604
|
+
function witnessFamilyByHrp(hrp) {
|
|
1605
|
+
for (const family of WITNESS_FAMILIES) {
|
|
1606
|
+
if (family.hrp.mainnet === hrp)
|
|
1607
|
+
return { family, chain: 'mainnet' };
|
|
1608
|
+
if (family.hrp.testnet === hrp)
|
|
1609
|
+
return { family, chain: 'testnet' };
|
|
1610
|
+
}
|
|
1611
|
+
return undefined;
|
|
1612
|
+
}
|
|
1613
|
+
/** The family encoded by `witnessVersion`, or undefined for any other version. */
|
|
1614
|
+
function witnessFamilyByVersion(witnessVersion) {
|
|
1615
|
+
return WITNESS_FAMILIES.find((family) => family.witnessVersion === witnessVersion);
|
|
1529
1616
|
}
|
|
1530
1617
|
|
|
1531
|
-
|
|
1532
|
-
|
|
1533
|
-
|
|
1534
|
-
|
|
1535
|
-
|
|
1536
|
-
|
|
1537
|
-
|
|
1538
|
-
|
|
1539
|
-
|
|
1540
|
-
|
|
1541
|
-
|
|
1542
|
-
|
|
1543
|
-
|
|
1544
|
-
|
|
1618
|
+
// Longest Bech32m string the node's decoder accepts (bech32.cpp).
|
|
1619
|
+
const BECH32M_MAX_LENGTH = 90;
|
|
1620
|
+
const AUTHSCRIPT_PROGRAM_LENGTH = 32;
|
|
1621
|
+
function tryBech32mDecode(address) {
|
|
1622
|
+
try {
|
|
1623
|
+
const { prefix, words } = distExports.bech32m.decode(address, BECH32M_MAX_LENGTH);
|
|
1624
|
+
return { hrp: prefix.toLowerCase(), words };
|
|
1625
|
+
}
|
|
1626
|
+
catch {
|
|
1627
|
+
return null;
|
|
1628
|
+
}
|
|
1629
|
+
}
|
|
1630
|
+
function decodeWitnessAddress(address, parts) {
|
|
1631
|
+
const owner = witnessFamilyByHrp(parts.hrp);
|
|
1632
|
+
if (!owner) {
|
|
1633
|
+
throw new Error(`Unsupported Bech32m prefix "${parts.hrp}" for ${address}`);
|
|
1634
|
+
}
|
|
1635
|
+
if (parts.words.length === 0) {
|
|
1636
|
+
throw new Error(`Empty witness program in ${address}`);
|
|
1637
|
+
}
|
|
1638
|
+
const version = parts.words[0];
|
|
1639
|
+
const { family, chain } = owner;
|
|
1640
|
+
if (version !== family.witnessVersion) {
|
|
1641
|
+
const actual = witnessFamilyByVersion(version);
|
|
1642
|
+
const hint = actual
|
|
1643
|
+
? `; witness v${version} addresses use the "${actual.hrp[chain]}" prefix`
|
|
1644
|
+
: '';
|
|
1645
|
+
const legacyHint = family.type === 'ecdsa' && version === 1
|
|
1646
|
+
? ' Generic AuthScript v1 addresses are now encoded as nc1p… / tnc1p… ' +
|
|
1647
|
+
'(same scriptPubKey): regenerate the address (neurai-key xna-authscript networks).'
|
|
1648
|
+
: '';
|
|
1649
|
+
throw new Error(`Address ${address}: the "${parts.hrp}" prefix only encodes witness v${family.witnessVersion}, ` +
|
|
1650
|
+
`not v${version}${hint}.${legacyHint}`);
|
|
1651
|
+
}
|
|
1652
|
+
let program;
|
|
1653
|
+
try {
|
|
1654
|
+
program = Uint8Array.from(distExports.bech32m.fromWords(parts.words.slice(1)));
|
|
1655
|
+
}
|
|
1656
|
+
catch {
|
|
1657
|
+
throw new Error(`Invalid witness program padding in ${address}`);
|
|
1658
|
+
}
|
|
1659
|
+
if (program.length !== AUTHSCRIPT_PROGRAM_LENGTH) {
|
|
1660
|
+
throw new Error(`Unsupported AuthScript program length ${program.length} for ${address} (expected ${AUTHSCRIPT_PROGRAM_LENGTH})`);
|
|
1545
1661
|
}
|
|
1546
|
-
|
|
1662
|
+
return {
|
|
1663
|
+
address,
|
|
1664
|
+
type: family.type,
|
|
1665
|
+
witnessVersion: family.witnessVersion,
|
|
1666
|
+
network: family.network[chain],
|
|
1667
|
+
program,
|
|
1668
|
+
commitment: program
|
|
1669
|
+
};
|
|
1670
|
+
}
|
|
1671
|
+
function decodeLegacyAddress(address) {
|
|
1672
|
+
const payload = Uint8Array.from(bs58check.decode(address));
|
|
1547
1673
|
if (payload.length !== 21) {
|
|
1548
1674
|
throw new Error(`Unsupported legacy address payload length for ${address}`);
|
|
1549
1675
|
}
|
|
@@ -1552,13 +1678,51 @@ function decodeAddress(address) {
|
|
|
1552
1678
|
throw new Error(`Unsupported legacy address prefix ${prefix} for ${address}`);
|
|
1553
1679
|
}
|
|
1554
1680
|
return {
|
|
1555
|
-
address
|
|
1681
|
+
address,
|
|
1556
1682
|
type: 'p2pkh',
|
|
1557
|
-
network:
|
|
1683
|
+
network: prefix === LEGACY_MAINNET_PREFIX ? 'xna-legacy' : 'xna-legacy-test',
|
|
1558
1684
|
program: payload.slice(1),
|
|
1559
1685
|
hash: payload.slice(1)
|
|
1560
1686
|
};
|
|
1561
1687
|
}
|
|
1688
|
+
/**
|
|
1689
|
+
* Decode a Neurai address the way the node does (base58.cpp
|
|
1690
|
+
* `DecodeDestination`): Bech32m first, Base58Check otherwise.
|
|
1691
|
+
*
|
|
1692
|
+
* - Base58 P2PKH → `type: 'p2pkh'`, network `xna-legacy` / `xna-legacy-test`
|
|
1693
|
+
* (an `xna-old-legacy` address is indistinguishable and reports
|
|
1694
|
+
* `xna-legacy`).
|
|
1695
|
+
* - Bech32m → `authscript` (v1, `nc`/`tnc`), `pq` (v2, `pq`/`tpq`) or
|
|
1696
|
+
* `ecdsa` (v3, `nq`/`tnq`), with `witnessVersion` and the 32-byte
|
|
1697
|
+
* commitment. Any other HRP/version pair is rejected, including the old
|
|
1698
|
+
* `nq1p…` / `tnq1p…` encoding of generic AuthScript v1.
|
|
1699
|
+
*
|
|
1700
|
+
* The decoder does not know whether a witness family is active on the
|
|
1701
|
+
* target chain: before activation the node refuses v2/v3 addresses and a
|
|
1702
|
+
* witness output is anyone-can-spend.
|
|
1703
|
+
*/
|
|
1704
|
+
function decodeAddress(address) {
|
|
1705
|
+
const normalized = resolveAddressInput(address);
|
|
1706
|
+
if (!normalized)
|
|
1707
|
+
throw new Error('Address is required');
|
|
1708
|
+
const bech32mParts = tryBech32mDecode(normalized);
|
|
1709
|
+
if (bech32mParts) {
|
|
1710
|
+
return decodeWitnessAddress(normalized, bech32mParts);
|
|
1711
|
+
}
|
|
1712
|
+
try {
|
|
1713
|
+
return decodeLegacyAddress(normalized);
|
|
1714
|
+
}
|
|
1715
|
+
catch (legacyError) {
|
|
1716
|
+
// Not Base58 either. When the string carries a known Bech32m prefix the
|
|
1717
|
+
// Bech32m failure (bad checksum, mixed case…) is the useful diagnosis.
|
|
1718
|
+
const separator = normalized.lastIndexOf('1');
|
|
1719
|
+
const hrp = separator > 0 ? normalized.slice(0, separator).toLowerCase() : '';
|
|
1720
|
+
if (witnessFamilyByHrp(hrp)) {
|
|
1721
|
+
throw new Error(`Invalid Bech32m address ${normalized} (checksum, case or character error)`);
|
|
1722
|
+
}
|
|
1723
|
+
throw legacyError;
|
|
1724
|
+
}
|
|
1725
|
+
}
|
|
1562
1726
|
|
|
1563
1727
|
/**
|
|
1564
1728
|
* Address helpers. Wraps `decodeAddress` from
|
|
@@ -1566,9 +1730,12 @@ function decodeAddress(address) {
|
|
|
1566
1730
|
* scriptPubKey bytes a covenant needs to hardcode. The actual
|
|
1567
1731
|
* scriptPubKey encoders live in `./standard/*`; this module delegates.
|
|
1568
1732
|
*
|
|
1569
|
-
*
|
|
1570
|
-
*
|
|
1571
|
-
* -
|
|
1733
|
+
* Every Neurai destination type is supported for the payment output
|
|
1734
|
+
* (output[0]):
|
|
1735
|
+
* - Legacy P2PKH (base58check) → `76a914<20>88ac`
|
|
1736
|
+
* - Generic AuthScript witness v1 (nc1p… / tnc1p…) → `5120<32>`
|
|
1737
|
+
* - Strict PQ witness v2 (pq1z… / tpq1z…) → `5220<32>`
|
|
1738
|
+
* - Strict ECDSA witness v3 (nq1r… / tnq1r…) → `5320<32>`
|
|
1572
1739
|
*/
|
|
1573
1740
|
/**
|
|
1574
1741
|
* Resolve any accepted seller address string into its scriptPubKey.
|
|
@@ -1585,11 +1752,14 @@ function encodeSellerScriptPubKey(address) {
|
|
|
1585
1752
|
hash
|
|
1586
1753
|
};
|
|
1587
1754
|
}
|
|
1588
|
-
if (decoded.type === 'authscript') {
|
|
1755
|
+
if (decoded.type === 'authscript' || decoded.type === 'pq' || decoded.type === 'ecdsa') {
|
|
1756
|
+
// The witness version is part of the destination: a pq1z… / nq1r…
|
|
1757
|
+
// payment must be hardcoded with OP_2 / OP_3, never with OP_1.
|
|
1589
1758
|
const program = Uint8Array.from(decoded.program);
|
|
1590
1759
|
return {
|
|
1591
|
-
kind:
|
|
1592
|
-
|
|
1760
|
+
kind: decoded.type,
|
|
1761
|
+
witnessVersion: decoded.witnessVersion,
|
|
1762
|
+
bytes: encodeAuthScriptScriptPubKey(program, decoded.witnessVersion),
|
|
1593
1763
|
hash: program
|
|
1594
1764
|
};
|
|
1595
1765
|
}
|
|
@@ -1604,8 +1774,8 @@ function encodeSellerScriptPubKey(address) {
|
|
|
1604
1774
|
* <prefix scriptPubKey bytes> OP_XNA_ASSET <pushdata(payload)> OP_DROP
|
|
1605
1775
|
*
|
|
1606
1776
|
* where `prefix` is the recipient's standard script (typically a P2PKH, an
|
|
1607
|
-
* AuthScript witness
|
|
1608
|
-
* order), and `payload` serializes a `CAssetTransfer`:
|
|
1777
|
+
* AuthScript `OP_1`/`OP_2`/`OP_3` witness program, or a bare covenant such
|
|
1778
|
+
* as the partial-fill sell order), and `payload` serializes a `CAssetTransfer`:
|
|
1609
1779
|
*
|
|
1610
1780
|
* payload = marker ("rvn" 0x72 0x76 0x6e | "xna" 0x78 0x6e 0x61)
|
|
1611
1781
|
* || type_marker (0x74 transfer)
|
|
@@ -2944,5 +3114,5 @@ function parsePartialFillScriptPQ(script, network = 'xna-test') {
|
|
|
2944
3114
|
};
|
|
2945
3115
|
}
|
|
2946
3116
|
|
|
2947
|
-
export { AUTHSCRIPT_LEGACY, AUTHSCRIPT_NOAUTH, AUTHSCRIPT_PQ, AUTHSCRIPT_REF, DEFAULT_PQ_TXHASH_SELECTOR, MULTISIG_MAX_PUBKEYS, NULLDATA_STANDARD_MAX_SIZE, ScriptBuilder, buildAuthScriptWitnessLegacy, buildAuthScriptWitnessNoAuth, buildAuthScriptWitnessPQ, buildAuthScriptWitnessRef, buildCancelScriptSig, buildCancelScriptSigHex, buildCancelScriptSigPQ, buildCancelScriptSigPQHex, buildCancelWitnessStack, buildCancelWitnessStackPQ, buildFillScriptSig, buildFillScriptSigHex, buildFillWitnessStack, buildPartialFillScript, buildPartialFillScriptHex, buildPartialFillScriptPQ, buildPartialFillScriptPQHex, bytesEqual, bytesToHex, concatBytes, encodeAuthScriptScriptPubKey, encodeMultisigRedeemScript, encodeMultisigRedeemScriptHex, encodeNullDataScript, encodeP2PKHScriptPubKey, encodeP2SHScriptPubKey, encodeP2WPKHScriptPubKey, encodeP2WSHScriptPubKey, encodeScriptNum, encodeSellerScriptPubKey, ensureHex, hexToBytes, isPartialFillScriptPQ, opcodes, parsePartialFillScript, parsePartialFillScriptPQ, pushBytes, pushHex, pushInt, splitAssetWrappedScriptPubKey };
|
|
3117
|
+
export { AUTHSCRIPT_LEGACY, AUTHSCRIPT_NOAUTH, AUTHSCRIPT_PQ, AUTHSCRIPT_REF, DEFAULT_PQ_TXHASH_SELECTOR, MULTISIG_MAX_PUBKEYS, NULLDATA_STANDARD_MAX_SIZE, PQ_PUBKEY_PREFIX, STRICT_PQ_PUBKEY_LENGTH, ScriptBuilder, buildAuthScriptWitnessLegacy, buildAuthScriptWitnessNoAuth, buildAuthScriptWitnessPQ, buildAuthScriptWitnessRef, buildCancelScriptSig, buildCancelScriptSigHex, buildCancelScriptSigPQ, buildCancelScriptSigPQHex, buildCancelWitnessStack, buildCancelWitnessStackPQ, buildFillScriptSig, buildFillScriptSigHex, buildFillWitnessStack, buildPartialFillScript, buildPartialFillScriptHex, buildPartialFillScriptPQ, buildPartialFillScriptPQHex, buildStrictWitnessECDSA, buildStrictWitnessPQ, bytesEqual, bytesToHex, concatBytes, encodeAuthScriptScriptPubKey, encodeMultisigRedeemScript, encodeMultisigRedeemScriptHex, encodeNullDataScript, encodeP2PKHScriptPubKey, encodeP2SHScriptPubKey, encodeP2WPKHScriptPubKey, encodeP2WSHScriptPubKey, encodeScriptNum, encodeSellerScriptPubKey, ensureHex, hexToBytes, isPartialFillScriptPQ, opcodes, parsePartialFillScript, parsePartialFillScriptPQ, pushBytes, pushHex, pushInt, splitAssetWrappedScriptPubKey };
|
|
2948
3118
|
//# sourceMappingURL=index.js.map
|