@xandeum/web3.js 1.8.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/dist/move.d.ts +14 -0
- package/dist/move.js +88 -0
- package/package.json +1 -1
- package/src/move.ts +55 -0
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
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
|
+
}
|