@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.
- package/LICENSE +51 -0
- package/README.md +164 -0
- package/dist/armageddon.d.ts +10 -0
- package/dist/armageddon.js +77 -0
- package/dist/bigbang.d.ts +8 -0
- package/dist/bigbang.js +70 -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 +84 -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 +87 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.js +35 -0
- package/dist/listDirectoryEntery.d.ts +21 -0
- package/dist/listDirectoryEntery.js +85 -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 +90 -0
- package/docs/.nojekyll +1 -0
- package/docs/assets/hierarchy.js +1 -0
- package/docs/assets/highlight.css +22 -0
- package/docs/assets/icons.js +18 -0
- package/docs/assets/icons.svg +1 -0
- package/docs/assets/main.js +60 -0
- package/docs/assets/navigation.js +1 -0
- package/docs/assets/search.js +1 -0
- package/docs/assets/style.css +1640 -0
- package/docs/functions/armageddon.html +6 -0
- package/docs/functions/bigbang.html +4 -0
- package/docs/functions/copyPath.html +14 -0
- package/docs/functions/createDirectory.html +14 -0
- package/docs/functions/createFile.html +16 -0
- package/docs/functions/exists.html +8 -0
- package/docs/functions/getMetadata.html +10 -0
- package/docs/functions/listDirectoryEntry.html +9 -0
- package/docs/functions/peek.html +18 -0
- package/docs/functions/poke.html +18 -0
- package/docs/functions/removeDirectory.html +14 -0
- package/docs/functions/removeFile.html +14 -0
- package/docs/functions/renamePath.html +15 -0
- package/docs/functions/subscribeResult.html +17 -0
- package/docs/functions/unsubscribeResult.html +6 -0
- package/docs/hierarchy.html +1 -0
- package/docs/index.html +2 -0
- package/docs/markdown/.nojekyll +0 -0
- package/docs/markdown/README.md +5 -0
- package/docs/markdown/functions/armageddon.md +35 -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/listDirectoryEntry.md +38 -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 +23 -0
- package/docs/modules.html +1 -0
- package/package.json +26 -0
- package/src/armageddon.ts +36 -0
- package/src/bigbang.ts +29 -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 +46 -0
- package/src/getMetadata.ts +49 -0
- package/src/index.ts +15 -0
- package/src/listDirectoryEntery.ts +50 -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 +118 -0
- package/tsconfig.json +14 -0
- package/typedoc.json +27 -0
|
@@ -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.createFile = createFile;
|
|
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 create a new file
|
|
49
|
+
* within a file system, identified by a file system ID (`fsid`).
|
|
50
|
+
*
|
|
51
|
+
* @param fsid - A stringified integer representing the file system ID where the file is to be created.
|
|
52
|
+
* @param path - The absolute or relative path within the file system where the file should be created.
|
|
53
|
+
* @param name - The name of the new file or directory to be created.
|
|
54
|
+
* @param wallet - The public key of the wallet that will sign and authorize the transaction.
|
|
55
|
+
* @returns A Promise that resolves to a Solana `Transaction` object containing the createFile instruction.
|
|
56
|
+
* @throws Will throw an error if `path` or `name` contains invalid characters.
|
|
57
|
+
*/
|
|
58
|
+
function createFile(fsid, path, name, wallet) {
|
|
59
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
60
|
+
var combinedPath, rest, instructionData, instruction, tx;
|
|
61
|
+
return __generator(this, function (_a) {
|
|
62
|
+
combinedPath = path + '/' + name;
|
|
63
|
+
(0, sanitizePath_1.sanitizePath)(combinedPath);
|
|
64
|
+
rest = Buffer.from("".concat(path, "\0").concat(name), 'utf-8');
|
|
65
|
+
instructionData = Buffer.concat([
|
|
66
|
+
Buffer.from(Int8Array.from([2]).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
|
+
}
|
package/dist/exists.d.ts
ADDED
|
@@ -0,0 +1,20 @@
|
|
|
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 check if a file or directory exists.
|
|
10
|
+
*
|
|
11
|
+
* This function calls the custom RPC method `isExist`, which should be implemented
|
|
12
|
+
* by the backend to validate the existence of metadata (files/directories) at a given path.
|
|
13
|
+
* @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
|
|
14
|
+
* @param path - The filesystem path to check (e.g., `/documents/myfile.txt`).
|
|
15
|
+
*
|
|
16
|
+
* @returns A `Promise<any>` resolving to the RPC response JSON, typically including a `result` field
|
|
17
|
+
* indicating existence (e.g., `true` or `false`), or `null` if not found.
|
|
18
|
+
*
|
|
19
|
+
*/
|
|
20
|
+
export declare function exists(connection: Connection, path: string): Promise<any>;
|
package/dist/exists.js
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
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.exists = exists;
|
|
40
|
+
/**
|
|
41
|
+
* Sends a JSON-RPC request to the Xandeum RPC endpoint to check if a file or directory exists.
|
|
42
|
+
*
|
|
43
|
+
* This function calls the custom RPC method `isExist`, which should be implemented
|
|
44
|
+
* by the backend to validate the existence of metadata (files/directories) at a given path.
|
|
45
|
+
* @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
|
|
46
|
+
* @param path - The filesystem path to check (e.g., `/documents/myfile.txt`).
|
|
47
|
+
*
|
|
48
|
+
* @returns A `Promise<any>` resolving to the RPC response JSON, typically including a `result` field
|
|
49
|
+
* indicating existence (e.g., `true` or `false`), or `null` if not found.
|
|
50
|
+
*
|
|
51
|
+
*/
|
|
52
|
+
function exists(connection, path) {
|
|
53
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
54
|
+
var url, requestBody, response, data;
|
|
55
|
+
return __generator(this, function (_a) {
|
|
56
|
+
switch (_a.label) {
|
|
57
|
+
case 0:
|
|
58
|
+
url = connection.rpcEndpoint;
|
|
59
|
+
requestBody = {
|
|
60
|
+
jsonrpc: '2.0',
|
|
61
|
+
id: 1,
|
|
62
|
+
method: 'isExist',
|
|
63
|
+
params: [path]
|
|
64
|
+
};
|
|
65
|
+
return [4 /*yield*/, fetch(url, {
|
|
66
|
+
method: 'POST',
|
|
67
|
+
headers: {
|
|
68
|
+
'Content-Type': 'application/json'
|
|
69
|
+
},
|
|
70
|
+
body: JSON.stringify(requestBody)
|
|
71
|
+
})];
|
|
72
|
+
case 1:
|
|
73
|
+
response = _a.sent();
|
|
74
|
+
if (!response.ok) {
|
|
75
|
+
throw new Error("HTTP error! Status: ".concat(response.status));
|
|
76
|
+
}
|
|
77
|
+
return [4 /*yield*/, response.json()];
|
|
78
|
+
case 2:
|
|
79
|
+
data = _a.sent();
|
|
80
|
+
return [2 /*return*/, data];
|
|
81
|
+
}
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
export interface RpcRequest {
|
|
2
|
+
jsonrpc: string;
|
|
3
|
+
id: number;
|
|
4
|
+
method: string;
|
|
5
|
+
params: any[];
|
|
6
|
+
}
|
|
7
|
+
/**
|
|
8
|
+
* Calls Solana RPC method `getMetadata` for the file and direcories with the given path. (parent_path, depth,type)
|
|
9
|
+
* @param path The metadata path (e.g., account or key)
|
|
10
|
+
* @param url The Xandeum RPC URL
|
|
11
|
+
*/
|
|
12
|
+
export declare function getInfo(path: string, url: string): Promise<any>;
|
package/dist/getInfo.js
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// const url = 'https://api.devnet.solana.com';
|
|
3
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
4
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
5
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
6
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
7
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
8
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
9
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
10
|
+
});
|
|
11
|
+
};
|
|
12
|
+
var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
13
|
+
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);
|
|
14
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
15
|
+
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
16
|
+
function step(op) {
|
|
17
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
18
|
+
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
19
|
+
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;
|
|
20
|
+
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
21
|
+
switch (op[0]) {
|
|
22
|
+
case 0: case 1: t = op; break;
|
|
23
|
+
case 4: _.label++; return { value: op[1], done: false };
|
|
24
|
+
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
25
|
+
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
26
|
+
default:
|
|
27
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
28
|
+
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
29
|
+
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
30
|
+
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
31
|
+
if (t[2]) _.ops.pop();
|
|
32
|
+
_.trys.pop(); continue;
|
|
33
|
+
}
|
|
34
|
+
op = body.call(thisArg, _);
|
|
35
|
+
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
36
|
+
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
37
|
+
}
|
|
38
|
+
};
|
|
39
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
40
|
+
exports.getInfo = getInfo;
|
|
41
|
+
/**
|
|
42
|
+
* Calls Solana RPC method `getMetadata` for the file and direcories with the given path. (parent_path, depth,type)
|
|
43
|
+
* @param path The metadata path (e.g., account or key)
|
|
44
|
+
* @param url The Xandeum RPC URL
|
|
45
|
+
*/
|
|
46
|
+
function getInfo(path, url) {
|
|
47
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
48
|
+
var requestBody, response, data;
|
|
49
|
+
return __generator(this, function (_a) {
|
|
50
|
+
switch (_a.label) {
|
|
51
|
+
case 0:
|
|
52
|
+
requestBody = {
|
|
53
|
+
jsonrpc: '2.0',
|
|
54
|
+
id: 1,
|
|
55
|
+
method: 'getInfo',
|
|
56
|
+
params: [path],
|
|
57
|
+
};
|
|
58
|
+
return [4 /*yield*/, fetch(url, {
|
|
59
|
+
method: 'POST',
|
|
60
|
+
headers: {
|
|
61
|
+
'Content-Type': 'application/json',
|
|
62
|
+
},
|
|
63
|
+
body: JSON.stringify(requestBody),
|
|
64
|
+
})];
|
|
65
|
+
case 1:
|
|
66
|
+
response = _a.sent();
|
|
67
|
+
if (!response.ok) {
|
|
68
|
+
throw new Error("HTTP error! Status: ".concat(response.status));
|
|
69
|
+
}
|
|
70
|
+
return [4 /*yield*/, response.json()];
|
|
71
|
+
case 2:
|
|
72
|
+
data = _a.sent();
|
|
73
|
+
return [2 /*return*/, data];
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
});
|
|
77
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
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 retrieve metadata
|
|
10
|
+
* about a file or directory at the given path.
|
|
11
|
+
*
|
|
12
|
+
* This function calls the custom RPC method `getMetadata`, which is implemented
|
|
13
|
+
* by the backend to return metadata such as type (file or directory), size,
|
|
14
|
+
* timestamps etc.
|
|
15
|
+
*
|
|
16
|
+
* @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
|
|
17
|
+
* @param path - The filesystem path to query metadata for (e.g., `/documents/myfile.txt`).
|
|
18
|
+
*
|
|
19
|
+
* @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
|
|
20
|
+
* typically containing a `result` object with metadata fields.
|
|
21
|
+
*
|
|
22
|
+
*/
|
|
23
|
+
export declare function getMetadata(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.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, 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) {
|
|
78
|
+
throw new Error("HTTP error! Status: ".concat(response.status));
|
|
79
|
+
}
|
|
80
|
+
return [4 /*yield*/, response.json()];
|
|
81
|
+
case 2:
|
|
82
|
+
data = _a.sent();
|
|
83
|
+
return [2 /*return*/, data];
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
});
|
|
87
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
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 { exists } from "./exists";
|
|
13
|
+
export { listDirectoryEntry } from "./listDirectoryEntery";
|
|
14
|
+
export { getMetadata } from "./getMetadata";
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
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
|
+
var exists_1 = require("./exists");
|
|
31
|
+
Object.defineProperty(exports, "exists", { enumerable: true, get: function () { return exists_1.exists; } });
|
|
32
|
+
var listDirectoryEntery_1 = require("./listDirectoryEntery");
|
|
33
|
+
Object.defineProperty(exports, "listDirectoryEntry", { enumerable: true, get: function () { return listDirectoryEntery_1.listDirectoryEntry; } });
|
|
34
|
+
var getMetadata_1 = require("./getMetadata");
|
|
35
|
+
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,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
|
+
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, 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) {
|
|
76
|
+
throw new Error("HTTP error! Status: ".concat(response.status));
|
|
77
|
+
}
|
|
78
|
+
return [4 /*yield*/, response.json()];
|
|
79
|
+
case 2:
|
|
80
|
+
data = _a.sent();
|
|
81
|
+
return [2 /*return*/, data];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
}
|
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>;
|