@didcid/gatekeeper 0.1.3 → 0.3.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.
@@ -0,0 +1,118 @@
1
+ export default class SearchIndex {
2
+ docs = new Map();
3
+ static ARRAY_WILDCARD_END = /\[\*]$/;
4
+ static ARRAY_WILDCARD_MID = /\[\*]\./;
5
+ store(did, doc) {
6
+ // Only index didDocumentData to focus on actual content
7
+ const data = doc.didDocumentData;
8
+ if (data && typeof data === 'object') {
9
+ this.docs.set(did, JSON.parse(JSON.stringify(data)));
10
+ }
11
+ else {
12
+ this.docs.set(did, {});
13
+ }
14
+ }
15
+ delete(did) {
16
+ this.docs.delete(did);
17
+ }
18
+ clear() {
19
+ this.docs.clear();
20
+ }
21
+ get size() {
22
+ return this.docs.size;
23
+ }
24
+ searchDocs(q) {
25
+ const out = [];
26
+ for (const [did, doc] of this.docs.entries()) {
27
+ if (JSON.stringify(doc).includes(q))
28
+ out.push(did);
29
+ }
30
+ return out;
31
+ }
32
+ queryDocs(where) {
33
+ const entry = Object.entries(where)[0];
34
+ if (!entry) {
35
+ return [];
36
+ }
37
+ const [rawPath, cond] = entry;
38
+ if (typeof cond !== 'object' || cond === null || !Array.isArray(cond.$in)) {
39
+ throw new Error('Only {$in:[...]} supported');
40
+ }
41
+ const list = cond.$in;
42
+ const isKeyWildcard = rawPath.endsWith('.*');
43
+ const isValueWildcard = rawPath.includes('.*.');
44
+ const isArrayTail = SearchIndex.ARRAY_WILDCARD_END.test(rawPath);
45
+ const isArrayMid = SearchIndex.ARRAY_WILDCARD_MID.test(rawPath);
46
+ const result = [];
47
+ for (const [did, doc] of this.docs.entries()) {
48
+ let match = false;
49
+ if (isArrayTail) {
50
+ const basePath = rawPath.replace(SearchIndex.ARRAY_WILDCARD_END, '');
51
+ const arr = this.getPath(doc, basePath);
52
+ if (Array.isArray(arr)) {
53
+ match = arr.some(v => list.includes(v));
54
+ }
55
+ }
56
+ else if (isArrayMid) {
57
+ const [prefix, suffix] = rawPath.split('[*].');
58
+ const arr = this.getPath(doc, prefix);
59
+ if (Array.isArray(arr)) {
60
+ match = arr.some(el => list.includes(this.getPath(el, suffix)));
61
+ }
62
+ }
63
+ else if (isKeyWildcard) {
64
+ const basePath = rawPath.slice(0, -2);
65
+ const obj = this.getPath(doc, basePath);
66
+ if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
67
+ const keys = Object.keys(obj);
68
+ match = keys.some(k => list.includes(k));
69
+ }
70
+ }
71
+ else if (isValueWildcard) {
72
+ const [prefix, suffix] = rawPath.split('.*.');
73
+ const obj = this.getPath(doc, prefix);
74
+ if (obj && typeof obj === 'object' && !Array.isArray(obj)) {
75
+ const values = Object.values(obj);
76
+ match = values.some(v => list.includes(this.getPath(v, suffix)));
77
+ }
78
+ }
79
+ else {
80
+ const val = this.getPath(doc, rawPath);
81
+ match = list.includes(val);
82
+ }
83
+ if (match) {
84
+ result.push(did);
85
+ }
86
+ }
87
+ return result;
88
+ }
89
+ getPath(root, path) {
90
+ if (!path || root == null) {
91
+ return undefined;
92
+ }
93
+ const clean = path.startsWith('$.') ? path.slice(2) : path.startsWith('$') ? path.slice(1) : path;
94
+ if (!clean) {
95
+ return root;
96
+ }
97
+ const parts = clean.split('.');
98
+ let cur = root;
99
+ for (const rawPart of parts) {
100
+ if (cur == null) {
101
+ return undefined;
102
+ }
103
+ const idx = Number.isInteger(+rawPart) ? +rawPart : null;
104
+ if (idx !== null && Array.isArray(cur)) {
105
+ cur = cur[idx];
106
+ continue;
107
+ }
108
+ if (typeof cur === 'object') {
109
+ cur = cur[rawPart];
110
+ }
111
+ else {
112
+ return undefined;
113
+ }
114
+ }
115
+ return cur;
116
+ }
117
+ }
118
+ //# sourceMappingURL=search-index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"search-index.js","sourceRoot":"","sources":["../../src/search-index.ts"],"names":[],"mappings":"AAMA,MAAM,CAAC,OAAO,OAAO,WAAW;IACpB,IAAI,G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C;YAC1B,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC;gBACd,OAAO,SAAS,CAAC;YACrB,CAAC;YAED,MAAM,GAAG,GAAG,MAAM,CAAC,SAAS,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,CAAC,CAAC,IAAI,CAAC;YAEzD,IAAI,GAAG,KAAK,IAAI,IAAI,KAAK,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;gBACrC,GAAG,GAAG,GAAG,CAAC,GAAG,CAAC,CAAC;gBACf,SAAS;YACb,CAAC;YAED,IAAI,OAAO,GAAG,KAAK,QAAQ,EAAE,CAAC;gBAC1B,GAAG,GAAI,GAA+B,CAAC,OAAO,CAAC,CAAC;YACpD,CAAC;iBAAM,CAAC;gBACJ,OAAO,SAAS,CAAC;YACrB,CAAC;QACL,CAAC;QACD,OAAO,GAAG,CAAC;IACf,CAAC"}
@@ -37,4 +37,9 @@ export default class GatekeeperClient implements GatekeeperInterface {
37
37
  getBlock(registry: string, block?: BlockId): Promise<BlockInfo | null>;
38
38
  addBlock(registry: string, block: BlockInfo): Promise<boolean>;
39
39
  generateDID(operation: Operation): Promise<string>;
40
+ searchDocs(q: string): Promise<string[]>;
41
+ queryDocs(where: Record<string, unknown>): Promise<string[]>;
42
+ search(query: {
43
+ where: Record<string, unknown>;
44
+ }): Promise<string[]>;
40
45
  }
