@xandeum/web3.js 1.2.0 → 1.3.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.
Files changed (117) hide show
  1. package/README.md +9 -6
  2. package/archbee.yaml +55 -0
  3. package/dist/armageddon.js +9 -1
  4. package/dist/assignCoowner.d.ts +12 -0
  5. package/dist/assignCoowner.js +89 -0
  6. package/dist/bigbang.d.ts +2 -1
  7. package/dist/bigbang.js +17 -3
  8. package/dist/const.d.ts +1 -0
  9. package/dist/const.js +2 -1
  10. package/dist/copyPath.js +9 -1
  11. package/dist/createDirectory.js +10 -2
  12. package/dist/createFile.js +10 -2
  13. package/dist/exists.js +7 -5
  14. package/dist/find.d.ts +22 -0
  15. package/dist/find.js +88 -0
  16. package/dist/getMetadata.js +7 -5
  17. package/dist/getXandeumResult.d.ts +15 -0
  18. package/dist/getXandeumResult.js +115 -0
  19. package/dist/helpers.d.ts +56 -0
  20. package/dist/helpers.js +80 -0
  21. package/dist/index.d.ts +5 -0
  22. package/dist/index.js +7 -1
  23. package/dist/listDirectoryEntery.js +7 -5
  24. package/dist/move.d.ts +14 -0
  25. package/dist/move.js +96 -0
  26. package/dist/pdaHelpers.d.ts +57 -0
  27. package/dist/pdaHelpers.js +83 -0
  28. package/dist/peek.js +9 -1
  29. package/dist/poke.js +9 -1
  30. package/dist/removeDirectory.js +9 -1
  31. package/dist/removeFile.js +9 -1
  32. package/dist/renamePath.js +9 -1
  33. package/dist/webSocket.d.ts +1 -1
  34. package/dist/webSocket.js +16 -3
  35. package/docs/html/assets/highlight.css +92 -0
  36. package/docs/html/assets/navigation.js +1 -0
  37. package/docs/html/assets/search.js +1 -0
  38. package/docs/{functions → html/functions}/armageddon.html +3 -3
  39. package/docs/html/functions/assignCoowner.html +8 -0
  40. package/docs/html/functions/bigbang.html +5 -0
  41. package/docs/{functions → html/functions}/copyPath.html +2 -8
  42. package/docs/{functions → html/functions}/createDirectory.html +2 -8
  43. package/docs/{functions → html/functions}/createFile.html +2 -9
  44. package/docs/{functions → html/functions}/exists.html +4 -4
  45. package/docs/html/functions/find.html +10 -0
  46. package/docs/html/functions/getMetadata.html +10 -0
  47. package/docs/html/functions/getXandeumResult.html +9 -0
  48. package/docs/{functions → html/functions}/listDirectoryEntry.html +4 -4
  49. package/docs/html/functions/move.html +9 -0
  50. package/docs/{functions → html/functions}/peek.html +2 -10
  51. package/docs/{functions → html/functions}/poke.html +2 -10
  52. package/docs/{functions → html/functions}/removeDirectory.html +2 -8
  53. package/docs/{functions → html/functions}/removeFile.html +2 -8
  54. package/docs/{functions → html/functions}/renamePath.html +3 -9
  55. package/docs/{functions → html/functions}/subscribeResult.html +4 -4
  56. package/docs/html/functions/unsubscribeResult.html +6 -0
  57. package/docs/{hierarchy.html → html/hierarchy.html} +1 -1
  58. package/docs/html/index.html +62 -0
  59. package/docs/html/modules.html +1 -0
  60. package/docs/markdown/README.md +166 -2
  61. package/docs/markdown/functions/armageddon.md +2 -3
  62. package/docs/markdown/functions/assignCoowner.md +46 -0
  63. package/docs/markdown/functions/bigbang.md +9 -3
  64. package/docs/markdown/functions/copyPath.md +2 -2
  65. package/docs/markdown/functions/createDirectory.md +2 -2
  66. package/docs/markdown/functions/createFile.md +2 -2
  67. package/docs/markdown/functions/exists.md +8 -8
  68. package/docs/markdown/functions/find.md +44 -0
  69. package/docs/markdown/functions/getMetadata.md +8 -8
  70. package/docs/markdown/functions/getXandeumResult.md +38 -0
  71. package/docs/markdown/functions/listDirectoryEntry.md +8 -8
  72. package/docs/markdown/functions/move.md +55 -0
  73. package/docs/markdown/functions/peek.md +2 -2
  74. package/docs/markdown/functions/poke.md +2 -2
  75. package/docs/markdown/functions/removeDirectory.md +2 -2
  76. package/docs/markdown/functions/removeFile.md +2 -2
  77. package/docs/markdown/functions/renamePath.md +2 -2
  78. package/docs/markdown/functions/subscribeResult.md +8 -8
  79. package/docs/markdown/functions/unsubscribeResult.md +8 -8
  80. package/docs/markdown/globals.md +6 -2
  81. package/package.json +3 -3
  82. package/src/armageddon.ts +8 -0
  83. package/src/assignCoowner.ts +49 -0
  84. package/src/bigbang.ts +13 -2
  85. package/src/const.ts +3 -1
  86. package/src/copyPath.ts +8 -1
  87. package/src/createDirectory.ts +9 -2
  88. package/src/createFile.ts +9 -3
  89. package/src/exists.ts +2 -1
  90. package/src/find.ts +53 -0
  91. package/src/getMetadata.ts +2 -1
  92. package/src/getXandeumResult.ts +67 -0
  93. package/src/helpers.ts +85 -0
  94. package/src/index.ts +5 -1
  95. package/src/listDirectoryEntery.ts +2 -1
  96. package/src/move.ts +62 -0
  97. package/src/peek.ts +8 -1
  98. package/src/poke.ts +8 -1
  99. package/src/removeDirectory.ts +8 -2
  100. package/src/removeFile.ts +8 -2
  101. package/src/renamePath.ts +8 -2
  102. package/src/webSocket.ts +18 -5
  103. package/typedoc.json +3 -4
  104. package/docs/assets/highlight.css +0 -22
  105. package/docs/assets/navigation.js +0 -1
  106. package/docs/assets/search.js +0 -1
  107. package/docs/functions/bigbang.html +0 -4
  108. package/docs/functions/getMetadata.html +0 -10
  109. package/docs/functions/unsubscribeResult.html +0 -6
  110. package/docs/index.html +0 -2
  111. package/docs/modules.html +0 -1
  112. /package/docs/{.nojekyll → html/.nojekyll} +0 -0
  113. /package/docs/{assets → html/assets}/hierarchy.js +0 -0
  114. /package/docs/{assets → html/assets}/icons.js +0 -0
  115. /package/docs/{assets → html/assets}/icons.svg +0 -0
  116. /package/docs/{assets → html/assets}/main.js +0 -0
  117. /package/docs/{assets → html/assets}/style.css +0 -0
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.getXandeumResult = getXandeumResult;
40
+ function sleep(ms) {
41
+ return new Promise(function (resolve) { return setTimeout(resolve, ms); });
42
+ }
43
+ /**
44
+ * Sends a JSON-RPC request to the Xandeum-compatible endpoint to retrieve
45
+ * the result of a transaction previously submitted with a specific signature.
46
+ *
47
+ * This function calls the custom RPC method `getXandeumResult`, which returns
48
+ * the result associated with the given transaction signature.
49
+ *
50
+ * @param connection - The Solana web3 connection object pointing to a Xandeum-compatible RPC endpoint.
51
+ * @param signature - The transaction signature string whose result should be queried.
52
+ *
53
+ * @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
54
+ * which includes the result of the transaction if available.
55
+ */
56
+ function getXandeumResult(connection, signature) {
57
+ return __awaiter(this, void 0, void 0, function () {
58
+ var url, maxAttempts, delayMs, attempt, response, text, data;
59
+ return __generator(this, function (_a) {
60
+ switch (_a.label) {
61
+ case 0:
62
+ url = connection.rpcEndpoint;
63
+ maxAttempts = 3;
64
+ delayMs = 5000;
65
+ attempt = 1;
66
+ _a.label = 1;
67
+ case 1:
68
+ if (!(attempt <= maxAttempts)) return [3 /*break*/, 8];
69
+ // Wait before every attempt (including the first one)
70
+ return [4 /*yield*/, sleep(delayMs)];
71
+ case 2:
72
+ // Wait before every attempt (including the first one)
73
+ _a.sent();
74
+ return [4 /*yield*/, fetch(url, {
75
+ method: "POST",
76
+ headers: { "Content-Type": "application/json" },
77
+ body: JSON.stringify({
78
+ jsonrpc: "2.0",
79
+ id: 1,
80
+ method: "getXandeumResult",
81
+ params: [signature],
82
+ }),
83
+ })];
84
+ case 3:
85
+ response = _a.sent();
86
+ if (!!response.ok) return [3 /*break*/, 5];
87
+ return [4 /*yield*/, response.text()];
88
+ case 4:
89
+ text = _a.sent();
90
+ console.error("Attempt ".concat(attempt, "/").concat(maxAttempts, " failed: ").concat(response.status, " ").concat(text));
91
+ if (attempt === maxAttempts) {
92
+ return [2 /*return*/, { result: null, error: "HTTP ".concat(response.status) }];
93
+ }
94
+ return [3 /*break*/, 7];
95
+ case 5: return [4 /*yield*/, response.json()];
96
+ case 6:
97
+ data = _a.sent();
98
+ // Change this condition if Xandeum uses a different "not ready" value
99
+ if ((data === null || data === void 0 ? void 0 : data.result) != null && data.result !== "pending") {
100
+ console.log("Got result on attempt ".concat(attempt));
101
+ return [2 /*return*/, data]; // Success — return immediately
102
+ }
103
+ console.log("Attempt ".concat(attempt, "/").concat(maxAttempts, ": still pending..."));
104
+ _a.label = 7;
105
+ case 7:
106
+ attempt++;
107
+ return [3 /*break*/, 1];
108
+ case 8:
109
+ // All 3 attempts done, still no result
110
+ console.log("Max attempts reached — result still not available");
111
+ return [2 /*return*/, { result: null, error: "Result not ready after 3 attempts" }];
112
+ }
113
+ });
114
+ });
115
+ }
@@ -0,0 +1,56 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ /**
3
+ * Seed used for deriving the fee distributor PDA
4
+ */
5
+ export declare const FEE_DISTRIBUTOR_SEED = "fee_distributor";
6
+ /**
7
+ * Duration of one pulse in seconds
8
+ */
9
+ export declare const PULSE_DURATION_SECONDS = 15;
10
+ /**
11
+ * Number of pulses in one yuga
12
+ */
13
+ export declare const PULSES_PER_YUGA = 16384;
14
+ /**
15
+ * Duration of one yuga in seconds (16384 * 15 = 245,760 seconds ≈ 2.84 days)
16
+ */
17
+ export declare const YUGA_DURATION_SECONDS: number;
18
+ /**
19
+ * Unix timestamp (in seconds) when the first yuga started
20
+ */
21
+ export declare const YUGA_START_TIMESTAMP = 1768898445;
22
+ /**
23
+ * Calculates the yuga number from a given unix timestamp.
24
+ *
25
+ * @param unixTimestamp - Unix timestamp in seconds
26
+ * @returns The yuga number for the given timestamp
27
+ */
28
+ export declare function getYugaFromTimestamp(unixTimestamp: number): number;
29
+ /**
30
+ * Gets the current yuga value.
31
+ * Yuga represents an epoch or era in the Xandeum system.
32
+ * Each yuga lasts 245,760 seconds (approximately 2.84 days).
33
+ *
34
+ * @returns The current yuga number
35
+ */
36
+ export declare function getCurrentYuga(): number;
37
+ /**
38
+ * Derives the Program Derived Address (PDA) for the fee distributor account.
39
+ *
40
+ * The PDA is derived using:
41
+ * - The fee distributor seed
42
+ * - The current yuga (epoch) as little-endian bytes
43
+ *
44
+ * @returns An object containing the PDA public key and bump seed
45
+ *
46
+ * @example
47
+ * ```typescript
48
+ * const { pda, bump } = getFeeDistributorPda()
49
+ * console.log('Fee Distributor PDA:', pda.toBase58())
50
+ * console.log('Bump seed:', bump)
51
+ * ```
52
+ */
53
+ export declare function getFeeDistributorPda(): {
54
+ pda: PublicKey;
55
+ bump: number;
56
+ };
@@ -0,0 +1,80 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.YUGA_START_TIMESTAMP = exports.YUGA_DURATION_SECONDS = exports.PULSES_PER_YUGA = exports.PULSE_DURATION_SECONDS = exports.FEE_DISTRIBUTOR_SEED = void 0;
7
+ exports.getYugaFromTimestamp = getYugaFromTimestamp;
8
+ exports.getCurrentYuga = getCurrentYuga;
9
+ exports.getFeeDistributorPda = getFeeDistributorPda;
10
+ var web3_js_1 = require("@solana/web3.js");
11
+ var const_1 = require("./const");
12
+ var bn_js_1 = __importDefault(require("bn.js"));
13
+ /**
14
+ * Seed used for deriving the fee distributor PDA
15
+ */
16
+ exports.FEE_DISTRIBUTOR_SEED = 'fee_distributor';
17
+ /**
18
+ * Duration of one pulse in seconds
19
+ */
20
+ exports.PULSE_DURATION_SECONDS = 15;
21
+ /**
22
+ * Number of pulses in one yuga
23
+ */
24
+ exports.PULSES_PER_YUGA = 16384;
25
+ /**
26
+ * Duration of one yuga in seconds (16384 * 15 = 245,760 seconds ≈ 2.84 days)
27
+ */
28
+ exports.YUGA_DURATION_SECONDS = exports.PULSES_PER_YUGA * exports.PULSE_DURATION_SECONDS;
29
+ /**
30
+ * Unix timestamp (in seconds) when the first yuga started
31
+ */
32
+ exports.YUGA_START_TIMESTAMP = 1768898445;
33
+ /**
34
+ * Calculates the yuga number from a given unix timestamp.
35
+ *
36
+ * @param unixTimestamp - Unix timestamp in seconds
37
+ * @returns The yuga number for the given timestamp
38
+ */
39
+ function getYugaFromTimestamp(unixTimestamp) {
40
+ if (unixTimestamp < exports.YUGA_START_TIMESTAMP) {
41
+ return 0;
42
+ }
43
+ return Math.floor((unixTimestamp - exports.YUGA_START_TIMESTAMP) / exports.YUGA_DURATION_SECONDS);
44
+ }
45
+ /**
46
+ * Gets the current yuga value.
47
+ * Yuga represents an epoch or era in the Xandeum system.
48
+ * Each yuga lasts 245,760 seconds (approximately 2.84 days).
49
+ *
50
+ * @returns The current yuga number
51
+ */
52
+ function getCurrentYuga() {
53
+ var currentTime = Math.floor(Date.now() / 1000);
54
+ return getYugaFromTimestamp(currentTime);
55
+ }
56
+ /**
57
+ * Derives the Program Derived Address (PDA) for the fee distributor account.
58
+ *
59
+ * The PDA is derived using:
60
+ * - The fee distributor seed
61
+ * - The current yuga (epoch) as little-endian bytes
62
+ *
63
+ * @returns An object containing the PDA public key and bump seed
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * const { pda, bump } = getFeeDistributorPda()
68
+ * console.log('Fee Distributor PDA:', pda.toBase58())
69
+ * console.log('Bump seed:', bump)
70
+ * ```
71
+ */
72
+ function getFeeDistributorPda() {
73
+ var yuga = getCurrentYuga();
74
+ var yugaBuffer = Buffer.from(new bn_js_1.default(yuga).toArray('le', 8));
75
+ var _a = web3_js_1.PublicKey.findProgramAddressSync([
76
+ Buffer.from(exports.FEE_DISTRIBUTOR_SEED, 'utf-8'),
77
+ yugaBuffer
78
+ ], new web3_js_1.PublicKey(const_1.stoincProgramId)), pda = _a[0], bump = _a[1];
79
+ return { pda: pda, bump: bump };
80
+ }
package/dist/index.d.ts CHANGED
@@ -9,6 +9,11 @@ export * from "./peek";
9
9
  export * from "./poke";
