@rougechain/sdk 0.7.0 → 0.8.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/dist/index.cjs +84 -5
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +81 -6
- package/dist/index.js.map +1 -1
- package/package.json +3 -2
package/dist/index.js
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
import { ml_dsa65 } from '@noble/post-quantum/ml-dsa.js';
|
|
2
2
|
import { sha256 } from '@noble/hashes/sha2';
|
|
3
|
+
import { generateMnemonic as generateMnemonic$1, validateMnemonic as validateMnemonic$1, mnemonicToSeedSync } from '@scure/bip39';
|
|
4
|
+
import { wordlist } from '@scure/bip39/wordlists/english.js';
|
|
5
|
+
import { hkdf } from '@noble/hashes/hkdf.js';
|
|
6
|
+
import { sha256 as sha256$1 } from '@noble/hashes/sha2.js';
|
|
3
7
|
|
|
4
8
|
// src/signer.ts
|
|
5
9
|
|
|
@@ -459,6 +463,28 @@ var RougeChain = class {
|
|
|
459
463
|
async getBurnedTokens() {
|
|
460
464
|
return this.get("/burned");
|
|
461
465
|
}
|
|
466
|
+
// ===== Address Resolution =====
|
|
467
|
+
/**
|
|
468
|
+
* Resolve a rouge1… address to its public key, or a public key to its rouge1 address.
|
|
469
|
+
* Uses the persistent on-chain address index for O(1) lookups.
|
|
470
|
+
*/
|
|
471
|
+
async resolveAddress(input) {
|
|
472
|
+
return this.get(`/resolve/${encodeURIComponent(input)}`);
|
|
473
|
+
}
|
|
474
|
+
// ===== Nonce =====
|
|
475
|
+
/** Get the current sequential nonce for an account. */
|
|
476
|
+
async getNonce(publicKey) {
|
|
477
|
+
return this.get(`/account/${encodeURIComponent(publicKey)}/nonce`);
|
|
478
|
+
}
|
|
479
|
+
// ===== Push Notifications =====
|
|
480
|
+
/** Register an Expo push token for a wallet to receive notifications. */
|
|
481
|
+
async registerPushToken(publicKey, pushToken, platform = "expo") {
|
|
482
|
+
return this.post("/push/register", { publicKey, pushToken, platform });
|
|
483
|
+
}
|
|
484
|
+
/** Unregister push notifications for a wallet. */
|
|
485
|
+
async unregisterPushToken(publicKey) {
|
|
486
|
+
return this.post("/push/unregister", { publicKey });
|
|
487
|
+
}
|
|
462
488
|
// ===== Write operations =====
|
|
463
489
|
async transfer(wallet, params) {
|
|
464
490
|
const tx = createSignedTransfer(
|
|
@@ -1193,24 +1219,69 @@ function formatAddress(address, prefixLen = 12, suffixLen = 4) {
|
|
|
1193
1219
|
if (address.length <= prefixLen + suffixLen + 3) return address;
|
|
1194
1220
|
return `${address.slice(0, prefixLen)}...${address.slice(-suffixLen)}`;
|
|
1195
1221
|
}
|
|
1222
|
+
var DOMAIN_INFO = new TextEncoder().encode("rougechain-ml-dsa-65-v1");
|
|
1223
|
+
function generateMnemonic(strength = 256) {
|
|
1224
|
+
return generateMnemonic$1(wordlist, strength);
|
|
1225
|
+
}
|
|
1226
|
+
function validateMnemonic(mnemonic) {
|
|
1227
|
+
return validateMnemonic$1(mnemonic, wordlist);
|
|
1228
|
+
}
|
|
1229
|
+
function mnemonicToMLDSASeed(mnemonic, passphrase) {
|
|
1230
|
+
const bip39Seed = mnemonicToSeedSync(mnemonic, passphrase);
|
|
1231
|
+
return hkdf(sha256$1, bip39Seed, void 0, DOMAIN_INFO, 32);
|
|
1232
|
+
}
|
|
1233
|
+
function keypairFromMnemonic(mnemonic, passphrase) {
|
|
1234
|
+
if (!validateMnemonic(mnemonic)) {
|
|
1235
|
+
throw new Error("Invalid mnemonic phrase");
|
|
1236
|
+
}
|
|
1237
|
+
const seed = mnemonicToMLDSASeed(mnemonic, passphrase);
|
|
1238
|
+
const keypair = ml_dsa65.keygen(seed);
|
|
1239
|
+
return {
|
|
1240
|
+
publicKey: bytesToHex(keypair.publicKey),
|
|
1241
|
+
secretKey: bytesToHex(keypair.secretKey)
|
|
1242
|
+
};
|
|
1243
|
+
}
|
|
1196
1244
|
|
|
1197
1245
|
// src/wallet.ts
|
|
1198
1246
|
var Wallet = class _Wallet {
|
|
1199
|
-
constructor(publicKey, privateKey) {
|
|
1247
|
+
constructor(publicKey, privateKey, mnemonic) {
|
|
1200
1248
|
this.publicKey = publicKey;
|
|
1201
1249
|
this.privateKey = privateKey;
|
|
1250
|
+
this.mnemonic = mnemonic;
|
|
1251
|
+
}
|
|
1252
|
+
/**
|
|
1253
|
+
* Generate a new ML-DSA-65 keypair with a BIP-39 mnemonic.
|
|
1254
|
+
* The mnemonic is stored on the wallet for backup/recovery.
|
|
1255
|
+
* @param strength 128 = 12 words (default), 256 = 24 words
|
|
1256
|
+
*/
|
|
1257
|
+
static generate(strength = 128) {
|
|
1258
|
+
const mnemonic = generateMnemonic(strength);
|
|
1259
|
+
const { publicKey, secretKey } = keypairFromMnemonic(mnemonic);
|
|
1260
|
+
return new _Wallet(publicKey, secretKey, mnemonic);
|
|
1202
1261
|
}
|
|
1203
1262
|
/**
|
|
1204
|
-
* Generate a
|
|
1205
|
-
*
|
|
1263
|
+
* Generate a wallet using pure random entropy (no mnemonic).
|
|
1264
|
+
* Keys cannot be recovered from a seed phrase.
|
|
1206
1265
|
*/
|
|
1207
|
-
static
|
|
1266
|
+
static generateRandom() {
|
|
1208
1267
|
const keypair = ml_dsa65.keygen();
|
|
1209
1268
|
return new _Wallet(
|
|
1210
1269
|
bytesToHex(keypair.publicKey),
|
|
1211
1270
|
bytesToHex(keypair.secretKey)
|
|
1212
1271
|
);
|
|
1213
1272
|
}
|
|
1273
|
+
/**
|
|
1274
|
+
* Restore a wallet from a BIP-39 mnemonic seed phrase.
|
|
1275
|
+
* @param mnemonic 12 or 24 word BIP-39 mnemonic
|
|
1276
|
+
* @param passphrase Optional BIP-39 passphrase (25th word)
|
|
1277
|
+
*/
|
|
1278
|
+
static fromMnemonic(mnemonic, passphrase) {
|
|
1279
|
+
if (!validateMnemonic(mnemonic)) {
|
|
1280
|
+
throw new Error("Invalid mnemonic phrase");
|
|
1281
|
+
}
|
|
1282
|
+
const { publicKey, secretKey } = keypairFromMnemonic(mnemonic, passphrase);
|
|
1283
|
+
return new _Wallet(publicKey, secretKey, mnemonic);
|
|
1284
|
+
}
|
|
1214
1285
|
/**
|
|
1215
1286
|
* Restore a wallet from existing hex-encoded keys.
|
|
1216
1287
|
*/
|
|
@@ -1221,7 +1292,11 @@ var Wallet = class _Wallet {
|
|
|
1221
1292
|
* Export keys as a plain object (for serialization/storage).
|
|
1222
1293
|
*/
|
|
1223
1294
|
toJSON() {
|
|
1224
|
-
return {
|
|
1295
|
+
return {
|
|
1296
|
+
publicKey: this.publicKey,
|
|
1297
|
+
privateKey: this.privateKey,
|
|
1298
|
+
...this.mnemonic ? { mnemonic: this.mnemonic } : {}
|
|
1299
|
+
};
|
|
1225
1300
|
}
|
|
1226
1301
|
/**
|
|
1227
1302
|
* Derive the compact Bech32m address from the public key.
|
|
@@ -1244,6 +1319,6 @@ var Wallet = class _Wallet {
|
|
|
1244
1319
|
}
|
|
1245
1320
|
};
|
|
1246
1321
|
|
|
1247
|
-
export { BURN_ADDRESS, RougeChain, Wallet, addressToHash, bytesToHex, computeCommitment, computeNullifier, createShieldedNote, createSignedBridgeWithdraw, createSignedShield, createSignedShieldedTransfer, createSignedTokenApproval, createSignedTokenMetadataClaim, createSignedTokenMetadataUpdate, createSignedTokenTransferFrom, createSignedUnshield, formatAddress, generateNonce, generateRandomness, hexToBytes, isBurnAddress, isRougeAddress, pubkeyToAddress, serializePayload, signTransaction, verifyTransaction };
|
|
1322
|
+
export { BURN_ADDRESS, RougeChain, Wallet, addressToHash, bytesToHex, computeCommitment, computeNullifier, createShieldedNote, createSignedBridgeWithdraw, createSignedShield, createSignedShieldedTransfer, createSignedTokenApproval, createSignedTokenMetadataClaim, createSignedTokenMetadataUpdate, createSignedTokenTransferFrom, createSignedUnshield, formatAddress, generateMnemonic, generateNonce, generateRandomness, hexToBytes, isBurnAddress, isRougeAddress, keypairFromMnemonic, mnemonicToMLDSASeed, pubkeyToAddress, serializePayload, signTransaction, validateMnemonic, verifyTransaction };
|
|
1248
1323
|
//# sourceMappingURL=index.js.map
|
|
1249
1324
|
//# sourceMappingURL=index.js.map
|