@peerbit/trusted-network 3.0.40 → 4.0.0-55cebfe

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,44 +1,43 @@
1
- import { Documents, Operation, PutOperation, CanRead, TransactionContext } from "@peerbit/document";
2
- import { AppendOptions } from "@peerbit/log";
1
+ import { type PeerId } from "@libp2p/interface";
3
2
  import { PublicSignKey } from "@peerbit/crypto";
4
- import { DeleteOperation } from "@peerbit/document";
5
- import { IdentityRelation } from "./identity-graph.js";
3
+ import { type CanPerformOperations, type CanRead, Documents, Operation } from "@peerbit/document";
4
+ import { type AppendOptions } from "@peerbit/log";
6
5
  import { Program } from "@peerbit/program";
7
- import { PeerId } from "@libp2p/interface";
8
- import { RoleOptions } from "@peerbit/shared-log";
6
+ import { type ReplicationOptions } from "@peerbit/shared-log";
7
+ import { FromTo, IdentityRelation } from "./identity-graph.js";
9
8
  type IdentityGraphArgs = {
10
9
  canRead?: CanRead<IdentityRelation>;
11
- role?: RoleOptions;
10
+ replicate?: ReplicationOptions;
12
11
  };
13
12
  export declare class IdentityGraph extends Program<IdentityGraphArgs> {
14
- relationGraph: Documents<IdentityRelation>;
13
+ relationGraph: Documents<IdentityRelation, FromTo>;
15
14
  constructor(props?: {
16
15
  id?: Uint8Array;
17
- relationGraph?: Documents<IdentityRelation>;
16
+ relationGraph?: Documents<IdentityRelation, FromTo>;
18
17
  });
19
- canPerform(operation: PutOperation<IdentityRelation> | DeleteOperation, context: TransactionContext<IdentityRelation>): Promise<boolean>;
18
+ canPerform(properties: CanPerformOperations<IdentityRelation>): Promise<boolean>;
20
19
  open(options?: IdentityGraphArgs): Promise<void>;
21
- addRelation(to: PublicSignKey | PeerId, options?: AppendOptions<Operation<IdentityRelation>>): Promise<void>;
20
+ addRelation(to: PublicSignKey | PeerId, options?: AppendOptions<Operation>): Promise<void>;
22
21
  }
23
22
  /**
24
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
25
24
  */
26
25
  type TrustedNetworkArgs = {
27
- role?: RoleOptions;
26
+ replicate?: ReplicationOptions;
28
27
  };
