@olane/o-core 0.1.1 → 0.1.3
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/dist/core/core.node.js +33 -49
- package/dist/core/defaults/config.js +5 -11
- package/dist/core/defaults/index.d.ts +1 -1
- package/dist/core/defaults/index.d.ts.map +1 -1
- package/dist/core/defaults/index.js +1 -17
- package/dist/core/graceful-shutdown.d.ts +25 -0
- package/dist/core/graceful-shutdown.d.ts.map +1 -0
- package/dist/core/graceful-shutdown.js +84 -0
- package/dist/core/index.d.ts +10 -9
- package/dist/core/index.d.ts.map +1 -1
- package/dist/core/index.js +10 -25
- package/dist/core/interfaces/connection-manager.config.js +1 -2
- package/dist/core/interfaces/connection-send-params.interface.js +1 -2
- package/dist/core/interfaces/core-config.interface.js +1 -2
- package/dist/core/interfaces/index.d.ts +5 -5
- package/dist/core/interfaces/index.d.ts.map +1 -1
- package/dist/core/interfaces/index.js +5 -21
- package/dist/core/interfaces/node-type.enum.js +2 -5
- package/dist/core/interfaces/restricted-addresses.enum.js +11 -14
- package/dist/core/interfaces/state.enum.js +2 -5
- package/dist/core/interfaces/use-options.interface.js +1 -2
- package/dist/core/lib/index.d.ts +7 -7
- package/dist/core/lib/index.d.ts.map +1 -1
- package/dist/core/lib/index.js +7 -23
- package/dist/core/lib/o-address-resolution.js +6 -8
- package/dist/core/lib/o-address-resolver.js +5 -12
- package/dist/core/lib/o-connection-manager.js +4 -10
- package/dist/core/lib/o-connection.js +16 -26
- package/dist/core/lib/o-request.js +3 -11
- package/dist/core/lib/o-response.js +3 -10
- package/dist/core/lib/resolvers/anything.resolver.js +4 -8
- package/dist/core/lib/resolvers/index.d.ts +4 -4
- package/dist/core/lib/resolvers/index.d.ts.map +1 -1
- package/dist/core/lib/resolvers/index.js +4 -20
- package/dist/core/lib/resolvers/method.resolver.js +4 -8
- package/dist/core/lib/resolvers/next-hop.resolver.js +9 -13
- package/dist/core/lib/resolvers/storage.resolver.js +2 -6
- package/dist/core/o-address.d.ts +1 -1
- package/dist/core/o-address.d.ts.map +1 -1
- package/dist/core/o-address.js +5 -11
- package/dist/core/o-dependency.js +1 -7
- package/dist/core/o-parameter.js +1 -10
- package/dist/core/utils/core.utils.d.ts +1 -1
- package/dist/core/utils/core.utils.d.ts.map +1 -1
- package/dist/core/utils/core.utils.js +17 -54
- package/dist/core/utils/index.d.ts +3 -3
- package/dist/core/utils/index.d.ts.map +1 -1
- package/dist/core/utils/index.js +3 -19
- package/dist/core/utils/logger.js +9 -18
- package/dist/core/utils/network.utils.js +2 -6
- package/dist/error/enums/codes.error.js +2 -5
- package/dist/error/index.d.ts +2 -2
- package/dist/error/index.d.ts.map +1 -1
- package/dist/error/index.js +2 -18
- package/dist/error/tool.error.js +3 -8
- package/dist/index.d.ts +6 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -22
- package/dist/node/index.d.ts +3 -3
- package/dist/node/index.d.ts.map +1 -1
- package/dist/node/index.js +3 -19
- package/dist/node/lib/local-search.lib.js +1 -5
- package/dist/node/lib/network-activity.lib.js +3 -9
- package/dist/node/node.js +42 -44
- package/dist/node-host/host.node.js +5 -9
- package/dist/node-host/index.d.ts +1 -1
- package/dist/node-host/index.d.ts.map +1 -1
- package/dist/node-host/index.js +1 -17
- package/dist/node-virtual/index.d.ts +1 -1
- package/dist/node-virtual/index.d.ts.map +1 -1
- package/dist/node-virtual/index.js +1 -17
- package/dist/node-virtual/virtual.node.js +4 -8
- package/dist/plan/agent.plan.js +13 -17
- package/dist/plan/configure/configure.plan.js +6 -10
- package/dist/plan/error/error.plan.js +6 -11
- package/dist/plan/index.d.ts +4 -4
- package/dist/plan/index.d.ts.map +1 -1
- package/dist/plan/index.js +4 -20
- package/dist/plan/interfaces/plan-config.interface.js +1 -2
- package/dist/plan/interfaces/plan-result.interface.js +1 -2
- package/dist/plan/interfaces/plan-type.enum.js +2 -5
- package/dist/plan/interfaces/plan.result.js +1 -2
- package/dist/plan/interfaces/query.config.js +1 -2
- package/dist/plan/interfaces/task.config.js +1 -2
- package/dist/plan/o-plan.d.ts +1 -1
- package/dist/plan/o-plan.d.ts.map +1 -1
- package/dist/plan/o-plan.js +19 -60
- package/dist/plan/plan.context.js +2 -6
- package/dist/plan/prompts/agent.prompt.js +2 -6
- package/dist/plan/prompts/configure.prompt.js +2 -6
- package/dist/plan/prompts/custom.prompt.js +1 -5
- package/dist/plan/prompts/error.prompt.js +1 -5
- package/dist/plan/prompts/search.prompt.js +1 -5
- package/dist/plan/search/prompts/search-analysis.prompt.js +1 -5
- package/dist/plan/search/search.plan.js +4 -10
- package/dist/plan/use/index.js +1 -17
- package/dist/plan/use/use.plan.js +9 -13
- package/package.json +6 -5
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const __1 = require("../");
|
|
5
|
-
const o_address_1 = require("../o-address");
|
|
6
|
-
class oAddressResolver {
|
|
7
|
-
address;
|
|
8
|
-
p2pNode;
|
|
9
|
-
logger;
|
|
1
|
+
import { Logger } from '../';
|
|
2
|
+
import { oAddress } from '../o-address';
|
|
3
|
+
export class oAddressResolver {
|
|
10
4
|
constructor(address, p2pNode) {
|
|
11
5
|
this.address = address;
|
|
12
6
|
this.p2pNode = p2pNode;
|
|
13
|
-
this.logger = new
|
|
7
|
+
this.logger = new Logger(this.constructor.name);
|
|
14
8
|
}
|
|
15
9
|
get transports() {
|
|
16
10
|
return [];
|
|
@@ -33,11 +27,10 @@ class oAddressResolver {
|
|
|
33
27
|
? targetAddress.protocol
|
|
34
28
|
: targetAddress.protocol.replace(this.address.protocol + '/', '');
|
|
35
29
|
const nextHop = remainingPath.replace('/o/', '').split('/').reverse().pop();
|
|
36
|
-
const nextHopAddress = new
|
|
30
|
+
const nextHopAddress = new oAddress(prefix + nextHop);
|
|
37
31
|
return nextHopAddress;
|
|
38
32
|
}
|
|
39
33
|
async resolve(address, node) {
|
|
40
34
|
return address;
|
|
41
35
|
}
|
|
42
36
|
}
|
|
43
|
-
exports.oAddressResolver = oAddressResolver;
|
|
@@ -1,12 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.oConnectionManager = void 0;
|
|
4
|
-
const o_connection_1 = require("./o-connection");
|
|
5
|
-
class oConnectionManager {
|
|
6
|
-
cache = new Map();
|
|
7
|
-
logger;
|
|
8
|
-
p2pNode;
|
|
1
|
+
import { oConnection } from './o-connection';
|
|
2
|
+
export class oConnectionManager {
|
|
9
3
|
constructor(config) {
|
|
4
|
+
this.cache = new Map();
|
|
10
5
|
this.logger = config.logger;
|
|
11
6
|
this.p2pNode = config.p2pNode;
|
|
12
7
|
}
|
|
@@ -34,7 +29,7 @@ class oConnectionManager {
|
|
|
34
29
|
// first time setup connection
|
|
35
30
|
try {
|
|
36
31
|
const p2pConnection = await this.p2pNode.dial(nextHopAddress.libp2pTransports);
|
|
37
|
-
const connection = new
|
|
32
|
+
const connection = new oConnection({
|
|
38
33
|
nextHopAddress: nextHopAddress,
|
|
39
34
|
address: address,
|
|
40
35
|
p2pConnection: p2pConnection,
|
|
@@ -68,4 +63,3 @@ class oConnectionManager {
|
|
|
68
63
|
return null;
|
|
69
64
|
}
|
|
70
65
|
}
|
|
71
|
-
exports.oConnectionManager = oConnectionManager;
|
|
@@ -1,26 +1,17 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
const o_protocol_1 = require("@olane/o-protocol");
|
|
9
|
-
const o_response_1 = require("./o-response");
|
|
10
|
-
class oConnection {
|
|
11
|
-
config;
|
|
12
|
-
id;
|
|
13
|
-
logger;
|
|
14
|
-
p2pConnection;
|
|
15
|
-
address;
|
|
16
|
-
nextHopAddress;
|
|
17
|
-
requestCounter = 0;
|
|
1
|
+
import { Uint8ArrayList, pushable, all } from '@olane/o-config';
|
|
2
|
+
import { Logger } from '../utils/logger';
|
|
3
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
4
|
+
import { oRequest } from './o-request';
|
|
5
|
+
import { oProtocolMethods } from '@olane/o-protocol';
|
|
6
|
+
import { oResponse } from './o-response';
|
|
7
|
+
export class oConnection {
|
|
18
8
|
constructor(config) {
|
|
19
9
|
this.config = config;
|
|
20
|
-
this.
|
|
10
|
+
this.requestCounter = 0;
|
|
11
|
+
this.id = uuidv4();
|
|
21
12
|
this.address = config.address;
|
|
22
13
|
this.nextHopAddress = config.nextHopAddress;
|
|
23
|
-
this.logger = new
|
|
14
|
+
this.logger = new Logger('Connection:[' +
|
|
24
15
|
(config.callerAddress?.value || 'unknown') +
|
|
25
16
|
']-->[' +
|
|
26
17
|
this.address.value +
|
|
@@ -29,8 +20,8 @@ class oConnection {
|
|
|
29
20
|
this.p2pConnection = config.p2pConnection;
|
|
30
21
|
}
|
|
31
22
|
async read(source) {
|
|
32
|
-
const chunks = await
|
|
33
|
-
const data = new
|
|
23
|
+
const chunks = await all(source);
|
|
24
|
+
const data = new Uint8ArrayList(...chunks).slice();
|
|
34
25
|
if (!data || data.length === 0) {
|
|
35
26
|
throw new Error('No data received');
|
|
36
27
|
}
|
|
@@ -43,7 +34,7 @@ class oConnection {
|
|
|
43
34
|
// do nothing
|
|
44
35
|
}
|
|
45
36
|
createRequest(method, params) {
|
|
46
|
-
return new
|
|
37
|
+
return new oRequest({
|
|
47
38
|
method: method,
|
|
48
39
|
params: {
|
|
49
40
|
_connectionId: this.id,
|
|
@@ -68,21 +59,21 @@ class oConnection {
|
|
|
68
59
|
async transmit(request) {
|
|
69
60
|
const stream = await this.p2pConnection.newStream(this.nextHopAddress.protocol);
|
|
70
61
|
// Create a pushable stream
|
|
71
|
-
const pushableStream =
|
|
62
|
+
const pushableStream = pushable();
|
|
72
63
|
pushableStream.push(new TextEncoder().encode(request.toString()));
|
|
73
64
|
pushableStream.end();
|
|
74
65
|
// Send the data
|
|
75
66
|
await stream.sink(pushableStream);
|
|
76
67
|
const res = await this.read(stream.source);
|
|
77
68
|
// process the response
|
|
78
|
-
const response = new
|
|
69
|
+
const response = new oResponse({
|
|
79
70
|
...res.result,
|
|
80
71
|
});
|
|
81
72
|
return response;
|
|
82
73
|
}
|
|
83
74
|
async send(data) {
|
|
84
75
|
// proxy through the router tool
|
|
85
|
-
const request = this.createRequest(
|
|
76
|
+
const request = this.createRequest(oProtocolMethods.ROUTE, data);
|
|
86
77
|
return this.transmit(request);
|
|
87
78
|
}
|
|
88
79
|
async close() {
|
|
@@ -91,4 +82,3 @@ class oConnection {
|
|
|
91
82
|
this.logger.debug('Connection closed');
|
|
92
83
|
}
|
|
93
84
|
}
|
|
94
|
-
exports.oConnection = oConnection;
|
|
@@ -1,14 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.oRequest = void 0;
|
|
4
|
-
const o_protocol_1 = require("@olane/o-protocol");
|
|
5
|
-
class oRequest {
|
|
6
|
-
jsonrpc;
|
|
7
|
-
method;
|
|
8
|
-
params;
|
|
9
|
-
id;
|
|
1
|
+
import { JSONRPC_VERSION, } from '@olane/o-protocol';
|
|
2
|
+
export class oRequest {
|
|
10
3
|
constructor(config) {
|
|
11
|
-
this.jsonrpc =
|
|
4
|
+
this.jsonrpc = JSONRPC_VERSION;
|
|
12
5
|
this.method = config.method;
|
|
13
6
|
this.params = config.params;
|
|
14
7
|
this.id = config.id;
|
|
@@ -31,4 +24,3 @@ class oRequest {
|
|
|
31
24
|
return new oRequest(json);
|
|
32
25
|
}
|
|
33
26
|
}
|
|
34
|
-
exports.oRequest = oRequest;
|
|
@@ -1,13 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
exports.oResponse = void 0;
|
|
4
|
-
const o_protocol_1 = require("@olane/o-protocol");
|
|
5
|
-
class oResponse {
|
|
6
|
-
jsonrpc;
|
|
7
|
-
id;
|
|
8
|
-
result;
|
|
1
|
+
import { JSONRPC_VERSION, } from '@olane/o-protocol';
|
|
2
|
+
export class oResponse {
|
|
9
3
|
constructor(config) {
|
|
10
|
-
this.jsonrpc =
|
|
4
|
+
this.jsonrpc = JSONRPC_VERSION;
|
|
11
5
|
this.id = config.id;
|
|
12
6
|
this.result = config;
|
|
13
7
|
}
|
|
@@ -22,4 +16,3 @@ class oResponse {
|
|
|
22
16
|
return JSON.stringify(this);
|
|
23
17
|
}
|
|
24
18
|
}
|
|
25
|
-
exports.oResponse = oResponse;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const o_address_1 = require("../../o-address");
|
|
5
|
-
const o_address_resolver_1 = require("../o-address-resolver");
|
|
6
|
-
class oAnythingResolver extends o_address_resolver_1.oAddressResolver {
|
|
1
|
+
import { oAddress } from '../../o-address';
|
|
2
|
+
import { oAddressResolver } from '../o-address-resolver';
|
|
3
|
+
export class oAnythingResolver extends oAddressResolver {
|
|
7
4
|
get transports() {
|
|
8
5
|
return ['/anything'];
|
|
9
6
|
}
|
|
@@ -12,7 +9,6 @@ class oAnythingResolver extends o_address_resolver_1.oAddressResolver {
|
|
|
12
9
|
// at this point, the next-hop resolver did not work so we can trust that the
|
|
13
10
|
// next hop should be contained within the current node as an abstraction
|
|
14
11
|
this.logger.debug('Resolving anything address: ', address);
|
|
15
|
-
return new
|
|
12
|
+
return new oAddress(nextHopAddress.toString(), (address.transports || []).concat(this.transports));
|
|
16
13
|
}
|
|
17
14
|
}
|
|
18
|
-
exports.oAnythingResolver = oAnythingResolver;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './anything.resolver';
|
|
2
|
-
export * from './method.resolver';
|
|
3
|
-
export * from './next-hop.resolver';
|
|
4
|
-
export * from './storage.resolver';
|
|
1
|
+
export * from './anything.resolver.js';
|
|
2
|
+
export * from './method.resolver.js';
|
|
3
|
+
export * from './next-hop.resolver.js';
|
|
4
|
+
export * from './storage.resolver.js';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/lib/resolvers/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../src/core/lib/resolvers/index.ts"],"names":[],"mappings":"AAAA,cAAc,wBAAwB,CAAC;AACvC,cAAc,sBAAsB,CAAC;AACrC,cAAc,wBAAwB,CAAC;AACvC,cAAc,uBAAuB,CAAC"}
|
|
@@ -1,20 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./anything.resolver"), exports);
|
|
18
|
-
__exportStar(require("./method.resolver"), exports);
|
|
19
|
-
__exportStar(require("./next-hop.resolver"), exports);
|
|
20
|
-
__exportStar(require("./storage.resolver"), exports);
|
|
1
|
+
export * from './anything.resolver.js';
|
|
2
|
+
export * from './method.resolver.js';
|
|
3
|
+
export * from './next-hop.resolver.js';
|
|
4
|
+
export * from './storage.resolver.js';
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const o_address_1 = require("../../o-address");
|
|
5
|
-
const anything_resolver_1 = require("./anything.resolver");
|
|
6
|
-
class oMethodResolver extends anything_resolver_1.oAnythingResolver {
|
|
1
|
+
import { oAddress } from '../../o-address';
|
|
2
|
+
import { oAnythingResolver } from './anything.resolver';
|
|
3
|
+
export class oMethodResolver extends oAnythingResolver {
|
|
7
4
|
static get transports() {
|
|
8
5
|
return ['/method'];
|
|
9
6
|
}
|
|
@@ -13,10 +10,9 @@ class oMethodResolver extends anything_resolver_1.oAnythingResolver {
|
|
|
13
10
|
if (method) {
|
|
14
11
|
const methodName = node.myTools()[method];
|
|
15
12
|
if (methodName) {
|
|
16
|
-
return new
|
|
13
|
+
return new oAddress(nextHopAddress.toString(), oMethodResolver.transports);
|
|
17
14
|
}
|
|
18
15
|
}
|
|
19
16
|
return address;
|
|
20
17
|
}
|
|
21
18
|
}
|
|
22
|
-
exports.oMethodResolver = oMethodResolver;
|
|
@@ -1,16 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
const o_address_resolver_1 = require("../o-address-resolver");
|
|
7
|
-
const utils_1 = require("../../utils");
|
|
8
|
-
class NextHopResolver extends o_address_resolver_1.oAddressResolver {
|
|
1
|
+
import { multiaddr } from '@olane/o-config';
|
|
2
|
+
import { oAddress } from '../../o-address';
|
|
3
|
+
import { oAddressResolver } from '../o-address-resolver';
|
|
4
|
+
import { NetworkUtils } from '../../utils';
|
|
5
|
+
export class NextHopResolver extends oAddressResolver {
|
|
9
6
|
// when we use the network to find the next hop, we need to make sure we are just searching for child addresses
|
|
10
7
|
async resolveAddressToTransports(address) {
|
|
11
8
|
try {
|
|
12
9
|
this.logger.debug('Finding node for address: ', address.toString());
|
|
13
|
-
const { transports } = await
|
|
10
|
+
const { transports } = await NetworkUtils.findNode(this.p2pNode, address);
|
|
14
11
|
this.logger.debug('Found node for address: ', address.toString());
|
|
15
12
|
return transports;
|
|
16
13
|
}
|
|
@@ -34,24 +31,23 @@ class NextHopResolver extends o_address_resolver_1.oAddressResolver {
|
|
|
34
31
|
if (!peer) {
|
|
35
32
|
return [];
|
|
36
33
|
}
|
|
37
|
-
return peer.addresses.map((a) =>
|
|
34
|
+
return peer.addresses.map((a) => multiaddr(a.multiaddr + '/p2p/' + peer.id.toString()));
|
|
38
35
|
}
|
|
39
36
|
async findNextHop(targetAddress) {
|
|
40
37
|
// check to see if we are at the destination
|
|
41
38
|
if (targetAddress.protocol === this.address.protocol) {
|
|
42
39
|
const transports = await this.findProviderTransports(targetAddress);
|
|
43
|
-
return new
|
|
40
|
+
return new oAddress(targetAddress.value, transports.map((t) => multiaddr(t)));
|
|
44
41
|
}
|
|
45
42
|
const nextHopAddress = this.determineNextHopAddress(targetAddress);
|
|
46
43
|
const transports = await this.findProviderTransports(nextHopAddress);
|
|
47
44
|
if (!transports.length) {
|
|
48
45
|
this.logger.warn('No transports found for next hop: ' + nextHopAddress.toString());
|
|
49
46
|
}
|
|
50
|
-
return new
|
|
47
|
+
return new oAddress(nextHopAddress.toString(), transports);
|
|
51
48
|
}
|
|
52
49
|
async resolve(address) {
|
|
53
50
|
// return this.findNextHop(address);
|
|
54
51
|
return this.findNextHop(address);
|
|
55
52
|
}
|
|
56
53
|
}
|
|
57
|
-
exports.NextHopResolver = NextHopResolver;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.StorageResolver = void 0;
|
|
4
|
-
const anything_resolver_1 = require("./anything.resolver");
|
|
1
|
+
import { oAnythingResolver } from './anything.resolver';
|
|
5
2
|
const storageTransports = ['/store'];
|
|
6
|
-
class StorageResolver extends
|
|
3
|
+
export class StorageResolver extends oAnythingResolver {
|
|
7
4
|
get transports() {
|
|
8
5
|
return storageTransports;
|
|
9
6
|
}
|
|
@@ -11,4 +8,3 @@ class StorageResolver extends anything_resolver_1.oAnythingResolver {
|
|
|
11
8
|
return storageTransports;
|
|
12
9
|
}
|
|
13
10
|
}
|
|
14
|
-
exports.StorageResolver = StorageResolver;
|
package/dist/core/o-address.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"o-address.d.ts","sourceRoot":"","sources":["../../src/core/o-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"o-address.d.ts","sourceRoot":"","sources":["../../src/core/o-address.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAa,MAAM,iBAAiB,CAAC;AACvD,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAGnC,qBAAa,QAAQ;aAED,KAAK,EAAE,MAAM;IACtB,UAAU,EAAE,KAAK,CAAC,SAAS,GAAG,MAAM,CAAC;gBAD5B,KAAK,EAAE,MAAM,EACtB,UAAU,GAAE,KAAK,CAAC,SAAS,GAAG,MAAM,CAAM;IAGnD,aAAa,CAAC,UAAU,EAAE,SAAS,EAAE,GAAG,IAAI;IAI5C,IAAI,gBAAgB,IAAI,SAAS,EAAE,CAElC;IAED,IAAI,gBAAgB,IAAI,MAAM,EAAE,CAE/B;IAED,QAAQ,IAAI,OAAO;IAOnB,IAAI,KAAK,IAAI,MAAM,CAElB;IAED,IAAI,QAAQ,IAAI,MAAM,CAErB;IAED,IAAI,IAAI,IAAI,MAAM,CAEjB;IAED,QAAQ,IAAI,MAAM;IAIlB,WAAW,IAAI,SAAS;IAIxB,MAAM,CAAC,aAAa,CAAC,EAAE,EAAE,SAAS,GAAG,QAAQ;IAI7C,MAAM,CAAC,MAAM,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO;IAI1C,KAAK,IAAI,OAAO,CAAC,GAAG,CAAC;CAG5B"}
|
package/dist/core/o-address.js
CHANGED
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
const o_config_1 = require("@olane/o-config");
|
|
5
|
-
const core_utils_1 = require("./utils/core.utils");
|
|
6
|
-
class oAddress {
|
|
7
|
-
value;
|
|
8
|
-
transports;
|
|
1
|
+
import { multiaddr } from '@olane/o-config';
|
|
2
|
+
import { CoreUtils } from './utils/core.utils';
|
|
3
|
+
export class oAddress {
|
|
9
4
|
constructor(value, transports = []) {
|
|
10
5
|
this.value = value;
|
|
11
6
|
this.transports = transports;
|
|
@@ -38,7 +33,7 @@ class oAddress {
|
|
|
38
33
|
return this.value;
|
|
39
34
|
}
|
|
40
35
|
toMultiaddr() {
|
|
41
|
-
return
|
|
36
|
+
return multiaddr(this.protocol);
|
|
42
37
|
}
|
|
43
38
|
static fromMultiaddr(ma) {
|
|
44
39
|
return new oAddress(ma.toString().replace('/o/', 'o://'));
|
|
@@ -47,7 +42,6 @@ class oAddress {
|
|
|
47
42
|
return a.value === b.value;
|
|
48
43
|
}
|
|
49
44
|
async toCID() {
|
|
50
|
-
return await
|
|
45
|
+
return await CoreUtils.toCID({ address: this.toString() });
|
|
51
46
|
}
|
|
52
47
|
}
|
|
53
|
-
exports.oAddress = oAddress;
|
|
@@ -1,9 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.oDependency = void 0;
|
|
4
|
-
class oDependency {
|
|
5
|
-
address;
|
|
6
|
-
version;
|
|
1
|
+
export class oDependency {
|
|
7
2
|
constructor(config) {
|
|
8
3
|
this.address = config.address;
|
|
9
4
|
this.version = config.version;
|
|
@@ -18,4 +13,3 @@ class oDependency {
|
|
|
18
13
|
return JSON.stringify(this.toJSON());
|
|
19
14
|
}
|
|
20
15
|
}
|
|
21
|
-
exports.oDependency = oDependency;
|
package/dist/core/o-parameter.js
CHANGED
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.oParameter = void 0;
|
|
4
|
-
class oParameter {
|
|
5
|
-
name;
|
|
6
|
-
type;
|
|
7
|
-
value;
|
|
8
|
-
description;
|
|
9
|
-
required;
|
|
1
|
+
export class oParameter {
|
|
10
2
|
constructor(config) {
|
|
11
3
|
this.name = config.name;
|
|
12
4
|
this.type = config.type;
|
|
@@ -27,4 +19,3 @@ class oParameter {
|
|
|
27
19
|
return JSON.stringify(this.toJSON());
|
|
28
20
|
}
|
|
29
21
|
}
|
|
30
|
-
exports.oParameter = oParameter;
|
|
@@ -2,7 +2,7 @@ import { Stream } from '@olane/o-config';
|
|
|
2
2
|
import { oAddress } from '../o-address';
|
|
3
3
|
import { oResponse } from '../lib/o-response';
|
|
4
4
|
import { oRequest } from '../lib/o-request';
|
|
5
|
-
import { CID } from 'multiformats
|
|
5
|
+
import { CID } from 'multiformats';
|
|
6
6
|
export declare class CoreUtils {
|
|
7
7
|
static generatePeerId(): Promise<any>;
|
|
8
8
|
static generatePrivateKey(seed: string): Promise<any>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"core.utils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/core.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAGP,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,
|
|
1
|
+
{"version":3,"file":"core.utils.d.ts","sourceRoot":"","sources":["../../../src/core/utils/core.utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAGL,MAAM,EAGP,MAAM,iBAAiB,CAAC;AAEzB,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,QAAQ,EAAE,MAAM,kBAAkB,CAAC;AAC5C,OAAO,EAAE,GAAG,EAAE,MAAM,cAAc,CAAC;AAInC,qBAAa,SAAS;WACP,cAAc,IAAI,OAAO,CAAC,GAAG,CAAC;WAK9B,kBAAkB,CAAC,IAAI,EAAE,MAAM,GAAG,OAAO,CAAC,GAAG,CAAC;WAQ7C,YAAY,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;WAOpC,YAAY,CACxB,aAAa,EAAE,QAAQ,EACvB,YAAY,EAAE,QAAQ,GACrB,QAAQ;WAIS,YAAY,CAAC,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM;WAWhD,aAAa,CAAC,MAAM,EAAE,GAAG,GAAG,OAAO,CAAC,QAAQ,CAAC;WAc7C,KAAK,CAAC,IAAI,EAAE,GAAG,GAAG,OAAO,CAAC,GAAG,CAAC;CAMnD"}
|
|
@@ -1,71 +1,35 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
-
var ownKeys = function(o) {
|
|
20
|
-
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
-
var ar = [];
|
|
22
|
-
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
-
return ar;
|
|
24
|
-
};
|
|
25
|
-
return ownKeys(o);
|
|
26
|
-
};
|
|
27
|
-
return function (mod) {
|
|
28
|
-
if (mod && mod.__esModule) return mod;
|
|
29
|
-
var result = {};
|
|
30
|
-
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
-
__setModuleDefault(result, mod);
|
|
32
|
-
return result;
|
|
33
|
-
};
|
|
34
|
-
})();
|
|
35
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
-
exports.CoreUtils = void 0;
|
|
37
|
-
const o_config_1 = require("@olane/o-config");
|
|
38
|
-
const crypto_1 = require("crypto");
|
|
39
|
-
const o_address_1 = require("../o-address");
|
|
40
|
-
const o_request_1 = require("../lib/o-request");
|
|
41
|
-
const cid_1 = require("multiformats/cid");
|
|
42
|
-
const json = __importStar(require("multiformats/codecs/json"));
|
|
43
|
-
const sha2_1 = require("multiformats/hashes/sha2");
|
|
44
|
-
class CoreUtils {
|
|
1
|
+
import { generateKeyPairFromSeed, createEd25519PeerId, Uint8ArrayList, pushable, } from '@olane/o-config';
|
|
2
|
+
import { createHash } from 'crypto';
|
|
3
|
+
import { oAddress } from '../o-address';
|
|
4
|
+
import { oRequest } from '../lib/o-request';
|
|
5
|
+
import { CID } from 'multiformats';
|
|
6
|
+
import * as json from 'multiformats/codecs/json';
|
|
7
|
+
import { sha256 } from 'multiformats/hashes/sha2';
|
|
8
|
+
export class CoreUtils {
|
|
45
9
|
static async generatePeerId() {
|
|
46
|
-
const peerId = await
|
|
10
|
+
const peerId = await createEd25519PeerId();
|
|
47
11
|
return peerId;
|
|
48
12
|
}
|
|
49
13
|
static async generatePrivateKey(seed) {
|
|
50
14
|
const seedBytes = new TextEncoder().encode(seed);
|
|
51
|
-
const privateKey = await
|
|
15
|
+
const privateKey = await generateKeyPairFromSeed('Ed25519', seedBytes);
|
|
52
16
|
return privateKey;
|
|
53
17
|
}
|
|
54
18
|
// Utility function to convert any phrase into a 32-character string
|
|
55
19
|
static phraseToSeed(phrase) {
|
|
56
20
|
// Use SHA-256 to create a consistent 32-byte hash
|
|
57
|
-
const hash =
|
|
21
|
+
const hash = createHash('sha256').update(phrase).digest('hex');
|
|
58
22
|
// Take the first 32 characters of the hex string
|
|
59
23
|
return hash.substring(0, 32);
|
|
60
24
|
}
|
|
61
25
|
static childAddress(parentAddress, childAddress) {
|
|
62
|
-
return new
|
|
26
|
+
return new oAddress(parentAddress.toString() + '/' + childAddress.paths);
|
|
63
27
|
}
|
|
64
28
|
static async sendResponse(response, stream) {
|
|
65
29
|
if (stream.status !== 'open') {
|
|
66
30
|
return;
|
|
67
31
|
}
|
|
68
|
-
const responseStream =
|
|
32
|
+
const responseStream = pushable();
|
|
69
33
|
responseStream.push(new TextEncoder().encode(response.toString()));
|
|
70
34
|
responseStream.end();
|
|
71
35
|
return await stream.sink(responseStream);
|
|
@@ -75,17 +39,16 @@ class CoreUtils {
|
|
|
75
39
|
for await (const chunk of stream.source) {
|
|
76
40
|
chunks.push(chunk.subarray());
|
|
77
41
|
}
|
|
78
|
-
const data = new
|
|
42
|
+
const data = new Uint8ArrayList(...chunks).slice();
|
|
79
43
|
if (!data || data.length === 0) {
|
|
80
44
|
throw new Error('No data received');
|
|
81
45
|
}
|
|
82
|
-
return new
|
|
46
|
+
return new oRequest(JSON.parse(new TextDecoder().decode(data)));
|
|
83
47
|
}
|
|
84
48
|
static async toCID(data) {
|
|
85
49
|
const bytes = json.encode(data);
|
|
86
|
-
const hash = await
|
|
87
|
-
const cid =
|
|
50
|
+
const hash = await sha256.digest(bytes);
|
|
51
|
+
const cid = CID.create(1, json.code, hash);
|
|
88
52
|
return cid;
|
|
89
53
|
}
|
|
90
54
|
}
|
|
91
|
-
exports.CoreUtils = CoreUtils;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export * from './core.utils';
|
|
2
|
-
export * from './logger';
|
|
3
|
-
export * from './network.utils';
|
|
1
|
+
export * from './core.utils.js';
|
|
2
|
+
export * from './logger.js';
|
|
3
|
+
export * from './network.utils.js';
|
|
4
4
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/core/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,aAAa,CAAC;AAC5B,cAAc,oBAAoB,CAAC"}
|
package/dist/core/utils/index.js
CHANGED
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
-
};
|
|
16
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
-
__exportStar(require("./core.utils"), exports);
|
|
18
|
-
__exportStar(require("./logger"), exports);
|
|
19
|
-
__exportStar(require("./network.utils"), exports);
|
|
1
|
+
export * from './core.utils.js';
|
|
2
|
+
export * from './logger.js';
|
|
3
|
+
export * from './network.utils.js';
|
|
@@ -1,32 +1,23 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.Logger = void 0;
|
|
7
|
-
const debug_1 = __importDefault(require("debug"));
|
|
8
|
-
const chalk_1 = __importDefault(require("chalk"));
|
|
9
|
-
class Logger {
|
|
10
|
-
name;
|
|
11
|
-
log;
|
|
1
|
+
import debug from 'debug';
|
|
2
|
+
import chalk from 'chalk';
|
|
3
|
+
export class Logger {
|
|
12
4
|
constructor(name) {
|
|
13
5
|
this.name = name;
|
|
14
|
-
this.log = (
|
|
6
|
+
this.log = debug('o-protocol:' + name);
|
|
15
7
|
}
|
|
16
8
|
debug(...args) {
|
|
17
|
-
this.log(
|
|
9
|
+
this.log(chalk.blue('[DEBUG]'), ...args);
|
|
18
10
|
}
|
|
19
11
|
info(...args) {
|
|
20
|
-
this.log(
|
|
12
|
+
this.log(chalk.green('[INFO]'), ...args);
|
|
21
13
|
}
|
|
22
14
|
warn(...args) {
|
|
23
|
-
this.log(
|
|
15
|
+
this.log(chalk.yellow('[WARN]'), ...args);
|
|
24
16
|
}
|
|
25
17
|
error(...args) {
|
|
26
|
-
this.log(
|
|
18
|
+
this.log(chalk.red('[ERROR]'), ...args);
|
|
27
19
|
}
|
|
28
20
|
alert(...args) {
|
|
29
|
-
this.log(
|
|
21
|
+
this.log(chalk.redBright('[ALERT]'), ...args);
|
|
30
22
|
}
|
|
31
23
|
}
|
|
32
|
-
exports.Logger = Logger;
|