@rougechain/sdk 1.0.0 → 1.1.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 CHANGED
@@ -363,6 +363,7 @@ var RougeChain = class {
363
363
  this.mail = new MailClient(this);
364
364
  this.messenger = new MessengerClient(this);
365
365
  this.shielded = new ShieldedClient(this);
366
+ this.social = new SocialClient(this);
366
367
  }
367
368
  // ===== Internal helpers =====
368
369
  /** @internal */
@@ -994,14 +995,29 @@ var MailClient = class {
994
995
  }
995
996
  // --- Mail (signed) ---
996
997
  async send(wallet, params) {
998
+ const sigPayload = params.encrypted_subject + "|" + params.encrypted_body + (params.encrypted_attachment ? "|" + params.encrypted_attachment : "");
999
+ let contentSig = params.content_signature || "";
1000
+ if (!contentSig && wallet.privateKey) {
1001
+ try {
1002
+ const { ml_dsa65: ml_dsa654 } = await import('@noble/post-quantum/ml-dsa.js');
1003
+ const privKey = typeof wallet.privateKey === "string" ? hexToBytes(wallet.privateKey) : wallet.privateKey;
1004
+ const sigBytes = ml_dsa654.sign(
1005
+ new TextEncoder().encode(sigPayload),
1006
+ privKey
1007
+ );
1008
+ contentSig = bytesToHex(sigBytes);
1009
+ } catch {
1010
+ }
1011
+ }
997
1012
  const signed = signRequest(wallet, {
998
1013
  fromWalletId: params.from,
999
1014
  toWalletIds: [params.to],
1000
1015
  subjectEncrypted: params.encrypted_subject,
1001
1016
  bodyEncrypted: params.encrypted_body,
1002
- contentSignature: params.body,
1017
+ attachmentEncrypted: params.encrypted_attachment,
1018
+ contentSignature: contentSig,
1003
1019
  replyToId: params.reply_to_id,
1004
- hasAttachment: false
1020
+ hasAttachment: !!params.encrypted_attachment
1005
1021
  });
1006
1022
  return this.rc.submitTx("/v2/mail/send", signed);
1007
1023
  }
@@ -1213,6 +1229,106 @@ var ShieldedClient = class {
1213
1229
  return this.rc.get("/contracts");
1214
1230
  }
1215
1231
  };