29
28
  export declare class TrustedNetwork extends Program<TrustedNetworkArgs> {
30
29
  rootTrust: PublicSignKey;
31
- trustGraph: Documents<IdentityRelation>;
30
+ trustGraph: Documents<IdentityRelation, FromTo>;
32
31
  constructor(props: {
33
32
  id?: Uint8Array;
34
33
  rootTrust: PublicSignKey | PeerId;
35
34
  });
36
35
  open(options?: TrustedNetworkArgs): Promise<void>;
37
- canPerform(operation: PutOperation<IdentityRelation> | DeleteOperation, context: TransactionContext<IdentityRelation>): Promise<boolean>;
36
+ canPerform(properties: CanPerformOperations<IdentityRelation>): Promise<boolean>;
38
37
  canRead(relation: any, publicKey?: PublicSignKey): Promise<boolean>;
39
38
  add(trustee: PublicSignKey | PeerId): Promise<IdentityRelation | undefined>;
40
39
  hasRelation(trustee: PublicSignKey | PeerId, truster?: PublicSignKey | PeerId): Promise<boolean>;
41
- getRelation(trustee: PublicSignKey | PeerId, truster?: PublicSignKey | PeerId): Promise<IdentityRelation | undefined>;
40
+ getRelation(trustee: PublicSignKey | PeerId, truster?: PublicSignKey | PeerId): Promise<IdentityRelation>;
42
41
  /**
43
42
  * Follow trust path back to trust root.
44
43
  * Trust root is always trusted.
@@ -46,7 +45,7 @@ export declare class TrustedNetwork extends Program<TrustedNetworkArgs> {
46
45
  * Root trust A trust B trust C
47
46
  * C is trusted by Root
48
47
  * @param trustee
49
- * @param truster, the truster "root", if undefined defaults to the root trust
48
+ * @param truster the truster "root", if undefined defaults to the root trust
50
49
  * @returns true, if trusted
51
50
  */
52
51
  isTrusted(trustee: PublicSignKey, truster?: PublicSignKey): Promise<boolean>;
@@ -55,3 +54,4 @@ export declare class TrustedNetwork extends Program<TrustedNetworkArgs> {
55
54
  hashCode(): string;
56
55
  }
57
56
  export {};
57
+ //# sourceMappingURL=controller.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,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,OAAO,CAAC,kBAAkB,CAAC;IAE9D,SAAS,EAAE,aAAa,CAAC;IAGzB,UAAU,EAAE,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,CAAC;gBAEpC,KAAK,EAAE;QAAE,EAAE,CAAC,EAAE,UAAU,CAAC;QAAC,SAAS,EAAE,aAAa,GAAG,MAAM,CAAA;KAAE;IAMnE,IAAI,CAAC,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"}
@@ -8,55 +8,49 @@ 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 { SearchRequest, Documents, PutOperation } from "@peerbit/document";
12
- import { PublicSignKey, getPublicKeyFromPeerId } from "@peerbit/crypto";
13
- import { DeleteOperation } from "@peerbit/document";
14
- import { IdentityRelation, createIdentityGraphStore, getPathGenerator, hasPath, getFromByTo, getToByFrom, getRelation } from "./identity-graph.js";
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";
15
+ import {} from "@peerbit/log";
15
16
  import { Program } from "@peerbit/program";
16
- import { sha256Base64Sync } from "@peerbit/crypto";
17
- 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";
18
19
  const coercePublicKey = (publicKey) => {
19
20
  return publicKey instanceof PublicSignKey
20
21
  ? publicKey
21
22
  : getPublicKeyFromPeerId(publicKey);
22
23
  };
23
- const canPerformByRelation = async (operation, context, isTrusted) => {
24
+ const canPerformByRelation = async (properties, isTrusted) => {
24
25
  // verify the payload
25
- if (operation instanceof PutOperation ||
26
- operation instanceof DeleteOperation) {
27
- /* const relation: Relation = operation.value || deserialize(operation.data, Relation); */
28
- const keys = await context.entry.getPublicKeys();
29
- const checkKey = async (key) => {
30
- if (operation instanceof PutOperation) {
31
- // TODO, this clause is only applicable when we modify the identityGraph, but it does not make sense that the canPerform method does not know what the payload will
32
- // be, upon deserialization. There should be known in the `canPerform` method whether we are appending to the identityGraph.
33
- const relation = operation.value;
34
- if (relation instanceof IdentityRelation) {
35
- if (!relation.from.equals(key)) {
36
- return false;
37
- }
26
+ const keys = await properties.entry.getPublicKeys();
27
+ const checkKey = async (key) => {
28
+ if (properties.type === "put") {
29
+ // TODO, this clause is only applicable when we modify the identityGraph, but it does not make sense that the canPerform method does not know what the payload will
30
+ // be, upon deserialization. There should be known in the `canPerform` method whether we are appending to the identityGraph.
31
+ const relation = properties.value;
32
+ if (relation instanceof IdentityRelation) {
33
+ if (!relation.from.equals(key)) {
34
+ return false;
38
35
  }
39
- // else assume the payload is accepted
40
- }
41
- if (isTrusted) {
42
- const trusted = await isTrusted(key);
43
- return trusted;
44
- }
45
- else {
46
- return true;
47
- }
48
- };
49
- for (const key of keys) {
50
- const result = await checkKey(key);
51
- if (result) {
52
- return true;
53
36
  }
37
+ // else assume the payload is accepted
38
+ }
39
+ if (isTrusted) {
40
+ const trusted = await isTrusted(key);
41
+ return trusted;
42
+ }
43
+ else {
44
+ return true;
45
+ }
46
+ };
47
+ for (const key of keys) {
48
+ const result = await checkKey(key);
49
+ if (result) {
50
+ return true;
54
51
  }
55
- return false;
56
- }
57
- else {
58
- return false;
59
52
  }
53
+ return false;
60
54
  };
61
55
  let IdentityGraph = class IdentityGraph extends Program {
62
56
  relationGraph;
@@ -67,30 +61,25 @@ let IdentityGraph = class IdentityGraph extends Program {
67
61
  props.relationGraph || createIdentityGraphStore(props?.id);
68
62
  }
69
63
  }
70
- async canPerform(operation, context) {
71
- return canPerformByRelation(operation, context);
64
+ async canPerform(properties) {
65
+ return canPerformByRelation(properties);
72
66
  }
73
67
  async open(options) {
74
68
  await this.relationGraph.open({
75
69
  type: IdentityRelation,
76
70
  canPerform: this.canPerform.bind(this),
77
- role: options?.role,
71
+ replicate: options?.replicate,
78
72
  index: {
79
73
  canRead: options?.canRead,
80
- fields: (obj, _entry) => {
81
- return {
82
- from: obj.from.hashcode(),
83
- to: obj.to.hashcode()
84
- };
85
- }
86
- }
74
+ type: FromTo,
75
+ },
87
76
  });
88
77
  }
89
78
  async addRelation(to, options) {
90
79
  /* trustee = PublicKey.from(trustee); */
91
80
  await this.relationGraph.put(new IdentityRelation({
92
81
  to: coercePublicKey(to),
93
- from: options?.identity?.publicKey || this.node.identity.publicKey
82
+ from: options?.identity?.publicKey || this.node.identity.publicKey,
94
83
  }), options);
95
84
  }
96
85
  };
@@ -115,23 +104,17 @@ let TrustedNetwork = class TrustedNetwork extends Program {
115
104
  await this.trustGraph.open({
116
105
  type: IdentityRelation,
117
106
  canPerform: this.canPerform.bind(this),
118
- role: options?.role || {
119
- type: "replicator",
120
- factor: 1
107
+ replicate: options?.replicate || {
108
+ factor: 1,
121
109
  },
122
110
  index: {
123
111
  canRead: this.canRead.bind(this),
124
- fields: (obj, _entry) => {
125
- return {
126
- from: obj.from.hashcode(),
127
- to: obj.to.hashcode()
128
- };
129
- }
130
- }
112
+ type: FromTo,
113
+ },
131
114
  }); // self referencing access controller
132
115
  }
133
- async canPerform(operation, context) {
134
- return canPerformByRelation(operation, context, (key) => this.isTrusted(key));
116
+ async canPerform(properties) {
117
+ return canPerformByRelation(properties, (key) => this.isTrusted(key));
135
118
  }
136
119
  async canRead(relation, publicKey) {
137
120
  return true; // TODO should we have read access control?
@@ -144,7 +127,7 @@ let TrustedNetwork = class TrustedNetwork extends Program {
144
127
  if (!existingRelation) {
145
128
  const relation = new IdentityRelation({
146
129
  to: key,
147
- from: this.node.identity.publicKey
130
+ from: this.node.identity.publicKey,
148
131
  });
149
132
  await this.trustGraph.put(relation);
150
133
  return relation;
@@ -164,19 +147,19 @@ let TrustedNetwork = class TrustedNetwork extends Program {
164
147
  * Root trust A trust B trust C
165
148
  * C is trusted by Root
166
149
  * @param trustee
167
- * @param truster, the truster "root", if undefined defaults to the root trust
150
+ * @param truster the truster "root", if undefined defaults to the root trust
168
151
  * @returns true, if trusted
169
152
  */
170
153
  async isTrusted(trustee, truster = this.rootTrust) {
171
154
  if (trustee.equals(this.rootTrust)) {
172
155
  return true;
173
156
  }
174
- if (this.trustGraph.log.role instanceof Replicator) {
157
+ if (await this.trustGraph.log.isReplicating()) {
175
158
  return this._isTrustedLocal(trustee, truster);
176
159
  }
177
160
  else {
178
161
  this.trustGraph.index.search(new SearchRequest({ query: [] }), {
179
- remote: { sync: true }
162
+ remote: { sync: true },
180
163
  });
181
164
  return this._isTrustedLocal(trustee, truster);
182
165
  }
@@ -211,4 +194,18 @@ TrustedNetwork = __decorate([
211
194
  __metadata("design:paramtypes", [Object])
212
195
  ], TrustedNetwork);
213
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
+ */
214
211
  //# sourceMappingURL=controller.js.map
@@ -0,0 +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,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,MAAM,qBAAqB,CAAC;AAC9D,OAAO,EACN,MAAM,EACN,gBAAgB,EAChB,wBAAwB,EACxB,WAAW,EACX,gBAAgB,EAChB,WAAW,EACX,WAAW,EACX,OAAO,GACP,MAAM,qBAAqB,CAAC;AAE7B,MAAM,eAAe,GAAG,CAAC,SAAiC,EAAE,EAAE;IAC7D,OAAO,SAAS,YAAY,aAAa;QACxC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC,CAAC;AACF,MAAM,oBAAoB,GAAG,KAAK,EACjC,UAAkD,EAClD,SAAoD,EACjC,E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AAY,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,6 +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 const createIdentityGraphStore: (id?: Uint8Array) => Documents<IdentityRelation>;
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>;
42
+ //# sourceMappingURL=identity-graph.d.ts.map
@@ -0,0 +1 @@
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,C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AEF,eAAO,MAAM,WAAW,SACjB,aAAa,MACf,aAAa,MACb,SAAS,CAAC,gBAAgB,EAAE,MAAM,CAAC,KACrC,OAAO,CAAC,gBAAgB,GAAG,SAAS,CAEtC,CAAC;AAEF,qBAAa,MAAM;IAElB,EAAE,EAAE,UAAU,CAAC;IAGf,IAAI,EAAE,MAAM,CAAC;IAGb,EAAE,EAAE,MAAM,CAAC;gBAEC,KAAK,EAAE,gBAAgB,EAAE,QAAQ,CAAC,EAAE,GAAG;CAKnD;AAED,eAAO,MAAM,wBAAwB,QAAS,UAAU,wCAGrD,CAAC"}
@@ -9,22 +9,22 @@ var __metadata = (this && this.__metadata) || function (k, v) {
9
9
  };
10
10
  var IdentityRelation_1;
11
11
  import { field, fixedArray, serialize, variant } from "@dao-xyz/borsh";
12
- import { Documents, SearchRequest, StringMatch } from "@peerbit/document";
13
- import { PublicSignKey } from "@peerbit/crypto";
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
@@ -0,0 +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,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;AAUrC,MAAM,CAAC,MAAM,WAAW,GAAqB;IAC5C,OAAO,EAAE,KAAK,EACb,EAAiB,EACjB,EAAuC,EACtC,EAAE;QACH,OAAO,OAAO,CAAC,GAAG,CACjB,MAAM,EAAE,CAAC,KAAK,CAAC,MAAM,CACpB,IAAI,aAAa,CAAC;YACjB,KAAK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C;AAEF,MAAM,CAAC,MAAM,WAAW,GAAG,KAAK,EAC/B,IAAmB,EACnB,EAAiB,EACjB,EAAuC,EACC,EAAE;IAC1C,OAAO,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,gBAAgB,CAAC,EAAE,IAAI,EAAE,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,CAAC;AAC5D,CAAC,CAAC;AAEF,MAAM,OAAO,MAAM;IAElB,EAAE,CAAa;IAGf,IAAI,CAAS;IAGb,EAAE,CAAS;IAEX,YAAY,KAAuB,EAAE,QAAc;QAClD,IAAI,CAAC,IAAI,GAAG,KAAK,CAAC,IAAI,CAAC,QAAQ,EAAE,CAAC;QAClC,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC,QAAQ,EAAE,CAAC;QAC9B,IAAI,CAAC,EAAE,GAAG,KAAK,CAAC,EAAE,CAAC;IACpB,CAAC;CACD;AAbA;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,UAAU,CAAC,IAAI,EAAE,EAAE,CAAC,EAAE,CAAC;8BAClC,UAAU;kCAAC;AAGf;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;oCACb;AAGb;IADC,KAAK,CAAC,EAAE,IAAI,EAAE,QAAQ,EAAE,CAAC;;kCACf;AASZ,MAAM,CAAC,MAAM,wBAAwB,GAAG,CAAC,EAAe,EAAE,EAAE,CAC3D,IAAI,SAAS,CAA2B;IACvC,EAAE;CACF,CAAC,CAAC"}
@@ -1,2 +1,3 @@
1
1
  export * from "./controller.js";
2
2
  export * from "./identity-graph.js";
3
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,iBAAiB,CAAC;AAChC,cAAc,qBAAqB,CAAC"}
package/package.json CHANGED
@@ -1,43 +1,70 @@
1
1
  {
2
- "name": "@peerbit/trusted-network",
3
- "version": "3.0.40",
4
- "description": "Access controller that operates on a DB",
5
- "type": "module",
6
- "sideEffects": false,
7
- "module": "lib/esm/index.js",
8
- "types": "lib/esm/index.d.ts",
9
- "exports": {
10
- "import": "./lib/esm/index.js",
11
- "require": "./lib/cjs/index.js"
12
- },
13
- "files": [
14
- "lib",
15
- "src",
16
- "!src/**/__tests__",
17
- "!lib/**/__tests__",
18
- "LICENSE"
19
- ],
20
- "publishConfig": {
21
- "access": "public"
22
- },
23
- "scripts": {
24
- "clean": "shx rm -rf lib/*",
25
- "build": "yarn clean && tsc -p tsconfig.json",
26
- "test": "node ../../../../node_modules/.bin/jest test -c ../../../../jest.config.ts --runInBand --forceExit",
27
- "test:unit": "node ../../../../node_modules/.bin/jest test -c ../../../../jest.config.unit.ts --runInBand --forceExit",
28
- "test:integration": "node ../node_modules/.bin/jest test -c ../../../../jest.config.integration.ts --runInBand --forceExit"
29
- },
30
- "author": "dao.xyz",
31
- "license": "MIT",
32
- "dependencies": {
33
- "@dao-xyz/borsh": "^5.2.1",
34
- "@peerbit/crypto": "2.2.0",
35
- "@peerbit/document": "6.0.7"
36
- },
37
- "devDependencies": {
38
- "@ethersproject/wallet": "^5.7.0",
39
- "@peerbit/test-utils": "^2.0.33",
40
- "@peerbit/time": "2.0.6"
41
- },
42
- "gitHead": "fcd486b9a5c3b7d94e2ae14f1b06ab2a0f7841ad"
2
+ "name": "@peerbit/trusted-network",
3
+ "version": "4.0.0-55cebfe",
4
+ "description": "Access controller that operates on a DB",
5
+ "sideEffects": false,
6
+ "type": "module",
7
+ "types": "./dist/src/index.d.ts",
8
+ "typesVersions": {
9
+ "*": {
10
+ "*": [
11
+ "*",
12
+ "dist/*",
13
+ "dist/src/*",
14
+ "dist/src/*/index"
15
+ ],
16
+ "src/*": [
17
+ "*",
18
+ "dist/*",
19
+ "dist/src/*",
20
+ "dist/src/*/index"
21
+ ]
22
+ }
23
+ },
24
+ "files": [
25
+ "src",
26
+ "dist",
27
+ "!dist/e2e",
28
+ "!dist/test",
29
+ "!**/*.tsbuildinfo"
30
+ ],
31
+ "exports": {
32
+ ".": {
33
+ "types": "./dist/src/index.d.ts",
34
+ "import": "./dist/src/index.js"
35
+ }
36
+ },
37
+ "eslintConfig": {
38
+ "extends": "peerbit",
39
+ "parserOptions": {
40
+ "project": true,
41
+ "sourceType": "module"
42
+ },
43
+ "ignorePatterns": [
44
+ "!.aegir.js",
45
+ "test/ts-use",
46
+ "*.d.ts"
47
+ ]
48
+ },
49
+ "publishConfig": {
50
+ "access": "public"
51
+ },
52
+ "scripts": {
53
+ "clean": "aegir clean",
54
+ "build": "aegir build --no-bundle",
55
+ "test": "aegir test --target node",
56
+ "lint": "aegir lint"
57
+ },
58
+ "author": "dao.xyz",
59
+ "license": "MIT",
60
+ "dependencies": {
61
+ "@dao-xyz/borsh": "^5.2.3",
62
+ "@peerbit/crypto": "2.3.0-55cebfe",
63
+ "@peerbit/document": "7.0.0-55cebfe"
64
+ },
65
+ "devDependencies": {
66
+ "@peerbit/time": "2.0.7-55cebfe",
67
+ "@ethersproject/wallet": "^5.7.0",
68
+ "@peerbit/test-utils": "2.0.34-55cebfe"
69
+ }
43
70
  }
package/src/controller.ts CHANGED
@@ -1,28 +1,30 @@
1
- import { deserialize, field, serialize, variant, vec } from "@dao-xyz/borsh";
1
+ import { field, serialize, variant } from "@dao-xyz/borsh";
2
+ import { type PeerId } from "@libp2p/interface";
2
3
  import {
3
- SearchRequest,
4
+ PublicSignKey,
5
+ getPublicKeyFromPeerId,
6
+ sha256Base64Sync,
7
+ } from "@peerbit/crypto";
8
+ import {
9
+ type CanPerformOperations,
10
+ type CanRead,
4
11
  Documents,
5
12
  Operation,
6
- PutOperation,
7
- CanRead,
8
- TransactionContext
9
13
  } from "@peerbit/document";
10
- import { AppendOptions } from "@peerbit/log";
11
- import { PublicSignKey, getPublicKeyFromPeerId } from "@peerbit/crypto";
12
- import { DeleteOperation } from "@peerbit/document";
14
+ import { SearchRequest } from "@peerbit/indexer-interface";
15
+ import { type AppendOptions } from "@peerbit/log";
16
+ import { Program } from "@peerbit/program";
17
+ import { type ReplicationOptions } from "@peerbit/shared-log";
13
18
  import {
19
+ FromTo,
14
20
  IdentityRelation,
15
21
  createIdentityGraphStore,
16
- getPathGenerator,
17
- hasPath,
18
22
  getFromByTo,
23
+ getPathGenerator,
24
+ getRelation,
19
25
  getToByFrom,
20
- getRelation
26
+ hasPath,
21
27
  } from "./identity-graph.js";
22
- import { Program } from "@peerbit/program";
23
- import { sha256Base64Sync } from "@peerbit/crypto";
24
- import { PeerId } from "@libp2p/interface";
25
- import { Replicator, RoleOptions } from "@peerbit/shared-log";
26
28
 
27
29
  const coercePublicKey = (publicKey: PublicSignKey | PeerId) => {
28
30
  return publicKey instanceof PublicSignKey
@@ -30,64 +32,54 @@ const coercePublicKey = (publicKey: PublicSignKey | PeerId) => {
30
32
  : getPublicKeyFromPeerId(publicKey);
31
33
  };
32
34
  const canPerformByRelation = async (
33
- operation: PutOperation<IdentityRelation> | DeleteOperation,
34
- context: TransactionContext<IdentityRelation>,
35
- isTrusted?: (key: PublicSignKey) => Promise<boolean>
35
+ properties: CanPerformOperations<IdentityRelation>,
36
+ isTrusted?: (key: PublicSignKey) => Promise<boolean>,
36
37
  ): Promise<boolean> => {
37
38
  // verify the payload
38
- if (
39
- operation instanceof PutOperation ||
40
- operation instanceof DeleteOperation
41
- ) {
42
- /* const relation: Relation = operation.value || deserialize(operation.data, Relation); */
39
+ const keys = await properties.entry.getPublicKeys();
40
+ const checkKey = async (key: PublicSignKey): Promise<boolean> => {
41
+ if (properties.type === "put") {
42
+ // TODO, this clause is only applicable when we modify the identityGraph, but it does not make sense that the canPerform method does not know what the payload will
43
+ // be, upon deserialization. There should be known in the `canPerform` method whether we are appending to the identityGraph.
43
44
 
44
- const keys = await context.entry.getPublicKeys();
45
- const checkKey = async (key: PublicSignKey): Promise<boolean> => {
46
- if (operation instanceof PutOperation) {
47
- // TODO, this clause is only applicable when we modify the identityGraph, but it does not make sense that the canPerform method does not know what the payload will
48
- // be, upon deserialization. There should be known in the `canPerform` method whether we are appending to the identityGraph.
49
-
50
- const relation = operation.value;
51
- if (relation instanceof IdentityRelation) {
52
- if (!relation.from.equals(key)) {
53
- return false;
54
- }
45
+ const relation = properties.value;
46
+ if (relation instanceof IdentityRelation) {
47
+ if (!relation.from.equals(key)) {
48
+ return false;
55
49
  }
56
-
57
- // else assume the payload is accepted
58
- }
59
- if (isTrusted) {
60
- const trusted = await isTrusted(key);
61
- return trusted;
62
- } else {
63
- return true;
64
- }
65
- };
66
- for (const key of keys) {
67
- const result = await checkKey(key);
68
- if (result) {
69
- return true;
70
50
  }
51
+
52
+ // else assume the payload is accepted
53
+ }
54
+ if (isTrusted) {
55
+ const trusted = await isTrusted(key);
56
+ return trusted;
57
+ } else {
58
+ return true;
59
+ }
60
+ };
61
+ for (const key of keys) {
62
+ const result = await checkKey(key);
63
+ if (result) {
64
+ return true;
71
65
  }
72
- return false;
73
- } else {
74
- return false;
75
66
  }
67
+ return false;
76
68
  };
77
69
 
78
70
  type IdentityGraphArgs = {
79
71
  canRead?: CanRead<IdentityRelation>;
80
- role?: RoleOptions;
72
+ replicate?: ReplicationOptions;
81
73
  };
82
74
 
83
75
  @variant("relations")
84
76
  export class IdentityGraph extends Program<IdentityGraphArgs> {
85
77
  @field({ type: Documents })
86
- relationGraph: Documents<IdentityRelation>;
78
+ relationGraph: Documents<IdentityRelation, FromTo>;
87
79
 
88
80
  constructor(props?: {
89
81
  id?: Uint8Array;
90
- relationGraph?: Documents<IdentityRelation>;
82
+ relationGraph?: Documents<IdentityRelation, FromTo>;
91
83
  }) {
92
84
  super();
93
85
  if (props) {
@@ -97,40 +89,34 @@ export class IdentityGraph extends Program<IdentityGraphArgs> {
97
89
  }
98
90
 
99
91
  async canPerform(
100
- operation: PutOperation<IdentityRelation> | DeleteOperation,
101
- context: TransactionContext<IdentityRelation>
92
+ properties: CanPerformOperations<IdentityRelation>,
102
93
  ): Promise<boolean> {
103
- return canPerformByRelation(operation, context);
94
+ return canPerformByRelation(properties);
104
95
  }
105
96
 
106
97
  async open(options?: IdentityGraphArgs) {
107
98
  await this.relationGraph.open({
108
99
  type: IdentityRelation,
109
100
  canPerform: this.canPerform.bind(this),
110
- role: options?.role,
101
+ replicate: options?.replicate,
111
102
  index: {
112
103
  canRead: options?.canRead,
113
- fields: (obj, _entry) => {
114
- return {
115
- from: obj.from.hashcode(),
116
- to: obj.to.hashcode()
117
- };
118
- }
119
- }
104
+ type: FromTo,
105
+ },
120
106
  });
121
107
  }
122
108
 
123
109
  async addRelation(
124
110
  to: PublicSignKey | PeerId,
125
- options?: AppendOptions<Operation<IdentityRelation>>
111
+ options?: AppendOptions<Operation>,
126
112
  ) {
127
113
  /* trustee = PublicKey.from(trustee); */
128
114
  await this.relationGraph.put(
129
115
  new IdentityRelation({
130
116
  to: coercePublicKey(to),
131
- from: options?.identity?.publicKey || this.node.identity.publicKey
117
+ from: options?.identity?.publicKey || this.node.identity.publicKey,
132
118
  }),
133
- options
119
+ options,
134
120
  );
135
121
  }
136
122
  }
@@ -139,7 +125,7 @@ export class IdentityGraph extends Program<IdentityGraphArgs> {
139
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
140
126
  */
141
127
 
142
- type TrustedNetworkArgs = { role?: RoleOptions };
128
+ type TrustedNetworkArgs = { replicate?: ReplicationOptions };
143
129
 
144
130
  @variant("trusted_network")
145
131
  export class TrustedNetwork extends Program<TrustedNetworkArgs> {
@@ -147,7 +133,7 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
147
133
  rootTrust: PublicSignKey;
148
134
 
149
135
  @field({ type: Documents })
150
- trustGraph: Documents<IdentityRelation>;
136
+ trustGraph: Documents<IdentityRelation, FromTo>;
151
137
 
152
138
  constructor(props: { id?: Uint8Array; rootTrust: PublicSignKey | PeerId }) {
153
139
  super();
@@ -159,29 +145,20 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
159
145
  await this.trustGraph.open({
160
146
  type: IdentityRelation,
161
147
  canPerform: this.canPerform.bind(this),
162
- role: options?.role || {
163
- type: "replicator",
164
- factor: 1
148
+ replicate: options?.replicate || {
149
+ factor: 1,
165
150
  },
166
151
  index: {
167
152
  canRead: this.canRead.bind(this),
168
- fields: (obj, _entry) => {
169
- return {
170
- from: obj.from.hashcode(),
171
- to: obj.to.hashcode()
172
- };
173
- }
174
- }
153
+ type: FromTo,
154
+ },
175
155
  }); // self referencing access controller
176
156
  }
177
157
 
178
158
  async canPerform(
179
- operation: PutOperation<IdentityRelation> | DeleteOperation,
180
- context: TransactionContext<IdentityRelation>
159
+ properties: CanPerformOperations<IdentityRelation>,
181
160
  ): Promise<boolean> {
182
- return canPerformByRelation(operation, context, (key) =>
183
- this.isTrusted(key)
184
- );
161
+ return canPerformByRelation(properties, (key) => this.isTrusted(key));
185
162
  }
186
163
 
187
164
  async canRead(relation: any, publicKey?: PublicSignKey): Promise<boolean> {
@@ -189,7 +166,7 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
189
166
  }
190
167
 
191
168
  async add(
192
- trustee: PublicSignKey | PeerId
169
+ trustee: PublicSignKey | PeerId,
193
170
  ): Promise<IdentityRelation | undefined> {
194
171
  const key =
195
172
  trustee instanceof PublicSignKey
@@ -198,12 +175,12 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
198
175
 
199
176
  const existingRelation = await this.getRelation(
200
177
  key,
201
- this.node.identity.publicKey
178
+ this.node.identity.publicKey,
202
179
  );
203
180
  if (!existingRelation) {
204
181
  const relation = new IdentityRelation({
205
182
  to: key,
206
- from: this.node.identity.publicKey
183
+ from: this.node.identity.publicKey,
207
184
  });
208
185
  await this.trustGraph.put(relation);
209
186
  return relation;
@@ -213,18 +190,18 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
213
190
 
214
191
  async hasRelation(
215
192
  trustee: PublicSignKey | PeerId,
216
- truster: PublicSignKey | PeerId = this.rootTrust
193
+ truster: PublicSignKey | PeerId = this.rootTrust,
217
194
  ) {
218
195
  return !!(await this.getRelation(trustee, truster));
219
196
  }
220
197
  getRelation(
221
198
  trustee: PublicSignKey | PeerId,
222
- truster: PublicSignKey | PeerId = this.rootTrust
199
+ truster: PublicSignKey | PeerId = this.rootTrust,
223
200
  ) {
224
201
  return getRelation(
225
202
  coercePublicKey(truster),
226
203
  coercePublicKey(trustee),
227
- this.trustGraph
204
+ this.trustGraph,
228
205
  );
229
206
  }
230
207
 
@@ -235,21 +212,21 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
235
212
  * Root trust A trust B trust C
236
213
  * C is trusted by Root
237
214
  * @param trustee
238
- * @param truster, the truster "root", if undefined defaults to the root trust
215
+ * @param truster the truster "root", if undefined defaults to the root trust
239
216
  * @returns true, if trusted
240
217
  */
241
218
  async isTrusted(
242
219
  trustee: PublicSignKey,
243
- truster: PublicSignKey = this.rootTrust
220
+ truster: PublicSignKey = this.rootTrust,
244
221
  ): Promise<boolean> {
245
222
  if (trustee.equals(this.rootTrust)) {
246
223
  return true;
247
224
  }
248
- if (this.trustGraph.log.role instanceof Replicator) {
225
+ if (await this.trustGraph.log.isReplicating()) {
249
226
  return this._isTrustedLocal(trustee, truster);
250
227
  } else {
251
228
  this.trustGraph.index.search(new SearchRequest({ query: [] }), {
252
- remote: { sync: true }
229
+ remote: { sync: true },
253
230
  });
254
231
  return this._isTrustedLocal(trustee, truster);
255
232
  }
@@ -257,13 +234,13 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
257
234
 
258
235
  async _isTrustedLocal(
259
236
  trustee: PublicSignKey,
260
- truster: PublicSignKey = this.rootTrust
237
+ truster: PublicSignKey = this.rootTrust,
261
238
  ): Promise<boolean> {
262
239
  const trustPath = await hasPath(
263
240
  trustee,
264
241
  truster,
265
242
  this.trustGraph,
266
- getFromByTo
243
+ getFromByTo,
267
244
  );
268
245
  return !!trustPath;
269
246
  }
@@ -282,3 +259,17 @@ export class TrustedNetwork extends Program<TrustedNetworkArgs> {
282
259
  return sha256Base64Sync(serialize(this));
283
260
  }
284
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
+ */
@@ -1,57 +1,63 @@
1
1
  import { field, fixedArray, serialize, variant } from "@dao-xyz/borsh";
2
- import { Documents, SearchRequest, StringMatch } from "@peerbit/document";
3
- import { PublicSignKey } from "@peerbit/crypto";
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 (to: PublicSignKey, db: Documents<IdentityRelation>) => {
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 (from: PublicSignKey, db: Documents<IdentityRelation>) => {
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
  });
@@ -1 +0,0 @@
1
- {"version":3,"file":"controller.js","sourceRoot":"","sources":["../../src/controller.ts"],"names":[],"mappings":";;;;;;;;;AAAA,OAAO,EAAe,KAAK,EAAE,SAAS,EAAE,OAAO,EAAO,MAAM,gBAAgB,CAAC;AAC7E,OAAO,EACN,aAAa,EACb,SAAS,EAET,YAAY,EAGZ,MAAM,mBAAmB,CAAC;AAE3B,OAAO,EAAE,aAAa,EAAE,sBAAsB,EAAE,MAAM,iBAAiB,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EACN,gBAAgB,EAChB,wBAAwB,EACxB,gBAAgB,EAChB,OAAO,EACP,WAAW,EACX,WAAW,EACX,WAAW,EACX,MAAM,qBAAqB,CAAC;AAC7B,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAC3C,OAAO,EAAE,gBAAgB,EAAE,MAAM,iBAAiB,CAAC;AAEnD,OAAO,EAAE,UAAU,EAAe,MAAM,qBAAqB,CAAC;AAE9D,MAAM,eAAe,GAAG,CAAC,SAAiC,EAAE,EAAE;IAC7D,OAAO,SAAS,YAAY,aAAa;QACxC,CAAC,CAAC,SAAS;QACX,CAAC,CAAC,sBAAsB,CAAC,SAAS,CAAC,CAAC;AACtC,CAAC,CAAC;AACF,MAAM,oBAAoB,GAAG,KAAK,EACjC,SAA2D,EAC3D,OAA6C,EAC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