dkg.js 6.0.0-beta.2.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.
@@ -0,0 +1,148 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
5
+ <script src="./dist/index.bundle.js"></script>
6
+ <script>
7
+ window.addEventListener('load', async function () {
8
+
9
+ const OT_NODE_HOSTNAME = 'alpha-stella-node-06.origin-trail.network';
10
+ const OT_NODE_PORT = '8900';
11
+
12
+ let options = { endpoint: OT_NODE_HOSTNAME, port: OT_NODE_PORT, useSSL: true, loglevel: 'trace' };
13
+ this.dkg = new SemanticWeb3(options);
14
+
15
+ this.dkg.nodeInfo().then(result => {
16
+ console.log('============ Node info results ===================');
17
+ console.log(JSON.stringify(result, null, 2));
18
+ console.log('===============================');
19
+ });
20
+
21
+ // SET & GET
22
+ // options = {
23
+ // keywords: ['ETHDenver'],
24
+ // visibility: 'public'
25
+ // };
26
+ //
27
+ // const content = {
28
+ // "@context": "https://www.schema.org/",
29
+ // "@type": "ERC721",
30
+ // "asset_data": {
31
+ // "properties": {
32
+ // "prop1": "value1",
33
+ // "prop2": {
34
+ // "abc":"ads",
35
+ // "abs":"adsb"
36
+ // },
37
+ // },
38
+ //
39
+ // "urls": "https://opensea.io/assets/0xbc4ca0eda7647a8ab7c2061c2e118a18a936f13d/8520"
40
+ //
41
+ // },
42
+ // "native_blockchain": "polygon",
43
+ // "onchain_data": {
44
+ // "contract_address": "0x123",
45
+ // "tokenID": "32",
46
+ // "tokenURI": "....",
47
+ // "owner": "0x12345431",
48
+ // "name": "Tracie 101 Updated",
49
+ // "symbol": "TRACIE",
50
+ // "eventHistory": [{
51
+ // "timestamp": "2020-10-12",
52
+ // "from": "0x123",
53
+ // "to": "0x343",
54
+ // "event": "Transfer",
55
+ // },
56
+ // {
57
+ // "timestamp": "2020-09-11",
58
+ // "from": "0x123",
59
+ // "to": "0x343",
60
+ // "event": "Sale",
61
+ // "price": "1.23",
62
+ // "currency": "ETH",
63
+ // }
64
+ //
65
+ // ]
66
+ // },
67
+ // "erc721_metadata": {
68
+ // "title": "Asset Metadata",
69
+ // "type": "object",
70
+ // "properties": {
71
+ // "name": {
72
+ // "type": "string",
73
+ // "description": "Identifies the asset to which this NFT represents"
74
+ // },
75
+ // "description": {
76
+ // "type": "string",
77
+ // "description": "Describes the asset to which this NFT represents"
78
+ // },
79
+ // "image": {
80
+ // "type": "string",
81
+ // "description": "A URI pointing to a resource with mime type image/* representing the asset to which this NFT represents. Consider making any images at a width between 320 and 1080 pixels and aspect ratio between 1.91:1 and 4:5 inclusive."
82
+ // }
83
+ // }
84
+ // },
85
+ // "linkedTo": [
86
+ // "ual1",
87
+ // "ual2",
88
+ // ]
89
+ // }
90
+ // let result = await dkg.assets.create(content,options)
91
+ // let ual = result.data.metadata.UALs[0];
92
+ // console.log(`Created UAL is ${ual}`)
93
+ //
94
+ // let asset = await dkg.assets.get(ual);
95
+ //
96
+ // const proof = await asset.data.proof.valueOf;
97
+ // console.log(`Proof is ${JSON.stringify(proof)}}`)
98
+
99
+ // SEARCH
100
+ // options = { query: 'ETHDenver', resultType: 'assertions' }; //or entities
101
+ // await dkg.search(options).then((result) => {
102
+ // console.log('============ Search results ===================');
103
+ // console.log(JSON.stringify(result, null, 2));
104
+ // console.log('===============================');
105
+ // });
106
+
107
+ // QUERY
108
+
109
+ // retrieve all connected UALs for given UAL
110
+ // ual = 'a44c97e1a27eab0db298f01f1a5d7c9d84caed8c7ce91480acaf92989888fc37';
111
+ // options = {
112
+ // query: `PREFIX schema: <http://schema.org/>
113
+ // construct { ?b2 schema:linkedTo ?linkedAssets }
114
+ // WHERE {
115
+ // GRAPH ?g {
116
+ // ?b1 schema:linkedTo ?linkedAssets .
117
+ // }
118
+ // ?b2 schema:hasUALs '${ual}'
119
+ // FILTER (?g = ?b2)
120
+ // }`
121
+ // };
122
+ //
123
+ // // all states for an asset
124
+ // ual = 'a44c97e1a27eab0db298f01f1a5d7c9d84caed8c7ce91480acaf92989888fc37';
125
+ // options = {
126
+ // query: `PREFIX schema: <http://schema.org/>
127
+ // construct { ?assertionId schema:hasUALs ?assertionId }
128
+ // WHERE {
129
+ // ?assertionId schema:hasUALs '${ual}' .
130
+ // }`
131
+ // };
132
+ //
133
+ // await dkg.query(options).then((result) => {
134
+ // console.log('============ Query results ===================');
135
+ // console.log(JSON.stringify(result, null, 2));
136
+ // console.log('===============================');
137
+ // });
138
+
139
+ });
140
+ </script>
141
+ </head>
142
+ <body>
143
+
144
+ <h1>Hello World!</h1>
145
+
146
+
147
+ </body>
148
+ </html>
package/header.png ADDED
Binary file
package/index.js ADDED
@@ -0,0 +1,12 @@
1
+ const NativeClient = require('./client/native-client')
2
+ const AssetsClient = require('./client/assets-client')
3
+
4
+ class DkgClient extends NativeClient {
5
+ constructor(props) {
6
+ super(props);
7
+
8
+ this.assets = new AssetsClient(props)
9
+ }
10
+
11
+ }
12
+ module.exports = DkgClient;
@@ -0,0 +1,29 @@
1
+ {
2
+ "@context": "https://schema.org/",
3
+ "@type": "Product",
4
+ "name": "Executive Anvil",
5
+ "image": "http://www.example.com/anvil_executive.jpg",
6
+ "description": "Sleeker than ACME's Classic Anvil, the Executive Anvil is perfect for the business traveler looking for something to drop from a height.",
7
+ "mpn": "925872",
8
+ "brand": {
9
+ "@type": "Thing",
10
+ "name": "ACME"
11
+ },
12
+ "aggregateRating": {
13
+ "@type": "AggregateRating",
14
+ "ratingValue": "4.4",
15
+ "reviewCount": "89"
16
+ },
17
+ "offers": {
18
+ "@type": "Offer",
19
+ "priceCurrency": "USD",
20
+ "price": "119.99",
21
+ "priceValidUntil": "2020-11-05",
22
+ "itemCondition": "http://schema.org/UsedCondition",
23
+ "availability": "http://schema.org/InStock",
24
+ "seller": {
25
+ "@type": "Organization",
26
+ "name": "Executive Objects"
27
+ }
28
+ }
29
+ }
package/native-demo.js ADDED
@@ -0,0 +1,113 @@
1
+ const DkgClient = require('./index');
2
+
3
+ const OT_NODE_HOSTNAME = '0.0.0.0';
4
+ const OT_NODE_PORT = '8900';
5
+
6
+ // initialize connection to your DKG Node
7
+ let options = { endpoint: OT_NODE_HOSTNAME, port: OT_NODE_PORT, useSSL: false, loglevel: 'trace' };
8
+ const dkg = new DkgClient(options);
9
+
10
+ async function main() {
11
+
12
+ console.log('============ DKG-Client v6 Demo ===================')
13
+
14
+ await dkg.nodeInfo().then(result => {
15
+ console.log('============ Node info results ===================');
16
+ console.log(JSON.stringify(result, null, 2));
17
+ console.log('===============================');
18
+ } );
19
+
20
+ await keypress();
21
+
22
+ options = {
23
+ filepath: './kg-example.json',
24
+ keywords: ['Product', 'Executive Objects', 'ACME'],
25
+ visibility: 'public'
26
+ };
27
+
28
+ await dkg.publish(options).then((result) => {
29
+ console.log('============ Publish results ===================');
30
+ console.log(JSON.stringify(result, null, 2));
31
+ console.log('===============================');
32
+ });
33
+
34
+ await keypress();
35
+
36
+ options = {
37
+ ids: [
38
+ '9f388253151d743a36ed2e06d3466949fab2190d09acafc36d973f4f1bbc74f3'
39
+ ]
40
+ };
41
+
42
+ await dkg.resolve(options).then((result) => {
43
+ console.log('============ Resolve results ===================');
44
+ console.log(JSON.stringify(result, null, 2));
45
+ console.log('===============================');
46
+ });
47
+
48
+ await keypress();
49
+
50
+ // search assertions
51
+ options = { query: 'acme', resultType: 'assertions' };
52
+ await dkg.search(options).then((result) => {
53
+ console.log('============ Search assertions results ===================');
54
+ console.log(JSON.stringify(result, null, 2));
55
+ console.log('===============================');
56
+ });
57
+
58
+ await keypress();
59
+
60
+ // search entities
61
+ options = { query: 'acme', resultType: 'entities' };
62
+ await dkg.search(options).then((result) => {
63
+ console.log('============ Search entities results ===================');
64
+ console.log(JSON.stringify(result, null, 2));
65
+ console.log('===============================');
66
+ });
67
+
68
+ await keypress();
69
+
70
+ options = {
71
+ query: `PREFIX schema: <http://schema.org/>
72
+ construct { ?s ?p ?o}
73
+ WHERE {
74
+ GRAPH ?g {?s ?p ?o .
75
+ ?s schema:offers / schema:seller/ schema:name "Executive Objects" .
76
+ }
77
+ }`
78
+ };
79
+
80
+ await dkg.query(options).then((result) => {
81
+ console.log('============ Query results ===================');
82
+ console.log(JSON.stringify(result, null, 2));
83
+ console.log('===============================');
84
+ });
85
+
86
+ await keypress();
87
+
88
+ options = {
89
+ nquads: [
90
+ '<did:dkg:43a5f8c55600a36882f9bac7c69c05a3e0edd1293b56b8024faf3a29d8157435> <http://schema.org/hasDataHash> \"019042b4b5cb5701579a4fd8e339bed0fa983b06920ed8cd4d5864ffcb01c801\" .',
91
+ '<did:dkg:43a5f8c55600a36882f9bac7c69c05a3e0edd1293b56b8024faf3a29d8157435> <http://schema.org/hasIssuer> \"0xbd084ab97c704fe4a6d620cb7c30c0be0366646f\" .'
92
+ ],
93
+ };
94
+ await dkg.validate(options).then((result) => {
95
+ console.log('============ Validate results ===================');
96
+ console.log(JSON.stringify(result, null, 2));
97
+ console.log('===============================');
98
+ });
99
+
100
+ console.log("That's all folks");
101
+ process.exit(0);
102
+ }
103
+
104
+ const keypress = async () => {
105
+ console.log('Press any key...')
106
+ process.stdin.setRawMode(true)
107
+ return new Promise(resolve => process.stdin.once('data', () => {
108
+ process.stdin.setRawMode(false)
109
+ resolve()
110
+ }))
111
+ }
112
+
113
+ main();
@@ -0,0 +1,19 @@
1
+ {
2
+ "@context": "http://schema.org/",
3
+ "@type": "nft",
4
+ "name": "Tracie 101 Updated",
5
+ "description": "The genesis collection of NFTs supercharged by the OriginTrail Decentralized Knowledge Graph",
6
+ "creator": "0xBD084aB97C704FE4a6D620CB7c30C0BE0366646f",
7
+ "dateCreated": "2021",
8
+ "blockchain": {
9
+ "name": "polygon",
10
+ "contract": "0x123",
11
+ "owner": "0xabc",
12
+ "standard": "ERC-721"
13
+ },
14
+ "connectedTo": [
15
+ "Tracie 10"
16
+ ],
17
+ "encodingFormat": "url",
18
+ "content": "https://lh3.googleusercontent.com/NZ9lz_eqVsNjMwbaAHldfszslDqkpkcenpMXZA3MwwDKyGeTY3aaOayMUqgjONS-DLpVis2bBgT-usK_-gUeqVIYs74psHZP-od28tI=w600"
19
+ }
@@ -0,0 +1,19 @@
1
+ {
2
+ "@context": "http://schema.org/",
3
+ "@type": "nft",
4
+ "name": "Tracie 101",
5
+ "description": "The genesis collection of NFTs supercharged by the OriginTrail Decentralized Knowledge Graph",
6
+ "creator": "0xBD084aB97C704FE4a6D620CB7c30C0BE0366646f",
7
+ "dateCreated": "2021",
8
+ "blockchain": {
9
+ "name": "polygon",
10
+ "contract": "0x123",
11
+ "owner": "0xabc",
12
+ "standard": "ERC-721"
13
+ },
14
+ "connectedTo": [
15
+ "Tracie 10"
16
+ ],
17
+ "encodingFormat": "url",
18
+ "content": "https://lh3.googleusercontent.com/NZ9lz_eqVsNjMwbaAHldfszslDqkpkcenpMXZA3MwwDKyGeTY3aaOayMUqgjONS-DLpVis2bBgT-usK_-gUeqVIYs74psHZP-od28tI=w600"
19
+ }
package/package.json ADDED
@@ -0,0 +1,44 @@
1
+ {
2
+ "name": "dkg.js",
3
+ "version": "6.0.0-beta.2.0",
4
+ "description": "Javascript library for interaction with the OriginTrail Decentralized Knowledge Graph",
5
+ "main": "index.js",
6
+ "scripts": {
7
+ "test": "npm run test",
8
+ "build": "npx webpack --config webpack.config.js"
9
+ },
10
+ "repository": {
11
+ "type": "git",
12
+ "url": "git+https://github.com/OriginTrail/dkg.js.git"
13
+ },
14
+ "keywords": [
15
+ "origintrail",
16
+ "knowledge",
17
+ "graph",
18
+ "dkg",
19
+ "blockchain",
20
+ "ot-node",
21
+ "v6"
22
+ ],
23
+ "author": "Trace Labs Group",
24
+ "license": "Apache-2.0",
25
+ "bugs": {
26
+ "url": "https://github.com/OriginTrail/dkg.js/issues"
27
+ },
28
+ "homepage": "https://github.com/OriginTrail/dkg.js/tree/master#readme",
29
+ "dependencies": {
30
+ "axios": "^0.21.1",
31
+ "crypto-js": "^4.1.1",
32
+ "form-data": "^4.0.0",
33
+ "loglevel": "^1.8.0",
34
+ "merkle-tools": "^1.4.1",
35
+ "n3": "^1.12.2",
36
+ "sparqljs": "^3.5.1",
37
+ "sync-request": "^6.1.0",
38
+ "uuid": "^8.3.2"
39
+ },
40
+ "devDependencies": {
41
+ "webpack": "^5.69.0",
42
+ "webpack-cli": "^4.9.2"
43
+ }
44
+ }
@@ -0,0 +1,119 @@
1
+ const request = require('sync-request');
2
+
3
+ class AssetsProxyPath {
4
+ constructor(options) {
5
+ this.nodeBaseUrl = `${options.useSSL ? "https://" : "http://"}${
6
+ options.endpoint
7
+ }:${options.port}`;
8
+ }
9
+
10
+ /**
11
+ * Creates a path Proxy with the given settings and internal data fields.
12
+ */
13
+
14
+
15
+ createPath() {
16
+ let settings = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
17
+ let data = arguments.length > 1 ? arguments[1] : undefined;
18
+ let id = arguments.length > 2 ? arguments[2] : undefined;
19
+ let loaded = arguments.length > 3 ? arguments[3] : false;
20
+
21
+ // The settings parameter is optional
22
+ if (data === undefined) [data, settings] = [settings, {}]; // Create the path's internal data object and the proxy that wraps it
23
+
24
+ const {
25
+ apply,
26
+ ...rawData
27
+ } = data;
28
+ let path = apply ? Object.assign(callPathFunction, rawData) : rawData;
29
+ path = {data: path};
30
+ const proxy = new Proxy(path, this);
31
+ path.proxy = proxy;
32
+ path.settings = settings;
33
+ path.id = id;
34
+ path.loaded = loaded;
35
+
36
+ function callPathFunction() {
37
+ for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
38
+ args[_key] = arguments[_key];
39
+ }
40
+
41
+ return apply(args, path, proxy);
42
+ }
43
+
44
+
45
+ if (!path.extendPath) {
46
+ const pathProxy = this;
47
+
48
+ path.extendPath = function extendPath(newData) {
49
+ return pathProxy.createPath(settings, {
50
+ extendPath,
51
+ ...newData
52
+ },
53
+ id,
54
+ true);
55
+ };
56
+ } // Return the proxied path
57
+
58
+
59
+ return proxy;
60
+ }
61
+
62
+ /**
63
+ * Handles access to a property
64
+ */
65
+ get(path, property) {
66
+ function helper(path) {
67
+ delete path.data.extendPath;
68
+ if (path.data.property)
69
+ return path.data.property;
70
+ else
71
+ return path.data;
72
+ }
73
+
74
+ if (property === 'then')
75
+ return undefined;
76
+
77
+ if (!path.loaded) {
78
+ const latestState = this.resolve(path.id)
79
+ path.data = latestState;
80
+ }
81
+
82
+ if (property === 'valueOf') {
83
+ return helper(path)
84
+ }
85
+
86
+ if (typeof path.data[property] === "function") {
87
+ return function () {
88
+ return helper(path)
89
+ }
90
+ }
91
+
92
+ if (path.data[property]) {
93
+ let newData;
94
+ if (typeof path.data[property] === 'string' || path.data[property] instanceof String)
95
+ newData = {property: path.data[property]}
96
+ else
97
+ newData = path.data[property];
98
+ return path.extendPath(newData);
99
+ }
100
+
101
+ return undefined;
102
+ }
103
+
104
+ resolve(id) {
105
+ let body = {
106
+ status: 'PENDING'
107
+ }
108
+ let response = request('GET', `${this.nodeBaseUrl}/resolve?ids=${id}`);
109
+ const handler = JSON.parse(response.getBody()).handler_id
110
+ while (body.status === 'PENDING') {
111
+ new Date(new Date().getTime() + 1000);
112
+ response = request('GET', `${this.nodeBaseUrl}/resolve/result/${handler}`);
113
+ body = JSON.parse(response.getBody());
114
+ }
115
+ return body.data[0].result;
116
+ }
117
+ }
118
+
119
+ module.exports = AssetsProxyPath;
@@ -0,0 +1,23 @@
1
+ const logger = require('loglevel');
2
+
3
+
4
+ class Logger {
5
+
6
+ constructor(level) {
7
+ logger.setLevel(level);
8
+ }
9
+
10
+ info (message) {
11
+ logger.info(message);
12
+ }
13
+
14
+ debug (message) {
15
+ logger.debug(message);
16
+ }
17
+
18
+ error (message) {
19
+ logger.error(message);
20
+ }
21
+ }
22
+
23
+ module.exports = Logger;
@@ -0,0 +1,12 @@
1
+ const path = require('path');
2
+
3
+ module.exports = {
4
+ mode: 'development',
5
+ entry: './index.js',
6
+ output: {
7
+ path: path.resolve(__dirname, 'dist'),
8
+ filename: 'index.bundle.js',
9
+ libraryTarget: "var",
10
+ library: "SemanticWeb3",
11
+ },
12
+ };