@neuraiproject/neurai-key 3.0.0 → 3.0.2
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 +35 -14
- package/dist/NeuraiKey.global.js +66 -14
- package/dist/NeuraiKey.global.js.map +1 -1
- package/dist/browser.js +67 -15
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +68 -14
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +17 -6
- package/dist/index.js +67 -15
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/browser.js
CHANGED
|
@@ -21500,6 +21500,13 @@ function uint32ToBytesBE(value) {
|
|
|
21500
21500
|
function hash160(data) {
|
|
21501
21501
|
return ripemd160(sha256(data));
|
|
21502
21502
|
}
|
|
21503
|
+
function sha256Hash(data) {
|
|
21504
|
+
return sha256(data);
|
|
21505
|
+
}
|
|
21506
|
+
function taggedHash(tag, data) {
|
|
21507
|
+
const tagHash = sha256(utf8ToBytes(tag));
|
|
21508
|
+
return sha256(concatBytes(tagHash, tagHash, data));
|
|
21509
|
+
}
|
|
21503
21510
|
function doubleSha256(data) {
|
|
21504
21511
|
return sha256(sha256(data));
|
|
21505
21512
|
}
|
|
@@ -21540,7 +21547,6 @@ function mnemonicToSeedBytes(mnemonicToSeedSync, mnemonic, passphrase) {
|
|
|
21540
21547
|
return Uint8Array.from(mnemonicToSeedSync(mnemonic, passphrase));
|
|
21541
21548
|
}
|
|
21542
21549
|
const BITCOIN_SEED_KEY = utf8ToBytes("Bitcoin seed");
|
|
21543
|
-
const HASH160_PREFIX = Uint8Array.from([0x05]);
|
|
21544
21550
|
|
|
21545
21551
|
/**
|
|
21546
21552
|
* Utils for modular division and fields.
|
|
@@ -23705,6 +23711,10 @@ function requireDist () {
|
|
|
23705
23711
|
|
|
23706
23712
|
var distExports = requireDist();
|
|
23707
23713
|
|
|
23714
|
+
const AUTHSCRIPT_TAG = "NeuraiAuthScript";
|
|
23715
|
+
const AUTHSCRIPT_VERSION = 0x01;
|
|
23716
|
+
const PQ_AUTH_TYPE = 0x01;
|
|
23717
|
+
const DEFAULT_WITNESS_SCRIPT = Uint8Array.from([0x51]);
|
|
23708
23718
|
function encodeWIF(privateKey, version, compressed = true) {
|
|
23709
23719
|
const payload = compressed
|
|
23710
23720
|
? concatBytes(Uint8Array.from([version]), privateKey, Uint8Array.from([0x01]))
|
|
@@ -23761,9 +23771,29 @@ function publicKeyHexFromWIF(wif, compressed = true) {
|
|
|
23761
23771
|
function bech32mEncode(hrp, witnessVersion, hash) {
|
|
23762
23772
|
return distExports.bech32m.encode(hrp, [witnessVersion, ...distExports.bech32m.toWords(hash)]);
|
|
23763
23773
|
}
|
|
23764
|
-
function
|
|
23765
|
-
|
|
23766
|
-
|
|
23774
|
+
function normalizeWitnessScript(input) {
|
|
23775
|
+
return input ? ensureBytes(input) : Uint8Array.from(DEFAULT_WITNESS_SCRIPT);
|
|
23776
|
+
}
|
|
23777
|
+
function pqPublicKeyToAuthDescriptor(publicKey) {
|
|
23778
|
+
return concatBytes(Uint8Array.from([PQ_AUTH_TYPE]), hash160(publicKey));
|
|
23779
|
+
}
|
|
23780
|
+
function pqPublicKeyToCommitment(publicKey, options = {}) {
|
|
23781
|
+
return pqPublicKeyToCommitmentParts(publicKey, options).commitment;
|
|
23782
|
+
}
|
|
23783
|
+
function pqPublicKeyToCommitmentParts(publicKey, options = {}) {
|
|
23784
|
+
const witnessScript = normalizeWitnessScript(options.witnessScript);
|
|
23785
|
+
const authDescriptor = pqPublicKeyToAuthDescriptor(publicKey);
|
|
23786
|
+
const witnessScriptHash = sha256Hash(witnessScript);
|
|
23787
|
+
const commitment = taggedHash(AUTHSCRIPT_TAG, concatBytes(Uint8Array.from([AUTHSCRIPT_VERSION]), authDescriptor, witnessScriptHash));
|
|
23788
|
+
return {
|
|
23789
|
+
authDescriptor,
|
|
23790
|
+
authType: PQ_AUTH_TYPE,
|
|
23791
|
+
commitment,
|
|
23792
|
+
witnessScript,
|
|
23793
|
+
};
|
|
23794
|
+
}
|
|
23795
|
+
function pqPublicKeyToAddressBytes(publicKey, network, options = {}) {
|
|
23796
|
+
return bech32mEncode(network.hrp, network.witnessVersion, pqPublicKeyToCommitment(publicKey, options));
|
|
23767
23797
|
}
|
|
23768
23798
|
function normalizePublicKey(input) {
|
|
23769
23799
|
return ensureBytes(input);
|
|
@@ -23925,8 +23955,8 @@ const pqNetworks = {
|
|
|
23925
23955
|
hrp: "tnq",
|
|
23926
23956
|
witnessVersion: 1,
|
|
23927
23957
|
purpose: 100,
|
|
23928
|
-
coinType:
|
|
23929
|
-
changeIndex:
|
|
23958
|
+
coinType: 1,
|
|
23959
|
+
changeIndex: 0,
|
|
23930
23960
|
bip32: { private: 70615956, public: 70617039 },
|
|
23931
23961
|
},
|
|
23932
23962
|
};
|
|
@@ -24023,7 +24053,7 @@ function getPQHDKey(network, mnemonic, passphrase = "") {
|
|
|
24023
24053
|
const seed = mnemonicToSeedBytes(mnemonicToSeedSync, mnemonic, passphrase);
|
|
24024
24054
|
return HDKey.fromMasterSeed(seed, chain.bip32);
|
|
24025
24055
|
}
|
|
24026
|
-
function getPQAddressByPath(network, hdKey, path) {
|
|
24056
|
+
function getPQAddressByPath(network, hdKey, path, options = {}) {
|
|
24027
24057
|
const chain = getPQNetwork(network);
|
|
24028
24058
|
const derived = hdKey.derive(path);
|
|
24029
24059
|
if (!derived.privateKey) {
|
|
@@ -24031,30 +24061,50 @@ function getPQAddressByPath(network, hdKey, path) {
|
|
|
24031
24061
|
}
|
|
24032
24062
|
const seed32 = Uint8Array.from(derived.privateKey);
|
|
24033
24063
|
const { publicKey, secretKey } = ml_dsa44.keygen(seed32);
|
|
24064
|
+
const authScript = pqPublicKeyToCommitmentParts(publicKey, options);
|
|
24034
24065
|
return {
|
|
24035
|
-
address: pqPublicKeyToAddressBytes(publicKey, chain),
|
|
24066
|
+
address: pqPublicKeyToAddressBytes(publicKey, chain, options),
|
|
24067
|
+
authType: authScript.authType,
|
|
24068
|
+
authDescriptor: bytesToHex(authScript.authDescriptor),
|
|
24069
|
+
commitment: bytesToHex(authScript.commitment),
|
|
24036
24070
|
path,
|
|
24037
24071
|
publicKey: bytesToHex(publicKey),
|
|
24038
24072
|
privateKey: bytesToHex(secretKey),
|
|
24039
24073
|
seedKey: bytesToHex(seed32),
|
|
24074
|
+
witnessScript: bytesToHex(authScript.witnessScript),
|
|
24040
24075
|
};
|
|
24041
24076
|
}
|
|
24042
|
-
function getPQAddress(network, mnemonic, account, index, passphrase = "") {
|
|
24077
|
+
function getPQAddress(network, mnemonic, account, index, passphrase = "", options = {}) {
|
|
24043
24078
|
const chain = getPQNetwork(network);
|
|
24044
24079
|
const hdKey = getPQHDKey(network, mnemonic, passphrase);
|
|
24045
24080
|
const path = `m/${chain.purpose}'/${chain.coinType}'/${account}'/${chain.changeIndex}/${index}`;
|
|
24046
|
-
return getPQAddressByPath(network, hdKey, path);
|
|
24081
|
+
return getPQAddressByPath(network, hdKey, path, options);
|
|
24082
|
+
}
|
|
24083
|
+
function pqPublicKeyToAddress(network, publicKey, options = {}) {
|
|
24084
|
+
const keyBytes = ensureBytes(publicKey);
|
|
24085
|
+
if (keyBytes.length !== 1312) {
|
|
24086
|
+
throw new Error("ML-DSA-44 public key must be 1312 bytes");
|
|
24087
|
+
}
|
|
24088
|
+
normalizeWitnessScript(options.witnessScript);
|
|
24089
|
+
return pqPublicKeyToAddressBytes(keyBytes, getPQNetwork(network), options);
|
|
24090
|
+
}
|
|
24091
|
+
function pqPublicKeyToCommitmentHex(publicKey, options = {}) {
|
|
24092
|
+
const keyBytes = ensureBytes(publicKey);
|
|
24093
|
+
if (keyBytes.length !== 1312) {
|
|
24094
|
+
throw new Error("ML-DSA-44 public key must be 1312 bytes");
|
|
24095
|
+
}
|
|
24096
|
+
return bytesToHex(pqPublicKeyToCommitment(keyBytes, options));
|
|
24047
24097
|
}
|
|
24048
|
-
function
|
|
24098
|
+
function pqPublicKeyToAuthDescriptorHex(publicKey) {
|
|
24049
24099
|
const keyBytes = ensureBytes(publicKey);
|
|
24050
24100
|
if (keyBytes.length !== 1312) {
|
|
24051
24101
|
throw new Error("ML-DSA-44 public key must be 1312 bytes");
|
|
24052
24102
|
}
|
|
24053
|
-
return
|
|
24103
|
+
return bytesToHex(pqPublicKeyToAuthDescriptor(keyBytes));
|
|
24054
24104
|
}
|
|
24055
|
-
function generatePQAddressObject(network = "xna-pq", passphrase = "") {
|
|
24105
|
+
function generatePQAddressObject(network = "xna-pq", passphrase = "", options = {}) {
|
|
24056
24106
|
const mnemonic = generateMnemonic();
|
|
24057
|
-
const addressObj = getPQAddress(network, mnemonic, 0, 0, passphrase);
|
|
24107
|
+
const addressObj = getPQAddress(network, mnemonic, 0, 0, passphrase, options);
|
|
24058
24108
|
return {
|
|
24059
24109
|
...addressObj,
|
|
24060
24110
|
mnemonic,
|
|
@@ -24077,8 +24127,10 @@ const NeuraiKey = {
|
|
|
24077
24127
|
getPQAddressByPath,
|
|
24078
24128
|
getPQHDKey,
|
|
24079
24129
|
pqPublicKeyToAddress,
|
|
24130
|
+
pqPublicKeyToAuthDescriptorHex,
|
|
24131
|
+
pqPublicKeyToCommitmentHex,
|
|
24080
24132
|
generatePQAddressObject,
|
|
24081
24133
|
};
|
|
24082
24134
|
|
|
24083
|
-
export { NeuraiKey as default, entropyToMnemonic, generateAddress, generateAddressObject, generateMnemonic, generatePQAddressObject, getAddressByPath, getAddressByWIF, getAddressPair, getCoinType, getHDKey, getPQAddress, getPQAddressByPath, getPQHDKey, getPubkeyByWIF, isMnemonicValid, pqPublicKeyToAddress, publicKeyToAddress };
|
|
24135
|
+
export { NeuraiKey as default, entropyToMnemonic, generateAddress, generateAddressObject, generateMnemonic, generatePQAddressObject, getAddressByPath, getAddressByWIF, getAddressPair, getCoinType, getHDKey, getPQAddress, getPQAddressByPath, getPQHDKey, getPubkeyByWIF, isMnemonicValid, pqPublicKeyToAddress, pqPublicKeyToAuthDescriptorHex, pqPublicKeyToCommitmentHex, publicKeyToAddress };
|
|
24084
24136
|
//# sourceMappingURL=browser.js.map
|