@show-karma/karma-gap-sdk 0.2.9 → 0.3.2

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.
@@ -31,27 +31,27 @@ class GapEasClient extends Fetcher_1.Fetcher {
31
31
  name: '',
32
32
  schema: Schema_1.Schema.rawToObject(schema.schema),
33
33
  uid: schema.uid,
34
- }));
34
+ }, this.gap));
35
35
  }
36
36
  async attestation(uid) {
37
37
  const query = gql_queries_1.gqlQueries.attestation(uid);
38
38
  const { attestation } = await this.query(query);
39
- return Attestation_1.Attestation.fromInterface([attestation])[0];
39
+ return Attestation_1.Attestation.fromInterface([attestation], this.network.name)[0];
40
40
  }
41
41
  async attestations(schemaName, search) {
42
- const schema = GapSchema_1.GapSchema.find(schemaName);
42
+ const schema = this.gap.findSchema(schemaName);
43
43
  const query = gql_queries_1.gqlQueries.attestationsOf(schema.uid, search);
44
44
  const { schema: { attestations }, } = await this.query(query);
45
45
  return attestations;
46
46
  }
47
47
  async attestationsOf(schemaName, recipient) {
48
- const schema = GapSchema_1.GapSchema.find(schemaName);
48
+ const schema = this.gap.findSchema(schemaName);
49
49
  const query = gql_queries_1.gqlQueries.attestationsOf(schema.uid, recipient);
50
50
  const { schema: { attestations }, } = await this.query(query);
51
51
  return attestations;
52
52
  }