10
10
  export * from "./removeDirectory";
11
11
  export * from "./copyPath";
12
+ export * from "./move";
13
+ export * from "./getXandeumResult";
14
+ export * from "./assignCoowner";
12
15
  export { exists } from "./exists";
13
16
  export { listDirectoryEntry } from "./listDirectoryEntery";
14
17
  export { getMetadata } from "./getMetadata";
18
+ export { find } from "./find";
19
+ export * from "./helpers";
package/dist/index.js CHANGED
@@ -14,7 +14,7 @@ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
14
  for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
15
  };
16
16
  Object.defineProperty(exports, "__esModule", { value: true });
17
- exports.getMetadata = exports.listDirectoryEntry = exports.exists = exports.bigbang = void 0;
17
+ exports.find = exports.getMetadata = exports.listDirectoryEntry = exports.exists = exports.bigbang = void 0;
18
18
  var bigbang_1 = require("./bigbang");
19
19
  Object.defineProperty(exports, "bigbang", { enumerable: true, get: function () { return bigbang_1.bigbang; } });
20
20
  __exportStar(require("./webSocket"), exports);
@@ -27,9 +27,15 @@ __exportStar(require("./peek"), exports);
27
27
  __exportStar(require("./poke"), exports);
28
28
  __exportStar(require("./removeDirectory"), exports);
