@peerbit/identity-access-controller 1.0.17 → 2.0.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.
- package/lib/esm/acl-db.d.ts +3 -4
- package/lib/esm/acl-db.js +13 -11
- package/lib/esm/acl-db.js.map +1 -1
- package/package.json +5 -5
- package/src/acl-db.ts +23 -11
package/lib/esm/acl-db.d.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { Documents, Role } from "@peerbit/document";
|
|
1
|
+
import { Documents, Role, TransactionContext, PutOperation, DeleteOperation } from "@peerbit/document";
|
|
2
2
|
import { TrustedNetwork, IdentityGraph } from "@peerbit/trusted-network";
|
|
3
3
|
import { Access } from "./access";
|
|
4
|
-
import { Entry } from "@peerbit/log";
|
|
5
4
|
import { PublicSignKey } from "@peerbit/crypto";
|
|
6
5
|
import { Program } from "@peerbit/program";
|
|
7
6
|
import { PeerId } from "@libp2p/interface-peer-id";
|
|
@@ -14,8 +13,8 @@ export declare class IdentityAccessController extends Program {
|
|
|
14
13
|
rootTrust: PublicSignKey | PeerId;
|
|
15
14
|
trustedNetwork?: TrustedNetwork;
|
|
16
15
|
});
|
|
17
|
-
canRead(s: PublicSignKey | undefined): Promise<boolean>;
|
|
18
|
-
|
|
16
|
+
canRead(_obj: any, s: PublicSignKey | undefined): Promise<boolean>;
|
|
17
|
+
canPerform(_operation: PutOperation<Access> | DeleteOperation, context: TransactionContext<Access>): Promise<boolean>;
|
|
19
18
|
open(properties?: {
|
|
20
19
|
role?: Role;
|
|
21
20
|
}): Promise<void>;
|
package/lib/esm/acl-db.js
CHANGED
|
@@ -8,7 +8,7 @@ var __metadata = (this && this.__metadata) || function (k, v) {
|
|
|
8
8
|
if (typeof Reflect === "object" && typeof Reflect.metadata === "function") return Reflect.metadata(k, v);
|
|
9
9
|
};
|
|
10
10
|
import { field, variant } from "@dao-xyz/borsh";
|
|
11
|
-
import { Documents, DocumentIndex } from "@peerbit/document";
|
|
11
|
+
import { Documents, DocumentIndex, } from "@peerbit/document";
|
|
12
12
|
import { getPathGenerator, TrustedNetwork, getFromByTo, IdentityGraph, createIdentityGraphStore, } from "@peerbit/trusted-network";
|
|
13
13
|
import { Access, AccessType } from "./access";
|
|
14
14
|
import { sha256Sync } from "@peerbit/crypto";
|
|
@@ -44,7 +44,7 @@ export let IdentityAccessController = class IdentityAccessController extends Pro
|
|
|
44
44
|
// can append will be anyone who has peformed some proof of work
|
|
45
45
|
// or
|
|
46
46
|
// custom can append
|
|
47
|
-
async canRead(s) {
|
|
47
|
+
async canRead(_obj, s) {
|
|
48
48
|
// TODO, improve, caching etc
|
|
49
49
|
if (!s) {
|
|
50
50
|
return false;
|
|
@@ -78,15 +78,15 @@ export let IdentityAccessController = class IdentityAccessController extends Pro
|
|
|
78
78
|
}
|
|
79
79
|
return false;
|
|
80
80
|
}
|
|
81
|
-
async
|
|
81
|
+
async canPerform(_operation, context) {
|
|
82
82
|
// TODO, improve, caching etc
|
|
83
83
|
// Check whether it is trusted by trust web
|
|
84
|
-
const
|
|
84
|
+
const canPerformByKey = async (key) => {
|
|
85
85
|
if (await this.trustedNetwork.isTrusted(key)) {
|
|
86
86
|
return true;
|
|
87
87
|
}
|
|
88
88
|
// Else check whether its trusted by this access controller
|
|
89
|
-
const
|
|
89
|
+
const canPerformCheck = async (key) => {
|
|
90
90
|
for (const value of this.access.index.index.values()) {
|
|
91
91
|
const access = value.value;
|
|
92
92
|
if (access instanceof Access) {
|
|
@@ -100,18 +100,18 @@ export let IdentityAccessController = class IdentityAccessController extends Pro
|
|
|
100
100
|
}
|
|
101
101
|
}
|
|
102
102
|
};
|
|
103
|
-
if (await
|
|
103
|
+
if (await canPerformCheck(key)) {
|
|
104
104
|
return true;
|
|
105
105
|
}
|
|
106
106
|
for await (const trustedByKey of getPathGenerator(key, this.identityGraphController.relationGraph, getFromByTo)) {
|
|
107
|
-
if (await
|
|
107
|
+
if (await canPerformCheck(trustedByKey.from)) {
|
|
108
108
|
return true;
|
|
109
109
|
}
|
|
110
110
|
}
|
|
111
111
|
return false;
|
|
112
112
|
};
|
|
113
|
-
for (const key of await entry.getPublicKeys()) {
|
|
114
|
-
if (await
|
|
113
|
+
for (const key of await context.entry.getPublicKeys()) {
|
|
114
|
+
if (await canPerformByKey(key)) {
|
|
115
115
|
return true;
|
|
116
116
|
}
|
|
117
117
|
}
|
|
@@ -125,8 +125,10 @@ export let IdentityAccessController = class IdentityAccessController extends Pro
|
|
|
125
125
|
await this.access.open({
|
|
126
126
|
role: properties?.role,
|
|
127
127
|
type: Access,
|
|
128
|
-
|
|
129
|
-
|
|
128
|
+
canPerform: this.canPerform.bind(this),
|
|
129
|
+
index: {
|
|
130
|
+
canRead: this.canRead.bind(this),
|
|
131
|
+
},
|
|
130
132
|
});
|
|
131
133
|
await this.trustedNetwork.open(properties);
|
|
132
134
|
}
|
package/lib/esm/acl-db.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"acl-db.js","sourceRoot":"","sources":["../../src/acl-db.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,
|
|
1
|
+
{"version":3,"file":"acl-db.js","sourceRoot":"","sources":["../../src/acl-db.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EACN,SAAS,EACT,aAAa,GAKb,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EACN,gBAAgB,EAChB,cAAc,EACd,WAAW,EACX,aAAa,EACb,wBAAwB,GACxB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAE9C,OAAO,EAAiB,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AA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GAAG,IAAI,MAAM,OAAO,CAAC,KAAK,CAAC,aAAa,EAAE,EAAE;YACtD,IAAI,MAAM,eAAe,CAAC,GAAG,CAAC,EAAE;gBAC/B,OAAO,IAAI,CAAC;aACZ;SACD;QACD,OAAO,KAAK,CAAC;IACd,CAAC;IAED,KAAK,CAAC,IAAI,CAAC,UAA4B;QACtC,MAAM,IAAI,CAAC,uBAAuB,CAAC,IAAI,CAAC;YACvC,IAAI,EAAE,UAAU,EAAE,IAAI;YACtB,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;SAChC,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;YACtB,IAAI,EAAE,UAAU,EAAE,IAAI;YACtB,IAAI,EAAE,MAAM;YACZ,UAAU,EAAE,IAAI,CAAC,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC;YACtC,KAAK,EAAE;gBACN,OAAO,EAAE,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;aAChC;SACD,CAAC,CAAC;QACH,MAAM,IAAI,CAAC,cAAc,CAAC,IAAI,CAAC,UAAU,CAAC,CAAC;IAC5C,CAAC;CACD,CAAA;AAjKA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;8BACnB,SAAS;wDAAS;AAG1B;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;8BACN,aAAa;yEAAC;AAGvC;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,cAAc,EAAE,CAAC;8BAChB,cAAc;gEAAC;AARnB,wBAAwB;IADpC,OAAO,CAAC,cAAc,CAAC;;GACX,wBAAwB,CAmKpC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@peerbit/identity-access-controller",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "2.0.0",
|
|
4
4
|
"description": "Access controller that operates on a DB",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"sideEffects": false,
|
|
@@ -31,12 +31,12 @@
|
|
|
31
31
|
"license": "MIT",
|
|
32
32
|
"dependencies": {
|
|
33
33
|
"@dao-xyz/borsh": "^5.1.5",
|
|
34
|
-
"@peerbit/document": "
|
|
35
|
-
"@peerbit/trusted-network": "
|
|
34
|
+
"@peerbit/document": "3.0.0",
|
|
35
|
+
"@peerbit/trusted-network": "2.0.0"
|
|
36
36
|
},
|
|
37
37
|
"devDependencies": {
|
|
38
|
-
"@peerbit/test-utils": "^1.0.
|
|
38
|
+
"@peerbit/test-utils": "^1.0.16",
|
|
39
39
|
"@peerbit/time": "^1.0.2"
|
|
40
40
|
},
|
|
41
|
-
"gitHead": "
|
|
41
|
+
"gitHead": "464e807d679e24b897b7811ac99d6f85fbd756f9"
|
|
42
42
|
}
|
package/src/acl-db.ts
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
import { field, variant } from "@dao-xyz/borsh";
|
|
2
|
-
import {
|
|
2
|
+
import {
|
|
3
|
+
Documents,
|
|
4
|
+
DocumentIndex,
|
|
5
|
+
Role,
|
|
6
|
+
TransactionContext,
|
|
7
|
+
PutOperation,
|
|
8
|
+
DeleteOperation,
|
|
9
|
+
} from "@peerbit/document";
|
|
3
10
|
import {
|
|
4
11
|
getPathGenerator,
|
|
5
12
|
TrustedNetwork,
|
|
@@ -62,7 +69,7 @@ export class IdentityAccessController extends Program {
|
|
|
62
69
|
|
|
63
70
|
// custom can append
|
|
64
71
|
|
|
65
|
-
async canRead(s: PublicSignKey | undefined): Promise<boolean> {
|
|
72
|
+
async canRead(_obj: any, s: PublicSignKey | undefined): Promise<boolean> {
|
|
66
73
|
// TODO, improve, caching etc
|
|
67
74
|
|
|
68
75
|
if (!s) {
|
|
@@ -110,16 +117,19 @@ export class IdentityAccessController extends Program {
|
|
|
110
117
|
return false;
|
|
111
118
|
}
|
|
112
119
|
|
|
113
|
-
async
|
|
120
|
+
async canPerform(
|
|
121
|
+
_operation: PutOperation<Access> | DeleteOperation,
|
|
122
|
+
context: TransactionContext<Access>
|
|
123
|
+
): Promise<boolean> {
|
|
114
124
|
// TODO, improve, caching etc
|
|
115
125
|
|
|
116
126
|
// Check whether it is trusted by trust web
|
|
117
|
-
const
|
|
127
|
+
const canPerformByKey = async (key: PublicSignKey): Promise<boolean> => {
|
|
118
128
|
if (await this.trustedNetwork.isTrusted(key)) {
|
|
119
129
|
return true;
|
|
120
130
|
}
|
|
121
131
|
// Else check whether its trusted by this access controller
|
|
122
|
-
const
|
|
132
|
+
const canPerformCheck = async (key: PublicSignKey) => {
|
|
123
133
|
for (const value of this.access.index.index.values()) {
|
|
124
134
|
const access = value.value;
|
|
125
135
|
if (access instanceof Access) {
|
|
@@ -137,7 +147,7 @@ export class IdentityAccessController extends Program {
|
|
|
137
147
|
}
|
|
138
148
|
}
|
|
139
149
|
};
|
|
140
|
-
if (await
|
|
150
|
+
if (await canPerformCheck(key)) {
|
|
141
151
|
return true;
|
|
142
152
|
}
|
|
143
153
|
for await (const trustedByKey of getPathGenerator(
|
|
@@ -145,7 +155,7 @@ export class IdentityAccessController extends Program {
|
|
|
145
155
|
this.identityGraphController.relationGraph,
|
|
146
156
|
getFromByTo
|
|
147
157
|
)) {
|
|
148
|
-
if (await
|
|
158
|
+
if (await canPerformCheck(trustedByKey.from)) {
|
|
149
159
|
return true;
|
|
150
160
|
}
|
|
151
161
|
}
|
|
@@ -153,8 +163,8 @@ export class IdentityAccessController extends Program {
|
|
|
153
163
|
return false;
|
|
154
164
|
};
|
|
155
165
|
|
|
156
|
-
for (const key of await entry.getPublicKeys()) {
|
|
157
|
-
if (await
|
|
166
|
+
for (const key of await context.entry.getPublicKeys()) {
|
|
167
|
+
if (await canPerformByKey(key)) {
|
|
158
168
|
return true;
|
|
159
169
|
}
|
|
160
170
|
}
|
|
@@ -169,8 +179,10 @@ export class IdentityAccessController extends Program {
|
|
|
169
179
|
await this.access.open({
|
|
170
180
|
role: properties?.role,
|
|
171
181
|
type: Access,
|
|
172
|
-
|
|
173
|
-
|
|
182
|
+
canPerform: this.canPerform.bind(this),
|
|
183
|
+
index: {
|
|
184
|
+
canRead: this.canRead.bind(this),
|
|
185
|
+
},
|
|
174
186
|
});
|
|
175
187
|
await this.trustedNetwork.open(properties);
|
|
176
188
|
}
|