@neuraiproject/neurai-rpc 0.6.2 → 0.8.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/CHANGELOG.md +17 -0
- package/DEPIN_EXAMPLES.md +45 -127
- package/DEPIN_IMPLEMENTATION_GUIDE_EN.md +19 -93
- package/README.md +29 -105
- package/depin.ts +144 -0
- package/dist/index.cjs +355 -331
- package/dist/index.d.cts +72 -4
- package/dist/index.d.ts +72 -4
- package/dist/index.mjs +346 -331
- package/docs.json +198 -198
- package/docs.ts +1342 -1504
- package/index.ts +54 -34
- package/json.ts +29 -0
- package/neurai_methods.md +743 -872
- package/package.json +4 -2
package/dist/index.d.cts
CHANGED
|
@@ -34,9 +34,9 @@ interface IMethods {
|
|
|
34
34
|
depinpoolpkey: string;
|
|
35
35
|
depinpoolstats: string;
|
|
36
36
|
depinreceivemsg: string;
|
|
37
|
+
depinreceiveseq: string;
|
|
37
38
|
depinsendmsg: string;
|
|
38
|
-
|
|
39
|
-
depinsignrequest: string;
|
|
39
|
+
depinsignrpc: string;
|
|
40
40
|
depinsubmitmsg: string;
|
|
41
41
|
disconnectnode: string;
|
|
42
42
|
distributereward: string;
|
|
@@ -201,11 +201,79 @@ interface IMethods {
|
|
|
201
201
|
}
|
|
202
202
|
declare const methods: IMethods;
|
|
203
203
|
|
|
204
|
+
/** Transport types only. Build and verify signatures with neurai-depin-msg. */
|
|
205
|
+
declare const DEPIN_RPC_PROTOCOL: 5;
|
|
206
|
+
declare const DEPIN_REMOTE_METHODS: readonly ["depingetmsginfo", "depinpoolstats", "depinmcpstatus", "depinchallenge", "depinreceivemsg", "depinreceiveseq", "depinlistsections", "depinclearmsg", "depinsubmitmsg", "depingetancestorrecipients"];
|
|
207
|
+
type DepinRemoteMethod = (typeof DEPIN_REMOTE_METHODS)[number];
|
|
208
|
+
interface DepinBootstrapRequest {
|
|
209
|
+
protocol: 5;
|
|
210
|
+
request_id: string;
|
|
211
|
+
timestamp_ms: number | bigint;
|
|
212
|
+
}
|
|
213
|
+
interface DepinSequenceCursor {
|
|
214
|
+
version: 1;
|
|
215
|
+
stream_id: string;
|
|
216
|
+
after_seq: number | bigint;
|
|
217
|
+
scope: string;
|
|
218
|
+
address: string;
|
|
219
|
+
from_timestamp: number | bigint;
|
|
220
|
+
}
|
|
221
|
+
interface DepinRpcRequest extends DepinBootstrapRequest {
|
|
222
|
+
network: string;
|
|
223
|
+
pool_pubkey: string;
|
|
224
|
+
pool_root: string;
|
|
225
|
+
instance_id: string;
|
|
226
|
+
membership_revision: string;
|
|
227
|
+
token: string;
|
|
228
|
+
address: string;
|
|
229
|
+
challenge: string;
|
|
230
|
+
args: Record<string, unknown>;
|
|
231
|
+
signature: string;
|
|
232
|
+
}
|
|
233
|
+
type DepinRpcParams = [DepinBootstrapRequest | DepinRpcRequest] | {
|
|
234
|
+
request: DepinBootstrapRequest | DepinRpcRequest;
|
|
235
|
+
};
|
|
236
|
+
interface DepinRpcResponse {
|
|
237
|
+
protocol: 5;
|
|
238
|
+
network: string;
|
|
239
|
+
pool_pubkey: string;
|
|
240
|
+
pool_root: string;
|
|
241
|
+
instance_id: string;
|
|
242
|
+
membership_revision: string;
|
|
243
|
+
membership_height: number;
|
|
244
|
+
membership_blockhash: string;
|
|
245
|
+
request_hash: string;
|
|
246
|
+
body_kind: 0 | 1;
|
|
247
|
+
body?: string;
|
|
248
|
+
encrypted?: string;
|
|
249
|
+
poolsig: string;
|
|
250
|
+
}
|
|
251
|
+
declare function isDepinRemoteMethod(method: string): method is DepinRemoteMethod;
|
|
252
|
+
/** Keep every signed byte intact. The node performs canonical validation. */
|
|
253
|
+
declare function getDepinRequest(params: unknown): DepinBootstrapRequest | DepinRpcRequest;
|
|
254
|
+
type RpcNode = {
|
|
255
|
+
rpc: (method: string, params: any) => Promise<any>;
|
|
256
|
+
};
|
|
257
|
+
/** Route signed requests to their exact pool/instance, with no request rewriting.
|
|
258
|
+
* Discovery is advisory routing metadata; the client verifies the final reply.
|
|
259
|
+
* No private request is broadcast and no write is retried by this router.
|
|
260
|
+
*/
|
|
261
|
+
declare function createDepinNodeRouter<T extends RpcNode>(healthyNodes: () => T[], randomId: () => string): (method: string, params: unknown) => Promise<T>;
|
|
262
|
+
|
|
263
|
+
/** Detect duplicate JSON property names, including equal values and escaped names.
|
|
264
|
+
* Syntax and numeric decoding are delegated to the JSON parser afterwards.
|
|
265
|
+
*/
|
|
266
|
+
declare function assertNoDuplicateJsonKeys(text: string): void;
|
|
267
|
+
|
|
268
|
+
declare const MAINNET_GENESIS_HASH = "00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806";
|
|
269
|
+
declare const TESTNET_GENESIS_HASH = "0000008b384aeffecdab182575dc4e86c9f07f90318c65088532660ed9a8a021";
|
|
270
|
+
/** Reject an RPC endpoint that serves a different chain with the same network label. */
|
|
271
|
+
declare function assertRpcGenesis(rpc: (method: string, params: any[]) => Promise<unknown>, expectedGenesisHash: string): Promise<void>;
|
|
204
272
|
/** Exact decimal parameter, emitted as a JSON number rather than a quoted string. */
|
|
205
273
|
declare function rpcNumber(value: string): LosslessNumber;
|
|
206
274
|
/** Preserve unsafe JSON numeric tokens as strings; retain safe number compatibility. */
|
|
207
275
|
declare function parseRpcJson(text: string): any;
|
|
208
276
|
declare function stringifyRpcJson(value: unknown): string;
|
|
209
|
-
declare function getRPC(username: string, password: string, URL: string): (method: string, params: any[]) => Promise<unknown>;
|
|
277
|
+
declare function getRPC(username: string, password: string, URL: string): (method: string, params: any[] | Record<string, unknown>) => Promise<unknown>;
|
|
210
278
|
|
|
211
|
-
export { getRPC, methods, parseRpcJson, rpcNumber, stringifyRpcJson };
|
|
279
|
+
export { DEPIN_REMOTE_METHODS, DEPIN_RPC_PROTOCOL, type DepinBootstrapRequest, type DepinRemoteMethod, type DepinRpcParams, type DepinRpcRequest, type DepinRpcResponse, type DepinSequenceCursor, MAINNET_GENESIS_HASH, TESTNET_GENESIS_HASH, assertNoDuplicateJsonKeys, assertRpcGenesis, createDepinNodeRouter, getDepinRequest, getRPC, isDepinRemoteMethod, methods, parseRpcJson, rpcNumber, stringifyRpcJson };
|
package/dist/index.d.ts
CHANGED
|
@@ -34,9 +34,9 @@ interface IMethods {
|
|
|
34
34
|
depinpoolpkey: string;
|
|
35
35
|
depinpoolstats: string;
|
|
36
36
|
depinreceivemsg: string;
|
|
37
|
+
depinreceiveseq: string;
|
|
37
38
|
depinsendmsg: string;
|
|
38
|
-
|
|
39
|
-
depinsignrequest: string;
|
|
39
|
+
depinsignrpc: string;
|
|
40
40
|
depinsubmitmsg: string;
|
|
41
41
|
disconnectnode: string;
|
|
42
42
|
distributereward: string;
|
|
@@ -201,11 +201,79 @@ interface IMethods {
|
|
|
201
201
|
}
|
|
202
202
|
declare const methods: IMethods;
|
|
203
203
|
|
|
204
|
+
/** Transport types only. Build and verify signatures with neurai-depin-msg. */
|
|
205
|
+
declare const DEPIN_RPC_PROTOCOL: 5;
|
|
206
|
+
declare const DEPIN_REMOTE_METHODS: readonly ["depingetmsginfo", "depinpoolstats", "depinmcpstatus", "depinchallenge", "depinreceivemsg", "depinreceiveseq", "depinlistsections", "depinclearmsg", "depinsubmitmsg", "depingetancestorrecipients"];
|
|
207
|
+
type DepinRemoteMethod = (typeof DEPIN_REMOTE_METHODS)[number];
|
|
208
|
+
interface DepinBootstrapRequest {
|
|
209
|
+
protocol: 5;
|
|
210
|
+
request_id: string;
|
|
211
|
+
timestamp_ms: number | bigint;
|
|
212
|
+
}
|
|
213
|
+
interface DepinSequenceCursor {
|
|
214
|
+
version: 1;
|
|
215
|
+
stream_id: string;
|
|
216
|
+
after_seq: number | bigint;
|
|
217
|
+
scope: string;
|
|
218
|
+
address: string;
|
|
219
|
+
from_timestamp: number | bigint;
|
|
220
|
+
}
|
|
221
|
+
interface DepinRpcRequest extends DepinBootstrapRequest {
|
|
222
|
+
network: string;
|
|
223
|
+
pool_pubkey: string;
|
|
224
|
+
pool_root: string;
|
|
225
|
+
instance_id: string;
|
|
226
|
+
membership_revision: string;
|
|
227
|
+
token: string;
|
|
228
|
+
address: string;
|
|
229
|
+
challenge: string;
|
|
230
|
+
args: Record<string, unknown>;
|
|
231
|
+
signature: string;
|
|
232
|
+
}
|
|
233
|
+
type DepinRpcParams = [DepinBootstrapRequest | DepinRpcRequest] | {
|
|
234
|
+
request: DepinBootstrapRequest | DepinRpcRequest;
|
|
235
|
+
};
|
|
236
|
+
interface DepinRpcResponse {
|
|
237
|
+
protocol: 5;
|
|
238
|
+
network: string;
|
|
239
|
+
pool_pubkey: string;
|
|
240
|
+
pool_root: string;
|
|
241
|
+
instance_id: string;
|
|
242
|
+
membership_revision: string;
|
|
243
|
+
membership_height: number;
|
|
244
|
+
membership_blockhash: string;
|
|
245
|
+
request_hash: string;
|
|
246
|
+
body_kind: 0 | 1;
|
|
247
|
+
body?: string;
|
|
248
|
+
encrypted?: string;
|
|
249
|
+
poolsig: string;
|
|
250
|
+
}
|
|
251
|
+
declare function isDepinRemoteMethod(method: string): method is DepinRemoteMethod;
|
|
252
|
+
/** Keep every signed byte intact. The node performs canonical validation. */
|
|
253
|
+
declare function getDepinRequest(params: unknown): DepinBootstrapRequest | DepinRpcRequest;
|
|
254
|
+
type RpcNode = {
|
|
255
|
+
rpc: (method: string, params: any) => Promise<any>;
|
|
256
|
+
};
|
|
257
|
+
/** Route signed requests to their exact pool/instance, with no request rewriting.
|
|
258
|
+
* Discovery is advisory routing metadata; the client verifies the final reply.
|
|
259
|
+
* No private request is broadcast and no write is retried by this router.
|
|
260
|
+
*/
|
|
261
|
+
declare function createDepinNodeRouter<T extends RpcNode>(healthyNodes: () => T[], randomId: () => string): (method: string, params: unknown) => Promise<T>;
|
|
262
|
+
|
|
263
|
+
/** Detect duplicate JSON property names, including equal values and escaped names.
|
|
264
|
+
* Syntax and numeric decoding are delegated to the JSON parser afterwards.
|
|
265
|
+
*/
|
|
266
|
+
declare function assertNoDuplicateJsonKeys(text: string): void;
|
|
267
|
+
|
|
268
|
+
declare const MAINNET_GENESIS_HASH = "00000044d33c0c0ba019be5c0249730424a69cb4c222153322f68c6104484806";
|
|
269
|
+
declare const TESTNET_GENESIS_HASH = "0000008b384aeffecdab182575dc4e86c9f07f90318c65088532660ed9a8a021";
|
|
270
|
+
/** Reject an RPC endpoint that serves a different chain with the same network label. */
|
|
271
|
+
declare function assertRpcGenesis(rpc: (method: string, params: any[]) => Promise<unknown>, expectedGenesisHash: string): Promise<void>;
|
|
204
272
|
/** Exact decimal parameter, emitted as a JSON number rather than a quoted string. */
|
|
205
273
|
declare function rpcNumber(value: string): LosslessNumber;
|
|
206
274
|
/** Preserve unsafe JSON numeric tokens as strings; retain safe number compatibility. */
|
|
207
275
|
declare function parseRpcJson(text: string): any;
|
|
208
276
|
declare function stringifyRpcJson(value: unknown): string;
|
|
209
|
-
declare function getRPC(username: string, password: string, URL: string): (method: string, params: any[]) => Promise<unknown>;
|
|
277
|
+
declare function getRPC(username: string, password: string, URL: string): (method: string, params: any[] | Record<string, unknown>) => Promise<unknown>;
|
|
210
278
|
|
|
211
|
-
export { getRPC, methods, parseRpcJson, rpcNumber, stringifyRpcJson };
|
|
279
|
+
export { DEPIN_REMOTE_METHODS, DEPIN_RPC_PROTOCOL, type DepinBootstrapRequest, type DepinRemoteMethod, type DepinRpcParams, type DepinRpcRequest, type DepinRpcResponse, type DepinSequenceCursor, MAINNET_GENESIS_HASH, TESTNET_GENESIS_HASH, assertNoDuplicateJsonKeys, assertRpcGenesis, createDepinNodeRouter, getDepinRequest, getRPC, isDepinRemoteMethod, methods, parseRpcJson, rpcNumber, stringifyRpcJson };
|