@minip2p/react-native 0.1.1 → 0.3.1
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 +25 -83
- package/android/src/main/jniLibs/arm64-v8a/libminip2p_ffi.so +0 -0
- package/android/src/main/jniLibs/x86_64/libminip2p_ffi.so +0 -0
- package/build/Minip2pFfi.xcframework/ios-arm64/libminip2p_ffi.a +0 -0
- package/build/Minip2pFfi.xcframework/ios-arm64-simulator/libminip2p_ffi.a +0 -0
- package/cpp/generated/minip2p_ffi.cpp +45 -2
- package/cpp/generated/minip2p_ffi.hpp +2 -0
- package/lib/module/adapter.js +16 -8
- package/lib/module/adapter.js.map +1 -1
- package/lib/module/generated/minip2p_ffi-ffi.js.map +1 -1
- package/lib/module/generated/minip2p_ffi.js +159 -46
- package/lib/module/generated/minip2p_ffi.js.map +1 -1
- package/lib/module/hook-lifecycle.js +116 -0
- package/lib/module/hook-lifecycle.js.map +1 -0
- package/lib/module/hooks.js +56 -0
- package/lib/module/hooks.js.map +1 -0
- package/lib/module/index.js +2 -1
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/src/adapter.d.ts +4 -4
- package/lib/typescript/src/adapter.d.ts.map +1 -1
- package/lib/typescript/src/generated/minip2p_ffi-ffi.d.ts +3 -1
- package/lib/typescript/src/generated/minip2p_ffi-ffi.d.ts.map +1 -1
- package/lib/typescript/src/generated/minip2p_ffi.d.ts +89 -3
- package/lib/typescript/src/generated/minip2p_ffi.d.ts.map +1 -1
- package/lib/typescript/src/hook-lifecycle.d.ts +38 -0
- package/lib/typescript/src/hook-lifecycle.d.ts.map +1 -0
- package/lib/typescript/src/hooks.d.ts +49 -0
- package/lib/typescript/src/hooks.d.ts.map +1 -0
- package/lib/typescript/src/index.d.ts +2 -1
- package/lib/typescript/src/index.d.ts.map +1 -1
- package/package.json +3 -2
- package/src/adapter.ts +40 -25
- package/src/generated/minip2p_ffi-ffi.ts +3 -1
- package/src/generated/minip2p_ffi.ts +199 -55
- package/src/hook-lifecycle.ts +152 -0
- package/src/hooks.ts +102 -0
- package/src/index.ts +8 -1
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { CloseReason, Unsubscribe } from "@minip2p/core";
|
|
2
|
+
export interface HookEndpoint {
|
|
3
|
+
close: () => void;
|
|
4
|
+
listenAddrs: () => readonly string[];
|
|
5
|
+
onClose: (handler: (reason: CloseReason) => void) => Unsubscribe;
|
|
6
|
+
peerId: () => string;
|
|
7
|
+
setActive: (active: boolean) => void;
|
|
8
|
+
}
|
|
9
|
+
export interface AppStateSource {
|
|
10
|
+
readonly currentState: string | null | undefined;
|
|
11
|
+
addEventListener: (type: "change", handler: (state: string) => void) => {
|
|
12
|
+
remove: () => void;
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
/** @internal */
|
|
16
|
+
export declare const bindAppStateSource: (endpoint: Pick<HookEndpoint, "setActive">, source: AppStateSource) => Unsubscribe;
|
|
17
|
+
export type LifecycleState<Endpoint extends HookEndpoint> = {
|
|
18
|
+
readonly status: "running";
|
|
19
|
+
readonly endpoint: Endpoint;
|
|
20
|
+
readonly peerId: string;
|
|
21
|
+
readonly listenAddrs: readonly string[];
|
|
22
|
+
} | {
|
|
23
|
+
readonly status: "closed";
|
|
24
|
+
} | {
|
|
25
|
+
readonly status: "failed";
|
|
26
|
+
readonly error: unknown;
|
|
27
|
+
};
|
|
28
|
+
/** @internal */
|
|
29
|
+
export declare const mountEndpointLifecycle: <Endpoint extends HookEndpoint>(options: {
|
|
30
|
+
readonly bindAppState: (endpoint: Endpoint) => Unsubscribe;
|
|
31
|
+
readonly create: () => Endpoint;
|
|
32
|
+
readonly notify: (state: LifecycleState<Endpoint>) => void;
|
|
33
|
+
readonly schedule?: (callback: () => void) => void;
|
|
34
|
+
}) => {
|
|
35
|
+
readonly close: () => void;
|
|
36
|
+
readonly cleanup: () => void;
|
|
37
|
+
};
|
|
38
|
+
//# sourceMappingURL=hook-lifecycle.d.ts.map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AQ,CAAC,KAAK,EAAE,OAAO,CAAA;CAAE,CAAC;AAE3D,gBAAgB;AAChB,eAAO,MAAM,sBAAsB,GAAI,QAAQ,SAAS,YAAY,EAAE,SAAS;IAC7E,QAAQ,CAAC,YAAY,EAAE,CAAC,QAAQ,EAAE,QAAQ,KAAK,WAAW,CAAC;IAC3D,QAAQ,CAAC,MAAM,EAAE,MAAM,QAAQ,CAAC;IAChC,QAAQ,CAAC,MAAM,EAAE,CAAC,KAAK,EAAE,cAAc,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC;IAC3D,QAAQ,CAAC,QAAQ,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;CACpD,KAAG;IAAE,QAAQ,CAAC,KAAK,EAAE,MAAM,IAAI,CAAC;IAAC,QAAQ,CAAC,OAAO,EAAE,MAAM,IAAI,CAAA;CA8E7D,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import type { DriverFailedError, Minip2pConfig, Unsubscribe } from "@minip2p/core";
|
|
2
|
+
import { Minip2p } from "./adapter.js";
|
|
3
|
+
/** Lifecycle state returned by {@link useMinip2p}. */
|
|
4
|
+
export type Minip2pHookState = {
|
|
5
|
+
readonly status: "starting";
|
|
6
|
+
readonly endpoint?: undefined;
|
|
7
|
+
readonly peerId?: undefined;
|
|
8
|
+
readonly listenAddrs?: undefined;
|
|
9
|
+
readonly error?: undefined;
|
|
10
|
+
} | {
|
|
11
|
+
readonly status: "running";
|
|
12
|
+
readonly endpoint: Minip2p;
|
|
13
|
+
readonly peerId: string;
|
|
14
|
+
readonly listenAddrs: readonly string[];
|
|
15
|
+
readonly error?: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
readonly status: "closed";
|
|
18
|
+
readonly endpoint?: undefined;
|
|
19
|
+
readonly peerId?: undefined;
|
|
20
|
+
readonly listenAddrs?: undefined;
|
|
21
|
+
readonly error?: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
readonly status: "failed";
|
|
24
|
+
readonly endpoint?: undefined;
|
|
25
|
+
readonly peerId?: undefined;
|
|
26
|
+
readonly listenAddrs?: undefined;
|
|
27
|
+
readonly error: unknown;
|
|
28
|
+
};
|
|
29
|
+
/** Hook lifecycle state plus an idempotent endpoint shutdown callback. */
|
|
30
|
+
export type UseMinip2pResult = Minip2pHookState & {
|
|
31
|
+
/** Closes the currently owned endpoint, if one exists. */
|
|
32
|
+
readonly close: () => void;
|
|
33
|
+
};
|
|
34
|
+
/** Mirrors the current and future React Native AppState into an endpoint. */
|
|
35
|
+
export declare const bindAppState: (endpoint: Pick<Minip2p, "setActive">) => Unsubscribe;
|
|
36
|
+
/**
|
|
37
|
+
* Owns a native endpoint for a committed component lifetime.
|
|
38
|
+
*
|
|
39
|
+
* Keep `createConfig` pure and stable for the component lifetime. Endpoint
|
|
40
|
+
* construction happens only in the committed effect.
|
|
41
|
+
*/
|
|
42
|
+
export declare const useMinip2p: (createConfig: () => Minip2pConfig) => UseMinip2pResult;
|
|
43
|
+
/** Narrows the failed hook state for consumers that want a native failure. */
|
|
44
|
+
export declare const isDriverFailure: (state: Minip2pHookState) => state is Extract<Minip2pHookState, {
|
|
45
|
+
status: "failed";
|
|
46
|
+
}> & {
|
|
47
|
+
error: DriverFailedError;
|
|
48
|
+
};
|
|
49
|
+
//# sourceMappingURL=hooks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../../../src/hooks.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,iBAAiB,EACjB,aAAa,EACb,WAAW,EACZ,MAAM,eAAe,CAAC;AAIvB,OAAO,EAAE,OAAO,EAAE,MAAM,cAAW,CAAC;AAGpC,sDAAsD;AACtD,MAAM,MAAM,gBAAgB,GACxB;IACE,QAAQ,CAAC,MAAM,EAAE,UAAU,CAAC;IAC5B,QAAQ,CAAC,QAAQ,CAAC,EAAE,SAAS,CAAC;IAC9B,QAAQ,C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CAAC;AAEF,8EAA8E;AAC9E,eAAO,MAAM,eAAe,GAC1B,OAAO,gBAAgB,KACtB,KAAK,IAAI,OAAO,CAAC,gBAAgB,EAAE;IAAE,MAAM,EAAE,QAAQ,CAAA;CAAE,CAAC,GAAG;IAC5D,KAAK,EAAE,iBAAiB,CAAC;CAIe,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
1
|
export * from "@minip2p/core";
|
|
2
|
-
export {
|
|
2
|
+
export { Minip2p, circuitAddress, generateSecretKey, peerIdFromSecretKey, } from "./adapter.js";
|
|
3
|
+
export { bindAppState, isDriverFailure, useMinip2p, type Minip2pHookState, type UseMinip2pResult, } from "./hooks.js";
|
|
3
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,cAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,eAAe,CAAC;AAC9B,OAAO,EACL,OAAO,EACP,cAAc,EACd,iBAAiB,EACjB,mBAAmB,GACpB,MAAM,cAAW,CAAC;AACnB,OAAO,EACL,YAAY,EACZ,eAAe,EACf,UAAU,EACV,KAAK,gBAAgB,EACrB,KAAK,gBAAgB,GACtB,MAAM,YAAS,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@minip2p/react-native",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "React Native bindings for minip2p",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"android",
|
|
@@ -67,7 +67,7 @@
|
|
|
67
67
|
"dependencies": {
|
|
68
68
|
"@ubjs/core": "0.31.0-3",
|
|
69
69
|
"uniffi-bindgen-react-native": "0.31.0-3",
|
|
70
|
-
"@minip2p/core": "0.1
|
|
70
|
+
"@minip2p/core": "0.3.1"
|
|
71
71
|
},
|
|
72
72
|
"devDependencies": {
|
|
73
73
|
"@react-native-community/cli": "20.1.0",
|
|
@@ -129,6 +129,7 @@
|
|
|
129
129
|
"ubrn:android": "env -u LIBCLANG_PATH ANDROID_HOME=${ANDROID_HOME:-$HOME/Library/Android/sdk} ANDROID_NDK_HOME=${ANDROID_NDK_HOME:-$HOME/Library/Android/sdk/ndk/28.2.13676358} ubrn build android --release --config ubrn.config.yaml --and-generate && node scripts/normalize-generated.mjs && node scripts/generate-codegen.mjs && node scripts/normalize-generated.mjs",
|
|
130
130
|
"clean": "del-cli android/.cxx android/build example/android/build example/android/app/build example/ios/build lib",
|
|
131
131
|
"build": "bob build && node scripts/normalize-generated.mjs",
|
|
132
|
+
"test": "pnpm build && node --test tests/*.test.mjs",
|
|
132
133
|
"typecheck": "tsc",
|
|
133
134
|
"lint": "ultracite check",
|
|
134
135
|
"format": "ultracite fix"
|
package/src/adapter.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
/* oxlint-disable class-methods-use-this, func-style, max-classes-per-file, no-use-before-define -- The adapter keeps its contract-complete native endpoint and public SDK subclass together, and uses hoisted conversion helpers. */
|
|
1
|
+
/* oxlint-disable class-methods-use-this, complexity, func-style, max-classes-per-file, no-use-before-define -- The adapter keeps its contract-complete native endpoint and public SDK subclass together, and uses hoisted conversion helpers. */
|
|
2
2
|
|
|
3
3
|
import {
|
|
4
4
|
BackpressureError,
|
|
5
5
|
MessageTooLargeError,
|
|
6
|
-
|
|
6
|
+
Minip2pBase,
|
|
7
7
|
NotPermittedError,
|
|
8
8
|
PubsubRouter,
|
|
9
9
|
} from "@minip2p/core";
|
|
@@ -11,16 +11,18 @@ import type {
|
|
|
11
11
|
Bytes,
|
|
12
12
|
IdentifyInfo,
|
|
13
13
|
KnownPeerInfo,
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
P2pEvent,
|
|
14
|
+
Minip2pConfig,
|
|
15
|
+
Minip2pDiscoveryOptions,
|
|
16
|
+
Minip2pMdnsOptions,
|
|
18
17
|
Reachability,
|
|
19
18
|
RelayReservationInfo,
|
|
20
19
|
} from "@minip2p/core";
|
|
21
20
|
import type {
|
|
22
|
-
|
|
23
|
-
|
|
21
|
+
Minip2pBackend,
|
|
22
|
+
Minip2pBackendFactory,
|
|
23
|
+
BackendOpenStream,
|
|
24
|
+
P2pEvent,
|
|
25
|
+
PathKind,
|
|
24
26
|
} from "@minip2p/core/backend";
|
|
25
27
|
|
|
26
28
|
import {
|
|
@@ -42,12 +44,12 @@ import type {
|
|
|
42
44
|
} from "./native";
|
|
43
45
|
import nativeModule from "./NativeMinip2p";
|
|
44
46
|
|
|
45
|
-
class ReactNativeBackend implements
|
|
47
|
+
class ReactNativeBackend implements Minip2pBackend {
|
|
46
48
|
readonly #endpoint: P2pEndpoint;
|
|
47
49
|
readonly #mdnsEnabled: boolean;
|
|
48
50
|
#listener: P2pEventListener | undefined;
|
|
49
51
|
|
|
50
|
-
constructor(config:
|
|
52
|
+
constructor(config: Minip2pConfig) {
|
|
51
53
|
this.#mdnsEnabled = config.mdns !== undefined && config.mdns !== false;
|
|
52
54
|
if (this.#mdnsEnabled) {
|
|
53
55
|
nativeModule.setMdnsEnabled(true);
|
|
@@ -136,6 +138,13 @@ class ReactNativeBackend implements MiniP2pBackend {
|
|
|
136
138
|
: normalizeReservation(reservation);
|
|
137
139
|
}
|
|
138
140
|
|
|
141
|
+
path(peerId: string): PathKind | undefined {
|
|
142
|
+
const path = translateErrors(() => this.#endpoint.path(peerId));
|
|
143
|
+
return path === undefined
|
|
144
|
+
? undefined
|
|
145
|
+
: (normalizeBigInts(path) as PathKind);
|
|
146
|
+
}
|
|
147
|
+
|
|
139
148
|
circuitAddress(relayAddress: string, peerId: string): string {
|
|
140
149
|
return translateErrors(() => nativeCircuitAddress(relayAddress, peerId));
|
|
141
150
|
}
|
|
@@ -178,11 +187,14 @@ class ReactNativeBackend implements MiniP2pBackend {
|
|
|
178
187
|
});
|
|
179
188
|
}
|
|
180
189
|
|
|
181
|
-
openStream(peerId: string, protocolId: string):
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
"streamId"
|
|
190
|
+
openStream(peerId: string, protocolId: string): BackendOpenStream {
|
|
191
|
+
const result = translateErrors(() =>
|
|
192
|
+
this.#endpoint.openStream(peerId, protocolId)
|
|
185
193
|
);
|
|
194
|
+
return {
|
|
195
|
+
connId: u64ToNumber(result.connId, "connId"),
|
|
196
|
+
streamId: u64ToNumber(result.streamId, "streamId"),
|
|
197
|
+
};
|
|
186
198
|
}
|
|
187
199
|
|
|
188
200
|
sendStream(peerId: string, streamId: number, data: Uint8Array): void {
|
|
@@ -272,7 +284,7 @@ class ReactNativeBackend implements MiniP2pBackend {
|
|
|
272
284
|
}
|
|
273
285
|
}
|
|
274
286
|
|
|
275
|
-
const backendFactory:
|
|
287
|
+
const backendFactory: Minip2pBackendFactory = {
|
|
276
288
|
circuitAddress: (relayAddress, peerId) =>
|
|
277
289
|
translateErrors(() => nativeCircuitAddress(relayAddress, peerId)),
|
|
278
290
|
create: (config) => new ReactNativeBackend(config),
|
|
@@ -282,14 +294,14 @@ const backendFactory: MiniP2pBackendFactory = {
|
|
|
282
294
|
};
|
|
283
295
|
|
|
284
296
|
/** High-level React Native owner for one native minip2p endpoint. */
|
|
285
|
-
export class
|
|
286
|
-
private constructor(backend:
|
|
297
|
+
export class Minip2p extends Minip2pBase {
|
|
298
|
+
private constructor(backend: Minip2pBackend, relays: readonly string[]) {
|
|
287
299
|
super(backend, relays);
|
|
288
300
|
}
|
|
289
301
|
|
|
290
302
|
/** Constructs and starts a React Native endpoint. */
|
|
291
|
-
static create(config:
|
|
292
|
-
return new
|
|
303
|
+
static create(config: Minip2pConfig): Minip2p {
|
|
304
|
+
return new Minip2p(backendFactory.create(config), config.relays ?? []);
|
|
293
305
|
}
|
|
294
306
|
}
|
|
295
307
|
|
|
@@ -308,17 +320,20 @@ export function circuitAddress(relayAddress: string, peerId: string): string {
|
|
|
308
320
|
return backendFactory.circuitAddress(relayAddress, peerId);
|
|
309
321
|
}
|
|
310
322
|
|
|
311
|
-
function toNativeConfig(config:
|
|
323
|
+
function toNativeConfig(config: Minip2pConfig): NativeEndpointConfig {
|
|
312
324
|
const discovery: NativeDiscoveryOptions | undefined =
|
|
313
325
|
config.discovery === undefined
|
|
314
326
|
? undefined
|
|
315
327
|
: {
|
|
316
|
-
autoDial: config.discovery.autoDial,
|
|
328
|
+
autoDial: config.discovery.autoDial ?? true,
|
|
317
329
|
beaconIntervalMs: numberToU64(
|
|
318
|
-
config.discovery.beaconIntervalMs,
|
|
330
|
+
config.discovery.beaconIntervalMs ?? 10_000,
|
|
319
331
|
"beaconIntervalMs"
|
|
320
332
|
),
|
|
321
|
-
peerTtlMs: numberToU64(
|
|
333
|
+
peerTtlMs: numberToU64(
|
|
334
|
+
config.discovery.peerTtlMs ?? 35_000,
|
|
335
|
+
"peerTtlMs"
|
|
336
|
+
),
|
|
322
337
|
topic: config.discovery.topic,
|
|
323
338
|
};
|
|
324
339
|
const mdnsOptions = config.mdns === true ? {} : config.mdns;
|
|
@@ -366,8 +381,8 @@ function toNativeConfig(config: MiniP2pConfig): NativeEndpointConfig {
|
|
|
366
381
|
}
|
|
367
382
|
|
|
368
383
|
function resolveMdnsAutoDial(
|
|
369
|
-
mdns:
|
|
370
|
-
discovery:
|
|
384
|
+
mdns: Minip2pMdnsOptions,
|
|
385
|
+
discovery: Minip2pDiscoveryOptions | undefined
|
|
371
386
|
): boolean {
|
|
372
387
|
return mdns.autoDial ?? discovery?.autoDial ?? true;
|
|
373
388
|
}
|
|
@@ -94,7 +94,8 @@ interface NativeModuleInterface {
|
|
|
94
94
|
ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_is_running(uniffiSelf: bigint, uniffi_out_err: UniffiRustCallStatus): number;
|
|
95
95
|
ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_known_peers(uniffiSelf: bigint, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
|
|
96
96
|
ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_listen_addrs(uniffiSelf: bigint, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
|
|
97
|
-
ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_open_stream(uniffiSelf: bigint, peerId: Uint8Array, protocolId: Uint8Array, uniffi_out_err: UniffiRustCallStatus):
|
|
97
|
+
ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_open_stream(uniffiSelf: bigint, peerId: Uint8Array, protocolId: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
|
|
98
|
+
ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_path(uniffiSelf: bigint, peerId: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
|
|
98
99
|
ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_peer_id(uniffiSelf: bigint, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
|
|
99
100
|
ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_peer_info(uniffiSelf: bigint, peerId: Uint8Array, uniffi_out_err: UniffiRustCallStatus): Uint8Array;
|
|
100
101
|
ubrn_uniffi_minip2p_ffi_fn_method_p2pendpoint_ping(uniffiSelf: bigint, peerId: Uint8Array, uniffi_out_err: UniffiRustCallStatus): void;
|
|
@@ -133,6 +134,7 @@ interface NativeModuleInterface {
|
|
|
133
134
|
ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_known_peers(): number;
|
|
134
135
|
ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_listen_addrs(): number;
|
|
135
136
|
ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_open_stream(): number;
|
|
137
|
+
ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_path(): number;
|
|
136
138
|
ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_peer_id(): number;
|
|
137
139
|
ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_peer_info(): number;
|
|
138
140
|
ubrn_uniffi_minip2p_ffi_checksum_method_p2pendpoint_ping(): number;
|