@parity/truapi-provider 0.1.1-dev-20260731.0 → 0.1.1-dev-20260814.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +23 -35
- package/dist/truapi_provider.d.ts +12 -6
- package/dist/truapi_provider.js +26 -20
- package/dist/truapi_provider_bg.wasm +0 -0
- package/dist/truapi_provider_bg.wasm.d.ts +6 -6
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
Network transport for the TrUAPI `ChainProvider` contract: an embedded
|
|
4
4
|
[smoldot](https://github.com/smol-dot/smoldot) light client, or a remote
|
|
5
|
-
WebSocket JSON-RPC node, behind one API. This is the WebAssembly build,
|
|
6
|
-
browser and desktop (webview) hosts.
|
|
7
|
-
crate natively over UniFFI, so network access works the same everywhere.
|
|
5
|
+
WebSocket JSON-RPC node, behind one API. This package is the WebAssembly build,
|
|
6
|
+
for browser and desktop (webview) hosts.
|
|
8
7
|
|
|
9
8
|
You connect to a network by its genesis hash, and everything else is handled for
|
|
10
9
|
you: the bundled catalog provides the spec and relay wiring, so clients never
|
|
11
10
|
ship or refresh specs of their own. One light client is shared across all
|
|
12
|
-
connections
|
|
13
|
-
|
|
11
|
+
connections. Its synced state can be captured and restored, so a launch resumes
|
|
12
|
+
from finalized state instead of syncing from scratch.
|
|
14
13
|
|
|
15
14
|
## Usage
|
|
16
15
|
|
|
@@ -29,45 +28,34 @@ import wasmUrl from "@parity/truapi-provider/truapi_provider_bg.wasm?url";
|
|
|
29
28
|
|
|
30
29
|
await init({ module_or_path: wasmUrl });
|
|
31
30
|
|
|
32
|
-
const
|
|
33
|
-
const
|
|
31
|
+
const genesis = "0x3740…";
|
|
32
|
+
const builder = new ChainProviderBuilder();
|
|
33
|
+
|
|
34
|
+
// Resume from the state saved by the previous run, when there is one.
|
|
35
|
+
const saved = localStorage.getItem(`chain-db:${genesis}`);
|
|
36
|
+
if (saved) builder.setDatabase(genesis, saved);
|
|
37
|
+
|
|
38
|
+
const provider = builder.build();
|
|
39
|
+
const connection = await provider.connect(genesis);
|
|
34
40
|
|
|
35
41
|
connection.send('{"jsonrpc":"2.0","id":1,"method":"chainSpec_v1_genesisHash","params":[]}');
|
|
36
42
|
const response = await connection.nextResponse(); // undefined once closed
|
|
37
43
|
connection.close();
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
#### Android (Kotlin)
|
|
41
|
-
|
|
42
|
-
Native targets deliver responses to a listener instead of a pull loop, and take
|
|
43
|
-
the genesis hash as 32 raw bytes.
|
|
44
44
|
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
val connection = provider.connect(genesisHash, object : ChainMessageListener {
|
|
49
|
-
override fun onMessage(message: String) { /* JSON-RPC response */ }
|
|
50
|
-
override fun onClosed() {}
|
|
51
|
-
})
|
|
52
|
-
|
|
53
|
-
connection.send("""{"jsonrpc":"2.0","id":1,"method":"chainSpec_v1_genesisHash","params":[]}""")
|
|
54
|
-
connection.close()
|
|
45
|
+
// Later, once the light client has synced, save state for the next launch.
|
|
46
|
+
localStorage.setItem(`chain-db:${genesis}`, await provider.snapshot(genesis));
|
|
55
47
|
```
|
|
56
48
|
|
|
57
|
-
|
|
49
|
+
Warm start is driven by the host: call `snapshot()` once the light client has
|
|
50
|
+
synced, persist the string, and hand it back through `setDatabase()` before
|
|
51
|
+
`build()` on the next launch.
|
|
58
52
|
|
|
59
|
-
|
|
60
|
-
let provider = ChainProvider()
|
|
53
|
+
## Native hosts
|
|
61
54
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
let connection = try provider.connect(genesisHash: genesis, listener: Responses())
|
|
68
|
-
connection.send(request: #"{"jsonrpc":"2.0","id":1,"method":"chainSpec_v1_genesisHash","params":[]}"#)
|
|
69
|
-
connection.close()
|
|
70
|
-
```
|
|
55
|
+
Android and iOS do not consume this package. The same `truapi-provider` crate is
|
|
56
|
+
published for them as its own artifacts over UniFFI — a `TrUAPIProvider` Swift
|
|
57
|
+
package and a `truapi-provider-android` AAR — exposing the same `ChainProvider`
|
|
58
|
+
contract with the same bundled catalog, so the wiring differs only in language.
|
|
71
59
|
|
|
72
60
|
## Building
|
|
73
61
|
|
|
@@ -78,6 +78,12 @@ export class Connection {
|
|
|
78
78
|
/**
|
|
79
79
|
* Resolve with the next JSON-RPC response or notification, or
|
|
80
80
|
* `undefined` once the connection is closed or dead.
|
|
81
|
+
*
|
|
82
|
+
* Calling this in a loop is not optional: it is the only thing that drains
|
|
83
|
+
* the connection. Frames queue until they are taken, and once the backlog
|
|
84
|
+
* reaches the connection's budget further [`send`](Connection::send) calls
|
|
85
|
+
* come back as JSON-RPC errors instead of being queued, so a caller that
|
|
86
|
+
* sends without reading eventually gets nothing but errors.
|
|
81
87
|
*/
|
|
82
88
|
nextResponse(): Promise<string | undefined>;
|
|
83
89
|
/**
|
|
@@ -144,12 +150,12 @@ export interface InitOutput {
|
|
|
144
150
|
readonly networkchains_people: (a: number, b: number) => void;
|
|
145
151
|
readonly networkchains_relay: (a: number, b: number) => void;
|
|
146
152
|
readonly setLogLevel: (a: number, b: number) => void;
|
|
147
|
-
readonly
|
|
148
|
-
readonly
|
|
149
|
-
readonly
|
|
150
|
-
readonly
|
|
151
|
-
readonly
|
|
152
|
-
readonly
|
|
153
|
+
readonly __wasm_bindgen_func_elem_19082: (a: number, b: number, c: number, d: number) => void;
|
|
154
|
+
readonly __wasm_bindgen_func_elem_19084: (a: number, b: number, c: number, d: number) => void;
|
|
155
|
+
readonly __wasm_bindgen_func_elem_3717: (a: number, b: number, c: number) => void;
|
|
156
|
+
readonly __wasm_bindgen_func_elem_3717_2: (a: number, b: number, c: number) => void;
|
|
157
|
+
readonly __wasm_bindgen_func_elem_3717_3: (a: number, b: number, c: number) => void;
|
|
158
|
+
readonly __wasm_bindgen_func_elem_7114: (a: number, b: number) => void;
|
|
153
159
|
readonly __wbindgen_export: (a: number, b: number) => number;
|
|
154
160
|
readonly __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
155
161
|
readonly __wbindgen_export3: (a: number) => void;
|
package/dist/truapi_provider.js
CHANGED
|
@@ -221,6 +221,12 @@ export class Connection {
|
|
|
221
221
|
/**
|
|
222
222
|
* Resolve with the next JSON-RPC response or notification, or
|
|
223
223
|
* `undefined` once the connection is closed or dead.
|
|
224
|
+
*
|
|
225
|
+
* Calling this in a loop is not optional: it is the only thing that drains
|
|
226
|
+
* the connection. Frames queue until they are taken, and once the backlog
|
|
227
|
+
* reaches the connection's budget further [`send`](Connection::send) calls
|
|
228
|
+
* come back as JSON-RPC errors instead of being queued, so a caller that
|
|
229
|
+
* sends without reading eventually gets nothing but errors.
|
|
224
230
|
* @returns {Promise<string | undefined>}
|
|
225
231
|
*/
|
|
226
232
|
nextResponse() {
|
|
@@ -472,7 +478,7 @@ function __wbg_get_imports() {
|
|
|
472
478
|
const a = state0.a;
|
|
473
479
|
state0.a = 0;
|
|
474
480
|
try {
|
|
475
|
-
return
|
|
481
|
+
return __wasm_bindgen_func_elem_19084(a, state0.b, arg0, arg1);
|
|
476
482
|
} finally {
|
|
477
483
|
state0.a = a;
|
|
478
484
|
}
|
|
@@ -589,28 +595,28 @@ function __wbg_get_imports() {
|
|
|
589
595
|
console.warn(getObject(arg0));
|
|
590
596
|
},
|
|
591
597
|
__wbindgen_cast_0000000000000001: function(arg0, arg1) {
|
|
592
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx:
|
|
593
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
598
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [Externref], shim_idx: 1825, ret: Result(Unit), inner_ret: Some(Result(Unit)) }, mutable: true }) -> Externref`.
|
|
599
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_19082);
|
|
594
600
|
return addHeapObject(ret);
|
|
595
601
|
},
|
|
596
602
|
__wbindgen_cast_0000000000000002: function(arg0, arg1) {
|
|
597
603
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("CloseEvent")], shim_idx: 20, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
598
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
604
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_3717);
|
|
599
605
|
return addHeapObject(ret);
|
|
600
606
|
},
|
|
601
607
|
__wbindgen_cast_0000000000000003: function(arg0, arg1) {
|
|
602
608
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("Event")], shim_idx: 20, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
603
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
609
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_3717_2);
|
|
604
610
|
return addHeapObject(ret);
|
|
605
611
|
},
|
|
606
612
|
__wbindgen_cast_0000000000000004: function(arg0, arg1) {
|
|
607
613
|
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [NamedExternref("MessageEvent")], shim_idx: 20, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
608
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
614
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_3717_3);
|
|
609
615
|
return addHeapObject(ret);
|
|
610
616
|
},
|
|
611
617
|
__wbindgen_cast_0000000000000005: function(arg0, arg1) {
|
|
612
|
-
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx:
|
|
613
|
-
const ret = makeMutClosure(arg0, arg1,
|
|
618
|
+
// Cast intrinsic for `Closure(Closure { owned: true, function: Function { arguments: [], shim_idx: 675, ret: Unit, inner_ret: Some(Unit) }, mutable: true }) -> Externref`.
|
|
619
|
+
const ret = makeMutClosure(arg0, arg1, __wasm_bindgen_func_elem_7114);
|
|
614
620
|
return addHeapObject(ret);
|
|
615
621
|
},
|
|
616
622
|
__wbindgen_cast_0000000000000006: function(arg0, arg1) {
|
|
@@ -637,26 +643,26 @@ function __wbg_get_imports() {
|
|
|
637
643
|
};
|
|
638
644
|
}
|
|
639
645
|
|
|
640
|
-
function
|
|
641
|
-
wasm.
|
|
646
|
+
function __wasm_bindgen_func_elem_7114(arg0, arg1) {
|
|
647
|
+
wasm.__wasm_bindgen_func_elem_7114(arg0, arg1);
|
|
642
648
|
}
|
|
643
649
|
|
|
644
|
-
function
|
|
645
|
-
wasm.
|
|
650
|
+
function __wasm_bindgen_func_elem_3717(arg0, arg1, arg2) {
|
|
651
|
+
wasm.__wasm_bindgen_func_elem_3717(arg0, arg1, addHeapObject(arg2));
|
|
646
652
|
}
|
|
647
653
|
|
|
648
|
-
function
|
|
649
|
-
wasm.
|
|
654
|
+
function __wasm_bindgen_func_elem_3717_2(arg0, arg1, arg2) {
|
|
655
|
+
wasm.__wasm_bindgen_func_elem_3717_2(arg0, arg1, addHeapObject(arg2));
|
|
650
656
|
}
|
|
651
657
|
|
|
652
|
-
function
|
|
653
|
-
wasm.
|
|
658
|
+
function __wasm_bindgen_func_elem_3717_3(arg0, arg1, arg2) {
|
|
659
|
+
wasm.__wasm_bindgen_func_elem_3717_3(arg0, arg1, addHeapObject(arg2));
|
|
654
660
|
}
|
|
655
661
|
|
|
656
|
-
function
|
|
662
|
+
function __wasm_bindgen_func_elem_19082(arg0, arg1, arg2) {
|
|
657
663
|
try {
|
|
658
664
|
const retptr = wasm.__wbindgen_add_to_stack_pointer(-16);
|
|
659
|
-
wasm.
|
|
665
|
+
wasm.__wasm_bindgen_func_elem_19082(retptr, arg0, arg1, addHeapObject(arg2));
|
|
660
666
|
var r0 = getDataViewMemory0().getInt32(retptr + 4 * 0, true);
|
|
661
667
|
var r1 = getDataViewMemory0().getInt32(retptr + 4 * 1, true);
|
|
662
668
|
if (r1) {
|
|
@@ -667,8 +673,8 @@ function __wasm_bindgen_func_elem_12915(arg0, arg1, arg2) {
|
|
|
667
673
|
}
|
|
668
674
|
}
|
|
669
675
|
|
|
670
|
-
function
|
|
671
|
-
wasm.
|
|
676
|
+
function __wasm_bindgen_func_elem_19084(arg0, arg1, arg2, arg3) {
|
|
677
|
+
wasm.__wasm_bindgen_func_elem_19084(arg0, arg1, addHeapObject(arg2), addHeapObject(arg3));
|
|
672
678
|
}
|
|
673
679
|
|
|
674
680
|
|
|
Binary file
|
|
@@ -21,12 +21,12 @@ export const networkchains_bulletin: (a: number, b: number) => void;
|
|
|
21
21
|
export const networkchains_people: (a: number, b: number) => void;
|
|
22
22
|
export const networkchains_relay: (a: number, b: number) => void;
|
|
23
23
|
export const setLogLevel: (a: number, b: number) => void;
|
|
24
|
-
export const
|
|
25
|
-
export const
|
|
26
|
-
export const
|
|
27
|
-
export const
|
|
28
|
-
export const
|
|
29
|
-
export const
|
|
24
|
+
export const __wasm_bindgen_func_elem_19082: (a: number, b: number, c: number, d: number) => void;
|
|
25
|
+
export const __wasm_bindgen_func_elem_19084: (a: number, b: number, c: number, d: number) => void;
|
|
26
|
+
export const __wasm_bindgen_func_elem_3717: (a: number, b: number, c: number) => void;
|
|
27
|
+
export const __wasm_bindgen_func_elem_3717_2: (a: number, b: number, c: number) => void;
|
|
28
|
+
export const __wasm_bindgen_func_elem_3717_3: (a: number, b: number, c: number) => void;
|
|
29
|
+
export const __wasm_bindgen_func_elem_7114: (a: number, b: number) => void;
|
|
30
30
|
export const __wbindgen_export: (a: number, b: number) => number;
|
|
31
31
|
export const __wbindgen_export2: (a: number, b: number, c: number, d: number) => number;
|
|
32
32
|
export const __wbindgen_export3: (a: number) => void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@parity/truapi-provider",
|
|
3
|
-
"version": "0.1.1-dev-
|
|
3
|
+
"version": "0.1.1-dev-20260814.0",
|
|
4
4
|
"description": "Network provider backends for the TrUAPI ChainProvider: an embedded smoldot light client and remote WebSocket JSON-RPC nodes, compiled to WebAssembly for browser hosts",
|
|
5
5
|
"license": "MIT AND Apache-2.0",
|
|
6
6
|
"author": "Parity Technologies <admin@parity.io>",
|