@neuraiproject/neurai-assets 1.2.2 → 1.2.3

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.cjs CHANGED
@@ -1041,11 +1041,15 @@ var hasRequiredNetworks;
1041
1041
  function requireNetworks () {
1042
1042
  if (hasRequiredNetworks) return networks;
1043
1043
  hasRequiredNetworks = 1;
1044
+ const MAINNET_NETWORKS = ['xna', 'mainnet', 'xna-pq', 'mainnet-pq'];
1045
+ const TESTNET_NETWORKS = ['xna-test', 'testnet', 'regtest', 'xna-pq-test', 'testnet-pq'];
1046
+
1044
1047
  const NETWORKS = {
1045
1048
  MAINNET: {
1046
1049
  name: 'xna',
1047
1050
  displayName: 'Neurai Mainnet',
1048
1051
  addressPrefix: 'N',
1052
+ authScriptAddressPrefix: 'nq1',
1049
1053
  pqAddressPrefix: 'nq1',
1050
1054
  assetNameMaxLength: 32,
1051
1055
  defaultRPCPort: 19001,
@@ -1056,6 +1060,7 @@ function requireNetworks () {
1056
1060
  name: 'xna-test',
1057
1061
  displayName: 'Neurai Testnet',
1058
1062
  addressPrefix: 't',
1063
+ authScriptAddressPrefix: 'tnq1',
1059
1064
  pqAddressPrefix: 'tnq1',
1060
1065
  assetNameMaxLength: 32, // Same as mainnet
1061
1066
  defaultRPCPort: 19101,
@@ -1064,8 +1069,9 @@ function requireNetworks () {
1064
1069
  },
1065
1070
  MAINNET_PQ: {
1066
1071
  name: 'xna-pq',
1067
- displayName: 'Neurai Mainnet PQ',
1072
+ displayName: 'Neurai Mainnet AuthScript',
1068
1073
  addressPrefix: 'N',
1074
+ authScriptAddressPrefix: 'nq1',
1069
1075
  pqAddressPrefix: 'nq1',
1070
1076
  assetNameMaxLength: 32,
1071
1077
  defaultRPCPort: 19001,
@@ -1074,8 +1080,9 @@ function requireNetworks () {
1074
1080
  },
1075
1081
  TESTNET_PQ: {
1076
1082
  name: 'xna-pq-test',
1077
- displayName: 'Neurai Testnet PQ',
1083
+ displayName: 'Neurai Testnet AuthScript',
1078
1084
  addressPrefix: 't',
1085
+ authScriptAddressPrefix: 'tnq1',
1079
1086
  pqAddressPrefix: 'tnq1',
1080
1087
  assetNameMaxLength: 32,
1081
1088
  defaultRPCPort: 19101,
@@ -1145,32 +1152,68 @@ function requireNetworks () {
1145
1152
 
1146
1153
  /**
1147
1154
  * Get network configuration
1155
+ * `xna-pq` / `xna-pq-test` are preserved as compatibility aliases for
1156
+ * AuthScript address flows on the same mainnet/testnet families.
1157
+ *
1148
1158
  * @param {string} networkName - Network name ('xna', 'xna-test', 'xna-pq', or 'xna-pq-test')
1149
1159
  * @returns {object} Network configuration
1150
1160
  */
1151
1161
  function getNetworkConfig(networkName) {
1152
- if (networkName === 'xna' || networkName === 'mainnet') {
1153
- return NETWORKS.MAINNET;
1154
- } else if (networkName === 'xna-test' || networkName === 'testnet') {
1155
- return NETWORKS.TESTNET;
1156
- } else if (networkName === 'xna-pq' || networkName === 'mainnet-pq') {
1157
- return NETWORKS.MAINNET_PQ;
1158
- } else if (networkName === 'xna-pq-test' || networkName === 'testnet-pq') {
1159
- return NETWORKS.TESTNET_PQ;
1162
+ if (MAINNET_NETWORKS.includes(networkName)) {
1163
+ return networkName === 'xna-pq' || networkName === 'mainnet-pq'
1164
+ ? NETWORKS.MAINNET_PQ
1165
+ : NETWORKS.MAINNET;
1166
+ } else if (TESTNET_NETWORKS.includes(networkName)) {
1167
+ return networkName === 'xna-pq-test' || networkName === 'testnet-pq'
1168
+ ? NETWORKS.TESTNET_PQ
1169
+ : NETWORKS.TESTNET;
1160
1170
  } else {
1161
1171
  throw new Error(`Unknown network: ${networkName}`);
1162
1172
  }
1163
1173
  }
1164
1174
 
1165
1175
  /**
1166
- * Detect network from address prefix
1176
+ * Resolve a network name to its chain family.
1177
+ * AuthScript aliases share the same family as legacy addresses.
1178
+ *
1179
+ * @param {string} networkName - Network name
1180
+ * @returns {'mainnet'|'testnet'} Network family
1181
+ */
1182
+ function resolveAddressNetworkFamily(networkName) {
1183
+ if (MAINNET_NETWORKS.includes(networkName)) {
1184
+ return 'mainnet';
1185
+ }
1186
+
1187
+ if (TESTNET_NETWORKS.includes(networkName)) {
1188
+ return 'testnet';
1189
+ }
1190
+
1191
+ throw new Error(`Unknown network: ${networkName}`);
1192
+ }
1193
+
1194
+ /**
1195
+ * Determine whether two network labels are compatible for address use.
1196
+ * This treats legacy and AuthScript labels on the same chain as compatible.
1197
+ *
1198
+ * @param {string} left - First network name
1199
+ * @param {string} right - Second network name
1200
+ * @returns {boolean} True if both belong to the same chain family
1201
+ */
1202
+ function areAddressNetworksCompatible(left, right) {
1203
+ return resolveAddressNetworkFamily(left) === resolveAddressNetworkFamily(right);
1204
+ }
1205
+
1206
+ /**
1207
+ * Detect network from address prefix.
1208
+ * `nq1...` / `tnq1...` are AuthScript witness-v1 destinations.
1209
+ *
1167
1210
  * @param {string} address - Neurai address
1168
1211
  * @returns {string} Network name ('xna', 'xna-test', 'xna-pq', or 'xna-pq-test')
1169
1212
  */
1170
1213
  function detectNetworkFromAddress(address) {
1171
- if (address.startsWith(NETWORKS.MAINNET_PQ.pqAddressPrefix)) {
1214
+ if (address.startsWith(NETWORKS.MAINNET_PQ.authScriptAddressPrefix)) {
1172
1215
  return 'xna-pq';
1173
- } else if (address.startsWith(NETWORKS.TESTNET_PQ.pqAddressPrefix)) {
1216
+ } else if (address.startsWith(NETWORKS.TESTNET_PQ.authScriptAddressPrefix)) {
1174
1217
  return 'xna-pq-test';
1175
1218
  } else if (address.startsWith('N')) {
1176
1219
  return 'xna';
@@ -1183,9 +1226,13 @@ function requireNetworks () {
1183
1226
 
1184
1227
  networks = {
1185
1228
  NETWORKS,
1229
+ MAINNET_NETWORKS,
1230
+ TESTNET_NETWORKS,
1186
1231
  ASSET_NAME_RULES,
1187
1232
  ASSET_LIMITS,
1188
1233
  getNetworkConfig,
1234
+ resolveAddressNetworkFamily,
1235
+ areAddressNetworksCompatible,
1189
1236
  detectNetworkFromAddress
1190
1237
  };
1191
1238
  return networks;
@@ -1213,9 +1260,13 @@ function requireConstants () {
1213
1260
  } = requireBurnAddresses();
1214
1261
  const {
1215
1262
  NETWORKS,
1263
+ MAINNET_NETWORKS,
1264
+ TESTNET_NETWORKS,
1216
1265
  ASSET_NAME_RULES,
1217
1266
  ASSET_LIMITS,
1218
1267
  getNetworkConfig,
1268
+ resolveAddressNetworkFamily,
1269
+ areAddressNetworksCompatible,
1219
1270
  detectNetworkFromAddress
1220
1271
  } = requireNetworks();
1221
1272
 
@@ -1238,9 +1289,13 @@ function requireConstants () {
1238
1289
 
1239
1290
  // Networks
1240
1291
  NETWORKS,
1292
+ MAINNET_NETWORKS,
1293
+ TESTNET_NETWORKS,
1241
1294
  ASSET_NAME_RULES,
1242
1295
  ASSET_LIMITS,
1243
1296
  getNetworkConfig,
1297
+ resolveAddressNetworkFamily,
1298
+ areAddressNetworksCompatible,
1244
1299
  detectNetworkFromAddress
1245
1300
  };
1246
1301
  return constants$1;
@@ -1857,7 +1912,11 @@ var hasRequiredNetworkDetector;
1857
1912
  function requireNetworkDetector () {
1858
1913
  if (hasRequiredNetworkDetector) return networkDetector;
1859
1914
  hasRequiredNetworkDetector = 1;
1860
- const { NETWORKS } = requireConstants();
1915
+ const {
1916
+ NETWORKS,
1917
+ areAddressNetworksCompatible,
1918
+ resolveAddressNetworkFamily
1919
+ } = requireConstants();
1861
1920
 
1862
1921
  class NetworkDetector {
1863
1922
  /**
@@ -1894,18 +1953,18 @@ function requireNetworkDetector () {
1894
1953
  /**
1895
1954
  * Detect network from address
1896
1955
  * @param {string} address - Neurai address
1897
- * @returns {string} Network name ('xna', 'xna-test', 'xna-pq', or 'xna-pq-test')
1956
+ * @returns {string} Network label ('xna', 'xna-test', 'xna-pq', or 'xna-pq-test')
1898
1957
  */
1899
1958
  static detectFromAddress(address) {
1900
1959
  if (!address || typeof address !== 'string') {
1901
1960
  throw new Error('Address must be a non-empty string');
1902
1961
  }
1903
1962
 
1904
- if (address.startsWith(NETWORKS.MAINNET_PQ.pqAddressPrefix)) {
1963
+ if (address.startsWith(NETWORKS.MAINNET_PQ.authScriptAddressPrefix)) {
1905
1964
  return 'xna-pq';
1906
1965
  }
1907
1966
 
1908
- if (address.startsWith(NETWORKS.TESTNET_PQ.pqAddressPrefix)) {
1967
+ if (address.startsWith(NETWORKS.TESTNET_PQ.authScriptAddressPrefix)) {
1909
1968
  return 'xna-pq-test';
1910
1969
  }
1911
1970
 
@@ -1925,31 +1984,32 @@ function requireNetworkDetector () {
1925
1984
  /**
1926
1985
  * Detect network from multiple addresses
1927
1986
  * @param {string[]} addresses - Array of addresses
1928
- * @returns {string} Network name ('xna', 'xna-test', 'xna-pq', or 'xna-pq-test')
1987
+ * @returns {string} Network label. Mixed legacy/AuthScript addresses on the same
1988
+ * chain are normalized to the chain family label (`xna` or `xna-test`).
1929
1989
  */
1930
1990
  static detectFromAddresses(addresses) {
1931
1991
  if (!Array.isArray(addresses) || addresses.length === 0) {
1932
1992
  throw new Error('Addresses must be a non-empty array');
1933
1993
  }
1934
1994
 
1935
- // Detect from first address
1936
- const network = this.detectFromAddress(addresses[0]);
1995
+ const firstNetwork = this.detectFromAddress(addresses[0]);
1996
+ const family = resolveAddressNetworkFamily(firstNetwork);
1937
1997
 
1938
1998
  // Verify all addresses are from the same network
1939
1999
  for (let i = 1; i < addresses.length; i++) {
1940
2000
  const otherNetwork = this.detectFromAddress(addresses[i]);
1941
- if (otherNetwork !== network) {
1942
- throw new Error(`Mixed network addresses detected: ${network} and ${otherNetwork}`);
2001
+ if (!areAddressNetworksCompatible(firstNetwork, otherNetwork)) {
2002
+ throw new Error(`Mixed network addresses detected: ${firstNetwork} and ${otherNetwork}`);
1943
2003
  }
1944
2004
  }
1945
2005
 
1946
- return network;
2006
+ return family === 'mainnet' ? 'xna' : 'xna-test';
1947
2007
  }
1948
2008
 
1949
2009
  /**
1950
2010
  * Validate that addresses match expected network
1951
2011
  * @param {string[]} addresses - Array of addresses
1952
- * @param {string} expectedNetwork - Expected network ('xna', 'xna-test', 'xna-pq', or 'xna-pq-test')
2012
+ * @param {string} expectedNetwork - Expected network label
1953
2013
  * @returns {boolean} True if all addresses match network
1954
2014
  */
1955
2015
  static validateAddressesNetwork(addresses, expectedNetwork) {
@@ -1959,7 +2019,7 @@ function requireNetworkDetector () {
1959
2019
 
1960
2020
  for (const address of addresses) {
1961
2021
  const network = this.detectFromAddress(address);
1962
- if (network !== expectedNetwork) {
2022
+ if (!areAddressNetworksCompatible(network, expectedNetwork)) {
1963
2023
  throw new Error(
1964
2024
  `Address ${address} is from ${network} but expected ${expectedNetwork}`
1965
2025
  );