@xandeum/web3.js 1.6.0 → 1.9.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/README.md CHANGED
@@ -38,7 +38,8 @@ import {
38
38
  import {
39
39
  Connection,
40
40
  sendAndConfirmTransaction,
41
- Keypair
41
+ Keypair,
42
+ PublicKey
42
43
  } from '@solana/web3.js'
43
44
 
44
45
  const connection = new Connection('https://apis.devnet.xandeum.com)
@@ -54,6 +55,8 @@ async function main() {
54
55
  const tx2 = await createFile('1', '/','hello.txt', wallet)
55
56
  await sendAndConfirmTransaction(connection, tx2, [signer])
56
57
 
58
+ const dataAccount = new PublicKey("FBM4G63KPUneqyLwQy6zVu81AsMqmkQjsdxNGBKq3dkv");
59
+
57
60
  // Write data
58
61
  const tx3 = await poke('1', '/hello.txt', 0, Buffer.from('Hello Xandeum!'), wallet)
59
62
  await sendAndConfirmTransaction(connection, tx3, [signer])
package/dist/exists.js CHANGED
@@ -51,7 +51,7 @@ exports.exists = exists;
51
51
  */
52
52
  function exists(connection, path) {
53
53
  return __awaiter(this, void 0, void 0, function () {
54
- var url, requestBody, response, data;
54
+ var url, requestBody, response, errorText, data;
55
55
  return __generator(this, function (_a) {
56
56
  switch (_a.label) {
57
57
  case 0:
@@ -71,11 +71,13 @@ function exists(connection, path) {
71
71
  })];
72
72
  case 1:
73
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()];
74
+ if (!!response.ok) return [3 /*break*/, 3];
75
+ return [4 /*yield*/, response.text()];
78
76
  case 2:
77
+ errorText = _a.sent();
78
+ return [2 /*return*/, Error("error! status: ".concat(response.status, ", message: ").concat(errorText))];
79
+ case 3: return [4 /*yield*/, response.json()];
80
+ case 4:
79
81
  data = _a.sent();
80
82
  return [2 /*return*/, data];
81
83
  }
@@ -54,7 +54,7 @@ exports.getMetadata = getMetadata;
54
54
  */
55
55
  function getMetadata(connection, path) {
56
56
  return __awaiter(this, void 0, void 0, function () {
57
- var url, requestBody, response, data;
57
+ var url, requestBody, response, errorText, data;
58
58
  return __generator(this, function (_a) {
59
59
  switch (_a.label) {
60
60
  case 0:
@@ -74,11 +74,13 @@ function getMetadata(connection, path) {
74
74
  })];
75
75
  case 1:
76
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()];
77
+ if (!!response.ok) return [3 /*break*/, 3];
78
+ return [4 /*yield*/, response.text()];
81
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:
82
84
  data = _a.sent();
83
85
  return [2 /*return*/, data];
84
86
  }
@@ -52,7 +52,7 @@ exports.listDirectoryEntry = listDirectoryEntry;
52
52
  */
53
53
  function listDirectoryEntry(connection, path) {
54
54
  return __awaiter(this, void 0, void 0, function () {
55
- var url, requestBody, response, data;
55
+ var url, requestBody, response, errorText, data;
56
56
  return __generator(this, function (_a) {
57
57
  switch (_a.label) {
58
58
  case 0:
@@ -72,11 +72,13 @@ function listDirectoryEntry(connection, path) {
72
72
  })];
73
73
  case 1:
74
74
  response = _a.sent();
75
- if (!response.ok) {
76
- throw new Error("HTTP error! Status: ".concat(response.status));
77
- }
78
- return [4 /*yield*/, response.json()];
75
+ if (!!response.ok) return [3 /*break*/, 3];
76
+ return [4 /*yield*/, response.text()];
79
77
  case 2:
78
+ errorText = _a.sent();
79
+ return [2 /*return*/, Error("error! status: ".concat(response.status, ", message: ").concat(errorText))];
80
+ case 3: return [4 /*yield*/, response.json()];
81
+ case 4:
80
82
  data = _a.sent();
81
83
  return [2 /*return*/, data];
82
84
  }
package/dist/move.d.ts ADDED
@@ -0,0 +1,14 @@
1
+ import { Transaction, PublicKey } from '@solana/web3.js';
2
+ /**
3
+ * Constructs a Solana transaction to copy a file or directory from one path to another.
4
+ *
5
+ * @param fsid - The unique numeric identifier representing the target file system.
6
+ * @param srcPath - The source path to copy from (e.g., `/documents`).
7
+ * @param destPath - The destination path to copy to (e.g., `/archive`).
8
+ * @param name - The name of the new file or directory at the destination (e.g., `report.txt`).
9
+ * @param wallet - The wallet public key used to sign and authorize the transaction.
10
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the copyPath instruction.
11
+ * @throws Will throw an error if `srcPath` or `destPath` contains invalid characters.
12
+ *
13
+ */
14
+ export declare function move(fsid: string, srcPath: string, destPath: string, name: string, wallet: PublicKey): Promise<Transaction>;
package/dist/move.js ADDED
@@ -0,0 +1,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([9]).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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@xandeum/web3.js",
3
- "version": "1.6.0",
3
+ "version": "1.9.0",
4
4
  "description": "Xandeum javascript api",
5
5
  "main": "dist/index.js",
6
6
  "types": "dist/index.d.ts",
package/src/exists.ts CHANGED
@@ -38,7 +38,8 @@ export interface RpcRequest {
38
38
  })
39
39
 
40
40
  if (!response.ok) {
41
- throw new Error(`HTTP error! Status: ${response.status}`)
41
+ const errorText = await response.text();
42
+ return Error(`error! status: ${response.status}, message: ${errorText}`);
42
43
  }
43
44
 
44
45
  const data = await response.json()
@@ -41,7 +41,8 @@ export async function getMetadata (connection: Connection,path: string): Promise
41
41
  })
42
42
 
43
43
  if (!response.ok) {
44
- throw new Error(`HTTP error! Status: ${response.status}`)
44
+ const errorText = await response.text();
45
+ return Error(`error! status: ${response.status}, message: ${errorText}`);
45
46
  }
46
47
 
47
48
  const data = await response.json()
@@ -42,7 +42,8 @@ export async function listDirectoryEntry (
42
42
  })
43
43
 
44
44
  if (!response.ok) {
45
- throw new Error(`HTTP error! Status: ${response.status}`)
45
+ const errorText = await response.text();
46
+ return Error(`error! status: ${response.status}, message: ${errorText}`);
46
47
  }
47
48
 
48
49
  const data = await response.json()
package/src/move.ts ADDED
@@ -0,0 +1,55 @@
1
+ import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
+ import BN from 'bn.js'
3
+ import { programId } from './const'
4
+ import { sanitizePath } from './sanitizePath'
5
+
6
+ /**
7
+ * Constructs a Solana transaction to copy a file or directory from one path to another.
8
+ *
9
+ * @param fsid - The unique numeric identifier representing the target file system.
10
+ * @param srcPath - The source path to copy from (e.g., `/documents`).
11
+ * @param destPath - The destination path to copy to (e.g., `/archive`).
12
+ * @param name - The name of the new file or directory at the destination (e.g., `report.txt`).
13
+ * @param wallet - The wallet public key used to sign and authorize the transaction.
14
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the copyPath instruction.
15
+ * @throws Will throw an error if `srcPath` or `destPath` contains invalid characters.
16
+ *
17
+ */
18
+
19
+ export async function move (
20
+ fsid: string,
21
+ srcPath: string,
22
+ destPath: string,
23
+ name: string,
24
+ wallet: PublicKey
25
+ ): Promise<Transaction> {
26
+ // Validate path: only letters, numbers, and /
27
+ sanitizePath(srcPath)
28
+
29
+ sanitizePath(destPath)
30
+ sanitizePath(name)
31
+
32
+
33
+ const rest = Buffer.from(`${srcPath}\0${destPath}\0${name}`, 'utf-8')
34
+
35
+ const instructionData = Buffer.concat([
36
+ Buffer.from(Int8Array.from([9]).buffer),
37
+ Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
38
+ rest
39
+ ])
40
+
41
+ const instruction = new TransactionInstruction({
42
+ keys: [
43
+ {
44
+ pubkey: wallet,
45
+ isSigner: true,
46
+ isWritable: true
47
+ }
48
+ ],
49
+ programId: new PublicKey(programId),
50
+ data: instructionData
51
+ })
52
+
53
+ const tx = new Transaction().add(instruction)
54
+ return tx
55
+ }