@neuraiproject/neurai-key 3.0.2 → 3.1.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/dist/browser.js CHANGED
@@ -23713,7 +23713,10 @@ var distExports = requireDist();
23713
23713
 
23714
23714
  const AUTHSCRIPT_TAG = "NeuraiAuthScript";
23715
23715
  const AUTHSCRIPT_VERSION = 0x01;
23716
+ const NOAUTH_TYPE = 0x00;
23716
23717
  const PQ_AUTH_TYPE = 0x01;
23718
+ const LEGACY_AUTH_TYPE = 0x02;
23719
+ const PQ_PUBLIC_KEY_HEADER = Uint8Array.from([0x05]);
23717
23720
  const DEFAULT_WITNESS_SCRIPT = Uint8Array.from([0x51]);
23718
23721
  function encodeWIF(privateKey, version, compressed = true) {
23719
23722
  const payload = compressed
@@ -23774,27 +23777,51 @@ function bech32mEncode(hrp, witnessVersion, hash) {
23774
23777
  function normalizeWitnessScript(input) {
23775
23778
  return input ? ensureBytes(input) : Uint8Array.from(DEFAULT_WITNESS_SCRIPT);
23776
23779
  }
23780
+ function buildAuthDescriptor(authType, publicKey) {
23781
+ if (authType === NOAUTH_TYPE) {
23782
+ return Uint8Array.from([NOAUTH_TYPE]);
23783
+ }
23784
+ if (!publicKey) {
23785
+ throw new Error(`Auth type 0x${authType.toString(16).padStart(2, "0")} requires a public key`);
23786
+ }
23787
+ if (authType === PQ_AUTH_TYPE) {
23788
+ return concatBytes(Uint8Array.from([PQ_AUTH_TYPE]), hash160(concatBytes(PQ_PUBLIC_KEY_HEADER, publicKey)));
23789
+ }
23790
+ if (authType === LEGACY_AUTH_TYPE) {
23791
+ return concatBytes(Uint8Array.from([LEGACY_AUTH_TYPE]), hash160(publicKey));
23792
+ }
23793
+ throw new Error(`Unsupported authType: 0x${String(authType).padStart(2, "0")}`);
23794
+ }
23777
23795
  function pqPublicKeyToAuthDescriptor(publicKey) {
23778
- return concatBytes(Uint8Array.from([PQ_AUTH_TYPE]), hash160(publicKey));
23796
+ return buildAuthDescriptor(PQ_AUTH_TYPE, publicKey);
23779
23797
  }
23780
23798
  function pqPublicKeyToCommitment(publicKey, options = {}) {
23781
23799
  return pqPublicKeyToCommitmentParts(publicKey, options).commitment;
23782
23800
  }
23783
- function pqPublicKeyToCommitmentParts(publicKey, options = {}) {
23801
+ function authScriptCommitmentParts(authType, publicKey, options = {}) {
23784
23802
  const witnessScript = normalizeWitnessScript(options.witnessScript);
23785
- const authDescriptor = pqPublicKeyToAuthDescriptor(publicKey);
23803
+ const authDescriptor = buildAuthDescriptor(authType, publicKey);
23786
23804
  const witnessScriptHash = sha256Hash(witnessScript);
23787
23805
  const commitment = taggedHash(AUTHSCRIPT_TAG, concatBytes(Uint8Array.from([AUTHSCRIPT_VERSION]), authDescriptor, witnessScriptHash));
23788
23806
  return {
23789
23807
  authDescriptor,
23790
- authType: PQ_AUTH_TYPE,
23808
+ authType,
23791
23809
  commitment,
23792
23810
  witnessScript,
23793
23811
  };
23794
23812
  }
23813
+ function pqPublicKeyToCommitmentParts(publicKey, options = {}) {
23814
+ return authScriptCommitmentParts(PQ_AUTH_TYPE, publicKey, options);
23815
+ }
23795
23816
  function pqPublicKeyToAddressBytes(publicKey, network, options = {}) {
23796
23817
  return bech32mEncode(network.hrp, network.witnessVersion, pqPublicKeyToCommitment(publicKey, options));
23797
23818
  }
23819
+ function noAuthToAddressBytes(network, options = {}) {
23820
+ return bech32mEncode(network.hrp, network.witnessVersion, authScriptCommitmentParts(NOAUTH_TYPE, null, options).commitment);
23821
+ }
23822
+ function legacyAuthScriptToAddressBytes(publicKey, network, options = {}) {
23823
+ return bech32mEncode(network.hrp, network.witnessVersion, authScriptCommitmentParts(LEGACY_AUTH_TYPE, publicKey, options).commitment);
23824
+ }
23798
23825
  function normalizePublicKey(input) {
23799
23826
  return ensureBytes(input);
23800
23827
  }
@@ -24064,7 +24091,7 @@ function getPQAddressByPath(network, hdKey, path, options = {}) {
24064
24091
  const authScript = pqPublicKeyToCommitmentParts(publicKey, options);
24065
24092
  return {
24066
24093
  address: pqPublicKeyToAddressBytes(publicKey, chain, options),
24067
- authType: authScript.authType,
24094
+ authType: 0x01,
24068
24095
  authDescriptor: bytesToHex(authScript.authDescriptor),
24069
24096
  commitment: bytesToHex(authScript.commitment),
24070
24097
  path,
@@ -24074,6 +24101,57 @@ function getPQAddressByPath(network, hdKey, path, options = {}) {
24074
24101
  witnessScript: bytesToHex(authScript.witnessScript),
24075
24102
  };
24076
24103
  }
24104
+ function getNoAuthAddress(network, options = {}) {
24105
+ const chain = getPQNetwork(network);
24106
+ const parts = authScriptCommitmentParts(0x00, null, options);
24107
+ return {
24108
+ address: noAuthToAddressBytes(chain, options),
24109
+ authType: 0x00,
24110
+ commitment: bytesToHex(parts.commitment),
24111
+ witnessScript: bytesToHex(parts.witnessScript),
24112
+ };
24113
+ }
24114
+ function getLegacyAuthScriptAddress(network, legacyNetwork, mnemonic, account, index, passphrase = "", options = {}) {
24115
+ const pqChain = getPQNetwork(network);
24116
+ const legacyChain = getNetwork(legacyNetwork);
24117
+ const coinType = legacyChain.bip44;
24118
+ const hdKey = getHDKey(legacyNetwork, mnemonic, passphrase);
24119
+ const path = `m/44'/${coinType}'/${account}'/0/${index}`;
24120
+ const derived = hdKey.derive(path);
24121
+ if (!derived.privateKey) {
24122
+ throw new Error("Could not derive private key for path");
24123
+ }
24124
+ const legacyObject = privateKeyToAddressObject(derived.privateKey, legacyChain, path);
24125
+ const publicKeyBytes = ensureBytes(legacyObject.publicKey);
24126
+ const parts = authScriptCommitmentParts(0x02, publicKeyBytes, options);
24127
+ return {
24128
+ address: legacyAuthScriptToAddressBytes(publicKeyBytes, pqChain, options),
24129
+ path,
24130
+ publicKey: legacyObject.publicKey,
24131
+ privateKey: legacyObject.privateKey,
24132
+ WIF: legacyObject.WIF,
24133
+ authType: 0x02,
24134
+ authDescriptor: bytesToHex(parts.authDescriptor),
24135
+ commitment: bytesToHex(parts.commitment),
24136
+ witnessScript: bytesToHex(parts.witnessScript),
24137
+ };
24138
+ }
24139
+ function getLegacyAuthScriptAddressByWIF(network, wif, options = {}) {
24140
+ const pqChain = getPQNetwork(network);
24141
+ const publicKeyHex = publicKeyHexFromWIF(wif);
24142
+ const publicKeyBytes = ensureBytes(publicKeyHex);
24143
+ const parts = authScriptCommitmentParts(0x02, publicKeyBytes, options);
24144
+ return {
24145
+ address: legacyAuthScriptToAddressBytes(publicKeyBytes, pqChain, options),
24146
+ publicKey: publicKeyHex,
24147
+ privateKey: "",
24148
+ WIF: wif,
24149
+ authType: 0x02,
24150
+ authDescriptor: bytesToHex(parts.authDescriptor),
24151
+ commitment: bytesToHex(parts.commitment),
24152
+ witnessScript: bytesToHex(parts.witnessScript),
24153
+ };
24154
+ }
24077
24155
  function getPQAddress(network, mnemonic, account, index, passphrase = "", options = {}) {
24078
24156
  const chain = getPQNetwork(network);
24079
24157
  const hdKey = getPQHDKey(network, mnemonic, passphrase);
@@ -24126,11 +24204,14 @@ const NeuraiKey = {
24126
24204
  getPQAddress,
24127
24205
  getPQAddressByPath,
24128
24206
  getPQHDKey,
24207
+ getNoAuthAddress,
24208
+ getLegacyAuthScriptAddress,
24209
+ getLegacyAuthScriptAddressByWIF,
24129
24210
  pqPublicKeyToAddress,
24130
24211
  pqPublicKeyToAuthDescriptorHex,
24131
24212
  pqPublicKeyToCommitmentHex,
24132
24213
  generatePQAddressObject,
24133
24214
  };
24134
24215
 
24135
- export { NeuraiKey as default, entropyToMnemonic, generateAddress, generateAddressObject, generateMnemonic, generatePQAddressObject, getAddressByPath, getAddressByWIF, getAddressPair, getCoinType, getHDKey, getPQAddress, getPQAddressByPath, getPQHDKey, getPubkeyByWIF, isMnemonicValid, pqPublicKeyToAddress, pqPublicKeyToAuthDescriptorHex, pqPublicKeyToCommitmentHex, publicKeyToAddress };
24216
+ export { NeuraiKey as default, entropyToMnemonic, generateAddress, generateAddressObject, generateMnemonic, generatePQAddressObject, getAddressByPath, getAddressByWIF, getAddressPair, getCoinType, getHDKey, getLegacyAuthScriptAddress, getLegacyAuthScriptAddressByWIF, getNoAuthAddress, getPQAddress, getPQAddressByPath, getPQHDKey, getPubkeyByWIF, isMnemonicValid, pqPublicKeyToAddress, pqPublicKeyToAuthDescriptorHex, pqPublicKeyToCommitmentHex, publicKeyToAddress };
24136
24217
  //# sourceMappingURL=browser.js.map