@rougechain/sdk 0.7.0 → 0.8.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.cjs +75 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +72 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.cjs
CHANGED
|
@@ -2,6 +2,10 @@
|
|
|
2
2
|
|
|
3
3
|
var mlDsa_js = require('@noble/post-quantum/ml-dsa.js');
|
|
4
4
|
var sha2 = require('@noble/hashes/sha2');
|
|
5
|
+
var bip39 = require('@scure/bip39');
|
|
6
|
+
var english_js = require('@scure/bip39/wordlists/english.js');
|
|
7
|
+
var hkdf_js = require('@noble/hashes/hkdf.js');
|
|
8
|
+
var sha2_js = require('@noble/hashes/sha2.js');
|
|
5
9
|
|
|
6
10
|
// src/signer.ts
|
|
7
11
|
|
|
@@ -461,6 +465,19 @@ var RougeChain = class {
|
|
|
461
465
|
async getBurnedTokens() {
|
|
462
466
|
return this.get("/burned");
|
|
463
467
|
}
|
|
468
|
+
// ===== Address Resolution =====
|
|
469
|
+
/**
|
|
470
|
+
* Resolve a rouge1… address to its public key, or a public key to its rouge1 address.
|
|
471
|
+
* Uses the persistent on-chain address index for O(1) lookups.
|
|
472
|
+
*/
|
|
473
|
+
async resolveAddress(input) {
|
|
474
|
+
return this.get(`/resolve/${encodeURIComponent(input)}`);
|
|
475
|
+
}
|
|
476
|
+
// ===== Nonce =====
|
|
477
|
+
/** Get the current sequential nonce for an account. */
|
|
478
|
+
async getNonce(publicKey) {
|
|
479
|
+
return this.get(`/account/${encodeURIComponent(publicKey)}/nonce`);
|
|
480
|
+
}
|
|
464
481
|
// ===== Write operations =====
|
|
465
482
|
async transfer(wallet, params) {
|
|
466
483
|
const tx = createSignedTransfer(
|
|
@@ -1195,24 +1212,69 @@ function formatAddress(address, prefixLen = 12, suffixLen = 4) {
|
|
|
1195
1212
|
if (address.length <= prefixLen + suffixLen + 3) return address;
|
|
1196
1213
|
return `${address.slice(0, prefixLen)}...${address.slice(-suffixLen)}`;
|
|
1197
1214
|
}
|
|
1215
|
+
var DOMAIN_INFO = new TextEncoder().encode("rougechain-ml-dsa-65-v1");
|
|
1216
|
+
function generateMnemonic(strength = 256) {
|
|
1217
|
+
return bip39.generateMnemonic(english_js.wordlist, strength);
|
|
1218
|
+
}
|
|
1219
|
+
function validateMnemonic(mnemonic) {
|
|
1220
|
+
return bip39.validateMnemonic(mnemonic, english_js.wordlist);
|
|
1221
|
+
}
|
|
1222
|
+
function mnemonicToMLDSASeed(mnemonic, passphrase) {
|
|
1223
|
+
const bip39Seed = bip39.mnemonicToSeedSync(mnemonic, passphrase);
|
|
1224
|
+
return hkdf_js.hkdf(sha2_js.sha256, bip39Seed, void 0, DOMAIN_INFO, 32);
|
|
1225
|
+
}
|
|
1226
|
+
function keypairFromMnemonic(mnemonic, passphrase) {
|
|
1227
|
+
if (!validateMnemonic(mnemonic)) {
|
|
1228
|
+
throw new Error("Invalid mnemonic phrase");
|
|
1229
|
+
}
|
|
1230
|
+
const seed = mnemonicToMLDSASeed(mnemonic, passphrase);
|
|
1231
|
+
const keypair = mlDsa_js.ml_dsa65.keygen(seed);
|
|
1232
|
+
return {
|
|
1233
|
+
publicKey: bytesToHex(keypair.publicKey),
|
|
1234
|
+
secretKey: bytesToHex(keypair.secretKey)
|
|
1235
|
+
};
|
|
1236
|
+
}
|
|
1198
1237
|
|
|
1199
1238
|
// src/wallet.ts
|
|
1200
1239
|
var Wallet = class _Wallet {
|
|
1201
|
-
constructor(publicKey, privateKey) {
|
|
1240
|
+
constructor(publicKey, privateKey, mnemonic) {
|
|
1202
1241
|
this.publicKey = publicKey;
|
|
1203
1242
|
this.privateKey = privateKey;
|
|
1243
|
+
this.mnemonic = mnemonic;
|
|
1244
|
+
}
|
|
1245
|
+
/**
|
|
1246
|
+
* Generate a new ML-DSA-65 keypair with a BIP-39 mnemonic.
|
|
1247
|
+
* The mnemonic is stored on the wallet for backup/recovery.
|
|
1248
|
+
* @param strength 128 = 12 words (default), 256 = 24 words
|
|
1249
|
+
*/
|
|
1250
|
+
static generate(strength = 128) {
|
|
1251
|
+
const mnemonic = generateMnemonic(strength);
|
|
1252
|
+
const { publicKey, secretKey } = keypairFromMnemonic(mnemonic);
|
|
1253
|
+
return new _Wallet(publicKey, secretKey, mnemonic);
|
|
1204
1254
|
}
|
|
1205
1255
|
/**
|
|
1206
|
-
* Generate a
|
|
1207
|
-
*
|
|
1256
|
+
* Generate a wallet using pure random entropy (no mnemonic).
|
|
1257
|
+
* Keys cannot be recovered from a seed phrase.
|
|
1208
1258
|
*/
|
|
1209
|
-
static
|
|
1259
|
+
static generateRandom() {
|
|
1210
1260
|
const keypair = mlDsa_js.ml_dsa65.keygen();
|
|
1211
1261
|
return new _Wallet(
|
|
1212
1262
|
bytesToHex(keypair.publicKey),
|
|
1213
1263
|
bytesToHex(keypair.secretKey)
|
|
1214
1264
|
);
|
|
1215
1265
|
}
|
|
1266
|
+
/**
|
|
1267
|
+
* Restore a wallet from a BIP-39 mnemonic seed phrase.
|
|
1268
|
+
* @param mnemonic 12 or 24 word BIP-39 mnemonic
|
|
1269
|
+
* @param passphrase Optional BIP-39 passphrase (25th word)
|
|
1270
|
+
*/
|
|
1271
|
+
static fromMnemonic(mnemonic, passphrase) {
|
|
1272
|
+
if (!validateMnemonic(mnemonic)) {
|
|
1273
|
+
throw new Error("Invalid mnemonic phrase");
|
|
1274
|
+
}
|
|
1275
|
+
const { publicKey, secretKey } = keypairFromMnemonic(mnemonic, passphrase);
|
|
1276
|
+
return new _Wallet(publicKey, secretKey, mnemonic);
|
|
1277
|
+
}
|
|
1216
1278
|
/**
|
|
1217
1279
|
* Restore a wallet from existing hex-encoded keys.
|
|
1218
1280
|
*/
|
|
@@ -1223,7 +1285,11 @@ var Wallet = class _Wallet {
|
|
|
1223
1285
|
* Export keys as a plain object (for serialization/storage).
|
|
1224
1286
|
*/
|
|
1225
1287
|
toJSON() {
|
|
1226
|
-
return {
|
|
1288
|
+
return {
|
|
1289
|
+
publicKey: this.publicKey,
|
|
1290
|
+
privateKey: this.privateKey,
|
|
1291
|
+
...this.mnemonic ? { mnemonic: this.mnemonic } : {}
|
|
1292
|
+
};
|
|
1227
1293
|
}
|
|
1228
1294
|
/**
|
|
1229
1295
|
* Derive the compact Bech32m address from the public key.
|
|
@@ -1263,14 +1329,18 @@ exports.createSignedTokenMetadataUpdate = createSignedTokenMetadataUpdate;
|
|
|
1263
1329
|
exports.createSignedTokenTransferFrom = createSignedTokenTransferFrom;
|
|
1264
1330
|
exports.createSignedUnshield = createSignedUnshield;
|
|
1265
1331
|
exports.formatAddress = formatAddress;
|
|
1332
|
+
exports.generateMnemonic = generateMnemonic;
|
|
1266
1333
|
exports.generateNonce = generateNonce;
|
|
1267
1334
|
exports.generateRandomness = generateRandomness;
|
|
1268
1335
|
exports.hexToBytes = hexToBytes;
|
|
1269
1336
|
exports.isBurnAddress = isBurnAddress;
|
|
1270
1337
|
exports.isRougeAddress = isRougeAddress;
|
|
1338
|
+
exports.keypairFromMnemonic = keypairFromMnemonic;
|
|
1339
|
+
exports.mnemonicToMLDSASeed = mnemonicToMLDSASeed;
|
|
1271
1340
|
exports.pubkeyToAddress = pubkeyToAddress;
|
|
1272
1341
|
exports.serializePayload = serializePayload;
|
|
1273
1342
|
exports.signTransaction = signTransaction;
|
|
1343
|
+
exports.validateMnemonic = validateMnemonic;
|
|
1274
1344
|
exports.verifyTransaction = verifyTransaction;
|
|
1275
1345
|
//# sourceMappingURL=index.cjs.map
|
|
1276
1346
|
//# sourceMappingURL=index.cjs.map
|