@@ -1,4 +1,4 @@
1
- import { BatchMetadata, BlockId, BlockInfo, CheckDIDsOptions, GatekeeperInterface, GatekeeperEvent, GatekeeperOptions, ImportEventsResult, Operation, DidCidDocument, ResolveDIDOptions, GetDIDOptions, CheckDIDsResult, ImportBatchResult, ProcessEventsResult, VerifyDbResult, Signature } from './types.js';
1
+ import { BatchMetadata, BlockId, BlockInfo, CheckDIDsOptions, GatekeeperInterface, GatekeeperEvent, GatekeeperOptions, ImportEventsResult, Operation, DidCidDocument, ResolveDIDOptions, GetDIDOptions, CheckDIDsResult, ImportBatchResult, ProcessEventsResult, VerifyDbResult, Proof } from './types.js';
2
2
  declare enum ImportStatus {
3
3
  ADDED = "added",
4
4
  MERGED = "merged",
@@ -18,7 +18,10 @@ export default class Gatekeeper implements GatekeeperInterface {
18
18
  private readonly maxQueueSize;
19
19
  supportedRegistries: string[];
20
20
  private didLocks;
21
+ private searchIndex;
21
22
  constructor(options: GatekeeperOptions);
23
+ initSearchIndex(): Promise<void>;
24
+ private updateSearchIndex;
22
25
  private withDidLock;
23
26
  verifyDb(options?: {
24
27
  chatty?: boolean;
@@ -32,7 +35,7 @@ export default class Gatekeeper implements GatekeeperInterface {
32
35
  verifyDIDFormat(did: string): boolean;
33
36
  verifyDateFormat(time?: string): boolean;
34
37
  verifyHashFormat(hash: string): boolean;
35
- verifySignatureFormat(signature?: Signature): boolean;
38
+ verifyProofFormat(proof?: Proof): boolean;
36
39
  verifyCreateOperation(operation: Operation): Promise<boolean>;
37
40
  verifyUpdateOperation(operation: Operation, doc: DidCidDocument): Promise<boolean>;
38
41
  queueOperation(registry: string, operation: Operation): Promise<void>;
@@ -63,5 +66,10 @@ export default class Gatekeeper implements GatekeeperInterface {
63
66
  getData(cid: string): Promise<Buffer | null>;
64
67
  addJSON(json: object): Promise<string>;
65
68
  getJSON(cid: string): Promise<object | null>;
69
+ searchDocs(q: string): Promise<string[]>;
70
+ queryDocs(where: Record<string, unknown>): Promise<string[]>;
71
+ search(query: {
72
+ where: Record<string, unknown>;
73
+ }): Promise<string[]>;
66
74
  }
67
75
  export {};
@@ -0,0 +1,12 @@
1
+ export default class SearchIndex {
2
+ private docs;
3
+ private static readonly ARRAY_WILDCARD_END;
4
+ private static readonly ARRAY_WILDCARD_MID;
5
+ store(did: string, doc: object): void;
6
+ delete(did: string): void;
7
+ clear(): void;
8
+ get size(): number;
9
+ searchDocs(q: string): string[];
10
+ queryDocs(where: Record<string, unknown>): string[];
11
+ private getPath;
12
+ }
@@ -148,6 +148,11 @@ export interface GatekeeperInterface {
148
148
  getBlock(registry: string, block?: BlockId): Promise<BlockInfo | null>;
149
149
  addBlock(registry: string, block: BlockInfo): Promise<boolean>;
150
150
  generateDID(operation: Operation): Promise<string>;
151
+ searchDocs(q: string): Promise<string[]>;
152
+ queryDocs(where: Record<string, unknown>): Promise<string[]>;
153
+ search(query: {
154
+ where: Record<string, unknown>;
155
+ }): Promise<string[]>;
151
156
  }
152
157
  export interface DidRegistration {
153
158
  height?: number;
@@ -171,7 +176,8 @@ export interface DocumentMetadata {
171
176
  updated?: string;
172
177
  canonicalId?: string;
173
178
  versionId?: string;
174
- version?: string;
179
+ versionSequence?: string;
180
+ version?: number;
175
181
  confirmed?: boolean;
176
182
  deactivated?: boolean;
177
183
  deleted?: string;
@@ -189,6 +195,7 @@ export interface DidCidDocument {
189
195
  publicKeyJwk?: EcdsaJwkPublic;
190
196
  }>;
191
197
  authentication?: string[];
198
+ assertionMethod?: string[];
192
199
  };
193
200
  didDocumentMetadata?: DocumentMetadata;
194
201
  didResolutionMetadata?: {
@@ -199,16 +206,18 @@ export interface DidCidDocument {
199
206
  didDocumentData?: unknown;
200
207
  didDocumentRegistration?: DocumentRegistration;
201
208
  }
202
- export interface Signature {
203
- signer?: string;
204
- signed: string;
205
- hash: string;
206
- value: string;
209
+ export type ProofPurpose = "assertionMethod" | "authentication";
210
+ export interface Proof {
211
+ type: "EcdsaSecp256k1Signature2019";
212
+ created: string;
213
+ verificationMethod: string;
214
+ proofPurpose: ProofPurpose;
215
+ proofValue: string;
207
216
  }
208
217
  export interface Operation {
209
218
  type: 'create' | 'update' | 'delete';
210
219
  created?: string;
211
- signature?: Signature;
220
+ proof?: Proof;
212
221
  registration?: DocumentRegistration;
213
222
  publicJwk?: EcdsaJwkPublic;
214
223
  controller?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@didcid/gatekeeper",
3
- "version": "0.1.3",
3
+ "version": "0.3.0",
4
4
  "description": "Archon Gatekeeper",
5
5
  "type": "module",
6
6
  "module": "./dist/esm/index.js",
@@ -124,5 +124,5 @@
124
124
  "devDependencies": {
125
125
  "@rollup/plugin-json": "^6.1.0"
126
126
  },
127
- "gitHead": "dd45ee46bf0bad26d796e210f7837f36a1505960"
127
+ "gitHead": "1563f84a36453fd632771eea93e1aa911e3ebc33"
128
128
  }