@rougechain/sdk 0.8.4 → 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 +37 -31
- package/dist/index.cjs +115 -138
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +115 -139
- 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() {
|
|
@@ -957,17 +960,10 @@ var MailClient = class {
|
|
|
957
960
|
constructor(rc) {
|
|
958
961
|
this.rc = rc;
|
|
959
962
|
}
|
|
960
|
-
// --- Name Registry ---
|
|
961
|
-
async registerName(name, walletId) {
|
|
962
|
-
|
|
963
|
-
|
|
964
|
-
name,
|
|
965
|
-
walletId
|
|
966
|
-
});
|
|
967
|
-
return { success: data.success === true, error: data.error, data };
|
|
968
|
-
} catch (e) {
|
|
969
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
970
|
-
}
|
|
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);
|
|
971
967
|
}
|
|
972
968
|
async resolveName(name) {
|
|
973
969
|
try {
|
|
@@ -990,85 +986,71 @@ var MailClient = class {
|
|
|
990
986
|
return null;
|
|
991
987
|
}
|
|
992
988
|
}
|
|
993
|
-
async releaseName(
|
|
994
|
-
|
|
995
|
-
|
|
996
|
-
|
|
997
|
-
|
|
998
|
-
|
|
999
|
-
|
|
1000
|
-
|
|
1001
|
-
|
|
1002
|
-
|
|
1003
|
-
|
|
1004
|
-
|
|
1005
|
-
|
|
1006
|
-
|
|
1007
|
-
}
|
|
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);
|
|
1008
1005
|
}
|
|
1009
|
-
|
|
1010
|
-
|
|
1006
|
+
async getInbox(wallet) {
|
|
1007
|
+
const signed = signRequest(wallet, { folder: "inbox" });
|
|
1011
1008
|
try {
|
|
1012
|
-
const data = await this.rc.post("/mail/
|
|
1013
|
-
return
|
|
1014
|
-
} catch
|
|
1015
|
-
return
|
|
1009
|
+
const data = await this.rc.post("/v2/mail/folder", signed);
|
|
1010
|
+
return data.messages ?? [];
|
|
1011
|
+
} catch {
|
|
1012
|
+
return [];
|
|
1016
1013
|
}
|
|
1017
1014
|
}
|
|
1018
|
-
async
|
|
1019
|
-
const
|
|
1020
|
-
`/mail/inbox?walletId=${encodeURIComponent(walletId)}`
|
|
1021
|
-
);
|
|
1022
|
-
return data.messages ?? [];
|
|
1023
|
-
}
|
|
1024
|
-
async getSent(walletId) {
|
|
1025
|
-
const data = await this.rc.get(
|
|
1026
|
-
`/mail/sent?walletId=${encodeURIComponent(walletId)}`
|
|
1027
|
-
);
|
|
1028
|
-
return data.messages ?? [];
|
|
1029
|
-
}
|
|
1030
|
-
async getTrash(walletId) {
|
|
1031
|
-
const data = await this.rc.get(
|
|
1032
|
-
`/mail/trash?walletId=${encodeURIComponent(walletId)}`
|
|
1033
|
-
);
|
|
1034
|
-
return data.messages ?? [];
|
|
1035
|
-
}
|
|
1036
|
-
async getMessage(id) {
|
|
1037
|
-
return this.rc.get(`/mail/message/${encodeURIComponent(id)}`);
|
|
1038
|
-
}
|
|
1039
|
-
async move(messageId, folder) {
|
|
1015
|
+
async getSent(wallet) {
|
|
1016
|
+
const signed = signRequest(wallet, { folder: "sent" });
|
|
1040
1017
|
try {
|
|
1041
|
-
const data = await this.rc.post("/mail/
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
return { success: data.success === true, error: data.error };
|
|
1046
|
-
} catch (e) {
|
|
1047
|
-
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 [];
|
|
1048
1022
|
}
|
|
1049
1023
|
}
|
|
1050
|
-
async
|
|
1024
|
+
async getTrash(wallet) {
|
|
1025
|
+
const signed = signRequest(wallet, { folder: "trash" });
|
|
1051
1026
|
try {
|
|
1052
|
-
const data = await this.rc.post("/mail/
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
return
|
|
1056
|
-
} catch (e) {
|
|
1057
|
-
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 [];
|
|
1058
1031
|
}
|
|
1059
1032
|
}
|
|
1060
|
-
async
|
|
1033
|
+
async getMessage(wallet, messageId) {
|
|
1034
|
+
const signed = signRequest(wallet, { messageId });
|
|
1061
1035
|
try {
|
|
1062
|
-
const
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
const data = await res.json();
|
|
1067
|
-
return { success: data.success === true, error: data.error };
|
|
1068
|
-
} catch (e) {
|
|
1069
|
-
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;
|
|
1070
1040
|
}
|
|
1071
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
|
+
}
|
|
1072
1054
|
};
|
|
1073
1055
|
var MessengerClient = class {
|
|
1074
1056
|
constructor(rc) {
|
|
@@ -1078,77 +1060,71 @@ var MessengerClient = class {
|
|
|
1078
1060
|
const data = await this.rc.get("/messenger/wallets");
|
|
1079
1061
|
return data.wallets ?? [];
|
|
1080
1062
|
}
|
|
1081
|
-
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, {});
|
|
1082
1075
|
try {
|
|
1083
|
-
const data = await this.rc.post(
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1076
|
+
const data = await this.rc.post(
|
|
1077
|
+
"/v2/messenger/conversations/list",
|
|
1078
|
+
signed
|
|
1079
|
+
);
|
|
1080
|
+
return data.conversations ?? [];
|
|
1081
|
+
} catch {
|
|
1082
|
+
return [];
|
|
1087
1083
|
}
|
|
1088
1084
|
}
|
|
1089
|
-
async
|
|
1090
|
-
const
|
|
1091
|
-
|
|
1092
|
-
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
);
|
|
1096
|
-
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);
|
|
1097
1092
|
}
|
|
1098
|
-
async
|
|
1093
|
+
async getMessages(wallet, conversationId) {
|
|
1094
|
+
const signed = signRequest(wallet, { conversationId });
|
|
1099
1095
|
try {
|
|
1100
|
-
const data = await this.rc.post(
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1096
|
+
const data = await this.rc.post(
|
|
1097
|
+
"/v2/messenger/messages/list",
|
|
1098
|
+
signed
|
|
1099
|
+
);
|
|
1100
|
+
return data.messages ?? [];
|
|
1101
|
+
} catch {
|
|
1102
|
+
return [];
|
|
1106
1103
|
}
|
|
1107
1104
|
}
|
|
1108
|
-
async
|
|
1109
|
-
const
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
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);
|
|
1113
1116
|
}
|
|
1114
|
-
async
|
|
1115
|
-
|
|
1116
|
-
|
|
1117
|
-
conversationId,
|
|
1118
|
-
senderWalletId,
|
|
1119
|
-
encryptedContent,
|
|
1120
|
-
signature: opts.signature ?? "",
|
|
1121
|
-
messageType: opts.messageType ?? "text",
|
|
1122
|
-
selfDestruct: opts.selfDestruct ?? false,
|
|
1123
|
-
destructAfterSeconds: opts.destructAfterSeconds,
|
|
1124
|
-
spoiler: opts.spoiler ?? false
|
|
1125
|
-
});
|
|
1126
|
-
return { success: data.success === true, error: data.error, data };
|
|
1127
|
-
} catch (e) {
|
|
1128
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1129
|
-
}
|
|
1117
|
+
async deleteMessage(wallet, messageId, conversationId) {
|
|
1118
|
+
const signed = signRequest(wallet, { messageId, conversationId });
|
|
1119
|
+
return this.rc.submitTx("/v2/messenger/messages/delete", signed);
|
|
1130
1120
|
}
|
|
1131
|
-
async
|
|
1132
|
-
|
|
1133
|
-
|
|
1134
|
-
`${this.rc.baseUrl}/messenger/messages/${encodeURIComponent(messageId)}`,
|
|
1135
|
-
{ method: "DELETE", headers: this.rc.headers }
|
|
1136
|
-
);
|
|
1137
|
-
const data = await res.json();
|
|
1138
|
-
return { success: data.success === true, error: data.error };
|
|
1139
|
-
} catch (e) {
|
|
1140
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1141
|
-
}
|
|
1121
|
+
async deleteConversation(wallet, conversationId) {
|
|
1122
|
+
const signed = signRequest(wallet, { conversationId });
|
|
1123
|
+
return this.rc.submitTx("/v2/messenger/conversations/delete", signed);
|
|
1142
1124
|
}
|
|
1143
|
-
async markRead(messageId) {
|
|
1144
|
-
|
|
1145
|
-
|
|
1146
|
-
messageId
|
|
1147
|
-
});
|
|
1148
|
-
return { success: data.success === true, error: data.error };
|
|
1149
|
-
} catch (e) {
|
|
1150
|
-
return { success: false, error: e instanceof Error ? e.message : String(e) };
|
|
1151
|
-
}
|
|
1125
|
+
async markRead(wallet, messageId, conversationId) {
|
|
1126
|
+
const signed = signRequest(wallet, { messageId, conversationId });
|
|
1127
|
+
return this.rc.submitTx("/v2/messenger/messages/read", signed);
|
|
1152
1128
|
}
|
|
1153
1129
|
};
|
|
1154
1130
|
var ShieldedClient = class {
|
|
@@ -1457,6 +1433,6 @@ var Wallet = class _Wallet {
|
|
|
1457
1433
|
}
|
|
1458
1434
|
};
|
|
1459
1435
|
|
|
1460
|
-
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 };
|
|
1461
1437
|
//# sourceMappingURL=index.js.map
|
|
1462
1438
|
//# sourceMappingURL=index.js.map
|