@peerbit/trusted-network 3.0.40-aa577a5 → 3.0.40-cccc078
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/dist/src/controller.d.ts +11 -11
- package/dist/src/controller.d.ts.map +1 -1
- package/dist/src/controller.js +32 -29
- package/dist/src/controller.js.map +1 -1
- package/dist/src/identity-graph.d.ts +13 -7
- package/dist/src/identity-graph.d.ts.map +1 -1
- package/dist/src/identity-graph.js +34 -12
- package/dist/src/identity-graph.js.map +1 -1
- package/package.json +10 -9
- package/src/controller.ts +59 -52
- package/src/identity-graph.ts +50 -27
package/dist/src/controller.d.ts
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { type AppendOptions } from "@peerbit/log";
|
|
1
|
+
import { type PeerId } from "@libp2p/interface";
|
|
3
2
|
import { PublicSignKey } from "@peerbit/crypto";
|
|
4
|
-
import {
|
|
3
|
+
import { type CanPerformOperations, type CanRead, Documents, Operation } from "@peerbit/document";
|
|
4
|
+
import { type AppendOptions } from "@peerbit/log";
|
|
5
5
|
import { Program } from "@peerbit/program";
|
|
6
|
-
import { type
|
|
7
|
-
import {
|
|
6
|
+
import { type ReplicationOptions } from "@peerbit/shared-log";
|
|
7
|
+
import { FromTo, IdentityRelation } from "./identity-graph.js";
|
|
8
8
|
type IdentityGraphArgs = {
|
|
9
9
|
canRead?: CanRead<IdentityRelation>;
|
|
10
|
-
|
|
10
|
+
replicate?: ReplicationOptions;
|
|
11
11
|
};
|
|
12
12
|
export declare class IdentityGraph extends Program<IdentityGraphArgs> {
|
|
13
|
-
relationGraph: Documents<IdentityRelation>;
|
|
13
|
+
relationGraph: Documents<IdentityRelation, FromTo>;
|
|
14
14
|
constructor(props?: {
|
|
15
15
|
id?: Uint8Array;
|
|
16
|
-
relationGraph?: Documents<IdentityRelation>;
|
|
16
|
+
relationGraph?: Documents<IdentityRelation, FromTo>;
|
|
17
17
|
});
|
|
18
18
|
canPerform(properties: CanPerformOperations<IdentityRelation>): Promise<boolean>;
|
|
19
19
|
open(options?: IdentityGraphArgs): Promise<void>;
|
|
@@ -23,11 +23,11 @@ export declare class IdentityGraph extends Program<IdentityGraphArgs> {
|
|
|
23
23
|
* Not shardeable since we can not query trusted relations, because this would lead to a recursive problem where we then need to determine whether the responder is trusted or not
|
|
24
24
|
*/
|
|
25
25
|
type TrustedNetworkArgs = {
|
|
26
|
-
|
|
26
|
+
replicate?: ReplicationOptions;
|
|
27
27
|
};
|
|
28
28
|
export declare class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
29
29
|
rootTrust: PublicSignKey;
|
|
30
|
-
trustGraph: Documents<IdentityRelation>;
|
|
30
|
+
trustGraph: Documents<IdentityRelation, FromTo>;
|
|
31
31
|
constructor(props: {
|
|
32
32
|
id?: Uint8Array;
|
|
33
33
|
rootTrust: PublicSignKey | PeerId;
|
|
@@ -45,7 +45,7 @@ export declare class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
|
45
45
|
* Root trust A trust B trust C
|
|
46
46
|
* C is trusted by Root
|
|
47
47
|
* @param trustee
|
|
48
|
-
* @param truster
|
|
48
|
+
* @param truster the truster "root", if undefined defaults to the root trust
|
|
49
49
|
* @returns true, if trusted
|
|
50
50
|
*/
|
|
51
51
|
isTrusted(trustee: PublicSignKey, truster?: PublicSignKey): Promise<boolean>;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller.ts"],"names":[],"mappings":"AACA,OAAO,
|
|
1
|
+
{"version":3,"file":"controller.d.ts","sourceRoot":"","sources":["../../src/controller.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACN,aAAa,EAGb,MAAM,iBAAiB,CAAC;AACzB,OAAO,EACN,KAAK,oBAAoB,EACzB,KAAK,OAAO,EACZ,SAAS,EACT,SAAS,EACT,MAA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AAC,OAAO,CAAC,EAAE,kBAAkB;IAcjC,UAAU,CACf,UAAU,EAAE,oBAAoB,CAAC,gBAAgB,CAAC,GAChD,OAAO,CAAC,OAAO,CAAC;IAIb,OAAO,CAAC,QAAQ,EAAE,GAAG,EAAE,SAAS,CAAC,EAAE,aAAa,GAAG,OAAO,CAAC,OAAO,CAAC;IAInE,GAAG,CACR,OAAO,EAAE,aAAa,GAAG,MAAM,GAC7B,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAAC;IAqBlC,WAAW,CAChB,OAAO,EAAE,aAAa,GAAG,MAAM,EAC/B,OAAO,GAAE,aAAa,GAAG,MAAuB;IAIjD,WAAW,CACV,OAAO,EAAE,aAAa,GAAG,MAAM,EAC/B,OAAO,GAAE,aAAa,GAAG,MAAuB;IASjD;;;;;;;;;OASG;IACG,SAAS,CACd,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE,aAA8B,GACrC,OAAO,CAAC,OAAO,CAAC;IAcb,eAAe,CACpB,OAAO,EAAE,aAAa,EACtB,OAAO,GAAE,aAA8B,GACrC,OAAO,CAAC,OAAO,CAAC;IAUb,UAAU,IAAI,OAAO,CAAC,aAAa,EAAE,CAAC;IAU5C,QAAQ,IAAI,MAAM;CAGlB"}
|
package/dist/src/controller.js
CHANGED
|
@@ -8,14 +8,14 @@ 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, serialize, variant } from "@dao-xyz/borsh";
|
|
11
|
-
import {
|
|
11
|
+
import {} from "@libp2p/interface";
|
|
12
|
+
import { PublicSignKey, getPublicKeyFromPeerId, sha256Base64Sync, } from "@peerbit/crypto";
|
|
13
|
+
import { Documents, Operation, } from "@peerbit/document";
|
|
14
|
+
import { SearchRequest } from "@peerbit/indexer-interface";
|
|
12
15
|
import {} from "@peerbit/log";
|
|
13
|
-
import { PublicSignKey, getPublicKeyFromPeerId } from "@peerbit/crypto";
|
|
14
|
-
import { IdentityRelation, createIdentityGraphStore, getPathGenerator, hasPath, getFromByTo, getToByFrom, getRelation } from "./identity-graph.js";
|
|
15
16
|
import { Program } from "@peerbit/program";
|
|
16
|
-
import {
|
|
17
|
-
import {} from "
|
|
18
|
-
import { Replicator } from "@peerbit/shared-log";
|
|
17
|
+
import {} from "@peerbit/shared-log";
|
|
18
|
+
import { FromTo, IdentityRelation, createIdentityGraphStore, getFromByTo, getPathGenerator, getRelation, getToByFrom, hasPath, } from "./identity-graph.js";
|
|
19
19
|
const coercePublicKey = (publicKey) => {
|
|
20
20
|
return publicKey instanceof PublicSignKey
|
|
21
21
|
? publicKey
|
|
@@ -68,23 +68,18 @@ let IdentityGraph = class IdentityGraph extends Program {
|
|
|
68
68
|
await this.relationGraph.open({
|
|
69
69
|
type: IdentityRelation,
|
|
70
70
|
canPerform: this.canPerform.bind(this),
|
|
71
|
-
|
|
71
|
+
replicate: options?.replicate,
|
|
72
72
|
index: {
|
|
73
73
|
canRead: options?.canRead,
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
from: obj.from.hashcode(),
|
|
77
|
-
to: obj.to.hashcode()
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
}
|
|
74
|
+
type: FromTo,
|
|
75
|
+
},
|
|
81
76
|
});
|
|
82
77
|
}
|
|
83
78
|
async addRelation(to, options) {
|
|
84
79
|
/* trustee = PublicKey.from(trustee); */
|
|
85
80
|
await this.relationGraph.put(new IdentityRelation({
|
|
86
81
|
to: coercePublicKey(to),
|
|
87
|
-
from: options?.identity?.publicKey || this.node.identity.publicKey
|
|
82
|
+
from: options?.identity?.publicKey || this.node.identity.publicKey,
|
|
88
83
|
}), options);
|
|
89
84
|
}
|
|
90
85
|
};
|
|
@@ -109,19 +104,13 @@ let TrustedNetwork = class TrustedNetwork extends Program {
|
|
|
109
104
|
await this.trustGraph.open({
|
|
110
105
|
type: IdentityRelation,
|
|
111
106
|
canPerform: this.canPerform.bind(this),
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
factor: 1
|
|
107
|
+
replicate: options?.replicate || {
|
|
108
|
+
factor: 1,
|
|
115
109
|
},
|
|
116
110
|
index: {
|
|
117
111
|
canRead: this.canRead.bind(this),
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
from: obj.from.hashcode(),
|
|
121
|
-
to: obj.to.hashcode()
|
|
122
|
-
};
|
|
123
|
-
}
|
|
124
|
-
}
|
|
112
|
+
type: FromTo,
|
|
113
|
+
},
|
|
125
114
|
}); // self referencing access controller
|
|
126
115
|
}
|
|
127
116
|
async canPerform(properties) {
|
|
@@ -138,7 +127,7 @@ let TrustedNetwork = class TrustedNetwork extends Program {
|
|
|
138
127
|
if (!existingRelation) {
|
|
139
128
|
const relation = new IdentityRelation({
|
|
140
129
|
to: key,
|
|
141
|
-
from: this.node.identity.publicKey
|
|
130
|
+
from: this.node.identity.publicKey,
|
|
142
131
|
});
|
|
143
132
|
await this.trustGraph.put(relation);
|
|
144
133
|
return relation;
|
|
@@ -158,19 +147,19 @@ let TrustedNetwork = class TrustedNetwork extends Program {
|
|
|
158
147
|
* Root trust A trust B trust C
|
|
159
148
|
* C is trusted by Root
|
|
160
149
|
* @param trustee
|
|
161
|
-
* @param truster
|
|
150
|
+
* @param truster the truster "root", if undefined defaults to the root trust
|
|
162
151
|
* @returns true, if trusted
|
|
163
152
|
*/
|
|
164
153
|
async isTrusted(trustee, truster = this.rootTrust) {
|
|
165
154
|
if (trustee.equals(this.rootTrust)) {
|
|
166
155
|
return true;
|
|
167
156
|
}
|
|
168
|
-
if (this.trustGraph.log.
|
|
157
|
+
if (await this.trustGraph.log.isReplicating()) {
|
|
169
158
|
return this._isTrustedLocal(trustee, truster);
|
|
170
159
|
}
|
|
171
160
|
else {
|
|
172
161
|
this.trustGraph.index.search(new SearchRequest({ query: [] }), {
|
|
173
|
-
remote: { sync: true }
|
|
162
|
+
remote: { sync: true },
|
|
174
163
|
});
|
|
175
164
|
return this._isTrustedLocal(trustee, truster);
|
|
176
165
|
}
|
|
@@ -205,4 +194,18 @@ TrustedNetwork = __decorate([
|
|
|
205
194
|
__metadata("design:paramtypes", [Object])
|
|
206
195
|
], TrustedNetwork);
|
|
207
196
|
export { TrustedNetwork };
|
|
197
|
+
/* TODO do we need these decorator functions?
|
|
198
|
+
export const getNetwork = (object: any): TrustedNetwork | undefined => {
|
|
199
|
+
return (
|
|
200
|
+
object.constructor.prototype._network &&
|
|
201
|
+
object[object.constructor.prototype._network]
|
|
202
|
+
);
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
export function network(options: { property: string }) {
|
|
206
|
+
return (constructor: any) => {
|
|
207
|
+
constructor.prototype._network = options.property;
|
|
208
|
+
};
|
|
209
|
+
}
|
|
210
|
+
*/
|
|
208
211
|
//# sourceMappingURL=controller.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/controller.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EACN,aAAa,EACb,
|
|
1
|
+
{"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/controller.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AAC3D,OAAO,EAAe,MAAM,mBAAmB,CAAC;AAChD,OAAO,EACN,aAAa,EACb,sBAAsB,EACtB,gBAAgB,GAChB,MAAM,iBAAiB,CAAC;AACzB,OAAO,EAGN,SAAS,EACT,SAAS,GACT,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,aAAa,EAAE,MAAM,4BAA4B,CAAC;AAC3D,OAAO,EAAsB,MAAM,cAAc,CAAC;AAClD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAA2B,MAA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H,OAAO,IAAI,CAAC,eAAe,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC;QAC/C,CAAC;IACF,CAAC;IAED,KAAK,CAAC,eAAe,CACpB,OAAsB,EACtB,UAAyB,IAAI,CAAC,SAAS;QAEvC,MAAM,SAAS,GAAG,MAAM,OAAO,CAC9B,OAAO,EACP,OAAO,EACP,IAAI,CAAC,UAAU,EACf,WAAW,CACX,CAAC;QACF,OAAO,CAAC,CAAC,SAAS,CAAC;IACpB,CAAC;IAED,KAAK,CAAC,UAAU;QACf,MAAM,OAAO,GAAG,IAAI,CAAC,SAAS,CAAC;QAC/B,MAAM,YAAY,GAAoB,CAAC,OAAO,CAAC,CAAC;QAChD,MAAM,SAAS,GAAG,gBAAgB,CAAC,OAAO,EAAE,IAAI,CAAC,UAAU,EAAE,WAAW,CAAC,CAAC;QAC1E,IAAI,KAAK,EAAE,MAAM,IAAI,IAAI,SAAS,EAAE,CAAC;YACpC,YAAY,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE,CAAC,CAAC;QAC5B,CAAC;QACD,OAAO,YAAY,CAAC;IACrB,CAAC;IAED,QAAQ;QACP,OAAO,gBAAgB,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC,CAAC;IAC1C,CAAC;CACD,CAAA;AAhIA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;8BACpB,aAAa;iDAAC;AAGzB;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,SAAS,EAAE,CAAC;8BACf,SAAS;kDAA2B;AALpC,cAAc;IAD1B,OAAO,CAAC,iBAAiB,CAAC;;GACd,cAAc,CAkI1B;;AACD;;;;;;;;;;;;;EAaE"}
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import { Documents } from "@peerbit/document";
|
|
2
1
|
import { PublicSignKey } from "@peerbit/crypto";
|
|
2
|
+
import { Documents } from "@peerbit/document";
|
|
3
3
|
export type RelationResolver = {
|
|
4
|
-
resolve: (key: PublicSignKey, db: Documents<IdentityRelation>) => Promise<IdentityRelation[]>;
|
|
4
|
+
resolve: (key: PublicSignKey, db: Documents<IdentityRelation, FromTo>) => Promise<IdentityRelation[]>;
|
|
5
5
|
next: (relation: IdentityRelation) => PublicSignKey;
|
|
6
6
|
};
|
|
7
7
|
export declare const getFromByTo: RelationResolver;
|
|
8
8
|
export declare const getToByFrom: RelationResolver;
|
|
9
|
-
export declare function getPathGenerator(from: PublicSignKey, db: Documents<IdentityRelation>, resolver: RelationResolver): AsyncGenerator<IdentityRelation, void, unknown>;
|
|
9
|
+
export declare function getPathGenerator(from: PublicSignKey, db: Documents<IdentityRelation, FromTo>, resolver: RelationResolver): AsyncGenerator<IdentityRelation, void, unknown>;
|
|
10
10
|
/**
|
|
11
11
|
* Get path, to target.
|
|
12
12
|
* @param start
|
|
@@ -14,7 +14,7 @@ export declare function getPathGenerator(from: PublicSignKey, db: Documents<Iden
|
|
|
14
14
|
* @param db
|
|
15
15
|
* @returns
|
|
16
16
|
*/
|
|
17
|
-
export declare const hasPathToTarget: (start: PublicSignKey, target: (key: PublicSignKey) => boolean, db: Documents<IdentityRelation>, resolver: RelationResolver) => Promise<boolean>;
|
|
17
|
+
export declare const hasPathToTarget: (start: PublicSignKey, target: (key: PublicSignKey) => boolean, db: Documents<IdentityRelation, FromTo>, resolver: RelationResolver) => Promise<boolean>;
|
|
18
18
|
export declare abstract class AbstractRelation {
|
|
19
19
|
id: Uint8Array;
|
|
20
20
|
}
|
|
@@ -30,7 +30,13 @@ export declare class IdentityRelation extends AbstractRelation {
|
|
|
30
30
|
initializeId(): void;
|
|
31
31
|
static id(to: PublicSignKey, from: PublicSignKey): Uint8Array;
|
|
32
32
|
}
|
|
33
|
-
export declare const hasPath: (start: PublicSignKey, end: PublicSignKey, db: Documents<IdentityRelation>, resolver: RelationResolver) => Promise<boolean>;
|
|
34
|
-
export declare const getRelation: (from: PublicSignKey, to: PublicSignKey, db: Documents<IdentityRelation>) => Promise<IdentityRelation | undefined>;
|
|
35
|
-
export declare
|
|
33
|
+
export declare const hasPath: (start: PublicSignKey, end: PublicSignKey, db: Documents<IdentityRelation, FromTo>, resolver: RelationResolver) => Promise<boolean>;
|
|
34
|
+
export declare const getRelation: (from: PublicSignKey, to: PublicSignKey, db: Documents<IdentityRelation, FromTo>) => Promise<IdentityRelation | undefined>;
|
|
35
|
+
export declare class FromTo {
|
|
36
|
+
id: Uint8Array;
|
|
37
|
+
from: string;
|
|
38
|
+
to: string;
|
|
39
|
+
constructor(props: IdentityRelation, _context?: any);
|
|
40
|
+
}
|
|
41
|
+
export declare const createIdentityGraphStore: (id?: Uint8Array) => Documents<IdentityRelation, FromTo>;
|
|
36
42
|
//# sourceMappingURL=identity-graph.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-graph.d.ts","sourceRoot":"","sources":["../../src/identity-graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"identity-graph.d.ts","sourceRoot":"","sources":["../../src/identity-graph.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,aAAa,EAAc,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAI9C,MAAM,MAAM,gBAAgB,GAAG;IAC9B,OAAO,EAAE,CACR,GAAG,EAAE,aAAa,EAClB,EAAE,EAAE,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,KACnC,OAAO,CAAC,gBAAgB,EAAE,CAAC,CAAC;IACjC,IAAI,EAAE,CAAC,QAAQ,EAAE,gBAAgB,KAAK,aAAa,CAAC;CACpD,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,gBAmBzB,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,gBAmBzB,CAAC;AAEF,wBAAuB,gBAAgB,CACtC,IAAI,EAAE,aAAa,EACnB,EAAE,EAAE,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,EACvC,QAAQ,EAAE,gBAAgB,m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{ field, fixedArray, serialize, variant } from "@dao-xyz/borsh";
|
|
12
|
-
import {
|
|
13
|
-
import {
|
|
12
|
+
import { PublicSignKey, sha256Sync } from "@peerbit/crypto";
|
|
13
|
+
import { Documents } from "@peerbit/document";
|
|
14
|
+
import { SearchRequest, StringMatch } from "@peerbit/indexer-interface";
|
|
14
15
|
import { concat } from "uint8arrays";
|
|
15
|
-
import { sha256Sync } from "@peerbit/crypto";
|
|
16
16
|
export const getFromByTo = {
|
|
17
17
|
resolve: async (to, db) => {
|
|
18
18
|
return Promise.all(await db.index.search(new SearchRequest({
|
|
19
19
|
query: [
|
|
20
20
|
new StringMatch({
|
|
21
21
|
key: "to",
|
|
22
|
-
value: to.hashcode()
|
|
23
|
-
})
|
|
24
|
-
]
|
|
22
|
+
value: to.hashcode(),
|
|
23
|
+
}),
|
|
24
|
+
],
|
|
25
25
|
})));
|
|
26
26
|
},
|
|
27
|
-
next: (relation) => relation.from
|
|
27
|
+
next: (relation) => relation.from,
|
|
28
28
|
};
|
|
29
29
|
export const getToByFrom = {
|
|
30
30
|
resolve: async (from, db) => {
|
|
@@ -32,12 +32,12 @@ export const getToByFrom = {
|
|
|
32
32
|
query: [
|
|
33
33
|
new StringMatch({
|
|
34
34
|
key: "from",
|
|
35
|
-
value: from.hashcode()
|
|
36
|
-
})
|
|
37
|
-
]
|
|
35
|
+
value: from.hashcode(),
|
|
36
|
+
}),
|
|
37
|
+
],
|
|
38
38
|
})));
|
|
39
39
|
},
|
|
40
|
-
next: (relation) => relation.to
|
|
40
|
+
next: (relation) => relation.to,
|
|
41
41
|
};
|
|
42
42
|
export async function* getPathGenerator(from, db, resolver) {
|
|
43
43
|
let iter = [from];
|
|
@@ -137,7 +137,29 @@ export const hasPath = async (start, end, db, resolver) => {
|
|
|
137
137
|
export const getRelation = async (from, to, db) => {
|
|
138
138
|
return db.index.get(new IdentityRelation({ from, to }).id);
|
|
139
139
|
};
|
|
140
|
+
export class FromTo {
|
|
141
|
+
id;
|
|
142
|
+
from;
|
|
143
|
+
to;
|
|
144
|
+
constructor(props, _context) {
|
|
145
|
+
this.from = props.from.hashcode();
|
|
146
|
+
this.to = props.to.hashcode();
|
|
147
|
+
this.id = props.id;
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
__decorate([
|
|
151
|
+
field({ type: fixedArray("u8", 32) }),
|
|
152
|
+
__metadata("design:type", Uint8Array)
|
|
153
|
+
], FromTo.prototype, "id", void 0);
|
|
154
|
+
__decorate([
|
|
155
|
+
field({ type: "string" }),
|
|
156
|
+
__metadata("design:type", String)
|
|
157
|
+
], FromTo.prototype, "from", void 0);
|
|
158
|
+
__decorate([
|
|
159
|
+
field({ type: "string" }),
|
|
160
|
+
__metadata("design:type", String)
|
|
161
|
+
], FromTo.prototype, "to", void 0);
|
|
140
162
|
export const createIdentityGraphStore = (id) => new Documents({
|
|
141
|
-
id
|
|
163
|
+
id,
|
|
142
164
|
});
|
|
143
165
|
//# sourceMappingURL=identity-graph.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"identity-graph.js","sourceRoot":"","sources":["../../src/identity-graph.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"identity-graph.js","sourceRoot":"","sources":["../../src/identity-graph.ts"],"names":[],"mappings":";;;;;;;;;;AAAA,OAAO,EAAE,KAAK,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,gBAAgB,CAAC;AACvE,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,iBAAiB,CAAC;AAC5D,OAAO,EAAE,SAAS,EAAE,MAAM,mBAAmB,CAAC;AAC9C,OAAO,EAAE,aAAa,EAAE,WAAW,EAAE,MAAM,4BAA4B,CAAC;AACxE,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AA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
|
3
|
-
"version": "3.0.40-
|
|
3
|
+
"version": "3.0.40-cccc078",
|
|
4
4
|
"description": "Access controller that operates on a DB",
|
|
5
|
-
"type": "module",
|
|
6
5
|
"sideEffects": false,
|
|
6
|
+
"type": "module",
|
|
7
7
|
"types": "./dist/src/index.d.ts",
|
|
8
8
|
"typesVersions": {
|
|
9
9
|
"*": {
|
|
@@ -35,7 +35,7 @@
|
|
|
35
35
|
}
|
|
36
36
|
},
|
|
37
37
|
"eslintConfig": {
|
|
38
|
-
"extends": "
|
|
38
|
+
"extends": "peerbit",
|
|
39
39
|
"parserOptions": {
|
|
40
40
|
"project": true,
|
|
41
41
|
"sourceType": "module"
|
|
@@ -52,18 +52,19 @@
|
|
|
52
52
|
"scripts": {
|
|
53
53
|
"clean": "aegir clean",
|
|
54
54
|
"build": "aegir build --no-bundle",
|
|
55
|
-
"test": "aegir test --target node"
|
|
55
|
+
"test": "aegir test --target node",
|
|
56
|
+
"lint": "aegir lint"
|
|
56
57
|
},
|
|
57
58
|
"author": "dao.xyz",
|
|
58
59
|
"license": "MIT",
|
|
59
60
|
"dependencies": {
|
|
60
|
-
"@dao-xyz/borsh": "^5.2.
|
|
61
|
-
"@peerbit/crypto": "2.2.0-
|
|
62
|
-
"@peerbit/document": "6.0.7-
|
|
61
|
+
"@dao-xyz/borsh": "^5.2.3",
|
|
62
|
+
"@peerbit/crypto": "2.2.0-cccc078",
|
|
63
|
+
"@peerbit/document": "6.0.7-cccc078"
|
|
63
64
|
},
|
|
64
65
|
"devDependencies": {
|
|
65
|
-
"@peerbit/time": "2.0.6-
|
|
66
|
+
"@peerbit/time": "2.0.6-cccc078",
|
|
66
67
|
"@ethersproject/wallet": "^5.7.0",
|
|
67
|
-
"@peerbit/test-utils": "2.0.33-
|
|
68
|
+
"@peerbit/test-utils": "2.0.33-cccc078"
|
|
68
69
|
}
|
|
69
70
|
}
|
package/src/controller.ts
CHANGED
|
@@ -1,26 +1,30 @@
|
|
|
1
1
|
import { field, serialize, variant } from "@dao-xyz/borsh";
|
|
2
|
+
import { type PeerId } from "@libp2p/interface";
|
|
3
|
+
import {
|
|
4
|
+
PublicSignKey,
|
|
5
|
+
getPublicKeyFromPeerId,
|
|
6
|
+
sha256Base64Sync,
|
|
7
|
+
} from "@peerbit/crypto";
|
|
2
8
|
import {
|
|
3
|
-
|
|
9
|
+
type CanPerformOperations,
|
|
10
|
+
type CanRead,
|
|
4
11
|
Documents,
|
|
5
12
|
Operation,
|
|
6
|
-
type CanRead,
|
|
7
|
-
type CanPerformOperations
|
|
8
13
|
} from "@peerbit/document";
|
|
14
|
+
import { SearchRequest } from "@peerbit/indexer-interface";
|
|
9
15
|
import { type AppendOptions } from "@peerbit/log";
|
|
10
|
-
import {
|
|
16
|
+
import { Program } from "@peerbit/program";
|
|
17
|
+
import { type ReplicationOptions } from "@peerbit/shared-log";
|
|
11
18
|
import {
|
|
19
|
+
FromTo,
|
|
12
20
|
IdentityRelation,
|
|
13
21
|
createIdentityGraphStore,
|
|
14
|
-
getPathGenerator,
|
|
15
|
-
hasPath,
|
|
16
22
|
getFromByTo,
|
|
23
|
+
getPathGenerator,
|
|
24
|
+
getRelation,
|
|
17
25
|
getToByFrom,
|
|
18
|
-
|
|
26
|
+
hasPath,
|
|
19
27
|
} from "./identity-graph.js";
|
|
20
|
-
import { Program } from "@peerbit/program";
|
|
21
|
-
import { sha256Base64Sync } from "@peerbit/crypto";
|
|
22
|
-
import { type PeerId } from "@libp2p/interface";
|
|
23
|
-
import { Replicator, type RoleOptions } from "@peerbit/shared-log";
|
|
24
28
|
|
|
25
29
|
const coercePublicKey = (publicKey: PublicSignKey | PeerId) => {
|
|
26
30
|
return publicKey instanceof PublicSignKey
|
|
@@ -29,7 +33,7 @@ const coercePublicKey = (publicKey: PublicSignKey | PeerId) => {
|
|
|
29
33
|
};
|
|
30
34
|
const canPerformByRelation = async (
|
|
31
35
|
properties: CanPerformOperations<IdentityRelation>,
|
|
32
|
-
isTrusted?: (key: PublicSignKey) => Promise<boolean
|
|
36
|
+
isTrusted?: (key: PublicSignKey) => Promise<boolean>,
|
|
33
37
|
): Promise<boolean> => {
|
|
34
38
|
// verify the payload
|
|
35
39
|
const keys = await properties.entry.getPublicKeys();
|
|
@@ -65,17 +69,17 @@ const canPerformByRelation = async (
|
|
|
65
69
|
|
|
66
70
|
type IdentityGraphArgs = {
|
|
67
71
|
canRead?: CanRead<IdentityRelation>;
|
|
68
|
-
|
|
72
|
+
replicate?: ReplicationOptions;
|
|
69
73
|
};
|
|
70
74
|
|
|
71
75
|
@variant("relations")
|
|
72
76
|
export class IdentityGraph extends Program<IdentityGraphArgs> {
|
|
73
77
|
@field({ type: Documents })
|
|
74
|
-
relationGraph: Documents<IdentityRelation>;
|
|
78
|
+
relationGraph: Documents<IdentityRelation, FromTo>;
|
|
75
79
|
|
|
76
80
|
constructor(props?: {
|
|
77
81
|
id?: Uint8Array;
|
|
78
|
-
relationGraph?: Documents<IdentityRelation>;
|
|
82
|
+
relationGraph?: Documents<IdentityRelation, FromTo>;
|
|
79
83
|
}) {
|
|
80
84
|
super();
|
|
81
85
|
if (props) {
|
|
@@ -85,7 +89,7 @@ export class IdentityGraph extends Program<IdentityGraphArgs> {
|
|
|
85
89
|
}
|
|
86
90
|
|
|
87
91
|
async canPerform(
|
|
88
|
-
properties: CanPerformOperations<IdentityRelation
|
|
92
|
+
properties: CanPerformOperations<IdentityRelation>,
|
|
89
93
|
): Promise<boolean> {
|
|
90
94
|
return canPerformByRelation(properties);
|
|
91
95
|
}
|
|
@@ -94,30 +98,25 @@ export class IdentityGraph extends Program<IdentityGraphArgs> {
|
|
|
94
98
|
await this.relationGraph.open({
|
|
95
99
|
type: IdentityRelation,
|
|
96
100
|
canPerform: this.canPerform.bind(this),
|
|
97
|
-
|
|
101
|
+
replicate: options?.replicate,
|
|
98
102
|
index: {
|
|
99
103
|
canRead: options?.canRead,
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
from: obj.from.hashcode(),
|
|
103
|
-
to: obj.to.hashcode()
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
}
|
|
104
|
+
type: FromTo,
|
|
105
|
+
},
|
|
107
106
|
});
|
|
108
107
|
}
|
|
109
108
|
|
|
110
109
|
async addRelation(
|
|
111
110
|
to: PublicSignKey | PeerId,
|
|
112
|
-
options?: AppendOptions<Operation
|
|
111
|
+
options?: AppendOptions<Operation>,
|
|
113
112
|
) {
|
|
114
113
|
/* trustee = PublicKey.from(trustee); */
|
|
115
114
|
await this.relationGraph.put(
|
|
116
115
|
new IdentityRelation({
|
|
117
116
|
to: coercePublicKey(to),
|
|
118
|
-
from: options?.identity?.publicKey || this.node.identity.publicKey
|
|
117
|
+
from: options?.identity?.publicKey || this.node.identity.publicKey,
|
|
119
118
|
}),
|
|
120
|
-
options
|
|
119
|
+
options,
|
|
121
120
|
);
|
|
122
121
|
}
|
|
123
122
|
}
|
|
@@ -126,7 +125,7 @@ export class IdentityGraph extends Program<IdentityGraphArgs> {
|
|
|
126
125
|
* Not shardeable since we can not query trusted relations, because this would lead to a recursive problem where we then need to determine whether the responder is trusted or not
|
|
127
126
|
*/
|
|
128
127
|
|
|
129
|
-
type TrustedNetworkArgs = {
|
|
128
|
+
type TrustedNetworkArgs = { replicate?: ReplicationOptions };
|
|
130
129
|
|
|
131
130
|
@variant("trusted_network")
|
|
132
131
|
export class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
@@ -134,7 +133,7 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
|
134
133
|
rootTrust: PublicSignKey;
|
|
135
134
|
|
|
136
135
|
@field({ type: Documents })
|
|
137
|
-
trustGraph: Documents<IdentityRelation>;
|
|
136
|
+
trustGraph: Documents<IdentityRelation, FromTo>;
|
|
138
137
|
|
|
139
138
|
constructor(props: { id?: Uint8Array; rootTrust: PublicSignKey | PeerId }) {
|
|
140
139
|
super();
|
|
@@ -146,24 +145,18 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
|
146
145
|
await this.trustGraph.open({
|
|
147
146
|
type: IdentityRelation,
|
|
148
147
|
canPerform: this.canPerform.bind(this),
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
factor: 1
|
|
148
|
+
replicate: options?.replicate || {
|
|
149
|
+
factor: 1,
|
|
152
150
|
},
|
|
153
151
|
index: {
|
|
154
152
|
canRead: this.canRead.bind(this),
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
from: obj.from.hashcode(),
|
|
158
|
-
to: obj.to.hashcode()
|
|
159
|
-
};
|
|
160
|
-
}
|
|
161
|
-
}
|
|
153
|
+
type: FromTo,
|
|
154
|
+
},
|
|
162
155
|
}); // self referencing access controller
|
|
163
156
|
}
|
|
164
157
|
|
|
165
158
|
async canPerform(
|
|
166
|
-
properties: CanPerformOperations<IdentityRelation
|
|
159
|
+
properties: CanPerformOperations<IdentityRelation>,
|
|
167
160
|
): Promise<boolean> {
|
|
168
161
|
return canPerformByRelation(properties, (key) => this.isTrusted(key));
|
|
169
162
|
}
|
|
@@ -173,7 +166,7 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
|
173
166
|
}
|
|
174
167
|
|
|
175
168
|
async add(
|
|
176
|
-
trustee: PublicSignKey | PeerId
|
|
169
|
+
trustee: PublicSignKey | PeerId,
|
|
177
170
|
): Promise<IdentityRelation | undefined> {
|
|
178
171
|
const key =
|
|
179
172
|
trustee instanceof PublicSignKey
|
|
@@ -182,12 +175,12 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
|
182
175
|
|
|
183
176
|
const existingRelation = await this.getRelation(
|
|
184
177
|
key,
|
|
185
|
-
this.node.identity.publicKey
|
|
178
|
+
this.node.identity.publicKey,
|
|
186
179
|
);
|
|
187
180
|
if (!existingRelation) {
|
|
188
181
|
const relation = new IdentityRelation({
|
|
189
182
|
to: key,
|
|
190
|
-
from: this.node.identity.publicKey
|
|
183
|
+
from: this.node.identity.publicKey,
|
|
191
184
|
});
|
|
192
185
|
await this.trustGraph.put(relation);
|
|
193
186
|
return relation;
|
|
@@ -197,18 +190,18 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
|
197
190
|
|
|
198
191
|
async hasRelation(
|
|
199
192
|
trustee: PublicSignKey | PeerId,
|
|
200
|
-
truster: PublicSignKey | PeerId = this.rootTrust
|
|
193
|
+
truster: PublicSignKey | PeerId = this.rootTrust,
|
|
201
194
|
) {
|
|
202
195
|
return !!(await this.getRelation(trustee, truster));
|
|
203
196
|
}
|
|
204
197
|
getRelation(
|
|
205
198
|
trustee: PublicSignKey | PeerId,
|
|
206
|
-
truster: PublicSignKey | PeerId = this.rootTrust
|
|
199
|
+
truster: PublicSignKey | PeerId = this.rootTrust,
|
|
207
200
|
) {
|
|
208
201
|
return getRelation(
|
|
209
202
|
coercePublicKey(truster),
|
|
210
203
|
coercePublicKey(trustee),
|
|
211
|
-
this.trustGraph
|
|
204
|
+
this.trustGraph,
|
|
212
205
|
);
|
|
213
206
|
}
|
|
214
207
|
|
|
@@ -219,21 +212,21 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
|
219
212
|
* Root trust A trust B trust C
|
|
220
213
|
* C is trusted by Root
|
|
221
214
|
* @param trustee
|
|
222
|
-
* @param truster
|
|
215
|
+
* @param truster the truster "root", if undefined defaults to the root trust
|
|
223
216
|
* @returns true, if trusted
|
|
224
217
|
*/
|
|
225
218
|
async isTrusted(
|
|
226
219
|
trustee: PublicSignKey,
|
|
227
|
-
truster: PublicSignKey = this.rootTrust
|
|
220
|
+
truster: PublicSignKey = this.rootTrust,
|
|
228
221
|
): Promise<boolean> {
|
|
229
222
|
if (trustee.equals(this.rootTrust)) {
|
|
230
223
|
return true;
|
|
231
224
|
}
|
|
232
|
-
if (this.trustGraph.log.
|
|
225
|
+
if (await this.trustGraph.log.isReplicating()) {
|
|
233
226
|
return this._isTrustedLocal(trustee, truster);
|
|
234
227
|
} else {
|
|
235
228
|
this.trustGraph.index.search(new SearchRequest({ query: [] }), {
|
|
236
|
-
remote: { sync: true }
|
|
229
|
+
remote: { sync: true },
|
|
237
230
|
});
|
|
238
231
|
return this._isTrustedLocal(trustee, truster);
|
|
239
232
|
}
|
|
@@ -241,13 +234,13 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
|
241
234
|
|
|
242
235
|
async _isTrustedLocal(
|
|
243
236
|
trustee: PublicSignKey,
|
|
244
|
-
truster: PublicSignKey = this.rootTrust
|
|
237
|
+
truster: PublicSignKey = this.rootTrust,
|
|
245
238
|
): Promise<boolean> {
|
|
246
239
|
const trustPath = await hasPath(
|
|
247
240
|
trustee,
|
|
248
241
|
truster,
|
|
249
242
|
this.trustGraph,
|
|
250
|
-
getFromByTo
|
|
243
|
+
getFromByTo,
|
|
251
244
|
);
|
|
252
245
|
return !!trustPath;
|
|
253
246
|
}
|
|
@@ -266,3 +259,17 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
|
|
|
266
259
|
return sha256Base64Sync(serialize(this));
|
|
267
260
|
}
|
|
268
261
|
}
|
|
262
|
+
/* TODO do we need these decorator functions?
|
|
263
|
+
export const getNetwork = (object: any): TrustedNetwork | undefined => {
|
|
264
|
+
return (
|
|
265
|
+
object.constructor.prototype._network &&
|
|
266
|
+
object[object.constructor.prototype._network]
|
|
267
|
+
);
|
|
268
|
+
};
|
|
269
|
+
|
|
270
|
+
export function network(options: { property: string }) {
|
|
271
|
+
return (constructor: any) => {
|
|
272
|
+
constructor.prototype._network = options.property;
|
|
273
|
+
};
|
|
274
|
+
}
|
|
275
|
+
*/
|
package/src/identity-graph.ts
CHANGED
|
@@ -1,57 +1,63 @@
|
|
|
1
1
|
import { field, fixedArray, serialize, variant } from "@dao-xyz/borsh";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { PublicSignKey, sha256Sync } from "@peerbit/crypto";
|
|
3
|
+
import { Documents } from "@peerbit/document";
|
|
4
|
+
import { SearchRequest, StringMatch } from "@peerbit/indexer-interface";
|
|
4
5
|
import { concat } from "uint8arrays";
|
|
5
|
-
import { sha256Sync } from "@peerbit/crypto";
|
|
6
6
|
|
|
7
7
|
export type RelationResolver = {
|
|
8
8
|
resolve: (
|
|
9
9
|
key: PublicSignKey,
|
|
10
|
-
db: Documents<IdentityRelation
|
|
10
|
+
db: Documents<IdentityRelation, FromTo>,
|
|
11
11
|
) => Promise<IdentityRelation[]>;
|
|
12
12
|
next: (relation: IdentityRelation) => PublicSignKey;
|
|
13
13
|
};
|
|
14
14
|
|
|
15
15
|
export const getFromByTo: RelationResolver = {
|
|
16
|
-
resolve: async (
|
|
16
|
+
resolve: async (
|
|
17
|
+
to: PublicSignKey,
|
|
18
|
+
db: Documents<IdentityRelation, FromTo>,
|
|
19
|
+
) => {
|
|
17
20
|
return Promise.all(
|
|
18
21
|
await db.index.search(
|
|
19
22
|
new SearchRequest({
|
|
20
23
|
query: [
|
|
21
24
|
new StringMatch({
|
|
22
25
|
key: "to",
|
|
23
|
-
value: to.hashcode()
|
|
24
|
-
})
|
|
25
|
-
]
|
|
26
|
-
})
|
|
27
|
-
)
|
|
26
|
+
value: to.hashcode(),
|
|
27
|
+
}),
|
|
28
|
+
],
|
|
29
|
+
}),
|
|
30
|
+
),
|
|
28
31
|
);
|
|
29
32
|
},
|
|
30
|
-
next: (relation) => relation.from
|
|
33
|
+
next: (relation) => relation.from,
|
|
31
34
|
};
|
|
32
35
|
|
|
33
36
|
export const getToByFrom: RelationResolver = {
|
|
34
|
-
resolve: async (
|
|
37
|
+
resolve: async (
|
|
38
|
+
from: PublicSignKey,
|
|
39
|
+
db: Documents<IdentityRelation, FromTo>,
|
|
40
|
+
) => {
|
|
35
41
|
return Promise.all(
|
|
36
42
|
await db.index.search(
|
|
37
43
|
new SearchRequest({
|
|
38
44
|
query: [
|
|
39
45
|
new StringMatch({
|
|
40
46
|
key: "from",
|
|
41
|
-
value: from.hashcode()
|
|
42
|
-
})
|
|
43
|
-
]
|
|
44
|
-
})
|
|
45
|
-
)
|
|
47
|
+
value: from.hashcode(),
|
|
48
|
+
}),
|
|
49
|
+
],
|
|
50
|
+
}),
|
|
51
|
+
),
|
|
46
52
|
);
|
|
47
53
|
},
|
|
48
|
-
next: (relation) => relation.to
|
|
54
|
+
next: (relation) => relation.to,
|
|
49
55
|
};
|
|
50
56
|
|
|
51
57
|
export async function* getPathGenerator(
|
|
52
58
|
from: PublicSignKey,
|
|
53
|
-
db: Documents<IdentityRelation>,
|
|
54
|
-
resolver: RelationResolver
|
|
59
|
+
db: Documents<IdentityRelation, FromTo>,
|
|
60
|
+
resolver: RelationResolver,
|
|
55
61
|
) {
|
|
56
62
|
let iter = [from];
|
|
57
63
|
const visited = new Set();
|
|
@@ -85,8 +91,8 @@ export async function* getPathGenerator(
|
|
|
85
91
|
export const hasPathToTarget = async (
|
|
86
92
|
start: PublicSignKey,
|
|
87
93
|
target: (key: PublicSignKey) => boolean,
|
|
88
|
-
db: Documents<IdentityRelation>,
|
|
89
|
-
resolver: RelationResolver
|
|
94
|
+
db: Documents<IdentityRelation, FromTo>,
|
|
95
|
+
resolver: RelationResolver,
|
|
90
96
|
): Promise<boolean> => {
|
|
91
97
|
if (!db) {
|
|
92
98
|
throw new Error("Not initalized");
|
|
@@ -152,8 +158,8 @@ export class IdentityRelation extends AbstractRelation {
|
|
|
152
158
|
export const hasPath = async (
|
|
153
159
|
start: PublicSignKey,
|
|
154
160
|
end: PublicSignKey,
|
|
155
|
-
db: Documents<IdentityRelation>,
|
|
156
|
-
resolver: RelationResolver
|
|
161
|
+
db: Documents<IdentityRelation, FromTo>,
|
|
162
|
+
resolver: RelationResolver,
|
|
157
163
|
): Promise<boolean> => {
|
|
158
164
|
return hasPathToTarget(start, (key) => end.equals(key), db, resolver);
|
|
159
165
|
};
|
|
@@ -161,12 +167,29 @@ export const hasPath = async (
|
|
|
161
167
|
export const getRelation = async (
|
|
162
168
|
from: PublicSignKey,
|
|
163
169
|
to: PublicSignKey,
|
|
164
|
-
db: Documents<IdentityRelation
|
|
170
|
+
db: Documents<IdentityRelation, FromTo>,
|
|
165
171
|
): Promise<IdentityRelation | undefined> => {
|
|
166
172
|
return db.index.get(new IdentityRelation({ from, to }).id);
|
|
167
173
|
};
|
|
168
174
|
|
|
175
|
+
export class FromTo {
|
|
176
|
+
@field({ type: fixedArray("u8", 32) })
|
|
177
|
+
id: Uint8Array;
|
|
178
|
+
|
|
179
|
+
@field({ type: "string" })
|
|
180
|
+
from: string;
|
|
181
|
+
|
|
182
|
+
@field({ type: "string" })
|
|
183
|
+
to: string;
|
|
184
|
+
|
|
185
|
+
constructor(props: IdentityRelation, _context?: any) {
|
|
186
|
+
this.from = props.from.hashcode();
|
|
187
|
+
this.to = props.to.hashcode();
|
|
188
|
+
this.id = props.id;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
|
|
169
192
|
export const createIdentityGraphStore = (id?: Uint8Array) =>
|
|
170
|
-
new Documents<IdentityRelation>({
|
|
171
|
-
id
|
|
193
|
+
new Documents<IdentityRelation, FromTo>({
|
|
194
|
+
id,
|
|
172
195
|
});
|