-
Notifications
You must be signed in to change notification settings - Fork 1
/
digital-twin.rst
1000 lines (660 loc) · 28.4 KB
/
digital-twin.rst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
================================================================================
Digital Twin
================================================================================
.. list-table::
:widths: auto
:stub-columns: 1
* - Class Name
- DigitalTwin
* - Extends
- `Logger <../common/logger.html>`_
* - Source
- `digital-twin.ts <https://github.com/evannetwork/api-blockchain-core/tree/master/src/contracts/digital-twin/digital-twin.ts>`_
* - Examples
- `digital-twin.spec.ts <https://github.com/evannetwork/api-blockchain-core/tree/master/src/contracts/digital-twin/digital-twin.spec.ts>`_
TL;DR: usage examples and a data flow can be found :doc:`here <./digital-twin-usage-examples>`.
A ``DigitalTwin`` is a wrapper, that holds data or references to data. This data can be
- a |source Container|_ - This is the most common use case, actual data is stored in the container and the ``DigitalTwin`` merely holds a reference to the container.
- an ``DigitalTwin`` - DigitalTwins can be linked together, so an entry can be another ``DigitalTwin``, which allows to navigate through twins to retrieve data properties from linked twins, see :ref:`getEntry <digital-twin_getEntry>`
- an account address / a contract address
- ``bytes32`` hashes (e.g. file hashes)
--------------------------------------------------------------------------------
.. _digital-twin_constructor:
constructor
================================================================================
.. code-block:: typescript
new DigitalTwin(options, config);
Create new ``DigitalTwin`` instance. This will not create a smart contract contract but is used to
load existing digital twins. To create a new contract, use the static :ref:`create <digital-twin_create>` function.
----------
Parameters
----------
#. ``options`` - ``DigitalTwinOptions``: runtime-like object with required modules
* ``contractLoader`` - |source contractLoader|_: |source contractLoader|_ instance
* ``cryptoProvider`` - |source cryptoProvider|_: |source cryptoProvider|_ instance
* ``dataContract`` - |source dataContract|_: |source dataContract|_ instance
* ``description`` - |source description|_: |source description|_ instance
* ``executor`` - |source executor|_: |source executor|_ instance
* ``log`` - ``Function`` (optional): function to use for logging: ``(message, level) => {...}``
* ``logLevel`` - |source logLevel|_ (optional): messages with this level will be logged with ``log``
* ``logLog`` - |source logLogInterface|_ (optional): container for collecting log messages
* ``logLogLevel`` - |source logLevel|_ (optional): messages with this level will be pushed to ``logLog``
* ``nameResolver`` - |source nameResolver|_: |source nameResolver|_ instance
* ``profile`` - |source profile|_: |source profile|_ instance
* ``rightsAndRoles`` - |source rightsAndRoles|_: |source rightsAndRoles|_ instance
* ``sharing`` - |source sharing|_: |source sharing|_ instance
* ``verifications`` - |source verifications|_: |source verifications|_ instance
* ``web3`` - |source web3|_: |source web3|_ instance
#. ``config`` - ``DigitalTwinConfig``: digital twin related config
* ``accountId`` - ``string``: account id of user, that interacts with digital twin
* ``containerConfig`` - ``ContainerConfig``: address of a ``DigitalTwin`` instance, can be ENS or contract address
* ``address`` - ``string`` (optional): address of an ``DigitalTwin`` instance, can be ENS or contract address
* ``description`` - ``string``: description has to be passed to ``.create`` to apply it to to contract
* ``factoryAddress`` - ``string`` (optional): factory address can be passed to ``.create`` for customer digital twin factory
-------
Returns
-------
``DigitalTwin`` instance
-------
Example
-------
.. code-block:: typescript
const digitalTwin = new DigitalTwin(
runtime,
{
accountId: '0x0000000000000000000000000000000000000000',
address: 'sample-digital-twin.somewhere.evan',
},
);
--------------------------------------------------------------------------------
= Creating Digital Identities =
===============================
.. _digital-twin_create:
create
================================================================================
.. code-block:: typescript
DigitalTwin.create(runtime, config);
Create digital twin contract.
Note, that this function is static. It is used on the ``DigitalTwin`` class object and returns a ``DigitalTwin`` class instance.
The options argument has the same structure as the options object that is passed to the constructor as it is used for the new ``DigitalTwin`` instance. The ``config`` argument requires a proper value for the property ``description``.
----------
Parameters
----------
#. ``options`` - ``ContainerOptions``: runtime-like object with required modules
* ``contractLoader`` - |source contractLoader|_: |source contractLoader|_ instance
* ``cryptoProvider`` - |source cryptoProvider|_: |source cryptoProvider|_ instance
* ``dataContract`` - |source dataContract|_: |source dataContract|_ instance
* ``description`` - |source description|_: |source description|_ instance
* ``executor`` - |source executor|_: |source executor|_ instance
* ``nameResolver`` - |source nameResolver|_: |source nameResolver|_ instance
* ``rightsAndRoles`` - |source rightsAndRoles|_: |source rightsAndRoles|_ instance
* ``sharing`` - |source sharing|_: |source sharing|_ instance
* ``verifications`` - |source verifications|_: |source verifications|_ instance
* ``web3`` - |source web3|_: |source web3|_ instance
* ``log`` - ``Function`` (optional): function to use for logging: ``(message, level) => {...}``
* ``logLevel`` - |source logLevel|_ (optional): messages with this level will be logged with ``log``
* ``logLog`` - |source logLogInterface|_ (optional): container for collecting log messages
* ``logLogLevel`` - |source logLevel|_ (optional): messages with this level will be pushed to ``logLog``
#. ``config`` - ``DigitalTwinConfig``: digital twin related config
* ``accountId`` - ``string``: account id of user, that interacts with digital twin
* ``containerConfig`` - ``ContainerConfig``: config, that will be used, when containers are created
* ``address`` - ``string`` (optional): ENS address used for digital twin
* ``description`` - ``string``: description has to be passed to ``.create`` to apply it to to contract
* ``factoryAddress`` - ``string`` (optional): factory address can be passed to ``.create`` for customer digital twin factory
-------
Returns
-------
``Promise`` returns ``DigitalTwin``: new instance bound to new ``DigitalTwin``
-------
Example
-------
.. code-block:: typescript
const digitalTwin = await DigitalTwin.create(options, config);
console.log(await digitalTwin.getContractAddress());
// Output:
// 0x0000000000000000000000000000000000001234
--------------------------------------------------------------------------------
= Container =
=============
.. _digital-twin_createContainers:
createContainers
================================================================================
.. code-block:: typescript
digitalTwin.createContainers(containers);
Create new `Container` instances and add them as entry to twin.
When a container entry fetched with :ref:`getEntry <digital-twin_getEntry>` or :ref:`getEntry <digital-twin_getEntries>`, the value will become a ``Container`` instance and can be used as such.
----------
Parameters
----------
#. ``containers`` - ``{ [id: string]: Partial<ContainerConfig> }``: object with containers to create, name is used as entry name in twin
-------
Returns
-------
``Promise`` returns ``{ [id: string]: Container }``: map with ``Container`` instances
-------
Example
-------
.. code-block:: typescript
const containers = await twin.createContainers({
entry1: { template: 'metadata' },
entry2: { template: 'metadata' },
});
--------------------------------------------------------------------------------
= Entries =
===========
.. _digital-twin_setEntry:
setEntry
================================================================================
.. code-block:: typescript
digitalTwin.setEntry(name, value, entryType);
Set entry in index contract; entries are unique, setting the same name a second time will overwrite the first value.
----------
Parameters
----------
#. ``name`` - ``string``: entry name
#. ``value`` - ``string``: value to set
#. ``entryType`` - ``DigitalTwinType``: type of given value
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
await digitalTwin.setEntry('myId', accountId, DigitalTwinEntryType.AccountId);
console.log((await digitalTwin.getEntry('myId')).value);
// Output:
// 0x0000000000000000000000000000000000000001
--------------------------------------------------------------------------------
.. _digital-twin_setEntries:
setEntries
================================================================================
.. code-block:: typescript
digitalTwin.setEntries(arguments);
Set multiple entries at index contract.
----------
Parameters
----------
#. ``entries`` - ``{[id: string]: DigitalTwinIndexEntry}``: entries to set
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
const sampleContractId = '0x00000000000000000000000000000000c0274ac7';
await digitalTwin.setEntries({
'account': { value: accountId, entryType: DigitalTwinEntryType.AccountId },
'contract': { value: sampleContractId, entryType: DigitalTwinEntryType.GenericContract },
});
const result = (await digitalTwin.getEntries()).map(entry => value);
console.log(result.account.value);
// Output:
// 0x0000000000000000000000000000000000000001
console.log(result.contract.value);
// Output:
// 0x00000000000000000000000000000000c0274ac7
--------------------------------------------------------------------------------
.. _digital-twin_getEntry:
getEntry
================================================================================
.. code-block:: typescript
digitalTwin.getEntry(name);
Get single entry from index contract.
When this twin has other twins as its entries, properties from those can be selected by building a path of properties.
For example a twin called ``car`` may have a link to another twin under the name ``tire``. The twin ``tire`` has an entry called ``metadata``. It is possible to retrieve this entry from the twin ``car`` with:
.. code-block:: typescript
const tireMetadata = await car.getEntry('tire/metadata');
----------
Parameters
----------
#. ``name`` - ``string``: entry name or path to data in linked twin
-------
Returns
-------
``Promise`` returns ``DigitalTwinIndexEntry``: entry object
-------
Example
-------
.. code-block:: typescript
await digitalTwin.setEntry('myId', accountId, DigitalTwinEntryType.AccountId);
console.log((await digitalTwin.getEntry('myId')).value);
// Output:
// 0x0000000000000000000000000000000000000001
--------------------------------------------------------------------------------
.. _digital-twin_getEntries:
getEntries
================================================================================
.. code-block:: typescript
digitalTwin.getEntries();
Get all entries from index contract.
-------
Returns
-------
``Promise`` returns ``{[id: string]: DigitalTwinIndexEntry}``: key-value map with all entries
-------
Example
-------
.. code-block:: typescript
const sampleContractId = '0x00000000000000000000000000000000c0274ac7';
await digitalTwin.setEntries({
'account': { value: accountId, entryType: DigitalTwinEntryType.AccountId },
'contract': { value: sampleContractId, entryType: DigitalTwinEntryType.GenericContract },
});
const result = (await digitalTwin.getEntries()).map(entry => value);
console.log(result.account.value);
// Output:
// 0x0000000000000000000000000000000000000001
console.log(result.contract.value);
// Output:
// 0x00000000000000000000000000000000c0274ac7
--------------------------------------------------------------------------------
= Verifications =
=================
.. _digital-twin_addVerifications:
addVerifications
================================================================================
.. code-block:: typescript
digitalTwin.addVerifications(verifications);
Add verifications to this twin; this will also add verifications to contract description.
If the calling account is the owner of the identity of the digital twin
- the description will is automatically updated with tags for verifications
- verifications issued with this function will be accepted automatically
See interface ``DigitalTwinVerificationEntry`` for input data format.
----------
Parameters
----------
#. ``verifications`` - ``DigitalTwinVerificationEntry[]``: list of verifications to add
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
await digitalTwin.addVerifications([{ topic: 'exampleVerification' }]);
--------------------------------------------------------------------------------
.. _digital-twin_getVerifications:
getVerifications
================================================================================
.. code-block:: typescript
digitalTwin.getVerifications();
Gets verifications from description and fetches list of verifications for each of them.
See |source verifications|_ documentation for details on output data format.
-------
Returns
-------
``Promise`` returns ``any``: list of verification lists from |source verifications|_, ``getVerifications``
-------
Example
-------
.. code-block:: typescript
await digitalTwin.addVerifications([{ topic: 'exampleVerification' }]);
const verifications = await digitalTwin.getVerifications());
--------------------------------------------------------------------------------
= Descriptions =
================
.. _digital-twin_getDescription:
getDescription
================================================================================
.. code-block:: typescript
digitalTwin.getDescription();
Returns description from digital twin.
-------
Returns
-------
``Promise`` returns ``any``: public part of the description
-------
Example
-------
.. code-block:: typescript
const description = await container.getDescription();
console.dir(description);
// Output:
// { name: 'test twin',
// description: 'twin from test run',
// author: 'evan GmbH',
// version: '0.1.0',
// dbcpVersion: 2,
// tags: [ 'evan-digital-twin' ],
// identity:
// '0x1a496043385fec8d52f61e2b700413f8e12eb6e7e11649f80c8f4716c1063d06' }
--------------------------------------------------------------------------------
.. _digital-twin_setDescription:
setDescription
================================================================================
.. code-block:: typescript
digitalTwin.setDescription(description);
Write given description to digital twins DBCP.
----------
Parameters
----------
#. ``description`` - ``any``: description (public part)
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
// get current description
const description = await digitalTwin.getDescription();
console.dir(description);
// Output:
// { name: 'test twin',
// description: 'twin from test run',
// author: 'evan GmbH',
// version: '0.1.0',
// dbcpVersion: 2,
// tags: [ 'evan-digital-twin' ],
// identity:
// '0x1a496043385fec8d52f61e2b700413f8e12eb6e7e11649f80c8f4716c1063d06' }
// update description
description.version = '0.1.1';
await digitalTwin.setDescription(description);
// fetch again
console.dir(await digitalTwin.getDescription());
// Output:
// { name: 'test twin',
// description: 'twin from test run',
// author: 'evan GmbH',
// version: '0.1.1',
// dbcpVersion: 2,
// tags: [ 'evan-digital-twin' ],
// identity:
// '0x1a496043385fec8d52f61e2b700413f8e12eb6e7e11649f80c8f4716c1063d06' }
--------------------------------------------------------------------------------
= Profile =
===========
.. _digital-twin_addAsFavorite:
addAsFavorite
================================================================================
.. code-block:: typescript
digitalTwin.addAsFavorite();
Add the digital twin with given address to profile.
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
const digitalTwin = new DigitalTwin(options.config);
if (await digitalTwin.isFavorite()) {
console.log('I know this digital twin!');
} else {
await digitalTwin.addToFavorites();
console.log('bookmarked digital twin');
}
--------------------------------------------------------------------------------
.. _digital-twin_getFavorites:
getFavorites
================================================================================
.. code-block:: typescript
DigitalTwin.getFavorites();
Gets bookmarked twins from profile.
**Note, that this function is called on the Class DigitalTwin and not on an instance of it.**
----------
Parameters
----------
#. ``options`` - ``ContainerOptions``: runtime-like object with required modules
* ``contractLoader`` - |source contractLoader|_: |source contractLoader|_ instance
* ``cryptoProvider`` - |source cryptoProvider|_: |source cryptoProvider|_ instance
* ``dataContract`` - |source dataContract|_: |source dataContract|_ instance
* ``description`` - |source description|_: |source description|_ instance
* ``executor`` - |source executor|_: |source executor|_ instance
* ``nameResolver`` - |source nameResolver|_: |source nameResolver|_ instance
* ``rightsAndRoles`` - |source rightsAndRoles|_: |source rightsAndRoles|_ instance
* ``sharing`` - |source sharing|_: |source sharing|_ instance
* ``verifications`` - |source verifications|_: |source verifications|_ instance
* ``web3`` - |source web3|_: |source web3|_ instance
* ``log`` - ``Function`` (optional): function to use for logging: ``(message, level) => {...}``
* ``logLevel`` - |source logLevel|_ (optional): messages with this level will be logged with ``log``
* ``logLog`` - |source logLogInterface|_ (optional): container for collecting log messages
* ``logLogLevel`` - |source logLevel|_ (optional): messages with this level will be pushed to ``logLog``
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
const favorites = await DigitalTwin.getFavorites(options);
console.dir(favorites);
// Output:
// [
// 'example.somewhere.evan',
// 'another.example.somewhere.else.evan',
// '0x0000000000000000000000000000000000001234'
// ]
--------------------------------------------------------------------------------
.. _digital-twin_isFavorite:
isFavorite
================================================================================
.. code-block:: typescript
digitalTwin.isFavorite();
Check if this digital twin is bookmarked in profile.
-------
Returns
-------
``Promise`` returns ``boolean``: true if bookmarked
-------
Example
-------
.. code-block:: typescript
const digitalTwin = new DigitalTwin(options.config);
if (await digitalTwin.isFavorite()) {
console.log('I know this digital twin!');
} else {
await digitalTwin.addToFavorites();
console.log('bookmarked digital twin');
}
--------------------------------------------------------------------------------
.. _digital-twin_removeFromFavorites:
removeFromFavorites
================================================================================
.. code-block:: typescript
digitalTwin.removeFromFavorites();
Removes the current twin from the favorites in profile.
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
const digitalTwin = new DigitalTwin(options.config);
if (await digitalTwin.isFavorite()) {
await digitalTwin.removeFromFavorites();
console.log('removed digital twin from favorites');
}
--------------------------------------------------------------------------------
= Utilities =
=============
.. _digital-twin_getValidity:
getValidity
================================================================================
.. code-block:: typescript
DigitalTwin.getValidity(options, ensAddress);
Check if a valid contract is located under the specified address, which allows to check for twins before actually loading them.
Return value properties have the following meaning:
- ``valid``: ``true`` if contract could not be found or if it doesn't have the tag "evan-digital-twin"
- ``exists``: ``true`` if a contract address could be found at given ENS address
- ``error``: an error object, if one of the other properties is ``false``
**Note, that this function is called on the Class DigitalTwin and not on an instance of it.**
----------
Parameters
----------
#. ``options`` - ``DigitalTwinOptions``: twin runtime options
* ``contractLoader`` - |source contractLoader|_: |source contractLoader|_ instance
* ``cryptoProvider`` - |source cryptoProvider|_: |source cryptoProvider|_ instance
* ``dataContract`` - |source dataContract|_: |source dataContract|_ instance
* ``description`` - |source description|_: |source description|_ instance
* ``executor`` - |source executor|_: |source executor|_ instance
* ``nameResolver`` - |source nameResolver|_: |source nameResolver|_ instance
* ``rightsAndRoles`` - |source rightsAndRoles|_: |source rightsAndRoles|_ instance
* ``sharing`` - |source sharing|_: |source sharing|_ instance
* ``verifications`` - |source verifications|_: |source verifications|_ instance
* ``web3`` - |source web3|_: |source web3|_ instance
* ``log`` - ``Function`` (optional): function to use for logging: ``(message, level) => {...}``
* ``logLevel`` - |source logLevel|_ (optional): messages with this level will be logged with ``log``
* ``logLog`` - |source logLogInterface|_ (optional): container for collecting log messages
* ``logLogLevel`` - |source logLevel|_ (optional): messages with this level will be pushed to ``logLog``
#. ``ensAddress`` - ``string``: ens address that should be checked
-------
Returns
-------
``Promise`` returns ``{ valid: boolean, exists: boolean, error: Error }``: resolved when done
-------
Example
-------
.. code-block:: typescript
const { valid } = await DigitalTwin.getValidity(runtime, address);
if (!valid) {
throw new Error(`no valid digital twin found at "${address}"`);
}
--------------------------------------------------------------------------------
.. _digital-twin_ensureContract:
ensureContract
================================================================================
.. code-block:: typescript
digitalTwin.ensureContract();
Check if digital twin contract already has been loaded, load from address / ENS if required.
Throws if contract could not be loaded.
This function is more commonly used for internal checks in the ``DigitalTwin`` module. For checking, if a given address can be used, it is recommended to use :ref:`getValidity <digital-twin_getValidity>`.
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
let digitalTwin;
try {
digitalTwin = new DigitalTwin(options, config);
await digitalTwin.ensureContract();
// use digital twin
} catch (ex) {
console.error(`could use digital twin; ${ex.message || ex}`);
}
--------------------------------------------------------------------------------
.. _digital-twin_getContractAddress:
getContractAddress
================================================================================
.. code-block:: typescript
digitalTwin.getContractAddress();
Get contract address of underlying DigitalTwin.
-------
Returns
-------
``Promise`` returns ``string``: contract address
-------
Example
-------
.. code-block:: typescript
const digitalTwin = new DigitalTwin(options, config);
console.log(await digitalTwin.getContractAddress());
// Output:
// 0x000000000000000000000000000000001d327171
--------------------------------------------------------------------------------
Additional Components
=====================
Public Properties
=================
.. _digital-twin_defaultDescription:
---------------------------
defaultDescription (static)
---------------------------
Default description used when no specific description is given to :ref:`.create <digital-twin_create>`.
.. code-block:: typescript
console.dir(DigitalTwin.defaultDescription);
// Output:
// {
// name: 'Digital Identity',
// description: 'Digital Identity Contract',
// author: '',
// version: '0.1.0',
// dbcpVersion: 2
// }
--------------------------------------------------------------------------------
Enums
=====
.. _digital-twin_DigitalTwinEntryType:
------------------------
DigitalTwinEntryType
------------------------
possible entry types for entries in index
#. ``AccountId``
#. ``Container``
#. ``FileHash``
#. ``GenericContract``
#. ``Hash``
#. ``DigitalTwin``
Interfaces
==========
.. _digital-twin_ContainerConfig:
---------------------
DigitalTwinConfig
---------------------
config for digital twin
#. ``accountId`` - ``string``: account id of user, that interacts with digital twin
#. ``containerConfig`` - ``ContainerConfig``: address of a ``DigitalTwin`` instance, can be ENS or contract address
#. ``address`` - ``string`` (optional): address of an ``DigitalTwin`` instance, can be ENS or contract address
#. ``description`` - ``string`` (optional): description has to be passed to ``.create`` to apply it to to contract
#. ``factoryAddress`` - ``string`` (optional): factory address can be passed to ``.create`` for customer digital twin factory
.. _digital-twin_DigitalTwinIndexEntry:
-------------------------
DigitalTwinIndexEntry
-------------------------
container for digital twin entry values
#. ``entryType`` - ``DigitalTwinEntryType`` (optional): type of entry in index
#. ``raw`` - ``any`` (optional): raw value (``bytes32`` hash)
#. ``value`` - ``any`` (optional): decrypted/loaded value
.. _digital-twin_DigitalTwinVerificationEntry:
--------------------------------
DigitalTwinVerificationEntry
--------------------------------
data for verifications for digital twins
#. ``topic`` - ``string``: name of the verification (full path)
#. ``descriptionDomain`` - ``string`` (optional): domain of the verification, this is a subdomain under 'verifications.evan', so passing 'example' will link verifications
#. ``disableSubVerifications`` - ``boolean`` (optional): if true, verifications created under this path are invalid, defaults to ``false``
#. ``expirationDate`` - ``number`` (optional): expiration date, for the verification, defaults to `0` (does not expire)
#. ``verificationValue`` - ``any`` (optional): json object which will be stored in the verification
.. required for building markup
.. |source container| replace:: ``Container``
.. _source container: ../contracts/container.html
.. |source contractLoader| replace:: ``ContractLoader``
.. _source contractLoader: ../contracts/contract-loader.html
.. |source cryptoProvider| replace:: ``CryptoProvider``
.. _source cryptoProvider: ../encryption/crypto-provider.html
.. |source dataContract| replace:: ``DataContract``
.. _source dataContract: ../contracts/data-contract.html
.. |source description| replace:: ``Description``
.. _source description: ../blockchain/description.html
.. |source executor| replace:: ``Executor``
.. _source executor: ../blockchain/executor.html
.. |source logLevel| replace:: ``LogLevel``
.. _source logLevel: ../common/logger.html#loglevel
.. |source logLogInterface| replace:: ``LogLogInterface``
.. _source logLogInterface: ../common/logger.html#logloginterface
.. |source nameResolver| replace:: ``NameResolver``
.. _source nameResolver: ../blockchain/name-resolver.html
.. |source profile| replace:: ``Profile``
.. _source profile: ../profile/profile.html
.. |source rightsAndRoles| replace:: ``RightsAndRoles``
.. _source rightsAndRoles: ../contracts/rights-and-roles.html
.. |source sharing| replace:: ``Sharing``
.. _source sharing: ../contracts/sharing.html
.. |source verifications| replace:: ``Verifications``
.. _source verifications: ../profile/verifications.html
.. |source web3| replace:: ``Web3``
.. _source web3: https://github.com/ethereum/web3.js/