29
29
  __exportStar(require("./copyPath"), exports);
30
+ __exportStar(require("./move"), exports);
31
+ __exportStar(require("./getXandeumResult"), exports);
32
+ __exportStar(require("./assignCoowner"), exports);
30
33
  var exists_1 = require("./exists");
31
34
  Object.defineProperty(exports, "exists", { enumerable: true, get: function () { return exists_1.exists; } });
32
35
  var listDirectoryEntery_1 = require("./listDirectoryEntery");
33
36
  Object.defineProperty(exports, "listDirectoryEntry", { enumerable: true, get: function () { return listDirectoryEntery_1.listDirectoryEntry; } });
34
37
  var getMetadata_1 = require("./getMetadata");
35
38
  Object.defineProperty(exports, "getMetadata", { enumerable: true, get: function () { return getMetadata_1.getMetadata; } });
39
+ var find_1 = require("./find");
40
+ Object.defineProperty(exports, "find", { enumerable: true, get: function () { return find_1.find; } });
41
+ __exportStar(require("./helpers"), exports);
@@ -52,7 +52,7 @@ exports.listDirectoryEntry = listDirectoryEntry;
52
52
  */
53
53
  function listDirectoryEntry(connection, path) {
54
54
  return __awaiter(this, void 0, void 0, function () {
55
- var url, requestBody, response, data;
55
+ var url, requestBody, response, errorText, data;
56
56
  return __generator(this, function (_a) {
57
57
  switch (_a.label) {
58
58
  case 0:
@@ -72,11 +72,13 @@ function listDirectoryEntry(connection, path) {
72
72
  })];
73
73
  case 1:
74
74
  response = _a.sent();
75
- if (!response.ok) {
76
- throw new Error("HTTP error! Status: ".concat(response.status));
77
- }
78
- return [4 /*yield*/, response.json()];
75
+ if (!!response.ok) return [3 /*break*/, 3];
76
+ return [4 /*yield*/, response.text()];
79
77
  case 2:
78
+ errorText = _a.sent();
79
+ return [2 /*return*/, Error("error! status: ".concat(response.status, ", message: ").concat(errorText))];
80
+ case 3: return [4 /*yield*/, response.json()];
81
+ case 4:
80
82
  data = _a.sent();
81
83
  return [2 /*return*/, data];
82
84
  }
package/dist/move.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { Transaction, PublicKey } from '@solana/web3.js';
2
+ /**
3
+ * Constructs a Solana transaction to copy a file or directory from one path to another.
4
+ *
5
+ * @param fsid - The unique numeric identifier representing the target file system.
6
+ * @param srcPath - The source path to copy from (e.g., `/documents`).
7
+ * @param destPath - The destination path to copy to (e.g., `/archive`).
8
+ * @param name - The name of the new file or directory at the destination (e.g., `report.txt`).
9
+ * @param wallet - The wallet public key used to sign and authorize the transaction.
10
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the copyPath instruction.
11
+ * @throws Will throw an error if `srcPath` or `destPath` contains invalid characters.
12
+ *
13
+ */
14
+ export declare function move(fsid: string, srcPath: string, destPath: string, name: string, wallet: PublicKey): Promise<Transaction>;
package/dist/move.js ADDED
@@ -0,0 +1,96 @@
1
+ "use strict";
2
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
+ return new (P || (P = Promise))(function (resolve, reject) {
5
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
6
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
7
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
8
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
9
+ });
10
+ };
11
+ var __generator = (this && this.__generator) || function (thisArg, body) {
12
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
13
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
14
+ function verb(n) { return function (v) { return step([n, v]); }; }
15
+ function step(op) {
16
+ if (f) throw new TypeError("Generator is already executing.");
17
+ while (g && (g = 0, op[0] && (_ = 0)), _) try {
18
+ if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
19
+ if (y = 0, t) op = [op[0] & 2, t.value];
20
+ switch (op[0]) {
21
+ case 0: case 1: t = op; break;
22
+ case 4: _.label++; return { value: op[1], done: false };
23
+ case 5: _.label++; y = op[1]; op = [0]; continue;
24
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
25
+ default:
26
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
27
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
28
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
29
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
30
+ if (t[2]) _.ops.pop();
31
+ _.trys.pop(); continue;
32
+ }
33
+ op = body.call(thisArg, _);
34
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
35
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
36
+ }
37
+ };
38
+ var __importDefault = (this && this.__importDefault) || function (mod) {
39
+ return (mod && mod.__esModule) ? mod : { "default": mod };
40
+ };
41
+ Object.defineProperty(exports, "__esModule", { value: true });
42
+ exports.move = move;
43
+ var web3_js_1 = require("@solana/web3.js");
44
+ var bn_js_1 = __importDefault(require("bn.js"));
45
+ var const_1 = require("./const");
46
+ var sanitizePath_1 = require("./sanitizePath");
47
+ var helpers_1 = require("./helpers");
48
+ /**
49
+ * Constructs a Solana transaction to copy a file or directory from one path to another.
50
+ *
51
+ * @param fsid - The unique numeric identifier representing the target file system.
52
+ * @param srcPath - The source path to copy from (e.g., `/documents`).
53
+ * @param destPath - The destination path to copy to (e.g., `/archive`).
54
+ * @param name - The name of the new file or directory at the destination (e.g., `report.txt`).
55
+ * @param wallet - The wallet public key used to sign and authorize the transaction.
56
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the copyPath instruction.
57
+ * @throws Will throw an error if `srcPath` or `destPath` contains invalid characters.
58
+ *
59
+ */
60
+ function move(fsid, srcPath, destPath, name, wallet) {
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ var rest, instructionData, feeDistributorPda, instruction, tx;
63
+ return __generator(this, function (_a) {
64
+ // Validate path: only letters, numbers, and /
65
+ (0, sanitizePath_1.sanitizePath)(srcPath);
66
+ (0, sanitizePath_1.sanitizePath)(destPath);
67
+ (0, sanitizePath_1.sanitizePath)(name);
68
+ rest = Buffer.from("".concat(srcPath, "\0").concat(destPath, "\0").concat(name), 'utf-8');
69
+ instructionData = Buffer.concat([
70
+ Buffer.from(Int8Array.from([0]).buffer),
71
+ Buffer.from(Int8Array.from([13]).buffer),
72
+ Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
73
+ rest
74
+ ]);
75
+ feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
76
+ instruction = new web3_js_1.TransactionInstruction({
77
+ keys: [
78
+ {
79
+ pubkey: wallet,
80
+ isSigner: true,
81
+ isWritable: true
82
+ },
83
+ {
84
+ pubkey: feeDistributorPda.pda,
85
+ isSigner: false,
86
+ isWritable: true
87
+ }
88
+ ],
89
+ programId: new web3_js_1.PublicKey(const_1.programId),
90
+ data: instructionData
91
+ });
92
+ tx = new web3_js_1.Transaction().add(instruction);
93
+ return [2 /*return*/, tx];
94
+ });
95
+ });
96
+ }
@@ -0,0 +1,57 @@
1
+ import { PublicKey } from '@solana/web3.js';
2
+ /**
3
+ * Seed used for deriving the fee distributor PDA
4
+ */
5
+ export declare const FEE_DISTRIBUTOR_SEED = "fee_distributor";
6
+ /**
7
+ * Duration of one pulse in seconds
8
+ */
9
+ export declare const PULSE_DURATION_SECONDS = 15;
10
+ /**
11
+ * Number of pulses in one yuga
12
+ */
13
+ export declare const PULSES_PER_YUGA = 16384;
14
+ /**
15
+ * Duration of one yuga in seconds (16384 * 15 = 245,760 seconds ≈ 2.84 days)
16
+ */
17
+ export declare const YUGA_DURATION_SECONDS: number;
18
+ /**
19
+ * Unix timestamp (in seconds) when the first yuga started
20
+ * TODO: Update this with your actual genesis timestamp
21
+ */
22
+ export declare const YUGA_START_TIMESTAMP = 1640995200;
23
+ /**
24
+ * Calculates the yuga number from a given unix timestamp.
25
+ *
26
+ * @param unixTimestamp - Unix timestamp in seconds
27
+ * @returns The yuga number for the given timestamp
28
+ */
29
+ export declare function getYugaFromTimestamp(unixTimestamp: number): number;
30
+ /**
31
+ * Gets the current yuga value.
32
+ * Yuga represents an epoch or era in the Xandeum system.
33
+ * Each yuga lasts 245,760 seconds (approximately 2.84 days).
34
+ *
35
+ * @returns The current yuga number
36
+ */
37
+ export declare function getCurrentYuga(): number;
38
+ /**
39
+ * Derives the Program Derived Address (PDA) for the fee distributor account.
40
+ *
41
+ * The PDA is derived using:
42
+ * - The fee distributor seed
43
+ * - The current yuga (epoch) as little-endian bytes
44
+ *
45
+ * @returns An object containing the PDA public key and bump seed
46
+ *
47
+ * @example
48
+ * ```typescript
49
+ * const { pda, bump } = getFeeDistributorPda()
50
+ * console.log('Fee Distributor PDA:', pda.toBase58())
51
+ * console.log('Bump seed:', bump)
52
+ * ```
53
+ */
54
+ export declare function getFeeDistributorPda(): {
55
+ pda: PublicKey;
56
+ bump: number;
57
+ };
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.YUGA_START_TIMESTAMP = exports.YUGA_DURATION_SECONDS = exports.PULSES_PER_YUGA = exports.PULSE_DURATION_SECONDS = exports.FEE_DISTRIBUTOR_SEED = void 0;
7
+ exports.getYugaFromTimestamp = getYugaFromTimestamp;
8
+ exports.getCurrentYuga = getCurrentYuga;
9
+ exports.getFeeDistributorPda = getFeeDistributorPda;
10
+ var web3_js_1 = require("@solana/web3.js");
11
+ var const_1 = require("./const");
12
+ var bn_js_1 = __importDefault(require("bn.js"));
13
+ /**
14
+ * Seed used for deriving the fee distributor PDA
15
+ */
16
+ exports.FEE_DISTRIBUTOR_SEED = 'fee_distributor';
17
+ /**
18
+ * Duration of one pulse in seconds
19
+ */
20
+ exports.PULSE_DURATION_SECONDS = 15;
21
+ /**
22
+ * Number of pulses in one yuga
23
+ */
24
+ exports.PULSES_PER_YUGA = 16384;
25
+ /**
26
+ * Duration of one yuga in seconds (16384 * 15 = 245,760 seconds ≈ 2.84 days)
27
+ */
28
+ exports.YUGA_DURATION_SECONDS = exports.PULSES_PER_YUGA * exports.PULSE_DURATION_SECONDS;
29
+ /**
30
+ * Unix timestamp (in seconds) when the first yuga started
31
+ * TODO: Update this with your actual genesis timestamp
32
+ */
33
+ exports.YUGA_START_TIMESTAMP = 1640995200; // Placeholder - update as needed
34
+ /**
35
+ * Calculates the yuga number from a given unix timestamp.
36
+ *
37
+ * @param unixTimestamp - Unix timestamp in seconds
38
+ * @returns The yuga number for the given timestamp
39
+ */
40
+ function getYugaFromTimestamp(unixTimestamp) {
41
+ if (unixTimestamp < exports.YUGA_START_TIMESTAMP) {
42
+ return 0;
43
+ }
44
+ return Math.floor((unixTimestamp - exports.YUGA_START_TIMESTAMP) / exports.YUGA_DURATION_SECONDS);
45
+ }
46
+ /**
47
+ * Gets the current yuga value.
48
+ * Yuga represents an epoch or era in the Xandeum system.
49
+ * Each yuga lasts 245,760 seconds (approximately 2.84 days).
50
+ *
51
+ * @returns The current yuga number
52
+ */
53
+ function getCurrentYuga() {
54
+ var currentTime = Math.floor(Date.now() / 1000); // Convert milliseconds to seconds
55
+ return getYugaFromTimestamp(currentTime);
56
+ }
57
+ /**
58
+ * Derives the Program Derived Address (PDA) for the fee distributor account.
59
+ *
60
+ * The PDA is derived using:
61
+ * - The fee distributor seed
62
+ * - The current yuga (epoch) as little-endian bytes
63
+ *
64
+ * @returns An object containing the PDA public key and bump seed
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * const { pda, bump } = getFeeDistributorPda()
69
+ * console.log('Fee Distributor PDA:', pda.toBase58())
70
+ * console.log('Bump seed:', bump)
71
+ * ```
72
+ */
73
+ function getFeeDistributorPda() {
74
+ var yuga = getCurrentYuga();
75
+ // Convert yuga to little-endian 8-byte array
76
+ var yugaBuffer = Buffer.from(new bn_js_1.default(yuga).toArray('le', 8));
77
+ // Find the PDA using the seed and yuga bytes
78
+ var _a = web3_js_1.PublicKey.findProgramAddressSync([
79
+ Buffer.from(exports.FEE_DISTRIBUTOR_SEED, 'utf-8'),
80
+ yugaBuffer
81
+ ], new web3_js_1.PublicKey(const_1.programId)), pda = _a[0], bump = _a[1];
82
+ return { pda: pda, bump: bump };
83
+ }
package/dist/peek.js CHANGED
@@ -44,6 +44,7 @@ var web3_js_1 = require("@solana/web3.js");
44
44
  var bn_js_1 = __importDefault(require("bn.js"));
45
45
  var const_1 = require("./const");
46
46
  var sanitizePath_1 = require("./sanitizePath");
47
+ var helpers_1 = require("./helpers");
47
48
  /**
48
49
  * Constructs a Solana transaction to perform a "peek" operation on a file within a file system.
49
50
  *
@@ -59,23 +60,30 @@ var sanitizePath_1 = require("./sanitizePath");
59
60
  */
60
61
  function peek(fsid, path, startPosition, endPosition, wallet) {
61
62
  return __awaiter(this, void 0, void 0, function () {
62
- var rest, instructionData, instruction, tx;
63
+ var rest, instructionData, feeDistributorPda, instruction, tx;
63
64
  return __generator(this, function (_a) {
64
65
  (0, sanitizePath_1.sanitizePath)(path);
65
66
  rest = Buffer.from("".concat(path), 'utf-8');
66
67
  instructionData = Buffer.concat([
68
+ Buffer.from(Int8Array.from([0]).buffer),
67
69
  Buffer.from(Int8Array.from([3]).buffer),
68
70
  Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
69
71
  Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(startPosition).toArray('le', 8))),
70
72
  Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(endPosition).toArray('le', 8))),
71
73
  rest
72
74
  ]);
75
+ feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
73
76
  instruction = new web3_js_1.TransactionInstruction({
74
77
  keys: [
75
78
  {
76
79
  pubkey: wallet,
77
80
  isSigner: true,
78
81
  isWritable: true
82
+ },
83
+ {
84
+ pubkey: feeDistributorPda.pda,
85
+ isSigner: false,
86
+ isWritable: true
79
87
  }
80
88
  ],
81
89
  programId: new web3_js_1.PublicKey(const_1.programId),
package/dist/poke.js CHANGED
@@ -44,6 +44,7 @@ var web3_js_1 = require("@solana/web3.js");
44
44
  var bn_js_1 = __importDefault(require("bn.js"));
45
45
  var const_1 = require("./const");
46
46
  var sanitizePath_1 = require("./sanitizePath");
47
+ var helpers_1 = require("./helpers");
47
48
  /**
48
49
  * Constructs a Solana transaction to perform a poke\operation, which writes data
49
50
  * to a file at the specified path and byte position.
@@ -58,18 +59,20 @@ var sanitizePath_1 = require("./sanitizePath");
58
59
  */
59
60
  function poke(fsid, path, position, wallet, dataKey) {
60
61
  return __awaiter(this, void 0, void 0, function () {
61
- var pathBuffer, pathLengthBuffer, instructionData, instruction, tx;
62
+ var pathBuffer, pathLengthBuffer, instructionData, feeDistributorPda, instruction, tx;
62
63
  return __generator(this, function (_a) {
63
64
  (0, sanitizePath_1.sanitizePath)(path);
64
65
  pathBuffer = Buffer.from(path, 'utf-8');
65
66
  pathLengthBuffer = Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(pathBuffer.length).toArray('le', 8)));
66
67
  instructionData = Buffer.concat([
68
+ Buffer.from(Int8Array.from([0]).buffer),
67
69
  Buffer.from(Int8Array.from([4]).buffer),
68
70
  Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
69
71
  Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(position).toArray('le', 8))),
70
72
  pathLengthBuffer,
71
73
  pathBuffer
72
74
  ]);
75
+ feeDistributorPda = (0, helpers_1.getFeeDistributorPda)();
73
76
  instruction = new web3_js_1.TransactionInstruction({
74
77
  keys: [
75
78
  {
@@ -81,6 +84,11 @@ function poke(fsid, path, position, wallet, dataKey) {
81
84
  pubkey: dataKey,
82
85
  isSigner: false,
83
86
  isWritable: false
87
+ },
88
+ {
89
+ pubkey: feeDistributorPda.pda,
90
+ isSigner: false,
91
+ isWritable: true
84
92
  }
85
93
  ],
86
94
  programId: new web3_js_1.PublicKey(const_1.programId),