-
Notifications
You must be signed in to change notification settings - Fork 1
/
claims.rst
747 lines (498 loc) · 21 KB
/
claims.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
================================================================================
Claims
================================================================================
.. list-table::
:widths: auto
:stub-columns: 1
* - Class Name
- Claims
* - Extends
- `Logger </common/logger.html>`_
* - Source
- `claims.ts <https://github.com/evannetwork/api-blockchain-core/blob/master/src/claims/claims.ts>`_
* - Tests
- `claims.spec.ts <https://github.com/evannetwork/api-blockchain-core/blob/master/src/claims/claims.spec.ts>`_
The ``Claims`` module allows to
- issue claims about oneself or about other parties
- confirm or delete claims about oneself
Claims have a pattern similar to file paths, a claim for an account called "foo" being an employee of a company called "bar" may look like this:
``/company/bar/employee``
Under this "path" a set of values can be found. These value describe the claim, the subject of the claim and optional its response to it. Basically an ``issuer`` creates a ``claim`` about a ``subject`` The values are:
- ``claim (name)``
full path to a claim, for example ``/company/bar/employee/foo``,
settable by the ``subject`` of the parent claim ``/company/bar/employee``
- ``subject``
an account, a claim has been issued for, can be a group/wallet or an externally owned account
being the ``subject`` of a ``claim`` basically means to be the owner of the claim and allows to create subclaims below the own claim path
- ``issuer``
an account (group/wallet or externally owned) that creates a claim,
to be able to issue a claim, the ``issuer`` has to be the ``subject`` of the parent claim ``/company/bar/employee``
- ``data``
The hash of the claim data, sitting in another location, a bit-mask, call data, or actual data based on the claim scheme.
- ``uri``
The location of the claim, this can be HTTP links, swarm hashes, IPFS hashes, and such.
- ``status``
this represents a ``claims`` status,
values are ``uint8`` range from 0 to 255, the currently used values are:
- 0: Issued
- 1: Confirmed
- ``signature``
Signature which is the proof that the claim issuer issued a claim of topic for this identity.
It MUST be a signed message of the following structure: keccak256(address identityHolder_address, uint256 _ topic, bytes data)
- ``creationDate``
creationDate of the claim
- ``id``
id of the current claim
- ``valid``
check if the claim has a valid signature
--------------------------------------------------------------------------------
.. _claims_constructor:
constructor
================================================================================
.. code-block:: typescript
new Claims(options);
Creates a new Claims instance.
Note, that the option properties ``registry`` and ``resolver`` are optional but should be provided
in most cases. As the module allows to create an own ENS structure, that includes an own ENS
registry and an own default resolver for it, setting them beforehand is optional.
----------
Parameters
----------
#. ``options`` - ``ClaimsOptions``: options for Claims constructor.
* ``accountStore`` - |source accountStore|_: |source accountStore|_ instance
* ``config`` - ``any``: config object with |source nameResolver|_ config
* ``contractLoader`` - |source contractLoader|_: |source contractLoader|_ instance
* ``description`` - |source description|_: |source description|_ instance
* ``dfs`` - |source dfsInterface|_: |source dfsInterface|_ instance
* ``executor`` - |source executor|_: |source executor|_ instance
* ``nameResolver`` - |source nameResolver|_: |source nameResolver|_ 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``
* ``storage`` - ``string`` (optional): contract address of the identity storage registry
-------
Returns
-------
``Claims`` instance
-------
Example
-------
.. code-block:: typescript
const claims = new Claims({
accountStore,
config,
contractLoader,
description,
dfs,
executor,
nameResolver,
storage: '0x0000000000000000000000000000000000000001',
});
--------------------------------------------------------------------------------
= Issuers =
==========================
.. _claims_createIdentity:
createIdentity
================================================================================
.. code-block:: typescript
claims.createIdentity(accountId[, contractId]);
Creates a new identity for account or contract and registers them on the storage. Returned identity is either a 40B contract address (for account identities) or a 32B idenity hash contract identities.
----------
Parameters
----------
#. ``accountId`` - ``string``: the account identifier
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
const identity = await claims.createIdentity(accounts[0]);
--------------------------------------------------------------------------------
.. _claims_identityAvailable:
identityAvailable
================================================================================
.. code-block:: typescript
claims.identityAvailable(subject);
Checks if a account has already an identity contract.
----------
Parameters
----------
#. ``subject`` - ``string``: target subject to check
-------
Returns
-------
``Promise`` returns ``boolean``: true if identity exists, otherwise false
-------
Example
-------
.. code-block:: typescript
console.log(await claims.identityAvailable(accounts[0]);
// Output:
// false
await await claims.createIdentity(accounts[0]);
console.log(await claims.identityAvailable(accounts[0]);
// Output:
// true
--------------------------------------------------------------------------------
.. _claims_getIdentityForAccount:
getIdentityForAccount
================================================================================
.. code-block:: typescript
claims.getIdentityForAccount(subject);
Gets the identity contract for a given account id or contract.
----------
Parameters
----------
#. ``subject`` - ``string``: target subject to get identity for
-------
Returns
-------
``Promise`` returns ``any``: identity contract instance
-------
Example
-------
.. code-block:: typescript
const identityContract = await claims.getIdentityForAccount(accounts[0]);
--------------------------------------------------------------------------------
.. _claims_setClaim:
setClaim
================================================================================
.. code-block:: typescript
claims.setClaim(issuer, subject, claimName[, expirationDate, claimValue, descriptionDomain]);
Sets or creates a claim; this requires the issuer to have permissions for the parent claim (if claim name seen as a path, the parent 'folder').
----------
Parameters
----------
#. ``issuer`` - ``string``: issuer of the claim
#. ``subject`` - ``string``: subject of the claim and the owner of the claim node
#. ``claimName`` - ``string``: name of the claim (full path)
#. ``expirationDate`` - ``number`` (optional): expiration date, for the claim, defaults to ``0`` (does not expire)
#. ``claimValue`` - ``string`` (optional): bytes32 hash of the claims value, will not be set if omitted
#. ``descriptionDomain`` - ``string`` (optional): domain of the claim, this is a subdomain under 'claims.evan', so passing 'example' will link claims description to 'example.claims.evan', unset if omitted
-------
Returns
-------
``Promise`` returns ``string``: id of new claim
-------
Example
-------
.. code-block:: typescript
// accounts[0] issues claim '/company' for accounts[1]
const firstClaim = await claims.setClaim(accounts[0], accounts[1], '/company');
// accounts[0] issues claim '/company' for accounts[1], sets an expiration date
// and links to description domain 'sample'
const secondClaim = await claims.setClaim(
accounts[0], accounts[1], '/company', expirationDate, claimValue, 'example');
--------------------------------------------------------------------------------
.. _claims_getClaims:
getClaims
================================================================================
.. code-block:: typescript
claims.getClaims(subject, claimName[, isIdentity]);
Gets claim information for a claim name from a given account; results has the following properties: creationBlock, creationDate, data, description, expirationDate, id, issuer, name, signature, status, subject, topic, uri, valid.
----------
Parameters
----------
#. ``subject`` - ``string``: subject of the claims
#. ``claimName`` - ``string``: name (/path) of a claim
#. ``isIdentity`` - ``string`` (optional): indicates if the subject is already an identity
-------
Returns
-------
``Promise`` returns ``any[]``: claim info array, contains: issuer, name, status, subject, data, uri, signature, creationDate
-------
Example
-------
.. code-block:: typescript
await claims.setClaim(accounts[0], accounts[1], '/company');
console.dir(await claims.getClaims(accounts[1], '/company'));
// Output:
[{
creationDate: 1234567890,
data: '0x0000000000000000000000000000000000000000000000000000000000000000',
description: {
name: 'sample claim',
description: 'I\'m a sample claim',
author: 'evan.network',
version: '1.0.0',
dbcpVersion: 1,
},
expirationDate: 1234567890,
id: '0x0000000000000000000000000000000000000000000000000000000000000000',
issuer: '0x0000000000000000000000000000000000000001',
name: '/company',
rejectReason: {
"rejected": "rejection message"
},
signature: '0x0000000000000000000000000000000000000000000000000000000000000000',
status: 0 (Issued) || 1 (Confirmed) || 2 (Rejected),
subject: '0x0000000000000000000000000000000000000002',
uri: '',
signature: '0x0000000000000000000000000000000000000000000000000000000000000000',
valid: true
}]
--------------------------------------------------------------------------------
.. _claims_identityAvailable:
identityAvailable
================================================================================
.. code-block:: typescript
claims.identityAvailable(subject);
checks if a account has already a identity contract
----------
Parameters
----------
#. ``subject`` - ``string``: subject of the claims
-------
Returns
-------
``Promise`` returns ``any``: true if identity exists, otherwise false
-------
Example
-------
.. code-block:: typescript
console.dir(await claims.identityAvailable(accounts[1]));
// Output:
true
--------------------------------------------------------------------------------
.. _claims_validateClaim:
validateClaim
================================================================================
.. code-block:: typescript
claims.validateClaim(subject, claimId[, isIdentity]);
validates a given claimId in case of integrity
----------
Parameters
----------
#. ``subject`` - ``string``: subject of the claims
#. ``claimId`` - ``string``: The claim identifier
#. ``isIdentity`` - ``boolean`` (optional): indicates if the subject is already an identity, defaults to ``false``
-------
Returns
-------
``Promise`` returns ``boolean``: resolves with true if the claim is valid, otherwise false
-------
Example
-------
.. code-block:: typescript
console.dir(await claims.validateClaim(
accounts[1]),
'0x0000000000000000000000000000000000000000000000000000000000000000',
);
// Output:
true
--------------------------------------------------------------------------------
.. _claims_validateClaimTree:
validateClaimTree
================================================================================
.. code-block:: typescript
claims.validateClaimTree(subject, claimLabel, treeArr);
validates a whole claim tree if the path is valid (called recursively)
----------
Parameters
----------
#. ``subject`` - ``string``: subject of the claims
#. ``claimLabel`` - ``string``: claim topic of a claim to build the tree for
#. ``treeArr`` - ``array`` (optional): result tree array, used for recursion, defaults to ``[]``
-------
Returns
-------
``Promise`` returns ``any[]``: Array with all resolved claims for the tree
-------
Example
-------
.. code-block:: typescript
console.dir(await claims.validateClaimTree(accounts[1], '/company/test/foo'));
// Output:
[{ issuer: '0x0000000000000000000000000000000000000001',
name: '/company/test/foo',
status: 1
subject: '0x0000000000000000000000000000000000000002',
data: '0x0000000000000000000000000000000000000000000000000000000000000000',
uri: '',
signature: '0x0000000000000000000000000000000000000000000000000000000000000000',
creationDate: 1234567890,
id: '0x0000000000000000000000000000000000000000000000000000000000000000',
valid: true },
{ issuer: '0x0000000000000000000000000000000000000001',
name: '/company/test',
status: 1
subject: '0x0000000000000000000000000000000000000002',
data: '0x0000000000000000000000000000000000000000000000000000000000000000',
uri: '',
signature: '0x0000000000000000000000000000000000000000000000000000000000000000',
creationDate: 1234567890,
id: '0x0000000000000000000000000000000000000000000000000000000000000000',
valid: true }]
--------------------------------------------------------------------------------
.. _claims_deleteClaim:
deleteClaim
================================================================================
.. code-block:: typescript
claims.deleteClaim(accountId, subject, claimId);
Delete a claim. This requires the **accountId** to have permissions for the parent claim (if claim name seen as a path, the parent 'folder'). Subjects of a claim may only delete it, if they are the issuer as well. If not, they can only react to it by confirming or rejecting the claim.
----------
Parameters
----------
#. ``accountid`` - ``string``: account, that performs the action
#. ``subject`` - ``string``: the subject of the claim
#. ``claimId`` - ``string``: id of a claim to delete
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
const claimId = await claims.setClaim(accounts[0], accounts[1], '/company');
await claims.deleteClaim(accounts[0], accounts[1], claimId);
--------------------------------------------------------------------------------
.. _claims_rejectClaim:
rejectClaim
================================================================================
.. code-block:: typescript
claims.rejectClaim(accountId, subject, claimId, rejectReason?);
Reject a Claim. This claim will be marked as rejected but not deleted. This is important for tracking reasons. You can also optionally add a reject reason as JSON object to track additional informations about the rejection. Issuer and Subject can reject a special claim.
----------
Parameters
----------
#. ``accountid`` - ``string``: account, that performs the action
#. ``subject`` - ``string``: the subject of the claim
#. ``claimId`` - ``string``: id of a claim to delete
#. ``rejectReason`` - ``object`` (optional): JSON Object of the rejection reason
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
const claimId = await claims.setClaim(accounts[0], accounts[1], '/company');
await claims.rejectClaim(accounts[0], accounts[1], claimId, { rejected: "because not valid anymore"});
--------------------------------------------------------------------------------
= Subjects =
==========================
.. _claims_confirmClaim:
confirmClaim
================================================================================
.. code-block:: typescript
claims.confirmClaim(accountId, subject, claimId);
Confirms a claim; this can be done, if a claim has been issued for a subject and the subject wants to confirms it.
----------
Parameters
----------
#. ``accountId`` - ``string``: account, that performs the action
#. ``subject`` - ``string``: claim subject
#. ``claimId`` - ``string``: id of a claim to confirm
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
const newClaim = await claims.setClaim(accounts[0], accounts[1], '/company');
await claims.confirmClaim(accounts[0], accounts[1], newClaim);
--------------------------------------------------------------------------------
= Descriptions =
==========================
.. _claims_setClaimDescription:
setClaimDescription
================================================================================
.. code-block:: typescript
claims.setClaimDescription(accountId, topic, domain, description);
Set description for a claim under a domain owned by given account. This sets the description at the ENS endpoint for a claim.
Notice, that this will **not** insert a description at the claim itself. Consider it as setting a global registry with the description for your claims and not as a label attached to a single claim.
So a setting a description for the claim ``/some/claim`` the subdomain ``example`` registers this at the ENS path `${sha3('/some/claim')}example.claims.evan``.
When this description has been set, it can be used when setting claims, e.g. with
.. code-block:: typescript
claims.setClaim(accounts[0], accounts[1], '/some/claim', expirationDate, claimValue, 'example');
A description can be setup even after claims have been issued. So it is recommended to use the claim domain when setting up claims, even if the description isn't required at the moment, when claims are set up.
----------
Parameters
----------
#. ``accountId`` - ``string``: accountId, that performs the description update
#. ``topic`` - ``string``: name of the claim (full path) to set description
#. ``domain`` - ``string``: domain of the claim, this is a subdomain under 'claims.evan', so passing 'example' will link claims description to 'example.claims.evan'
#. ``description`` - ``string``: DBCP description of the claim; can be an Envelope but only public properties are used
-------
Returns
-------
``Promise`` returns ``void``: resolved when done
-------
Example
-------
.. code-block:: typescript
const sampleClaimsDomain = 'sample';
const sampleClaimTopic = '/company';
const sampleDescription = {
name: 'sample claim',
description: 'I\'m a sample claim',
author: 'evan.network',
version: '1.0.0',
dbcpVersion: 1,
};
await claims.setClaimDescription(accounts[0], sampleClaimTopic, sampleClaimsDomain, sampleDescription);
await claims.setClaim(accounts[0], accounts[1], sampleClaimTopic, null, null, sampleClaimsDomain);
const claimsForAccount = await claims.getClaims(accounts[1], sampleClaimTopic);
const last = claimsForAccount.length - 1;
console.dir(claimsForAccount[last].description);
// Output:
// {
// name: 'sample claim',
// description: 'I\'m a sample claim',
// author: 'evan.network',
// version: '1.0.0',
// dbcpVersion: 1,
// }
--------------------------------------------------------------------------------
= Deployment =
==========================
.. _claims_createStructure:
createStructure
================================================================================
.. code-block:: typescript
claims.createStructure(accountId);
Create a new claims structure; this includes a userregistry and the associated libraries. This
isn't required for creating a module instance, its is solely used for creating new structures on the
blockchain.
----------
Parameters
----------
#. ``accountId`` - ``string``: account, that execute the transaction and owner of the new registry
-------
Returns
-------
``Promise`` returns ``any``: object with property 'storage', that is a web3js
contract instance
-------
Example
-------
.. code-block:: typescript
const claimsStructure = await claims.createStructure(accountId);
console.log(claimsStructure.storage.options.address);
// Output:
// 0x000000000000000000000000000000000000000a
.. required for building markup
.. |source accountStore| replace:: ``AccountStore``
.. _source accountStore: /blockchain/account-store.html
.. |source contractLoader| replace:: ``ContractLoader``
.. _source contractLoader: /contracts/contract-loader.html
.. |source description| replace:: ``Description``
.. _source description: /blockchain/description.html
.. |source dfsInterface| replace:: ``DfsInterface``
.. _source dfsInterface: /dfs/dfs-interface.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