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