@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
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
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
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 remove a file from a file system,
|
|
8
|
+
* identified by a file system ID (`fsid`) and a UTF-8 encoded file path.
|
|
9
|
+
*
|
|
10
|
+
* @param fsid - A stringified integer representing the file system ID in which the file resides.
|
|
11
|
+
* @param path - The full path to the file to be deleted.
|
|
12
|
+
* @param wallet - The public key of the wallet that signs and authorizes the transaction.
|
|
13
|
+
* @returns A Promise that resolves to a Solana `Transaction` object containing the remove file instruction.
|
|
14
|
+
* @throws May throw an error if `path` is invalid per `sanitizePath`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
export async function removeFile (
|
|
18
|
+
fsid: string,
|
|
19
|
+
path: string,
|
|
20
|
+
wallet: PublicKey
|
|
21
|
+
): Promise<Transaction> {
|
|
22
|
+
sanitizePath(path)
|
|
23
|
+
|
|
24
|
+
const instructionData = Buffer.concat([
|
|
25
|
+
Buffer.from(Int8Array.from([5]).buffer),
|
|
26
|
+
Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
|
|
27
|
+
Buffer.from(`${path}`, 'utf-8')
|
|
28
|
+
])
|
|
29
|
+
|
|
30
|
+
const instruction = new TransactionInstruction({
|
|
31
|
+
keys: [
|
|
32
|
+
{
|
|
33
|
+
pubkey: wallet,
|
|
34
|
+
isSigner: true,
|
|
35
|
+
isWritable: true
|
|
36
|
+
}
|
|
37
|
+
],
|
|
38
|
+
programId: new PublicKey(programId),
|
|
39
|
+
data: instructionData
|
|
40
|
+
})
|
|
41
|
+
|
|
42
|
+
const tx = new Transaction().add(instruction)
|
|
43
|
+
return tx
|
|
44
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
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 rename (or move) a file or directory
|
|
8
|
+
* within a file system, based on a provided file system ID (`fsid`).
|
|
9
|
+
*
|
|
10
|
+
* @param fsid - A stringified integer representing the file system ID where the path exists.
|
|
11
|
+
* @param oldPath - The current path of the file or directory to be renamed or moved.
|
|
12
|
+
* @param name - The new name to assign to the file or directory.
|
|
13
|
+
* @param wallet - The public key of the wallet that signs and authorizes the transaction.
|
|
14
|
+
* @returns A Promise that resolves to a Solana `Transaction` object containing the rename path instruction.
|
|
15
|
+
* @throws May throw an error if either `oldPath` or `newPath` is invalid per `sanitizePath`.
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
export async function renamePath (
|
|
19
|
+
fsid: string,
|
|
20
|
+
oldPath: string,
|
|
21
|
+
name: string,
|
|
22
|
+
wallet: PublicKey
|
|
23
|
+
): Promise<Transaction> {
|
|
24
|
+
sanitizePath(oldPath)
|
|
25
|
+
|
|
26
|
+
sanitizePath(name)
|
|
27
|
+
|
|
28
|
+
const rest = Buffer.from(`${oldPath}\0${name}`, 'utf-8')
|
|
29
|
+
|
|
30
|
+
const instructionData = Buffer.concat([
|
|
31
|
+
Buffer.from(Int8Array.from([8]).buffer),
|
|
32
|
+
Buffer.from(Uint8Array.of(...new BN(fsid).toArray('le', 8))),
|
|
33
|
+
rest
|
|
34
|
+
])
|
|
35
|
+
|
|
36
|
+
const instruction = new TransactionInstruction({
|
|
37
|
+
keys: [
|
|
38
|
+
{
|
|
39
|
+
pubkey: wallet,
|
|
40
|
+
isSigner: true,
|
|
41
|
+
isWritable: true
|
|
42
|
+
}
|
|
43
|
+
],
|
|
44
|
+
programId: new PublicKey(programId),
|
|
45
|
+
data: instructionData
|
|
46
|
+
})
|
|
47
|
+
|
|
48
|
+
const tx = new Transaction().add(instruction)
|
|
49
|
+
return tx
|
|
50
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Sanitizes file path for validate path.
|
|
3
|
+
* Ensures the path contains only allowed characters, prevents path traversal,
|
|
4
|
+
* and normalizes the path to start with a single slash.
|
|
5
|
+
*
|
|
6
|
+
* Allowed characters: alphanumeric, '/', '_', '-', '.'
|
|
7
|
+
* Disallowed: consecutive slashes (//), path traversal (..), control characters,
|
|
8
|
+
* invalid filesystem characters (<, >, :, ", \, |, ?, *),
|
|
9
|
+
* empty or whitespace-only paths.
|
|
10
|
+
*
|
|
11
|
+
* @param path - The file path to sanitize.
|
|
12
|
+
* @throws Error if the path is invalid.
|
|
13
|
+
*/
|
|
14
|
+
export function sanitizePath(path: string): void {
|
|
15
|
+
// Check for empty or whitespace-only paths
|
|
16
|
+
if (!path || path.trim() === "") {
|
|
17
|
+
throw new Error("Path cannot be empty or whitespace-only");
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
// Check for consecutive slashes (// or more)
|
|
21
|
+
if (/\/\/+/.test(path)) {
|
|
22
|
+
throw new Error("Consecutive slashes (//) are not allowed");
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
// Check for path traversal sequences (..)
|
|
26
|
+
if (path.includes("..")) {
|
|
27
|
+
throw new Error("Path traversal sequences (..) are not allowed");
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// Check for control characters (ASCII 0-31 and 127)
|
|
31
|
+
for (let i = 0; i < path.length; i++) {
|
|
32
|
+
const code = path.charCodeAt(i);
|
|
33
|
+
if (code <= 31 || code === 127) {
|
|
34
|
+
throw new Error("Control characters are not allowed in paths");
|
|
35
|
+
}
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
// Check for allowed characters: alphanumeric, /, _, -, .
|
|
39
|
+
if (!/^[a-zA-Z0-9\/_\-\.]*$/.test(path)) {
|
|
40
|
+
throw new Error(
|
|
41
|
+
"Path must contain only alphanumeric characters, single slashes, underscores (_), hyphens (-), or periods (.)"
|
|
42
|
+
);
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
// Check for invalid filesystem characters
|
|
46
|
+
const invalidChars = ["<", ">", ":", '"', "\\", "|", "?", "*"];
|
|
47
|
+
for (let i = 0; i < path.length; i++) {
|
|
48
|
+
if (invalidChars.includes(path[i])) {
|
|
49
|
+
throw new Error(
|
|
50
|
+
'Path contains invalid filesystem characters (<, >, :, ", \\, |, ?, *)'
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
// Check path component length (max 255 bytes)
|
|
57
|
+
const components = path.split("/").filter((c) => c.length > 0);
|
|
58
|
+
for (const component of components) {
|
|
59
|
+
if (new TextEncoder().encode(component).length > 255) {
|
|
60
|
+
throw new Error("Path component exceeds 255 bytes");
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
// Check total path length (max 4096 bytes)
|
|
65
|
+
if (new TextEncoder().encode(path).length > 4096) {
|
|
66
|
+
throw new Error("Total path length exceeds 4096 bytes");
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
}
|
package/src/webSocket.ts
ADDED
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import WebSocket from 'ws'
|
|
2
|
+
import { PublicKey, Transaction, TransactionInstruction, Keypair, Connection, clusterApiUrl,ComputeBudgetProgram } from "@solana/web3.js"
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Represents the structure of result data received from a WebSocket subscription.
|
|
6
|
+
*
|
|
7
|
+
* - `fsid` (optional): The file system ID returned from the result.
|
|
8
|
+
* - `status` (optional): The status of the transaction or operation.
|
|
9
|
+
* - `data` (optional): Any custom payload or message associated with the result.
|
|
10
|
+
* - `subscription` (optional): The ID of the WebSocket subscription.
|
|
11
|
+
*/
|
|
12
|
+
type ResultValue = {
|
|
13
|
+
fsid?: string
|
|
14
|
+
status?: string
|
|
15
|
+
data?: any
|
|
16
|
+
subscription?: string
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Opens a WebSocket connection and subscribes to the result of a transaction
|
|
21
|
+
* via the custom `xandeumResultSubscribe` method.
|
|
22
|
+
*
|
|
23
|
+
* This is useful for receiving asynchronous results tied to an on-chain operation,
|
|
24
|
+
* such as file creation, modification, or deletion.
|
|
25
|
+
*
|
|
26
|
+
* The subscription sends a JSON-RPC request with:
|
|
27
|
+
* - `method`: "xandeumResultSubscribe"
|
|
28
|
+
* - `params`: [txId, { commitment: "finalized" }]
|
|
29
|
+
*
|
|
30
|
+
* The WebSocket listens for result messages and invokes the `onResult` callback
|
|
31
|
+
* if a valid result with `fsid`, `status`, or `data` is received.
|
|
32
|
+
*
|
|
33
|
+
* @param tx - The transaction ID you want to listen for results from.
|
|
34
|
+
* @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
|
|
35
|
+
* @param onResult - Callback to handle incoming result messages. Triggered when a valid response is received.
|
|
36
|
+
* @param onError - (Optional) Callback triggered if a WebSocket error occurs.
|
|
37
|
+
* @param onClose - (Optional) Callback triggered when the WebSocket connection closes.
|
|
38
|
+
*/
|
|
39
|
+
|
|
40
|
+
export function subscribeResult (
|
|
41
|
+
connection: Connection,
|
|
42
|
+
tx: string,
|
|
43
|
+
onResult: (value: ResultValue) => void,
|
|
44
|
+
onError?: (err: any) => void,
|
|
45
|
+
onClose?: () => void
|
|
46
|
+
): void {
|
|
47
|
+
let rpcEndpoint = connection.rpcEndpoint;
|
|
48
|
+
const ws = new WebSocket(rpcEndpoint.replace('http', 'ws'));
|
|
49
|
+
|
|
50
|
+
ws.addEventListener('open', () => {
|
|
51
|
+
const subscriptionMessage = {
|
|
52
|
+
jsonrpc: '2.0',
|
|
53
|
+
id: 1,
|
|
54
|
+
method: 'xandeumResultSubscribe',
|
|
55
|
+
params: [tx, { commitment: 'finalized' }]
|
|
56
|
+
}
|
|
57
|
+
ws.send(JSON.stringify(subscriptionMessage))
|
|
58
|
+
})
|
|
59
|
+
|
|
60
|
+
ws.addEventListener('message', event => {
|
|
61
|
+
const d = JSON.parse(String(event.data).replace(/:\s*(\d{16,})/g, ': "$1"'))
|
|
62
|
+
|
|
63
|
+
const value = d?.params?.result?.value
|
|
64
|
+
if (
|
|
65
|
+
(value?.fsid || value?.status || value?.data) &&
|
|
66
|
+
d?.params?.subscription
|
|
67
|
+
) {
|
|
68
|
+
onResult({
|
|
69
|
+
fsid: value.fsid,
|
|
70
|
+
status: value.status,
|
|
71
|
+
data: value.message,
|
|
72
|
+
subscription: d.params.subscription
|
|
73
|
+
})
|
|
74
|
+
}
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
ws.addEventListener('error', error => {
|
|
78
|
+
if (onError) onError(error)
|
|
79
|
+
})
|
|
80
|
+
|
|
81
|
+
ws.addEventListener('close', () => {
|
|
82
|
+
if (onClose) onClose()
|
|
83
|
+
})
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Sends a WebSocket JSON-RPC message to unsubscribe from a previously subscribed transaction result
|
|
88
|
+
* using the `xandeumResultUnsubscribed` method (note: custom method, ensure server-side implementation matches).
|
|
89
|
+
*
|
|
90
|
+
* This function automatically closes the WebSocket connection after sending the unsubscribe request.
|
|
91
|
+
*
|
|
92
|
+
* @param subscriptionId - The ID of the active subscription you want to cancel.
|
|
93
|
+
* @param connection - The solana web3 connection with Xandeum-compatible JSON-RPC endpoint (e.g., `'https://api.devnet.solana.com'`).
|
|
94
|
+
*/
|
|
95
|
+
|
|
96
|
+
export function unsubscribeResult(connection: Connection,subscriptionId: string): void {
|
|
97
|
+
let rpcEndpoint = connection.rpcEndpoint;
|
|
98
|
+
const ws = new WebSocket(rpcEndpoint.replace('http', 'ws'));
|
|
99
|
+
|
|
100
|
+
ws.addEventListener('open', () => {
|
|
101
|
+
const unsubscribeMessage = {
|
|
102
|
+
jsonrpc: '2.0',
|
|
103
|
+
id: 2,
|
|
104
|
+
method: 'xandeumResultUnsubscribe',
|
|
105
|
+
params: [subscriptionId]
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
ws.send(JSON.stringify(unsubscribeMessage))
|
|
109
|
+
console.log(
|
|
110
|
+
`Sent xandeumResultUnsubscribe for subscription ID: ${subscriptionId}`
|
|
111
|
+
)
|
|
112
|
+
ws.close()
|
|
113
|
+
})
|
|
114
|
+
|
|
115
|
+
ws.addEventListener('error', err => {
|
|
116
|
+
console.error('WebSocket error during unsubscribe:', err)
|
|
117
|
+
})
|
|
118
|
+
}
|
package/tsconfig.json
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
{
|
|
2
|
+
"compilerOptions": {
|
|
3
|
+
"target": "ES5",
|
|
4
|
+
"module": "CommonJS",
|
|
5
|
+
"outDir": "dist",
|
|
6
|
+
"rootDir": "src",
|
|
7
|
+
"declaration": true,
|
|
8
|
+
"esModuleInterop": true,
|
|
9
|
+
"strict": true
|
|
10
|
+
},
|
|
11
|
+
"include": ["src/**/*.ts"],
|
|
12
|
+
"exclude": ["node_modules", "dist"]
|
|
13
|
+
}
|
|
14
|
+
|
package/typedoc.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://typedoc.org/schema.json",
|
|
3
|
+
"entryPoints": ["src/index.ts"],
|
|
4
|
+
"plugin": ["typedoc-plugin-markdown"],
|
|
5
|
+
"out": "docs/markdown",
|
|
6
|
+
"tsconfig": "tsconfig.json",
|
|
7
|
+
"name": "Xandeum Web3 Library",
|
|
8
|
+
"readme": "README.md",
|
|
9
|
+
"theme": "default",
|
|
10
|
+
"includeVersion": true,
|
|
11
|
+
"hideGenerator": false,
|
|
12
|
+
"githubPages": true,
|
|
13
|
+
"cleanOutputDir": true,
|
|
14
|
+
"excludePrivate": true,
|
|
15
|
+
"excludeProtected": true,
|
|
16
|
+
"excludeInternal": true,
|
|
17
|
+
"excludeNotDocumented": false,
|
|
18
|
+
"gitRemote": "origin",
|
|
19
|
+
"gitRevision": "main",
|
|
20
|
+
"sourceLinkTemplate": "https://github.com/Xandeum/test_web3/blob/{gitRevision}/{path}#L{line}",
|
|
21
|
+
"visibilityFilters": {
|
|
22
|
+
"protected": false,
|
|
23
|
+
"private": false,
|
|
24
|
+
"inherited": true,
|
|
25
|
+
"external": true
|
|
26
|
+
}
|
|
27
|
+
}
|