dkg.js 6.0.0 → 6.0.2

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.
@@ -1,21 +1,20 @@
1
- const jsonld = require('jsonld');
2
- const DKG = require('./index.js');
1
+ const DKG = require('../index.js');
3
2
 
4
3
  const OT_NODE_HOSTNAME = 'http://localhost';
5
4
  const OT_NODE_PORT = '8900';
6
5
  const PUBLIC_KEY = '0xBaF76aC0d0ef9a2FFF76884d54C9D3e270290a43';
7
6
  const PRIVATE_KEY = '0x9b9af041edc816692276ac3c8f1d5565e3c01ddff80ec982943a29bd8d1d8863';
8
- const blockchain = {
9
- name: 'ganache',
10
- publicKey: PUBLIC_KEY,
11
- privateKey: PRIVATE_KEY,
12
- };
13
7
 
14
8
  const DkgClient = new DKG({
15
9
  endpoint: OT_NODE_HOSTNAME,
16
10
  port: OT_NODE_PORT,
17
- useSSL: true,
18
- loglevel: 'trace',
11
+ blockchain: {
12
+ name: 'ganache',
13
+ publicKey: PUBLIC_KEY,
14
+ privateKey: PRIVATE_KEY,
15
+ },
16
+ maxNumberOfRetries: 60,
17
+ frequency: 2,
19
18
  });
20
19
 
