@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,60 @@
|
|
|
1
|
+
[**Xandeum Web3 Library v9.2.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Xandeum Web3 Library](../globals.md) / subscribeResult
|
|
6
|
+
|
|
7
|
+
# Function: subscribeResult()
|
|
8
|
+
|
|
9
|
+
> **subscribeResult**(`tx`, `wsUrl`, `onResult`, `onError?`, `onClose?`): `void`
|
|
10
|
+
|
|
11
|
+
Defined in: [webSocket.ts:38](https://github.com/Xandeum/test_web3/blob/main/src/webSocket.ts#L38)
|
|
12
|
+
|
|
13
|
+
Opens a WebSocket connection and subscribes to the result of a transaction
|
|
14
|
+
via the custom `xandeumResultSubscribe` method.
|
|
15
|
+
|
|
16
|
+
This is useful for receiving asynchronous results tied to an on-chain operation,
|
|
17
|
+
such as file creation, modification, or deletion.
|
|
18
|
+
|
|
19
|
+
The subscription sends a JSON-RPC request with:
|
|
20
|
+
- `method`: "xandeumResultSubscribe"
|
|
21
|
+
- `params`: [txId, { commitment: "finalized" }]
|
|
22
|
+
|
|
23
|
+
The WebSocket listens for result messages and invokes the `onResult` callback
|
|
24
|
+
if a valid result with `fsid`, `status`, or `data` is received.
|
|
25
|
+
|
|
26
|
+
## Parameters
|
|
27
|
+
|
|
28
|
+
### tx
|
|
29
|
+
|
|
30
|
+
`string`
|
|
31
|
+
|
|
32
|
+
The transaction ID you want to listen for results from.
|
|
33
|
+
|
|
34
|
+
### wsUrl
|
|
35
|
+
|
|
36
|
+
`string`
|
|
37
|
+
|
|
38
|
+
The full WebSocket endpoint (e.g., `wss://...`) to connect to.
|
|
39
|
+
|
|
40
|
+
### onResult
|
|
41
|
+
|
|
42
|
+
(`value`) => `void`
|
|
43
|
+
|
|
44
|
+
Callback to handle incoming result messages. Triggered when a valid response is received.
|
|
45
|
+
|
|
46
|
+
### onError?
|
|
47
|
+
|
|
48
|
+
(`err`) => `void`
|
|
49
|
+
|
|
50
|
+
(Optional) Callback triggered if a WebSocket error occurs.
|
|
51
|
+
|
|
52
|
+
### onClose?
|
|
53
|
+
|
|
54
|
+
() => `void`
|
|
55
|
+
|
|
56
|
+
(Optional) Callback triggered when the WebSocket connection closes.
|
|
57
|
+
|
|
58
|
+
## Returns
|
|
59
|
+
|
|
60
|
+
`void`
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
[**Xandeum Web3 Library v9.2.0**](../README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
[Xandeum Web3 Library](../globals.md) / unsubscribeResult
|
|
6
|
+
|
|
7
|
+
# Function: unsubscribeResult()
|
|
8
|
+
|
|
9
|
+
> **unsubscribeResult**(`subscriptionId`, `wsUrl`): `void`
|
|
10
|
+
|
|
11
|
+
Defined in: [webSocket.ts:93](https://github.com/Xandeum/test_web3/blob/main/src/webSocket.ts#L93)
|
|
12
|
+
|
|
13
|
+
Sends a WebSocket JSON-RPC message to unsubscribe from a previously subscribed transaction result
|
|
14
|
+
using the `xandeumResultUnsubscribed` method (note: custom method, ensure server-side implementation matches).
|
|
15
|
+
|
|
16
|
+
This function automatically closes the WebSocket connection after sending the unsubscribe request.
|
|
17
|
+
|
|
18
|
+
## Parameters
|
|
19
|
+
|
|
20
|
+
### subscriptionId
|
|
21
|
+
|
|
22
|
+
`string`
|
|
23
|
+
|
|
24
|
+
The ID of the active subscription you want to cancel.
|
|
25
|
+
|
|
26
|
+
### wsUrl
|
|
27
|
+
|
|
28
|
+
`string`
|
|
29
|
+
|
|
30
|
+
The WebSocket endpoint (e.g., `wss://...`) to connect to for unsubscribing.
|
|
31
|
+
|
|
32
|
+
## Returns
|
|
33
|
+
|
|
34
|
+
`void`
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
[**Xandeum Web3 Library v9.2.0**](README.md)
|
|
2
|
+
|
|
3
|
+
***
|
|
4
|
+
|
|
5
|
+
# Xandeum Web3 Library v9.2.0
|
|
6
|
+
|
|
7
|
+
## Functions
|
|
8
|
+
|
|
9
|
+
- [armageddon](functions/armageddon.md)
|
|
10
|
+
- [bigbang](functions/bigbang.md)
|
|
11
|
+
- [copyPath](functions/copyPath.md)
|
|
12
|
+
- [createDirectory](functions/createDirectory.md)
|
|
13
|
+
- [createFile](functions/createFile.md)
|
|
14
|
+
- [exists](functions/exists.md)
|
|
15
|
+
- [getMetadata](functions/getMetadata.md)
|
|
16
|
+
- [listDirectoryEntry](functions/listDirectoryEntry.md)
|
|
17
|
+
- [peek](functions/peek.md)
|
|
18
|
+
- [poke](functions/poke.md)
|
|
19
|
+
- [removeDirectory](functions/removeDirectory.md)
|
|
20
|
+
- [removeFile](functions/removeFile.md)
|
|
21
|
+
- [renamePath](functions/renamePath.md)
|
|
22
|
+
- [subscribeResult](functions/subscribeResult.md)
|
|
23
|
+
- [unsubscribeResult](functions/unsubscribeResult.md)
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
<!DOCTYPE html><html class="default" lang="en" data-base="./"><head><meta charset="utf-8"/><meta http-equiv="x-ua-compatible" content="IE=edge"/><title>Xandeum Web3 Library - v9.0.0</title><meta name="description" content="Documentation for Xandeum Web3 Library"/><meta name="viewport" content="width=device-width, initial-scale=1"/><link rel="stylesheet" href="assets/style.css"/><link rel="stylesheet" href="assets/highlight.css"/><script defer src="assets/main.js"></script><script async src="assets/icons.js" id="tsd-icons-script"></script><script async src="assets/search.js" id="tsd-search-script"></script><script async src="assets/navigation.js" id="tsd-nav-script"></script></head><body><script>document.documentElement.dataset.theme = localStorage.getItem("tsd-theme") || "os";document.body.style.display="none";setTimeout(() => window.app?app.showPage():document.body.style.removeProperty("display"),500)</script><header class="tsd-page-toolbar"><div class="tsd-toolbar-contents container"><a href="index.html" class="title">Xandeum Web3 Library - v9.0.0</a><div id="tsd-toolbar-links"></div><button id="tsd-search-trigger" class="tsd-widget" aria-label="Search"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-search"></use></svg></button><dialog id="tsd-search" aria-label="Search"><input role="combobox" id="tsd-search-input" aria-controls="tsd-search-results" aria-autocomplete="list" aria-expanded="true" autocapitalize="off" autocomplete="off" placeholder="Search the docs" maxLength="100"/><ul role="listbox" id="tsd-search-results"></ul><div id="tsd-search-status" aria-live="polite" aria-atomic="true"><div>Preparing search index...</div></div></dialog><a href="#" class="tsd-widget menu" id="tsd-toolbar-menu-trigger" data-toggle="menu" aria-label="Menu"><svg width="16" height="16" viewBox="0 0 16 16" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-menu"></use></svg></a></div></header><div class="container container-main"><div class="col-content"><div class="tsd-page-title"><ul class="tsd-breadcrumb" aria-label="Breadcrumb"></ul><h1>Xandeum Web3 Library - v9.0.0</h1></div><details class="tsd-panel-group tsd-member-group tsd-accordion" open><summary class="tsd-accordion-summary" data-key="section-Functions"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h2>Functions</h2></summary><dl class="tsd-member-summaries"><dt class="tsd-member-summary" id="armageddon"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/armageddon.html">armageddon</a><a href="#armageddon" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="bigbang"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/bigbang.html">bigbang</a><a href="#bigbang" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="copypath"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/copyPath.html">copyPath</a><a href="#copypath" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="createdirectory"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/createDirectory.html">createDirectory</a><a href="#createdirectory" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="createfile"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/createFile.html">createFile</a><a href="#createfile" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="exists"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/exists.html">exists</a><a href="#exists" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="getmetadata"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/getMetadata.html">getMetadata</a><a href="#getmetadata" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="listdirectoryentry"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/listDirectoryEntry.html">listDirectoryEntry</a><a href="#listdirectoryentry" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="peek"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/peek.html">peek</a><a href="#peek" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="poke"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/poke.html">poke</a><a href="#poke" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="removedirectory"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/removeDirectory.html">removeDirectory</a><a href="#removedirectory" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="removefile"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/removeFile.html">removeFile</a><a href="#removefile" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="renamepath"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/renamePath.html">renamePath</a><a href="#renamepath" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="subscriberesult"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/subscribeResult.html">subscribeResult</a><a href="#subscriberesult" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd><dt class="tsd-member-summary" id="unsubscriberesult"><span class="tsd-member-summary-name"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><a href="functions/unsubscribeResult.html">unsubscribeResult</a><a href="#unsubscriberesult" aria-label="Permalink" class="tsd-anchor-icon"><svg viewBox="0 0 24 24" aria-hidden="true"><use href="assets/icons.svg#icon-anchor"></use></svg></a></span></dt><dd class="tsd-member-summary"></dd></dl></details></div><div class="col-sidebar"><div class="page-menu"><div class="tsd-navigation settings"><details class="tsd-accordion"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>Settings</h3></summary><div class="tsd-accordion-details"><div class="tsd-filter-visibility"><span class="settings-label">Member Visibility</span><ul id="tsd-filter-options"><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-inherited" name="inherited" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>Inherited</span></label></li><li class="tsd-filter-item"><label class="tsd-filter-input"><input type="checkbox" id="tsd-filter-external" name="external" checked/><svg width="32" height="32" viewBox="0 0 32 32" aria-hidden="true"><rect class="tsd-checkbox-background" width="30" height="30" x="1" y="1" rx="6" fill="none"></rect><path class="tsd-checkbox-checkmark" d="M8.35422 16.8214L13.2143 21.75L24.6458 10.25" stroke="none" stroke-width="3.5" stroke-linejoin="round" fill="none"></path></svg><span>External</span></label></li></ul></div><div class="tsd-theme-toggle"><label class="settings-label" for="tsd-theme">Theme</label><select id="tsd-theme"><option value="os">OS</option><option value="light">Light</option><option value="dark">Dark</option></select></div></div></details></div><details open class="tsd-accordion tsd-page-navigation"><summary class="tsd-accordion-summary"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg><h3>On This Page</h3></summary><div class="tsd-accordion-details"><details open class="tsd-accordion tsd-page-navigation-section"><summary class="tsd-accordion-summary" data-key="section-Functions"><svg width="20" height="20" viewBox="0 0 24 24" fill="none" aria-hidden="true"><use href="assets/icons.svg#icon-chevronDown"></use></svg>Functions</summary><div><a href="#armageddon"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>armageddon</span></a><a href="#bigbang"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>bigbang</span></a><a href="#copypath"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>copy<wbr/>Path</span></a><a href="#createdirectory"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>create<wbr/>Directory</span></a><a href="#createfile"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>create<wbr/>File</span></a><a href="#exists"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>exists</span></a><a href="#getmetadata"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>get<wbr/>Metadata</span></a><a href="#listdirectoryentry"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>list<wbr/>Directory<wbr/>Entry</span></a><a href="#peek"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>peek</span></a><a href="#poke"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>poke</span></a><a href="#removedirectory"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>remove<wbr/>Directory</span></a><a href="#removefile"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>remove<wbr/>File</span></a><a href="#renamepath"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>rename<wbr/>Path</span></a><a href="#subscriberesult"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>subscribe<wbr/>Result</span></a><a href="#unsubscriberesult"><svg class="tsd-kind-icon" viewBox="0 0 24 24" aria-label="Function"><use href="assets/icons.svg#icon-64"></use></svg><span>unsubscribe<wbr/>Result</span></a></div></details></div></details></div><div class="site-menu"><nav class="tsd-navigation"><a href="modules.html" class="current">Xandeum Web3 Library - v9.0.0</a><ul class="tsd-small-nested-navigation" id="tsd-nav-container"><li>Loading...</li></ul></nav></div></div></div><footer><p class="tsd-generator">Generated using <a href="https://typedoc.org/" target="_blank">TypeDoc</a></p></footer><div class="overlay"></div></body></html>
|
package/package.json
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@xandeum/web3.js",
|
|
3
|
+
"version": "1.1.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"
|
|
10
|
+
},
|
|
11
|
+
"author": "",
|
|
12
|
+
"license": "MIT",
|
|
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,29 @@
|
|
|
1
|
+
import { Transaction, TransactionInstruction, PublicKey } from '@solana/web3.js'
|
|
2
|
+
import { programId } from './const'
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Constructs a Solana transaction that triggers the "bigbang" instruction and create new file system.
|
|
6
|
+
*
|
|
7
|
+
* @param wallet - The public key of the wallet that will sign and authorize the transaction.
|
|
8
|
+
* @returns A Promise that resolves to a Solana `Transaction` object containing the bigbang instruction.
|
|
9
|
+
*/
|
|
10
|
+
export async function bigbang (wallet: PublicKey): Promise<Transaction> {
|
|
11
|
+
const instructionData = Buffer.concat([
|
|
12
|
+
Buffer.from(Int8Array.from([0]).buffer)
|
|
13
|
+
])
|
|
14
|
+
|
|
15
|
+
const instruction = new TransactionInstruction({
|
|
16
|
+
keys: [
|
|
17
|
+
{
|
|
18
|
+
pubkey: wallet,
|
|
19
|
+
isSigner: true,
|
|
20
|
+
isWritable: true
|
|
21
|
+
}
|
|
22
|
+
],
|
|
23
|
+
programId: new PublicKey(programId),
|
|
24
|
+
data: instructionData
|
|
25
|
+
})
|
|
26
|
+
|
|
27
|
+
const tx = new Transaction().add(instruction)
|
|
28
|
+
return tx
|
|
29
|
+
}
|
package/src/const.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const programId="xSHLJPXU8QW3A9kGiRoL94bksJ7ZZPY4dUwJPAT8CVK";
|
package/src/copyPath.ts
ADDED
|
@@ -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
|
+
let combinedPath = 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
|
+
let combinedPath = 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,46 @@
|
|
|
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
|
+
throw new Error(`HTTP error! Status: ${response.status}`)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
const data = await response.json()
|
|
45
|
+
return data
|
|
46
|
+
}
|
|
@@ -0,0 +1,49 @@
|
|
|
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
|
+
throw new Error(`HTTP error! Status: ${response.status}`)
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
const data = await response.json()
|
|
48
|
+
return data
|
|
49
|
+
}
|
package/src/index.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
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
|
+
|
|
13
|
+
export {exists } from "./exists";
|
|
14
|
+
export {listDirectoryEntry} from "./listDirectoryEntery";
|
|
15
|
+
export {getMetadata} from "./getMetadata";
|
|
@@ -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 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
|
+
throw new Error(`HTTP error! Status: ${response.status}`)
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
const data = await response.json()
|
|
49
|
+
return data
|
|
50
|
+
}
|
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
|
+
}
|