1232
+ var SocialClient = class {
1233
+ constructor(rc) {
1234
+ this.rc = rc;
1235
+ }
1236
+ async recordPlay(wallet, trackId) {
1237
+ const signed = signRequest(wallet, { trackId });
1238
+ return this.rc.submitTx("/v2/social/play", signed);
1239
+ }
1240
+ async toggleLike(wallet, trackId) {
1241
+ const signed = signRequest(wallet, { trackId });
1242
+ return this.rc.submitTx("/v2/social/like", signed);
1243
+ }
1244
+ async postComment(wallet, trackId, body) {
1245
+ const signed = signRequest(wallet, { trackId, body });
1246
+ return this.rc.submitTx("/v2/social/comment", signed);
1247
+ }
1248
+ async deleteComment(wallet, commentId) {
1249
+ const signed = signRequest(wallet, { commentId });
1250
+ return this.rc.submitTx("/v2/social/comment/delete", signed);
1251
+ }
1252
+ async toggleFollow(wallet, artistPubkey) {
1253
+ const signed = signRequest(wallet, { artistPubkey });
1254
+ return this.rc.submitTx("/v2/social/follow", signed);
1255
+ }
1256
+ async getTrackStats(trackId, viewerPubkey) {
1257
+ const q = viewerPubkey ? `?viewer=${encodeURIComponent(viewerPubkey)}` : "";
1258
+ return this.rc.get(`/social/track/${encodeURIComponent(trackId)}/stats${q}`);
1259
+ }
1260
+ async getComments(trackId, limit = 50, offset = 0) {
1261
+ const data = await this.rc.get(
1262
+ `/social/track/${encodeURIComponent(trackId)}/comments?limit=${limit}&offset=${offset}`
1263
+ );
1264
+ return data.comments ?? [];
1265
+ }
1266
+ async getArtistStats(pubkey, viewerPubkey) {
1267
+ const q = viewerPubkey ? `?viewer=${encodeURIComponent(viewerPubkey)}` : "";
1268
+ return this.rc.get(`/social/artist/${encodeURIComponent(pubkey)}/stats${q}`);
1269
+ }
1270
+ async getUserLikes(pubkey) {
1271
+ const data = await this.rc.get(`/social/user/${encodeURIComponent(pubkey)}/likes`);
1272
+ return data.trackIds ?? [];
1273
+ }
1274
+ async getUserFollowing(pubkey) {
1275
+ const data = await this.rc.get(`/social/user/${encodeURIComponent(pubkey)}/following`);
1276
+ return data.artists ?? [];
1277
+ }
1278
+ // ── Posts ──────────────────────────────────────────────
1279
+ async createPost(wallet, body, replyToId) {
1280
+ const payload = { body };
1281
+ if (replyToId) payload.replyToId = replyToId;
1282
+ const signed = signRequest(wallet, payload);
1283
+ return this.rc.submitTx("/v2/social/post", signed);
1284
+ }
1285
+ async deletePost(wallet, postId) {
1286
+ const signed = signRequest(wallet, { postId });
1287
+ return this.rc.submitTx("/v2/social/post/delete", signed);
1288
+ }
1289
+ async toggleRepost(wallet, postId) {
1290
+ const signed = signRequest(wallet, { postId });
1291
+ return this.rc.submitTx("/v2/social/repost", signed);
1292
+ }
1293
+ async getPost(postId, viewerPubkey) {
1294
+ const q = viewerPubkey ? `?viewer=${encodeURIComponent(viewerPubkey)}` : "";
1295
+ try {
1296
+ return await this.rc.get(`/social/post/${encodeURIComponent(postId)}${q}`);
1297
+ } catch {
1298
+ return null;
1299
+ }
1300
+ }
1301
+ async getPostStats(postId, viewerPubkey) {
1302
+ const q = viewerPubkey ? `?viewer=${encodeURIComponent(viewerPubkey)}` : "";
1303
+ return this.rc.get(`/social/post/${encodeURIComponent(postId)}/stats${q}`);
1304
+ }
1305
+ async getPostReplies(postId, limit = 50, offset = 0) {
1306
+ const data = await this.rc.get(
1307
+ `/social/post/${encodeURIComponent(postId)}/replies?limit=${limit}&offset=${offset}`
1308
+ );
1309
+ return data.replies ?? [];
1310
+ }
1311
+ async getUserPosts(pubkey, limit = 50, offset = 0) {
1312
+ return this.rc.get(
1313
+ `/social/user/${encodeURIComponent(pubkey)}/posts?limit=${limit}&offset=${offset}`
1314
+ );
1315
+ }
1316
+ async getGlobalTimeline(limit = 50, offset = 0) {
1317
+ const data = await this.rc.get(
1318
+ `/social/timeline?limit=${limit}&offset=${offset}`
1319
+ );
1320
+ return data.posts ?? [];
1321
+ }
1322
+ async getFollowingFeed(wallet, limit = 50, offset = 0) {
1323
+ const signed = signRequest(wallet, { limit, offset });
1324
+ try {
1325
+ const data = await this.rc.submitTx("/v2/social/feed", signed);
1326
+ return data.posts ?? [];
1327
+ } catch {
1328
+ return [];
1329
+ }
1330
+ }
1331
+ };
1216
1332
 
1217
1333
  // src/address.ts
1218
1334
  var CHARSET = "qpzry9x8gf2tvdw0s3jn54khce6mua7l";