@origintrail-official/dkg-core 0.0.1-dev.1773506972.23bf9c0
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 +201 -0
- package/README.md +33 -0
- package/dist/constants.d.ts +25 -0
- package/dist/constants.d.ts.map +1 -0
- package/dist/constants.js +57 -0
- package/dist/constants.js.map +1 -0
- package/dist/crypto/canonicalize.d.ts +12 -0
- package/dist/crypto/canonicalize.d.ts.map +1 -0
- package/dist/crypto/canonicalize.js +43 -0
- package/dist/crypto/canonicalize.js.map +1 -0
- package/dist/crypto/ed25519.d.ts +9 -0
- package/dist/crypto/ed25519.d.ts.map +1 -0
- package/dist/crypto/ed25519.js +14 -0
- package/dist/crypto/ed25519.js.map +1 -0
- package/dist/crypto/hashing.d.ts +2 -0
- package/dist/crypto/hashing.d.ts.map +1 -0
- package/dist/crypto/hashing.js +5 -0
- package/dist/crypto/hashing.js.map +1 -0
- package/dist/crypto/index.d.ts +6 -0
- package/dist/crypto/index.d.ts.map +1 -0
- package/dist/crypto/index.js +6 -0
- package/dist/crypto/index.js.map +1 -0
- package/dist/crypto/merkle.d.ts +19 -0
- package/dist/crypto/merkle.d.ts.map +1 -0
- package/dist/crypto/merkle.js +103 -0
- package/dist/crypto/merkle.js.map +1 -0
- package/dist/crypto/oracle-verify.d.ts +45 -0
- package/dist/crypto/oracle-verify.d.ts.map +1 -0
- package/dist/crypto/oracle-verify.js +76 -0
- package/dist/crypto/oracle-verify.js.map +1 -0
- package/dist/discovery.d.ts +23 -0
- package/dist/discovery.d.ts.map +1 -0
- package/dist/discovery.js +61 -0
- package/dist/discovery.js.map +1 -0
- package/dist/event-bus.d.ts +38 -0
- package/dist/event-bus.d.ts.map +1 -0
- package/dist/event-bus.js +75 -0
- package/dist/event-bus.js.map +1 -0
- package/dist/genesis.d.ts +51 -0
- package/dist/genesis.d.ts.map +1 -0
- package/dist/genesis.js +159 -0
- package/dist/genesis.js.map +1 -0
- package/dist/gossipsub-manager.d.ts +17 -0
- package/dist/gossipsub-manager.d.ts.map +1 -0
- package/dist/gossipsub-manager.js +69 -0
- package/dist/gossipsub-manager.js.map +1 -0
- package/dist/index.d.ts +14 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +14 -0
- package/dist/index.js.map +1 -0
- package/dist/logger.d.ts +35 -0
- package/dist/logger.d.ts.map +1 -0
- package/dist/logger.js +48 -0
- package/dist/logger.js.map +1 -0
- package/dist/node.d.ts +47 -0
- package/dist/node.d.ts.map +1 -0
- package/dist/node.js +307 -0
- package/dist/node.js.map +1 -0
- package/dist/proto/access.d.ts +22 -0
- package/dist/proto/access.d.ts.map +1 -0
- package/dist/proto/access.js +26 -0
- package/dist/proto/access.js.map +1 -0
- package/dist/proto/discover.d.ts +19 -0
- package/dist/proto/discover.d.ts.map +1 -0
- package/dist/proto/discover.js +24 -0
- package/dist/proto/discover.js.map +1 -0
- package/dist/proto/finalization.d.ts +28 -0
- package/dist/proto/finalization.d.ts.map +1 -0
- package/dist/proto/finalization.js +42 -0
- package/dist/proto/finalization.js.map +1 -0
- package/dist/proto/index.d.ts +9 -0
- package/dist/proto/index.d.ts.map +1 -0
- package/dist/proto/index.js +9 -0
- package/dist/proto/index.js.map +1 -0
- package/dist/proto/ka-update.d.ts +27 -0
- package/dist/proto/ka-update.d.ts.map +1 -0
- package/dist/proto/ka-update.js +55 -0
- package/dist/proto/ka-update.js.map +1 -0
- package/dist/proto/message.d.ts +21 -0
- package/dist/proto/message.d.ts.map +1 -0
- package/dist/proto/message.js +18 -0
- package/dist/proto/message.js.map +1 -0
- package/dist/proto/publish.d.ts +50 -0
- package/dist/proto/publish.d.ts.map +1 -0
- package/dist/proto/publish.js +44 -0
- package/dist/proto/publish.js.map +1 -0
- package/dist/proto/query.d.ts +27 -0
- package/dist/proto/query.d.ts.map +1 -0
- package/dist/proto/query.js +32 -0
- package/dist/proto/query.js.map +1 -0
- package/dist/proto/workspace.d.ts +34 -0
- package/dist/proto/workspace.d.ts.map +1 -0
- package/dist/proto/workspace.js +37 -0
- package/dist/proto/workspace.js.map +1 -0
- package/dist/protocol-router.d.ts +23 -0
- package/dist/protocol-router.d.ts.map +1 -0
- package/dist/protocol-router.js +127 -0
- package/dist/protocol-router.js.map +1 -0
- package/dist/rate-limiter.d.ts +33 -0
- package/dist/rate-limiter.d.ts.map +1 -0
- package/dist/rate-limiter.js +80 -0
- package/dist/rate-limiter.js.map +1 -0
- package/dist/retry.d.ts +21 -0
- package/dist/retry.d.ts.map +1 -0
- package/dist/retry.js +42 -0
- package/dist/retry.js.map +1 -0
- package/dist/sparql-safe.d.ts +59 -0
- package/dist/sparql-safe.d.ts.map +1 -0
- package/dist/sparql-safe.js +118 -0
- package/dist/sparql-safe.js.map +1 -0
- package/dist/types.d.ts +57 -0
- package/dist/types.d.ts.map +1 -0
- package/dist/types.js +2 -0
- package/dist/types.js.map +1 -0
- package/package.json +57 -0
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { DKGEvent } from './event-bus.js';
|
|
2
|
+
import { withRetry } from './retry.js';
|
|
3
|
+
export class GossipSubManager {
|
|
4
|
+
node;
|
|
5
|
+
eventBus;
|
|
6
|
+
topicHandlers = new Map();
|
|
7
|
+
constructor(node, eventBus) {
|
|
8
|
+
this.node = node;
|
|
9
|
+
this.eventBus = eventBus;
|
|
10
|
+
this.setupListener();
|
|
11
|
+
}
|
|
12
|
+
setupListener() {
|
|
13
|
+
const pubsub = this.node.libp2p.services.pubsub;
|
|
14
|
+
pubsub.addEventListener('message', (evt) => {
|
|
15
|
+
const msg = evt.detail;
|
|
16
|
+
const topic = msg.topic;
|
|
17
|
+
const data = msg.data instanceof Uint8Array ? msg.data : new Uint8Array(0);
|
|
18
|
+
const from = 'from' in msg ? String(msg.from) : 'unknown';
|
|
19
|
+
this.eventBus.emit(DKGEvent.GOSSIP_MESSAGE, { topic, data, from });
|
|
20
|
+
const handlers = this.topicHandlers.get(topic);
|
|
21
|
+
if (handlers) {
|
|
22
|
+
for (const handler of handlers) {
|
|
23
|
+
try {
|
|
24
|
+
handler(topic, data, from);
|
|
25
|
+
}
|
|
26
|
+
catch (err) {
|
|
27
|
+
console.error(`[GossipSub] handler error on topic "${topic}":`, err instanceof Error ? err.message : err);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
subscribe(topic) {
|
|
34
|
+
this.node.libp2p.services.pubsub.subscribe(topic);
|
|
35
|
+
}
|
|
36
|
+
unsubscribe(topic) {
|
|
37
|
+
this.node.libp2p.services.pubsub.unsubscribe(topic);
|
|
38
|
+
this.topicHandlers.delete(topic);
|
|
39
|
+
}
|
|
40
|
+
async publish(topic, data) {
|
|
41
|
+
await withRetry(() => this.node.libp2p.services.pubsub.publish(topic, data), {
|
|
42
|
+
maxAttempts: 3,
|
|
43
|
+
baseDelayMs: 500,
|
|
44
|
+
onRetry: (attempt, delay) => {
|
|
45
|
+
console.warn(`[GossipSub] publish retry ${attempt}/3 on topic "${topic}" (delay ${Math.round(delay)}ms)`);
|
|
46
|
+
},
|
|
47
|
+
});
|
|
48
|
+
}
|
|
49
|
+
onMessage(topic, handler) {
|
|
50
|
+
let handlers = this.topicHandlers.get(topic);
|
|
51
|
+
if (!handlers) {
|
|
52
|
+
handlers = new Set();
|
|
53
|
+
this.topicHandlers.set(topic, handlers);
|
|
54
|
+
}
|
|
55
|
+
handlers.add(handler);
|
|
56
|
+
}
|
|
57
|
+
offMessage(topic, handler) {
|
|
58
|
+
const handlers = this.topicHandlers.get(topic);
|
|
59
|
+
if (!handlers)
|
|
60
|
+
return;
|
|
61
|
+
handlers.delete(handler);
|
|
62
|
+
if (handlers.size === 0)
|
|
63
|
+
this.topicHandlers.delete(topic);
|
|
64
|
+
}
|
|
65
|
+
get subscribedTopics() {
|
|
66
|
+
return this.node.libp2p.services.pubsub.getTopics();
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
//# sourceMappingURL=g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a,EAAE,OAA6B;QACpD,IAAI,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ,EAAE,CAAC;YACd,QAAQ,GAAG,IAAI,GAAG,EAAE,CAAC;YACrB,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,EAAE,QAAQ,CAAC,CAAC;QAC1C,CAAC;QACD,QAAQ,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;IACxB,CAAC;IAED,UAAU,CAAC,KAAa,EAAE,OAA6B;QACrD,MAAM,QAAQ,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,KAAK,CAAC,CAAC;QAC/C,IAAI,CAAC,QAAQ;YAAE,OAAO;QACtB,QAAQ,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;QACzB,IAAI,QAAQ,CAAC,IAAI,KAAK,CAAC;YAAE,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;IAC5D,CAAC;IAED,IAAI,gBAAgB;QAClB,OAAO,IAAI,CAAC,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC;IACtD,CAAC;CACF"}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './constants.js';
|
|
3
|
+
export * from './event-bus.js';
|
|
4
|
+
export { Logger, createOperationContext, type OperationContext, type OperationName, type LogSink } from './logger.js';
|
|
5
|
+
export * from './crypto/index.js';
|
|
6
|
+
export * from './proto/index.js';
|
|
7
|
+
export { DKGNode } from './node.js';
|
|
8
|
+
export { ProtocolRouter, DEFAULT_MAX_READ_BYTES } from './protocol-router.js';
|
|
9
|
+
export { GossipSubManager, type GossipMessageHandler } from './gossipsub-manager.js';
|
|
10
|
+
export { PeerDiscoveryManager } from './discovery.js';
|
|
11
|
+
export { getGenesisQuads, computeNetworkId, getGenesisRaw, SYSTEM_PARANETS, DKG_ONTOLOGY, type GenesisQuad, } from './genesis.js';
|
|
12
|
+
export { withRetry, type RetryOptions } from './retry.js';
|
|
13
|
+
export { assertSafeIri, isSafeIri, sparqlIri, escapeSparqlLiteral, sparqlString, sparqlInt, assertSafeRdfTerm, } from './sparql-safe.js';
|
|
14
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAAE,KAAK,gBAAgB,EAAE,KAAK,aAAa,EAAE,KAAK,OAAO,EAAE,MAAM,aAAa,CAAC;AACtH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAAE,KAAK,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,YAAY,EACZ,KAAK,WAAW,GACjB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAE,KAAK,YAAY,EAAE,MAAM,YAAY,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,iBAAiB,GAClB,MAAM,kBAAkB,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export * from './types.js';
|
|
2
|
+
export * from './constants.js';
|
|
3
|
+
export * from './event-bus.js';
|
|
4
|
+
export { Logger, createOperationContext } from './logger.js';
|
|
5
|
+
export * from './crypto/index.js';
|
|
6
|
+
export * from './proto/index.js';
|
|
7
|
+
export { DKGNode } from './node.js';
|
|
8
|
+
export { ProtocolRouter, DEFAULT_MAX_READ_BYTES } from './protocol-router.js';
|
|
9
|
+
export { GossipSubManager } from './gossipsub-manager.js';
|
|
10
|
+
export { PeerDiscoveryManager } from './discovery.js';
|
|
11
|
+
export { getGenesisQuads, computeNetworkId, getGenesisRaw, SYSTEM_PARANETS, DKG_ONTOLOGY, } from './genesis.js';
|
|
12
|
+
export { withRetry } from './retry.js';
|
|
13
|
+
export { assertSafeIri, isSafeIri, sparqlIri, escapeSparqlLiteral, sparqlString, sparqlInt, assertSafeRdfTerm, } from './sparql-safe.js';
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,YAAY,CAAC;AAC3B,cAAc,gBAAgB,CAAC;AAC/B,cAAc,gBAAgB,CAAC;AAC/B,OAAO,EAAE,MAAM,EAAE,sBAAsB,EAA2D,MAAM,aAAa,CAAC;AACtH,cAAc,mBAAmB,CAAC;AAClC,cAAc,kBAAkB,CAAC;AACjC,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACpC,OAAO,EAAE,cAAc,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAC;AAC9E,OAAO,EAAE,gBAAgB,EAA6B,MAAM,wBAAwB,CAAC;AACrF,OAAO,EAAE,oBAAoB,EAAE,MAAM,gBAAgB,CAAC;AACtD,OAAO,EACL,eAAe,EACf,gBAAgB,EAChB,aAAa,EACb,eAAe,EACf,YAAY,GAEb,MAAM,cAAc,CAAC;AACtB,OAAO,EAAE,SAAS,EAAqB,MAAM,YAAY,CAAC;AAC1D,OAAO,EACL,aAAa,EACb,SAAS,EACT,SAAS,EACT,mBAAmB,EACnB,YAAY,EACZ,SAAS,EACT,iBAAiB,GAClB,MAAM,kBAAkB,CAAC"}
|
package/dist/logger.d.ts
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
export type OperationName = 'publish' | 'update' | 'query' | 'resolve' | 'connect' | 'sync' | 'system' | 'workspace' | 'enshrine' | 'gossip' | 'ka-update' | 'reconstruct' | 'init';
|
|
2
|
+
export interface OperationContext {
|
|
3
|
+
operationId: string;
|
|
4
|
+
operationName: OperationName;
|
|
5
|
+
/** The originating node's operation ID, present when this operation was triggered by a remote message. */
|
|
6
|
+
sourceOperationId?: string;
|
|
7
|
+
}
|
|
8
|
+
export type LogSink = (entry: {
|
|
9
|
+
level: string;
|
|
10
|
+
operationName: string;
|
|
11
|
+
operationId: string;
|
|
12
|
+
sourceOperationId?: string;
|
|
13
|
+
module: string;
|
|
14
|
+
message: string;
|
|
15
|
+
}) => void;
|
|
16
|
+
/**
|
|
17
|
+
* Structured logger that prefixes every message with a timestamp,
|
|
18
|
+
* operation name, and operation ID for cross-node log correlation.
|
|
19
|
+
*
|
|
20
|
+
* Format: YYYY-MM-DD HH:MM:SS <operationName> <operationId> "<message>"
|
|
21
|
+
*/
|
|
22
|
+
export declare class Logger {
|
|
23
|
+
private readonly moduleName;
|
|
24
|
+
private static sink;
|
|
25
|
+
private readonly prefix;
|
|
26
|
+
static setSink(sink: LogSink | null): void;
|
|
27
|
+
constructor(moduleName: string);
|
|
28
|
+
debug(ctx: OperationContext, message: string): void;
|
|
29
|
+
info(ctx: OperationContext, message: string): void;
|
|
30
|
+
warn(ctx: OperationContext, message: string): void;
|
|
31
|
+
error(ctx: OperationContext, message: string): void;
|
|
32
|
+
private format;
|
|
33
|
+
}
|
|
34
|
+
export declare function createOperationContext(operationName: OperationName, sourceOperationId?: string): OperationContext;
|
|
35
|
+
//# sourceMappingURL=logger.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRo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UD,wBAAgB,sBAAsB,CAAC,aAAa,EAAE,aAAa,EAAE,iBAAiB,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAEjH"}
|
package/dist/logger.js
ADDED
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
import { randomUUID } from 'node:crypto';
|
|
2
|
+
/**
|
|
3
|
+
* Structured logger that prefixes every message with a timestamp,
|
|
4
|
+
* operation name, and operation ID for cross-node log correlation.
|
|
5
|
+
*
|
|
6
|
+
* Format: YYYY-MM-DD HH:MM:SS <operationName> <operationId> "<message>"
|
|
7
|
+
*/
|
|
8
|
+
export class Logger {
|
|
9
|
+
moduleName;
|
|
10
|
+
static sink = null;
|
|
11
|
+
prefix;
|
|
12
|
+
static setSink(sink) {
|
|
13
|
+
Logger.sink = sink;
|
|
14
|
+
}
|
|
15
|
+
constructor(moduleName) {
|
|
16
|
+
this.moduleName = moduleName;
|
|
17
|
+
this.prefix = moduleName;
|
|
18
|
+
}
|
|
19
|
+
debug(ctx, message) {
|
|
20
|
+
Logger.sink?.({ level: 'debug', operationName: ctx.operationName, operationId: ctx.operationId, sourceOperationId: ctx.sourceOperationId, module: this.moduleName, message });
|
|
21
|
+
}
|
|
22
|
+
info(ctx, message) {
|
|
23
|
+
process.stdout.write(`${this.format(ctx, message)}\n`);
|
|
24
|
+
Logger.sink?.({ level: 'info', operationName: ctx.operationName, operationId: ctx.operationId, sourceOperationId: ctx.sourceOperationId, module: this.moduleName, message });
|
|
25
|
+
}
|
|
26
|
+
warn(ctx, message) {
|
|
27
|
+
process.stderr.write(`${this.format(ctx, message)} [WARN]\n`);
|
|
28
|
+
Logger.sink?.({ level: 'warn', operationName: ctx.operationName, operationId: ctx.operationId, sourceOperationId: ctx.sourceOperationId, module: this.moduleName, message });
|
|
29
|
+
}
|
|
30
|
+
error(ctx, message) {
|
|
31
|
+
process.stderr.write(`${this.format(ctx, message)} [ERROR]\n`);
|
|
32
|
+
Logger.sink?.({ level: 'error', operationName: ctx.operationName, operationId: ctx.operationId, sourceOperationId: ctx.sourceOperationId, module: this.moduleName, message });
|
|
33
|
+
}
|
|
34
|
+
format(ctx, message) {
|
|
35
|
+
const ts = formatTimestamp(new Date());
|
|
36
|
+
const src = ctx.sourceOperationId ? ` [from:${ctx.sourceOperationId}]` : '';
|
|
37
|
+
return `${ts} ${ctx.operationName} ${ctx.operationId}${src} [${this.prefix}] ${message}`;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
function formatTimestamp(d) {
|
|
41
|
+
const pad = (n) => String(n).padStart(2, '0');
|
|
42
|
+
return (`${d.getFullYear()}-${pad(d.getMonth() + 1)}-${pad(d.getDate())} ` +
|
|
43
|
+
`${pad(d.getHours())}:${pad(d.getMinutes())}:${pad(d.getSeconds())}`);
|
|
44
|
+
}
|
|
45
|
+
export function createOperationContext(operationName, sourceOperationId) {
|
|
46
|
+
return { operationId: randomUUID(), operationName, sourceOperationId };
|
|
47
|
+
}
|
|
48
|
+
//# sourceMappingURL=logger.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"logger.js","sourceRoot":"","sources":["../src/logger.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAoBzC;;;;;GAKG;AACH,MAAM,OAAO,MAAM;IAQY;IAPrB,MAAM,CAAC,IAAI,GAAmB,IAAI,CAAC;IAC1B,MAAM,CAAS;IAEhC,MAAM,CAAC,OAAO,CAAC,IAAoB;QACjC,MAAM,CAAC,IAAI,GAAG,IAAI,CAAC;IACrB,CAAC;IAED,YAA6B,UAAkB;QAAlB,eAAU,GAAV,UAAU,CAAQ;QAC7C,IAAI,CAAC,MAAM,GAAG,UAAU,CAAC;IAC3B,CAAC;IAED,KAAK,CAAC,GAAqB,EAAE,OAAe;QAC1C,MAAM,CAAC,IAAI,EAAE,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,aAAa,EAAE,GAAG,CAAC,aAAa,EAAE,WAAW,EAAE,GAAG,CAAC,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DHT } from '@libp2p/kad-dht';
|
|
3
|
+
import { type GossipSub } from '@libp2p/gossipsub';
|
|
4
|
+
import { type Ping } from '@libp2p/ping';
|
|
5
|
+
import type { DKGNodeConfig } from './types.js';
|
|
6
|
+
export interface DKGServices extends Record<string, unknown> {
|
|
7
|
+
dht: KadDHT;
|
|
8
|
+
pubsub: GossipSub;
|
|
9
|
+
identify: unknown;
|
|
10
|
+
ping: Ping;
|
|
11
|
+
dcutr: unknown;
|
|
12
|
+
autoNAT?: unknown;
|
|
13
|
+
relay?: unknown;
|
|
14
|
+
}
|
|
15
|
+
export declare class DKGNode {
|
|
16
|
+
private node;
|
|
17
|
+
private readonly config;
|
|
18
|
+
/** Peers currently connected only via relay (candidates for DCUtR upgrade). */
|
|
19
|
+
private readonly relayedPeers;
|
|
20
|
+
private relayWatchdogTimer;
|
|
21
|
+
private relayTargets;
|
|
22
|
+
private relayWatchdogConsecutiveFailures;
|
|
23
|
+
constructor(config?: DKGNodeConfig);
|
|
24
|
+
start(): Promise<void>;
|
|
25
|
+
/**
|
|
26
|
+
* Periodically check that relay connections are alive. After a network
|
|
27
|
+
* outage (e.g. laptop sleep/wake) TCP sockets die silently and libp2p
|
|
28
|
+
* won't automatically redial. Uses exponential backoff when the relay is
|
|
29
|
+
* unreachable and resets to the base interval on successful reconnect.
|
|
30
|
+
*/
|
|
31
|
+
private startRelayWatchdog;
|
|
32
|
+
private scheduleWatchdogTick;
|
|
33
|
+
private watchdogTick;
|
|
34
|
+
/**
|
|
35
|
+
* Wire up connection:open / connection:close listeners that track transport
|
|
36
|
+
* type (direct vs relayed) and detect DCUtR upgrades from relay to direct.
|
|
37
|
+
*/
|
|
38
|
+
private setupConnectionObservability;
|
|
39
|
+
stop(): Promise<void>;
|
|
40
|
+
get peerId(): string;
|
|
41
|
+
get peerIdBytes(): Uint8Array;
|
|
42
|
+
get multiaddrs(): string[];
|
|
43
|
+
get libp2p(): Libp2p<DKGServices>;
|
|
44
|
+
get isStarted(): boolean;
|
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AAI,CAAC;IAa3B,IAAI,MAAM,IAAI,MAAM,CAEnB;IAED,IAAI,WAAW,IAAI,UAAU,CAE5B;IAED,IAAI,UAAU,IAAI,MAAM,EAAE,CAIzB;IAED,IAAI,MAAM,IAAI,MAAM,CAAC,WAAW,CAAC,CAEhC;IAED,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,OAAO,CAAC,WAAW;CAIpB"}
|
package/dist/node.js
ADDED
|
@@ -0,0 +1,307 @@
|
|
|
1
|
+
import { createLibp2p } from 'libp2p';
|
|
2
|
+
import { tcp } from '@libp2p/tcp';
|
|
3
|
+
import { webSockets } from '@libp2p/websockets';
|
|
4
|
+
import { noise } from '@libp2p/noise';
|
|
5
|
+
import { yamux } from '@libp2p/yamux';
|
|
6
|
+
import { bootstrap } from '@libp2p/bootstrap';
|
|
7
|
+
import { kadDHT } from '@libp2p/kad-dht';
|
|
8
|
+
import { gossipsub } from '@libp2p/gossipsub';
|
|
9
|
+
import { mdns } from '@libp2p/mdns';
|
|
10
|
+
import { identify } from '@libp2p/identify';
|
|
11
|
+
import { ping } from '@libp2p/ping';
|
|
12
|
+
import { circuitRelayTransport } from '@libp2p/circuit-relay-v2';
|
|
13
|
+
import { circuitRelayServer } from '@libp2p/circuit-relay-v2';
|
|
14
|
+
import { dcutr } from '@libp2p/dcutr';
|
|
15
|
+
import { autoNAT } from '@libp2p/autonat';
|
|
16
|
+
import { generateKeyPair, privateKeyFromRaw } from '@libp2p/crypto/keys';
|
|
17
|
+
import { peerIdFromString } from '@libp2p/peer-id';
|
|
18
|
+
import { ed25519GetPublicKey } from './crypto/ed25519.js';
|
|
19
|
+
import { DHT_PROTOCOL } from './constants.js';
|
|
20
|
+
const RELAY_WATCHDOG_BASE_INTERVAL_MS = 10_000;
|
|
21
|
+
const RELAY_WATCHDOG_MAX_INTERVAL_MS = 5 * 60_000;
|
|
22
|
+
/** Short delay before redialing a disconnected relay to avoid hammering (ms). */
|
|
23
|
+
const RELAY_REDIAL_DELAY_MS = 1_500;
|
|
24
|
+
export class DKGNode {
|
|
25
|
+
node = null;
|
|
26
|
+
config;
|
|
27
|
+
/** Peers currently connected only via relay (candidates for DCUtR upgrade). */
|
|
28
|
+
relayedPeers = new Set();
|
|
29
|
+
relayWatchdogTimer = null;
|
|
30
|
+
relayTargets = [];
|
|
31
|
+
relayWatchdogConsecutiveFailures = 0;
|
|
32
|
+
constructor(config = {}) {
|
|
33
|
+
this.config = config;
|
|
34
|
+
}
|
|
35
|
+
async start() {
|
|
36
|
+
if (this.node)
|
|
37
|
+
return;
|
|
38
|
+
let privateKey;
|
|
39
|
+
if (this.config.privateKey) {
|
|
40
|
+
// privateKeyFromRaw needs 64 bytes for Ed25519: seed(32) + publicKey(32)
|
|
41
|
+
const seed = this.config.privateKey;
|
|
42
|
+
const pub = await ed25519GetPublicKey(seed);
|
|
43
|
+
const raw64 = new Uint8Array(64);
|
|
44
|
+
raw64.set(seed, 0);
|
|
45
|
+
raw64.set(pub, 32);
|
|
46
|
+
privateKey = privateKeyFromRaw(raw64);
|
|
47
|
+
}
|
|
48
|
+
else {
|
|
49
|
+
privateKey = await generateKeyPair('Ed25519');
|
|
50
|
+
}
|
|
51
|
+
const peerDiscovery = [];
|
|
52
|
+
if (this.config.bootstrapPeers && this.config.bootstrapPeers.length > 0) {
|
|
53
|
+
peerDiscovery.push(bootstrap({ list: this.config.bootstrapPeers }));
|
|
54
|
+
}
|
|
55
|
+
if (this.config.enableMdns !== false) {
|
|
56
|
+
peerDiscovery.push(mdns());
|
|
57
|
+
}
|
|
58
|
+
// TCP keepAlive helps prevent idle relay connections from being dropped by
|
|
59
|
+
// middleboxes or remote timeouts (common cause of ECONNRESET).
|
|
60
|
+
const transports = [
|
|
61
|
+
tcp({ dialOpts: { keepAlive: true } }),
|
|
62
|
+
webSockets(),
|
|
63
|
+
circuitRelayTransport(),
|
|
64
|
+
];
|
|
65
|
+
const isCore = this.config.nodeRole === 'core';
|
|
66
|
+
const enableRelay = this.config.enableRelayServer ?? isCore;
|
|
67
|
+
// Nodes that already know their NAT status skip autoNAT probing:
|
|
68
|
+
// - relayPeers set → agent behind NAT (knows it needs relay)
|
|
69
|
+
// - enableRelayServer/core → public node acting as relay
|
|
70
|
+
const useAutoNAT = this.config.enableAutoNAT ??
|
|
71
|
+
!(this.config.relayPeers?.length || enableRelay);
|
|
72
|
+
const services = {
|
|
73
|
+
identify: identify(),
|
|
74
|
+
ping: ping(),
|
|
75
|
+
dht: kadDHT({ protocol: DHT_PROTOCOL }),
|
|
76
|
+
pubsub: gossipsub({
|
|
77
|
+
emitSelf: false,
|
|
78
|
+
allowPublishToZeroTopicPeers: true,
|
|
79
|
+
floodPublish: true,
|
|
80
|
+
D: 4,
|
|
81
|
+
Dlo: 2,
|
|
82
|
+
Dhi: 8,
|
|
83
|
+
}),
|
|
84
|
+
dcutr: dcutr(),
|
|
85
|
+
};
|
|
86
|
+
if (useAutoNAT) {
|
|
87
|
+
services.autoNAT = autoNAT();
|
|
88
|
+
}
|
|
89
|
+
if (enableRelay) {
|
|
90
|
+
services.relay = circuitRelayServer({
|
|
91
|
+
reservations: {
|
|
92
|
+
maxReservations: 256,
|
|
93
|
+
defaultDurationLimit: 5 * 60 * 1000,
|
|
94
|
+
defaultDataLimit: BigInt(1 << 24),
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
const listenAddrs = [
|
|
99
|
+
...(this.config.listenAddresses ?? [
|
|
100
|
+
'/ip4/0.0.0.0/tcp/0',
|
|
101
|
+
'/ip4/0.0.0.0/tcp/0/ws',
|
|
102
|
+
]),
|
|
103
|
+
];
|
|
104
|
+
// When relay peers are configured, listen on circuit addresses to ensure
|
|
105
|
+
// the node requests a reservation and becomes reachable through relays.
|
|
106
|
+
if (this.config.relayPeers?.length) {
|
|
107
|
+
listenAddrs.push('/p2p-circuit');
|
|
108
|
+
}
|
|
109
|
+
this.node = await createLibp2p({
|
|
110
|
+
privateKey,
|
|
111
|
+
addresses: {
|
|
112
|
+
listen: listenAddrs,
|
|
113
|
+
...(this.config.announceAddresses?.length
|
|
114
|
+
? { announce: this.config.announceAddresses }
|
|
115
|
+
: {}),
|
|
116
|
+
},
|
|
117
|
+
transports: transports,
|
|
118
|
+
connectionEncrypters: [noise()],
|
|
119
|
+
streamMuxers: [yamux()],
|
|
120
|
+
peerDiscovery,
|
|
121
|
+
services,
|
|
122
|
+
connectionManager: {
|
|
123
|
+
minConnections: 0,
|
|
124
|
+
// Reserve capacity for relay peers so they are not evicted under load.
|
|
125
|
+
maxConnections: 500,
|
|
126
|
+
},
|
|
127
|
+
});
|
|
128
|
+
this.setupConnectionObservability();
|
|
129
|
+
// Connect to relay peers and tag them as keep-alive so libp2p's
|
|
130
|
+
// connection manager maintains the connection and auto-redials.
|
|
131
|
+
if (this.config.relayPeers?.length) {
|
|
132
|
+
const { multiaddr } = await import('@multiformats/multiaddr');
|
|
133
|
+
for (const addr of this.config.relayPeers) {
|
|
134
|
+
const ma = multiaddr(addr);
|
|
135
|
+
const p2pComponent = ma.getComponents().find(c => c.name === 'p2p');
|
|
136
|
+
if (!p2pComponent?.value)
|
|
137
|
+
continue;
|
|
138
|
+
const peerId = peerIdFromString(p2pComponent.value);
|
|
139
|
+
if (peerId.equals(this.node.peerId))
|
|
140
|
+
continue;
|
|
141
|
+
this.relayTargets.push({ peerId, addr: ma });
|
|
142
|
+
await this.node.peerStore.merge(peerId, {
|
|
143
|
+
multiaddrs: [ma],
|
|
144
|
+
tags: {
|
|
145
|
+
'keep-alive-dkg-relay': { value: 100 },
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
try {
|
|
149
|
+
await this.node.dial(ma);
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
// watchdog will retry
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
this.startRelayWatchdog();
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Periodically check that relay connections are alive. After a network
|
|
160
|
+
* outage (e.g. laptop sleep/wake) TCP sockets die silently and libp2p
|
|
161
|
+
* won't automatically redial. Uses exponential backoff when the relay is
|
|
162
|
+
* unreachable and resets to the base interval on successful reconnect.
|
|
163
|
+
*/
|
|
164
|
+
startRelayWatchdog() {
|
|
165
|
+
if (this.relayWatchdogTimer)
|
|
166
|
+
return;
|
|
167
|
+
if (this.relayTargets.length === 0)
|
|
168
|
+
return;
|
|
169
|
+
this.scheduleWatchdogTick();
|
|
170
|
+
}
|
|
171
|
+
scheduleWatchdogTick() {
|
|
172
|
+
const delay = Math.min(RELAY_WATCHDOG_BASE_INTERVAL_MS * Math.pow(2, this.relayWatchdogConsecutiveFailures), RELAY_WATCHDOG_MAX_INTERVAL_MS);
|
|
173
|
+
this.relayWatchdogTimer = setTimeout(async () => {
|
|
174
|
+
await this.watchdogTick();
|
|
175
|
+
if (this.node)
|
|
176
|
+
this.scheduleWatchdogTick();
|
|
177
|
+
}, delay);
|
|
178
|
+
if (this.relayWatchdogTimer.unref) {
|
|
179
|
+
this.relayWatchdogTimer.unref();
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
async watchdogTick() {
|
|
183
|
+
const node = this.node;
|
|
184
|
+
if (!node)
|
|
185
|
+
return;
|
|
186
|
+
const ts = () => new Date().toISOString();
|
|
187
|
+
const short = (id) => id.slice(-8);
|
|
188
|
+
let allConnected = true;
|
|
189
|
+
for (const { peerId, addr } of this.relayTargets) {
|
|
190
|
+
if (peerId.equals(node.peerId))
|
|
191
|
+
continue;
|
|
192
|
+
const conns = node.getConnections(peerId);
|
|
193
|
+
if (conns.length > 0)
|
|
194
|
+
continue;
|
|
195
|
+
allConnected = false;
|
|
196
|
+
console.log(`[${ts()}] Relay watchdog: ${short(peerId.toString())} disconnected, redialing…`);
|
|
197
|
+
// Brief delay before redial to avoid hammering the relay after a drop.
|
|
198
|
+
const delayMs = RELAY_REDIAL_DELAY_MS + Math.floor(Math.random() * 1000);
|
|
199
|
+
await new Promise(r => setTimeout(r, delayMs));
|
|
200
|
+
try {
|
|
201
|
+
await node.dial(addr);
|
|
202
|
+
console.log(`[${ts()}] Relay watchdog: reconnected to ${short(peerId.toString())}`);
|
|
203
|
+
}
|
|
204
|
+
catch (err) {
|
|
205
|
+
console.log(`[${ts()}] Relay watchdog: redial failed for ${short(peerId.toString())}: ${err.message}`);
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
if (allConnected) {
|
|
209
|
+
this.relayWatchdogConsecutiveFailures = 0;
|
|
210
|
+
}
|
|
211
|
+
else {
|
|
212
|
+
this.relayWatchdogConsecutiveFailures++;
|
|
213
|
+
const nextDelay = Math.min(RELAY_WATCHDOG_BASE_INTERVAL_MS * Math.pow(2, this.relayWatchdogConsecutiveFailures), RELAY_WATCHDOG_MAX_INTERVAL_MS);
|
|
214
|
+
console.log(`[${ts()}] Relay watchdog: next check in ${Math.round(nextDelay / 1000)}s (attempt ${this.relayWatchdogConsecutiveFailures})`);
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Wire up connection:open / connection:close listeners that track transport
|
|
219
|
+
* type (direct vs relayed) and detect DCUtR upgrades from relay to direct.
|
|
220
|
+
*/
|
|
221
|
+
setupConnectionObservability() {
|
|
222
|
+
const node = this.requireNode();
|
|
223
|
+
const ts = () => new Date().toISOString();
|
|
224
|
+
const short = (id) => id.slice(-8);
|
|
225
|
+
node.addEventListener('connection:open', (evt) => {
|
|
226
|
+
const conn = evt.detail;
|
|
227
|
+
const pid = conn.remotePeer.toString();
|
|
228
|
+
const addr = conn.remoteAddr?.toString() ?? 'unknown';
|
|
229
|
+
const transport = addr.includes('/p2p-circuit') ? 'relayed' : 'direct';
|
|
230
|
+
const dir = conn.direction;
|
|
231
|
+
if (transport === 'relayed') {
|
|
232
|
+
this.relayedPeers.add(pid);
|
|
233
|
+
console.log(`[${ts()}] Connection opened: ${short(pid)} transport=relayed ` +
|
|
234
|
+
`dir=${dir} addr=${addr}`);
|
|
235
|
+
}
|
|
236
|
+
else {
|
|
237
|
+
const upgraded = this.relayedPeers.has(pid);
|
|
238
|
+
if (upgraded) {
|
|
239
|
+
this.relayedPeers.delete(pid);
|
|
240
|
+
console.log(`[${ts()}] DCUtR upgrade: ${short(pid)} relayed -> direct ` +
|
|
241
|
+
`dir=${dir} addr=${addr}`);
|
|
242
|
+
}
|
|
243
|
+
else {
|
|
244
|
+
console.log(`[${ts()}] Connection opened: ${short(pid)} transport=direct ` +
|
|
245
|
+
`dir=${dir} addr=${addr}`);
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
});
|
|
249
|
+
node.addEventListener('connection:close', (evt) => {
|
|
250
|
+
const conn = evt.detail;
|
|
251
|
+
const pid = conn.remotePeer.toString();
|
|
252
|
+
const addr = conn.remoteAddr?.toString() ?? 'unknown';
|
|
253
|
+
const transport = addr.includes('/p2p-circuit') ? 'relayed' : 'direct';
|
|
254
|
+
const durationMs = conn.timeline.close
|
|
255
|
+
? conn.timeline.close - conn.timeline.open
|
|
256
|
+
: '?';
|
|
257
|
+
// If this was the last connection to the peer, clean up tracking state.
|
|
258
|
+
const remaining = node.getConnections(conn.remotePeer);
|
|
259
|
+
if (remaining.length === 0) {
|
|
260
|
+
this.relayedPeers.delete(pid);
|
|
261
|
+
}
|
|
262
|
+
console.log(`[${ts()}] Connection closed: ${short(pid)} transport=${transport} ` +
|
|
263
|
+
`duration=${durationMs}ms addr=${addr}`);
|
|
264
|
+
});
|
|
265
|
+
node.addEventListener('peer:disconnect', (evt) => {
|
|
266
|
+
const pid = evt.detail.toString();
|
|
267
|
+
this.relayedPeers.delete(pid);
|
|
268
|
+
console.log(`[${ts()}] Peer disconnected: ${short(pid)}`);
|
|
269
|
+
});
|
|
270
|
+
}
|
|
271
|
+
async stop() {
|
|
272
|
+
if (!this.node)
|
|
273
|
+
return;
|
|
274
|
+
if (this.relayWatchdogTimer) {
|
|
275
|
+
clearTimeout(this.relayWatchdogTimer);
|
|
276
|
+
this.relayWatchdogTimer = null;
|
|
277
|
+
}
|
|
278
|
+
this.relayTargets = [];
|
|
279
|
+
this.relayWatchdogConsecutiveFailures = 0;
|
|
280
|
+
this.relayedPeers.clear();
|
|
281
|
+
await this.node.stop();
|
|
282
|
+
this.node = null;
|
|
283
|
+
}
|
|
284
|
+
get peerId() {
|
|
285
|
+
return this.requireNode().peerId.toString();
|
|
286
|
+
}
|
|
287
|
+
get peerIdBytes() {
|
|
288
|
+
return this.requireNode().peerId.toMultihash().bytes;
|
|
289
|
+
}
|
|
290
|
+
get multiaddrs() {
|
|
291
|
+
return this.requireNode()
|
|
292
|
+
.getMultiaddrs()
|
|
293
|
+
.map((ma) => ma.toString());
|
|
294
|
+
}
|
|
295
|
+
get libp2p() {
|
|
296
|
+
return this.requireNode();
|
|
297
|
+
}
|
|
298
|
+
get isStarted() {
|
|
299
|
+
return this.node !== null;
|
|
300
|
+
}
|
|
301
|
+
requireNode() {
|
|
302
|
+
if (!this.node)
|
|
303
|
+
throw new Error('DKGNode not started');
|
|
304
|
+
return this.node;
|
|
305
|
+
}
|
|
306
|
+
}
|
|
307
|
+
//# sourceMappingURL=node.js.map
|
package/dist/node.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"node.js","sourceRoot":"","sources":["../src/node.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAe,MAAM,QAAQ,CAAC;AACnD,OAAO,EAAE,GAAG,EAAE,MAAM,aAAa,CAAC;AAClC,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,MAAM,EAAe,MAAM,iBAAiB,CAAC;AACtD,OAAO,EAAE,SAAS,EAAkB,MAAM,mBAAmB,CAAC;AAC9D,OAAO,EAAE,IAAI,EAAE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AI,GAAG,IAAI,CAAC;IACnB,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,QAAQ,EAAE,CAAC;IAC9C,CAAC;IAED,IAAI,WAAW;QACb,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC;IACvD,CAAC;IAED,IAAI,UAAU;QACZ,OAAO,IAAI,CAAC,WAAW,EAAE;aACtB,aAAa,EAAE;aACf,GAAG,CAAC,CAAC,EAAE,EAAE,EAAE,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC,CAAC;IAChC,CAAC;IAED,IAAI,MAAM;QACR,OAAO,IAAI,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,IAAI,KAAK,IAAI,CAAC;IAC5B,CAAC;IAEO,WAAW;QACjB,IAAI,CAAC,IAAI,CAAC,IAAI;YAAE,MAAM,IAAI,KAAK,CAAC,qBAAqB,CAAC,CAAC;QACvD,OAAO,IAAI,CAAC,IAAI,CAAC;IACnB,CAAC;CACF"}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import protobuf from 'protobufjs';
|
|
2
|
+
export declare const AccessRequestSchema: protobuf.Type;
|
|
3
|
+
export declare const AccessResponseSchema: protobuf.Type;
|
|
4
|
+
export interface AccessRequestMsg {
|
|
5
|
+
kaUal: string;
|
|
6
|
+
requesterPeerId: string;
|
|
7
|
+
paymentProof: Uint8Array;
|
|
8
|
+
requesterSignature: Uint8Array;
|
|
9
|
+
/** Ed25519 public key for signature verification. */
|
|
10
|
+
requesterPublicKey?: Uint8Array;
|
|
11
|
+
}
|
|
12
|
+
export interface AccessResponseMsg {
|
|
13
|
+
granted: boolean;
|
|
14
|
+
nquads: Uint8Array;
|
|
15
|
+
privateMerkleRoot: Uint8Array;
|
|
16
|
+
rejectionReason: string;
|
|
17
|
+
}
|
|
18
|
+
export declare function encodeAccessRequest(msg: AccessRequestMsg): Uint8Array;
|
|
19
|
+
export declare function decodeAccessRequest(buf: Uint8Array): AccessRequestMsg;
|
|
20
|
+
export declare function encodeAccessResponse(msg: AccessResponseMsg): Uint8Array;
|
|
21
|
+
export declare function decodeAccessResponse(buf: Uint8Array): AccessResponseMsg;
|
|
22
|
+
//# sourceMappingURL=access.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"access.d.ts","sourceRoot":"","sources":["../../src/proto/access.ts"],"names":[],"mappings":"AAAA,OAAO,QAAQ,MAAM,YAAY,CAAC;AAIlC,eAAO,MAAM,mBAAmB,eAKmB,CAAC;AAEpD,eAAO,MAAM,oBAAoB,eAIgB,CAAC;AAElD,MAAM,WAAW,gBAAgB;IAC/B,KAAK,EAAE,MAAM,CAAC;IACd,eAAe,EAAE,MAAM,CAAC;IACxB,YAAY,EAAE,UAAU,CAAC;IACzB,kBAAkB,EAAE,UAAU,CAAC;IAC/B,qDAAqD;IACrD,kBAAkB,CAAC,EAAE,UAAU,CAAC;CACjC;AAED,MAAM,WAAW,iBAAiB;IAChC,OAAO,EAAE,OAAO,CAAC;IACjB,MAAM,EAAE,UAAU,CAAC;IACnB,iBAAiB,EAAE,UAAU,CAAC;IAC9B,eAAe,EAAE,MAAM,CAAC;CACzB;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,gBAAgB,GAAG,UAAU,CAIrE;AAED,wBAAgB,mBAAmB,CAAC,GAAG,EAAE,UAAU,GAAG,gBAAgB,CAErE;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,iBAAiB,GAAG,UAAU,CAIvE;AAED,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,UAAU,GAAG,iBAAiB,CAEvE"}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import protobuf from 'protobufjs';
|
|
2
|
+
const { Type, Field } = protobuf;
|
|
3
|
+
export const AccessRequestSchema = new Type('AccessRequest')
|
|
4
|
+
.add(new Field('kaUal', 1, 'string'))
|
|
5
|
+
.add(new Field('requesterPeerId', 2, 'string'))
|
|
6
|
+
.add(new Field('paymentProof', 3, 'bytes'))
|
|
7
|
+
.add(new Field('requesterSignature', 4, 'bytes'))
|
|
8
|
+
.add(new Field('requesterPublicKey', 5, 'bytes'));
|
|
9
|
+
export const AccessResponseSchema = new Type('AccessResponse')
|
|
10
|
+
.add(new Field('granted', 1, 'bool'))
|
|
11
|
+
.add(new Field('nquads', 2, 'bytes'))
|
|
12
|
+
.add(new Field('privateMerkleRoot', 3, 'bytes'))
|
|
13
|
+
.add(new Field('rejectionReason', 4, 'string'));
|
|
14
|
+
export function encodeAccessRequest(msg) {
|
|
15
|
+
return AccessRequestSchema.encode(AccessRequestSchema.create(msg)).finish();
|
|
16
|
+
}
|
|
17
|
+
export function decodeAccessRequest(buf) {
|
|
18
|
+
return AccessRequestSchema.decode(buf);
|
|
19
|
+
}
|
|
20
|
+
export function encodeAccessResponse(msg) {
|
|
21
|
+
return AccessResponseSchema.encode(AccessResponseSchema.create(msg)).finish();
|
|
22
|
+
}
|
|
23
|
+
export function decodeAccessResponse(buf) {
|
|
24
|
+
return AccessResponseSchema.decode(buf);
|
|
25
|
+
}
|
|
26
|
+
//# sourceMappingURL=access.js.map
|