@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/README.md +102 -8
- package/dist/NeuraiKey.global.js +86 -5
- package/dist/NeuraiKey.global.js.map +1 -1
- package/dist/browser.js +87 -6
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +89 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +30 -4
- package/dist/index.js +87 -6
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -23717,7 +23717,10 @@ var distExports = requireDist();
|
|
|
23717
23717
|
|
|
23718
23718
|
const AUTHSCRIPT_TAG = "NeuraiAuthScript";
|
|
23719
23719
|
const AUTHSCRIPT_VERSION = 0x01;
|
|
23720
|
+
const NOAUTH_TYPE = 0x00;
|
|
23720
23721
|
const PQ_AUTH_TYPE = 0x01;
|
|
23722
|
+
const LEGACY_AUTH_TYPE = 0x02;
|
|
23723
|
+
const PQ_PUBLIC_KEY_HEADER = Uint8Array.from([0x05]);
|
|
23721
23724
|
const DEFAULT_WITNESS_SCRIPT = Uint8Array.from([0x51]);
|
|
23722
23725
|
function encodeWIF(privateKey, version, compressed = true) {
|
|
23723
23726
|
const payload = compressed
|
|
@@ -23778,27 +23781,51 @@ function bech32mEncode(hrp, witnessVersion, hash) {
|
|
|
23778
23781
|
function normalizeWitnessScript(input) {
|
|
23779
23782
|
return input ? ensureBytes(input) : Uint8Array.from(DEFAULT_WITNESS_SCRIPT);
|
|
23780
23783
|
}
|
|
23784
|
+
function buildAuthDescriptor(authType, publicKey) {
|
|
23785
|
+
if (authType === NOAUTH_TYPE) {
|
|
23786
|
+
return Uint8Array.from([NOAUTH_TYPE]);
|
|
23787
|
+
}
|
|
23788
|
+
if (!publicKey) {
|
|
23789
|
+
throw new Error(`Auth type 0x${authType.toString(16).padStart(2, "0")} requires a public key`);
|
|
23790
|
+
}
|
|
23791
|
+
if (authType === PQ_AUTH_TYPE) {
|
|
23792
|
+
return concatBytes(Uint8Array.from([PQ_AUTH_TYPE]), hash160(concatBytes(PQ_PUBLIC_KEY_HEADER, publicKey)));
|
|
23793
|
+
}
|
|
23794
|
+
if (authType === LEGACY_AUTH_TYPE) {
|
|
23795
|
+
return concatBytes(Uint8Array.from([LEGACY_AUTH_TYPE]), hash160(publicKey));
|
|
23796
|
+
}
|
|
23797
|
+
throw new Error(`Unsupported authType: 0x${String(authType).padStart(2, "0")}`);
|
|
23798
|
+
}
|
|
23781
23799
|
function pqPublicKeyToAuthDescriptor(publicKey) {
|
|
23782
|
-
return
|
|
23800
|
+
return buildAuthDescriptor(PQ_AUTH_TYPE, publicKey);
|
|
23783
23801
|
}
|
|
23784
23802
|
function pqPublicKeyToCommitment(publicKey, options = {}) {
|
|
23785
23803
|
return pqPublicKeyToCommitmentParts(publicKey, options).commitment;
|
|
23786
23804
|
}
|
|
23787
|
-
function
|
|
23805
|
+
function authScriptCommitmentParts(authType, publicKey, options = {}) {
|
|
23788
23806
|
const witnessScript = normalizeWitnessScript(options.witnessScript);
|
|
23789
|
-
const authDescriptor =
|
|
23807
|
+
const authDescriptor = buildAuthDescriptor(authType, publicKey);
|
|
23790
23808
|
const witnessScriptHash = sha256Hash(witnessScript);
|
|
23791
23809
|
const commitment = taggedHash(AUTHSCRIPT_TAG, concatBytes(Uint8Array.from([AUTHSCRIPT_VERSION]), authDescriptor, witnessScriptHash));
|
|
23792
23810
|
return {
|
|
23793
23811
|
authDescriptor,
|
|
23794
|
-
authType
|
|
23812
|
+
authType,
|
|
23795
23813
|
commitment,
|
|
23796
23814
|
witnessScript,
|
|
23797
23815
|
};
|
|
23798
23816
|
}
|
|
23817
|
+
function pqPublicKeyToCommitmentParts(publicKey, options = {}) {
|
|
23818
|
+
return authScriptCommitmentParts(PQ_AUTH_TYPE, publicKey, options);
|
|
23819
|
+
}
|
|
23799
23820
|
function pqPublicKeyToAddressBytes(publicKey, network, options = {}) {
|
|
23800
23821
|
return bech32mEncode(network.hrp, network.witnessVersion, pqPublicKeyToCommitment(publicKey, options));
|
|
23801
23822
|
}
|
|
23823
|
+
function noAuthToAddressBytes(network, options = {}) {
|
|
23824
|
+
return bech32mEncode(network.hrp, network.witnessVersion, authScriptCommitmentParts(NOAUTH_TYPE, null, options).commitment);
|
|
23825
|
+
}
|
|
23826
|
+
function legacyAuthScriptToAddressBytes(publicKey, network, options = {}) {
|
|
23827
|
+
return bech32mEncode(network.hrp, network.witnessVersion, authScriptCommitmentParts(LEGACY_AUTH_TYPE, publicKey, options).commitment);
|
|
23828
|
+
}
|
|
23802
23829
|
function normalizePublicKey(input) {
|
|
23803
23830
|
return ensureBytes(input);
|
|
23804
23831
|
}
|
|
@@ -24068,7 +24095,7 @@ function getPQAddressByPath(network, hdKey, path, options = {}) {
|
|
|
24068
24095
|
const authScript = pqPublicKeyToCommitmentParts(publicKey, options);
|
|
24069
24096
|
return {
|
|
24070
24097
|
address: pqPublicKeyToAddressBytes(publicKey, chain, options),
|
|
24071
|
-
authType:
|
|
24098
|
+
authType: 0x01,
|
|
24072
24099
|
authDescriptor: bytesToHex(authScript.authDescriptor),
|
|
24073
24100
|
commitment: bytesToHex(authScript.commitment),
|
|
24074
24101
|
path,
|
|
@@ -24078,6 +24105,57 @@ function getPQAddressByPath(network, hdKey, path, options = {}) {
|
|
|
24078
24105
|
witnessScript: bytesToHex(authScript.witnessScript),
|
|
24079
24106
|
};
|
|
24080
24107
|
}
|
|
24108
|
+
function getNoAuthAddress(network, options = {}) {
|
|
24109
|
+
const chain = getPQNetwork(network);
|
|
24110
|
+
const parts = authScriptCommitmentParts(0x00, null, options);
|
|
24111
|
+
return {
|
|
24112
|
+
address: noAuthToAddressBytes(chain, options),
|
|
24113
|
+
authType: 0x00,
|
|
24114
|
+
commitment: bytesToHex(parts.commitment),
|
|
24115
|
+
witnessScript: bytesToHex(parts.witnessScript),
|
|
24116
|
+
};
|
|
24117
|
+
}
|
|
24118
|
+
function getLegacyAuthScriptAddress(network, legacyNetwork, mnemonic, account, index, passphrase = "", options = {}) {
|
|
24119
|
+
const pqChain = getPQNetwork(network);
|
|
24120
|
+
const legacyChain = getNetwork(legacyNetwork);
|
|
24121
|
+
const coinType = legacyChain.bip44;
|
|
24122
|
+
const hdKey = getHDKey(legacyNetwork, mnemonic, passphrase);
|
|
24123
|
+
const path = `m/44'/${coinType}'/${account}'/0/${index}`;
|
|
24124
|
+
const derived = hdKey.derive(path);
|
|
24125
|
+
if (!derived.privateKey) {
|
|
24126
|
+
throw new Error("Could not derive private key for path");
|
|
24127
|
+
}
|
|
24128
|
+
const legacyObject = privateKeyToAddressObject(derived.privateKey, legacyChain, path);
|
|
24129
|
+
const publicKeyBytes = ensureBytes(legacyObject.publicKey);
|
|
24130
|
+
const parts = authScriptCommitmentParts(0x02, publicKeyBytes, options);
|
|
24131
|
+
return {
|
|
24132
|
+
address: legacyAuthScriptToAddressBytes(publicKeyBytes, pqChain, options),
|
|
24133
|
+
path,
|
|
24134
|
+
publicKey: legacyObject.publicKey,
|
|
24135
|
+
privateKey: legacyObject.privateKey,
|
|
24136
|
+
WIF: legacyObject.WIF,
|
|
24137
|
+
authType: 0x02,
|
|
24138
|
+
authDescriptor: bytesToHex(parts.authDescriptor),
|
|
24139
|
+
commitment: bytesToHex(parts.commitment),
|
|
24140
|
+
witnessScript: bytesToHex(parts.witnessScript),
|
|
24141
|
+
};
|
|
24142
|
+
}
|
|
24143
|
+
function getLegacyAuthScriptAddressByWIF(network, wif, options = {}) {
|
|
24144
|
+
const pqChain = getPQNetwork(network);
|
|
24145
|
+
const publicKeyHex = publicKeyHexFromWIF(wif);
|
|
24146
|
+
const publicKeyBytes = ensureBytes(publicKeyHex);
|
|
24147
|
+
const parts = authScriptCommitmentParts(0x02, publicKeyBytes, options);
|
|
24148
|
+
return {
|
|
24149
|
+
address: legacyAuthScriptToAddressBytes(publicKeyBytes, pqChain, options),
|
|
24150
|
+
publicKey: publicKeyHex,
|
|
24151
|
+
privateKey: "",
|
|
24152
|
+
WIF: wif,
|
|
24153
|
+
authType: 0x02,
|
|
24154
|
+
authDescriptor: bytesToHex(parts.authDescriptor),
|
|
24155
|
+
commitment: bytesToHex(parts.commitment),
|
|
24156
|
+
witnessScript: bytesToHex(parts.witnessScript),
|
|
24157
|
+
};
|
|
24158
|
+
}
|
|
24081
24159
|
function getPQAddress(network, mnemonic, account, index, passphrase = "", options = {}) {
|
|
24082
24160
|
const chain = getPQNetwork(network);
|
|
24083
24161
|
const hdKey = getPQHDKey(network, mnemonic, passphrase);
|
|
@@ -24130,6 +24208,9 @@ const NeuraiKey = {
|
|
|
24130
24208
|
getPQAddress,
|
|
24131
24209
|
getPQAddressByPath,
|
|
24132
24210
|
getPQHDKey,
|
|
24211
|
+
getNoAuthAddress,
|
|
24212
|
+
getLegacyAuthScriptAddress,
|
|
24213
|
+
getLegacyAuthScriptAddressByWIF,
|
|
24133
24214
|
pqPublicKeyToAddress,
|
|
24134
24215
|
pqPublicKeyToAuthDescriptorHex,
|
|
24135
24216
|
pqPublicKeyToCommitmentHex,
|
|
@@ -24147,6 +24228,9 @@ exports.getAddressByWIF = getAddressByWIF;
|
|
|
24147
24228
|
exports.getAddressPair = getAddressPair;
|
|
24148
24229
|
exports.getCoinType = getCoinType;
|
|
24149
24230
|
exports.getHDKey = getHDKey;
|
|
24231
|
+
exports.getLegacyAuthScriptAddress = getLegacyAuthScriptAddress;
|
|
24232
|
+
exports.getLegacyAuthScriptAddressByWIF = getLegacyAuthScriptAddressByWIF;
|
|
24233
|
+
exports.getNoAuthAddress = getNoAuthAddress;
|
|
24150
24234
|
exports.getPQAddress = getPQAddress;
|
|
24151
24235
|
exports.getPQAddressByPath = getPQAddressByPath;
|
|
24152
24236
|
exports.getPQHDKey = getPQHDKey;
|