@xandeum/web3.js 0.4.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/LICENSE +51 -0
- package/README.md +167 -0
- package/archbee.yaml +55 -0
- package/dist/armageddon.d.ts +10 -0
- package/dist/armageddon.js +77 -0
- package/dist/assignCoowner.d.ts +12 -0
- package/dist/assignCoowner.js +81 -0
- package/dist/bigbang.d.ts +9 -0
- package/dist/bigbang.js +76 -0
- package/dist/const.d.ts +1 -0
- package/dist/const.js +4 -0
- package/dist/copyPath.d.ts +13 -0
- package/dist/copyPath.js +86 -0
- package/dist/createDirectory.d.ts +12 -0
- package/dist/createDirectory.js +84 -0
- package/dist/createFile.d.ts +13 -0
- package/dist/createFile.js +85 -0
- package/dist/exists.d.ts +20 -0
- package/dist/exists.js +86 -0
- package/dist/find.d.ts +22 -0
- package/dist/find.js +88 -0
- package/dist/getInfo.d.ts +12 -0
- package/dist/getInfo.js +77 -0
- package/dist/getMetadata.d.ts +23 -0
- package/dist/getMetadata.js +89 -0
- package/dist/getXandeumResult.d.ts +15 -0
- package/dist/getXandeumResult.js +95 -0
- package/dist/index.d.ts +16 -0
- package/dist/index.js +37 -0
- package/dist/listDirectoryEntery.d.ts +21 -0
- package/dist/listDirectoryEntery.js +87 -0
- package/dist/move.d.ts +14 -0
- package/dist/move.js +88 -0
- package/dist/peek.d.ts +15 -0
- package/dist/peek.js +88 -0
- package/dist/poke.d.ts +14 -0
- package/dist/poke.js +93 -0
- package/dist/removeDirectory.d.ts +12 -0
- package/dist/removeDirectory.js +82 -0
- package/dist/removeFile.d.ts +12 -0
- package/dist/removeFile.js +82 -0
- package/dist/renamePath.d.ts +13 -0
- package/dist/renamePath.js +85 -0
- package/dist/sanitizePath.d.ts +14 -0
- package/dist/sanitizePath.js +60 -0
- package/dist/webSocket.d.ts +47 -0
- package/dist/webSocket.js +103 -0
- package/docs/html/.nojekyll +1 -0
- package/docs/html/assets/hierarchy.js +1 -0
- package/docs/html/assets/highlight.css +92 -0
- package/docs/html/assets/icons.js +18 -0
- package/docs/html/assets/icons.svg +1 -0
- package/docs/html/assets/main.js +60 -0
- package/docs/html/assets/navigation.js +1 -0
- package/docs/html/assets/search.js +1 -0
- package/docs/html/assets/style.css +1640 -0
- package/docs/html/functions/armageddon.html +6 -0
- package/docs/html/functions/bigbang.html +5 -0
- package/docs/html/functions/copyPath.html +8 -0
- package/docs/html/functions/createDirectory.html +8 -0
- package/docs/html/functions/createFile.html +9 -0
- package/docs/html/functions/exists.html +8 -0
- package/docs/html/functions/getMetadata.html +10 -0
- package/docs/html/functions/getXandeumResult.html +9 -0
- package/docs/html/functions/listDirectoryEntry.html +9 -0
- package/docs/html/functions/move.html +9 -0
- package/docs/html/functions/peek.html +10 -0
- package/docs/html/functions/poke.html +10 -0
- package/docs/html/functions/removeDirectory.html +8 -0
- package/docs/html/functions/removeFile.html +8 -0
- package/docs/html/functions/renamePath.html +9 -0
- package/docs/html/functions/subscribeResult.html +17 -0
- package/docs/html/functions/unsubscribeResult.html +6 -0
- package/docs/html/hierarchy.html +1 -0
- package/docs/html/index.html +62 -0
- package/docs/html/modules.html +1 -0
- package/docs/markdown/.nojekyll +0 -0
- package/docs/markdown/README.md +169 -0
- package/docs/markdown/functions/armageddon.md +34 -0
- package/docs/markdown/functions/bigbang.md +27 -0
- package/docs/markdown/functions/copyPath.md +49 -0
- package/docs/markdown/functions/createDirectory.md +49 -0
- package/docs/markdown/functions/createFile.md +50 -0
- package/docs/markdown/functions/exists.md +37 -0
- package/docs/markdown/functions/getMetadata.md +39 -0
- package/docs/markdown/functions/getXandeumResult.md +38 -0
- package/docs/markdown/functions/listDirectoryEntry.md +38 -0
- package/docs/markdown/functions/move.md +55 -0
- package/docs/markdown/functions/peek.md +57 -0
- package/docs/markdown/functions/poke.md +56 -0
- package/docs/markdown/functions/removeDirectory.md +44 -0
- package/docs/markdown/functions/removeFile.md +44 -0
- package/docs/markdown/functions/renamePath.md +50 -0
- package/docs/markdown/functions/subscribeResult.md +60 -0
- package/docs/markdown/functions/unsubscribeResult.md +34 -0
- package/docs/markdown/globals.md +25 -0
- package/docs/markdown/summary.md +44 -0
- package/package.json +26 -0
- package/src/armageddon.ts +36 -0
- package/src/bigbang.ts +32 -0
- package/src/const.ts +1 -0
- package/src/copyPath.ts +51 -0
- package/src/createDirectory.ts +47 -0
- package/src/createFile.ts +47 -0
- package/src/exists.ts +47 -0
- package/src/getMetadata.ts +50 -0
- package/src/getXandeumResult.ts +48 -0
- package/src/index.ts +16 -0
- package/src/listDirectoryEntery.ts +51 -0
- package/src/move.ts +55 -0
- package/src/peek.ts +52 -0
- package/src/poke.ts +59 -0
- package/src/removeDirectory.ts +43 -0
- package/src/removeFile.ts +44 -0
- package/src/renamePath.ts +50 -0
- package/src/sanitizePath.ts +69 -0
- package/src/webSocket.ts +131 -0
- package/tsconfig.json +14 -0
- package/typedoc.json +26 -0
|
@@ -0,0 +1,89 @@
|
|
|
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.getMetadata = getMetadata;
|
|
40
|
+
/**
|
|
41
|
+
* Sends a JSON-RPC request to the Xandeum RPC endpoint to retrieve metadata
|
|
42
|
+
* about a file or directory at the given path.
|
|
43
|
+
*
|
|
44
|
+
* This function calls the custom RPC method `getMetadata`, which is implemented
|
|
45
|
+
* by the backend to return metadata such as type (file or directory), size,
|
|
46
|
+
* timestamps etc.
|
|
47
|
+
*
|
|
48
|
+
* @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
|
|
49
|
+
* @param path - The filesystem path to query metadata for (e.g., `/documents/myfile.txt`).
|
|
50
|
+
*
|
|
51
|
+
* @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
|
|
52
|
+
* typically containing a `result` object with metadata fields.
|
|
53
|
+
*
|
|
54
|
+
*/
|
|
55
|
+
function getMetadata(connection, path) {
|
|
56
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
57
|
+
var url, requestBody, response, errorText, data;
|
|
58
|
+
return __generator(this, function (_a) {
|
|
59
|
+
switch (_a.label) {
|
|
60
|
+
case 0:
|
|
61
|
+
url = connection.rpcEndpoint;
|
|
62
|
+
requestBody = {
|
|
63
|
+
jsonrpc: '2.0',
|
|
64
|
+
id: 1,
|
|
65
|
+
method: 'getMetadata',
|
|
66
|
+
params: [path]
|
|
67
|
+
};
|
|
68
|
+
return [4 /*yield*/, fetch(url, {
|
|
69
|
+
method: 'POST',
|
|
70
|
+
headers: {
|
|
71
|
+
'Content-Type': 'application/json'
|
|
72
|
+
},
|
|
73
|
+
body: JSON.stringify(requestBody)
|
|
74
|
+
})];
|
|
75
|
+
case 1:
|
|
76
|
+
response = _a.sent();
|
|
77
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
78
|
+
return [4 /*yield*/, response.text()];
|
|
79
|
+
case 2:
|
|
80
|
+
errorText = _a.sent();
|
|
81
|
+
return [2 /*return*/, Error("error! status: ".concat(response.status, ", message: ").concat(errorText))];
|
|
82
|
+
case 3: return [4 /*yield*/, response.json()];
|
|
83
|
+
case 4:
|
|
84
|
+
data = _a.sent();
|
|
85
|
+
return [2 /*return*/, data];
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
});
|
|
89
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Connection } from "@solana/web3.js";
|
|
2
|
+
/**
|
|
3
|
+
* Sends a JSON-RPC request to the Xandeum-compatible endpoint to retrieve
|
|
4
|
+
* the result of a transaction previously submitted with a specific signature.
|
|
5
|
+
*
|
|
6
|
+
* This function calls the custom RPC method `getXandeumResult`, which returns
|
|
7
|
+
* the result associated with the given transaction signature.
|
|
8
|
+
*
|
|
9
|
+
* @param connection - The Solana web3 connection object pointing to a Xandeum-compatible RPC endpoint.
|
|
10
|
+
* @param signature - The transaction signature string whose result should be queried.
|
|
11
|
+
*
|
|
12
|
+
* @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
|
|
13
|
+
* which includes the result of the transaction if available.
|
|
14
|
+
*/
|
|
15
|
+
export declare function getXandeumResult(connection: Connection, signature: string): Promise<any>;
|
|
@@ -0,0 +1,95 @@
|
|
|
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, requestBody, response, errorText, data;
|
|
59
|
+
return __generator(this, function (_a) {
|
|
60
|
+
switch (_a.label) {
|
|
61
|
+
case 0:
|
|
62
|
+
url = connection.rpcEndpoint;
|
|
63
|
+
requestBody = {
|
|
64
|
+
jsonrpc: '2.0',
|
|
65
|
+
id: 1,
|
|
66
|
+
method: 'getXandeumResult',
|
|
67
|
+
params: [signature]
|
|
68
|
+
};
|
|
69
|
+
// sleeping To let the transaction process
|
|
70
|
+
return [4 /*yield*/, sleep(5000)];
|
|
71
|
+
case 1:
|
|
72
|
+
// sleeping To let the transaction process
|
|
73
|
+
_a.sent();
|
|
74
|
+
return [4 /*yield*/, fetch(url, {
|
|
75
|
+
method: 'POST',
|
|
76
|
+
headers: {
|
|
77
|
+
'Content-Type': 'application/json'
|
|
78
|
+
},
|
|
79
|
+
body: JSON.stringify(requestBody)
|
|
80
|
+
})];
|
|
81
|
+
case 2:
|
|
82
|
+
response = _a.sent();
|
|
83
|
+
if (!!response.ok) return [3 /*break*/, 4];
|
|
84
|
+
return [4 /*yield*/, response.text()];
|
|
85
|
+
case 3:
|
|
86
|
+
errorText = _a.sent();
|
|
87
|
+
return [2 /*return*/, new Error("Error! status: ".concat(response.status, ", message: ").concat(errorText))];
|
|
88
|
+
case 4: return [4 /*yield*/, response.json()];
|
|
89
|
+
case 5:
|
|
90
|
+
data = _a.sent();
|
|
91
|
+
return [2 /*return*/, data];
|
|
92
|
+
}
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
export { bigbang } from "./bigbang";
|
|
2
|
+
export * from './webSocket';
|
|
3
|
+
export * from "./armageddon";
|
|
4
|
+
export * from "./removeFile";
|
|
5
|
+
export * from "./renamePath";
|
|
6
|
+
export * from "./createFile";
|
|
7
|
+
export * from "./createDirectory";
|
|
8
|
+
export * from "./peek";
|
|
9
|
+
export * from "./poke";
|
|
10
|
+
export * from "./removeDirectory";
|
|
11
|
+
export * from "./copyPath";
|
|
12
|
+
export * from "./move";
|
|
13
|
+
export * from "./getXandeumResult";
|
|
14
|
+
export { exists } from "./exists";
|
|
15
|
+
export { listDirectoryEntry } from "./listDirectoryEntery";
|
|
16
|
+
export { getMetadata } from "./getMetadata";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.getMetadata = exports.listDirectoryEntry = exports.exists = exports.bigbang = void 0;
|
|
18
|
+
var bigbang_1 = require("./bigbang");
|
|
19
|
+
Object.defineProperty(exports, "bigbang", { enumerable: true, get: function () { return bigbang_1.bigbang; } });
|
|
20
|
+
__exportStar(require("./webSocket"), exports);
|
|
21
|
+
__exportStar(require("./armageddon"), exports);
|
|
22
|
+
__exportStar(require("./removeFile"), exports);
|
|
23
|
+
__exportStar(require("./renamePath"), exports);
|
|
24
|
+
__exportStar(require("./createFile"), exports);
|
|
25
|
+
__exportStar(require("./createDirectory"), exports);
|
|
26
|
+
__exportStar(require("./peek"), exports);
|
|
27
|
+
__exportStar(require("./poke"), exports);
|
|
28
|
+
__exportStar(require("./removeDirectory"), exports);
|
|
29
|
+
__exportStar(require("./copyPath"), exports);
|
|
30
|
+
__exportStar(require("./move"), exports);
|
|
31
|
+
__exportStar(require("./getXandeumResult"), exports);
|
|
32
|
+
var exists_1 = require("./exists");
|
|
33
|
+
Object.defineProperty(exports, "exists", { enumerable: true, get: function () { return exists_1.exists; } });
|
|
34
|
+
var listDirectoryEntery_1 = require("./listDirectoryEntery");
|
|
35
|
+
Object.defineProperty(exports, "listDirectoryEntry", { enumerable: true, get: function () { return listDirectoryEntery_1.listDirectoryEntry; } });
|
|
36
|
+
var getMetadata_1 = require("./getMetadata");
|
|
37
|
+
Object.defineProperty(exports, "getMetadata", { enumerable: true, get: function () { return getMetadata_1.getMetadata; } });
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { Connection } from "@solana/web3.js";
|
|
2
|
+
export interface RpcRequest {
|
|
3
|
+
jsonrpc: string;
|
|
4
|
+
id: number;
|
|
5
|
+
method: string;
|
|
6
|
+
params: any[];
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Sends a JSON-RPC request to the Xandeum RPC endpoint to list all entries (files and subdirectories)
|
|
10
|
+
* within a specified path.
|
|
11
|
+
*
|
|
12
|
+
* This function calls the custom RPC method `listDirs`, which is return an array of
|
|
13
|
+
* directory entry metadata — names, types etc.
|
|
14
|
+
*
|
|
15
|
+
* @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
|
|
16
|
+
* @param path - The filesystem path representing the directory to list (e.g., `/documents`).
|
|
17
|
+
*
|
|
18
|
+
* @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
|
|
19
|
+
* typically including a `result` array containing directory entry objects.
|
|
20
|
+
*/
|
|
21
|
+
export declare function listDirectoryEntry(connection: Connection, path: string): Promise<any>;
|
|
@@ -0,0 +1,87 @@
|
|
|
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.listDirectoryEntry = listDirectoryEntry;
|
|
40
|
+
/**
|
|
41
|
+
* Sends a JSON-RPC request to the Xandeum RPC endpoint to list all entries (files and subdirectories)
|
|
42
|
+
* within a specified path.
|
|
43
|
+
*
|
|
44
|
+
* This function calls the custom RPC method `listDirs`, which is return an array of
|
|
45
|
+
* directory entry metadata — names, types etc.
|
|
46
|
+
*
|
|
47
|
+
* @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
|
|
48
|
+
* @param path - The filesystem path representing the directory to list (e.g., `/documents`).
|
|
49
|
+
*
|
|
50
|
+
* @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
|
|
51
|
+
* typically including a `result` array containing directory entry objects.
|
|
52
|
+
*/
|
|
53
|
+
function listDirectoryEntry(connection, path) {
|
|
54
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
55
|
+
var url, requestBody, response, errorText, data;
|
|
56
|
+
return __generator(this, function (_a) {
|
|
57
|
+
switch (_a.label) {
|
|
58
|
+
case 0:
|
|
59
|
+
url = connection.rpcEndpoint;
|
|
60
|
+
requestBody = {
|
|
61
|
+
jsonrpc: '2.0',
|
|
62
|
+
id: 1,
|
|
63
|
+
method: 'listDirs',
|
|
64
|
+
params: [path]
|
|
65
|
+
};
|
|
66
|
+
return [4 /*yield*/, fetch(url, {
|
|
67
|
+
method: 'POST',
|
|
68
|
+
headers: {
|
|
69
|
+
'Content-Type': 'application/json'
|
|
70
|
+
},
|
|
71
|
+
body: JSON.stringify(requestBody)
|
|
72
|
+
})];
|
|
73
|
+
case 1:
|
|
74
|
+
response = _a.sent();
|
|
75
|
+
if (!!response.ok) return [3 /*break*/, 3];
|
|
76
|
+
return [4 /*yield*/, response.text()];
|
|
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:
|
|
82
|
+
data = _a.sent();
|
|
83
|
+
return [2 /*return*/, data];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
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,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.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
|
+
/**
|
|
48
|
+
* Constructs a Solana transaction to copy a file or directory from one path to another.
|
|
49
|
+
*
|
|
50
|
+
* @param fsid - The unique numeric identifier representing the target file system.
|
|
51
|
+
* @param srcPath - The source path to copy from (e.g., `/documents`).
|
|
52
|
+
* @param destPath - The destination path to copy to (e.g., `/archive`).
|
|
53
|
+
* @param name - The name of the new file or directory at the destination (e.g., `report.txt`).
|
|
54
|
+
* @param wallet - The wallet public key used to sign and authorize the transaction.
|
|
55
|
+
* @returns A Promise that resolves to a Solana `Transaction` object containing the copyPath instruction.
|
|
56
|
+
* @throws Will throw an error if `srcPath` or `destPath` contains invalid characters.
|
|
57
|
+
*
|
|
58
|
+
*/
|
|
59
|
+
function move(fsid, srcPath, destPath, name, wallet) {
|
|
60
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
61
|
+
var rest, instructionData, instruction, tx;
|
|
62
|
+
return __generator(this, function (_a) {
|
|
63
|
+
// Validate path: only letters, numbers, and /
|
|
64
|
+
(0, sanitizePath_1.sanitizePath)(srcPath);
|
|
65
|
+
(0, sanitizePath_1.sanitizePath)(destPath);
|
|
66
|
+
(0, sanitizePath_1.sanitizePath)(name);
|
|
67
|
+
rest = Buffer.from("".concat(srcPath, "\0").concat(destPath, "\0").concat(name), 'utf-8');
|
|
68
|
+
instructionData = Buffer.concat([
|
|
69
|
+
Buffer.from(Int8Array.from([13]).buffer),
|
|
70
|
+
Buffer.from(Uint8Array.of.apply(Uint8Array, new bn_js_1.default(fsid).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/peek.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Transaction, PublicKey } from '@solana/web3.js';
|
|
2
|
+
/**
|
|
3
|
+
* Constructs a Solana transaction to perform a "peek" operation on a file within a file system.
|
|
4
|
+
*
|
|
5
|
+
* The peek operation reads data between two byte offsets within a specified file path.
|
|
6
|
+
*
|
|
7
|
+
* @param fsid - A stringified integer representing the file system ID in which the file resides.
|
|
8
|
+
* @param path - The path to the file to be peeked.
|
|
9
|
+
* @param startPosition - The starting byte offset (inclusive) to begin reading from.
|
|
10
|
+
* @param endPosition - The ending byte offset (exclusive) to stop reading at.
|
|
11
|
+
* @param wallet - The public key of the wallet that will sign and authorize the transaction.
|
|
12
|
+
* @returns A Promise that resolves to a Solana `Transaction` object containing the peek instruction.
|
|
13
|
+
* @throws Will throw an error if the `path` contains invalid characters.
|
|
14
|
+
*/
|
|
15
|
+
export declare function peek(fsid: string, path: string, startPosition: number, endPosition: number, wallet: PublicKey): Promise<Transaction>;
|
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>;
|