@neuraiproject/neurai-key 3.0.1 → 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 +126 -13
- package/dist/NeuraiKey.global.js +145 -12
- package/dist/NeuraiKey.global.js.map +1 -1
- package/dist/browser.js +146 -13
- package/dist/browser.js.map +1 -1
- package/dist/index.cjs +150 -12
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +43 -6
- package/dist/index.js +146 -13
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -5,7 +5,7 @@ Generate Neurai addresses from a mnemonic phrase following the standards BIP32,
|
|
|
5
5
|
That is, use your 12 words to get addresses for Neurai mainnet and testnet.
|
|
6
6
|
|
|
7
7
|
**NPM**: https://www.npmjs.com/package/@neuraiproject/neurai-key
|
|
8
|
-
**CDN**: https://cdn.jsdelivr.net/npm/@neuraiproject/neurai-key@3.
|
|
8
|
+
**CDN**: https://cdn.jsdelivr.net/npm/@neuraiproject/neurai-key@3.1.0/dist/NeuraiKey.global.js
|
|
9
9
|
|
|
10
10
|
## Features
|
|
11
11
|
|
|
@@ -16,7 +16,16 @@ That is, use your 12 words to get addresses for Neurai mainnet and testnet.
|
|
|
16
16
|
- ✅ Mainnet and Testnet support for Neurai (XNA)
|
|
17
17
|
- ✅ Support for both XNA (BIP44: 1900) and XNA Legacy (BIP44: 0) networks
|
|
18
18
|
- ✅ Convert raw public keys into Neurai mainnet or testnet addresses
|
|
19
|
-
- ✅
|
|
19
|
+
- ✅ AuthScript witness v1 addresses with Bech32m encoding
|
|
20
|
+
- ✅ `authType = 0x00` NoAuth addresses from `witnessScript` only
|
|
21
|
+
- ✅ `authType = 0x01` PostQuantum ML-DSA-44 AuthScript addresses
|
|
22
|
+
- ✅ `authType = 0x02` Legacy secp256k1 AuthScript addresses
|
|
23
|
+
|
|
24
|
+
## Compatibility Note
|
|
25
|
+
|
|
26
|
+
Starting in `3.1.0`, PQ AuthScript descriptors are computed as `0x01 || HASH160(0x05 || rawPublicKey)` to match `neurai-sign-transaction` and the node implementation.
|
|
27
|
+
|
|
28
|
+
This changes PQ AuthScript addresses and commitments compared to older releases of this library. If you previously generated PQ addresses with an older version of `neurai-key`, treat them as legacy outputs and verify fund exposure before migrating.
|
|
20
29
|
|
|
21
30
|
## Network Types
|
|
22
31
|
|
|
@@ -24,7 +33,7 @@ This library supports three Neurai network configurations:
|
|
|
24
33
|
|
|
25
34
|
- **`xna` / `xna-test`**: Current Neurai standard (BIP44 coin type: 1900)
|
|
26
35
|
- **`xna-legacy` / `xna-legacy-test`**: Legacy Neurai addresses (BIP44 coin type: 0)
|
|
27
|
-
- **`xna-pq` / `xna-pq-test`**:
|
|
36
|
+
- **`xna-pq` / `xna-pq-test`**: AuthScript witness v1 addresses (Bech32m, `nq1` / `tnq1`)
|
|
28
37
|
|
|
29
38
|
The main difference is the derivation path and address encoding:
|
|
30
39
|
- **XNA**: mainnet `m/44'/1900'/0'/0/0`, testnet `m/44'/1'/0'/0/0` — Base58Check (recommended for new wallets)
|
|
@@ -181,9 +190,17 @@ console.log(testAddress); // tPXGaMRNwZuV1UKSrD9gABPscrJWUmedQ9
|
|
|
181
190
|
|
|
182
191
|
`publicKeyToAddress` throws if the key length is not 33 or 65 bytes so invalid inputs are surfaced immediately.
|
|
183
192
|
|
|
184
|
-
## PostQuantum (ML-DSA-44) Addresses
|
|
193
|
+
## PostQuantum (ML-DSA-44) AuthScript Addresses
|
|
194
|
+
|
|
195
|
+
Generate quantum-resistant AuthScript addresses using the ML-DSA-44 signature scheme (FIPS 204). The library now follows the migrated `witness v1 = AuthScript` layout, so the Bech32m program is a 32-byte commitment instead of the old 20-byte PQ keyhash.
|
|
185
196
|
|
|
186
|
-
|
|
197
|
+
Supported AuthScript variants:
|
|
198
|
+
|
|
199
|
+
| `authType` | Name | Description |
|
|
200
|
+
|------------|------|-------------|
|
|
201
|
+
| `0x00` | NoAuth | No signature. Spend path depends only on `witnessScript` |
|
|
202
|
+
| `0x01` | PQ | ML-DSA-44 post-quantum signature |
|
|
203
|
+
| `0x02` | Legacy | secp256k1 signature inside the AuthScript framework |
|
|
187
204
|
|
|
188
205
|
### Generate a PQ address
|
|
189
206
|
|
|
@@ -205,11 +222,15 @@ Outputs
|
|
|
205
222
|
|
|
206
223
|
```
|
|
207
224
|
{
|
|
208
|
-
address: 'nq1...', // Bech32m address
|
|
225
|
+
address: 'nq1...', // Bech32m AuthScript address
|
|
226
|
+
authType: 1, // 0x01 = PQ single-key auth
|
|
227
|
+
authDescriptor: '01...', // 0x01 || HASH160(0x05 || pq_pubkey)
|
|
228
|
+
commitment: '...', // tagged_hash("NeuraiAuthScript", ...)
|
|
209
229
|
path: "m/100'/1900'/0'/0/0", // PQ derivation path
|
|
210
230
|
publicKey: '...', // ML-DSA-44 public key (2624 hex chars = 1312 bytes)
|
|
211
231
|
privateKey: '...', // ML-DSA-44 private key (5120 hex chars = 2560 bytes)
|
|
212
|
-
seedKey: '...'
|
|
232
|
+
seedKey: '...', // 32-byte BIP32 seed used for ML-DSA keygen (64 hex chars)
|
|
233
|
+
witnessScript: '51' // default OP_TRUE script for simple PQ auth
|
|
213
234
|
}
|
|
214
235
|
```
|
|
215
236
|
|
|
@@ -229,6 +250,96 @@ const reconstructed = NeuraiKey.pqPublicKeyToAddress("xna-pq", pqAddress.publicK
|
|
|
229
250
|
// reconstructed === pqAddress.address
|
|
230
251
|
```
|
|
231
252
|
|
|
253
|
+
### Custom AuthScript witnessScript
|
|
254
|
+
|
|
255
|
+
```javascript
|
|
256
|
+
const pqAddress = NeuraiKey.getPQAddress("xna-pq", mnemonic, 0, 0, "", {
|
|
257
|
+
witnessScript: "5151"
|
|
258
|
+
});
|
|
259
|
+
|
|
260
|
+
console.log(pqAddress.witnessScript); // 5151
|
|
261
|
+
console.log(pqAddress.commitment); // new 32-byte commitment
|
|
262
|
+
```
|
|
263
|
+
|
|
264
|
+
`getPQAddress()` always generates `authType = 0x01` PQ addresses. Use `getNoAuthAddress()` for `0x00` and `getLegacyAuthScriptAddress()` / `getLegacyAuthScriptAddressByWIF()` for `0x02`.
|
|
265
|
+
|
|
266
|
+
### Generate a NoAuth address
|
|
267
|
+
|
|
268
|
+
```javascript
|
|
269
|
+
import NeuraiKey from "@neuraiproject/neurai-key";
|
|
270
|
+
|
|
271
|
+
const noAuth = NeuraiKey.getNoAuthAddress("xna-pq-test");
|
|
272
|
+
|
|
273
|
+
console.log(noAuth);
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
Outputs
|
|
277
|
+
|
|
278
|
+
```javascript
|
|
279
|
+
{
|
|
280
|
+
address: "tnq1...",
|
|
281
|
+
authType: 0,
|
|
282
|
+
commitment: "...",
|
|
283
|
+
witnessScript: "51"
|
|
284
|
+
}
|
|
285
|
+
```
|
|
286
|
+
|
|
287
|
+
You can provide a custom `witnessScript`:
|
|
288
|
+
|
|
289
|
+
```javascript
|
|
290
|
+
const noAuth = NeuraiKey.getNoAuthAddress("xna-pq-test", {
|
|
291
|
+
witnessScript: "527551"
|
|
292
|
+
});
|
|
293
|
+
```
|
|
294
|
+
|
|
295
|
+
### Generate a Legacy AuthScript address from mnemonic
|
|
296
|
+
|
|
297
|
+
This derives a normal secp256k1 key using the selected legacy/current HD network, then wraps it as an AuthScript address using the PQ Bech32m network.
|
|
298
|
+
|
|
299
|
+
```javascript
|
|
300
|
+
import NeuraiKey from "@neuraiproject/neurai-key";
|
|
301
|
+
|
|
302
|
+
const mnemonic = "result pact model attract result puzzle final boss private educate luggage era";
|
|
303
|
+
|
|
304
|
+
const legacyAuth = NeuraiKey.getLegacyAuthScriptAddress(
|
|
305
|
+
"xna-pq-test",
|
|
306
|
+
"xna-test",
|
|
307
|
+
mnemonic,
|
|
308
|
+
0,
|
|
309
|
+
0
|
|
310
|
+
);
|
|
311
|
+
|
|
312
|
+
console.log(legacyAuth);
|
|
313
|
+
```
|
|
314
|
+
|
|
315
|
+
Outputs
|
|
316
|
+
|
|
317
|
+
```javascript
|
|
318
|
+
{
|
|
319
|
+
address: "tnq1...",
|
|
320
|
+
path: "m/44'/1'/0'/0/0",
|
|
321
|
+
publicKey: "...", // compressed secp256k1 pubkey
|
|
322
|
+
privateKey: "...",
|
|
323
|
+
WIF: "...",
|
|
324
|
+
authType: 2,
|
|
325
|
+
authDescriptor: "02...",
|
|
326
|
+
commitment: "...",
|
|
327
|
+
witnessScript: "51"
|
|
328
|
+
}
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
### Generate a Legacy AuthScript address from WIF
|
|
332
|
+
|
|
333
|
+
```javascript
|
|
334
|
+
import NeuraiKey from "@neuraiproject/neurai-key";
|
|
335
|
+
|
|
336
|
+
const wif = "cVP9mzcDqMzWDhekiKMWKqEy739Cp6rKDT4tbG4wXXVfopMfTiBW";
|
|
337
|
+
const legacyAuth = NeuraiKey.getLegacyAuthScriptAddressByWIF("xna-pq-test", wif);
|
|
338
|
+
|
|
339
|
+
console.log(legacyAuth.address);
|
|
340
|
+
console.log(legacyAuth.publicKey);
|
|
341
|
+
```
|
|
342
|
+
|
|
232
343
|
### Advanced: derive by path with HD key reuse
|
|
233
344
|
|
|
234
345
|
```javascript
|
|
@@ -237,20 +348,22 @@ const addr0 = NeuraiKey.getPQAddressByPath("xna-pq", hdKey, "m/100'/1900'/0'/0/0
|
|
|
237
348
|
const addr1 = NeuraiKey.getPQAddressByPath("xna-pq", hdKey, "m/100'/1900'/0'/0/1");
|
|
238
349
|
```
|
|
239
350
|
|
|
240
|
-
### PQ
|
|
351
|
+
### PQ AuthScript Details
|
|
241
352
|
|
|
242
353
|
| Property | Value |
|
|
243
354
|
|----------|-------|
|
|
244
355
|
| Signature algorithm | ML-DSA-44 (FIPS 204) |
|
|
245
|
-
| Address encoding | Bech32m (witness
|
|
356
|
+
| Address encoding | Bech32m (`witness v1` AuthScript) |
|
|
246
357
|
| Mainnet HRP / prefix | `nq` / `nq1...` |
|
|
247
358
|
| Testnet HRP / prefix | `tnq` / `tnq1...` |
|
|
248
359
|
| Public key size | 1312 bytes |
|
|
249
360
|
| Derivation path (mainnet) | `m/100'/1900'/0'/0/index` |
|
|
250
361
|
| Derivation path (testnet default/external) | `m/100'/1'/account'/0/index` |
|
|
251
|
-
|
|
|
362
|
+
| Auth descriptor | `0x01 \|\| HASH160(0x05 \|\| pq_pubkey)` |
|
|
363
|
+
| Commitment | `tagged_hash("NeuraiAuthScript", 0x01 \|\| auth_descriptor \|\| SHA256(witnessScript))` |
|
|
364
|
+
| Default witnessScript | `OP_TRUE` (`51` in hex) |
|
|
252
365
|
|
|
253
|
-
**Note**: PQ addresses do not have a WIF (Wallet Import Format) field since WIF is specific to secp256k1 keys. The `seedKey` field contains the 32-byte BIP32-derived seed used for deterministic ML-DSA-44 key generation, useful for cross-implementation verification.
|
|
366
|
+
**Note**: PQ AuthScript addresses do not have a WIF (Wallet Import Format) field since WIF is specific to secp256k1 keys. The `seedKey` field contains the 32-byte BIP32-derived seed used for deterministic ML-DSA-44 key generation, useful for cross-implementation verification.
|
|
254
367
|
|
|
255
368
|
## Get public key from WIF
|
|
256
369
|
|
|
@@ -299,7 +412,7 @@ const NeuraiKey = require("@neuraiproject/neurai-key");
|
|
|
299
412
|
</html>
|
|
300
413
|
```
|
|
301
414
|
|
|
302
|
-
## Package layout in `3.
|
|
415
|
+
## Package layout in `3.1.0`
|
|
303
416
|
|
|
304
417
|
- `dist/index.js`: ESM main entry
|
|
305
418
|
- `dist/index.cjs`: CommonJS entry
|
|
@@ -319,7 +432,7 @@ const NeuraiKey = require("@neuraiproject/neurai-key");
|
|
|
319
432
|
|
|
320
433
|
`npm test`
|
|
321
434
|
|
|
322
|
-
The test script already builds the package before running
|
|
435
|
+
The test script already builds the package before running Vitest.
|
|
323
436
|
|
|
324
437
|
## BIP32
|
|
325
438
|
|
package/dist/NeuraiKey.global.js
CHANGED
|
@@ -21503,6 +21503,13 @@ zurdo`.split('\n');
|
|
|
21503
21503
|
function hash160(data) {
|
|
21504
21504
|
return ripemd160(sha256(data));
|
|
21505
21505
|
}
|
|
21506
|
+
function sha256Hash(data) {
|
|
21507
|
+
return sha256(data);
|
|
21508
|
+
}
|
|
21509
|
+
function taggedHash(tag, data) {
|
|
21510
|
+
const tagHash = sha256(utf8ToBytes(tag));
|
|
21511
|
+
return sha256(concatBytes(tagHash, tagHash, data));
|
|
21512
|
+
}
|
|
21506
21513
|
function doubleSha256(data) {
|
|
21507
21514
|
return sha256(sha256(data));
|
|
21508
21515
|
}
|
|
@@ -21543,7 +21550,6 @@ zurdo`.split('\n');
|
|
|
21543
21550
|
return Uint8Array.from(mnemonicToSeedSync(mnemonic, passphrase));
|
|
21544
21551
|
}
|
|
21545
21552
|
const BITCOIN_SEED_KEY = utf8ToBytes("Bitcoin seed");
|
|
21546
|
-
const HASH160_PREFIX = Uint8Array.from([0x05]);
|
|
21547
21553
|
|
|
21548
21554
|
/**
|
|
21549
21555
|
* Utils for modular division and fields.
|
|
@@ -23708,6 +23714,13 @@ zurdo`.split('\n');
|
|
|
23708
23714
|
|
|
23709
23715
|
var distExports = requireDist();
|
|
23710
23716
|
|
|
23717
|
+
const AUTHSCRIPT_TAG = "NeuraiAuthScript";
|
|
23718
|
+
const AUTHSCRIPT_VERSION = 0x01;
|
|
23719
|
+
const NOAUTH_TYPE = 0x00;
|
|
23720
|
+
const PQ_AUTH_TYPE = 0x01;
|
|
23721
|
+
const LEGACY_AUTH_TYPE = 0x02;
|
|
23722
|
+
const PQ_PUBLIC_KEY_HEADER = Uint8Array.from([0x05]);
|
|
23723
|
+
const DEFAULT_WITNESS_SCRIPT = Uint8Array.from([0x51]);
|
|
23711
23724
|
function encodeWIF(privateKey, version, compressed = true) {
|
|
23712
23725
|
const payload = compressed
|
|
23713
23726
|
? concatBytes(Uint8Array.from([version]), privateKey, Uint8Array.from([0x01]))
|
|
@@ -23764,9 +23777,53 @@ zurdo`.split('\n');
|
|
|
23764
23777
|
function bech32mEncode(hrp, witnessVersion, hash) {
|
|
23765
23778
|
return distExports.bech32m.encode(hrp, [witnessVersion, ...distExports.bech32m.toWords(hash)]);
|
|
23766
23779
|
}
|
|
23767
|
-
function
|
|
23768
|
-
|
|
23769
|
-
|
|
23780
|
+
function normalizeWitnessScript(input) {
|
|
23781
|
+
return input ? ensureBytes(input) : Uint8Array.from(DEFAULT_WITNESS_SCRIPT);
|
|
23782
|
+
}
|
|
23783
|
+
function buildAuthDescriptor(authType, publicKey) {
|
|
23784
|
+
if (authType === NOAUTH_TYPE) {
|
|
23785
|
+
return Uint8Array.from([NOAUTH_TYPE]);
|
|
23786
|
+
}
|
|
23787
|
+
if (!publicKey) {
|
|
23788
|
+
throw new Error(`Auth type 0x${authType.toString(16).padStart(2, "0")} requires a public key`);
|
|
23789
|
+
}
|
|
23790
|
+
if (authType === PQ_AUTH_TYPE) {
|
|
23791
|
+
return concatBytes(Uint8Array.from([PQ_AUTH_TYPE]), hash160(concatBytes(PQ_PUBLIC_KEY_HEADER, publicKey)));
|
|
23792
|
+
}
|
|
23793
|
+
if (authType === LEGACY_AUTH_TYPE) {
|
|
23794
|
+
return concatBytes(Uint8Array.from([LEGACY_AUTH_TYPE]), hash160(publicKey));
|
|
23795
|
+
}
|
|
23796
|
+
throw new Error(`Unsupported authType: 0x${String(authType).padStart(2, "0")}`);
|
|
23797
|
+
}
|
|
23798
|
+
function pqPublicKeyToAuthDescriptor(publicKey) {
|
|
23799
|
+
return buildAuthDescriptor(PQ_AUTH_TYPE, publicKey);
|
|
23800
|
+
}
|
|
23801
|
+
function pqPublicKeyToCommitment(publicKey, options = {}) {
|
|
23802
|
+
return pqPublicKeyToCommitmentParts(publicKey, options).commitment;
|
|
23803
|
+
}
|
|
23804
|
+
function authScriptCommitmentParts(authType, publicKey, options = {}) {
|
|
23805
|
+
const witnessScript = normalizeWitnessScript(options.witnessScript);
|
|
23806
|
+
const authDescriptor = buildAuthDescriptor(authType, publicKey);
|
|
23807
|
+
const witnessScriptHash = sha256Hash(witnessScript);
|
|
23808
|
+
const commitment = taggedHash(AUTHSCRIPT_TAG, concatBytes(Uint8Array.from([AUTHSCRIPT_VERSION]), authDescriptor, witnessScriptHash));
|
|
23809
|
+
return {
|
|
23810
|
+
authDescriptor,
|
|
23811
|
+
authType,
|
|
23812
|
+
commitment,
|
|
23813
|
+
witnessScript,
|
|
23814
|
+
};
|
|
23815
|
+
}
|
|
23816
|
+
function pqPublicKeyToCommitmentParts(publicKey, options = {}) {
|
|
23817
|
+
return authScriptCommitmentParts(PQ_AUTH_TYPE, publicKey, options);
|
|
23818
|
+
}
|
|
23819
|
+
function pqPublicKeyToAddressBytes(publicKey, network, options = {}) {
|
|
23820
|
+
return bech32mEncode(network.hrp, network.witnessVersion, pqPublicKeyToCommitment(publicKey, options));
|
|
23821
|
+
}
|
|
23822
|
+
function noAuthToAddressBytes(network, options = {}) {
|
|
23823
|
+
return bech32mEncode(network.hrp, network.witnessVersion, authScriptCommitmentParts(NOAUTH_TYPE, null, options).commitment);
|
|
23824
|
+
}
|
|
23825
|
+
function legacyAuthScriptToAddressBytes(publicKey, network, options = {}) {
|
|
23826
|
+
return bech32mEncode(network.hrp, network.witnessVersion, authScriptCommitmentParts(LEGACY_AUTH_TYPE, publicKey, options).commitment);
|
|
23770
23827
|
}
|
|
23771
23828
|
function normalizePublicKey(input) {
|
|
23772
23829
|
return ensureBytes(input);
|
|
@@ -24026,7 +24083,7 @@ zurdo`.split('\n');
|
|
|
24026
24083
|
const seed = mnemonicToSeedBytes(mnemonicToSeedSync, mnemonic, passphrase);
|
|
24027
24084
|
return HDKey.fromMasterSeed(seed, chain.bip32);
|
|
24028
24085
|
}
|
|
24029
|
-
function getPQAddressByPath(network, hdKey, path) {
|
|
24086
|
+
function getPQAddressByPath(network, hdKey, path, options = {}) {
|
|
24030
24087
|
const chain = getPQNetwork(network);
|
|
24031
24088
|
const derived = hdKey.derive(path);
|
|
24032
24089
|
if (!derived.privateKey) {
|
|
@@ -24034,30 +24091,101 @@ zurdo`.split('\n');
|
|
|
24034
24091
|
}
|
|
24035
24092
|
const seed32 = Uint8Array.from(derived.privateKey);
|
|
24036
24093
|
const { publicKey, secretKey } = ml_dsa44.keygen(seed32);
|
|
24094
|
+
const authScript = pqPublicKeyToCommitmentParts(publicKey, options);
|
|
24037
24095
|
return {
|
|
24038
|
-
address: pqPublicKeyToAddressBytes(publicKey, chain),
|
|
24096
|
+
address: pqPublicKeyToAddressBytes(publicKey, chain, options),
|
|
24097
|
+
authType: 0x01,
|
|
24098
|
+
authDescriptor: bytesToHex(authScript.authDescriptor),
|
|
24099
|
+
commitment: bytesToHex(authScript.commitment),
|
|
24039
24100
|
path,
|
|
24040
24101
|
publicKey: bytesToHex(publicKey),
|
|
24041
24102
|
privateKey: bytesToHex(secretKey),
|
|
24042
24103
|
seedKey: bytesToHex(seed32),
|
|
24104
|
+
witnessScript: bytesToHex(authScript.witnessScript),
|
|
24043
24105
|
};
|
|
24044
24106
|
}
|
|
24045
|
-
function
|
|
24107
|
+
function getNoAuthAddress(network, options = {}) {
|
|
24108
|
+
const chain = getPQNetwork(network);
|
|
24109
|
+
const parts = authScriptCommitmentParts(0x00, null, options);
|
|
24110
|
+
return {
|
|
24111
|
+
address: noAuthToAddressBytes(chain, options),
|
|
24112
|
+
authType: 0x00,
|
|
24113
|
+
commitment: bytesToHex(parts.commitment),
|
|
24114
|
+
witnessScript: bytesToHex(parts.witnessScript),
|
|
24115
|
+
};
|
|
24116
|
+
}
|
|
24117
|
+
function getLegacyAuthScriptAddress(network, legacyNetwork, mnemonic, account, index, passphrase = "", options = {}) {
|
|
24118
|
+
const pqChain = getPQNetwork(network);
|
|
24119
|
+
const legacyChain = getNetwork(legacyNetwork);
|
|
24120
|
+
const coinType = legacyChain.bip44;
|
|
24121
|
+
const hdKey = getHDKey(legacyNetwork, mnemonic, passphrase);
|
|
24122
|
+
const path = `m/44'/${coinType}'/${account}'/0/${index}`;
|
|
24123
|
+
const derived = hdKey.derive(path);
|
|
24124
|
+
if (!derived.privateKey) {
|
|
24125
|
+
throw new Error("Could not derive private key for path");
|
|
24126
|
+
}
|
|
24127
|
+
const legacyObject = privateKeyToAddressObject(derived.privateKey, legacyChain, path);
|
|
24128
|
+
const publicKeyBytes = ensureBytes(legacyObject.publicKey);
|
|
24129
|
+
const parts = authScriptCommitmentParts(0x02, publicKeyBytes, options);
|
|
24130
|
+
return {
|
|
24131
|
+
address: legacyAuthScriptToAddressBytes(publicKeyBytes, pqChain, options),
|
|
24132
|
+
path,
|
|
24133
|
+
publicKey: legacyObject.publicKey,
|
|
24134
|
+
privateKey: legacyObject.privateKey,
|
|
24135
|
+
WIF: legacyObject.WIF,
|
|
24136
|
+
authType: 0x02,
|
|
24137
|
+
authDescriptor: bytesToHex(parts.authDescriptor),
|
|
24138
|
+
commitment: bytesToHex(parts.commitment),
|
|
24139
|
+
witnessScript: bytesToHex(parts.witnessScript),
|
|
24140
|
+
};
|
|
24141
|
+
}
|
|
24142
|
+
function getLegacyAuthScriptAddressByWIF(network, wif, options = {}) {
|
|
24143
|
+
const pqChain = getPQNetwork(network);
|
|
24144
|
+
const publicKeyHex = publicKeyHexFromWIF(wif);
|
|
24145
|
+
const publicKeyBytes = ensureBytes(publicKeyHex);
|
|
24146
|
+
const parts = authScriptCommitmentParts(0x02, publicKeyBytes, options);
|
|
24147
|
+
return {
|
|
24148
|
+
address: legacyAuthScriptToAddressBytes(publicKeyBytes, pqChain, options),
|
|
24149
|
+
publicKey: publicKeyHex,
|
|
24150
|
+
privateKey: "",
|
|
24151
|
+
WIF: wif,
|
|
24152
|
+
authType: 0x02,
|
|
24153
|
+
authDescriptor: bytesToHex(parts.authDescriptor),
|
|
24154
|
+
commitment: bytesToHex(parts.commitment),
|
|
24155
|
+
witnessScript: bytesToHex(parts.witnessScript),
|
|
24156
|
+
};
|
|
24157
|
+
}
|
|
24158
|
+
function getPQAddress(network, mnemonic, account, index, passphrase = "", options = {}) {
|
|
24046
24159
|
const chain = getPQNetwork(network);
|
|
24047
24160
|
const hdKey = getPQHDKey(network, mnemonic, passphrase);
|
|
24048
24161
|
const path = `m/${chain.purpose}'/${chain.coinType}'/${account}'/${chain.changeIndex}/${index}`;
|
|
24049
|
-
return getPQAddressByPath(network, hdKey, path);
|
|
24162
|
+
return getPQAddressByPath(network, hdKey, path, options);
|
|
24163
|
+
}
|
|
24164
|
+
function pqPublicKeyToAddress(network, publicKey, options = {}) {
|
|
24165
|
+
const keyBytes = ensureBytes(publicKey);
|
|
24166
|
+
if (keyBytes.length !== 1312) {
|
|
24167
|
+
throw new Error("ML-DSA-44 public key must be 1312 bytes");
|
|
24168
|
+
}
|
|
24169
|
+
normalizeWitnessScript(options.witnessScript);
|
|
24170
|
+
return pqPublicKeyToAddressBytes(keyBytes, getPQNetwork(network), options);
|
|
24171
|
+
}
|
|
24172
|
+
function pqPublicKeyToCommitmentHex(publicKey, options = {}) {
|
|
24173
|
+
const keyBytes = ensureBytes(publicKey);
|
|
24174
|
+
if (keyBytes.length !== 1312) {
|
|
24175
|
+
throw new Error("ML-DSA-44 public key must be 1312 bytes");
|
|
24176
|
+
}
|
|
24177
|
+
return bytesToHex(pqPublicKeyToCommitment(keyBytes, options));
|
|
24050
24178
|
}
|
|
24051
|
-
function
|
|
24179
|
+
function pqPublicKeyToAuthDescriptorHex(publicKey) {
|
|
24052
24180
|
const keyBytes = ensureBytes(publicKey);
|
|
24053
24181
|
if (keyBytes.length !== 1312) {
|
|
24054
24182
|
throw new Error("ML-DSA-44 public key must be 1312 bytes");
|
|
24055
24183
|
}
|
|
24056
|
-
return
|
|
24184
|
+
return bytesToHex(pqPublicKeyToAuthDescriptor(keyBytes));
|
|
24057
24185
|
}
|
|
24058
|
-
function generatePQAddressObject(network = "xna-pq", passphrase = "") {
|
|
24186
|
+
function generatePQAddressObject(network = "xna-pq", passphrase = "", options = {}) {
|
|
24059
24187
|
const mnemonic = generateMnemonic();
|
|
24060
|
-
const addressObj = getPQAddress(network, mnemonic, 0, 0, passphrase);
|
|
24188
|
+
const addressObj = getPQAddress(network, mnemonic, 0, 0, passphrase, options);
|
|
24061
24189
|
return {
|
|
24062
24190
|
...addressObj,
|
|
24063
24191
|
mnemonic,
|
|
@@ -24079,7 +24207,12 @@ zurdo`.split('\n');
|
|
|
24079
24207
|
getPQAddress,
|
|
24080
24208
|
getPQAddressByPath,
|
|
24081
24209
|
getPQHDKey,
|
|
24210
|
+
getNoAuthAddress,
|
|
24211
|
+
getLegacyAuthScriptAddress,
|
|
24212
|
+
getLegacyAuthScriptAddressByWIF,
|
|
24082
24213
|
pqPublicKeyToAddress,
|
|
24214
|
+
pqPublicKeyToAuthDescriptorHex,
|
|
24215
|
+
pqPublicKeyToCommitmentHex,
|
|
24083
24216
|
generatePQAddressObject,
|
|
24084
24217
|
};
|
|
24085
24218
|
|