@show-karma/karma-gap-sdk 0.1.31 → 0.1.33

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,7 +1,7 @@
1
- import { Hex, IAttestation, JSONStr, MultiAttestData, SignerOrProvider } from "../types";
2
- import { Schema } from "./Schema";
3
- import { SchemaItem, SchemaValue } from "@ethereum-attestation-service/eas-sdk";
4
- import { GapSchema } from "./GapSchema";
1
+ import { Hex, IAttestation, JSONStr, MultiAttestData, SignerOrProvider } from '../types';
2
+ import { Schema } from './Schema';
3
+ import { SchemaItem, SchemaValue } from '@ethereum-attestation-service/eas-sdk';
4
+ import { GapSchema } from './GapSchema';
5
5
  export interface AttestationArgs<T = unknown, S extends Schema = Schema> {
6
6
  data: T | string;
7
7
  schema: S;
@@ -48,7 +48,7 @@ class Attestation {
48
48
  this.recipient = args.recipient;
49
49
  this.revoked = args.revoked;
50
50
  this.revocationTime = (0, get_date_1.getDate)(args.revocationTime);
51
- this.createdAt = (0, get_date_1.getDate)(args.createdAt || Date.now());
51
+ this.createdAt = (0, get_date_1.getDate)(args.createdAt || Date.now() / 1000);
52
52
  }
53
53
  /**
54
54
  * Encodes the schema.
@@ -70,7 +70,7 @@ class Attestation {
70
70
  setValues(values) {
71
71
  const isJsonSchema = this.schema.isJsonSchema();
72
72
  if (isJsonSchema)
73
- this.schema.setValue("json", JSON.stringify(values));
73
+ this.schema.setValue('json', JSON.stringify(values));
74
74
  this._data = values;
75
75
  Object.entries(values).forEach(([key, value]) => {
76
76
  this[key] = value;
@@ -90,7 +90,7 @@ class Attestation {
90
90
  * @returns
91
91
  */
92
92
  fromDecodedSchema(data) {
93
- return typeof data === "string"
93
+ return typeof data === 'string'
94
94
  ? Attestation.fromDecodedSchema(data)
95
95
  : data;
96
96
  }
@@ -116,7 +116,7 @@ class Attestation {
116
116
  }
117
117
  catch (error) {
118
118
  console.error(error);
119
- throw new SchemaError_1.SchemaError("REVOKE_ERROR", "Error revoking attestation.");
119
+ throw new SchemaError_1.SchemaError('REVOKE_ERROR', 'Error revoking attestation.');
120
120
  }
121
121
  }
122
122
  /**
@@ -140,7 +140,7 @@ class Attestation {
140
140
  }
141
141
  catch (error) {
142
142
  console.error(error);
143
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Error during attestation.");
143
+ throw new SchemaError_1.AttestationError('ATTEST_ERROR', 'Error during attestation.');
144
144
  }
145
145
  }
146
146
  /**
@@ -218,17 +218,17 @@ class Attestation {
218
218
  const parsed = JSON.parse(data);
219
219
  if (data.length < 2 && !/\{.*\}/gim.test(data))
220
220
  return {};
221
- if (parsed.length === 1 && parsed[0].name === "json") {
221
+ if (parsed.length === 1 && parsed[0].name === 'json') {
222
222
  const { value } = parsed[0];
223
- return (typeof value.value === "string"
223
+ return (typeof value.value === 'string'
224
224
  ? JSON.parse(value.value)
225
225
  : value.value);
226
226
  }
227
227
  if (parsed && Array.isArray(parsed)) {
228
228
  return parsed.reduce((acc, curr) => {
229
229
  const { value } = curr.value;
230
- if (curr.type.includes("uint")) {
231
- acc[curr.name] = ["string", "bigint"].includes(typeof value)
230
+ if (curr.type.includes('uint')) {
231
+ acc[curr.name] = ['string', 'bigint'].includes(typeof value)
232
232
  ? BigInt(value)
233
233
  : Number(value);
234
234
  }
@@ -237,11 +237,11 @@ class Attestation {
237
237
  return acc;
238
238
  }, {});
239
239
  }
240
- throw new SchemaError_1.SchemaError("INVALID_DATA", "Data must be a valid JSON array string.");
240
+ throw new SchemaError_1.SchemaError('INVALID_DATA', 'Data must be a valid JSON array string.');
241
241
  }
242
242
  catch (error) {
243
243
  console.error(error);
244
- throw new SchemaError_1.SchemaError("INVALID_DATA", "Data must be a valid JSON string.");
244
+ throw new SchemaError_1.SchemaError('INVALID_DATA', 'Data must be a valid JSON string.');
245
245
  }
246
246
  }
247
247
  /**
@@ -272,10 +272,10 @@ class Attestation {
272
272
  assert(args, strict = false) {
273
273
  const { schema, uid } = args;
274
274
  if (!schema || !(schema instanceof Schema_1.Schema)) {
275
- throw new SchemaError_1.SchemaError("MISSING_FIELD", "Schema must be an array.");
275
+ throw new SchemaError_1.SchemaError('MISSING_FIELD', 'Schema must be an array.');
276
276
  }
277
277
  if (!uid) {
278
- throw new SchemaError_1.SchemaError("MISSING_FIELD", "Schema uid is required");
278
+ throw new SchemaError_1.SchemaError('MISSING_FIELD', 'Schema uid is required');
279
279
  }
280
280
  if (strict)
281
281
  Schema_1.Schema.validate();
@@ -303,7 +303,7 @@ class Attestation {
303
303
  recipient: to,
304
304
  attester: from,
305
305
  schema,
306
- uid: "0x0",
306
+ uid: '0x0',
307
307
  createdAt: new Date(),
308
308
  });
309
309
  }
@@ -1,6 +1,6 @@
1
- import { SignerOrProvider } from "../../types";
2
- import { Attestation } from "../Attestation";
3
- import { MilestoneCompleted } from "../types/attestations";
1
+ import { SignerOrProvider } from '../../types';
2
+ import { Attestation } from '../Attestation';
3
+ import { MilestoneCompleted } from '../types/attestations';
4
4
  interface _Milestone extends Milestone {
5
5
  }
6
6
  export interface IMilestone {
@@ -13,16 +13,16 @@ class Milestone extends Attestation_1.Attestation {
13
13
  * @param signer
14
14
  * @param reason
15
15
  */
