@veritier/sdk 0.1.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.
Files changed (40) hide show
  1. package/dist/AgentManager.d.ts +32 -0
  2. package/dist/AgentManager.d.ts.map +1 -0
  3. package/dist/AgentManager.js +87 -0
  4. package/dist/AgentManager.js.map +1 -0
  5. package/dist/HSPSettlementGate.d.ts +43 -0
  6. package/dist/HSPSettlementGate.d.ts.map +1 -0
  7. package/dist/HSPSettlementGate.js +86 -0
  8. package/dist/HSPSettlementGate.js.map +1 -0
  9. package/dist/IdentityManager.d.ts +30 -0
  10. package/dist/IdentityManager.d.ts.map +1 -0
  11. package/dist/IdentityManager.js +66 -0
  12. package/dist/IdentityManager.js.map +1 -0
  13. package/dist/ProofGenerator.d.ts +27 -0
  14. package/dist/ProofGenerator.d.ts.map +1 -0
  15. package/dist/ProofGenerator.js +115 -0
  16. package/dist/ProofGenerator.js.map +1 -0
  17. package/dist/TierChecker.d.ts +13 -0
  18. package/dist/TierChecker.d.ts.map +1 -0
  19. package/dist/TierChecker.js +41 -0
  20. package/dist/TierChecker.js.map +1 -0
  21. package/dist/Veritier.d.ts +78 -0
  22. package/dist/Veritier.d.ts.map +1 -0
  23. package/dist/Veritier.js +124 -0
  24. package/dist/Veritier.js.map +1 -0
  25. package/dist/abis/AgentRegistry.json +863 -0
  26. package/dist/abis/ComplianceAggregator.json +293 -0
  27. package/dist/abis/IdentityRegistry.json +536 -0
  28. package/dist/constants.d.ts +19 -0
  29. package/dist/constants.d.ts.map +1 -0
  30. package/dist/constants.js +33 -0
  31. package/dist/constants.js.map +1 -0
  32. package/dist/index.d.ts +11 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +28 -0
  35. package/dist/index.js.map +1 -0
  36. package/dist/types.d.ts +120 -0
  37. package/dist/types.d.ts.map +1 -0
  38. package/dist/types.js +20 -0
  39. package/dist/types.js.map +1 -0
  40. package/package.json +21 -0
