@rougechain/sdk 0.1.1 → 0.3.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 +210 -209
- package/dist/index.cjs +278 -32
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +126 -10
- package/dist/index.d.ts +126 -10
- package/dist/index.js +276 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -28,7 +28,7 @@ function serializePayload(payload) {
|
|
|
28
28
|
}
|
|
29
29
|
function signTransaction(payload, privateKey, publicKey) {
|
|
30
30
|
const payloadBytes = serializePayload(payload);
|
|
31
|
-
const signature = mlDsa_js.ml_dsa65.sign(hexToBytes(privateKey)
|
|
31
|
+
const signature = mlDsa_js.ml_dsa65.sign(payloadBytes, hexToBytes(privateKey));
|
|
32
32
|
return {
|
|
33
33
|
payload,
|
|
34
34
|
signature: bytesToHex(signature),
|
|
@@ -39,9 +39,9 @@ function verifyTransaction(signedTx) {
|
|
|
39
39
|
try {
|
|
40
40
|
const payloadBytes = serializePayload(signedTx.payload);
|
|
41
41
|
return mlDsa_js.ml_dsa65.verify(
|
|
42
|
-
hexToBytes(signedTx.
|
|
42
|
+
hexToBytes(signedTx.signature),
|
|
43
43
|
payloadBytes,
|
|
44
|
-
hexToBytes(signedTx.
|
|
44
|
+
hexToBytes(signedTx.public_key)
|
|
45
45
|
);
|
|
46
46
|
} catch {
|
|
47
47
|
return false;
|
|
@@ -62,13 +62,31 @@ function buildAndSign(wallet, payload) {
|
|
|
62
62
|
function createSignedTransfer(wallet, to, amount, fee = 1, token = "XRGE") {
|
|
63
63
|
return buildAndSign(wallet, { type: "transfer", to, amount, fee, token });
|
|
64
64
|
}
|
|
65
|
-
function createSignedTokenCreation(wallet, tokenName, tokenSymbol, initialSupply, fee = 10) {
|
|
65
|
+
function createSignedTokenCreation(wallet, tokenName, tokenSymbol, initialSupply, fee = 10, image) {
|
|
66
66
|
return buildAndSign(wallet, {
|
|
67
67
|
type: "create_token",
|
|
68
68
|
token_name: tokenName,
|
|
69
69
|
token_symbol: tokenSymbol,
|
|
70
70
|
initial_supply: initialSupply,
|
|
71
|
-
fee
|
|
71
|
+
fee,
|
|
72
|
+
...image ? { image } : {}
|
|
73
|
+
});
|
|
74
|
+
}
|
|
75
|
+
function createSignedTokenMetadataUpdate(wallet, tokenSymbol, metadata) {
|
|
76
|
+
return buildAndSign(wallet, {
|
|
77
|
+
type: "update_token_metadata",
|
|
78
|
+
token_symbol: tokenSymbol,
|
|
79
|
+
...metadata.image !== void 0 ? { image: metadata.image } : {},
|
|
80
|
+
...metadata.description !== void 0 ? { description: metadata.description } : {},
|
|
81
|
+
...metadata.website !== void 0 ? { website: metadata.website } : {},
|
|
82
|
+
...metadata.twitter !== void 0 ? { twitter: metadata.twitter } : {},
|
|
83
|
+
...metadata.discord !== void 0 ? { discord: metadata.discord } : {}
|
|
84
|
+
});
|
|
85
|
+
}
|
|
86
|
+
function createSignedTokenMetadataClaim(wallet, tokenSymbol) {
|
|
87
|
+
return buildAndSign(wallet, {
|
|
88
|
+
type: "claim_token_metadata",
|
|
89
|
+
token_symbol: tokenSymbol
|
|
72
90
|
});
|
|
73
91
|
}
|
|
74
92
|
function createSignedSwap(wallet, tokenIn, tokenOut, amountIn, minAmountOut) {
|
|
@@ -122,6 +140,16 @@ function createSignedBurn(wallet, amount, fee = 1, token = "XRGE") {
|
|
|
122
140
|
token
|
|
123
141
|
});
|
|
124
142
|
}
|
|
143
|
+
function createSignedBridgeWithdraw(wallet, amount, evmAddress, tokenSymbol = "qETH", fee = 0.1) {
|
|
144
|
+
const evm = evmAddress.startsWith("0x") ? evmAddress : `0x${evmAddress}`;
|
|
145
|
+
return buildAndSign(wallet, {
|
|
146
|
+
type: "bridge_withdraw",
|
|
147
|
+
amount,
|
|
148
|
+
fee,
|
|
149
|
+
tokenSymbol,
|
|
150
|
+
evmAddress: evm
|
|
151
|
+
});
|
|
152
|
+
}
|
|
125
153
|
function createSignedNftCreateCollection(wallet, symbol, name, opts = {}) {
|
|
126
154
|
return buildAndSign(wallet, {
|
|
127
155
|
type: "nft_create_collection",
|
|
@@ -202,6 +230,8 @@ var RougeChain = class {
|
|
|
202
230
|
this.nft = new NftClient(this);
|
|
203
231
|
this.dex = new DexClient(this);
|
|
204
232
|
this.bridge = new BridgeClient(this);
|
|
233
|
+
this.mail = new MailClient(this);
|
|
234
|
+
this.messenger = new MessengerClient(this);
|
|
205
235
|
}
|
|
206
236
|
// ===== Internal helpers =====
|
|
207
237
|
/** @internal */
|
|
@@ -336,7 +366,8 @@ var RougeChain = class {
|
|
|
336
366
|
params.name,
|
|
337
367
|
params.symbol,
|
|
338
368
|
params.totalSupply,
|
|
339
|
-
params.fee
|
|
369
|
+
params.fee,
|
|
370
|
+
params.image
|
|
340
371
|
);
|
|
341
372
|
return this.submitTx("/v2/token/create", tx);
|
|
342
373
|
}
|
|
@@ -357,24 +388,18 @@ var RougeChain = class {
|
|
|
357
388
|
return this.submitTx("/v2/transfer", tx);
|
|
358
389
|
}
|
|
359
390
|
async updateTokenMetadata(wallet, params) {
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
} catch (e) {
|
|
373
|
-
return {
|
|
374
|
-
success: false,
|
|
375
|
-
error: e instanceof Error ? e.message : String(e)
|
|
376
|
-
};
|
|
377
|
-
}
|
|
391
|
+
const tx = createSignedTokenMetadataUpdate(wallet, params.symbol, {
|
|
392
|
+
image: params.image,
|
|
393
|
+
description: params.description,
|
|
394
|
+
website: params.website,
|
|
395
|
+
twitter: params.twitter,
|
|
396
|
+
discord: params.discord
|
|
397
|
+
});
|
|
398
|
+
return this.submitTx("/v2/token/metadata/update", tx);
|
|
399
|
+
}
|
|
400
|
+
async claimTokenMetadata(wallet, tokenSymbol) {
|
|
401
|
+
const tx = createSignedTokenMetadataClaim(wallet, tokenSymbol);
|
|
402
|
+
return this.submitTx("/v2/token/metadata/claim", tx);
|
|
378
403
|
}
|
|
379
404
|
};
|
|
380
405
|
var NftClient = class {
|
|
@@ -547,7 +572,8 @@ var BridgeClient = class {
|
|
|
547
572
|
return {
|
|
548
573
|
enabled: data.enabled === true,
|
|
549
574
|
custodyAddress: data.custodyAddress,
|
|
550
|
-
chainId: data.chainId ?? 84532
|
|
575
|
+
chainId: data.chainId ?? 84532,
|
|
576
|
+
supportedTokens: data.supportedTokens
|
|
551
577
|
};
|
|
552
578
|
} catch {
|
|
553
579
|
return { enabled: false, chainId: 84532 };
|
|
@@ -559,17 +585,25 @@ var BridgeClient = class {
|
|
|
559
585
|
);
|
|
560
586
|
return data.withdrawals;
|
|
561
587
|
}
|
|
588
|
+
/** Withdraw qETH/qUSDC — signed client-side, private key never sent to server */
|
|
562
589
|
async withdraw(wallet, params) {
|
|
563
590
|
try {
|
|
564
|
-
const
|
|
591
|
+
const tokenSymbol = params.tokenSymbol ?? "qETH";
|
|
592
|
+
const signed = createSignedBridgeWithdraw(
|
|
593
|
+
wallet,
|
|
594
|
+
params.amount,
|
|
595
|
+
params.evmAddress,
|
|
596
|
+
tokenSymbol,
|
|
597
|
+
params.fee
|
|
598
|
+
);
|
|
565
599
|
const data = await this.rc.post(
|
|
566
600
|
"/bridge/withdraw",
|
|
567
601
|
{
|
|
568
|
-
fromPrivateKey: wallet.privateKey,
|
|
569
602
|
fromPublicKey: wallet.publicKey,
|
|
570
603
|
amountUnits: params.amount,
|
|
571
|
-
evmAddress:
|
|
572
|
-
|
|
604
|
+
evmAddress: signed.payload.evmAddress,
|
|
605
|
+
signature: signed.signature,
|
|
606
|
+
payload: signed.payload
|
|
573
607
|
}
|
|
574
608
|
);
|
|
575
609
|
return {
|
|
@@ -584,6 +618,7 @@ var BridgeClient = class {
|
|
|
584
618
|
};
|
|
585
619
|
}
|
|
586
620
|
}
|
|
621
|
+
/** Claim qETH or qUSDC after depositing on Base Sepolia */
|
|
587
622
|
async claim(params) {
|
|
588
623
|
try {
|
|
589
624
|
const data = await this.rc.post(
|
|
@@ -592,7 +627,8 @@ var BridgeClient = class {
|
|
|
592
627
|
evmTxHash: params.evmTxHash.startsWith("0x") ? params.evmTxHash : `0x${params.evmTxHash}`,
|
|
593
628
|
evmAddress: params.evmAddress.startsWith("0x") ? params.evmAddress : `0x${params.evmAddress}`,
|
|
594
629
|
evmSignature: params.evmSignature,
|
|
595
|
-
recipientRougechainPubkey: params.recipientPubkey
|
|
630
|
+
recipientRougechainPubkey: params.recipientPubkey,
|
|
631
|
+
token: params.token ?? "ETH"
|
|
596
632
|
}
|
|
597
633
|
);
|
|
598
634
|
return {
|
|
@@ -607,6 +643,213 @@ var BridgeClient = class {
|
|
|
607
643
|
};
|
|
608
644
|
}
|
|
609
645
|
}
|
|
646
|
+
// ── XRGE Bridge ──
|
|
647
|
+
async getXrgeConfig() {
|
|
648
|
+
try {
|
|
649
|
+
const data = await this.rc.get("/bridge/xrge/config");
|
|
650
|
+
return {
|
|
651
|
+
enabled: data.enabled === true,
|
|
652
|
+
vaultAddress: data.vaultAddress,
|
|
653
|
+
tokenAddress: data.tokenAddress,
|
|
654
|
+
chainId: data.chainId ?? 84532
|
|
655
|
+
};
|
|
656
|
+
} catch {
|
|
657
|
+
return { enabled: false, chainId: 84532 };
|
|
658
|
+
}
|
|
659
|
+
}
|
|
660
|
+
async claimXrge(params) {
|
|
661
|
+
try {
|
|
662
|
+
const data = await this.rc.post(
|
|
663
|
+
"/bridge/xrge/claim",
|
|
664
|
+
{
|
|
665
|
+
evmTxHash: params.evmTxHash.startsWith("0x") ? params.evmTxHash : `0x${params.evmTxHash}`,
|
|
666
|
+
evmAddress: params.evmAddress.startsWith("0x") ? params.evmAddress : `0x${params.evmAddress}`,
|
|
667
|
+
amount: params.amount,
|
|
668
|
+
recipientRougechainPubkey: params.recipientPubkey
|
|
669
|
+
}
|
|
670
|
+
);
|
|
671
|
+
return {
|
|
672
|
+
success: data.success === true,
|
|
673
|
+
error: data.error,
|
|
674
|
+
data
|
|
675
|
+
};
|
|
676
|
+
} catch (e) {
|
|
677
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
678
|
+
}
|
|
679
|
+
}
|
|
680
|
+
async withdrawXrge(wallet, params) {
|
|
681
|
+
try {
|
|
682
|
+
const signed = createSignedBridgeWithdraw(
|
|
683
|
+
wallet,
|
|
684
|
+
params.amount,
|
|
685
|
+
params.evmAddress,
|
|
686
|
+
"XRGE",
|
|
687
|
+
0.1
|
|
688
|
+
);
|
|
689
|
+
const data = await this.rc.post(
|
|
690
|
+
"/bridge/xrge/withdraw",
|
|
691
|
+
{
|
|
692
|
+
fromPublicKey: wallet.publicKey,
|
|
693
|
+
amount: params.amount,
|
|
694
|
+
evmAddress: signed.payload.evmAddress,
|
|
695
|
+
signature: signed.signature,
|
|
696
|
+
payload: signed.payload
|
|
697
|
+
}
|
|
698
|
+
);
|
|
699
|
+
return {
|
|
700
|
+
success: data.success === true,
|
|
701
|
+
error: data.error,
|
|
702
|
+
data
|
|
703
|
+
};
|
|
704
|
+
} catch (e) {
|
|
705
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
706
|
+
}
|
|
707
|
+
}
|
|
708
|
+
async getXrgeWithdrawals() {
|
|
709
|
+
try {
|
|
710
|
+
const data = await this.rc.get(
|
|
711
|
+
"/bridge/xrge/withdrawals"
|
|
712
|
+
);
|
|
713
|
+
return data.withdrawals;
|
|
714
|
+
} catch {
|
|
715
|
+
return [];
|
|
716
|
+
}
|
|
717
|
+
}
|
|
718
|
+
};
|
|
719
|
+
var MailClient = class {
|
|
720
|
+
constructor(rc) {
|
|
721
|
+
this.rc = rc;
|
|
722
|
+
}
|
|
723
|
+
async send(params) {
|
|
724
|
+
try {
|
|
725
|
+
const data = await this.rc.post("/mail/send", params);
|
|
726
|
+
return { success: data.success === true, error: data.error, data };
|
|
727
|
+
} catch (e) {
|
|
728
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
729
|
+
}
|
|
730
|
+
}
|
|
731
|
+
async getInbox(walletId) {
|
|
732
|
+
const data = await this.rc.get(
|
|
733
|
+
`/mail/inbox?walletId=${encodeURIComponent(walletId)}`
|
|
734
|
+
);
|
|
735
|
+
return data.messages ?? [];
|
|
736
|
+
}
|
|
737
|
+
async getSent(walletId) {
|
|
738
|
+
const data = await this.rc.get(
|
|
739
|
+
`/mail/sent?walletId=${encodeURIComponent(walletId)}`
|
|
740
|
+
);
|
|
741
|
+
return data.messages ?? [];
|
|
742
|
+
}
|
|
743
|
+
async getTrash(walletId) {
|
|
744
|
+
const data = await this.rc.get(
|
|
745
|
+
`/mail/trash?walletId=${encodeURIComponent(walletId)}`
|
|
746
|
+
);
|
|
747
|
+
return data.messages ?? [];
|
|
748
|
+
}
|
|
749
|
+
async getMessage(id) {
|
|
750
|
+
return this.rc.get(`/mail/message/${encodeURIComponent(id)}`);
|
|
751
|
+
}
|
|
752
|
+
async move(messageId, folder) {
|
|
753
|
+
try {
|
|
754
|
+
const data = await this.rc.post("/mail/move", {
|
|
755
|
+
messageId,
|
|
756
|
+
folder
|
|
757
|
+
});
|
|
758
|
+
return { success: data.success === true, error: data.error };
|
|
759
|
+
} catch (e) {
|
|
760
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
761
|
+
}
|
|
762
|
+
}
|
|
763
|
+
async markRead(messageId) {
|
|
764
|
+
try {
|
|
765
|
+
const data = await this.rc.post("/mail/read", {
|
|
766
|
+
messageId
|
|
767
|
+
});
|
|
768
|
+
return { success: data.success === true, error: data.error };
|
|
769
|
+
} catch (e) {
|
|
770
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
771
|
+
}
|
|
772
|
+
}
|
|
773
|
+
async delete(id) {
|
|
774
|
+
try {
|
|
775
|
+
const res = await this.rc.fetchFn(
|
|
776
|
+
`${this.rc.baseUrl}/mail/${encodeURIComponent(id)}`,
|
|
777
|
+
{ method: "DELETE", headers: this.rc.headers }
|
|
778
|
+
);
|
|
779
|
+
const data = await res.json();
|
|
780
|
+
return { success: data.success === true, error: data.error };
|
|
781
|
+
} catch (e) {
|
|
782
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
783
|
+
}
|
|
784
|
+
}
|
|
785
|
+
};
|
|
786
|
+
var MessengerClient = class {
|
|
787
|
+
constructor(rc) {
|
|
788
|
+
this.rc = rc;
|
|
789
|
+
}
|
|
790
|
+
async getWallets() {
|
|
791
|
+
const data = await this.rc.get("/messenger/wallets");
|
|
792
|
+
return data.wallets ?? [];
|
|
793
|
+
}
|
|
794
|
+
async registerWallet(walletId, displayName, encryptionPublicKey) {
|
|
795
|
+
try {
|
|
796
|
+
const data = await this.rc.post("/messenger/wallets/register", {
|
|
797
|
+
wallet_id: walletId,
|
|
798
|
+
display_name: displayName,
|
|
799
|
+
encryption_public_key: encryptionPublicKey
|
|
800
|
+
});
|
|
801
|
+
return { success: data.success === true, error: data.error };
|
|
802
|
+
} catch (e) {
|
|
803
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
async getConversations(walletId) {
|
|
807
|
+
const data = await this.rc.get(
|
|
808
|
+
`/messenger/conversations?walletId=${encodeURIComponent(walletId)}`
|
|
809
|
+
);
|
|
810
|
+
return data.conversations ?? [];
|
|
811
|
+
}
|
|
812
|
+
async createConversation(participants) {
|
|
813
|
+
try {
|
|
814
|
+
const data = await this.rc.post("/messenger/conversations", {
|
|
815
|
+
participants
|
|
816
|
+
});
|
|
817
|
+
return { success: data.success === true, error: data.error, data };
|
|
818
|
+
} catch (e) {
|
|
819
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
async getMessages(conversationId) {
|
|
823
|
+
const data = await this.rc.get(
|
|
824
|
+
`/messenger/messages?conversationId=${encodeURIComponent(conversationId)}`
|
|
825
|
+
);
|
|
826
|
+
return data.messages ?? [];
|
|
827
|
+
}
|
|
828
|
+
async sendMessage(conversationId, sender, encryptedContent, opts = {}) {
|
|
829
|
+
try {
|
|
830
|
+
const data = await this.rc.post("/messenger/messages", {
|
|
831
|
+
conversation_id: conversationId,
|
|
832
|
+
sender,
|
|
833
|
+
encrypted_content: encryptedContent,
|
|
834
|
+
media_type: opts.mediaType,
|
|
835
|
+
media_data: opts.mediaData,
|
|
836
|
+
self_destruct: opts.selfDestruct
|
|
837
|
+
});
|
|
838
|
+
return { success: data.success === true, error: data.error, data };
|
|
839
|
+
} catch (e) {
|
|
840
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
async markRead(messageId) {
|
|
844
|
+
try {
|
|
845
|
+
const data = await this.rc.post("/messenger/messages/read", {
|
|
846
|
+
message_id: messageId
|
|
847
|
+
});
|
|
848
|
+
return { success: data.success === true, error: data.error };
|
|
849
|
+
} catch (e) {
|
|
850
|
+
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
851
|
+
}
|
|
852
|
+
}
|
|
610
853
|
};
|
|
611
854
|
var Wallet = class _Wallet {
|
|
612
855
|
constructor(publicKey, privateKey) {
|
|
@@ -642,8 +885,8 @@ var Wallet = class _Wallet {
|
|
|
642
885
|
verify() {
|
|
643
886
|
try {
|
|
644
887
|
const msg = new TextEncoder().encode("rougechain-verify");
|
|
645
|
-
const sig = mlDsa_js.ml_dsa65.sign(hexToBytes(this.privateKey)
|
|
646
|
-
return mlDsa_js.ml_dsa65.verify(hexToBytes(this.publicKey)
|
|
888
|
+
const sig = mlDsa_js.ml_dsa65.sign(msg, hexToBytes(this.privateKey));
|
|
889
|
+
return mlDsa_js.ml_dsa65.verify(sig, msg, hexToBytes(this.publicKey));
|
|
647
890
|
} catch {
|
|
648
891
|
return false;
|
|
649
892
|
}
|
|
@@ -654,6 +897,9 @@ exports.BURN_ADDRESS = BURN_ADDRESS;
|
|
|
654
897
|
exports.RougeChain = RougeChain;
|
|
655
898
|
exports.Wallet = Wallet;
|
|
656
899
|
exports.bytesToHex = bytesToHex;
|
|
900
|
+
exports.createSignedBridgeWithdraw = createSignedBridgeWithdraw;
|
|
901
|
+
exports.createSignedTokenMetadataClaim = createSignedTokenMetadataClaim;
|
|
902
|
+
exports.createSignedTokenMetadataUpdate = createSignedTokenMetadataUpdate;
|
|
657
903
|
exports.generateNonce = generateNonce;
|
|
658
904
|
exports.hexToBytes = hexToBytes;
|
|
659
905
|
exports.isBurnAddress = isBurnAddress;
|