@rougechain/sdk 0.8.3 → 0.9.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 +117 -26
- package/dist/index.cjs +210 -110
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +210 -111
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -284,6 +284,9 @@ function createSignedPushUnregister(wallet) {
|
|
|
284
284
|
type: "push_unregister"
|
|
285
285
|
});
|
|
286
286
|
}
|
|
287
|
+
function signRequest(wallet, payload) {
|
|
288
|
+
return buildAndSign(wallet, payload);
|
|
289
|
+
}
|
|
287
290
|
var COMMITMENT_DOMAIN = new TextEncoder().encode("ROUGECHAIN_COMMITMENT_V1");
|
|
288
291
|
var NULLIFIER_DOMAIN = new TextEncoder().encode("ROUGECHAIN_NULLIFIER_V1");
|
|
289
292
|
function generateRandomness() {
|
|
@@ -466,6 +469,19 @@ var RougeChain = class {
|
|
|
466
469
|
async getFinality() {
|
|
467
470
|
return this.get("/finality");
|
|
468
471
|
}
|
|
472
|
+
// ===== EIP-1559 Fee Info =====
|
|
473
|
+
/** Get current EIP-1559 fee information including base fee and suggestions. */
|
|
474
|
+
async getFeeInfo() {
|
|
475
|
+
return this.get("/fee");
|
|
476
|
+
}
|
|
477
|
+
// ===== BFT Finality Proofs =====
|
|
478
|
+
/**
|
|
479
|
+
* Get a BFT finality proof for a specific block height.
|
|
480
|
+
* Returns the aggregated precommit votes that prove ≥2/3 validator stake agreed.
|
|
481
|
+
*/
|
|
482
|
+
async getFinalityProof(height) {
|
|
483
|
+
return this.get(`/finality/${height}`);
|
|
484
|
+
}
|
|
469
485
|
// ===== Peers =====
|
|
470
486
|
async getPeers() {
|
|
471
487
|
const data = await this.get("/peers");
|
|
@@ -551,6 +567,39 @@ var RougeChain = class {
|
|
|
551
567
|
const tx = createSignedTokenMetadataClaim(wallet, tokenSymbol);
|
|
552
568
|
return this.submitTx("/v2/token/metadata/claim", tx);
|
|
553
569
|
}
|
|
570
|
+
/**
|
|
571
|
+
* Mint additional tokens for a mintable token (creator only).
|
|
572
|
+
* The token must have been created with `mintable: true`.
|
|
573
|
+
*/
|
|
574
|
+
async mintTokens(wallet, params) {
|
|
575
|
+
return this.post("/v2/token/mint", {
|
|
576
|
+
public_key: wallet.publicKey,
|
|
577
|
+
symbol: params.symbol,
|
|
578
|
+
amount: params.amount,
|
|
579
|
+
fee: params.fee ?? 1,
|
|
580
|
+
signature: ""
|
|
581
|
+
// Will be signed server-side via PQC verification
|
|
582
|
+
});
|
|
583
|
+
}
|
|
584
|
+
// ===== WebSocket =====
|
|
585
|
+
/**
|
|
586
|
+
* Connect to the node's WebSocket and optionally subscribe to specific topics.
|
|
587
|
+
* Topics: "blocks", "transactions", "stats", "account:<pubkey>", "token:<symbol>"
|
|
588
|
+
*
|
|
589
|
+
* @example
|
|
590
|
+
* const ws = client.connectWebSocket(["blocks", "account:abc123"]);
|
|
591
|
+
* ws.onmessage = (e) => console.log(JSON.parse(e.data));
|
|
592
|
+
*/
|
|
593
|
+
connectWebSocket(topics) {
|
|
594
|
+
const wsUrl = this.baseUrl.replace(/^http/, "ws") + "/ws";
|
|
595
|
+
const ws = new WebSocket(wsUrl);
|
|
596
|
+
if (topics && topics.length > 0) {
|
|
597
|
+
ws.addEventListener("open", () => {
|
|
598
|
+
ws.send(JSON.stringify({ subscribe: topics }));
|
|
599
|
+
});
|
|
600
|
+
}
|
|
601
|
+
return ws;
|
|
602
|
+
}
|
|
554
603
|
// ===== Rollup =====
|
|
555
604
|
/** Get the current rollup accumulator status. */
|
|
556
605
|
async getRollupStatus() {
|
|
@@ -911,68 +960,97 @@ var MailClient = class {
|
|
|
911
960
|
constructor(rc) {
|
|
912
961
|
this.rc = rc;
|
|
913
962
|
}
|
|
914
|
-
|
|
963
|
+
// --- Name Registry (signed) ---
|
|
964
|
+
async registerName(wallet, name, walletId) {
|
|
965
|
+
const signed = signRequest(wallet, { name, walletId });
|
|
966
|
+
return this.rc.submitTx("/v2/names/register", signed);
|
|
967
|
+
}
|
|
968
|
+
async resolveName(name) {
|
|
915
969
|
try {
|
|
916
|
-
const data = await this.rc.
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
970
|
+
const data = await this.rc.get(
|
|
971
|
+
`/names/resolve/${encodeURIComponent(name.toLowerCase())}`
|
|
972
|
+
);
|
|
973
|
+
if (!data.success) return null;
|
|
974
|
+
return { entry: data.entry, wallet: data.wallet };
|
|
975
|
+
} catch {
|
|
976
|
+
return null;
|
|
920
977
|
}
|
|
921
978
|
}
|
|
922
|
-
async
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
);
|
|
932
|
-
return data.messages ?? [];
|
|
979
|
+
async reverseLookup(walletId) {
|
|
980
|
+
try {
|
|
981
|
+
const data = await this.rc.get(
|
|
982
|
+
`/names/reverse/${encodeURIComponent(walletId)}`
|
|
983
|
+
);
|
|
984
|
+
return data.name || null;
|
|
985
|
+
} catch {
|
|
986
|
+
return null;
|
|
987
|
+
}
|
|
933
988
|
}
|
|
934
|
-
async
|
|
935
|
-
const
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
989
|
+
async releaseName(wallet, name) {
|
|
990
|
+
const signed = signRequest(wallet, { name });
|
|
991
|
+
return this.rc.submitTx("/v2/names/release", signed);
|
|
992
|
+
}
|
|
993
|
+
// --- Mail (signed) ---
|
|
994
|
+
async send(wallet, params) {
|
|
995
|
+
const signed = signRequest(wallet, {
|
|
996
|
+
fromWalletId: params.from,
|
|
997
|
+
toWalletIds: [params.to],
|
|
998
|
+
subjectEncrypted: params.encrypted_subject,
|
|
999
|
+
bodyEncrypted: params.encrypted_body,
|
|
1000
|
+
contentSignature: params.body,
|
|
1001
|
+
replyToId: params.reply_to_id,
|
|
1002
|
+
hasAttachment: false
|
|
1003
|
+
});
|
|
1004
|
+
return this.rc.submitTx("/v2/mail/send", signed);
|
|
939
1005
|
}
|
|
940
|
-
async
|
|
941
|
-
|
|
1006
|
+
async getInbox(wallet) {
|
|
1007
|
+
const signed = signRequest(wallet, { folder: "inbox" });
|
|
1008
|
+
try {
|
|
1009
|
+
const data = await this.rc.post("/v2/mail/folder", signed);
|
|
1010
|
+
return data.messages ?? [];
|
|
1011
|
+
} catch {
|
|
1012
|
+
return [];
|
|
1013
|
+
}
|
|
942
1014
|
}
|
|
943
|
-
async
|
|
1015
|
+
async getSent(wallet) {
|
|
1016
|
+
const signed = signRequest(wallet, { folder: "sent" });
|
|
944
1017
|
try {
|
|
945
|
-
const data = await this.rc.post("/mail/
|
|
946
|
-
|
|
947
|
-
|
|
948
|
-
|
|
949
|
-
return { success: data.success === true, error: data.error };
|
|
950
|
-
} catch (e) {
|
|
951
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1018
|
+
const data = await this.rc.post("/v2/mail/folder", signed);
|
|
1019
|
+
return data.messages ?? [];
|
|
1020
|
+
} catch {
|
|
1021
|
+
return [];
|
|
952
1022
|
}
|
|
953
1023
|
}
|
|
954
|
-
async
|
|
1024
|
+
async getTrash(wallet) {
|
|
1025
|
+
const signed = signRequest(wallet, { folder: "trash" });
|
|
955
1026
|
try {
|
|
956
|
-
const data = await this.rc.post("/mail/
|
|
957
|
-
|
|
958
|
-
|
|
959
|
-
return
|
|
960
|
-
} catch (e) {
|
|
961
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1027
|
+
const data = await this.rc.post("/v2/mail/folder", signed);
|
|
1028
|
+
return data.messages ?? [];
|
|
1029
|
+
} catch {
|
|
1030
|
+
return [];
|
|
962
1031
|
}
|
|
963
1032
|
}
|
|
964
|
-
async
|
|
1033
|
+
async getMessage(wallet, messageId) {
|
|
1034
|
+
const signed = signRequest(wallet, { messageId });
|
|
965
1035
|
try {
|
|
966
|
-
const
|
|
967
|
-
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
const data = await res.json();
|
|
971
|
-
return { success: data.success === true, error: data.error };
|
|
972
|
-
} catch (e) {
|
|
973
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1036
|
+
const data = await this.rc.post("/v2/mail/message", signed);
|
|
1037
|
+
return data.message ?? null;
|
|
1038
|
+
} catch {
|
|
1039
|
+
return null;
|
|
974
1040
|
}
|
|
975
1041
|
}
|
|
1042
|
+
async move(wallet, messageId, folder) {
|
|
1043
|
+
const signed = signRequest(wallet, { messageId, folder });
|
|
1044
|
+
return this.rc.submitTx("/v2/mail/move", signed);
|
|
1045
|
+
}
|
|
1046
|
+
async markRead(wallet, messageId) {
|
|
1047
|
+
const signed = signRequest(wallet, { messageId });
|
|
1048
|
+
return this.rc.submitTx("/v2/mail/read", signed);
|
|
1049
|
+
}
|
|
1050
|
+
async delete(wallet, messageId) {
|
|
1051
|
+
const signed = signRequest(wallet, { messageId });
|
|
1052
|
+
return this.rc.submitTx("/v2/mail/delete", signed);
|
|
1053
|
+
}
|
|
976
1054
|
};
|
|
977
1055
|
var MessengerClient = class {
|
|
978
1056
|
constructor(rc) {
|
|
@@ -982,77 +1060,71 @@ var MessengerClient = class {
|
|
|
982
1060
|
const data = await this.rc.get("/messenger/wallets");
|
|
983
1061
|
return data.wallets ?? [];
|
|
984
1062
|
}
|
|
985
|
-
async registerWallet(opts) {
|
|
1063
|
+
async registerWallet(wallet, opts) {
|
|
1064
|
+
const signed = signRequest(wallet, {
|
|
1065
|
+
id: opts.id,
|
|
1066
|
+
displayName: opts.displayName,
|
|
1067
|
+
signingPublicKey: opts.signingPublicKey,
|
|
1068
|
+
encryptionPublicKey: opts.encryptionPublicKey,
|
|
1069
|
+
discoverable: opts.discoverable ?? true
|
|
1070
|
+
});
|
|
1071
|
+
return this.rc.submitTx("/v2/messenger/wallets/register", signed);
|
|
1072
|
+
}
|
|
1073
|
+
async getConversations(wallet) {
|
|
1074
|
+
const signed = signRequest(wallet, {});
|
|
986
1075
|
try {
|
|
987
|
-
const data = await this.rc.post(
|
|
988
|
-
|
|
989
|
-
|
|
990
|
-
|
|
1076
|
+
const data = await this.rc.post(
|
|
1077
|
+
"/v2/messenger/conversations/list",
|
|
1078
|
+
signed
|
|
1079
|
+
);
|
|
1080
|
+
return data.conversations ?? [];
|
|
1081
|
+
} catch {
|
|
1082
|
+
return [];
|
|
991
1083
|
}
|
|
992
1084
|
}
|
|
993
|
-
async
|
|
994
|
-
const
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
);
|
|
1000
|
-
return data.conversations ?? [];
|
|
1085
|
+
async createConversation(wallet, participantIds, opts = {}) {
|
|
1086
|
+
const signed = signRequest(wallet, {
|
|
1087
|
+
participantIds,
|
|
1088
|
+
name: opts.name,
|
|
1089
|
+
isGroup: opts.isGroup ?? false
|
|
1090
|
+
});
|
|
1091
|
+
return this.rc.submitTx("/v2/messenger/conversations", signed);
|
|
1001
1092
|
}
|
|
1002
|
-
async
|
|
1093
|
+
async getMessages(wallet, conversationId) {
|
|
1094
|
+
const signed = signRequest(wallet, { conversationId });
|
|
1003
1095
|
try {
|
|
1004
|
-
const data = await this.rc.post(
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
|
|
1008
|
-
|
|
1009
|
-
|
|
1096
|
+
const data = await this.rc.post(
|
|
1097
|
+
"/v2/messenger/messages/list",
|
|
1098
|
+
signed
|
|
1099
|
+
);
|
|
1100
|
+
return data.messages ?? [];
|
|
1101
|
+
} catch {
|
|
1102
|
+
return [];
|
|
1010
1103
|
}
|
|
1011
1104
|
}
|
|
1012
|
-
async
|
|
1013
|
-
const
|
|
1014
|
-
|
|
1015
|
-
|
|
1016
|
-
|
|
1105
|
+
async sendMessage(wallet, conversationId, encryptedContent, opts = {}) {
|
|
1106
|
+
const signed = signRequest(wallet, {
|
|
1107
|
+
conversationId,
|
|
1108
|
+
encryptedContent,
|
|
1109
|
+
contentSignature: opts.contentSignature ?? "",
|
|
1110
|
+
messageType: opts.messageType ?? "text",
|
|
1111
|
+
selfDestruct: opts.selfDestruct ?? false,
|
|
1112
|
+
destructAfterSeconds: opts.destructAfterSeconds,
|
|
1113
|
+
spoiler: opts.spoiler ?? false
|
|
1114
|
+
});
|
|
1115
|
+
return this.rc.submitTx("/v2/messenger/messages", signed);
|
|
1017
1116
|
}
|
|
1018
|
-
async
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
conversationId,
|
|
1022
|
-
senderWalletId,
|
|
1023
|
-
encryptedContent,
|
|
1024
|
-
signature: opts.signature ?? "",
|
|
1025
|
-
messageType: opts.messageType ?? "text",
|
|
1026
|
-
selfDestruct: opts.selfDestruct ?? false,
|
|
1027
|
-
destructAfterSeconds: opts.destructAfterSeconds,
|
|
1028
|
-
spoiler: opts.spoiler ?? false
|
|
1029
|
-
});
|
|
1030
|
-
return { success: data.success === true, error: data.error, data };
|
|
1031
|
-
} catch (e) {
|
|
1032
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1033
|
-
}
|
|
1117
|
+
async deleteMessage(wallet, messageId, conversationId) {
|
|
1118
|
+
const signed = signRequest(wallet, { messageId, conversationId });
|
|
1119
|
+
return this.rc.submitTx("/v2/messenger/messages/delete", signed);
|
|
1034
1120
|
}
|
|
1035
|
-
async
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
`${this.rc.baseUrl}/messenger/messages/${encodeURIComponent(messageId)}`,
|
|
1039
|
-
{ method: "DELETE", headers: this.rc.headers }
|
|
1040
|
-
);
|
|
1041
|
-
const data = await res.json();
|
|
1042
|
-
return { success: data.success === true, error: data.error };
|
|
1043
|
-
} catch (e) {
|
|
1044
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1045
|
-
}
|
|
1121
|
+
async deleteConversation(wallet, conversationId) {
|
|
1122
|
+
const signed = signRequest(wallet, { conversationId });
|
|
1123
|
+
return this.rc.submitTx("/v2/messenger/conversations/delete", signed);
|
|
1046
1124
|
}
|
|
1047
|
-
async markRead(messageId) {
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
messageId
|
|
1051
|
-
});
|
|
1052
|
-
return { success: data.success === true, error: data.error };
|
|
1053
|
-
} catch (e) {
|
|
1054
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1055
|
-
}
|
|
1125
|
+
async markRead(wallet, messageId, conversationId) {
|
|
1126
|
+
const signed = signRequest(wallet, { messageId, conversationId });
|
|
1127
|
+
return this.rc.submitTx("/v2/messenger/messages/read", signed);
|
|
1056
1128
|
}
|
|
1057
1129
|
};
|
|
1058
1130
|
var ShieldedClient = class {
|
|
@@ -1111,6 +1183,33 @@ var ShieldedClient = class {
|
|
|
1111
1183
|
);
|
|
1112
1184
|
return this.rc.submitTx("/v2/shielded/unshield", tx);
|
|
1113
1185
|
}
|
|
1186
|
+
// ─── WASM Smart Contracts ──────────────────────────────────────────
|
|
1187
|
+
/** Deploy a WASM smart contract */
|
|
1188
|
+
async deployContract(params) {
|
|
1189
|
+
return this.rc.post("/v2/contract/deploy", params);
|
|
1190
|
+
}
|
|
1191
|
+
/** Call a WASM smart contract method (mutating) */
|
|
1192
|
+
async callContract(params) {
|
|
1193
|
+
return this.rc.post("/v2/contract/call", params);
|
|
1194
|
+
}
|
|
1195
|
+
/** Get contract metadata */
|
|
1196
|
+
async getContract(addr) {
|
|
1197
|
+
return this.rc.get(`/contract/${addr}`);
|
|
1198
|
+
}
|
|
1199
|
+
/** Read contract storage. Omit key for full state dump. */
|
|
1200
|
+
async getContractState(addr, key) {
|
|
1201
|
+
const q = key ? `?key=${encodeURIComponent(key)}` : "";
|
|
1202
|
+
return this.rc.get(`/contract/${addr}/state${q}`);
|
|
1203
|
+
}
|
|
1204
|
+
/** Get contract events */
|
|
1205
|
+
async getContractEvents(addr, limit) {
|
|
1206
|
+
const q = limit ? `?limit=${limit}` : "";
|
|
1207
|
+
return this.rc.get(`/contract/${addr}/events${q}`);
|
|
1208
|
+
}
|
|
1209
|
+
/** List all deployed contracts */
|
|
1210
|
+
async listContracts() {
|
|
1211
|
+
return this.rc.get("/contracts");
|
|
1212
|
+
}
|
|
1114
1213
|
};
|
|
1115
1214
|
|
|
1116
1215
|
// src/address.ts
|
|
@@ -1267,9 +1366,9 @@ var Wallet = class _Wallet {
|
|
|
1267
1366
|
/**
|
|
1268
1367
|
* Generate a new ML-DSA-65 keypair with a BIP-39 mnemonic.
|
|
1269
1368
|
* The mnemonic is stored on the wallet for backup/recovery.
|
|
1270
|
-
* @param strength
|
|
1369
|
+
* @param strength 256 = 24 words (default, post-quantum safe), 128 = 12 words
|
|
1271
1370
|
*/
|
|
1272
|
-
static generate(strength =
|
|
1371
|
+
static generate(strength = 256) {
|
|
1273
1372
|
const mnemonic = generateMnemonic(strength);
|
|
1274
1373
|
const { publicKey, secretKey } = keypairFromMnemonic(mnemonic);
|
|
1275
1374
|
return new _Wallet(publicKey, secretKey, mnemonic);
|
|
@@ -1334,6 +1433,6 @@ var Wallet = class _Wallet {
|
|
|
1334
1433
|
}
|
|
1335
1434
|
};
|
|
1336
1435
|
|
|
1337
|
-
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 };
|
|
1436
|
+
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, signRequest, signTransaction, validateMnemonic, verifyTransaction };
|
|
1338
1437
|
//# sourceMappingURL=index.js.map
|
|
1339
1438
|
//# sourceMappingURL=index.js.map
|