@xandeum/web3.js 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.
Files changed (103) hide show
  1. package/LICENSE +51 -0
  2. package/README.md +164 -0
  3. package/dist/armageddon.d.ts +10 -0
  4. package/dist/armageddon.js +77 -0
  5. package/dist/bigbang.d.ts +8 -0
  6. package/dist/bigbang.js +70 -0
  7. package/dist/const.d.ts +1 -0
  8. package/dist/const.js +4 -0
  9. package/dist/copyPath.d.ts +13 -0
  10. package/dist/copyPath.js +86 -0
  11. package/dist/createDirectory.d.ts +12 -0
  12. package/dist/createDirectory.js +84 -0
  13. package/dist/createFile.d.ts +13 -0
  14. package/dist/createFile.js +85 -0
  15. package/dist/exists.d.ts +20 -0
  16. package/dist/exists.js +84 -0
  17. package/dist/getInfo.d.ts +12 -0
  18. package/dist/getInfo.js +77 -0
  19. package/dist/getMetadata.d.ts +23 -0
  20. package/dist/getMetadata.js +87 -0
  21. package/dist/index.d.ts +14 -0
  22. package/dist/index.js +35 -0
  23. package/dist/listDirectoryEntery.d.ts +21 -0
  24. package/dist/listDirectoryEntery.js +85 -0
  25. package/dist/peek.d.ts +15 -0
  26. package/dist/peek.js +88 -0
  27. package/dist/poke.d.ts +14 -0
  28. package/dist/poke.js +93 -0
  29. package/dist/removeDirectory.d.ts +12 -0
  30. package/dist/removeDirectory.js +82 -0
  31. package/dist/removeFile.d.ts +12 -0
  32. package/dist/removeFile.js +82 -0
  33. package/dist/renamePath.d.ts +13 -0
  34. package/dist/renamePath.js +85 -0
  35. package/dist/sanitizePath.d.ts +14 -0
  36. package/dist/sanitizePath.js +60 -0
  37. package/dist/webSocket.d.ts +47 -0
  38. package/dist/webSocket.js +90 -0
  39. package/docs/.nojekyll +1 -0
  40. package/docs/assets/hierarchy.js +1 -0
  41. package/docs/assets/highlight.css +22 -0
  42. package/docs/assets/icons.js +18 -0
  43. package/docs/assets/icons.svg +1 -0
  44. package/docs/assets/main.js +60 -0
  45. package/docs/assets/navigation.js +1 -0
  46. package/docs/assets/search.js +1 -0
  47. package/docs/assets/style.css +1640 -0
  48. package/docs/functions/armageddon.html +6 -0
  49. package/docs/functions/bigbang.html +4 -0
  50. package/docs/functions/copyPath.html +14 -0
  51. package/docs/functions/createDirectory.html +14 -0
  52. package/docs/functions/createFile.html +16 -0
  53. package/docs/functions/exists.html +8 -0
  54. package/docs/functions/getMetadata.html +10 -0
  55. package/docs/functions/listDirectoryEntry.html +9 -0
  56. package/docs/functions/peek.html +18 -0
  57. package/docs/functions/poke.html +18 -0
  58. package/docs/functions/removeDirectory.html +14 -0
  59. package/docs/functions/removeFile.html +14 -0
  60. package/docs/functions/renamePath.html +15 -0
  61. package/docs/functions/subscribeResult.html +17 -0
  62. package/docs/functions/unsubscribeResult.html +6 -0
  63. package/docs/hierarchy.html +1 -0
  64. package/docs/index.html +2 -0
  65. package/docs/markdown/.nojekyll +0 -0
  66. package/docs/markdown/README.md +5 -0
  67. package/docs/markdown/functions/armageddon.md +35 -0
  68. package/docs/markdown/functions/bigbang.md +27 -0
  69. package/docs/markdown/functions/copyPath.md +49 -0
  70. package/docs/markdown/functions/createDirectory.md +49 -0
  71. package/docs/markdown/functions/createFile.md +50 -0
  72. package/docs/markdown/functions/exists.md +37 -0
  73. package/docs/markdown/functions/getMetadata.md +39 -0
  74. package/docs/markdown/functions/listDirectoryEntry.md +38 -0
  75. package/docs/markdown/functions/peek.md +57 -0
  76. package/docs/markdown/functions/poke.md +56 -0
  77. package/docs/markdown/functions/removeDirectory.md +44 -0
  78. package/docs/markdown/functions/removeFile.md +44 -0
  79. package/docs/markdown/functions/renamePath.md +50 -0
  80. package/docs/markdown/functions/subscribeResult.md +60 -0
  81. package/docs/markdown/functions/unsubscribeResult.md +34 -0
  82. package/docs/markdown/globals.md +23 -0
  83. package/docs/modules.html +1 -0
  84. package/package.json +26 -0
  85. package/src/armageddon.ts +36 -0
  86. package/src/bigbang.ts +29 -0
  87. package/src/const.ts +1 -0
  88. package/src/copyPath.ts +51 -0
  89. package/src/createDirectory.ts +47 -0
  90. package/src/createFile.ts +47 -0
  91. package/src/exists.ts +46 -0
  92. package/src/getMetadata.ts +49 -0
  93. package/src/index.ts +15 -0
  94. package/src/listDirectoryEntery.ts +50 -0
  95. package/src/peek.ts +52 -0
  96. package/src/poke.ts +59 -0
  97. package/src/removeDirectory.ts +43 -0
  98. package/src/removeFile.ts +44 -0
  99. package/src/renamePath.ts +50 -0
  100. package/src/sanitizePath.ts +69 -0
  101. package/src/webSocket.ts +118 -0
  102. package/tsconfig.json +14 -0
  103. package/typedoc.json +27 -0
