@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.
Files changed (119) hide show
  1. package/LICENSE +51 -0
  2. package/README.md +167 -0
  3. package/archbee.yaml +55 -0
  4. package/dist/armageddon.d.ts +10 -0
  5. package/dist/armageddon.js +77 -0
  6. package/dist/assignCoowner.d.ts +12 -0
  7. package/dist/assignCoowner.js +81 -0
  8. package/dist/bigbang.d.ts +9 -0
  9. package/dist/bigbang.js +76 -0
  10. package/dist/const.d.ts +1 -0
  11. package/dist/const.js +4 -0
  12. package/dist/copyPath.d.ts +13 -0
  13. package/dist/copyPath.js +86 -0
  14. package/dist/createDirectory.d.ts +12 -0
  15. package/dist/createDirectory.js +84 -0
  16. package/dist/createFile.d.ts +13 -0
  17. package/dist/createFile.js +85 -0
  18. package/dist/exists.d.ts +20 -0
  19. package/dist/exists.js +86 -0
  20. package/dist/find.d.ts +22 -0
  21. package/dist/find.js +88 -0
  22. package/dist/getInfo.d.ts +12 -0
  23. package/dist/getInfo.js +77 -0
  24. package/dist/getMetadata.d.ts +23 -0
  25. package/dist/getMetadata.js +89 -0
  26. package/dist/getXandeumResult.d.ts +15 -0
  27. package/dist/getXandeumResult.js +95 -0
  28. package/dist/index.d.ts +16 -0
  29. package/dist/index.js +37 -0
  30. package/dist/listDirectoryEntery.d.ts +21 -0
  31. package/dist/listDirectoryEntery.js +87 -0
  32. package/dist/move.d.ts +14 -0
  33. package/dist/move.js +88 -0
  34. package/dist/peek.d.ts +15 -0
  35. package/dist/peek.js +88 -0
  36. package/dist/poke.d.ts +14 -0
  37. package/dist/poke.js +93 -0
  38. package/dist/removeDirectory.d.ts +12 -0
  39. package/dist/removeDirectory.js +82 -0
  40. package/dist/removeFile.d.ts +12 -0
  41. package/dist/removeFile.js +82 -0
  42. package/dist/renamePath.d.ts +13 -0
  43. package/dist/renamePath.js +85 -0
  44. package/dist/sanitizePath.d.ts +14 -0
  45. package/dist/sanitizePath.js +60 -0
  46. package/dist/webSocket.d.ts +47 -0
  47. package/dist/webSocket.js +103 -0
  48. package/docs/html/.nojekyll +1 -0
  49. package/docs/html/assets/hierarchy.js +1 -0
  50. package/docs/html/assets/highlight.css +92 -0
  51. package/docs/html/assets/icons.js +18 -0
  52. package/docs/html/assets/icons.svg +1 -0
  53. package/docs/html/assets/main.js +60 -0
  54. package/docs/html/assets/navigation.js +1 -0
  55. package/docs/html/assets/search.js +1 -0
  56. package/docs/html/assets/style.css +1640 -0
  57. package/docs/html/functions/armageddon.html +6 -0
  58. package/docs/html/functions/bigbang.html +5 -0
  59. package/docs/html/functions/copyPath.html +8 -0
  60. package/docs/html/functions/createDirectory.html +8 -0
  61. package/docs/html/functions/createFile.html +9 -0
  62. package/docs/html/functions/exists.html +8 -0
  63. package/docs/html/functions/getMetadata.html +10 -0
  64. package/docs/html/functions/getXandeumResult.html +9 -0
  65. package/docs/html/functions/listDirectoryEntry.html +9 -0
  66. package/docs/html/functions/move.html +9 -0
  67. package/docs/html/functions/peek.html +10 -0
  68. package/docs/html/functions/poke.html +10 -0
  69. package/docs/html/functions/removeDirectory.html +8 -0
  70. package/docs/html/functions/removeFile.html +8 -0
  71. package/docs/html/functions/renamePath.html +9 -0
  72. package/docs/html/functions/subscribeResult.html +17 -0
  73. package/docs/html/functions/unsubscribeResult.html +6 -0
  74. package/docs/html/hierarchy.html +1 -0
  75. package/docs/html/index.html +62 -0
  76. package/docs/html/modules.html +1 -0
  77. package/docs/markdown/.nojekyll +0 -0
  78. package/docs/markdown/README.md +169 -0
  79. package/docs/markdown/functions/armageddon.md +34 -0
  80. package/docs/markdown/functions/bigbang.md +27 -0
  81. package/docs/markdown/functions/copyPath.md +49 -0
  82. package/docs/markdown/functions/createDirectory.md +49 -0
  83. package/docs/markdown/functions/createFile.md +50 -0
  84. package/docs/markdown/functions/exists.md +37 -0
  85. package/docs/markdown/functions/getMetadata.md +39 -0
  86. package/docs/markdown/functions/getXandeumResult.md +38 -0
  87. package/docs/markdown/functions/listDirectoryEntry.md +38 -0
  88. package/docs/markdown/functions/move.md +55 -0
  89. package/docs/markdown/functions/peek.md +57 -0
  90. package/docs/markdown/functions/poke.md +56 -0
  91. package/docs/markdown/functions/removeDirectory.md +44 -0
  92. package/docs/markdown/functions/removeFile.md +44 -0
  93. package/docs/markdown/functions/renamePath.md +50 -0
  94. package/docs/markdown/functions/subscribeResult.md +60 -0
  95. package/docs/markdown/functions/unsubscribeResult.md +34 -0
  96. package/docs/markdown/globals.md +25 -0
  97. package/docs/markdown/summary.md +44 -0
  98. package/package.json +26 -0
  99. package/src/armageddon.ts +36 -0
  100. package/src/bigbang.ts +32 -0
  101. package/src/const.ts +1 -0
  102. package/src/copyPath.ts +51 -0
  103. package/src/createDirectory.ts +47 -0
  104. package/src/createFile.ts +47 -0
  105. package/src/exists.ts +47 -0
  106. package/src/getMetadata.ts +50 -0
  107. package/src/getXandeumResult.ts +48 -0
  108. package/src/index.ts +16 -0
  109. package/src/listDirectoryEntery.ts +51 -0
  110. package/src/move.ts +55 -0
  111. package/src/peek.ts +52 -0
  112. package/src/poke.ts +59 -0
  113. package/src/removeDirectory.ts +43 -0
  114. package/src/removeFile.ts +44 -0
  115. package/src/renamePath.ts +50 -0
  116. package/src/sanitizePath.ts +69 -0
  117. package/src/webSocket.ts +131 -0
  118. package/tsconfig.json +14 -0
  119. package/typedoc.json +26 -0
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@xandeum/web3.js",
3
+ "version": "0.4.0",
4
+ "description": "Xandeum javascript api",
5
+ "main": "dist/index.js",
6
+ "types": "dist/index.d.ts",
7
+ "scripts": {
8
+ "build": "tsc",
9
+ "deploy-docs": "typedoc && gh-pages -d docs/html"
10
+ },
11
+ "author": "",
12
+ "license": "Apache-2.0",
13
+ "publishConfig": {
14
+ "access": "public"
15
+ },
16
+ "dependencies": {
17
+ "@solana/web3.js": "^1.98.2",
18
+ "ws": "^8.18.2"
19
+ },
20
+ "devDependencies": {
21
+ "@types/bn.js": "^5.1.6",
22
+ "gh-pages": "^6.3.0",
23
+ "typedoc": "^0.28.4",
24
+ "typedoc-plugin-markdown": "^4.6.3"
25
+ }
26
+ }
@@ -0,0 +1,36 @@
1
+ import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
+ import BN from 'bn.js'
3
+ import { programId } from './const.js'
4
+
5
+ /**
6
+ * Constructs a Solana transaction that triggers the "armageddon" instruction
7
+ * on the specified file system (fsid).
8
+ *
9
+ * @param fsid - A stringified integer representing the file system ID to be used in the instruction.
10
+ * @param wallet - The public key of the wallet that will sign and authorize the transaction.
11
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the armageddon instruction.
12
+ */
13
+ export async function armageddon (
14
+ fsid: string,
15
+ wallet: PublicKey
16
+ ): Promise<Transaction> {
17
+ const instructionData = Buffer.concat([
18
+ Buffer.from(Int8Array.from([1]).buffer),
19
+ Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8)))
20
+ ])
21
+
22
+ const instruction = new TransactionInstruction({
23
+ keys: [
24
+ {
25
+ pubkey: wallet,
26
+ isSigner: true,
27
+ isWritable: true
28
+ }
29
+ ],
30
+ programId: new PublicKey(programId),
31
+ data: instructionData
32
+ })
33
+
34
+ const tx = new Transaction().add(instruction)
35
+ return tx
36
+ }
package/src/bigbang.ts ADDED
@@ -0,0 +1,32 @@
1
+ import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
2
+ import BN from 'bn.js'
3
+ import { programId } from './const'
4
+
5
+ /**
6
+ * Constructs a Solana transaction that triggers the "bigbang" instruction and create new file system.
7
+ *
8
+ * @param wallet - The public key of the wallet that will sign and authorize the transaction.
9
+ * @param replica_count - A stringified integer representing the number of replicas for the new file system.
10
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the bigbang instruction.
11
+ */
12
+ export async function bigbang (replica_count:string,wallet: PublicKey): Promise<Transaction> {
13
+ const instructionData = Buffer.concat([
14
+ Buffer.from(Int8Array.from([0]).buffer),
15
+ Buffer.from(Uint8Array.of(...new BN(replica_count).toArray('le', 8)))
16
+ ])
17
+
18
+ const instruction = new TransactionInstruction({
19
+ keys: [
20
+ {
21
+ pubkey: wallet,
22
+ isSigner: true,
23
+ isWritable: true
24
+ }
25
+ ],
26
+ programId: new PublicKey(programId),
27
+ data: instructionData
28
+ })
29
+
30
+ const tx = new Transaction().add(instruction)
31
+ return tx
32
+ }
package/src/const.ts ADDED
@@ -0,0 +1 @@
1
+ export const programId="xSHLJPXU8QW3A9kGiRoL94bksJ7ZZPY4dUwJPAT8CVK";
@@ -0,0 +1,51 @@
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/report.txt`).
11
+ * @param destPath - The destination path to copy to (e.g., `/archive/report.txt`).
12
+ * @param wallet - The wallet public key used to sign and authorize the transaction.
13
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the copyPath instruction.
14
+ * @throws Will throw an error if `srcPath` or `destPath` contains invalid characters.
15
+ *
16
+ */
17
+
18
+ export async function copyPath (
19
+ fsid: string,
20
+ srcPath: string,
21
+ destPath: string,
22
+ wallet: PublicKey
23
+ ): Promise<Transaction> {
24
+ // Validate path: only letters, numbers, and /
25
+ sanitizePath(srcPath)
26
+
27
+ sanitizePath(destPath)
28
+
29
+ const rest = Buffer.from(`${srcPath}\0${destPath}`, 'utf-8')
30
+
31
+ const instructionData = Buffer.concat([
32
+ Buffer.from(Int8Array.from([9]).buffer),
33
+ Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
34
+ rest
35
+ ])
36
+
37
+ const instruction = new TransactionInstruction({
38
+ keys: [
39
+ {
40
+ pubkey: wallet,
41
+ isSigner: true,
42
+ isWritable: true
43
+ }
44
+ ],
45
+ programId: new PublicKey(programId),
46
+ data: instructionData
47
+ })
48
+
49
+ const tx = new Transaction().add(instruction)
50
+ return tx
51
+ }
@@ -0,0 +1,47 @@
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 create a new directory within a file system.
8
+ *
9
+ * @param fsid - A numeric filesystem identifier used to scope the directory creation.
10
+ * @param path - The parent path where the directory should be created (e.g., `/documents`).
11
+ * @param name - The name of the new directory (e.g., `reports`).
12
+ * @param wallet - The signer’s public key that authorizes the transaction.
13
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the createDirectory instruction.
14
+ * @throws Will throw an error if `path` or `name` contains invalid characters.@throws Will throw if the combined path is invalid (non-alphanumeric or unsupported characters).
15
+ */
16
+
17
+ export async function createDirectory (
18
+ fsid: string,
19
+ path: string,
20
+ name: string,
21
+ wallet: PublicKey
22
+ ): Promise<Transaction> {
23
+ // Validate path: only letters, numbers, and /
24
+ const combinedPath = path.endsWith('/') ? `${path}${name}` : `${path}/${name}`
25
+ sanitizePath(combinedPath)
26
+ const rest = Buffer.from(`${path}\0${name}`, 'utf-8')
27
+ const instructionData = Buffer.concat([
28
+ Buffer.from(Int8Array.from([6]).buffer),
29
+ Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
30
+ rest
31
+ ])
32
+
33
+ const instruction = new TransactionInstruction({
34
+ keys: [
35
+ {
36
+ pubkey: wallet,
37
+ isSigner: true,
38
+ isWritable: true
39
+ }
40
+ ],
41
+ programId: new PublicKey(programId),
42
+ data: instructionData
43
+ })
44
+
45
+ const tx = new Transaction().add(instruction)
46
+ return tx
47
+ }
@@ -0,0 +1,47 @@
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 create a new file
8
+ * within a file system, identified by a file system ID (`fsid`).
9
+ *
10
+ * @param fsid - A stringified integer representing the file system ID where the file is to be created.
11
+ * @param path - The absolute or relative path within the file system where the file should be created.
12
+ * @param name - The name of the new file or directory to be created.
13
+ * @param wallet - The public key of the wallet that will sign and authorize the transaction.
14
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the createFile instruction.
15
+ * @throws Will throw an error if `path` or `name` contains invalid characters.
16
+ */
17
+ export async function createFile (
18
+ fsid: string,
19
+ path: string,
20
+ name: string,
21
+ wallet: PublicKey
22
+ ): Promise<Transaction> {
23
+ const combinedPath = path.endsWith('/') ? `${path}${name}` : `${path}/${name}`
24
+ sanitizePath(combinedPath);
25
+
26
+ const rest = Buffer.from(`${path}\0${name}`, 'utf-8')
27
+ const instructionData = Buffer.concat([
28
+ Buffer.from(Int8Array.from([2]).buffer),
29
+ Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
30
+ rest
31
+ ])
32
+
33
+ const instruction = new TransactionInstruction({
34
+ keys: [
35
+ {
36
+ pubkey: wallet,
37
+ isSigner: true,
38
+ isWritable: true
39
+ }
40
+ ],
41
+ programId: new PublicKey(programId),
42
+ data: instructionData
43
+ })
44
+
45
+ const tx = new Transaction().add(instruction)
46
+ return tx
47
+ }
package/src/exists.ts ADDED
@@ -0,0 +1,47 @@
1
+ import { Connection } from "@solana/web3.js"
2
+
3
+ export interface RpcRequest {
4
+ jsonrpc: string
5
+ id: number
6
+ method: string
7
+ params: any[]
8
+ }
9
+
10
+ /**
11
+ * Sends a JSON-RPC request to the Xandeum RPC endpoint to check if a file or directory exists.
12
+ *
13
+ * This function calls the custom RPC method `isExist`, which should be implemented
14
+ * by the backend to validate the existence of metadata (files/directories) at a given path.
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 to check (e.g., `/documents/myfile.txt`).
17
+ *
18
+ * @returns A `Promise<any>` resolving to the RPC response JSON, typically including a `result` field
19
+ * indicating existence (e.g., `true` or `false`), or `null` if not found.
20
+ *
21
+ */
22
+
23
+ export async function exists (connection: Connection,path: string): Promise<any> {
24
+ const url = connection.rpcEndpoint;
25
+ const requestBody: RpcRequest = {
26
+ jsonrpc: '2.0',
27
+ id: 1,
28
+ method: 'isExist',
29
+ params: [path]
30
+ }
31
+
32
+ const response = await fetch(url, {
33
+ method: 'POST',
34
+ headers: {
35
+ 'Content-Type': 'application/json'
36
+ },
37
+ body: JSON.stringify(requestBody)
38
+ })
39
+
40
+ if (!response.ok) {
41
+ const errorText = await response.text();
42
+ return Error(`error! status: ${response.status}, message: ${errorText}`);
43
+ }
44
+
45
+ const data = await response.json()
46
+ return data
47
+ }
@@ -0,0 +1,50 @@
1
+ import { Connection } from "@solana/web3.js"
2
+
3
+ export interface RpcRequest {
4
+ jsonrpc: string
5
+ id: number
6
+ method: string
7
+ params: any[]
8
+ }
9
+
10
+ /**
11
+ * Sends a JSON-RPC request to the Xandeum RPC endpoint to retrieve metadata
12
+ * about a file or directory at the given path.
13
+ *
14
+ * This function calls the custom RPC method `getMetadata`, which is implemented
15
+ * by the backend to return metadata such as type (file or directory), size,
16
+ * timestamps etc.
17
+ *
18
+ * @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
19
+ * @param path - The filesystem path to query metadata for (e.g., `/documents/myfile.txt`).
20
+ *
21
+ * @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
22
+ * typically containing a `result` object with metadata fields.
23
+ *
24
+ */
25
+
26
+ export async function getMetadata (connection: Connection,path: string): Promise<any> {
27
+ const url = connection.rpcEndpoint;
28
+ const requestBody: RpcRequest = {
29
+ jsonrpc: '2.0',
30
+ id: 1,
31
+ method: 'getMetadata',
32
+ params: [path]
33
+ }
34
+
35
+ const response = await fetch(url, {
36
+ method: 'POST',
37
+ headers: {
38
+ 'Content-Type': 'application/json'
39
+ },
40
+ body: JSON.stringify(requestBody)
41
+ })
42
+
43
+ if (!response.ok) {
44
+ const errorText = await response.text();
45
+ return Error(`error! status: ${response.status}, message: ${errorText}`);
46
+ }
47
+
48
+ const data = await response.json()
49
+ return data
50
+ }
@@ -0,0 +1,48 @@
1
+
2
+ import { Connection } from "@solana/web3.js"
3
+
4
+ function sleep(ms: number) {
5
+ return new Promise(resolve => setTimeout(resolve, ms));
6
+ }
7
+
8
+ /**
9
+ * Sends a JSON-RPC request to the Xandeum-compatible endpoint to retrieve
10
+ * the result of a transaction previously submitted with a specific signature.
11
+ *
12
+ * This function calls the custom RPC method `getXandeumResult`, which returns
13
+ * the result associated with the given transaction signature.
14
+ *
15
+ * @param connection - The Solana web3 connection object pointing to a Xandeum-compatible RPC endpoint.
16
+ * @param signature - The transaction signature string whose result should be queried.
17
+ *
18
+ * @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
19
+ * which includes the result of the transaction if available.
20
+ */
21
+ export async function getXandeumResult( connection: Connection, signature: string): Promise<any> {
22
+ const url = connection.rpcEndpoint;
23
+ const requestBody = {
24
+ jsonrpc: '2.0',
25
+ id: 1,
26
+ method: 'getXandeumResult',
27
+ params: [signature]
28
+ }
29
+
30
+ // sleeping To let the transaction process
31
+ await sleep(5000);
32
+
33
+ const response = await fetch(url, {
34
+ method: 'POST',
35
+ headers: {
36
+ 'Content-Type': 'application/json'
37
+ },
38
+ body: JSON.stringify(requestBody)
39
+ })
40
+
41
+ if (!response.ok) {
42
+ const errorText = await response.text();
43
+ return new Error(`Error! status: ${response.status}, message: ${errorText}`);
44
+ }
45
+
46
+ const data = await response.json()
47
+ return data
48
+ }
package/src/index.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";
@@ -0,0 +1,51 @@
1
+ import { Connection } from "@solana/web3.js"
2
+
3
+ export interface RpcRequest {
4
+ jsonrpc: string
5
+ id: number
6
+ method: string
7
+ params: any[]
8
+ }
9
+
10
+ /**
11
+ * Sends a JSON-RPC request to the Xandeum RPC endpoint to list all entries (files and subdirectories)
12
+ * within a specified path.
13
+ *
14
+ * This function calls the custom RPC method `listDirs`, which is return an array of
15
+ * directory entry metadata — names, types etc.
16
+ *
17
+ * @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
18
+ * @param path - The filesystem path representing the directory to list (e.g., `/documents`).
19
+ *
20
+ * @returns A `Promise<any>` resolving to the parsed JSON response from the RPC server,
21
+ * typically including a `result` array containing directory entry objects.
22
+ */
23
+
24
+ export async function listDirectoryEntry (
25
+ connection: Connection,
26
+ path: string,
27
+ ): Promise<any> {
28
+ const url = connection.rpcEndpoint;
29
+ const requestBody: RpcRequest = {
30
+ jsonrpc: '2.0',
31
+ id: 1,
32
+ method: 'listDirs',
33
+ params: [path]
34
+ }
35
+
36
+ const response = await fetch(url, {
37
+ method: 'POST',
38
+ headers: {
39
+ 'Content-Type': 'application/json'
40
+ },
41
+ body: JSON.stringify(requestBody)
42
+ })
43
+
44
+ if (!response.ok) {
45
+ const errorText = await response.text();
46
+ return Error(`error! status: ${response.status}, message: ${errorText}`);
47
+ }
48
+
49
+ const data = await response.json()
50
+ return data
51
+ }
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([13]).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
+ }
package/src/peek.ts ADDED
@@ -0,0 +1,52 @@
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 perform a "peek" operation on a file within a file system.
8
+ *
9
+ * The peek operation reads data between two byte offsets within a specified file path.
10
+ *
11
+ * @param fsid - A stringified integer representing the file system ID in which the file resides.
12
+ * @param path - The path to the file to be peeked.
13
+ * @param startPosition - The starting byte offset (inclusive) to begin reading from.
14
+ * @param endPosition - The ending byte offset (exclusive) to stop reading at.
15
+ * @param wallet - The public key of the wallet that will sign and authorize the transaction.
16
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the peek instruction.
17
+ * @throws Will throw an error if the `path` contains invalid characters.
18
+ */
19
+
20
+ export async function peek (
21
+ fsid: string,
22
+ path: string,
23
+ startPosition: number,
24
+ endPosition: number,
25
+ wallet: PublicKey
26
+ ): Promise<Transaction> {
27
+ sanitizePath(path)
28
+
29
+ const rest = Buffer.from(`${path}`, 'utf-8')
30
+ const instructionData = Buffer.concat([
31
+ Buffer.from(Int8Array.from([3]).buffer),
32
+ Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
33
+ Buffer.from(Uint8Array.of(...new BN(startPosition).toArray('le', 8))),
34
+ Buffer.from(Uint8Array.of(...new BN(endPosition).toArray('le', 8))),
35
+ rest
36
+ ])
37
+
38
+ const instruction = new TransactionInstruction({
39
+ keys: [
40
+ {
41
+ pubkey: wallet,
42
+ isSigner: true,
43
+ isWritable: true
44
+ }
45
+ ],
46
+ programId: new PublicKey(programId),
47
+ data: instructionData
48
+ })
49
+
50
+ const tx = new Transaction().add(instruction)
51
+ return tx
52
+ }
package/src/poke.ts ADDED
@@ -0,0 +1,59 @@
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 perform a poke\operation, which writes data
8
+ * to a file at the specified path and byte position.
9
+ *
10
+ * @param fsid - A stringified integer representing the file system ID where the file resides.
11
+ * @param path - The path to the file to be written to.
12
+ * @param position - The byte offset in the file where data should be written.
13
+ * @param wallet - The public key of the wallet that signs and authorizes the transaction.
14
+ * @param dataKey - A public key of a data account that holds the content to be written to the file.
15
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the poke instruction.
16
+ * @throws Will throw an error if the `path` contains invalid characters.
17
+ */
18
+
19
+ export async function poke (
20
+ fsid: string,
21
+ path: string,
22
+ position: number,
23
+ wallet: PublicKey,
24
+ dataKey: PublicKey
25
+ ): Promise<Transaction> {
26
+ sanitizePath(path)
27
+
28
+ // Encode the path as UTF-8
29
+ const pathBuffer = Buffer.from(path, 'utf-8')
30
+ // Encode the path length as an 8-byte little-endian unsigned integer
31
+ const pathLengthBuffer = Buffer.from(Uint8Array.of(...new BN(pathBuffer.length).toArray('le', 8)))
32
+ const instructionData = Buffer.concat([
33
+ Buffer.from(Int8Array.from([4]).buffer),
34
+ Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
35
+ Buffer.from(Uint8Array.of(...new BN(position).toArray('le', 8))),
36
+ pathLengthBuffer,
37
+ pathBuffer
38
+ ])
39
+
40
+ const instruction = new TransactionInstruction({
41
+ keys: [
42
+ {
43
+ pubkey: wallet,
44
+ isSigner: true,
45
+ isWritable: true
46
+ },
47
+ {
48
+ pubkey: dataKey,
49
+ isSigner: false,
50
+ isWritable: false
51
+ }
52
+ ],
53
+ programId: new PublicKey(programId),
54
+ data: instructionData
55
+ })
56
+
57
+ const tx = new Transaction().add(instruction)
58
+ return tx
59
+ }
@@ -0,0 +1,43 @@
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 perform a "remove directory" operation
8
+ * in a file system, identified by a file system ID (`fsid`).
9
+ *
10
+ * @param fsid - A stringified integer representing the file system ID containing the directory.
11
+ * @param path - The full path to the directory that should be removed.
12
+ * @param wallet - The public key of the wallet that will sign and authorize the transaction.
13
+ * @returns A Promise that resolves to a Solana `Transaction` object containing the remove directory instruction.
14
+ * @throws May throw an error if the `path` fails validation in `sanitizePath`.
15
+ */
16
+
17
+ export async function removeDirectory (
18
+ fsid: string,
19
+ path: string,
20
+ wallet: PublicKey
21
+ ): Promise<Transaction> {
22
+ sanitizePath(path)
23
+ const instructionData = Buffer.concat([
24
+ Buffer.from(Int8Array.from([7]).buffer),
25
+ Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
26
+ Buffer.from(`${path}`, 'utf-8')
27
+ ])
28
+
29
+ const instruction = new TransactionInstruction({
30
+ keys: [
31
+ {
32
+ pubkey: wallet,
33
+ isSigner: true,
34
+ isWritable: true
35
+ }
36
+ ],
37
+ programId: new PublicKey(programId),
38
+ data: instructionData
39
+ })
40
+
41
+ const tx = new Transaction().add(instruction)
42
+ return tx
43
+ }