@monolythium/core-sdk 0.4.24 → 0.5.1
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 +17 -9
- package/dist/crypto/index.cjs +45 -88
- package/dist/crypto/index.cjs.map +1 -1
- package/dist/crypto/index.d.cts +43 -30
- package/dist/crypto/index.d.ts +43 -30
- package/dist/crypto/index.js +39 -71
- package/dist/crypto/index.js.map +1 -1
- package/dist/index.cjs +402 -50
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +399 -1
- package/dist/index.d.ts +399 -1
- package/dist/index.js +373 -52
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -290,21 +290,29 @@ const readiness = bridgeQuoteSubmitReadiness(intent, routeDisclosures);
|
|
|
290
290
|
console.log(readiness.routeSelectionReady, readiness.quoteReady, readiness.blockedReasons);
|
|
291
291
|
```
|
|
292
292
|
|
|
293
|
-
###
|
|
293
|
+
### BIP-39 + ML-DSA-65 helpers
|
|
294
294
|
|
|
295
|
-
Wallets and faucets
|
|
296
|
-
TypeScript from
|
|
295
|
+
Wallets and faucets derive deterministic ML-DSA-65 backends directly in
|
|
296
|
+
TypeScript from standard 24-word BIP-39 mnemonics. The signing seed is the
|
|
297
|
+
domain-separated SHAKE256 of the standard BIP-39 PBKDF2 seed:
|
|
298
|
+
|
|
299
|
+
```text
|
|
300
|
+
seed64 = mnemonicToSeedSync(mnemonic, "") // HMAC-SHA512, 2048 rounds, 64 bytes
|
|
301
|
+
mldsa65Seed = shake256("monolythium.mldsa65.v1" || seed64, { dkLen: 32 })
|
|
302
|
+
```
|
|
297
303
|
|
|
298
304
|
```ts
|
|
299
305
|
import {
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
306
|
+
generateMnemonic,
|
|
307
|
+
validateMnemonic,
|
|
308
|
+
mnemonicToAddress,
|
|
309
|
+
mnemonicToMlDsa65Backend,
|
|
303
310
|
} from "@monolythium/core-sdk/crypto";
|
|
304
311
|
|
|
305
|
-
const mnemonic =
|
|
306
|
-
|
|
307
|
-
const
|
|
312
|
+
const mnemonic = generateMnemonic(); // 24 words, 256-bit BIP-39
|
|
313
|
+
validateMnemonic(mnemonic); // true (checksum + 24-word count)
|
|
314
|
+
const address = mnemonicToAddress(mnemonic);
|
|
315
|
+
const backend = mnemonicToMlDsa65Backend(mnemonic);
|
|
308
316
|
const signature = backend.sign(new Uint8Array([1, 2, 3]));
|
|
309
317
|
```
|
|
310
318
|
|
package/dist/crypto/index.cjs
CHANGED
|
@@ -352,98 +352,66 @@ function encodeMlDsa65Opaque(raw) {
|
|
|
352
352
|
out.set(bytes, 14);
|
|
353
353
|
return out;
|
|
354
354
|
}
|
|
355
|
-
var
|
|
356
|
-
var
|
|
357
|
-
var
|
|
358
|
-
var
|
|
359
|
-
var
|
|
360
|
-
var PQM1_PAYLOAD_LEN = 32;
|
|
361
|
-
var PQM1_ENTROPY_LEN = 30;
|
|
362
|
-
var PQM1_V1_MNEMONIC_WORDS = 24;
|
|
363
|
-
var PQM1_V1_MLDSA65_DOMAIN_TAG = "monolythium.pqm1.v1.mldsa65";
|
|
364
|
-
var Pqm1Error = class extends Error {
|
|
355
|
+
var MLDSA65_MNEMONIC_WORDS = 24;
|
|
356
|
+
var MLDSA65_SEED_DOMAIN = "monolythium.mldsa65.v1";
|
|
357
|
+
var MLDSA65_ENTROPY_LEN = 32;
|
|
358
|
+
var DOMAIN_BYTES = new TextEncoder().encode(MLDSA65_SEED_DOMAIN);
|
|
359
|
+
var MnemonicError = class extends Error {
|
|
365
360
|
constructor(kind, message) {
|
|
366
361
|
super(message);
|
|
367
362
|
this.kind = kind;
|
|
368
|
-
this.name = "
|
|
363
|
+
this.name = "MnemonicError";
|
|
369
364
|
}
|
|
370
365
|
kind;
|
|
371
366
|
};
|
|
372
|
-
var DOMAIN_BYTES = new TextEncoder().encode(PQM1_V1_MLDSA65_DOMAIN_TAG);
|
|
373
367
|
function normalizeMnemonic(mnemonic) {
|
|
374
368
|
return mnemonic.trim().toLowerCase().replace(/\s+/g, " ");
|
|
375
369
|
}
|
|
376
|
-
function
|
|
377
|
-
|
|
378
|
-
throw new Pqm1Error("badPayloadLength", `PQM-1 payload must be ${PQM1_PAYLOAD_LEN} bytes, got ${bytes.length}`);
|
|
379
|
-
}
|
|
380
|
-
if (bytes[0] !== PQM1_ALGO_TAG_MLDSA65) {
|
|
381
|
-
throw new Pqm1Error("unsupportedAlgorithm", `unsupported PQM-1 algorithm tag 0x${bytes[0].toString(16).padStart(2, "0")}`);
|
|
382
|
-
}
|
|
383
|
-
if (bytes[1] !== PQM1_VERSION_V1) {
|
|
384
|
-
throw new Pqm1Error("unsupportedVersion", `unsupported PQM-1 version 0x${bytes[1].toString(16).padStart(2, "0")}`);
|
|
385
|
-
}
|
|
370
|
+
function wordCount(normalized) {
|
|
371
|
+
return normalized.length === 0 ? 0 : normalized.split(" ").length;
|
|
386
372
|
}
|
|
387
373
|
function defaultRandomFill(bytes) {
|
|
388
374
|
const cryptoObj = globalThis.crypto;
|
|
389
375
|
if (!cryptoObj?.getRandomValues) {
|
|
390
|
-
throw new
|
|
376
|
+
throw new MnemonicError("missingRandom", "globalThis.crypto.getRandomValues is unavailable");
|
|
391
377
|
}
|
|
392
378
|
cryptoObj.getRandomValues(bytes);
|
|
393
379
|
}
|
|
394
|
-
function
|
|
395
|
-
const
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
payload[1] = PQM1_VERSION_V1;
|
|
399
|
-
payload.set(ent, 2);
|
|
400
|
-
return payload;
|
|
401
|
-
}
|
|
402
|
-
function parsePqm1Payload(payload) {
|
|
403
|
-
const bytes = expectBytes(payload, PQM1_PAYLOAD_LEN, "PQM-1 payload").slice();
|
|
404
|
-
ensureSupportedPayload(bytes);
|
|
405
|
-
return {
|
|
406
|
-
algoTag: PQM1_ALGO_TAG_MLDSA65,
|
|
407
|
-
version: PQM1_VERSION_V1,
|
|
408
|
-
entropy: bytes.slice(2),
|
|
409
|
-
bytes
|
|
410
|
-
};
|
|
380
|
+
function generateMnemonic(rng = defaultRandomFill) {
|
|
381
|
+
const entropy = new Uint8Array(MLDSA65_ENTROPY_LEN);
|
|
382
|
+
rng(entropy);
|
|
383
|
+
return bip39.entropyToMnemonic(entropy, english_js.wordlist);
|
|
411
384
|
}
|
|
412
|
-
function
|
|
413
|
-
const
|
|
414
|
-
|
|
385
|
+
function validateMnemonic(mnemonic) {
|
|
386
|
+
const normalized = normalizeMnemonic(mnemonic);
|
|
387
|
+
if (wordCount(normalized) !== MLDSA65_MNEMONIC_WORDS) {
|
|
388
|
+
return false;
|
|
389
|
+
}
|
|
390
|
+
return bip39.validateMnemonic(normalized, english_js.wordlist);
|
|
415
391
|
}
|
|
416
|
-
function
|
|
392
|
+
function mnemonicToMlDsa65Seed(mnemonic) {
|
|
417
393
|
const normalized = normalizeMnemonic(mnemonic);
|
|
418
|
-
const words = normalized
|
|
419
|
-
if (words
|
|
420
|
-
throw new
|
|
394
|
+
const words = wordCount(normalized);
|
|
395
|
+
if (words !== MLDSA65_MNEMONIC_WORDS) {
|
|
396
|
+
throw new MnemonicError(
|
|
397
|
+
"badWordCount",
|
|
398
|
+
`mnemonic must be ${MLDSA65_MNEMONIC_WORDS} words, got ${words}`
|
|
399
|
+
);
|
|
421
400
|
}
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
401
|
+
if (!bip39.validateMnemonic(normalized, english_js.wordlist)) {
|
|
402
|
+
throw new MnemonicError(
|
|
403
|
+
"bip39Decode",
|
|
404
|
+
"invalid BIP-39 mnemonic (unknown word or bad checksum)"
|
|
405
|
+
);
|
|
427
406
|
}
|
|
428
|
-
|
|
407
|
+
const seed64 = bip39.mnemonicToSeedSync(normalized, "");
|
|
408
|
+
return sha3_js.shake256(concatBytes(DOMAIN_BYTES, seed64), { dkLen: ML_DSA_65_SEED_LEN });
|
|
429
409
|
}
|
|
430
|
-
function
|
|
431
|
-
|
|
432
|
-
return sha3_js.shake256(concatBytes(DOMAIN_BYTES, parsed.bytes), { dkLen: ML_DSA_65_SEED_LEN });
|
|
410
|
+
function mnemonicToMlDsa65Backend(mnemonic) {
|
|
411
|
+
return MlDsa65Backend.fromSeed(mnemonicToMlDsa65Seed(mnemonic));
|
|
433
412
|
}
|
|
434
|
-
function
|
|
435
|
-
return
|
|
436
|
-
}
|
|
437
|
-
function pqm1MnemonicToMlDsa65Backend(mnemonic) {
|
|
438
|
-
return MlDsa65Backend.fromSeed(pqm1MnemonicToMlDsa65Seed(mnemonic));
|
|
439
|
-
}
|
|
440
|
-
function pqm1MnemonicToAddress(mnemonic) {
|
|
441
|
-
return pqm1MnemonicToMlDsa65Backend(mnemonic).getAddress();
|
|
442
|
-
}
|
|
443
|
-
function generatePqm1Mnemonic(rng = defaultRandomFill) {
|
|
444
|
-
const entropy = new Uint8Array(PQM1_ENTROPY_LEN);
|
|
445
|
-
rng(entropy);
|
|
446
|
-
return pqm1PayloadToMnemonic(assemblePqm1Payload(entropy));
|
|
413
|
+
function mnemonicToAddress(mnemonic) {
|
|
414
|
+
return mnemonicToMlDsa65Backend(mnemonic).getAddress();
|
|
447
415
|
}
|
|
448
416
|
|
|
449
417
|
// src/crypto/envelope.ts
|
|
@@ -504,43 +472,32 @@ function bytesEqual(a, b) {
|
|
|
504
472
|
exports.ADDRESS_DERIVATION_DOMAIN = ADDRESS_DERIVATION_DOMAIN;
|
|
505
473
|
exports.BincodeWriter = BincodeWriter;
|
|
506
474
|
exports.ENUM_VARIANT_INDEX_ML_DSA_65 = ENUM_VARIANT_INDEX_ML_DSA_65;
|
|
475
|
+
exports.MLDSA65_MNEMONIC_WORDS = MLDSA65_MNEMONIC_WORDS;
|
|
476
|
+
exports.MLDSA65_SEED_DOMAIN = MLDSA65_SEED_DOMAIN;
|
|
507
477
|
exports.ML_DSA_65_PUBLIC_KEY_LEN = ML_DSA_65_PUBLIC_KEY_LEN;
|
|
508
478
|
exports.ML_DSA_65_SEED_LEN = ML_DSA_65_SEED_LEN;
|
|
509
479
|
exports.ML_DSA_65_SIGNATURE_LEN = ML_DSA_65_SIGNATURE_LEN;
|
|
510
480
|
exports.ML_DSA_65_SIGNING_KEY_LEN = ML_DSA_65_SIGNING_KEY_LEN;
|
|
511
481
|
exports.MempoolClass = MempoolClass;
|
|
512
482
|
exports.MlDsa65Backend = MlDsa65Backend;
|
|
513
|
-
exports.
|
|
514
|
-
exports.PQM1_ALGO_TAG_MLDSA65 = PQM1_ALGO_TAG_MLDSA65;
|
|
515
|
-
exports.PQM1_ALGO_TAG_MLDSA87_RESERVED = PQM1_ALGO_TAG_MLDSA87_RESERVED;
|
|
516
|
-
exports.PQM1_ALGO_TAG_SLHDSA128S_RESERVED = PQM1_ALGO_TAG_SLHDSA128S_RESERVED;
|
|
517
|
-
exports.PQM1_ENTROPY_LEN = PQM1_ENTROPY_LEN;
|
|
518
|
-
exports.PQM1_PAYLOAD_LEN = PQM1_PAYLOAD_LEN;
|
|
519
|
-
exports.PQM1_V1_MLDSA65_DOMAIN_TAG = PQM1_V1_MLDSA65_DOMAIN_TAG;
|
|
520
|
-
exports.PQM1_V1_MNEMONIC_WORDS = PQM1_V1_MNEMONIC_WORDS;
|
|
521
|
-
exports.PQM1_VERSION_V1 = PQM1_VERSION_V1;
|
|
522
|
-
exports.Pqm1Error = Pqm1Error;
|
|
483
|
+
exports.MnemonicError = MnemonicError;
|
|
523
484
|
exports.STANDARD_ALGO_NUMBER_ML_DSA_65 = STANDARD_ALGO_NUMBER_ML_DSA_65;
|
|
524
|
-
exports.assemblePqm1Payload = assemblePqm1Payload;
|
|
525
485
|
exports.bincodeSignedTransaction = bincodeSignedTransaction;
|
|
526
486
|
exports.buildPlaintextSubmission = buildPlaintextSubmission;
|
|
527
487
|
exports.bytesToHex = bytesToHex;
|
|
528
488
|
exports.concatBytes = concatBytes;
|
|
529
|
-
exports.derivePqm1MlDsa65SeedFromPayload = derivePqm1MlDsa65SeedFromPayload;
|
|
530
489
|
exports.encodeMlDsa65Opaque = encodeMlDsa65Opaque;
|
|
531
490
|
exports.encodeTransactionForHash = encodeTransactionForHash;
|
|
532
491
|
exports.expectBytes = expectBytes;
|
|
533
|
-
exports.
|
|
492
|
+
exports.generateMnemonic = generateMnemonic;
|
|
534
493
|
exports.hexToBytes = hexToBytes;
|
|
535
494
|
exports.mlDsa65AddressBytes = mlDsa65AddressBytes;
|
|
536
495
|
exports.mlDsa65AddressFromPublicKey = mlDsa65AddressFromPublicKey;
|
|
537
|
-
exports.
|
|
538
|
-
exports.
|
|
539
|
-
exports.
|
|
540
|
-
exports.pqm1MnemonicToMlDsa65Seed = pqm1MnemonicToMlDsa65Seed;
|
|
541
|
-
exports.pqm1MnemonicToPayload = pqm1MnemonicToPayload;
|
|
542
|
-
exports.pqm1PayloadToMnemonic = pqm1PayloadToMnemonic;
|
|
496
|
+
exports.mnemonicToAddress = mnemonicToAddress;
|
|
497
|
+
exports.mnemonicToMlDsa65Backend = mnemonicToMlDsa65Backend;
|
|
498
|
+
exports.mnemonicToMlDsa65Seed = mnemonicToMlDsa65Seed;
|
|
543
499
|
exports.submitPlaintextTransaction = submitPlaintextTransaction;
|
|
544
500
|
exports.submitTransaction = submitTransaction;
|
|
501
|
+
exports.validateMnemonic = validateMnemonic;
|
|
545
502
|
//# sourceMappingURL=index.cjs.map
|
|
546
503
|
//# sourceMappingURL=index.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../../src/crypto/bincode.ts","../../src/crypto/bytes.ts","../../src/crypto/tx.ts","../../src/crypto/ml-dsa.ts","../../src/crypto/pqm1.ts","../../src/crypto/envelope.ts","../../src/crypto/submission.ts"],"names":["ml_dsa65","keccak_256","blake3","entropyToMnemonic","wordlist","mnemonicToEntropy","shake256"],"mappings":";;;;;;;;;AAAO,IAAM,gBAAN,MAAoB;AAAA,EACzB,UAAoB,EAAC;AAAA,EAErB,GAAG,KAAA,EAAqB;AACtB,IAAA,IAAA,CAAK,I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AA,GAAI,CAAA,CAAE,QAAQ,CAAA,EAAA,EAAK;AACjC,IAAA,IAAI,EAAE,CAAC,CAAA,KAAM,CAAA,CAAE,CAAC,GAAG,OAAO,KAAA;AAAA,EAC5B;AACA,EAAA,OAAO,IAAA;AACT","file":"index.cjs","sourcesContent":["export class BincodeWriter {\n #chunks: number[] = [];\n\n u8(value: number): void {\n this.#int(value, 1);\n }\n\n u16(value: number): void {\n this.#int(value, 2);\n }\n\n u32(value: number): void {\n this.#int(value, 4);\n }\n\n u64(value: bigint | number): void {\n this.#big(value, 8);\n }\n\n u128(value: bigint | number): void {\n this.#big(value, 16);\n }\n\n enumVariant(value: number): void {\n this.u32(value);\n }\n\n rawBytes(bytes: Uint8Array): void {\n for (const b of bytes) this.#chunks.push(b);\n }\n\n bytes(bytes: Uint8Array): void {\n this.u64(BigInt(bytes.length));\n this.rawBytes(bytes);\n }\n\n optionBytes(bytes: Uint8Array | null): void {\n if (bytes === null) {\n this.u8(0);\n return;\n }\n this.u8(1);\n this.rawBytes(bytes);\n }\n\n toBytes(): Uint8Array {\n return Uint8Array.from(this.#chunks);\n }\n\n #int(value: number, bytes: number): void {\n if (!Number.isSafeInteger(value) || value < 0 || value >= 2 ** (bytes * 8)) {\n throw new Error(`integer out of u${bytes * 8} range`);\n }\n for (let i = 0; i < bytes; i++) {\n this.#chunks.push((value >> (8 * i)) & 0xff);\n }\n }\n\n #big(value: bigint | number, bytes: number): void {\n let v = typeof value === \"bigint\" ? value : BigInt(value);\n if (v < 0n || v >= (1n << BigInt(bytes * 8))) {\n throw new Error(`integer out of u${bytes * 8} range`);\n }\n for (let i = 0; i < bytes; i++) {\n this.#chunks.push(Number(v & 0xffn));\n v >>= 8n;\n }\n }\n}\n","export function concatBytes(...chunks: Uint8Array[]): Uint8Array {\n const len = chunks.reduce((n, c) => n + c.length, 0);\n const out = new Uint8Array(len);\n let off = 0;\n for (const chunk of chunks) {\n out.set(chunk, off);\n off += chunk.length;\n }\n return out;\n}\n\nexport function bytesToHex(bytes: Uint8Array): string {\n let out = \"0x\";\n for (let i = 0; i < bytes.length; i++) {\n out += bytes[i]!.toString(16).padStart(2, \"0\");\n }\n return out;\n}\n\nexport function hexToBytes(hex: string, label = \"hex\"): Uint8Array {\n const stripped = hex.startsWith(\"0x\") || hex.startsWith(\"0X\") ? hex.slice(2) : hex;\n if (stripped.length % 2 !== 0) {\n throw new Error(`${label} must have even length`);\n }\n const out = new Uint8Array(stripped.length / 2);\n for (let i = 0; i < out.length; i++) {\n const b = Number.parseInt(stripped.slice(i * 2, i * 2 + 2), 16);\n if (Number.isNaN(b)) {\n throw new Error(`${label} contains invalid hex`);\n }\n out[i] = b;\n }\n return out;\n}\n\nexport function expectBytes(value: Uint8Array | readonly number[], len: number, label: string): Uint8Array {\n if (value.length !== len) {\n throw new Error(`${label} must be ${len} bytes, got ${value.length}`);\n }\n return value instanceof Uint8Array ? value : Uint8Array.from(value);\n}\n\nexport function bigintToBeBytes(value: bigint, bytes: number, label: string): Uint8Array {\n if (value < 0n || value >= (1n << BigInt(bytes * 8))) {\n throw new Error(`${label} out of ${bytes * 8}-bit range`);\n }\n const out = new Uint8Array(bytes);\n let v = value;\n for (let i = bytes - 1; i >= 0; i--) {\n out[i] = Number(v & 0xffn);\n v >>= 8n;\n }\n return out;\n}\n\nexport function parseBigint(value: bigint | number | string | undefined, label: string): bigint {\n if (value === undefined) throw new Error(`${label} missing`);\n if (typeof value === \"bigint\") return value;\n if (typeof value === \"number\") {\n if (!Number.isSafeInteger(value) || value < 0) throw new Error(`${label} must be a non-negative safe integer`);\n return BigInt(value);\n }\n if (value.startsWith(\"0x\") || value.startsWith(\"0X\")) return BigInt(value);\n return BigInt(value);\n}\n","import { BincodeWriter } from \"./bincode.js\";\nimport { bigintToBeBytes, concatBytes, expectBytes, hexToBytes, parseBigint } from \"./bytes.js\";\nimport {\n ENUM_VARIANT_INDEX_ML_DSA_65,\n ML_DSA_65_PUBLIC_KEY_LEN,\n ML_DSA_65_SIGNATURE_LEN,\n STANDARD_ALGO_NUMBER_ML_DSA_65,\n} from \"./ml-dsa.js\";\n\nexport interface NativeEvmTxFields {\n chainId: bigint | number | string;\n nonce: bigint | number | string;\n maxPriorityFeePerGas: bigint | number | string;\n maxFeePerGas: bigint | number | string;\n gasLimit: bigint | number | string;\n to: Uint8Array | readonly number[] | string | null;\n value: bigint | number | string;\n input?: Uint8Array | readonly number[] | string;\n extensions?: readonly NativeTxExtensionLike[];\n}\n\nexport interface NativeTxExtension {\n kind: number;\n body: Uint8Array | readonly number[] | string;\n}\n\nexport interface NativeTxExtensionDescriptor {\n kind: number;\n bodyHex: string;\n}\n\nexport type NativeTxExtensionLike = NativeTxExtension | NativeTxExtensionDescriptor;\n\nexport function encodeTransactionForHash(fields: NativeEvmTxFields, tag: 0x01 | 0x02): Uint8Array {\n const n = normalizeTxFields(fields);\n return concatBytes(\n Uint8Array.of(tag),\n bigintToBeBytes(n.chainId, 8, \"chainId\"),\n bigintToBeBytes(n.nonce, 8, \"nonce\"),\n bigintToBeBytes(n.maxPriorityFeePerGas, 32, \"maxPriorityFeePerGas\"),\n bigintToBeBytes(n.maxFeePerGas, 32, \"maxFeePerGas\"),\n bigintToBeBytes(n.gasLimit, 8, \"gasLimit\"),\n n.to === null ? Uint8Array.of(0) : concatBytes(Uint8Array.of(1), n.to),\n bigintToBeBytes(n.value, 32, \"value\"),\n bigintToBeBytes(BigInt(n.input.length), 4, \"input.length\"),\n n.input,\n new Uint8Array(4), // access_list length\n encodeExtensionsForHash(n.extensions),\n );\n}\n\nexport function bincodeSignedTransaction(\n fields: NativeEvmTxFields,\n signature: Uint8Array | readonly number[],\n publicKey: Uint8Array | readonly number[],\n): Uint8Array {\n const n = normalizeTxFields(fields);\n const sig = expectBytes(signature, ML_DSA_65_SIGNATURE_LEN, \"ML-DSA-65 signature\");\n const pk = expectBytes(publicKey, ML_DSA_65_PUBLIC_KEY_LEN, \"ML-DSA-65 public key\");\n const w = new BincodeWriter();\n w.u64(n.chainId);\n w.u64(n.nonce);\n // Amount(U256) goes through alloy's ruint serde, which emits\n // `serialize_bytes(&to_be_bytes_vec())` for non-human-readable\n // serializers. bincode 1.x renders that as `u64(len) || 32 bytes BE`.\n // Address inside Option<Address> takes the same `serialize_bytes`\n // path via alloy's FixedBytes impl, so admin-tag(1) is followed by a\n // length-prefixed 20-byte payload, not a raw 20-byte run.\n w.bytes(uint256Be(n.maxPriorityFeePerGas, \"maxPriorityFeePerGas\"));\n w.bytes(uint256Be(n.maxFeePerGas, \"maxFeePerGas\"));\n w.u64(n.gasLimit);\n if (n.to === null) {\n w.u8(0);\n } else {\n w.u8(1);\n w.bytes(n.to);\n }\n w.bytes(uint256Be(n.value, \"value\"));\n w.bytes(n.input);\n w.u64(0n); // access_list length\n w.u64(BigInt(n.extensions.length));\n for (const ext of n.extensions) bincodeTypedExtensionInto(w, ext);\n bincodeMlDsa65OpaqueInto(w, sig);\n bincodeMlDsa65OpaqueInto(w, pk);\n return w.toBytes();\n}\n\ninterface NormalizedNativeTxExtension {\n kind: number;\n body: Uint8Array;\n}\n\ninterface NormalizedNativeEvmTxFields {\n chainId: bigint;\n nonce: bigint;\n maxPriorityFeePerGas: bigint;\n maxFeePerGas: bigint;\n gasLimit: bigint;\n to: Uint8Array | null;\n value: bigint;\n input: Uint8Array;\n extensions: NormalizedNativeTxExtension[];\n}\n\nfunction normalizeTxFields(fields: NativeEvmTxFields): NormalizedNativeEvmTxFields {\n return {\n chainId: parseBigint(fields.chainId, \"chainId\"),\n nonce: parseBigint(fields.nonce, \"nonce\"),\n maxPriorityFeePerGas: parseBigint(fields.maxPriorityFeePerGas, \"maxPriorityFeePerGas\"),\n maxFeePerGas: parseBigint(fields.maxFeePerGas, \"maxFeePerGas\"),\n gasLimit: parseBigint(fields.gasLimit, \"gasLimit\"),\n to: normalizeTo(fields.to),\n value: parseBigint(fields.value, \"value\"),\n input: normalizeBytes(fields.input ?? new Uint8Array(0), \"input\"),\n extensions: normalizeExtensions(fields.extensions),\n };\n}\n\nfunction normalizeTo(value: NativeEvmTxFields[\"to\"]): Uint8Array | null {\n if (value === null) return null;\n const bytes = normalizeBytes(value, \"to\");\n return expectBytes(bytes, 20, \"to\");\n}\n\nfunction normalizeBytes(value: Uint8Array | readonly number[] | string, label: string): Uint8Array {\n if (typeof value === \"string\") return hexToBytes(value, label);\n return value instanceof Uint8Array ? value : Uint8Array.from(value);\n}\n\nfunction normalizeExtensions(value: NativeEvmTxFields[\"extensions\"]): NormalizedNativeTxExtension[] {\n if (value === undefined) return [];\n return value.map((ext, index) => {\n if (!Number.isInteger(ext.kind) || ext.kind < 0 || ext.kind > 0xff) {\n throw new Error(`extensions[${index}].kind out of u8 range`);\n }\n const body = normalizeBytes(\"bodyHex\" in ext ? ext.bodyHex : ext.body, `extensions[${index}].body`);\n if (body.length > 0xffff_ffff) {\n throw new Error(`extensions[${index}].body exceeds u32 length`);\n }\n return { kind: ext.kind, body };\n });\n}\n\nfunction encodeExtensionsForHash(extensions: readonly NormalizedNativeTxExtension[]): Uint8Array {\n const chunks: Uint8Array[] = [bigintToBeBytes(BigInt(extensions.length), 4, \"extensions.length\")];\n for (const ext of extensions) {\n chunks.push(\n Uint8Array.of(ext.kind),\n bigintToBeBytes(BigInt(ext.body.length), 4, \"extension.body.length\"),\n ext.body,\n );\n }\n return concatBytes(...chunks);\n}\n\nfunction uint256Be(value: bigint, label: string): Uint8Array {\n if (value < 0n || value >= 1n << 256n) throw new Error(`${label} out of u256 range`);\n const out = new Uint8Array(32);\n let v = value;\n for (let i = 31; i >= 0; i--) {\n out[i] = Number(v & 0xffn);\n v >>= 8n;\n }\n return out;\n}\n\nfunction bincodeMlDsa65OpaqueInto(w: BincodeWriter, raw: Uint8Array): void {\n w.enumVariant(ENUM_VARIANT_INDEX_ML_DSA_65);\n w.u16(STANDARD_ALGO_NUMBER_ML_DSA_65);\n w.bytes(raw);\n}\n\nfunction bincodeTypedExtensionInto(w: BincodeWriter, ext: NormalizedNativeTxExtension): void {\n w.u8(ext.kind);\n w.bytes(ext.body);\n}\n","import { ml_dsa65 } from \"@noble/post-quantum/ml-dsa.js\";\nimport { blake3 } from \"@noble/hashes/blake3.js\";\nimport { keccak_256 } from \"@noble/hashes/sha3.js\";\nimport { bigintToBeBytes, bytesToHex, concatBytes, expectBytes } from \"./bytes.js\";\nimport { bincodeSignedTransaction, encodeTransactionForHash, type NativeEvmTxFields } from \"./tx.js\";\n\nexport const ML_DSA_65_SEED_LEN = 32;\nexport const ML_DSA_65_SIGNING_KEY_LEN = 4032;\nexport const ML_DSA_65_PUBLIC_KEY_LEN = 1952;\nexport const ML_DSA_65_SIGNATURE_LEN = 3309;\nexport const STANDARD_ALGO_NUMBER_ML_DSA_65 = 1001;\nexport const ENUM_VARIANT_INDEX_ML_DSA_65 = 3;\nexport const ADDRESS_DERIVATION_DOMAIN = \"MONO_ADDRESS_BLAKE3_20_V1\";\n\nconst ADDRESS_DERIVATION_DOMAIN_BYTES = new TextEncoder().encode(ADDRESS_DERIVATION_DOMAIN);\n\nexport class MlDsa65Backend {\n readonly #secretKey: Uint8Array;\n readonly #publicKey: Uint8Array;\n readonly #addressBytes: Uint8Array;\n #disposed = false;\n\n private constructor(secretKey: Uint8Array, publicKey: Uint8Array) {\n this.#secretKey = expectBytes(secretKey, ML_DSA_65_SIGNING_KEY_LEN, \"ML-DSA-65 secret key\").slice();\n this.#publicKey = expectBytes(publicKey, ML_DSA_65_PUBLIC_KEY_LEN, \"ML-DSA-65 public key\").slice();\n this.#addressBytes = mlDsa65AddressBytes(this.#publicKey);\n }\n\n static fromSeed(seed: Uint8Array | readonly number[]): MlDsa65Backend {\n const kp = ml_dsa65.keygen(expectBytes(seed, ML_DSA_65_SEED_LEN, \"ML-DSA-65 seed\"));\n return new MlDsa65Backend(kp.secretKey, kp.publicKey);\n }\n\n publicKey(): Uint8Array {\n return this.#publicKey.slice();\n }\n\n addressBytes(): Uint8Array {\n return this.#addressBytes.slice();\n }\n\n getAddress(): string {\n return bytesToHex(this.#addressBytes);\n }\n\n sign(message: Uint8Array): Uint8Array {\n if (this.#disposed) {\n throw new Error(\"MlDsa65Backend disposed\");\n }\n return ml_dsa65.sign(message, this.#secretKey, { extraEntropy: false });\n }\n\n /**\n * Best-effort deterministic wipe of the in-memory secret key. Zeroes the\n * SDK-held `#secretKey` copy and makes any subsequent `sign()` /\n * `signPrehash()` / `signEvmTx()` throw `\"MlDsa65Backend disposed\"` rather\n * than signing with a zeroed key. Idempotent. Public material\n * (`publicKey()` / `getAddress()` / `verify()`) stays usable.\n *\n * Defense-in-depth (S1-01): narrows the post-lock residency window of the\n * ML-DSA-65 secret in the JS heap. `@noble/post-quantum`'s internal\n * transient keygen/sign buffers are out of scope; the SDK-held copy is the\n * meaningful residency win.\n */\n dispose(): void {\n this.#secretKey.fill(0);\n this.#disposed = true;\n }\n\n /** Alias for {@link dispose}. */\n zeroize(): void {\n this.dispose();\n }\n\n /** Whether {@link dispose} has been called (the secret key is wiped). */\n get disposed(): boolean {\n return this.#disposed;\n }\n\n signPrehash(digest: Uint8Array): Uint8Array {\n return this.sign(expectBytes(digest, 32, \"prehash\"));\n }\n\n verify(message: Uint8Array, signature: Uint8Array): boolean {\n return ml_dsa65.verify(\n expectBytes(signature, ML_DSA_65_SIGNATURE_LEN, \"ML-DSA-65 signature\"),\n message,\n this.#publicKey,\n );\n }\n\n signEvmTx(fields: NativeEvmTxFields): {\n wireHex: string;\n wireBytes: Uint8Array;\n sighash: Uint8Array;\n txHash: Uint8Array;\n } {\n const txHashPreimage = encodeTransactionForHash(fields, 0x01);\n const sighash = keccak_256(txHashPreimage);\n const signature = this.sign(sighash);\n const wireBytes = bincodeSignedTransaction(fields, signature, this.#publicKey);\n const txHash = keccak_256(\n concatBytes(\n encodeTransactionForHash(fields, 0x02),\n signature,\n this.#publicKey,\n ),\n );\n return {\n wireHex: bytesToHex(wireBytes).slice(2),\n wireBytes,\n sighash,\n txHash,\n };\n }\n}\n\nexport function mlDsa65AddressFromPublicKey(publicKey: Uint8Array | readonly number[]): string {\n return bytesToHex(mlDsa65AddressBytes(publicKey));\n}\n\nexport function mlDsa65AddressBytes(publicKey: Uint8Array | readonly number[]): Uint8Array {\n const bytes = expectBytes(publicKey, ML_DSA_65_PUBLIC_KEY_LEN, \"ML-DSA-65 public key\");\n return blake3(concatBytes(\n ADDRESS_DERIVATION_DOMAIN_BYTES,\n bigintToBeBytes(BigInt(STANDARD_ALGO_NUMBER_ML_DSA_65), 2, \"ML-DSA-65 algo id\"),\n bytes,\n )).slice(0, 20);\n}\n\nexport function encodeMlDsa65Opaque(raw: Uint8Array | readonly number[]): Uint8Array {\n const bytes = raw instanceof Uint8Array ? raw : Uint8Array.from(raw);\n const len = bytes.length === ML_DSA_65_PUBLIC_KEY_LEN ? ML_DSA_65_PUBLIC_KEY_LEN : ML_DSA_65_SIGNATURE_LEN;\n expectBytes(bytes, len, \"ML-DSA-65 opaque bytes\");\n const out = new Uint8Array(4 + 2 + 8 + bytes.length);\n const dv = new DataView(out.buffer);\n dv.setUint32(0, ENUM_VARIANT_INDEX_ML_DSA_65, true);\n dv.setUint16(4, STANDARD_ALGO_NUMBER_ML_DSA_65, true);\n dv.setBigUint64(6, BigInt(bytes.length), true);\n out.set(bytes, 14);\n return out;\n}\n\nexport function uint256Bytes(value: bigint | number | string, label: string): Uint8Array {\n const v = typeof value === \"bigint\" ? value : typeof value === \"number\" ? BigInt(value) : BigInt(value);\n return bigintToBeBytes(v, 32, label);\n}\n","import { shake256 } from \"@noble/hashes/sha3.js\";\nimport { entropyToMnemonic, mnemonicToEntropy } from \"@scure/bip39\";\nimport { wordlist } from \"@scure/bip39/wordlists/english.js\";\nimport { concatBytes, expectBytes } from \"./bytes.js\";\nimport { ML_DSA_65_SEED_LEN, MlDsa65Backend } from \"./ml-dsa.js\";\n\nexport const PQM1_ALGO_TAG_MLDSA65 = 0x01;\nexport const PQM1_ALGO_TAG_MLDSA87_RESERVED = 0x02;\nexport const PQM1_ALGO_TAG_SLHDSA128S_RESERVED = 0x03;\nexport const PQM1_ALGO_TAG_FALCON512_RESERVED = 0x04;\nexport const PQM1_VERSION_V1 = 0x01;\nexport const PQM1_PAYLOAD_LEN = 32;\nexport const PQM1_ENTROPY_LEN = 30;\nexport const PQM1_V1_MNEMONIC_WORDS = 24;\nexport const PQM1_V1_MLDSA65_DOMAIN_TAG = \"monolythium.pqm1.v1.mldsa65\";\n\nexport type Pqm1ErrorKind =\n | \"badWordCount\"\n | \"bip39Decode\"\n | \"badPayloadLength\"\n | \"unsupportedAlgorithm\"\n | \"unsupportedVersion\"\n | \"missingRandom\";\n\nexport class Pqm1Error extends Error {\n constructor(\n readonly kind: Pqm1ErrorKind,\n message: string,\n ) {\n super(message);\n this.name = \"Pqm1Error\";\n }\n}\n\nexport interface Pqm1Payload {\n algoTag: typeof PQM1_ALGO_TAG_MLDSA65;\n version: typeof PQM1_VERSION_V1;\n entropy: Uint8Array;\n bytes: Uint8Array;\n}\n\nexport type Pqm1Rng = (bytes: Uint8Array) => void;\n\nconst DOMAIN_BYTES = new TextEncoder().encode(PQM1_V1_MLDSA65_DOMAIN_TAG);\n\nfunction normalizeMnemonic(mnemonic: string): string {\n return mnemonic.trim().toLowerCase().replace(/\\s+/g, \" \");\n}\n\nfunction ensureSupportedPayload(bytes: Uint8Array): void {\n if (bytes.length !== PQM1_PAYLOAD_LEN) {\n throw new Pqm1Error(\"badPayloadLength\", `PQM-1 payload must be ${PQM1_PAYLOAD_LEN} bytes, got ${bytes.length}`);\n }\n if (bytes[0] !== PQM1_ALGO_TAG_MLDSA65) {\n throw new Pqm1Error(\"unsupportedAlgorithm\", `unsupported PQM-1 algorithm tag 0x${bytes[0]!.toString(16).padStart(2, \"0\")}`);\n }\n if (bytes[1] !== PQM1_VERSION_V1) {\n throw new Pqm1Error(\"unsupportedVersion\", `unsupported PQM-1 version 0x${bytes[1]!.toString(16).padStart(2, \"0\")}`);\n }\n}\n\nfunction defaultRandomFill(bytes: Uint8Array): void {\n const cryptoObj = globalThis.crypto;\n if (!cryptoObj?.getRandomValues) {\n throw new Pqm1Error(\"missingRandom\", \"globalThis.crypto.getRandomValues is unavailable\");\n }\n cryptoObj.getRandomValues(bytes);\n}\n\nexport function assemblePqm1Payload(entropy: Uint8Array | readonly number[]): Uint8Array {\n const ent = expectBytes(entropy, PQM1_ENTROPY_LEN, \"PQM-1 entropy\");\n const payload = new Uint8Array(PQM1_PAYLOAD_LEN);\n payload[0] = PQM1_ALGO_TAG_MLDSA65;\n payload[1] = PQM1_VERSION_V1;\n payload.set(ent, 2);\n return payload;\n}\n\nexport function parsePqm1Payload(payload: Uint8Array | readonly number[]): Pqm1Payload {\n const bytes = expectBytes(payload, PQM1_PAYLOAD_LEN, \"PQM-1 payload\").slice();\n ensureSupportedPayload(bytes);\n return {\n algoTag: PQM1_ALGO_TAG_MLDSA65,\n version: PQM1_VERSION_V1,\n entropy: bytes.slice(2),\n bytes,\n };\n}\n\nexport function pqm1PayloadToMnemonic(payload: Uint8Array | readonly number[]): string {\n const parsed = parsePqm1Payload(payload);\n return entropyToMnemonic(parsed.bytes, wordlist);\n}\n\nexport function pqm1MnemonicToPayload(mnemonic: string): Pqm1Payload {\n const normalized = normalizeMnemonic(mnemonic);\n const words = normalized.length === 0 ? [] : normalized.split(\" \");\n if (words.length !== PQM1_V1_MNEMONIC_WORDS) {\n throw new Pqm1Error(\"badWordCount\", `PQM-1 mnemonic must be ${PQM1_V1_MNEMONIC_WORDS} words, got ${words.length}`);\n }\n let payload: Uint8Array;\n try {\n payload = mnemonicToEntropy(normalized, wordlist);\n } catch (e) {\n throw new Pqm1Error(\"bip39Decode\", `invalid PQM-1 mnemonic: ${(e as Error).message}`);\n }\n return parsePqm1Payload(payload);\n}\n\nexport function derivePqm1MlDsa65SeedFromPayload(payload: Uint8Array | readonly number[]): Uint8Array {\n const parsed = parsePqm1Payload(payload);\n return shake256(concatBytes(DOMAIN_BYTES, parsed.bytes), { dkLen: ML_DSA_65_SEED_LEN });\n}\n\nexport function pqm1MnemonicToMlDsa65Seed(mnemonic: string): Uint8Array {\n return derivePqm1MlDsa65SeedFromPayload(pqm1MnemonicToPayload(mnemonic).bytes);\n}\n\nexport function pqm1MnemonicToMlDsa65Backend(mnemonic: string): MlDsa65Backend {\n return MlDsa65Backend.fromSeed(pqm1MnemonicToMlDsa65Seed(mnemonic));\n}\n\nexport function pqm1MnemonicToAddress(mnemonic: string): string {\n return pqm1MnemonicToMlDsa65Backend(mnemonic).getAddress();\n}\n\nexport function generatePqm1Mnemonic(rng: Pqm1Rng = defaultRandomFill): string {\n const entropy = new Uint8Array(PQM1_ENTROPY_LEN);\n rng(entropy);\n return pqm1PayloadToMnemonic(assemblePqm1Payload(entropy));\n}\n","/**\n * Mempool transaction-class tags.\n *\n * The encrypted-mempool (LythiumSeal) envelope was removed at the v2\n * re-genesis; plaintext submission is the sole submit path. This module now\n * carries only the {@link MempoolClass} tag the node uses to classify a\n * transaction for ordering/admission.\n */\n\nexport const MempoolClass = {\n Transfer: 0,\n ContractCall: 1,\n PrivacyOp: 2,\n CLOBOp: 3,\n AgentOp: 4,\n FoundationOp: 5,\n /** @deprecated Use FoundationOp. */\n GovernanceOp: 5,\n RWAOp: 6,\n} as const;\nexport type MempoolClass = (typeof MempoolClass)[keyof typeof MempoolClass];\n","import { bytesToHex, hexToBytes } from \"./bytes.js\";\nimport type { MlDsa65Backend } from \"./ml-dsa.js\";\nimport type { NativeEvmTxFields } from \"./tx.js\";\n\nexport interface JsonRpcCallClient {\n call<T>(method: string, params?: unknown): Promise<T>;\n}\n\n/**\n * A built plaintext submission — the bincode-encoded chain-side\n * `SignedTransaction` (`0x`-prefixed hex) ready to hand to\n * `mesh_submitTx`, plus the canonical hashes the wallet validates the\n * node echo against.\n *\n * Mirrors the chain-side artefacts produced by the Rust SDK's\n * `build_chain_signed_tx` (`mono-core/crates/core/sdk/src/tx.rs`): the\n * ML-DSA-65 signature is taken over the canonical chain-side `sighash`\n * (keccak-256 of the 0x01-tagged preimage) and the canonical native tx\n * hash is the keccak-256 of the 0x02-tagged preimage with the signature\n * and public key appended.\n */\nexport interface PlaintextSubmission {\n /** Bincode `SignedTransaction` wire bytes, `0x`-prefixed. */\n signedTxWireHex: string;\n /** Canonical native tx hash the node echoes on admission. */\n innerTxHashHex: string;\n /** Canonical chain-side sighash that was signed. */\n innerSighashHex: string;\n /** Length in bytes of the bincode `SignedTransaction`. */\n innerWireBytes: number;\n}\n\n/**\n * Build a PLAINTEXT submission — the sole submit path since the v2\n * re-genesis dropped the encrypted (LythiumSeal) mempool.\n *\n * It re-shapes the native tx into the chain-side `SignedTransaction`,\n * signs over the canonical `sighash` with the ML-DSA-65 backend,\n * bincode-serializes the result, and `0x`-hex-encodes it. The bytes are\n * forwarded verbatim through `mesh_submitTx` (the node routes them to\n * `MempoolTx::plaintext` via `submit_raw`).\n *\n * Mirrors `TxClient::submit_plaintext` in the Rust SDK.\n */\nexport function buildPlaintextSubmission(args: {\n backend: MlDsa65Backend;\n tx: NativeEvmTxFields;\n}): PlaintextSubmission {\n const signed = args.backend.signEvmTx(args.tx);\n return {\n signedTxWireHex: `0x${signed.wireHex}`,\n innerTxHashHex: bytesToHex(signed.txHash),\n innerSighashHex: bytesToHex(signed.sighash),\n innerWireBytes: signed.wireBytes.length,\n };\n}\n\n/**\n * Submit a bincode-encoded chain-side `SignedTransaction` (`0x`-hex)\n * through the plaintext `mesh_submitTx` path and validate the node's\n * echoed canonical tx hash against the locally computed one.\n *\n * Mirrors the validation in `TxClient::submit_plaintext`: the node\n * echoes the 32-byte canonical native tx hash on admission, and any\n * mismatch (or non-32-byte response) is rejected loud so a wallet never\n * trusts a hash it did not derive itself.\n *\n * @returns the validated canonical native tx hash (`0x`-prefixed).\n */\nexport async function submitPlaintextTransaction(\n client: JsonRpcCallClient,\n signedTxWireHex: string,\n expectedTxHashHex: string,\n): Promise<string> {\n const returned = await client.call<string>(\"mesh_submitTx\", [signedTxWireHex]);\n const returnedBytes = hexToBytes(returned, \"mesh_submitTx tx hash\");\n if (returnedBytes.length !== 32) {\n throw new Error(\n `mesh_submitTx tx hash must be 32 bytes, got ${returnedBytes.length}`,\n );\n }\n const expectedBytes = hexToBytes(expectedTxHashHex, \"expected tx hash\");\n if (!bytesEqual(returnedBytes, expectedBytes)) {\n throw new Error(\n `mesh_submitTx returned tx hash ${bytesToHex(returnedBytes)} but the locally computed canonical hash is ${bytesToHex(expectedBytes)}`,\n );\n }\n return bytesToHex(returnedBytes);\n}\n\n/**\n * Build, sign, and submit a native transaction through the plaintext\n * `mesh_submitTx` path.\n *\n * Mirrors `TxClient::build_sign_submit` in the Rust SDK. The encrypted\n * (LythiumSeal) submit path was removed at the v2 re-genesis, so this is\n * the single build-sign-submit entry point.\n *\n * @returns the node-echoed-and-validated canonical native tx hash\n * (`0x`-prefixed).\n */\nexport async function submitTransaction(args: {\n client: JsonRpcCallClient;\n backend: MlDsa65Backend;\n tx: NativeEvmTxFields;\n}): Promise<string> {\n const plaintext = buildPlaintextSubmission({ backend: args.backend, tx: args.tx });\n return submitPlaintextTransaction(\n args.client,\n plaintext.signedTxWireHex,\n plaintext.innerTxHashHex,\n );\n}\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n"]}
|
|
1
|
+
{"version":3,"sources":["../../src/crypto/bincode.ts","../../src/crypto/bytes.ts","../../src/crypto/tx.ts","../../src/crypto/ml-dsa.ts","../../src/crypto/mnemonic.ts","../../src/crypto/envelope.ts","../../src/crypto/submission.ts"],"names":["ml_dsa65","keccak_256","blake3","entropyToMnemonic","wordlist","bip39ValidateMnemonic","mnemonicToSeedSync","shake256"],"mappings":";;;;;;;;;AAAO,IAAM,gBAAN,MAAoB;AAAA,EACzB,UAAoB,EAAC;AAAA,EAErB,GAAG,KAAA,EAAqB;AACtB,IAAA,IAAA,CAAK,IAAA,CAAK,OAAO,CAAC,CAAA;AAAA,EACpB;AAAA,EAEA,I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CAAC,UAAA,CAAW,aAAA,EAAe,aAAa,CAAA,EAAG;AAC7C,IAAA,MAAM,IAAI,KAAA;AAAA,MACR,kCAAkC,UAAA,CAAW,aAAa,CAAC,CAAA,4CAAA,EAA+C,UAAA,CAAW,aAAa,CAAC,CAAA;AAAA,KACrI;AAAA,EACF;AACA,EAAA,OAAO,WAAW,aAAa,CAAA;AACjC;AAaA,eAAsB,kBAAkB,IAAA,EAIpB;AAClB,EAAA,MAAM,SAAA,GAAY,yBAAyB,EAAE,OAAA,EAAS,KAAK,OAAA,EAAS,EAAA,EAAI,IAAA,CAAK,EAAA,EAAI,CAAA;AACjF,EAAA,OAAO,0BAAA;AAAA,IACL,IAAA,CAAK,MAAA;AAAA,IACL,SAAA,CAAU,eAAA;AAAA,IACV,SAAA,CAAU;AAAA,GACZ;AACF;AAEA,SAAS,UAAA,CAAW,GAAe,CAAA,EAAwB;AACzD,EAAA,IAAI,CAAA,CAAE,MAAA,KAAW,CAAA,CAAE,MAAA,EAAQ,OAAO,KAAA;AAClC,EAAA,KAAA,IAAS,CAAA,GAAI,CAAA,EAAG,CAAA,GAAI,CAAA,CAAE,QAAQ,CAAA,EAAA,EAAK;AACjC,IAAA,IAAI,EAAE,CAAC,CAAA,KAAM,CAAA,CAAE,CAAC,GAAG,OAAO,KAAA;AAAA,EAC5B;AACA,EAAA,OAAO,IAAA;AACT","file":"index.cjs","sourcesContent":["export class BincodeWriter {\n #chunks: number[] = [];\n\n u8(value: number): void {\n this.#int(value, 1);\n }\n\n u16(value: number): void {\n this.#int(value, 2);\n }\n\n u32(value: number): void {\n this.#int(value, 4);\n }\n\n u64(value: bigint | number): void {\n this.#big(value, 8);\n }\n\n u128(value: bigint | number): void {\n this.#big(value, 16);\n }\n\n enumVariant(value: number): void {\n this.u32(value);\n }\n\n rawBytes(bytes: Uint8Array): void {\n for (const b of bytes) this.#chunks.push(b);\n }\n\n bytes(bytes: Uint8Array): void {\n this.u64(BigInt(bytes.length));\n this.rawBytes(bytes);\n }\n\n optionBytes(bytes: Uint8Array | null): void {\n if (bytes === null) {\n this.u8(0);\n return;\n }\n this.u8(1);\n this.rawBytes(bytes);\n }\n\n toBytes(): Uint8Array {\n return Uint8Array.from(this.#chunks);\n }\n\n #int(value: number, bytes: number): void {\n if (!Number.isSafeInteger(value) || value < 0 || value >= 2 ** (bytes * 8)) {\n throw new Error(`integer out of u${bytes * 8} range`);\n }\n for (let i = 0; i < bytes; i++) {\n this.#chunks.push((value >> (8 * i)) & 0xff);\n }\n }\n\n #big(value: bigint | number, bytes: number): void {\n let v = typeof value === \"bigint\" ? value : BigInt(value);\n if (v < 0n || v >= (1n << BigInt(bytes * 8))) {\n throw new Error(`integer out of u${bytes * 8} range`);\n }\n for (let i = 0; i < bytes; i++) {\n this.#chunks.push(Number(v & 0xffn));\n v >>= 8n;\n }\n }\n}\n","export function concatBytes(...chunks: Uint8Array[]): Uint8Array {\n const len = chunks.reduce((n, c) => n + c.length, 0);\n const out = new Uint8Array(len);\n let off = 0;\n for (const chunk of chunks) {\n out.set(chunk, off);\n off += chunk.length;\n }\n return out;\n}\n\nexport function bytesToHex(bytes: Uint8Array): string {\n let out = \"0x\";\n for (let i = 0; i < bytes.length; i++) {\n out += bytes[i]!.toString(16).padStart(2, \"0\");\n }\n return out;\n}\n\nexport function hexToBytes(hex: string, label = \"hex\"): Uint8Array {\n const stripped = hex.startsWith(\"0x\") || hex.startsWith(\"0X\") ? hex.slice(2) : hex;\n if (stripped.length % 2 !== 0) {\n throw new Error(`${label} must have even length`);\n }\n const out = new Uint8Array(stripped.length / 2);\n for (let i = 0; i < out.length; i++) {\n const b = Number.parseInt(stripped.slice(i * 2, i * 2 + 2), 16);\n if (Number.isNaN(b)) {\n throw new Error(`${label} contains invalid hex`);\n }\n out[i] = b;\n }\n return out;\n}\n\nexport function expectBytes(value: Uint8Array | readonly number[], len: number, label: string): Uint8Array {\n if (value.length !== len) {\n throw new Error(`${label} must be ${len} bytes, got ${value.length}`);\n }\n return value instanceof Uint8Array ? value : Uint8Array.from(value);\n}\n\nexport function bigintToBeBytes(value: bigint, bytes: number, label: string): Uint8Array {\n if (value < 0n || value >= (1n << BigInt(bytes * 8))) {\n throw new Error(`${label} out of ${bytes * 8}-bit range`);\n }\n const out = new Uint8Array(bytes);\n let v = value;\n for (let i = bytes - 1; i >= 0; i--) {\n out[i] = Number(v & 0xffn);\n v >>= 8n;\n }\n return out;\n}\n\nexport function parseBigint(value: bigint | number | string | undefined, label: string): bigint {\n if (value === undefined) throw new Error(`${label} missing`);\n if (typeof value === \"bigint\") return value;\n if (typeof value === \"number\") {\n if (!Number.isSafeInteger(value) || value < 0) throw new Error(`${label} must be a non-negative safe integer`);\n return BigInt(value);\n }\n if (value.startsWith(\"0x\") || value.startsWith(\"0X\")) return BigInt(value);\n return BigInt(value);\n}\n","import { BincodeWriter } from \"./bincode.js\";\nimport { bigintToBeBytes, concatBytes, expectBytes, hexToBytes, parseBigint } from \"./bytes.js\";\nimport {\n ENUM_VARIANT_INDEX_ML_DSA_65,\n ML_DSA_65_PUBLIC_KEY_LEN,\n ML_DSA_65_SIGNATURE_LEN,\n STANDARD_ALGO_NUMBER_ML_DSA_65,\n} from \"./ml-dsa.js\";\n\nexport interface NativeEvmTxFields {\n chainId: bigint | number | string;\n nonce: bigint | number | string;\n maxPriorityFeePerGas: bigint | number | string;\n maxFeePerGas: bigint | number | string;\n gasLimit: bigint | number | string;\n to: Uint8Array | readonly number[] | string | null;\n value: bigint | number | string;\n input?: Uint8Array | readonly number[] | string;\n extensions?: readonly NativeTxExtensionLike[];\n}\n\nexport interface NativeTxExtension {\n kind: number;\n body: Uint8Array | readonly number[] | string;\n}\n\nexport interface NativeTxExtensionDescriptor {\n kind: number;\n bodyHex: string;\n}\n\nexport type NativeTxExtensionLike = NativeTxExtension | NativeTxExtensionDescriptor;\n\nexport function encodeTransactionForHash(fields: NativeEvmTxFields, tag: 0x01 | 0x02): Uint8Array {\n const n = normalizeTxFields(fields);\n return concatBytes(\n Uint8Array.of(tag),\n bigintToBeBytes(n.chainId, 8, \"chainId\"),\n bigintToBeBytes(n.nonce, 8, \"nonce\"),\n bigintToBeBytes(n.maxPriorityFeePerGas, 32, \"maxPriorityFeePerGas\"),\n bigintToBeBytes(n.maxFeePerGas, 32, \"maxFeePerGas\"),\n bigintToBeBytes(n.gasLimit, 8, \"gasLimit\"),\n n.to === null ? Uint8Array.of(0) : concatBytes(Uint8Array.of(1), n.to),\n bigintToBeBytes(n.value, 32, \"value\"),\n bigintToBeBytes(BigInt(n.input.length), 4, \"input.length\"),\n n.input,\n new Uint8Array(4), // access_list length\n encodeExtensionsForHash(n.extensions),\n );\n}\n\nexport function bincodeSignedTransaction(\n fields: NativeEvmTxFields,\n signature: Uint8Array | readonly number[],\n publicKey: Uint8Array | readonly number[],\n): Uint8Array {\n const n = normalizeTxFields(fields);\n const sig = expectBytes(signature, ML_DSA_65_SIGNATURE_LEN, \"ML-DSA-65 signature\");\n const pk = expectBytes(publicKey, ML_DSA_65_PUBLIC_KEY_LEN, \"ML-DSA-65 public key\");\n const w = new BincodeWriter();\n w.u64(n.chainId);\n w.u64(n.nonce);\n // Amount(U256) goes through alloy's ruint serde, which emits\n // `serialize_bytes(&to_be_bytes_vec())` for non-human-readable\n // serializers. bincode 1.x renders that as `u64(len) || 32 bytes BE`.\n // Address inside Option<Address> takes the same `serialize_bytes`\n // path via alloy's FixedBytes impl, so admin-tag(1) is followed by a\n // length-prefixed 20-byte payload, not a raw 20-byte run.\n w.bytes(uint256Be(n.maxPriorityFeePerGas, \"maxPriorityFeePerGas\"));\n w.bytes(uint256Be(n.maxFeePerGas, \"maxFeePerGas\"));\n w.u64(n.gasLimit);\n if (n.to === null) {\n w.u8(0);\n } else {\n w.u8(1);\n w.bytes(n.to);\n }\n w.bytes(uint256Be(n.value, \"value\"));\n w.bytes(n.input);\n w.u64(0n); // access_list length\n w.u64(BigInt(n.extensions.length));\n for (const ext of n.extensions) bincodeTypedExtensionInto(w, ext);\n bincodeMlDsa65OpaqueInto(w, sig);\n bincodeMlDsa65OpaqueInto(w, pk);\n return w.toBytes();\n}\n\ninterface NormalizedNativeTxExtension {\n kind: number;\n body: Uint8Array;\n}\n\ninterface NormalizedNativeEvmTxFields {\n chainId: bigint;\n nonce: bigint;\n maxPriorityFeePerGas: bigint;\n maxFeePerGas: bigint;\n gasLimit: bigint;\n to: Uint8Array | null;\n value: bigint;\n input: Uint8Array;\n extensions: NormalizedNativeTxExtension[];\n}\n\nfunction normalizeTxFields(fields: NativeEvmTxFields): NormalizedNativeEvmTxFields {\n return {\n chainId: parseBigint(fields.chainId, \"chainId\"),\n nonce: parseBigint(fields.nonce, \"nonce\"),\n maxPriorityFeePerGas: parseBigint(fields.maxPriorityFeePerGas, \"maxPriorityFeePerGas\"),\n maxFeePerGas: parseBigint(fields.maxFeePerGas, \"maxFeePerGas\"),\n gasLimit: parseBigint(fields.gasLimit, \"gasLimit\"),\n to: normalizeTo(fields.to),\n value: parseBigint(fields.value, \"value\"),\n input: normalizeBytes(fields.input ?? new Uint8Array(0), \"input\"),\n extensions: normalizeExtensions(fields.extensions),\n };\n}\n\nfunction normalizeTo(value: NativeEvmTxFields[\"to\"]): Uint8Array | null {\n if (value === null) return null;\n const bytes = normalizeBytes(value, \"to\");\n return expectBytes(bytes, 20, \"to\");\n}\n\nfunction normalizeBytes(value: Uint8Array | readonly number[] | string, label: string): Uint8Array {\n if (typeof value === \"string\") return hexToBytes(value, label);\n return value instanceof Uint8Array ? value : Uint8Array.from(value);\n}\n\nfunction normalizeExtensions(value: NativeEvmTxFields[\"extensions\"]): NormalizedNativeTxExtension[] {\n if (value === undefined) return [];\n return value.map((ext, index) => {\n if (!Number.isInteger(ext.kind) || ext.kind < 0 || ext.kind > 0xff) {\n throw new Error(`extensions[${index}].kind out of u8 range`);\n }\n const body = normalizeBytes(\"bodyHex\" in ext ? ext.bodyHex : ext.body, `extensions[${index}].body`);\n if (body.length > 0xffff_ffff) {\n throw new Error(`extensions[${index}].body exceeds u32 length`);\n }\n return { kind: ext.kind, body };\n });\n}\n\nfunction encodeExtensionsForHash(extensions: readonly NormalizedNativeTxExtension[]): Uint8Array {\n const chunks: Uint8Array[] = [bigintToBeBytes(BigInt(extensions.length), 4, \"extensions.length\")];\n for (const ext of extensions) {\n chunks.push(\n Uint8Array.of(ext.kind),\n bigintToBeBytes(BigInt(ext.body.length), 4, \"extension.body.length\"),\n ext.body,\n );\n }\n return concatBytes(...chunks);\n}\n\nfunction uint256Be(value: bigint, label: string): Uint8Array {\n if (value < 0n || value >= 1n << 256n) throw new Error(`${label} out of u256 range`);\n const out = new Uint8Array(32);\n let v = value;\n for (let i = 31; i >= 0; i--) {\n out[i] = Number(v & 0xffn);\n v >>= 8n;\n }\n return out;\n}\n\nfunction bincodeMlDsa65OpaqueInto(w: BincodeWriter, raw: Uint8Array): void {\n w.enumVariant(ENUM_VARIANT_INDEX_ML_DSA_65);\n w.u16(STANDARD_ALGO_NUMBER_ML_DSA_65);\n w.bytes(raw);\n}\n\nfunction bincodeTypedExtensionInto(w: BincodeWriter, ext: NormalizedNativeTxExtension): void {\n w.u8(ext.kind);\n w.bytes(ext.body);\n}\n","import { ml_dsa65 } from \"@noble/post-quantum/ml-dsa.js\";\nimport { blake3 } from \"@noble/hashes/blake3.js\";\nimport { keccak_256 } from \"@noble/hashes/sha3.js\";\nimport { bigintToBeBytes, bytesToHex, concatBytes, expectBytes } from \"./bytes.js\";\nimport { bincodeSignedTransaction, encodeTransactionForHash, type NativeEvmTxFields } from \"./tx.js\";\n\nexport const ML_DSA_65_SEED_LEN = 32;\nexport const ML_DSA_65_SIGNING_KEY_LEN = 4032;\nexport const ML_DSA_65_PUBLIC_KEY_LEN = 1952;\nexport const ML_DSA_65_SIGNATURE_LEN = 3309;\nexport const STANDARD_ALGO_NUMBER_ML_DSA_65 = 1001;\nexport const ENUM_VARIANT_INDEX_ML_DSA_65 = 3;\nexport const ADDRESS_DERIVATION_DOMAIN = \"MONO_ADDRESS_BLAKE3_20_V1\";\n\nconst ADDRESS_DERIVATION_DOMAIN_BYTES = new TextEncoder().encode(ADDRESS_DERIVATION_DOMAIN);\n\nexport class MlDsa65Backend {\n readonly #secretKey: Uint8Array;\n readonly #publicKey: Uint8Array;\n readonly #addressBytes: Uint8Array;\n #disposed = false;\n\n private constructor(secretKey: Uint8Array, publicKey: Uint8Array) {\n this.#secretKey = expectBytes(secretKey, ML_DSA_65_SIGNING_KEY_LEN, \"ML-DSA-65 secret key\").slice();\n this.#publicKey = expectBytes(publicKey, ML_DSA_65_PUBLIC_KEY_LEN, \"ML-DSA-65 public key\").slice();\n this.#addressBytes = mlDsa65AddressBytes(this.#publicKey);\n }\n\n static fromSeed(seed: Uint8Array | readonly number[]): MlDsa65Backend {\n const kp = ml_dsa65.keygen(expectBytes(seed, ML_DSA_65_SEED_LEN, \"ML-DSA-65 seed\"));\n return new MlDsa65Backend(kp.secretKey, kp.publicKey);\n }\n\n publicKey(): Uint8Array {\n return this.#publicKey.slice();\n }\n\n addressBytes(): Uint8Array {\n return this.#addressBytes.slice();\n }\n\n getAddress(): string {\n return bytesToHex(this.#addressBytes);\n }\n\n sign(message: Uint8Array): Uint8Array {\n if (this.#disposed) {\n throw new Error(\"MlDsa65Backend disposed\");\n }\n return ml_dsa65.sign(message, this.#secretKey, { extraEntropy: false });\n }\n\n /**\n * Best-effort deterministic wipe of the in-memory secret key. Zeroes the\n * SDK-held `#secretKey` copy and makes any subsequent `sign()` /\n * `signPrehash()` / `signEvmTx()` throw `\"MlDsa65Backend disposed\"` rather\n * than signing with a zeroed key. Idempotent. Public material\n * (`publicKey()` / `getAddress()` / `verify()`) stays usable.\n *\n * Defense-in-depth (S1-01): narrows the post-lock residency window of the\n * ML-DSA-65 secret in the JS heap. `@noble/post-quantum`'s internal\n * transient keygen/sign buffers are out of scope; the SDK-held copy is the\n * meaningful residency win.\n */\n dispose(): void {\n this.#secretKey.fill(0);\n this.#disposed = true;\n }\n\n /** Alias for {@link dispose}. */\n zeroize(): void {\n this.dispose();\n }\n\n /** Whether {@link dispose} has been called (the secret key is wiped). */\n get disposed(): boolean {\n return this.#disposed;\n }\n\n signPrehash(digest: Uint8Array): Uint8Array {\n return this.sign(expectBytes(digest, 32, \"prehash\"));\n }\n\n verify(message: Uint8Array, signature: Uint8Array): boolean {\n return ml_dsa65.verify(\n expectBytes(signature, ML_DSA_65_SIGNATURE_LEN, \"ML-DSA-65 signature\"),\n message,\n this.#publicKey,\n );\n }\n\n signEvmTx(fields: NativeEvmTxFields): {\n wireHex: string;\n wireBytes: Uint8Array;\n sighash: Uint8Array;\n txHash: Uint8Array;\n } {\n const txHashPreimage = encodeTransactionForHash(fields, 0x01);\n const sighash = keccak_256(txHashPreimage);\n const signature = this.sign(sighash);\n const wireBytes = bincodeSignedTransaction(fields, signature, this.#publicKey);\n const txHash = keccak_256(\n concatBytes(\n encodeTransactionForHash(fields, 0x02),\n signature,\n this.#publicKey,\n ),\n );\n return {\n wireHex: bytesToHex(wireBytes).slice(2),\n wireBytes,\n sighash,\n txHash,\n };\n }\n}\n\nexport function mlDsa65AddressFromPublicKey(publicKey: Uint8Array | readonly number[]): string {\n return bytesToHex(mlDsa65AddressBytes(publicKey));\n}\n\nexport function mlDsa65AddressBytes(publicKey: Uint8Array | readonly number[]): Uint8Array {\n const bytes = expectBytes(publicKey, ML_DSA_65_PUBLIC_KEY_LEN, \"ML-DSA-65 public key\");\n return blake3(concatBytes(\n ADDRESS_DERIVATION_DOMAIN_BYTES,\n bigintToBeBytes(BigInt(STANDARD_ALGO_NUMBER_ML_DSA_65), 2, \"ML-DSA-65 algo id\"),\n bytes,\n )).slice(0, 20);\n}\n\nexport function encodeMlDsa65Opaque(raw: Uint8Array | readonly number[]): Uint8Array {\n const bytes = raw instanceof Uint8Array ? raw : Uint8Array.from(raw);\n const len = bytes.length === ML_DSA_65_PUBLIC_KEY_LEN ? ML_DSA_65_PUBLIC_KEY_LEN : ML_DSA_65_SIGNATURE_LEN;\n expectBytes(bytes, len, \"ML-DSA-65 opaque bytes\");\n const out = new Uint8Array(4 + 2 + 8 + bytes.length);\n const dv = new DataView(out.buffer);\n dv.setUint32(0, ENUM_VARIANT_INDEX_ML_DSA_65, true);\n dv.setUint16(4, STANDARD_ALGO_NUMBER_ML_DSA_65, true);\n dv.setBigUint64(6, BigInt(bytes.length), true);\n out.set(bytes, 14);\n return out;\n}\n\nexport function uint256Bytes(value: bigint | number | string, label: string): Uint8Array {\n const v = typeof value === \"bigint\" ? value : typeof value === \"number\" ? BigInt(value) : BigInt(value);\n return bigintToBeBytes(v, 32, label);\n}\n","import { shake256 } from \"@noble/hashes/sha3.js\";\nimport {\n entropyToMnemonic,\n mnemonicToSeedSync,\n validateMnemonic as bip39ValidateMnemonic,\n} from \"@scure/bip39\";\nimport { wordlist } from \"@scure/bip39/wordlists/english.js\";\nimport { concatBytes } from \"./bytes.js\";\nimport { ML_DSA_65_SEED_LEN, MlDsa65Backend } from \"./ml-dsa.js\";\n\n/**\n * Standard BIP-39 -> ML-DSA-65 wallet key derivation.\n *\n * A wallet mnemonic is a plain 24-word English BIP-39 phrase (256-bit /\n * 32-byte entropy) with NO custom header bytes. The signing seed is derived\n * from the standard BIP-39 PBKDF2 seed via a domain-separated SHAKE256:\n *\n * seed64 = BIP-39 PBKDF2 seed = mnemonicToSeedSync(mnemonic, \"\")\n * (HMAC-SHA512, 2048 rounds, 64 bytes)\n * mldsa65Seed = shake256( utf8(\"monolythium.mldsa65.v1\") || seed64,\n * { dkLen: 32 } )\n *\n * `MlDsa65Backend.fromSeed(mldsa65Seed)` then yields the deterministic\n * ML-DSA-65 keypair / address. This is the SDK foundation imported by every\n * wallet + monarch-desktop through `@monolythium/core-sdk/crypto`.\n */\n\n/** Number of words in a Monolythium wallet mnemonic (256-bit BIP-39). */\nexport const MLDSA65_MNEMONIC_WORDS = 24;\n/** Domain-separation tag mixed into the ML-DSA-65 seed derivation. */\nexport const MLDSA65_SEED_DOMAIN = \"monolythium.mldsa65.v1\";\n\n/** BIP-39 entropy length backing a 24-word mnemonic (32 bytes => 256 bits). */\nconst MLDSA65_ENTROPY_LEN = 32;\n\nconst DOMAIN_BYTES = new TextEncoder().encode(MLDSA65_SEED_DOMAIN);\n\nexport type MnemonicErrorKind = \"badWordCount\" | \"bip39Decode\" | \"missingRandom\";\n\nexport class MnemonicError extends Error {\n constructor(\n readonly kind: MnemonicErrorKind,\n message: string,\n ) {\n super(message);\n this.name = \"MnemonicError\";\n }\n}\n\nexport type MnemonicRng = (bytes: Uint8Array) => void;\n\n/**\n * Normalize a mnemonic for validation/derivation: trim, lowercase, and\n * collapse any internal whitespace run to a single ASCII space.\n */\nfunction normalizeMnemonic(mnemonic: string): string {\n return mnemonic.trim().toLowerCase().replace(/\\s+/g, \" \");\n}\n\nfunction wordCount(normalized: string): number {\n return normalized.length === 0 ? 0 : normalized.split(\" \").length;\n}\n\nfunction defaultRandomFill(bytes: Uint8Array): void {\n const cryptoObj = globalThis.crypto;\n if (!cryptoObj?.getRandomValues) {\n throw new MnemonicError(\"missingRandom\", \"globalThis.crypto.getRandomValues is unavailable\");\n }\n cryptoObj.getRandomValues(bytes);\n}\n\n/** Generate a fresh 24-word BIP-39 mnemonic from 32 bytes of entropy. */\nexport function generateMnemonic(rng: MnemonicRng = defaultRandomFill): string {\n const entropy = new Uint8Array(MLDSA65_ENTROPY_LEN);\n rng(entropy);\n return entropyToMnemonic(entropy, wordlist);\n}\n\n/**\n * Returns `true` only when `mnemonic` is exactly 24 words AND passes the\n * BIP-39 wordlist + checksum validation.\n */\nexport function validateMnemonic(mnemonic: string): boolean {\n const normalized = normalizeMnemonic(mnemonic);\n if (wordCount(normalized) !== MLDSA65_MNEMONIC_WORDS) {\n return false;\n }\n return bip39ValidateMnemonic(normalized, wordlist);\n}\n\n/**\n * Derive the 32-byte ML-DSA-65 seed from a 24-word BIP-39 mnemonic.\n * Throws a typed {@link MnemonicError} when the input is not a valid 24-word\n * mnemonic.\n */\nexport function mnemonicToMlDsa65Seed(mnemonic: string): Uint8Array {\n const normalized = normalizeMnemonic(mnemonic);\n const words = wordCount(normalized);\n if (words !== MLDSA65_MNEMONIC_WORDS) {\n throw new MnemonicError(\n \"badWordCount\",\n `mnemonic must be ${MLDSA65_MNEMONIC_WORDS} words, got ${words}`,\n );\n }\n if (!bip39ValidateMnemonic(normalized, wordlist)) {\n throw new MnemonicError(\n \"bip39Decode\",\n \"invalid BIP-39 mnemonic (unknown word or bad checksum)\",\n );\n }\n const seed64 = mnemonicToSeedSync(normalized, \"\");\n return shake256(concatBytes(DOMAIN_BYTES, seed64), { dkLen: ML_DSA_65_SEED_LEN });\n}\n\n/** Derive the ML-DSA-65 signing backend from a 24-word BIP-39 mnemonic. */\nexport function mnemonicToMlDsa65Backend(mnemonic: string): MlDsa65Backend {\n return MlDsa65Backend.fromSeed(mnemonicToMlDsa65Seed(mnemonic));\n}\n\n/** Derive the wallet address (0x-hex) from a 24-word BIP-39 mnemonic. */\nexport function mnemonicToAddress(mnemonic: string): string {\n return mnemonicToMlDsa65Backend(mnemonic).getAddress();\n}\n","/**\n * Mempool transaction-class tags.\n *\n * The encrypted-mempool (LythiumSeal) envelope was removed at the v2\n * re-genesis; plaintext submission is the sole submit path. This module now\n * carries only the {@link MempoolClass} tag the node uses to classify a\n * transaction for ordering/admission.\n */\n\nexport const MempoolClass = {\n Transfer: 0,\n ContractCall: 1,\n PrivacyOp: 2,\n CLOBOp: 3,\n AgentOp: 4,\n FoundationOp: 5,\n /** @deprecated Use FoundationOp. */\n GovernanceOp: 5,\n RWAOp: 6,\n} as const;\nexport type MempoolClass = (typeof MempoolClass)[keyof typeof MempoolClass];\n","import { bytesToHex, hexToBytes } from \"./bytes.js\";\nimport type { MlDsa65Backend } from \"./ml-dsa.js\";\nimport type { NativeEvmTxFields } from \"./tx.js\";\n\nexport interface JsonRpcCallClient {\n call<T>(method: string, params?: unknown): Promise<T>;\n}\n\n/**\n * A built plaintext submission — the bincode-encoded chain-side\n * `SignedTransaction` (`0x`-prefixed hex) ready to hand to\n * `mesh_submitTx`, plus the canonical hashes the wallet validates the\n * node echo against.\n *\n * Mirrors the chain-side artefacts produced by the Rust SDK's\n * `build_chain_signed_tx` (`mono-core/crates/core/sdk/src/tx.rs`): the\n * ML-DSA-65 signature is taken over the canonical chain-side `sighash`\n * (keccak-256 of the 0x01-tagged preimage) and the canonical native tx\n * hash is the keccak-256 of the 0x02-tagged preimage with the signature\n * and public key appended.\n */\nexport interface PlaintextSubmission {\n /** Bincode `SignedTransaction` wire bytes, `0x`-prefixed. */\n signedTxWireHex: string;\n /** Canonical native tx hash the node echoes on admission. */\n innerTxHashHex: string;\n /** Canonical chain-side sighash that was signed. */\n innerSighashHex: string;\n /** Length in bytes of the bincode `SignedTransaction`. */\n innerWireBytes: number;\n}\n\n/**\n * Build a PLAINTEXT submission — the sole submit path since the v2\n * re-genesis dropped the encrypted (LythiumSeal) mempool.\n *\n * It re-shapes the native tx into the chain-side `SignedTransaction`,\n * signs over the canonical `sighash` with the ML-DSA-65 backend,\n * bincode-serializes the result, and `0x`-hex-encodes it. The bytes are\n * forwarded verbatim through `mesh_submitTx` (the node routes them to\n * `MempoolTx::plaintext` via `submit_raw`).\n *\n * Mirrors `TxClient::submit_plaintext` in the Rust SDK.\n */\nexport function buildPlaintextSubmission(args: {\n backend: MlDsa65Backend;\n tx: NativeEvmTxFields;\n}): PlaintextSubmission {\n const signed = args.backend.signEvmTx(args.tx);\n return {\n signedTxWireHex: `0x${signed.wireHex}`,\n innerTxHashHex: bytesToHex(signed.txHash),\n innerSighashHex: bytesToHex(signed.sighash),\n innerWireBytes: signed.wireBytes.length,\n };\n}\n\n/**\n * Submit a bincode-encoded chain-side `SignedTransaction` (`0x`-hex)\n * through the plaintext `mesh_submitTx` path and validate the node's\n * echoed canonical tx hash against the locally computed one.\n *\n * Mirrors the validation in `TxClient::submit_plaintext`: the node\n * echoes the 32-byte canonical native tx hash on admission, and any\n * mismatch (or non-32-byte response) is rejected loud so a wallet never\n * trusts a hash it did not derive itself.\n *\n * @returns the validated canonical native tx hash (`0x`-prefixed).\n */\nexport async function submitPlaintextTransaction(\n client: JsonRpcCallClient,\n signedTxWireHex: string,\n expectedTxHashHex: string,\n): Promise<string> {\n const returned = await client.call<string>(\"mesh_submitTx\", [signedTxWireHex]);\n const returnedBytes = hexToBytes(returned, \"mesh_submitTx tx hash\");\n if (returnedBytes.length !== 32) {\n throw new Error(\n `mesh_submitTx tx hash must be 32 bytes, got ${returnedBytes.length}`,\n );\n }\n const expectedBytes = hexToBytes(expectedTxHashHex, \"expected tx hash\");\n if (!bytesEqual(returnedBytes, expectedBytes)) {\n throw new Error(\n `mesh_submitTx returned tx hash ${bytesToHex(returnedBytes)} but the locally computed canonical hash is ${bytesToHex(expectedBytes)}`,\n );\n }\n return bytesToHex(returnedBytes);\n}\n\n/**\n * Build, sign, and submit a native transaction through the plaintext\n * `mesh_submitTx` path.\n *\n * Mirrors `TxClient::build_sign_submit` in the Rust SDK. The encrypted\n * (LythiumSeal) submit path was removed at the v2 re-genesis, so this is\n * the single build-sign-submit entry point.\n *\n * @returns the node-echoed-and-validated canonical native tx hash\n * (`0x`-prefixed).\n */\nexport async function submitTransaction(args: {\n client: JsonRpcCallClient;\n backend: MlDsa65Backend;\n tx: NativeEvmTxFields;\n}): Promise<string> {\n const plaintext = buildPlaintextSubmission({ backend: args.backend, tx: args.tx });\n return submitPlaintextTransaction(\n args.client,\n plaintext.signedTxWireHex,\n plaintext.innerTxHashHex,\n );\n}\n\nfunction bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n if (a.length !== b.length) return false;\n for (let i = 0; i < a.length; i++) {\n if (a[i] !== b[i]) return false;\n }\n return true;\n}\n"]}
|
package/dist/crypto/index.d.cts
CHANGED
|
@@ -20,36 +20,49 @@ declare function bytesToHex(bytes: Uint8Array): string;
|
|
|
20
20
|
declare function hexToBytes(hex: string, label?: string): Uint8Array;
|
|
21
21
|
declare function expectBytes(value: Uint8Array | readonly number[], len: number, label: string): Uint8Array;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Standard BIP-39 -> ML-DSA-65 wallet key derivation.
|
|
25
|
+
*
|
|
26
|
+
* A wallet mnemonic is a plain 24-word English BIP-39 phrase (256-bit /
|
|
27
|
+
* 32-byte entropy) with NO custom header bytes. The signing seed is derived
|
|
28
|
+
* from the standard BIP-39 PBKDF2 seed via a domain-separated SHAKE256:
|
|
29
|
+
*
|
|
30
|
+
* seed64 = BIP-39 PBKDF2 seed = mnemonicToSeedSync(mnemonic, "")
|
|
31
|
+
* (HMAC-SHA512, 2048 rounds, 64 bytes)
|
|
32
|
+
* mldsa65Seed = shake256( utf8("monolythium.mldsa65.v1") || seed64,
|
|
33
|
+
* { dkLen: 32 } )
|
|
34
|
+
*
|
|
35
|
+
* `MlDsa65Backend.fromSeed(mldsa65Seed)` then yields the deterministic
|
|
36
|
+
* ML-DSA-65 keypair / address. This is the SDK foundation imported by every
|
|
37
|
+
* wallet + monarch-desktop through `@monolythium/core-sdk/crypto`.
|
|
38
|
+
*/
|
|
39
|
+
/** Number of words in a Monolythium wallet mnemonic (256-bit BIP-39). */
|
|
40
|
+
declare const MLDSA65_MNEMONIC_WORDS = 24;
|
|
41
|
+
/** Domain-separation tag mixed into the ML-DSA-65 seed derivation. */
|
|
42
|
+
declare const MLDSA65_SEED_DOMAIN = "monolythium.mldsa65.v1";
|
|
43
|
+
type MnemonicErrorKind = "badWordCount" | "bip39Decode" | "missingRandom";
|
|
44
|
+
declare class MnemonicError extends Error {
|
|
45
|
+
readonly kind: MnemonicErrorKind;
|
|
46
|
+
constructor(kind: MnemonicErrorKind, message: string);
|
|
42
47
|
}
|
|
43
|
-
type
|
|
44
|
-
|
|
45
|
-
declare function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
declare function
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
type MnemonicRng = (bytes: Uint8Array) => void;
|
|
49
|
+
/** Generate a fresh 24-word BIP-39 mnemonic from 32 bytes of entropy. */
|
|
50
|
+
declare function generateMnemonic(rng?: MnemonicRng): string;
|
|
51
|
+
/**
|
|
52
|
+
* Returns `true` only when `mnemonic` is exactly 24 words AND passes the
|
|
53
|
+
* BIP-39 wordlist + checksum validation.
|
|
54
|
+
*/
|
|
55
|
+
declare function validateMnemonic(mnemonic: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Derive the 32-byte ML-DSA-65 seed from a 24-word BIP-39 mnemonic.
|
|
58
|
+
* Throws a typed {@link MnemonicError} when the input is not a valid 24-word
|
|
59
|
+
* mnemonic.
|
|
60
|
+
*/
|
|
61
|
+
declare function mnemonicToMlDsa65Seed(mnemonic: string): Uint8Array;
|
|
62
|
+
/** Derive the ML-DSA-65 signing backend from a 24-word BIP-39 mnemonic. */
|
|
63
|
+
declare function mnemonicToMlDsa65Backend(mnemonic: string): MlDsa65Backend;
|
|
64
|
+
/** Derive the wallet address (0x-hex) from a 24-word BIP-39 mnemonic. */
|
|
65
|
+
declare function mnemonicToAddress(mnemonic: string): string;
|
|
53
66
|
|
|
54
67
|
interface JsonRpcCallClient {
|
|
55
68
|
call<T>(method: string, params?: unknown): Promise<T>;
|
|
@@ -123,4 +136,4 @@ declare function submitTransaction(args: {
|
|
|
123
136
|
tx: NativeEvmTxFields;
|
|
124
137
|
}): Promise<string>;
|
|
125
138
|
|
|
126
|
-
export { BincodeWriter, type JsonRpcCallClient,
|
|
139
|
+
export { BincodeWriter, type JsonRpcCallClient, MLDSA65_MNEMONIC_WORDS, MLDSA65_SEED_DOMAIN, MlDsa65Backend, MnemonicError, type MnemonicErrorKind, type MnemonicRng, NativeEvmTxFields, type PlaintextSubmission, buildPlaintextSubmission, bytesToHex, concatBytes, expectBytes, generateMnemonic, hexToBytes, mnemonicToAddress, mnemonicToMlDsa65Backend, mnemonicToMlDsa65Seed, submitPlaintextTransaction, submitTransaction, validateMnemonic };
|
package/dist/crypto/index.d.ts
CHANGED
|
@@ -20,36 +20,49 @@ declare function bytesToHex(bytes: Uint8Array): string;
|
|
|
20
20
|
declare function hexToBytes(hex: string, label?: string): Uint8Array;
|
|
21
21
|
declare function expectBytes(value: Uint8Array | readonly number[], len: number, label: string): Uint8Array;
|
|
22
22
|
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
23
|
+
/**
|
|
24
|
+
* Standard BIP-39 -> ML-DSA-65 wallet key derivation.
|
|
25
|
+
*
|
|
26
|
+
* A wallet mnemonic is a plain 24-word English BIP-39 phrase (256-bit /
|
|
27
|
+
* 32-byte entropy) with NO custom header bytes. The signing seed is derived
|
|
28
|
+
* from the standard BIP-39 PBKDF2 seed via a domain-separated SHAKE256:
|
|
29
|
+
*
|
|
30
|
+
* seed64 = BIP-39 PBKDF2 seed = mnemonicToSeedSync(mnemonic, "")
|
|
31
|
+
* (HMAC-SHA512, 2048 rounds, 64 bytes)
|
|
32
|
+
* mldsa65Seed = shake256( utf8("monolythium.mldsa65.v1") || seed64,
|
|
33
|
+
* { dkLen: 32 } )
|
|
34
|
+
*
|
|
35
|
+
* `MlDsa65Backend.fromSeed(mldsa65Seed)` then yields the deterministic
|
|
36
|
+
* ML-DSA-65 keypair / address. This is the SDK foundation imported by every
|
|
37
|
+
* wallet + monarch-desktop through `@monolythium/core-sdk/crypto`.
|
|
38
|
+
*/
|
|
39
|
+
/** Number of words in a Monolythium wallet mnemonic (256-bit BIP-39). */
|
|
40
|
+
declare const MLDSA65_MNEMONIC_WORDS = 24;
|
|
41
|
+
/** Domain-separation tag mixed into the ML-DSA-65 seed derivation. */
|
|
42
|
+
declare const MLDSA65_SEED_DOMAIN = "monolythium.mldsa65.v1";
|
|
43
|
+
type MnemonicErrorKind = "badWordCount" | "bip39Decode" | "missingRandom";
|
|
44
|
+
declare class MnemonicError extends Error {
|
|
45
|
+
readonly kind: MnemonicErrorKind;
|
|
46
|
+
constructor(kind: MnemonicErrorKind, message: string);
|
|
42
47
|
}
|
|
43
|
-
type
|
|
44
|
-
|
|
45
|
-
declare function
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
declare function
|
|
51
|
-
|
|
52
|
-
|
|
48
|
+
type MnemonicRng = (bytes: Uint8Array) => void;
|
|
49
|
+
/** Generate a fresh 24-word BIP-39 mnemonic from 32 bytes of entropy. */
|
|
50
|
+
declare function generateMnemonic(rng?: MnemonicRng): string;
|
|
51
|
+
/**
|
|
52
|
+
* Returns `true` only when `mnemonic` is exactly 24 words AND passes the
|
|
53
|
+
* BIP-39 wordlist + checksum validation.
|
|
54
|
+
*/
|
|
55
|
+
declare function validateMnemonic(mnemonic: string): boolean;
|
|
56
|
+
/**
|
|
57
|
+
* Derive the 32-byte ML-DSA-65 seed from a 24-word BIP-39 mnemonic.
|
|
58
|
+
* Throws a typed {@link MnemonicError} when the input is not a valid 24-word
|
|
59
|
+
* mnemonic.
|
|
60
|
+
*/
|
|
61
|
+
declare function mnemonicToMlDsa65Seed(mnemonic: string): Uint8Array;
|
|
62
|
+
/** Derive the ML-DSA-65 signing backend from a 24-word BIP-39 mnemonic. */
|
|
63
|
+
declare function mnemonicToMlDsa65Backend(mnemonic: string): MlDsa65Backend;
|
|
64
|
+
/** Derive the wallet address (0x-hex) from a 24-word BIP-39 mnemonic. */
|
|
65
|
+
declare function mnemonicToAddress(mnemonic: string): string;
|
|
53
66
|
|
|
54
67
|
interface JsonRpcCallClient {
|
|
55
68
|
call<T>(method: string, params?: unknown): Promise<T>;
|
|
@@ -123,4 +136,4 @@ declare function submitTransaction(args: {
|
|
|
123
136
|
tx: NativeEvmTxFields;
|
|
124
137
|
}): Promise<string>;
|
|
125
138
|
|
|
126
|
-
export { BincodeWriter, type JsonRpcCallClient,
|
|
139
|
+
export { BincodeWriter, type JsonRpcCallClient, MLDSA65_MNEMONIC_WORDS, MLDSA65_SEED_DOMAIN, MlDsa65Backend, MnemonicError, type MnemonicErrorKind, type MnemonicRng, NativeEvmTxFields, type PlaintextSubmission, buildPlaintextSubmission, bytesToHex, concatBytes, expectBytes, generateMnemonic, hexToBytes, mnemonicToAddress, mnemonicToMlDsa65Backend, mnemonicToMlDsa65Seed, submitPlaintextTransaction, submitTransaction, validateMnemonic };
|