21
20
  function divider() {
@@ -36,7 +35,7 @@ function divider() {
36
35
  const createAssetResult = await DkgClient.asset.create(
37
36
  {
38
37
  public: {
39
- '@context': ['https://schema.org'],
38
+ '@context': ['http://schema.org'],
40
39
  '@id': 'uuid:1',
41
40
  company: 'OT',
42
41
  user: {
@@ -47,7 +46,7 @@ function divider() {
47
46
  },
48
47
  },
49
48
  private: {
50
- '@context': ['https://schema.org'],
49
+ '@context': ['http://schema.org'],
51
50
  '@graph': [
52
51
  {
53
52
  '@id': 'uuid:user:1',
@@ -62,60 +61,34 @@ function divider() {
62
61
  ],
63
62
  },
64
63
  },
65
- {
66
- epochsNum: 2,
67
- maxNumberOfRetries: 30,
68
- frequency: 2,
69
- blockchain,
70
- },
64
+ { epochsNum: 2 },
71
65
  );
72
66
  console.log('======================== ASSET CREATED');
73
67
  console.log(createAssetResult);
74
68
 
75
69
  divider();
76
- const ownerResult = await DkgClient.asset.getOwner(createAssetResult.UAL, {
77
- blockchain,
70
+
71
+ const getPrivateAssetResult = await DkgClient.asset.get(createAssetResult.UAL, {
72
+ contentType: 'private',
78
73
  });
79
- console.log('======================== GET ASSET OWNER');
80
- console.log(ownerResult);
74
+ console.log('======================== PRIVATE ASSET CONTENT RESOLVED');
75
+ console.log(JSON.stringify(getPrivateAssetResult, null, 2));
81
76
 
82
77
  divider();
83
78
 
84
- const getAssetResult = await DkgClient.asset.get(createAssetResult.UAL, {
85
- validate: true,
86
- maxNumberOfRetries: 30,
87
- frequency: 1,
88
- blockchain,
89
- });
90
- console.log('======================== ASSET RESOLVED');
91
- console.log(JSON.stringify(getAssetResult, null, 2));
92
-
93
79
  divider();
94
80
 
95
- const queryResult = await DkgClient.graph.query(
96
- 'construct { ?s ?p ?o } where { ?s ?p ?o . <uuid:user:1> ?p ?o }',
97
- 'CONSTRUCT',
98
- );
99
- console.log('======================== QUERY RESULT');
100
- console.log(
101
- JSON.stringify(
102
- await jsonld.fromRDF(queryResult.data, {
103
- algorithm: 'URDNA2015',
104
- format: 'application/n-quads',
105
- }),
106
- null,
107
- 2,
108
- ),
109
- );
81
+ const getPublicAssetResult = await DkgClient.asset.get(createAssetResult.UAL);
82
+ console.log('======================== PUBLIC ASSET CONTENT RESOLVED');
83
+ console.log(JSON.stringify(getPublicAssetResult, null, 2));
110
84
 
111
85
  divider();
112
86
 
113
- const newOwner = '0x2ACa90078563133db78085F66e6B8Cf5531623Ad';
114
- const transferResult = await DkgClient.asset.transfer(createAssetResult.UAL, newOwner, {
115
- blockchain,
116
- });
117
- console.log(`======================== ASSET TRANSFERRED TO ${newOwner}`);
118
- console.log(transferResult);
87
+ divider();
88
+
89
+ const getAssetResult = await DkgClient.asset.get(createAssetResult.UAL, { contentType: 'all' });
90
+ console.log('======================== ALL ASSET CONTENT RESOLVED');
91
+ console.log(JSON.stringify(getAssetResult, null, 2));
119
92
 
120
93
  divider();
121
94
  })();
@@ -94,7 +94,7 @@
94
94
  integrity="sha384-MrcW6ZMFYlzcLA8Nl+NtUVF0sA7MsXsP1UyJoMp4YLEuNSfAP+JcXn/tWtIaxVXM"
95
95
  crossorigin="anonymous"></script>
96
96
  <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
97
- <script src="./dist/dkg.min.js"></script>
97
+ <script src="../dist/dkg.min.js"></script>
98
98
  <script>
99
99
 
100
100
  </script>
@@ -153,13 +153,11 @@
153
153
  },
154
154
  methods: {
155
155
  initializeDKGClient(blockchain) {
156
- const OT_NODE_HOSTNAME = 'https://v6-pegasus-node-12.origin-trail.network';
156
+ const OT_NODE_HOSTNAME = 'localhost';
157
157
  const OT_NODE_PORT = '8900';
158
158
  const options = {
159
159
  endpoint: OT_NODE_HOSTNAME,
160
160
  port: OT_NODE_PORT,
161
- useSSL: false,
162
- loglevel: 'trace',
163
161
  blockchain: {
164
162
  name: "otp"
165
163
  }
@@ -0,0 +1,184 @@
1
+ const jsonld = require('jsonld');
2
+ const DKG = require('../index.js');
3
+
4
+ const OT_NODE_HOSTNAME = 'http://localhost';
5
+ const OT_NODE_PORT = '8900';
6
+ const PUBLIC_KEY = '0xf39Fd6e51aad88F6F4ce6aB8827279cffFb92266';
7
+ const PRIVATE_KEY = '0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80';
8
+
9
+ const DkgClient = new DKG({
10
+ endpoint: OT_NODE_HOSTNAME,
11
+ port: OT_NODE_PORT,
12
+ blockchain: {
13
+ name: 'hardhat',
14
+ publicKey: PUBLIC_KEY,
15
+ privateKey: PRIVATE_KEY,
16
+ },
17
+ maxNumberOfRetries: 30,
18
+ frequency: 2,
19
+ contentType: 'all',
20
+ });
21
+
22
+ function divider() {
23
+ console.log('==================================================');
24
+ console.log('==================================================');
25
+ console.log('==================================================');
26
+ }
27
+
28
+ (async () => {
29
+ divider();
30
+
31
+ const nodeInfo = await DkgClient.node.info();
32
+ console.log('======================== NODE INFO RECEIVED');
33
+ console.log(nodeInfo);
34
+
35
+ divider();
36
+
37
+ const createAssetResult = await DkgClient.asset.create(
38
+ {
39
+ public: {
40
+ '@context': ['https://schema.org'],
41
+ '@id': 'uuid:1',
42
+ company: 'OT',
43
+ user: {
44
+ '@id': 'uuid:user:1',
45
+ },
46
+ city: {
47
+ '@id': 'uuid:belgrade',
48
+ },
49
+ },
50
+ private: {
51
+ '@context': ['https://schema.org'],
52
+ '@graph': [
53
+ {
54
+ '@id': 'uuid:user:1',
55
+ name: 'Adam',
56
+ lastname: 'Smith',
57
+ },
58
+ {
59
+ '@id': 'uuid:belgrade',
60
+ title: 'Belgrade',
61
+ postCode: '11000',
62
+ },
63
+ ],
64
+ },
65
+ },
66
+ { epochsNum: 2 },
67
+ );
68
+ console.log('======================== ASSET CREATED');
69
+ console.log(createAssetResult);
70
+
71
+ divider();
72
+
73
+ const ownerResult = await DkgClient.asset.getOwner(createAssetResult.UAL);
74
+ console.log('======================== GET ASSET OWNER');
75
+ console.log(ownerResult);
76
+
77
+ divider();
78
+
79
+ const getAssetResult = await DkgClient.asset.get(createAssetResult.UAL);
80
+ console.log('======================== ASSET RESOLVED');
81
+ console.log(JSON.stringify(getAssetResult, null, 2));
82
+
83
+ divider();
84
+
85
+ const updateAssetResult = await DkgClient.asset.update(createAssetResult.UAL, {
86
+ public: {
87
+ '@context': ['https://schema.org'],
88
+ '@id': 'uuid:1',
89
+ company: 'TL',
90
+ user: {
91
+ '@id': 'uuid:user:2',
92
+ },
93
+ city: {
94
+ '@id': 'uuid:Nis',
95
+ },
96
+ },
97
+ private: {
98
+ '@context': ['https://schema.org'],
99
+ '@graph': [
100
+ {
101
+ '@id': 'uuid:user:1',
102
+ name: 'Adam',
103
+ lastname: 'Smith',
104
+ identifier: `${Math.floor(Math.random() * 1e10)}`,
105
+ },
106
+ ],
107
+ },
108
+ });
109
+ console.log('======================== ASSET UPDATED');
110
+ console.log(updateAssetResult);
111
+
112
+ divider();
113
+
114
+ let getLatestAssetResult = await DkgClient.asset.get(createAssetResult.UAL);
115
+ console.log('======================== ASSET LATEST RESOLVED');
116
+ console.log(JSON.stringify(getLatestAssetResult, null, 2));
117
+
118
+ divider();
119
+
120
+ let getLatestFinalizedAssetResult = await DkgClient.asset.get(createAssetResult.UAL, {
121
+ state: 'LATEST_FINALIZED',
122
+ });
123
+ console.log('======================== ASSET LATEST FINALIZED RESOLVED');
124
+ console.log(JSON.stringify(getLatestFinalizedAssetResult, null, 2));
125
+
126
+ divider();
127
+
128
+ await DkgClient.asset.waitFinalization(createAssetResult.UAL);
129
+ console.log('======================== FINALIZATION COMPLETED');
130
+
131
+ divider();
132
+
133
+ getLatestFinalizedAssetResult = await DkgClient.asset.get(createAssetResult.UAL, {
134
+ state: 'LATEST_FINALIZED',
135
+ });
136
+ console.log('======================== ASSET LATEST FINALIZED RESOLVED');
137
+ console.log(JSON.stringify(getLatestFinalizedAssetResult, null, 2));
138
+
139
+ divider();
140
+
141
+ let queryResult = await DkgClient.graph.query(
142
+ 'construct { ?s ?p ?o } where { ?s ?p ?o . <uuid:1> ?p ?o }',
143
+ 'CONSTRUCT',
144
+ );
145
+ console.log('======================== QUERY LOCAL CURRENT RESULT');
146
+ console.log(
147
+ JSON.stringify(
148
+ await jsonld.fromRDF(queryResult.data, {
149
+ algorithm: 'URDNA2015',
150
+ format: 'application/n-quads',
151
+ }),
152
+ null,
153
+ 2,
154
+ ),
155
+ );
156
+
157
+ divider();
158
+
159
+ queryResult = await DkgClient.graph.query(
160
+ 'construct { ?s ?p ?o } where { ?s ?p ?o . <uuid:1> ?p ?o }',
161
+ 'CONSTRUCT',
162
+ { graphState: 'HISTORICAL', graphLocation: 'LOCAL_KG' },
163
+ );
164
+ console.log('======================== QUERY LOCAL HISTORY RESULT');
165
+ console.log(
166
+ JSON.stringify(
167
+ await jsonld.fromRDF(queryResult.data, {
168
+ algorithm: 'URDNA2015',
169
+ format: 'application/n-quads',
170
+ }),
171
+ null,
172
+ 2,
173
+ ),
174
+ );
175
+
176
+ divider();
177
+
178
+ const newOwner = '0x2ACa90078563133db78085F66e6B8Cf5531623Ad';
179
+ const transferResult = await DkgClient.asset.transfer(createAssetResult.UAL, newOwner);
180
+ console.log(`======================== ASSET TRANSFERRED TO ${newOwner}`);
181
+ console.log(transferResult);
182
+
183
+ divider();
184
+ })();
@@ -7,7 +7,7 @@
7
7
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
8
8
  <title>Document</title>
9
9
  <script src="https://cdn.jsdelivr.net/npm/web3@latest/dist/web3.min.js"></script>
10
- <script src="./dist/dkg.min.js"></script>
10
+ <script src="../dist/dkg.min.js"></script>
11
11
  </head>
12
12
  <body>
13
13
 
@@ -1,10 +1,10 @@
1
- const DKG = require('./index');
1
+ const DKG = require('../index');
2
2
 
3
3
  const OT_NODE_HOSTNAME = 'localhost';
4
4
  const OT_NODE_PORT = '8903';
5
5
 
6
6
  // initialize connection to your DKG Node
7
- let options = { endpoint: OT_NODE_HOSTNAME, port: OT_NODE_PORT, useSSL: false, loglevel: 'trace' };
7
+ let options = { endpoint: OT_NODE_HOSTNAME, port: OT_NODE_PORT, };
8
8
  const dkg = new DKG(options);
9
9
 
10
10
  async function main() {