@@ -0,0 +1,32 @@
1
+ import { ethers } from "ethers";
2
+ import type { VeritierConfig, AgentInfo, RegisterAgentParams, SubmitFeedbackParams, UpgradeAgentTierParams } from "./types";
3
+ export declare class AgentManager {
4
+ private provider;
5
+ private contract;
6
+ constructor(config: VeritierConfig, provider: ethers.JsonRpcProvider);
7
+ /**
8
+ * Register a new AI agent. Caller must be Tier 2+.
9
+ * Returns the new agent's token ID and transaction receipt.
10
+ */
11
+ registerAgent(params: RegisterAgentParams): Promise<{
12
+ agentId: bigint;
13
+ tx: ethers.TransactionReceipt;
14
+ }>;
15
+ /** Get the tier of an agent */
16
+ getAgentTier(agentId: bigint): Promise<number>;
17
+ /** Get full agent details */
18
+ getAgent(agentId: bigint): Promise<AgentInfo>;
19
+ /** Submit feedback for an agent (-100 to +100) */
20
+ submitFeedback(params: SubmitFeedbackParams): Promise<ethers.TransactionReceipt>;
21
+ /** Upgrade agent tier (requires reputation threshold + cooldown) */
22
+ upgradeAgentTier(params: UpgradeAgentTierParams): Promise<ethers.TransactionReceipt>;
23
+ /** Get reputation score for an agent */
24
+ getReputationScore(agentId: bigint): Promise<{
25
+ total: bigint;
26
+ count: bigint;
27
+ average: number;
28
+ }>;
29
+ /** Check if an agent meets a required tier */
30
+ isAgentTierValid(agentId: bigint, requiredTier: number): Promise<boolean>;
31
+ }
32
+ //# sourceMappingURL=AgentManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentManager.d.ts","sourceRoot":"","sources":["../src/AgentManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EACV,cAAc,EACd,SAAS,EACT,mBAAmB,EACnB,oBAAoB,EACpB,sBAAsB,EACvB,MAAM,SAAS,CAAC;AAGjB,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,QAAQ,CAAkB;gBAEtB,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,eAAe;IASpE;;;OAGG;IACG,aAAa,CACjB,MAAM,EAAE,mBAAmB,GAC1B,OAAO,CAAC;QAAE,OAAO,EAAE,MAAM,CAAC;QAAC,EAAE,EAAE,MAAM,CAAC,kBAAkB,CAAA;KAAE,CAAC;IAoB9D,+BAA+B;IACzB,YAAY,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAIpD,6BAA6B;IACvB,QAAQ,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,SAAS,CAAC;IAqBnD,kDAAkD;IAC5C,cAAc,CAAC,MAAM,EAAE,oBAAoB,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAMtF,oEAAoE;IAC9D,gBAAgB,CAAC,MAAM,EAAE,sBAAsB,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAM1F,wCAAwC;IAClC,kBAAkB,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,KAAK,EAAE,MAAM,CAAC;QAAC,OAAO,EAAE,MAAM,CAAA;KAAE,CAAC;IAQrG,8CAA8C;IACxC,gBAAgB,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;CAGhF"}
@@ -0,0 +1,87 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.AgentManager = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const AgentRegistry_json_1 = __importDefault(require("./abis/AgentRegistry.json"));
9
+ class AgentManager {
10
+ provider;
11
+ contract;
12
+ constructor(config, provider) {
13
+ this.provider = provider;
14
+ this.contract = new ethers_1.ethers.Contract(config.contracts.agentRegistry, AgentRegistry_json_1.default, provider);
15
+ }
16
+ /**
17
+ * Register a new AI agent. Caller must be Tier 2+.
18
+ * Returns the new agent's token ID and transaction receipt.
19
+ */
20
+ async registerAgent(params) {
21
+ const contract = this.contract.connect(params.signer);
22
+ const tx = await contract.registerAgent(params.agentURI);
23
+ const receipt = await tx.wait();
24
+ // Extract agentId from AgentRegistered event
25
+ const event = receipt.logs
26
+ .map((log) => {
27
+ try {
28
+ return this.contract.interface.parseLog({ topics: [...log.topics], data: log.data });
29
+ }
30
+ catch {
31
+ return null;
32
+ }
33
+ })
34
+ .find((e) => e?.name === "AgentRegistered");
35
+ const agentId = event ? BigInt(event.args[0]) : 0n;
36
+ return { agentId, tx: receipt };
37
+ }
38
+ /** Get the tier of an agent */
39
+ async getAgentTier(agentId) {
40
+ return Number(await this.contract.getAgentTier(agentId));
41
+ }
42
+ /** Get full agent details */
43
+ async getAgent(agentId) {
44
+ const [owner, uri, tier, reputation] = await Promise.all([
45
+ this.contract.getAgentOwner(agentId),
46
+ this.contract.getAgentURI(agentId),
47
+ this.contract.getAgentTier(agentId).then((t) => Number(t)),
48
+ this.contract.getReputationScore(agentId),
49
+ ]);
50
+ const total = reputation[0];
51
+ const count = reputation[1];
52
+ const average = count > 0n ? Number(total) / Number(count) : 0;
53
+ return {
54
+ id: agentId,
55
+ owner,
56
+ uri,
57
+ tier,
58
+ reputation: { total, count, average },
59
+ };
60
+ }
61
+ /** Submit feedback for an agent (-100 to +100) */
62
+ async submitFeedback(params) {
63
+ const contract = this.contract.connect(params.signer);
64
+ const tx = await contract.submitFeedback(params.agentId, params.score, params.tag);
65
+ return await tx.wait();
66
+ }
67
+ /** Upgrade agent tier (requires reputation threshold + cooldown) */
68
+ async upgradeAgentTier(params) {
69
+ const contract = this.contract.connect(params.signer);
70
+ const tx = await contract.upgradeAgentTier(params.agentId, params.newTier, "0x");
71
+ return await tx.wait();
72
+ }
73
+ /** Get reputation score for an agent */
74
+ async getReputationScore(agentId) {
75
+ const result = await this.contract.getReputationScore(agentId);
76
+ const total = BigInt(result[0]);
77
+ const count = BigInt(result[1]);
78
+ const average = count > 0n ? Number(total) / Number(count) : 0;
79
+ return { total, count, average };
80
+ }
81
+ /** Check if an agent meets a required tier */
82
+ async isAgentTierValid(agentId, requiredTier) {
83
+ return await this.contract.isAgentTierValid(agentId, requiredTier);
84
+ }
85
+ }
86
+ exports.AgentManager = AgentManager;
87
+ //# sourceMappingURL=AgentManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"AgentManager.js","sourceRoot":"","sources":["../src/AgentManager.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAgC;AAQhC,mFAAyD;AAEzD,MAAa,YAAY;IACf,QAAQ,CAAyB;IACjC,QAAQ,CAAkB;IAElC,YAAY,MAAsB,EAAE,QAAgC;QAClE,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,eAAM,CAAC,QAAQ,CACjC,MAAM,CAAC,SAAS,CAAC,aAAa,EAC9B,4BAAgB,EAChB,QAAQ,CACT,CAAC;IACJ,CAAC;IAED;;;OAGG;IACH,KAAK,CAAC,aAAa,CACjB,MAA2B;QAE3B,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAC,MAAM,CAAoB,CAAC;QACzE,MAAM,EAAE,GAAG,MAAM,QAAQ,CAAC,aAAa,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC;QACzD,MAAM,OAAO,GAAG,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;QAEhC,6CAA6C;QAC7C,MAAM,KAAK,GAAG,OAAO,CAAC,IAAI;aACvB,GAAG,CAAC,CAAC,GAAe,EAAE,EAAE;YACvB,IAAI,CAAC;gBACH,OAAO,IAAI,CAAC,QAAQ,CAAC,SAAS,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC,GAAG,GAAG,CAAC,MAAM,CAAC,EAAE,IAAI,EAAE,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;YACvF,CAAC;YA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,KAAK,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;QAC/D,OAAO,EAAE,KAAK,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;IACnC,CAAC;IAED,8CAA8C;IAC9C,KAAK,CAAC,gBAAgB,CAAC,OAAe,EAAE,YAAoB;QAC1D,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC,gBAAgB,CAAC,OAAO,EAAE,YAAY,CAAC,CAAC;IACrE,CAAC;CACF;AA7FD,oCA6FC"}
@@ -0,0 +1,43 @@
1
+ import type { Veritier } from "./Veritier";
2
+ export interface SettlementCheckParams {
3
+ from: string;
4
+ to: string;
5
+ amount: number;
6
+ }
7
+ export interface SettlementResult {
8
+ allowed: boolean;
9
+ requiredTier: number;
10
+ senderTier: number;
11
+ receiverTier: number;
12
+ reason?: string;
13
+ }
14
+ /**
15
+ * HSPSettlementGate — HashKey Settlement Protocol compliance middleware
16
+ *
17
+ * Verifies both sender and receiver meet the required Veritier tier
18
+ * for the transaction amount before an HSP settlement is processed.
19
+ *
20
+ * Tier thresholds (mapped to Hong Kong SFC regulatory levels):
21
+ * - ≤ $1,000 → Tier 1 (Basic)
22
+ * - ≤ $50,000 → Tier 2 (Verified)
23
+ * - Unlimited → Tier 3 (Institutional)
24
+ */
25
+ export declare class HSPSettlementGate {
26
+ private veritier;
27
+ private static readonly THRESHOLDS;
28
+ constructor(veritier: Veritier);
29
+ /**
30
+ * Check whether a settlement between two parties is allowed
31
+ * based on their Veritier tier and the transaction amount.
32
+ */
33
+ checkSettlement(params: SettlementCheckParams): Promise<SettlementResult>;
34
+ checkSettlement(from: string, to: string, amount: number): Promise<SettlementResult>;
35
+ /**
36
+ * Check a settlement using demo/mock tiers (no on-chain call).
37
+ * Used when no wallet is connected or in demo mode.
38
+ */
39
+ static checkSettlementDemo(amount: number, senderTier: number, receiverTier: number): SettlementResult;
40
+ /** Determine the minimum tier required for a given USD amount */
41
+ static getRequiredTier(amount: number): number;
42
+ }
43
+ //# sourceMappingURL=HSPSettlementGate.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HSPSettlementGate.d.ts","sourceRoot":"","sources":["../src/HSPSettlementGate.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAE3C,MAAM,WAAW,qBAAqB;IACpC,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,MAAM,EAAE,MAAM,CAAC;CAChB;AAED,MAAM,WAAW,gBAAgB;IAC/B,OAAO,EAAE,OAAO,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,UAAU,EAAE,MAAM,CAAC;IACnB,YAAY,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED;;;;;;;;;;GAUG;AACH,qBAAa,iBAAiB;IAC5B,OAAO,CAAC,QAAQ,CAAW;IAE3B,OAAO,CAAC,MAAM,CAAC,QAAQ,CAAC,UAAU,CAIhC;gBAEU,QAAQ,EAAE,QAAQ;IAI9B;;;OAGG;IACG,eAAe,CAAC,MAAM,EAAE,qBAAqB,GAAG,OAAO,CAAC,gBAAgB,CAAC;IACzE,eAAe,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE,MAAM,GAAG,OAAO,CAAC,gBAAgB,CAAC;IAqC1F;;;OAGG;IACH,MAAM,CAAC,mBAAmB,CACxB,MAAM,EAAE,MAAM,EACd,UAAU,EAAE,MAAM,EAClB,YAAY,EAAE,MAAM,GACnB,gBAAgB;IAsBnB,iEAAiE;IACjE,MAAM,CAAC,eAAe,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM;CAM/C"}
@@ -0,0 +1,86 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.HSPSettlementGate = void 0;
4
+ /**
5
+ * HSPSettlementGate — HashKey Settlement Protocol compliance middleware
6
+ *
7
+ * Verifies both sender and receiver meet the required Veritier tier
8
+ * for the transaction amount before an HSP settlement is processed.
9
+ *
10
+ * Tier thresholds (mapped to Hong Kong SFC regulatory levels):
11
+ * - ≤ $1,000 → Tier 1 (Basic)
12
+ * - ≤ $50,000 → Tier 2 (Verified)
13
+ * - Unlimited → Tier 3 (Institutional)
14
+ */
15
+ class HSPSettlementGate {
16
+ veritier;
17
+ static THRESHOLDS = [
18
+ { maxAmount: 1_000, tier: 1 },
19
+ { maxAmount: 50_000, tier: 2 },
20
+ { maxAmount: Infinity, tier: 3 },
21
+ ];
22
+ constructor(veritier) {
23
+ this.veritier = veritier;
24
+ }
25
+ async checkSettlement(fromOrParams, to, amount) {
26
+ const params = typeof fromOrParams === "string"
27
+ ? { from: fromOrParams, to: to, amount: amount }
28
+ : fromOrParams;
29
+ const requiredTier = HSPSettlementGate.getRequiredTier(params.amount);
30
+ const [senderTier, receiverTier] = await Promise.all([
31
+ this.veritier.getTier(params.from),
32
+ this.veritier.getTier(params.to),
33
+ ]);
34
+ const senderOk = senderTier >= requiredTier;
35
+ const receiverOk = receiverTier >= requiredTier;
36
+ if (senderOk && receiverOk) {
37
+ return { allowed: true, requiredTier, senderTier, receiverTier };
38
+ }
39
+ const reasons = [];
40
+ if (!senderOk)
41
+ reasons.push(`Sender needs Tier ${requiredTier}, has Tier ${senderTier}`);
42
+ if (!receiverOk)
43
+ reasons.push(`Receiver needs Tier ${requiredTier}, has Tier ${receiverTier}`);
44
+ return {
45
+ allowed: false,
46
+ requiredTier,
47
+ senderTier,
48
+ receiverTier,
49
+ reason: reasons.join(". "),
50
+ };
51
+ }
52
+ /**
53
+ * Check a settlement using demo/mock tiers (no on-chain call).
54
+ * Used when no wallet is connected or in demo mode.
55
+ */
56
+ static checkSettlementDemo(amount, senderTier, receiverTier) {
57
+ const requiredTier = HSPSettlementGate.getRequiredTier(amount);
58
+ const senderOk = senderTier >= requiredTier;
59
+ const receiverOk = receiverTier >= requiredTier;
60
+ if (senderOk && receiverOk) {
61
+ return { allowed: true, requiredTier, senderTier, receiverTier };
62
+ }
63
+ const reasons = [];
64
+ if (!senderOk)
65
+ reasons.push(`Sender needs Tier ${requiredTier}, has Tier ${senderTier}`);
66
+ if (!receiverOk)
67
+ reasons.push(`Receiver needs Tier ${requiredTier}, has Tier ${receiverTier}`);
68
+ return {
69
+ allowed: false,
70
+ requiredTier,
71
+ senderTier,
72
+ receiverTier,
73
+ reason: reasons.join(". "),
74
+ };
75
+ }
76
+ /** Determine the minimum tier required for a given USD amount */
77
+ static getRequiredTier(amount) {
78
+ for (const t of HSPSettlementGate.THRESHOLDS) {
79
+ if (amount <= t.maxAmount)
80
+ return t.tier;
81
+ }
82
+ return 3;
83
+ }
84
+ }
85
+ exports.HSPSettlementGate = HSPSettlementGate;
86
+ //# sourceMappingURL=HSPSettlementGate.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"HSPSettlementGate.js","sourceRoot":"","sources":["../src/HSPSettlementGate.ts"],"names":[],"mappings":";;;AAgBA;;;;;;;;;;GAUG;AACH,MAAa,iBAAiB;IACpB,QAAQ,CAAW;IAEnB,MAAM,CAAU,UAAU,GAAG;QACnC,EAAE,SAAS,EAAE,KAAK,EAAE,IAAI,EAAE,CAAC,EAAE;QAC7B,EAAE,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,CAAC,EAAE;QAC9B,EAAE,SAAS,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,EAAE;KACjC,CAAC;IAEF,YAAY,QAAkB;QAC5B,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;IAC3B,CAAC;IAQD,KAAK,CAAC,eAAe,CACnB,YAA4C,EAC5C,EAAW,EACX,MAAe;QAEf,MAAM,MAAM,GACV,OAAO,YAAY,KAAK,QAAQ;YAC9B,CAAC,CAAC,EAAE,IAAI,EAAE,YAAY,EAAE,EAAE,EAAE,EAAG,EAAE,MAAM,EAAE,MAAO,EAAE;YAClD,CAAC,CAAC,YAAY,CAAC;QAEnB,MAAM,YAAY,GAAG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E,IAAI,EAAE,YAAY,EAAE,UAAU,EAAE,YAAY,EAAE,CAAC;QACnE,CAAC;QAED,MAAM,OAAO,GAAa,EAAE,CAAC;QAC7B,IAAI,CAAC,QAAQ;YAAE,OAAO,CAAC,IAAI,CAAC,qBAAqB,YAAY,cAAc,UAAU,EAAE,CAAC,CAAC;QACzF,IAAI,CAAC,UAAU;YAAE,OAAO,CAAC,IAAI,CAAC,uBAAuB,YAAY,cAAc,YAAY,EAAE,CAAC,CAAC;QAE/F,OAAO;YACL,OAAO,EAAE,KAAK;YACd,YAAY;YACZ,UAAU;YACV,YAAY;YACZ,MAAM,EAAE,OAAO,CAAC,IAAI,CAAC,IAAI,CAAC;SAC3B,CAAC;IACJ,CAAC;IAED,iEAAiE;IACjE,MAAM,CAAC,eAAe,CAAC,MAAc;QACnC,KAAK,MAAM,CAAC,IAAI,iBAAiB,CAAC,UAAU,EAAE,CAAC;YAC7C,IAAI,MAAM,IAAI,CAAC,CAAC,SAAS;gBAAE,OAAO,CAAC,CAAC,IAAI,CAAC;QAC3C,CAAC;QACD,OAAO,CAAC,CAAC;IACX,CAAC;;AA3FH,8CA4FC"}
@@ -0,0 +1,30 @@
1
+ import { ethers } from "ethers";
2
+ import type { VeritierConfig, VerifyAndRegisterParams } from "./types";
3
+ export declare class IdentityManager {
4
+ private provider;
5
+ private contract;
6
+ private config;
7
+ constructor(config: VeritierConfig, provider: ethers.JsonRpcProvider);
8
+ /** Get the current tier of an address (returns 0 if expired) */
9
+ getTier(address: string): Promise<number>;
10
+ /** Check if an address is verified (tier > 0 and not expired) */
11
+ isVerified(address: string): Promise<boolean>;
12
+ /** Check if an address meets a required tier */
13
+ isTierValid(address: string, requiredTier: number): Promise<boolean>;
14
+ /** Get the identity Merkle root */
15
+ getIdentityRoot(): Promise<string>;
16
+ /** Check if a nullifier has been used */
17
+ isNullifierUsed(nullifier: string): Promise<boolean>;
18
+ /** Check if an address is a trusted issuer */
19
+ isTrustedIssuer(address: string): Promise<boolean>;
20
+ /**
21
+ * Verify a ZK proof and register at a tier.
22
+ * Converts the snarkjs proof format to Solidity calldata and submits on-chain.
23
+ */
24
+ verifyAndRegister(params: VerifyAndRegisterParams): Promise<ethers.TransactionReceipt>;
25
+ /**
26
+ * Upgrade to a higher tier with a new proof.
27
+ */
28
+ upgradeTier(params: VerifyAndRegisterParams): Promise<ethers.TransactionReceipt>;
29
+ }
30
+ //# sourceMappingURL=IdentityManager.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdentityManager.d.ts","sourceRoot":"","sources":["../src/IdentityManager.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,uBAAuB,EAAE,MAAM,SAAS,CAAC;AAIvE,qBAAa,eAAe;IAC1B,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,QAAQ,CAAkB;IAClC,OAAO,CAAC,MAAM,CAAiB;gBAEnB,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,eAAe;IAUpE,gEAAgE;IAC1D,OAAO,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC;IAI/C,iEAAiE;IAC3D,UAAU,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAInD,gDAAgD;IAC1C,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1E,mCAAmC;IAC7B,eAAe,IAAI,OAAO,CAAC,MAAM,CAAC;IAIxC,yCAAyC;IACnC,eAAe,CAAC,SAAS,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAI1D,8CAA8C;IACxC,eAAe,CAAC,OAAO,EAAE,MAAM,GAAG,OAAO,CAAC,OAAO,CAAC;IAIxD;;;OAGG;IACG,iBAAiB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;IAe5F;;OAEG;IACG,WAAW,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,MAAM,CAAC,kBAAkB,CAAC;CAcvF"}
@@ -0,0 +1,66 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.IdentityManager = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const ProofGenerator_1 = require("./ProofGenerator");
9
+ const IdentityRegistry_json_1 = __importDefault(require("./abis/IdentityRegistry.json"));
10
+ class IdentityManager {
11
+ provider;
12
+ contract;
13
+ config;
14
+ constructor(config, provider) {
15
+ this.config = config;
16
+ this.provider = provider;
17
+ this.contract = new ethers_1.ethers.Contract(config.contracts.identityRegistry, IdentityRegistry_json_1.default, provider);
18
+ }
19
+ /** Get the current tier of an address (returns 0 if expired) */
20
+ async getTier(address) {
21
+ return Number(await this.contract.getTier(address));
22
+ }
23
+ /** Check if an address is verified (tier > 0 and not expired) */
24
+ async isVerified(address) {
25
+ return await this.contract.isVerified(address);
26
+ }
27
+ /** Check if an address meets a required tier */
28
+ async isTierValid(address, requiredTier) {
29
+ return await this.contract.isTierValid(address, requiredTier);
30
+ }
31
+ /** Get the identity Merkle root */
32
+ async getIdentityRoot() {
33
+ return await this.contract.getIdentityRoot();
34
+ }
35
+ /** Check if a nullifier has been used */
36
+ async isNullifierUsed(nullifier) {
37
+ return await this.contract.isNullifierUsed(nullifier);
38
+ }
39
+ /** Check if an address is a trusted issuer */
40
+ async isTrustedIssuer(address) {
41
+ return await this.contract.isTrustedIssuer(address);
42
+ }
43
+ /**
44
+ * Verify a ZK proof and register at a tier.
45
+ * Converts the snarkjs proof format to Solidity calldata and submits on-chain.
46
+ */
47
+ async verifyAndRegister(params) {
48
+ const { proof, publicSignals, targetTier, signer } = params;
49
+ const calldata = ProofGenerator_1.ProofGenerator.proofToSolidityCalldata(proof);
50
+ const contract = this.contract.connect(signer);
51
+ const tx = await contract.verifyAndRegister(calldata.pA, calldata.pB, calldata.pC, publicSignals.map((s) => BigInt(s)), targetTier);
52
+ return await tx.wait();
53
+ }
54
+ /**
55
+ * Upgrade to a higher tier with a new proof.
56
+ */
57
+ async upgradeTier(params) {
58
+ const { proof, publicSignals, targetTier: newTier, signer } = params;
59
+ const calldata = ProofGenerator_1.ProofGenerator.proofToSolidityCalldata(proof);
60
+ const contract = this.contract.connect(signer);
61
+ const tx = await contract.upgradeTier(calldata.pA, calldata.pB, calldata.pC, publicSignals.map((s) => BigInt(s)), newTier);
62
+ return await tx.wait();
63
+ }
64
+ }
65
+ exports.IdentityManager = IdentityManager;
66
+ //# sourceMappingURL=IdentityManager.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"IdentityManager.js","sourceRoot":"","sources":["../src/IdentityManager.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAgC;AAEhC,qDAAkD;AAClD,yFAA+D;AAE/D,MAAa,eAAe;IAClB,QAAQ,CAAyB;IACjC,QAAQ,CAAkB;IAC1B,MAAM,CAAiB;IAE/B,YAAY,MAAsB,EAAE,QAAgC;QAClE,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,QAAQ,GAAG,QAAQ,CAAC;QACzB,IAAI,CAAC,QAAQ,GAAG,IAAI,eAAM,CAAC,QAAQ,CACjC,MAAM,CAAC,SAAS,CAAC,gBAAgB,EACjC,+BAAmB,EACnB,QAAQ,CACT,CAAC;IACJ,CAAC;IAED,gEAAgE;IAChE,KAAK,CAAC,OAAO,CAAC,OAAe;QAC3B,OAAO,MAAM,CAAC,MAAM,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC,CAAC;IACtD,CAAC;IAED,iEAAiE;IACjE,KAAK,CAAC,UAAU,CAAC,OAAe;QAC9B,OAAO,MAAM,IAAI,CAAC,QAAQ,CAAC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AM,EAAE,KAAK,EAAE,aAAa,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,EAAE,GAAG,MAAM,CAAC;QACrE,MAAM,QAAQ,GAAG,+BAAc,CAAC,uBAAuB,CAAC,KAAK,CAAC,CAAC;QAE/D,MAAM,QAAQ,GAAG,IAAI,CAAC,QAAQ,CAAC,OAAO,CAAC,MAAM,CAAoB,CAAC;QAClE,MAAM,EAAE,GAAG,MAAM,QAAQ,CAAC,WAAW,CACnC,QAAQ,CAAC,EAAE,EACX,QAAQ,CAAC,EAAE,EACX,QAAQ,CAAC,EAAE,EACX,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,EACnC,OAAO,CACR,CAAC;QACF,OAAO,MAAM,EAAE,CAAC,IAAI,EAAE,CAAC;IACzB,CAAC;CACF;AAjFD,0CAiFC"}
@@ -0,0 +1,27 @@
1
+ import type { CircuitArtifact, Groth16Proof, SolidityCalldata, ProofResult, AgeProofParams, JurisdictionProofParams, TierProofParams } from "./types";
2
+ export declare class ProofGenerator {
3
+ private artifacts;
4
+ constructor(artifacts: Record<string, CircuitArtifact>);
5
+ /**
6
+ * Generate a Groth16 proof for a given circuit
7
+ */
8
+ generateProof(circuitName: string, inputs: Record<string, string | string[]>): Promise<ProofResult>;
9
+ /**
10
+ * Generate an AgeProof — proves user is at least ageThreshold years old
11
+ */
12
+ generateAgeProof(params: AgeProofParams): Promise<ProofResult>;
13
+ /**
14
+ * Generate a JurisdictionProof — proves user's country is in allowed whitelist
15
+ */
16
+ generateJurisdictionProof(params: JurisdictionProofParams): Promise<ProofResult>;
17
+ /**
18
+ * Generate a TierProof — proves user holds a specific tier or higher
19
+ */
20
+ generateTierProof(params: TierProofParams): Promise<ProofResult>;
21
+ /**
22
+ * Convert snarkjs proof to Solidity calldata format.
23
+ * Note: pi_b coordinates are swapped (x1,x0 → x0,x1) for the BN128 pairing check.
24
+ */
25
+ static proofToSolidityCalldata(proof: Groth16Proof): SolidityCalldata;
26
+ }
27
+ //# sourceMappingURL=ProofGenerator.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProofGenerator.d.ts","sourceRoot":"","sources":["../src/ProofGenerator.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,WAAW,EACX,cAAc,EACd,uBAAuB,EACvB,eAAe,EAChB,MAAM,SAAS,CAAC;AAEjB,qBAAa,cAAc;IACzB,OAAO,CAAC,SAAS,CAAkC;gBAEvC,SAAS,EAAE,MAAM,CAAC,MAAM,EAAE,eAAe,CAAC;IAItD;;OAEG;IACG,aAAa,CACjB,WAAW,EAAE,MAAM,EACnB,MAAM,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,GACxC,OAAO,CAAC,WAAW,CAAC;IAavB;;OAEG;IACG,gBAAgB,CAAC,MAAM,EAAE,cAAc,GAAG,OAAO,CAAC,WAAW,CAAC;IAapE;;OAEG;IACG,yBAAyB,CAAC,MAAM,EAAE,uBAAuB,GAAG,OAAO,CAAC,WAAW,CAAC;IAetF;;OAEG;IACG,iBAAiB,CAAC,MAAM,EAAE,eAAe,GAAG,OAAO,CAAC,WAAW,CAAC;IAYtE;;;OAGG;IACH,MAAM,CAAC,uBAAuB,CAAC,KAAK,EAAE,YAAY,GAAG,gBAAgB;CAUtE"}
@@ -0,0 +1,115 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || (function () {
19
+ var ownKeys = function(o) {
20
+ ownKeys = Object.getOwnPropertyNames || function (o) {
21
+ var ar = [];
22
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
+ return ar;
24
+ };
25
+ return ownKeys(o);
26
+ };
27
+ return function (mod) {
28
+ if (mod && mod.__esModule) return mod;
29
+ var result = {};
30
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
+ __setModuleDefault(result, mod);
32
+ return result;
33
+ };
34
+ })();
35
+ Object.defineProperty(exports, "__esModule", { value: true });
36
+ exports.ProofGenerator = void 0;
37
+ const snarkjs = __importStar(require("snarkjs"));
38
+ class ProofGenerator {
39
+ artifacts;
40
+ constructor(artifacts) {
41
+ this.artifacts = artifacts;
42
+ }
43
+ /**
44
+ * Generate a Groth16 proof for a given circuit
45
+ */
46
+ async generateProof(circuitName, inputs) {
47
+ const artifact = this.artifacts[circuitName];
48
+ if (!artifact)
49
+ throw new Error(`Unknown circuit: ${circuitName}`);
50
+ const { proof, publicSignals } = await snarkjs.groth16.fullProve(inputs, artifact.wasm, artifact.zkey);
51
+ return { proof: proof, publicSignals };
52
+ }
53
+ /**
54
+ * Generate an AgeProof — proves user is at least ageThreshold years old
55
+ */
56
+ async generateAgeProof(params) {
57
+ return this.generateProof("ageProof", {
58
+ birthDate: params.birthDate.toString(),
59
+ issuerPubKey: [params.issuerPubKey[0].toString(), params.issuerPubKey[1].toString()],
60
+ signatureR8: [params.signatureR8[0].toString(), params.signatureR8[1].toString()],
61
+ signatureS: params.signatureS.toString(),
62
+ ageThreshold: params.ageThreshold.toString(),
63
+ currentDate: params.currentDate.toString(),
64
+ issuerPubKeyHash: params.issuerPubKeyHash.toString(),
65
+ nullifier: params.nullifier.toString(),
66
+ });
67
+ }
68
+ /**
69
+ * Generate a JurisdictionProof — proves user's country is in allowed whitelist
70
+ */
71
+ async generateJurisdictionProof(params) {
72
+ return this.generateProof("jurisdictionProof", {
73
+ countryCode: params.countryCode.toString(),
74
+ issuerPubKey: [params.issuerPubKey[0].toString(), params.issuerPubKey[1].toString()],
75
+ signatureR8: [params.signatureR8[0].toString(), params.signatureR8[1].toString()],
76
+ signatureS: params.signatureS.toString(),
77
+ pathElements: params.pathElements.map((e) => e.toString()),
78
+ pathIndices: params.pathIndices.map((i) => i.toString()),
79
+ allowedCountriesRoot: params.allowedCountriesRoot.toString(),
80
+ issuerPubKeyHash: params.issuerPubKeyHash.toString(),
81
+ nullifier: params.nullifier.toString(),
82
+ jurisdictionBucket: params.jurisdictionBucket.toString(),
83
+ });
84
+ }
85
+ /**
86
+ * Generate a TierProof — proves user holds a specific tier or higher
87
+ */
88
+ async generateTierProof(params) {
89
+ return this.generateProof("tierProof", {
90
+ userTier: params.userTier.toString(),
91
+ secret: params.secret.toString(),
92
+ pathElements: params.pathElements.map((e) => e.toString()),
93
+ pathIndices: params.pathIndices.map((i) => i.toString()),
94
+ requiredTier: params.requiredTier.toString(),
95
+ identityRoot: params.identityRoot.toString(),
96
+ userAddress: params.userAddress.toString(),
97
+ });
98
+ }
99
+ /**
100
+ * Convert snarkjs proof to Solidity calldata format.
101
+ * Note: pi_b coordinates are swapped (x1,x0 → x0,x1) for the BN128 pairing check.
102
+ */
103
+ static proofToSolidityCalldata(proof) {
104
+ return {
105
+ pA: [BigInt(proof.pi_a[0]), BigInt(proof.pi_a[1])],
106
+ pB: [
107
+ [BigInt(proof.pi_b[0][1]), BigInt(proof.pi_b[0][0])],
108
+ [BigInt(proof.pi_b[1][1]), BigInt(proof.pi_b[1][0])],
109
+ ],
110
+ pC: [BigInt(proof.pi_c[0]), BigInt(proof.pi_c[1])],
111
+ };
112
+ }
113
+ }
114
+ exports.ProofGenerator = ProofGenerator;
115
+ //# sourceMappingURL=ProofGenerator.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"ProofGenerator.js","sourceRoot":"","sources":["../src/ProofGenerator.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA,iDAAmC;AAWnC,MAAa,cAAc;IACjB,SAAS,CAAkC;IAEnD,YAAY,SAA0C;QACpD,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC;IAC7B,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,aAAa,CACjB,WAAmB,EACnB,MAAyC;QAEzC,MAAM,QAAQ,GAAG,IAAI,CAAC,SAAS,CAAC,WAAW,CAAC,CAAC;QAC7C,IAAI,CAAC,QAAQ;YAAE,MAAM,IAAI,KAAK,CAAC,oBAAoB,WAAW,EAAE,CAAC,CAAC;QAElE,MAAM,EAAE,KAAK,EAAE,aAAa,EAAE,GAAG,MAAM,OAAO,CAAC,OAAO,CAAC,SAAS,CAC9D,MAAM,EACN,QAAQ,CAAC,IAAI,EACb,QAAQ,CAAC,IAAI,CACd,CAAC;QAEF,OAAO,EAAE,KAAK,EAAE,KAAqB,EAAE,aAAa,EAAE,CAAC;IACzD,CAAC;IAED;;OAEG;IACH,KAAK,CAAC,gBAAgB,CAAC,MAAsB;QAC3C,OAAO,IAAI,CAAC,aAAa,CAAC,UAAU,EAAE;YACpC,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE;YACtC,YAAY,EAAE,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;YACpF,WAAW,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,QAAQ,EAAE,CAAC;YACjF,UAAU,E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,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;aACrD;YACD,EAAE,EAAE,CAAC,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC;SACnD,CAAC;IACJ,CAAC;CACF;AAzFD,wCAyFC"}
@@ -0,0 +1,13 @@
1
+ import { ethers } from "ethers";
2
+ import type { VeritierConfig, TierDistribution } from "./types";
3
+ export declare class TierChecker {
4
+ private provider;
5
+ private aggregator;
6
+ private identityAddress;
7
+ constructor(config: VeritierConfig, provider: ethers.JsonRpcProvider);
8
+ /** Get aggregate tier distribution from ComplianceAggregator */
9
+ getTierDistribution(): Promise<TierDistribution>;
10
+ /** Get jurisdiction distribution (bucket → count) */
11
+ getJurisdictionDistribution(): Promise<Record<number, bigint>>;
12
+ }
13
+ //# sourceMappingURL=TierChecker.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TierChecker.d.ts","sourceRoot":"","sources":["../src/TierChecker.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,KAAK,EAAE,cAAc,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAC;AAGhE,qBAAa,WAAW;IACtB,OAAO,CAAC,QAAQ,CAAyB;IACzC,OAAO,CAAC,UAAU,CAAkB;IACpC,OAAO,CAAC,eAAe,CAAS;gBAEpB,MAAM,EAAE,cAAc,EAAE,QAAQ,EAAE,MAAM,CAAC,eAAe;IAUpE,gEAAgE;IAC1D,mBAAmB,IAAI,OAAO,CAAC,gBAAgB,CAAC;IAatD,qDAAqD;IAC/C,2BAA2B,IAAI,OAAO,CAAC,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;CAYrE"}
@@ -0,0 +1,41 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.TierChecker = void 0;
7
+ const ethers_1 = require("ethers");
8
+ const ComplianceAggregator_json_1 = __importDefault(require("./abis/ComplianceAggregator.json"));
9
+ class TierChecker {
10
+ provider;
11
+ aggregator;
12
+ identityAddress;
13
+ constructor(config, provider) {
14
+ this.provider = provider;
15
+ this.identityAddress = config.contracts.identityRegistry;
16
+ this.aggregator = new ethers_1.ethers.Contract(config.contracts.complianceAggregator, ComplianceAggregator_json_1.default, provider);
17
+ }
18
+ /** Get aggregate tier distribution from ComplianceAggregator */
19
+ async getTierDistribution() {
20
+ const [tier0, tier1, tier2, tier3, totalHumans, totalAgents] = await Promise.all([
21
+ this.aggregator.tierCounts(0).then((v) => BigInt(v)),
22
+ this.aggregator.tierCounts(1).then((v) => BigInt(v)),
23
+ this.aggregator.tierCounts(2).then((v) => BigInt(v)),
24
+ this.aggregator.tierCounts(3).then((v) => BigInt(v)),
25
+ this.aggregator.totalHumans().then((v) => BigInt(v)),
26
+ this.aggregator.totalAgents().then((v) => BigInt(v)),
27
+ ]);
28
+ return { tier0, tier1, tier2, tier3, totalHumans, totalAgents };
29
+ }
30
+ /** Get jurisdiction distribution (bucket → count) */
31
+ async getJurisdictionDistribution() {
32
+ const buckets = {};
33
+ const results = await Promise.all([0, 1, 2, 3, 4, 5].map((b) => this.aggregator.jurisdictionCounts(b).then((v) => BigInt(v))));
34
+ for (let i = 0; i < 6; i++) {
35
+ buckets[i] = results[i];
36
+ }
37
+ return buckets;
38
+ }
39
+ }
40
+ exports.TierChecker = TierChecker;
41
+ //# sourceMappingURL=TierChecker.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"TierChecker.js","sourceRoot":"","sources":["../src/TierChecker.ts"],"names":[],"mappings":";;;;;;AAAA,mCAAgC;AAEhC,iGAAuE;AAEvE,MAAa,WAAW;IACd,QAAQ,CAAyB;IACjC,UAAU,CAAkB;IAC5B,eAAe,C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