53
53
  async attestationsTo(schemaName, recipient) {
54
- const schema = GapSchema_1.GapSchema.find(schemaName);
54
+ const schema = this.gap.findSchema(schemaName);
55
55
  const query = gql_queries_1.gqlQueries.attestationsTo(schema.uid, recipient);
56
56
  const { schema: { attestations }, } = await this.query(query);
57
57
  return attestations;
@@ -62,31 +62,31 @@ class GapEasClient extends Fetcher_1.Fetcher {
62
62
  * @param parentUid the parent uid to get dependents of.
63
63
  */
64
64
  async dependentsOf(parentSchema, parentUid) {
65
- const parent = GapSchema_1.GapSchema.find(parentSchema);
65
+ const parent = this.gap.findSchema(parentSchema);
66
66
  const children = parent.children.map((c) => c.uid);
67
67
  if (!children.length)
68
68
  throw new SchemaError_1.SchemaError('INVALID_REFERENCE', `Schema ${parentSchema} has no children.`);
69
69
  const query = gql_queries_1.gqlQueries.dependentsOf(parentUid, children);
70
70
  const { attestations } = await this.query(query);
71
- return Attestation_1.Attestation.fromInterface(attestations);
71
+ return Attestation_1.Attestation.fromInterface(attestations, this.network.name);
72
72
  }
73
73
  async communities(search) {
74
- const [community, communityDetails] = GapSchema_1.GapSchema.findMany([
74
+ const [community, communityDetails] = this.gap.findManySchemas([
75
75
  'Community',
76
76
  'CommunityDetails',
77
77
  ]);
78
78
  const query = gql_queries_1.gqlQueries.attestationsOf(community.uid, search);
79
79
  const { schema: { attestations }, } = await this.query(query);
80
- const communities = Attestation_1.Attestation.fromInterface(attestations);
80
+ const communities = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
81
81
  if (!communities.length)
82
82
  return [];
83
83
  return this.communitiesDetails(communities);
84
84
  }
85
85
  async communitiesOf(address) {
86
- const [community] = GapSchema_1.GapSchema.findMany(['Community']);
86
+ const [community] = this.gap.findManySchemas(['Community']);
87
87
  const query = gql_queries_1.gqlQueries.attestationsTo(community.uid, address);
88
88
  const { schema: { attestations }, } = await this.query(query);
89
- const communities = Attestation_1.Attestation.fromInterface(attestations);
89
+ const communities = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
90
90
  if (!communities.length)
91
91
  return [];
92
92
  return this.communitiesDetails(communities);
@@ -94,7 +94,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
94
94
  async communitiesByIds(uids) {
95
95
  if (!uids.length)
96
96
  return [];
97
- const communityDetails = GapSchema_1.GapSchema.find('CommunityDetails');
97
+ const communityDetails = this.gap.findSchema('CommunityDetails');
98
98
  const communityQuery = gql_queries_1.gqlQueries.attestationsIn(uids);
99
99
  const detailsQuery = gql_queries_1.gqlQueries.dependentsOf(uids, [communityDetails.uid]);
100
100
  try {
@@ -102,8 +102,8 @@ class GapEasClient extends Fetcher_1.Fetcher {
102
102
  this.query(communityQuery),
103
103
  this.query(detailsQuery),
104
104
  ]);
105
- const communitiesAttestations = Attestation_1.Attestation.fromInterface(communities.attestations || []);
106
- const detailsAttestations = Attestation_1.Attestation.fromInterface(details.attestations || []);
105
+ const communitiesAttestations = Attestation_1.Attestation.fromInterface(communities.attestations || [], this.network.name);
106
+ const detailsAttestations = Attestation_1.Attestation.fromInterface(details.attestations || [], this.network.name);
107
107
  communitiesAttestations.forEach((community) => {
108
108
  community.details = detailsAttestations.find((d) => d.refUID === community.uid);
109
109
  });
@@ -114,13 +114,13 @@ class GapEasClient extends Fetcher_1.Fetcher {
114
114
  }
115
115
  }
116
116
  async communitiesDetails(communities) {
117
- const [project, communityDetails] = GapSchema_1.GapSchema.findMany([
117
+ const [project, communityDetails] = this.gap.findManySchemas([
118
118
  'Project',
119
119
  'CommunityDetails',
120
120
  ]);
121
121
  const ref = gql_queries_1.gqlQueries.dependentsOf(communities.map((c) => c.uid), [communityDetails.uid]);
122
122
  const results = await this.query(ref);
123
- const deps = Attestation_1.Attestation.fromInterface(results.attestations || []);
123
+ const deps = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
124
124
  return communities.map((community) => {
125
125
  community.projects = (deps.filter((ref) => ref.schema.uid === project.uid && ref.refUID === community.uid));
126
126
  community.details = (deps.find((ref) => ref.schema.uid === communityDetails.uid &&
@@ -129,13 +129,13 @@ class GapEasClient extends Fetcher_1.Fetcher {
129
129
  });
130
130
  }
131
131
  async communityBySlug(slug) {
132
- const communitySchema = GapSchema_1.GapSchema.find('CommunityDetails');
132
+ const communitySchema = this.gap.findSchema('CommunityDetails');
133
133
  const query = gql_queries_1.gqlQueries.attestationsOf(communitySchema.uid, this.getSearchFieldString('slug', slug));
134
134
  try {
135
135
  const { schema: { attestations }, } = await this.query(query);
136
136
  if (!attestations.length)
137
137
  throw new Error('Community not found.');
138
- const communities = (0, utils_1.mapFilter)(Attestation_1.Attestation.fromInterface(attestations), (details) => !!details.name, (details) => {
138
+ const communities = (0, utils_1.mapFilter)(Attestation_1.Attestation.fromInterface(attestations, this.network.name), (details) => !!details.name, (details) => {
139
139
  const community = new Community_1.Community({
140
140
  data: { community: true },
141
141
  uid: details.refUID,
@@ -161,7 +161,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
161
161
  const { attestation } = await this.query(query);
162
162
  if (!attestation)
163
163
  throw new Error('Community not found.');
164
- const communities = Attestation_1.Attestation.fromInterface([attestation]).map((c) => new Community_1.Community(c));
164
+ const communities = Attestation_1.Attestation.fromInterface([attestation], this.network.name).map((c) => new Community_1.Community(c));
165
165
  const [withDetails] = await this.communitiesDetails(communities);
166
166
  if (!withDetails)
167
167
  throw new Error('Community not found.');
@@ -177,14 +177,14 @@ class GapEasClient extends Fetcher_1.Fetcher {
177
177
  */
178
178
  async projectsDetails(projects) {
179
179
  // Get projects array and fetch details, members, grants, etc then append to the project and return the array.
180
- const [projectDetails] = GapSchema_1.GapSchema.findMany(['ProjectDetails']);
180
+ const [projectDetails] = this.gap.findManySchemas(['ProjectDetails']);
181
181
  const refQuery = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [projectDetails.uid]);
182
182
  const [result, members, grants] = await Promise.all([
183
183
  this.query(refQuery),
184
184
  this.membersOf(projects),
185
185
  this.grantsFor(projects, true),
186
186
  ]);
187
- const deps = Attestation_1.Attestation.fromInterface(result.attestations || []);
187
+ const deps = Attestation_1.Attestation.fromInterface(result.attestations || [], this.network.name);
188
188
  return projects.map((project) => {
189
189
  project.details = (deps.find((ref) => ref.schema.uid === projectDetails.uid && ref.refUID === project.uid));
190
190
  project.members = members.filter((m) => m.refUID === project.uid);
@@ -197,25 +197,23 @@ class GapEasClient extends Fetcher_1.Fetcher {
197
197
  const { attestation } = await this.query(query);
198
198
  if (!attestation)
199
199
  throw new Error('Project not found.');
200
- const projectAttestation = Attestation_1.Attestation.fromInterface([
201
- attestation,
202
- ])[0];
200
+ const projectAttestation = Attestation_1.Attestation.fromInterface([attestation], this.network.name)[0];
203
201
  const [result] = await this.projectsDetails([
204
202
  new entities_1.Project(projectAttestation),
205
203
  ]);
206
204
  return result;
207
205
  }
208
206
  async projectBySlug(slug) {
209
- const projectDetails = GapSchema_1.GapSchema.find('ProjectDetails');
207
+ const projectDetails = this.gap.findSchema('ProjectDetails');
210
208
  const query = gql_queries_1.gqlQueries.attestationsOf(projectDetails.uid, this.getSearchFieldString('slug', slug));
211
209
  const { schema: { attestations }, } = await this.query(query);
212
- const projectAttestations = Attestation_1.Attestation.fromInterface(attestations).filter((p) => p.title);
210
+ const projectAttestations = Attestation_1.Attestation.fromInterface(attestations, this.network.name).filter((p) => p.title);
213
211
  if (!projectAttestations.length)
214
212
  throw new Error('Project not found.');
215
213
  const project = new entities_1.Project({
216
214
  data: { project: true },
217
215
  uid: projectAttestations[0].refUID,
218
- schema: GapSchema_1.GapSchema.find('Project'),
216
+ schema: this.gap.findSchema('Project'),
219
217
  recipient: projectAttestations[0].recipient,
220
218
  });
221
219
  const [withDetails] = await this.projectsDetails([project]);
@@ -224,7 +222,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
224
222
  return withDetails;
225
223
  }
226
224
  async slugExists(slug) {
227
- const details = GapSchema_1.GapSchema.find('ProjectDetails');
225
+ const details = this.gap.findSchema('ProjectDetails');
228
226
  const query = gql_queries_1.gqlQueries.attestationsOf(details.uid, 'slug');
229
227
  const { schema: { attestations }, } = await this.query(query);
230
228
  return attestations.some((a) => a.decodedDataJson.includes(slug));
@@ -236,14 +234,14 @@ class GapEasClient extends Fetcher_1.Fetcher {
236
234
  const result = await this.attestations('Project', name);
237
235
  if (!result.length)
238
236
  return [];
239
- const projects = Attestation_1.Attestation.fromInterface(result);
237
+ const projects = Attestation_1.Attestation.fromInterface(result, this.network.name);
240
238
  return this.projectsDetails(projects);
241
239
  }
242
240
  async projectsOf(grantee) {
243
241
  const result = await this.attestationsTo('Project', grantee);
244
242
  if (!result.length)
245
243
  return [];
246
- const projects = Attestation_1.Attestation.fromInterface(result);
244
+ const projects = Attestation_1.Attestation.fromInterface(result, this.network.name);
247
245
  return this.projectsDetails(projects);
248
246
  }
249
247
  async grantee(address) {
@@ -262,19 +260,19 @@ class GapEasClient extends Fetcher_1.Fetcher {
262
260
  }, []);
263
261
  }
264
262
  async grantsOf(grantee, withCommunity) {
265
- const [grant, grantDetails, grantVerified] = GapSchema_1.GapSchema.findMany([
263
+ const [grant, grantDetails, grantVerified] = this.gap.findManySchemas([
266
264
  'Grant',
267
265
  'GrantDetails',
268
266
  'GrantVerified',
269
267
  ]);
270
268
  const query = gql_queries_1.gqlQueries.attestationsTo(grant.uid, grantee);
271
269
  const { schema: { attestations }, } = await this.query(query);
272
- const grants = Attestation_1.Attestation.fromInterface(attestations);
270
+ const grants = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
273
271
  if (!grants.length)
274
272
  return [];
275
273
  const ref = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [grantDetails.uid, grantVerified.uid], grants.map((g) => g.recipient));
276
274
  const results = await this.query(ref);
277
- const deps = Attestation_1.Attestation.fromInterface(results.attestations || []);
275
+ const deps = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
278
276
  const milestones = await this.milestonesOf(grants);
279
277
  const communities = withCommunity
280
278
  ? await this.communitiesByIds((0, utils_1.mapFilter)(grants, (g) => !!g.communityUID, (g) => g.communityUID))
@@ -292,17 +290,17 @@ class GapEasClient extends Fetcher_1.Fetcher {
292
290
  return this.grantsUpdates(withDetails);
293
291
  }
294
292
  async grantsUpdates(grants) {
295
- const details = GapSchema_1.GapSchema.find('GrantDetails');
293
+ const details = this.gap.findSchema('GrantDetails');
296
294
  const query = gql_queries_1.gqlQueries.attestationsOf(details.uid, this.getSearchFieldString('type', 'grant-update'), grants.map((g) => g.uid));
297
295
  const { schema: { attestations }, } = await this.query(query);
298
- const updates = Attestation_1.Attestation.fromInterface(attestations);
296
+ const updates = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
299
297
  return grants.map((grant) => {
300
298
  grant.updates = updates.filter((u) => u.refUID === grant.uid);
301
299
  return grant;
302
300
  });
303
301
  }
304
302
  async grantsByCommunity(uid) {
305
- const [grant, grantDetails, project, projectDetails] = GapSchema_1.GapSchema.findMany([
303
+ const [grant, grantDetails, project, projectDetails] = this.gap.findManySchemas([
306
304
  'Grant',
307
305
  'GrantDetails',
308
306
  'Project',
@@ -310,15 +308,15 @@ class GapEasClient extends Fetcher_1.Fetcher {
310
308
  ]);
311
309
  const query = gql_queries_1.gqlQueries.attestations(grant.uid, uid);
312
310
  const { schema: { attestations }, } = await this.query(query);
313
- const grants = Attestation_1.Attestation.fromInterface(attestations).map((g) => new entities_1.Grant(g));
311
+ const grants = Attestation_1.Attestation.fromInterface(attestations, this.network.name).map((g) => new entities_1.Grant(g));
314
312
  if (!grants.length)
315
313
  return [];
316
314
  const refs = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => [g.uid, g.refUID]).flat(), [grantDetails.uid, project.uid]);
317
315
  const results = await this.query(refs);
318
- const deps = Attestation_1.Attestation.fromInterface(results.attestations || []);
316
+ const deps = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
319
317
  const projectsQuery = gql_queries_1.gqlQueries.attestationsIn(grants.map((g) => g.refUID));
320
318
  const { attestations: projectAttestations } = await this.query(projectsQuery);
321
- const projects = Attestation_1.Attestation.fromInterface(projectAttestations);
319
+ const projects = Attestation_1.Attestation.fromInterface(projectAttestations, this.network.name);
322
320
  const milestones = await this.milestonesOf(grants);
323
321
  const getSummaryProject = (project) => ({
324
322
  title: project.details?.title,
@@ -342,7 +340,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
342
340
  .filter((g) => !!g.project);
343
341
  }
344
342
  async grantsFor(projects, withCommunity) {
345
- const [grant, grantDetails] = GapSchema_1.GapSchema.findMany([
343
+ const [grant, grantDetails] = this.gap.findManySchemas([
346
344
  'Grant',
347
345
  'GrantDetails',
348
346
  'Milestone',
@@ -351,11 +349,11 @@ class GapEasClient extends Fetcher_1.Fetcher {
351
349
  ]);
352
350
  const query = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [grant.uid]);
353
351
  const { attestations: grants } = await this.query(query);
354
- const grantsWithDetails = Attestation_1.Attestation.fromInterface(grants).map((g) => new entities_1.Grant(g));
352
+ const grantsWithDetails = Attestation_1.Attestation.fromInterface(grants, this.network.name).map((g) => new entities_1.Grant(g));
355
353
  const ref = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [grantDetails.uid]);
356
354
  const { attestations } = await this.query(ref);
357
355
  const milestones = await this.milestonesOf(grantsWithDetails);
358
- const deps = Attestation_1.Attestation.fromInterface(attestations);
356
+ const deps = Attestation_1.Attestation.fromInterface(attestations, this.network.name);
359
357
  // TODO unify this with grantsOf
360
358
  grantsWithDetails.forEach((grant) => {
361
359
  grant.details = (deps.find((d) => d.refUID === grant.uid &&
@@ -378,21 +376,21 @@ class GapEasClient extends Fetcher_1.Fetcher {
378
376
  a.createdAt.getTime() - b.createdAt.getTime());
379
377
  }
380
378
  async milestonesOf(grants) {
381
- const [milestone, milestoneApproved, milestoneCompleted] = GapSchema_1.GapSchema.findMany([
379
+ const [milestone, milestoneApproved, milestoneCompleted] = this.gap.findManySchemas([
382
380
  'Milestone',
383
381
  'MilestoneApproved',
384
382
  'MilestoneCompleted',
385
383
  ]);
386
384
  const query = gql_queries_1.gqlQueries.dependentsOf(grants.map((g) => g.uid), [milestone.uid]);
387
385
  const { attestations } = await this.query(query);
388
- const milestones = Attestation_1.Attestation.fromInterface(attestations)
386
+ const milestones = Attestation_1.Attestation.fromInterface(attestations, this.network.name)
389
387
  .map((milestone) => new entities_1.Milestone(milestone))
390
388
  .filter((m) => typeof m.endsAt !== 'undefined');
391
389
  if (!milestones.length)
392
390
  return [];
393
391
  const ref = gql_queries_1.gqlQueries.dependentsOf(milestones.map((m) => m.uid), [milestoneApproved.uid, milestoneCompleted.uid]);
394
392
  const results = await this.query(ref);
395
- const deps = Attestation_1.Attestation.fromInterface(results.attestations || []);
393
+ const deps = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
396
394
  return milestones.map((milestone) => {
397
395
  const refs = deps.filter((ref) => ref.refUID === milestone.uid);
398
396
  milestone.endsAt = (0, to_unix_1.toUnix)(milestone.endsAt);
@@ -403,7 +401,7 @@ class GapEasClient extends Fetcher_1.Fetcher {
403
401
  });
404
402
  }
405
403
  async membersOf(projects) {
406
- const [member, memberDetails] = GapSchema_1.GapSchema.findMany([
404
+ const [member, memberDetails] = this.gap.findManySchemas([
407
405
  'MemberOf',
408
406
  'MemberDetails',
409
407
  ]);
@@ -411,11 +409,11 @@ class GapEasClient extends Fetcher_1.Fetcher {
411
409
  return [];
412
410
  const query = gql_queries_1.gqlQueries.dependentsOf(projects.map((p) => p.uid), [member.uid], projects.map((p) => p.attester));
413
411
  const results = await this.query(query);
414
- const members = Attestation_1.Attestation.fromInterface(results.attestations || []);
412
+ const members = Attestation_1.Attestation.fromInterface(results.attestations || [], this.network.name);
415
413
  if (members.length) {
416
414
  const ref = gql_queries_1.gqlQueries.dependentsOf(members.map((a) => a.uid), [memberDetails.uid], members.map((a) => a.attester));
417
415
  const detailsResult = await this.query(ref);
418
- const detailsRef = Attestation_1.Attestation.fromInterface(detailsResult.attestations || []);
416
+ const detailsRef = Attestation_1.Attestation.fromInterface(detailsResult.attestations || [], this.network.name);
419
417
  members.forEach((member) => {
420
418
  member.details = detailsRef.find((d) => d.refUID === member.uid);
421
419
  });
@@ -1,5 +1,6 @@
1
1
  import { SchemaEncoder, SchemaItem, SchemaValue } from '@ethereum-attestation-service/eas-sdk';
2
- import { AttestArgs, Hex, MultiRevokeArgs, SchemaInterface, SignerOrProvider } from '../types';
2
+ import { AttestArgs, Hex, MultiRevokeArgs, SchemaInterface, SignerOrProvider, TNetwork } from '../types';
3
+ import { GAP } from './GAP';
3
4
  import { Attestation } from './Attestation';
4
5
  /**
5
6
  * Represents the EAS Schema and provides methods to encode and decode the schema,
@@ -67,20 +68,21 @@ import { Attestation } from './Attestation';
67
68
  * ```
68
69
  */
69
70
  export declare abstract class Schema<T extends string = string> implements SchemaInterface<T> {
70
- protected static schemas: Schema[];
71
+ protected static schemas: Record<TNetwork, Schema[]>;
71
72
  protected encoder: SchemaEncoder;
72
73
  private _schema;
73
74
  readonly uid: Hex;
74
75
  readonly name: string;
75
76
  readonly revocable?: boolean;
76
77
  readonly references?: T;
78
+ readonly gap: GAP;
77
79
  /**
78
80
  * Creates a new schema instance
79
81
  * @param args
80
82
  * @param strict If true, will throw an error if schema reference is not valid. With this option, user should add schemas
81
83
  * in a strict order.
82
84
  */
83
- constructor(args: SchemaInterface<T>, strict?: boolean, ignoreSchema?: boolean);
85
+ constructor(args: SchemaInterface<T>, gap?: GAP, strict?: boolean, ignoreSchema?: boolean);
84
86
  /**
85
87
  * Encode the schema to be used as payload in the attestation
86
88
  * @returns
@@ -153,7 +155,7 @@ export declare abstract class Schema<T extends string = string> implements Schem
153
155
  * @returns
154
156
  */
155
157
  multiRevoke(signer: SignerOrProvider, toRevoke: MultiRevokeArgs[]): Promise<void>;
156
- static exists(name: string): Schema<string>;
158
+ static exists(name: string, network: TNetwork): Schema<string>;
157
159
  /**
158
160
  * Adds the schema signature to a shares list. Use Schema.get("SchemaName") to get the schema.
159
161
  *
@@ -161,32 +163,32 @@ export declare abstract class Schema<T extends string = string> implements Schem
161
163
  * of the class AND its data can be overriden by any changes.__
162
164
  * @param schemas
163
165
  */
164
- static add<T extends Schema>(...schemas: T[]): void;
165
- static getAll<T extends Schema>(): T[];
166
- static get<N extends string, T extends Schema>(name: N): T;
166
+ static add<T extends Schema>(network: TNetwork, ...schemas: T[]): void;
167
+ static getAll<T extends Schema>(network: TNetwork): T[];
168
+ static get<N extends string, T extends Schema>(name: N, network: TNetwork): T;
167
169
  /**
168
170
  * Find many schemas by name and return them as an array in the same order.
169
171
  * @param names
170
172
  * @returns
171
173
  */
172
- static getMany<N extends string, T extends Schema>(names: N[]): T[];
173
- static getNames(): string[];
174
+ static getMany<N extends string, T extends Schema>(names: N[], network: TNetwork): T[];
175
+ static getNames(network: TNetwork): string[];
174
176
  /**
175
177
  * Validade references
176
178
  * @throws {SchemaError} if any reference is not valid
177
179
  * @returns {true} if references are valid
178
180
  */
179
- static validate(): true;
181
+ static validate(network: TNetwork): true;
180
182
  /**
181
183
  * Replaces the schema list with a new list.
182
184
  * @param schemas
183
185
  */
184
- static replaceAll(schemas: Schema[]): void;
186
+ static replaceAll(schemas: Schema[], network: TNetwork): void;
185
187
  /**
186
188
  * Replaces a schema from the schema list.
187
189
  * @throws {SchemaError} if desired schema name does not exist.
188
190
  */
189
- static replaceOne(schema: Schema): void;
191
+ static replaceOne(schema: Schema, network: TNetwork): void;
190
192
  /**
191
193
  * Transforms the given raw schema to SchemaItem[]
192
194
  *
@@ -79,9 +79,10 @@ class Schema {
79
79
  * @param strict If true, will throw an error if schema reference is not valid. With this option, user should add schemas
80
80
  * in a strict order.
81
81
  */
82
- constructor(args, strict = false, ignoreSchema = false) {
82
+ constructor(args, gap, strict = false, ignoreSchema = false) {
83
83
  this._schema = [];
84
84
  this.assert(args, strict);
85
+ this.gap = gap;
85
86
  this._schema = args.schema;
86
87
  this.uid = args.uid;
87
88
  this.name = args.name;
@@ -162,7 +163,7 @@ class Schema {
162
163
  // if (!uid) {
163
164
  // throw new SchemaError("MISSING_FIELD", "Schema uid is required");
164
165
  // }
165
- if (strict && references && !Schema.exists(references)) {
166
+ if (strict && references && !Schema.exists(references, this.gap.network)) {
166
167
  throw new SchemaError_1.SchemaError('INVALID_REFERENCE', `Schema ${name} references ${references} but it does not exist.`);
167
168
  }
168
169
  }
@@ -171,7 +172,7 @@ class Schema {
171
172
  * @returns
172
173
  */
173
174
  async attestOffchain({ data, signer, to, refUID }) {
174
- const eas = await GAP_1.GAP.eas.getOffchain();
175
+ const eas = await this.gap.eas.getOffchain();
175
176
  const payload = {
176
177
  data,
177
178
  version: eas.version,
@@ -191,7 +192,7 @@ class Schema {
191
192
  * @returns
192
193
  */
193
194
  async revokeOffchain(uid, signer) {
194
- const eas = GAP_1.GAP.eas.connect(signer);
195
+ const eas = this.gap.eas.connect(signer);
195
196
  return eas.revokeOffchain(uid);
196
197
  }
197
198
  /**
@@ -201,7 +202,7 @@ class Schema {
201
202
  * @returns
202
203
  */
203
204
  async multiRevokeOffchain(uids, signer) {
204
- const eas = GAP_1.GAP.eas.connect(signer);
205
+ const eas = this.gap.eas.connect(signer);
205
206
  return eas.multiRevokeOffchain(uids);
206
207
  }
207
208
  /**
@@ -219,7 +220,7 @@ class Schema {
219
220
  * @returns {Object} An object containing the attestation results, including the CID if 'ipfsKey' is enabled.
220
221
  */
221
222
  async attest({ data, to, signer, refUID }) {
222
- const eas = GAP_1.GAP.eas.connect(signer);
223
+ const eas = this.gap.eas.connect(signer);
223
224
  if (this.references && !refUID)
224
225
  throw new SchemaError_1.AttestationError('INVALID_REFERENCE', 'Attestation schema references another schema but no reference UID was provided.');
225
226
  if (this.isJsonSchema()) {
@@ -278,7 +279,7 @@ class Schema {
278
279
  if (this.references && !entity.refUID)
279
280
  throw new SchemaError_1.SchemaError('INVALID_REF_UID', `Entity ${entity.schema.name} references another schema but no reference UID was provided.`);
280
281
  });
281
- const eas = GAP_1.GAP.eas.connect(signer);
282
+ const eas = this.gap.eas.connect(signer);
282
283
  const entityBySchema = entities.reduce((acc, entity) => {
283
284
  const schema = entity.schema.uid;
284
285
  if (!acc[schema])
@@ -313,7 +314,7 @@ class Schema {
313
314
  acc[schemaId].push(uid);
314
315
  return acc;
315
316
  }, {});
316
- const eas = GAP_1.GAP.eas.connect(signer);
317
+ const eas = this.gap.eas.connect(signer);
317
318
  const payload = Object.entries(groupBySchema).map(([schema, uids]) => ({
318
319
  schema,
319
320
  data: uids.map((uid) => ({ uid })),
@@ -323,8 +324,8 @@ class Schema {
323
324
  });
324
325
  return tx.wait();
325
326
  }
326
- static exists(name) {
327
- return this.schemas.find((schema) => schema.name === name);
327
+ static exists(name, network) {
328
+ return this.schemas[network].find((schema) => schema.name === name);
328
329
  }
329
330
  /**
330
331
  * Adds the schema signature to a shares list. Use Schema.get("SchemaName") to get the schema.
@@ -333,21 +334,21 @@ class Schema {
333
334
  * of the class AND its data can be overriden by any changes.__
334
335
  * @param schemas
335
336
  */
336
- static add(...schemas) {
337
+ static add(network, ...schemas) {
337
338
  schemas.forEach((schema) => {
338
- if (!this.exists(schema.name))
339
- this.schemas.push(schema);
339
+ if (!this.exists(schema.name, network))
340
+ this.schemas[network].push(schema);
340
341
  else
341
342
  throw new SchemaError_1.SchemaError('SCHEMA_ALREADY_EXISTS', `Schema ${schema.name} already exists.`);
342
343
  });
343
344
  }
344
- static getAll() {
345
- return this.schemas;
345
+ static getAll(network) {
346
+ return this.schemas[network];
346
347
  }
347
- static get(name) {
348
- const schema = this.schemas.find((schema) => schema.name === name || schema.uid === name);
348
+ static get(name, network) {
349
+ const schema = this.schemas[network].find((schema) => schema.name === name || schema.uid === name);
349
350
  if (!schema)
350
- throw new SchemaError_1.SchemaError('SCHEMA_NOT_FOUND', `Schema ${name} not found. Available schemas: ${Schema.getNames()}`);
351
+ throw new SchemaError_1.SchemaError('SCHEMA_NOT_FOUND', `Schema ${name} not found. Available schemas: ${Schema.getNames(network)}`);
351
352
  return schema;
352
353
  }
353
354
  /**
@@ -355,21 +356,21 @@ class Schema {
355
356
  * @param names
356
357
  * @returns
357
358
  */
358
- static getMany(names) {
359
- return names.map((name) => this.get(name));
359
+ static getMany(names, network) {
360
+ return names.map((name) => this.get(name, network));
360
361
  }
361
- static getNames() {
362
- return Schema.schemas.map((schema) => schema.name);
362
+ static getNames(network) {
363
+ return Schema.schemas[network].map((schema) => schema.name);
363
364
  }
364
365
  /**
365
366
  * Validade references
366
367
  * @throws {SchemaError} if any reference is not valid
367
368
  * @returns {true} if references are valid
368
369
  */
369
- static validate() {
370
+ static validate(network) {
370
371
  const errors = [];
371
- this.schemas.forEach((schema) => {
372
- if (!schema.references || Schema.exists(schema.references))
372
+ this.schemas[network].forEach((schema) => {
373
+ if (!schema.references || Schema.exists(schema.references, network))
373
374
  return;
374
375
  else
375
376
  errors.push(new SchemaError_1.SchemaError('INVALID_REFERENCE', `Schema ${schema.name} references ${schema.references} but it does not exist.`));
@@ -382,15 +383,15 @@ class Schema {
382
383
  * Replaces the schema list with a new list.
383
384
  * @param schemas
384
385
  */
385
- static replaceAll(schemas) {
386
- this.schemas = schemas;
386
+ static replaceAll(schemas, network) {
387
+ this.schemas[network] = schemas;
387
388
  }
388
389
  /**
389
390
  * Replaces a schema from the schema list.
390
391
  * @throws {SchemaError} if desired schema name does not exist.
391
392
  */
392
- static replaceOne(schema) {
393
- const idx = this.schemas.findIndex((item) => schema.name === item.name);
393
+ static replaceOne(schema, network) {
394
+ const idx = this.schemas[network].findIndex((item) => schema.name === item.name);
394
395
  if (!~idx)
395
396
  throw new SchemaError_1.SchemaError('SCHEMA_NOT_FOUND', `Schema ${schema.name} not found.`);
396
397
  this.schemas[idx] = schema;
@@ -434,7 +435,7 @@ class Schema {
434
435
  * the changes made to it will reflect the original instance.
435
436
  */
436
437
  get children() {
437
- return Schema.schemas.filter((schema) => schema.references === this.name || schema.references === this.uid);
438
+ return Schema.schemas[this.gap.network].filter((schema) => schema.references === this.name || schema.references === this.uid);
438
439
  }
439
440
  /**
440
441
  * Asserts and sets the schema value.
@@ -446,4 +447,9 @@ class Schema {
446
447
  }
447
448
  }
448
449
  exports.Schema = Schema;
449
- Schema.schemas = [];
450
+ Schema.schemas = {
451
+ 'optimism-goerli': [],
452
+ optimism: [],
453
+ sepolia: [],
454
+ arbitrum: [],
455
+ };