16
- async approve(signer, reason = "") {
16
+ async approve(signer, reason = '') {
17
17
  if (!this.completed)
18
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
19
- const schema = GapSchema_1.GapSchema.find("MilestoneCompleted");
20
- schema.setValue("type", "approved");
21
- schema.setValue("reason", reason);
18
+ throw new SchemaError_1.AttestationError('ATTEST_ERROR', 'Milestone is not completed');
19
+ const schema = GapSchema_1.GapSchema.find('MilestoneCompleted');
20
+ schema.setValue('type', 'approved');
21
+ schema.setValue('reason', reason);
22
22
  await this.attestStatus(signer, schema);
23
23
  this.approved = new attestations_1.MilestoneCompleted({
24
24
  data: {
25
- type: "approved",
25
+ type: 'approved',
26
26
  reason,
27
27
  },
28
28
  refUID: this.uid,
@@ -37,8 +37,13 @@ class Milestone extends Attestation_1.Attestation {
37
37
  */
38
38
  async revokeApproval(signer) {
39
39
  if (!this.approved)
40
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not approved");
41
- await this.approved.revoke(signer);
40
+ throw new SchemaError_1.AttestationError('ATTEST_ERROR', 'Milestone is not approved');
41
+ await this.approved.schema.multiRevoke(signer, [
42
+ {
43
+ schemaId: this.completed.schema.uid,
44
+ uid: this.completed.uid,
45
+ },
46
+ ]);
42
47
  }
43
48
  /**
44
49
  * Reject a completed milestone. If the milestone is not completed or already rejected,
@@ -46,16 +51,16 @@ class Milestone extends Attestation_1.Attestation {
46
51
  * @param signer
47
52
  * @param reason
48
53
  */
49
- async reject(signer, reason = "") {
54
+ async reject(signer, reason = '') {
50
55
  if (!this.completed)
51
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
52
- const schema = GapSchema_1.GapSchema.find("MilestoneCompleted");
53
- schema.setValue("type", "rejected");
54
- schema.setValue("reason", reason);
56
+ throw new SchemaError_1.AttestationError('ATTEST_ERROR', 'Milestone is not completed');
57
+ const schema = GapSchema_1.GapSchema.find('MilestoneCompleted');
58
+ schema.setValue('type', 'rejected');
59
+ schema.setValue('reason', reason);
55
60
  await this.attestStatus(signer, schema);
56
61
  this.rejected = new attestations_1.MilestoneCompleted({
57
62
  data: {
58
- type: "rejected",
63
+ type: 'rejected',
59
64
  reason,
60
65
  },
61
66
  refUID: this.uid,
@@ -70,8 +75,13 @@ class Milestone extends Attestation_1.Attestation {
70
75
  */
71
76
  async revokeRejection(signer) {
72
77
  if (!this.rejected)
73
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not rejected");
74
- await this.rejected.revoke(signer);
78
+ throw new SchemaError_1.AttestationError('ATTEST_ERROR', 'Milestone is not rejected');
79
+ await this.rejected.schema.multiRevoke(signer, [
80
+ {
81
+ schemaId: this.completed.schema.uid,
82
+ uid: this.completed.uid,
83
+ },
84
+ ]);
75
85
  }
76
86
  /**
77
87
  * Marks a milestone as completed. If the milestone is already completed,
@@ -79,14 +89,14 @@ class Milestone extends Attestation_1.Attestation {
79
89
  * @param signer
80
90
  * @param reason
81
91
  */
82
- async complete(signer, reason = "") {
83
- const schema = GapSchema_1.GapSchema.find("MilestoneCompleted");
84
- schema.setValue("type", "completed");
85
- schema.setValue("reason", reason);
92
+ async complete(signer, reason = '') {
93
+ const schema = GapSchema_1.GapSchema.find('MilestoneCompleted');
94
+ schema.setValue('type', 'completed');
95
+ schema.setValue('reason', reason);
86
96
  await this.attestStatus(signer, schema);
87
97
  this.completed = new attestations_1.MilestoneCompleted({
88
98
  data: {
89
- type: "completed",
99
+ type: 'completed',
90
100
  reason,
91
101
  },
92
102
  refUID: this.uid,
@@ -101,8 +111,13 @@ class Milestone extends Attestation_1.Attestation {
101
111
  */
102
112
  async revokeCompletion(signer) {
103
113
  if (!this.completed)
104
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", "Milestone is not completed");
105
- await this.completed.revoke(signer);
114
+ throw new SchemaError_1.AttestationError('ATTEST_ERROR', 'Milestone is not completed');
115
+ await this.completed.schema.multiRevoke(signer, [
116
+ {
117
+ schemaId: this.completed.schema.uid,
118
+ uid: this.completed.uid,
119
+ },
120
+ ]);
106
121
  }
107
122
  /**
108
123
  * Attest the status of the milestone as approved, rejected or completed.
@@ -125,7 +140,7 @@ class Milestone extends Attestation_1.Attestation {
125
140
  }
126
141
  catch (error) {
127
142
  console.error(error);
128
- throw new SchemaError_1.AttestationError("ATTEST_ERROR", error.message);
143
+ throw new SchemaError_1.AttestationError('ATTEST_ERROR', error.message);
129
144
  }
130
145
  }
131
146
  static from(attestations) {
@@ -135,7 +150,7 @@ class Milestone extends Attestation_1.Attestation {
135
150
  data: {
136
151
  ...attestation.data,
137
152
  },
138
- schema: GapSchema_1.GapSchema.find("Milestone"),
153
+ schema: GapSchema_1.GapSchema.find('Milestone'),
139
154
  });
140
155
  if (attestation.completed) {
141
156
  milestone.completed = new attestations_1.MilestoneCompleted({
@@ -143,7 +158,7 @@ class Milestone extends Attestation_1.Attestation {
143
158
  data: {
144
159
  ...attestation.completed.data,
145
160
  },
146
- schema: GapSchema_1.GapSchema.find("MilestoneCompleted"),
161
+ schema: GapSchema_1.GapSchema.find('MilestoneCompleted'),
147
162
  });
148
163
  }
149
164
  if (attestation.approved) {
@@ -152,7 +167,7 @@ class Milestone extends Attestation_1.Attestation {
152
167
  data: {
153
168
  ...attestation.completed.data,
154
169
  },
155
- schema: GapSchema_1.GapSchema.find("MilestoneCompleted"),
170
+ schema: GapSchema_1.GapSchema.find('MilestoneCompleted'),
156
171
  });
157
172
  }
158
173
  if (attestation.rejected) {
@@ -161,7 +176,7 @@ class Milestone extends Attestation_1.Attestation {
161
176
  data: {
162
177
  ...attestation.completed.data,
163
178
  },
164
- schema: GapSchema_1.GapSchema.find("MilestoneCompleted"),
179
+ schema: GapSchema_1.GapSchema.find('MilestoneCompleted'),
165
180
  });
166
181
  }
167
182
  return milestone;
package/package.json CHANGED
@@ -3,7 +3,7 @@
3
3
  "publishConfig": {
4
4
  "access": "public"
5
5
  },
6
- "version": "0.1.31",
6
+ "version": "0.1.33",
7
7
  "description": "Simple and easy interface between EAS and Karma GAP.",
8
8
  "main": "dist/index.js",
9
9
  "author": "KarmaHQ",
package/readme.md CHANGED
@@ -657,7 +657,7 @@ export default handler;
657
657
 
658
658
  > Please note that `NEXT_GELATO_API_KEY` is not an actual API key but the name of the environment variable to retrieve from `process.env`. This setup will not expose the API key in the frontend. Your `.env` file should contain a field like `NEXT_GELATO_API_KEY=abcdefg123`. For more details, refer to [sponsor-handler.ts L63](https://github.com/show-karma/karma-gap-sdk/blob/f2f3f863c8b2b475ca74bd76bb9290a075c12f60/core/utils/gelato/sponsor-handler.ts#L63).
659
659
 
660
- ## After placing the API page, set `gelatoOpts.sponsorUrl: '/api/sponsored-txn'`, and all transactions will be routed through the Gelato Relay network.
660
+ After placing the API page, set `gelatoOpts.sponsorUrl: '/api/sponsored-txn'`, and all transactions will be routed through the Gelato Relay network.
661
661
 
662
662
  ### External API
663
663