@learncard/network-plugin 2.4.18 → 2.4.19

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.
@@ -9784,6 +9784,28 @@ var LCNNotificationValidator = mod.object({
9784
9784
  data: LCNNotificationDataValidator.optional(),
9785
9785
  sent: mod.string().datetime().optional()
9786
9786
  });
9787
+ var AUTH_GRANT_AUDIENCE_DOMAIN_PREFIX = "auth-grant:";
9788
+ var AuthGrantValidator = mod.object({
9789
+ id: mod.string(),
9790
+ name: mod.string(),
9791
+ description: mod.string().optional(),
9792
+ challenge: mod.string().startsWith(AUTH_GRANT_AUDIENCE_DOMAIN_PREFIX).min(10, { message: "Challenge is too short" }).max(100, { message: "Challenge is too long" }),
9793
+ status: mod.enum(["revoked", "active"], {
9794
+ required_error: "Status is required",
9795
+ invalid_type_error: "Status must be either active or revoked"
9796
+ }),
9797
+ scope: mod.string(),
9798
+ createdAt: mod.string().datetime({ message: "createdAt must be a valid ISO 8601 datetime string" }),
9799
+ expiresAt: mod.string().datetime({ message: "expiresAt must be a valid ISO 8601 datetime string" }).nullish().optional()
9800
+ });
9801
+ var FlatAuthGrantValidator = mod.object({ id: mod.string() }).catchall(mod.any());
9802
+ var AuthGrantStatusValidator = mod.enum(["active", "revoked"]);
9803
+ var AuthGrantQueryValidator = mod.object({
9804
+ id: StringQuery,
9805
+ name: StringQuery,
9806
+ description: StringQuery,
9807
+ status: AuthGrantStatusValidator
9808
+ }).partial();
9787
9809
 
9788
9810
  // src/plugin.ts
9789
9811
  var getLearnCardNetworkPlugin = /* @__PURE__ */ __name(async (learnCard, url) => {
@@ -10523,6 +10545,58 @@ var getLearnCardNetworkPlugin = /* @__PURE__ */ __name(async (learnCard, url) =>
10523
10545
  throw new Error("Please make an account first!");
10524
10546
  return client.claimHook.deleteClaimHook.mutate({ id });
10525
10547
  },
10548
+ addAuthGrant: async (_learnCard, authGrant) => {
10549
+ if (!userData)
10550
+ throw new Error("Please make an account first!");
10551
+ return client.authGrants.addAuthGrant.mutate(authGrant);
10552
+ },
10553
+ revokeAuthGrant: async (_learnCard, id) => {
10554
+ if (!userData)
10555
+ throw new Error("Please make an account first!");
10556
+ return client.authGrants.revokeAuthGrant.mutate({ id });
10557
+ },
10558
+ deleteAuthGrant: async (_learnCard, id) => {
10559
+ if (!userData)
10560
+ throw new Error("Please make an account first!");
10561
+ return client.authGrants.deleteAuthGrant.mutate({ id });
10562
+ },
10563
+ updateAuthGrant: async (_learnCard, id, updates) => {
10564
+ if (!userData)
10565
+ throw new Error("Please make an account first!");
10566
+ return client.authGrants.updateAuthGrant.mutate({ id, updates });
10567
+ },
10568
+ getAuthGrant: async (_learnCard, id) => {
10569
+ if (!userData)
10570
+ throw new Error("Please make an account first!");
10571
+ return client.authGrants.getAuthGrant.query({ id });
10572
+ },
10573
+ getAuthGrants: async (_learnCard, options) => {
10574
+ if (!userData)
10575
+ throw new Error("Please make an account first!");
10576
+ return client.authGrants.getAuthGrants.query(options);
10577
+ },
10578
+ getAPITokenForAuthGrant: async (_learnCard, id) => {
10579
+ if (!userData)
10580
+ throw new Error("Please make an account first!");
10581
+ const authGrant = await client.authGrants.getAuthGrant.query({ id });
10582
+ if (!authGrant)
10583
+ throw new Error("Auth grant not found");
10584
+ if (authGrant.status !== "active")
10585
+ throw new Error("Auth grant is not active");
10586
+ if (!authGrant.challenge)
10587
+ throw new Error("Auth grant has no challenge");
10588
+ if (!authGrant.scope)
10589
+ throw new Error("Auth grant has no scope");
10590
+ if (authGrant.expiresAt && new Date(authGrant.expiresAt) < new Date())
10591
+ throw new Error("Auth grant is expired");
10592
+ const apiToken = await _learnCard.invoke.getDidAuthVp({
10593
+ challenge: authGrant.challenge,
10594
+ proofFormat: "jwt"
10595
+ });
10596
+ if (!apiToken)
10597
+ throw new Error("Failed to get API Token for auth grant");
10598
+ return apiToken;
10599
+ },
10526
10600
  resolveFromLCN: async (_learnCard, uri) => {
10527
10601
  const result = await client.storage.resolve.query({ uri });
10528
10602
  return UnsignedVCValidator.or(VCValidator).or(VPValidator).or(JWEValidator).or(ConsentFlowContractValidator).or(ConsentFlowTermsValidator).parseAsync(result);