package/dist/peek.js ADDED
@@ -0,0 +1,88 @@
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.peek = peek;
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
+ /**
48
+ * Constructs a Solana transaction to perform a "peek" operation on a file within a file system.
49
+ *
50
+ * The peek operation reads data between two byte offsets within a specified file path.
51
+ *
52
+ * @param fsid - A stringified integer representing the file system ID in which the file resides.
53
+ * @param path - The path to the file to be peeked.
54
+ * @param startPosition - The starting byte offset (inclusive) to begin reading from.
55
+ * @param endPosition - The ending byte offset (exclusive) to stop reading at.
56
+ * @param wallet - The public key of the wallet that will sign and authorize the transaction.
57
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the peek instruction.
58
+ * @throws Will throw an error if the `path` contains invalid characters.
59
+ */
60
+ function peek(fsid, path, startPosition, endPosition, wallet) {
61
+ return __awaiter(this, void 0, void 0, function () {
62
+ var rest, instructionData, instruction, tx;
63
+ return __generator(this, function (_a) {
64
+ (0, sanitizePath_1.sanitizePath)(path);
65
+ rest = Buffer.from("".concat(path), 'utf-8');
66
+ instructionData = Buffer.concat([
67
+ Buffer.from(Int8Array.from([3]).buffer),
68
+ Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
69
+ Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(startPosition).toArray('le', 8))),
70
+ Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(endPosition).toArray('le', 8))),
71
+ rest
72
+ ]);
73
+ instruction = new web3_js_1.TransactionInstruction({
74
+ keys: [
75
+ {
76
+ pubkey: wallet,
77
+ isSigner: true,
78
+ isWritable: true
79
+ }
80
+ ],
81
+ programId: new web3_js_1.PublicKey(const_1.programId),
82
+ data: instructionData
83
+ });
84
+ tx = new web3_js_1.Transaction().add(instruction);
85
+ return [2 /*return*/, tx];
86
+ });
87
+ });
88
+ }
package/dist/poke.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { Transaction, PublicKey } from '@solana/web3.js';
2
+ /**
3
+ * Constructs a Solana transaction to perform a poke\operation, which writes data
4
+ * to a file at the specified path and byte position.
5
+ *
6
+ * @param fsid - A stringified integer representing the file system ID where the file resides.
7
+ * @param path - The path to the file to be written to.
8
+ * @param position - The byte offset in the file where data should be written.
9
+ * @param wallet - The public key of the wallet that signs and authorizes the transaction.
10
+ * @param dataKey - A public key of a data account that holds the content to be written to the file.
11
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the poke instruction.
12
+ * @throws Will throw an error if the `path` contains invalid characters.
13
+ */
14
+ export declare function poke(fsid: string, path: string, position: number, wallet: PublicKey, dataKey: PublicKey): Promise<Transaction>;
package/dist/poke.js ADDED
@@ -0,0 +1,93 @@
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.poke = poke;
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
+ /**
48
+ * Constructs a Solana transaction to perform a poke\operation, which writes data
49
+ * to a file at the specified path and byte position.
50
+ *
51
+ * @param fsid - A stringified integer representing the file system ID where the file resides.
52
+ * @param path - The path to the file to be written to.
53
+ * @param position - The byte offset in the file where data should be written.
54
+ * @param wallet - The public key of the wallet that signs and authorizes the transaction.
55
+ * @param dataKey - A public key of a data account that holds the content to be written to the file.
56
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the poke instruction.
57
+ * @throws Will throw an error if the `path` contains invalid characters.
58
+ */
59
+ function poke(fsid, path, position, wallet, dataKey) {
60
+ return __awaiter(this, void 0, void 0, function () {
61
+ var pathBuffer, pathLengthBuffer, instructionData, instruction, tx;
62
+ return __generator(this, function (_a) {
63
+ (0, sanitizePath_1.sanitizePath)(path);
64
+ pathBuffer = Buffer.from(path, 'utf-8');
65
+ pathLengthBuffer = Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(pathBuffer.length).toArray('le', 8)));
66
+ instructionData = Buffer.concat([
67
+ Buffer.from(Int8Array.from([4]).buffer),
68
+ Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
69
+ Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(position).toArray('le', 8))),
70
+ pathLengthBuffer,
71
+ pathBuffer
72
+ ]);
73
+ instruction = new web3_js_1.TransactionInstruction({
74
+ keys: [
75
+ {
76
+ pubkey: wallet,
77
+ isSigner: true,
78
+ isWritable: true
79
+ },
80
+ {
81
+ pubkey: dataKey,
82
+ isSigner: false,
83
+ isWritable: false
84
+ }
85
+ ],
86
+ programId: new web3_js_1.PublicKey(const_1.programId),
87
+ data: instructionData
88
+ });
89
+ tx = new web3_js_1.Transaction().add(instruction);
90
+ return [2 /*return*/, tx];
91
+ });
92
+ });
93
+ }
@@ -0,0 +1,12 @@
1
+ import { Transaction, PublicKey } from '@solana/web3.js';
2
+ /**
3
+ * Constructs a Solana transaction to perform a "remove directory" operation
4
+ * in a file system, identified by a file system ID (`fsid`).
5
+ *
6
+ * @param fsid - A stringified integer representing the file system ID containing the directory.
7
+ * @param path - The full path to the directory that should be removed.
8
+ * @param wallet - The public key of the wallet that will sign and authorize the transaction.
9
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the remove directory instruction.
10
+ * @throws May throw an error if the `path` fails validation in `sanitizePath`.
11
+ */
12
+ export declare function removeDirectory(fsid: string, path: string, wallet: PublicKey): Promise<Transaction>;
@@ -0,0 +1,82 @@
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.removeDirectory = removeDirectory;
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
+ /**
48
+ * Constructs a Solana transaction to perform a "remove directory" operation
49
+ * in a file system, identified by a file system ID (`fsid`).
50
+ *
51
+ * @param fsid - A stringified integer representing the file system ID containing the directory.
52
+ * @param path - The full path to the directory that should be removed.
53
+ * @param wallet - The public key of the wallet that will sign and authorize the transaction.
54
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the remove directory instruction.
55
+ * @throws May throw an error if the `path` fails validation in `sanitizePath`.
56
+ */
57
+ function removeDirectory(fsid, path, wallet) {
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var instructionData, instruction, tx;
60
+ return __generator(this, function (_a) {
61
+ (0, sanitizePath_1.sanitizePath)(path);
62
+ instructionData = Buffer.concat([
63
+ Buffer.from(Int8Array.from([7]).buffer),
64
+ Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
65
+ Buffer.from("".concat(path), 'utf-8')
66
+ ]);
67
+ instruction = new web3_js_1.TransactionInstruction({
68
+ keys: [
69
+ {
70
+ pubkey: wallet,
71
+ isSigner: true,
72
+ isWritable: true
73
+ }
74
+ ],
75
+ programId: new web3_js_1.PublicKey(const_1.programId),
76
+ data: instructionData
77
+ });
78
+ tx = new web3_js_1.Transaction().add(instruction);
79
+ return [2 /*return*/, tx];
80
+ });
81
+ });
82
+ }
@@ -0,0 +1,12 @@
1
+ import { Transaction, PublicKey } from '@solana/web3.js';
2
+ /**
3
+ * Constructs a Solana transaction to remove a file from a file system,
4
+ * identified by a file system ID (`fsid`) and a UTF-8 encoded file path.
5
+ *
6
+ * @param fsid - A stringified integer representing the file system ID in which the file resides.
7
+ * @param path - The full path to the file to be deleted.
8
+ * @param wallet - The public key of the wallet that signs and authorizes the transaction.
9
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the remove file instruction.
10
+ * @throws May throw an error if `path` is invalid per `sanitizePath`.
11
+ */
12
+ export declare function removeFile(fsid: string, path: string, wallet: PublicKey): Promise<Transaction>;
@@ -0,0 +1,82 @@
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.removeFile = removeFile;
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
+ /**
48
+ * Constructs a Solana transaction to remove a file from a file system,
49
+ * identified by a file system ID (`fsid`) and a UTF-8 encoded file path.
50
+ *
51
+ * @param fsid - A stringified integer representing the file system ID in which the file resides.
52
+ * @param path - The full path to the file to be deleted.
53
+ * @param wallet - The public key of the wallet that signs and authorizes the transaction.
54
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the remove file instruction.
55
+ * @throws May throw an error if `path` is invalid per `sanitizePath`.
56
+ */
57
+ function removeFile(fsid, path, wallet) {
58
+ return __awaiter(this, void 0, void 0, function () {
59
+ var instructionData, instruction, tx;
60
+ return __generator(this, function (_a) {
61
+ (0, sanitizePath_1.sanitizePath)(path);
62
+ instructionData = Buffer.concat([
63
+ Buffer.from(Int8Array.from([5]).buffer),
64
+ Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
65
+ Buffer.from("".concat(path), 'utf-8')
66
+ ]);
67
+ instruction = new web3_js_1.TransactionInstruction({
68
+ keys: [
69
+ {
70
+ pubkey: wallet,
71
+ isSigner: true,
72
+ isWritable: true
73
+ }
74
+ ],
75
+ programId: new web3_js_1.PublicKey(const_1.programId),
76
+ data: instructionData
77
+ });
78
+ tx = new web3_js_1.Transaction().add(instruction);
79
+ return [2 /*return*/, tx];
80
+ });
81
+ });
82
+ }
@@ -0,0 +1,13 @@
1
+ import { Transaction, PublicKey } from '@solana/web3.js';
2
+ /**
3
+ * Constructs a Solana transaction to rename (or move) a file or directory
4
+ * within a file system, based on a provided file system ID (`fsid`).
5
+ *
6
+ * @param fsid - A stringified integer representing the file system ID where the path exists.
7
+ * @param oldPath - The current path of the file or directory to be renamed or moved.
8
+ * @param name - The new name to assign to the file or directory.
9
+ * @param wallet - The public key of the wallet that signs and authorizes the transaction.
10
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the rename path instruction.
11
+ * @throws May throw an error if either `oldPath` or `newPath` is invalid per `sanitizePath`.
12
+ */
13
+ export declare function renamePath(fsid: string, oldPath: string, name: string, wallet: PublicKey): Promise<Transaction>;
@@ -0,0 +1,85 @@
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.renamePath = renamePath;
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
+ /**
48
+ * Constructs a Solana transaction to rename (or move) a file or directory
49
+ * within a file system, based on a provided file system ID (`fsid`).
50
+ *
51
+ * @param fsid - A stringified integer representing the file system ID where the path exists.
52
+ * @param oldPath - The current path of the file or directory to be renamed or moved.
53
+ * @param name - The new name to assign to the file or directory.
54
+ * @param wallet - The public key of the wallet that signs and authorizes the transaction.
55
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the rename path instruction.
56
+ * @throws May throw an error if either `oldPath` or `newPath` is invalid per `sanitizePath`.
57
+ */
58
+ function renamePath(fsid, oldPath, name, wallet) {
59
+ return __awaiter(this, void 0, void 0, function () {
60
+ var rest, instructionData, instruction, tx;
61
+ return __generator(this, function (_a) {
62
+ (0, sanitizePath_1.sanitizePath)(oldPath);
63
+ (0, sanitizePath_1.sanitizePath)(name);
64
+ rest = Buffer.from("".concat(oldPath, "\0").concat(name), 'utf-8');
65
+ instructionData = Buffer.concat([
66
+ Buffer.from(Int8Array.from([8]).buffer),
67
+ Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).toArray('le', 8))),
68
+ rest
69
+ ]);
70
+ instruction = new web3_js_1.TransactionInstruction({
71
+ keys: [
72
+ {
73
+ pubkey: wallet,
74
+ isSigner: true,
75
+ isWritable: true
76
+ }
77
+ ],
78
+ programId: new web3_js_1.PublicKey(const_1.programId),
79
+ data: instructionData
80
+ });
81
+ tx = new web3_js_1.Transaction().add(instruction);
82
+ return [2 /*return*/, tx];
83
+ });
84
+ });
85
+ }
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Sanitizes file path for validate path.
3
+ * Ensures the path contains only allowed characters, prevents path traversal,
4
+ * and normalizes the path to start with a single slash.
5
+ *
6
+ * Allowed characters: alphanumeric, '/', '_', '-', '.'
7
+ * Disallowed: consecutive slashes (//), path traversal (..), control characters,
8
+ * invalid filesystem characters (<, >, :, ", \, |, ?, *),
9
+ * empty or whitespace-only paths.
10
+ *
11
+ * @param path - The file path to sanitize.
12
+ * @throws Error if the path is invalid.
13
+ */
14
+ export declare function sanitizePath(path: string): void;
@@ -0,0 +1,60 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.sanitizePath = sanitizePath;
4
+ /**
5
+ * Sanitizes file path for validate path.
6
+ * Ensures the path contains only allowed characters, prevents path traversal,
7
+ * and normalizes the path to start with a single slash.
8
+ *
9
+ * Allowed characters: alphanumeric, '/', '_', '-', '.'
10
+ * Disallowed: consecutive slashes (//), path traversal (..), control characters,
11
+ * invalid filesystem characters (<, >, :, ", \, |, ?, *),
12
+ * empty or whitespace-only paths.
13
+ *
14
+ * @param path - The file path to sanitize.
15
+ * @throws Error if the path is invalid.
16
+ */
17
+ function sanitizePath(path) {
18
+ // Check for empty or whitespace-only paths
19
+ if (!path || path.trim() === "") {
20
+ throw new Error("Path cannot be empty or whitespace-only");
21
+ }
22
+ // Check for consecutive slashes (// or more)
23
+ if (/\/\/+/.test(path)) {
24
+ throw new Error("Consecutive slashes (//) are not allowed");
25
+ }
26
+ // Check for path traversal sequences (..)
27
+ if (path.includes("..")) {
28
+ throw new Error("Path traversal sequences (..) are not allowed");
29
+ }
30
+ // Check for control characters (ASCII 0-31 and 127)
31
+ for (var i = 0; i < path.length; i++) {
32
+ var code = path.charCodeAt(i);
33
+ if (code <= 31 || code === 127) {
34
+ throw new Error("Control characters are not allowed in paths");
35
+ }
36
+ }
37
+ // Check for allowed characters: alphanumeric, /, _, -, .
38
+ if (!/^[a-zA-Z0-9\/_\-\.]*$/.test(path)) {
39
+ throw new Error("Path must contain only alphanumeric characters, single slashes, underscores (_), hyphens (-), or periods (.)");
40
+ }
41
+ // Check for invalid filesystem characters
42
+ var invalidChars = ["<", ">", ":", '"', "\\", "|", "?", "*"];
43
+ for (var i = 0; i < path.length; i++) {
44
+ if (invalidChars.includes(path[i])) {
45
+ throw new Error('Path contains invalid filesystem characters (<, >, :, ", \\, |, ?, *)');
46
+ }
47
+ }
48
+ // Check path component length (max 255 bytes)
49
+ var components = path.split("/").filter(function (c) { return c.length > 0; });
50
+ for (var _i = 0, components_1 = components; _i < components_1.length; _i++) {
51
+ var component = components_1[_i];
52
+ if (new TextEncoder().encode(component).length > 255) {
53
+ throw new Error("Path component exceeds 255 bytes");
54
+ }
55
+ }
56
+ // Check total path length (max 4096 bytes)
57
+ if (new TextEncoder().encode(path).length > 4096) {
58
+ throw new Error("Total path length exceeds 4096 bytes");
59
+ }
60
+ }
@@ -0,0 +1,47 @@
1
+ import { Connection } from "@solana/web3.js";
2
+ /**
3
+ * Represents the structure of result data received from a WebSocket subscription.
4
+ *
5
+ * - `fsid` (optional): The file system ID returned from the result.
6
+ * - `status` (optional): The status of the transaction or operation.
7
+ * - `data` (optional): Any custom payload or message associated with the result.
8
+ * - `subscription` (optional): The ID of the WebSocket subscription.
9
+ */
10
+ type ResultValue = {
11
+ fsid?: string;
12
+ status?: string;
13
+ data?: any;
14
+ subscription?: string;
15
+ };
16
+ /**
17
+ * Opens a WebSocket connection and subscribes to the result of a transaction
18
+ * via the custom `xandeumResultSubscribe` method.
19
+ *
20
+ * This is useful for receiving asynchronous results tied to an on-chain operation,
21
+ * such as file creation, modification, or deletion.
22
+ *
23
+ * The subscription sends a JSON-RPC request with:
24
+ * - `method`: "xandeumResultSubscribe"
25
+ * - `params`: [txId, { commitment: "finalized" }]
26
+ *
27
+ * The WebSocket listens for result messages and invokes the `onResult` callback
28
+ * if a valid result with `fsid`, `status`, or `data` is received.
29
+ *
30
+ * @param tx - The transaction ID you want to listen for results from.
31
+ * @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
32
+ * @param onResult - Callback to handle incoming result messages. Triggered when a valid response is received.
33
+ * @param onError - (Optional) Callback triggered if a WebSocket error occurs.
34
+ * @param onClose - (Optional) Callback triggered when the WebSocket connection closes.
35
+ */
36
+ export declare function subscribeResult(connection: Connection, tx: string, onResult: (value: ResultValue) => void, onError?: (err: any) => void, onClose?: () => void): void;
37
+ /**
38
+ * Sends a WebSocket JSON-RPC message to unsubscribe from a previously subscribed transaction result
39
+ * using the `xandeumResultUnsubscribed` method (note: custom method, ensure server-side implementation matches).
40
+ *
41
+ * This function automatically closes the WebSocket connection after sending the unsubscribe request.
42
+ *
43
+ * @param subscriptionId - The ID of the active subscription you want to cancel.
44
+ * @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
45
+ */
46
+ export declare function unsubscribeResult(connection: Connection, subscriptionId: string): void;
47
+ export {};