@medialane/sdk 0.129.2 → 0.131.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.
@@ -566,6 +566,7 @@ var ApiClient = class {
566
566
  headers: this.asSubject(siwsToken)
567
567
  });
568
568
  }
569
+ /** @deprecated Use the funding methods (`createFunding`, or `fundWithChainTransfer` from `@medialane/sdk/starknet`). This call only nudges a legacy scanner and never credits anything itself. */
569
570
  checkDeposit(txHash, siwsToken) {
570
571
  return this.request("/v1/portal/credits/check", {
571
572
  method: "POST",
@@ -573,6 +574,52 @@ var ApiClient = class {
573
574
  headers: this.asSubject(siwsToken)
574
575
  });
575
576
  }
577
+ getFundingMethods(siwsToken) {
578
+ return this.request("/v1/portal/funding/methods", {
579
+ method: "GET",
580
+ headers: this.asSubject(siwsToken)
581
+ });
582
+ }
583
+ createFunding(input, siwsToken) {
584
+ return this.request("/v1/portal/funding", {
585
+ method: "POST",
586
+ body: JSON.stringify({ method: input.method, params: input.params }),
587
+ headers: this.asSubject(siwsToken)
588
+ });
589
+ }
590
+ getFunding(id, siwsToken) {
591
+ return this.request(`/v1/portal/funding/${encodeURIComponent(id)}`, {
592
+ method: "GET",
593
+ headers: this.asSubject(siwsToken)
594
+ });
595
+ }
596
+ getFundingChallenge(id, payer, siwsToken) {
597
+ return this.request(`/v1/portal/funding/${encodeURIComponent(id)}/challenge`, {
598
+ method: "POST",
599
+ body: JSON.stringify({ payer }),
600
+ headers: this.asSubject(siwsToken)
601
+ });
602
+ }
603
+ authorizeFunding(id, input, siwsToken) {
604
+ return this.request(
605
+ `/v1/portal/funding/${encodeURIComponent(id)}/authorize`,
606
+ { method: "POST", body: JSON.stringify({ payer: input.payer, signature: input.signature }), headers: this.asSubject(siwsToken) }
607
+ );
608
+ }
609
+ submitFunding(id, txHash, siwsToken) {
610
+ return this.request(`/v1/portal/funding/${encodeURIComponent(id)}/submit`, {
611
+ method: "POST",
612
+ body: JSON.stringify({ txHash }),
613
+ headers: this.asSubject(siwsToken)
614
+ });
615
+ }
616
+ cancelFunding(id, siwsToken) {
617
+ return this.request(`/v1/portal/funding/${encodeURIComponent(id)}/cancel`, {
618
+ method: "POST",
619
+ body: JSON.stringify({}),
620
+ headers: this.asSubject(siwsToken)
621
+ });
622
+ }
576
623
  getWebhooks() {
577
624
  return this.get("/v1/portal/webhooks");
578
625
  }
@@ -600,12 +647,9 @@ var ApiClient = class {
600
647
  registerBusinessProvisioning(params) {
601
648
  return this.post(
602
649
  "/v1/business/provisioning",
603
- params
650
+ { chain: params.chain ?? "STARKNET", recipientScheme: params.recipientScheme, recipientValue: params.recipientValue }
604
651
  );
605
652
  }
606
- completeBusinessProvisioning(id) {
607
- return this.post(`/v1/business/provisioning/${id}/complete`, {});
608
- }
609
653
  getCollectionProfile(contractAddress) {
610
654
  return this.request(
611
655
  `/v1/collections/${this.addr(contractAddress)}/profile`,
@@ -702,11 +746,28 @@ var ApiClient = class {
702
746
  headers: this.bearer(siwsToken)
703
747
  });
704
748
  }
705
- async checkEmailExists(email) {
706
- const { exists } = await this.get(
749
+ async checkEmail(email) {
750
+ const body = await this.get(
707
751
  `/v1/auth/email/exists?email=${encodeURIComponent(email)}`
708
752
  );
709
- return exists;
753
+ return { exists: body.exists, walletWaiting: body.walletWaiting === true };
754
+ }
755
+ async requestEmailCode(email) {
756
+ await this.post("/v1/auth/email/request-code", { email });
757
+ }
758
+ async registerEmailAccount(email) {
759
+ await this.post("/v1/auth/email/register-account", { email });
760
+ }
761
+ async verifyEmailCode(email, code) {
762
+ const body = await this.post("/v1/auth/email/verify-code", { email, code });
763
+ return { token: body.token, waitingWallets: body.waitingWallets ?? [] };
764
+ }
765
+ claimWallet(params) {
766
+ return this.post("/v1/users/me/claim-wallet", params);
767
+ }
768
+ async getSessionWallet() {
769
+ const body = await this.post("/v1/users/me/wallet", {});
770
+ return body.walletAddress ?? null;
710
771
  }
711
772
  getMyWallet(siwsToken) {
712
773
  return this.request(
@@ -11618,6 +11679,69 @@ async function requestSiwsToken({
11618
11679
  return token;
11619
11680
  }
11620
11681
 
11682
+ // src/starknet/funding/chain-transfer.ts
11683
+ var FundingTransferNotSentError = class extends Error {
11684
+ constructor(message = "The transfer was not sent.") {
11685
+ super(message);
11686
+ this.name = "FundingTransferNotSentError";
11687
+ }
11688
+ };
11689
+ function fundingApiFor(client, siwsToken) {
11690
+ return {
11691
+ createFunding: (input) => client.createFunding(input, siwsToken),
11692
+ getFundingChallenge: (id, payer) => client.getFundingChallenge(id, payer, siwsToken),
11693
+ authorizeFunding: (id, input) => client.authorizeFunding(id, input, siwsToken),
11694
+ submitFunding: (id, txHash) => client.submitFunding(id, txHash, siwsToken),
11695
+ cancelFunding: (id) => client.cancelFunding(id, siwsToken)
11696
+ };
11697
+ }
11698
+ function buildFundingTransferCall(instructions) {
11699
+ const amount = BigInt(instructions.amountAtomic);
11700
+ const mask = (1n << 128n) - 1n;
11701
+ return {
11702
+ contractAddress: instructions.asset,
11703
+ entrypoint: "transfer",
11704
+ calldata: [instructions.payTo, (amount & mask).toString(), (amount >> 128n).toString()]
11705
+ };
11706
+ }
11707
+ async function fundWithChainTransfer(api, wallet, options) {
11708
+ const step = options.onStep ?? (() => {
11709
+ });
11710
+ const sleep2 = options.sleep ?? ((ms) => new Promise((resolve) => setTimeout(resolve, ms)));
11711
+ const pollMs = options.pollMs ?? 3e3;
11712
+ const maxPolls = options.maxPolls ?? 20;
11713
+ step("creating");
11714
+ const { data: intent } = await api.createFunding({ method: "chain-transfer", params: { amountUsdc: options.amountUsdc } });
11715
+ let txHash;
11716
+ let transferStarted = false;
11717
+ try {
11718
+ step("signing");
11719
+ const challenge = await api.getFundingChallenge(intent.id, wallet.address);
11720
+ const signature = await wallet.signTypedData(challenge.data.typedData);
11721
+ step("authorizing");
11722
+ const authorized = await api.authorizeFunding(intent.id, { payer: wallet.address, signature });
11723
+ step("paying");
11724
+ transferStarted = true;
11725
+ ({ txHash } = await wallet.sendTransfer(buildFundingTransferCall(authorized.data.instructions)));
11726
+ } catch (err) {
11727
+ if (!transferStarted || err instanceof FundingTransferNotSentError) {
11728
+ await api.cancelFunding(intent.id).catch(() => void 0);
11729
+ }
11730
+ throw err;
11731
+ }
11732
+ step("confirming");
11733
+ let reason = "waiting for the transfer to confirm";
11734
+ for (let attempt = 0; attempt < maxPolls; attempt++) {
11735
+ const res = await api.submitFunding(intent.id, txHash);
11736
+ if (res.data.status === "SETTLED") {
11737
+ return { status: "SETTLED", intentId: intent.id, credited: res.data.credited };
11738
+ }
11739
+ reason = res.data.reason;
11740
+ await sleep2(pollMs);
11741
+ }
11742
+ return { status: "PENDING", intentId: intent.id, reason };
11743
+ }
11744
+
11621
11745
  // src/errors.ts
11622
11746
  var UserFacingError = class extends Error {
11623
11747
  constructor(message) {
@@ -12906,6 +13030,7 @@ exports.DropCollectionABI = DropCollectionABI;
12906
13030
  exports.DropFactoryABI = DropFactoryABI;
12907
13031
  exports.DropService = DropService;
12908
13032
  exports.ERC1155CollectionService = ERC1155CollectionService;
13033
+ exports.FundingTransferNotSentError = FundingTransferNotSentError;
12909
13034
  exports.IPClubCollectionABI = IPClubCollectionABI;
12910
13035
  exports.IPClubFactoryABI = IPClubFactoryABI;
12911
13036
  exports.IPCollection1155ABI = IPCollection1155ABI;
@@ -12949,6 +13074,7 @@ exports.buildCompleteEscapeOwnerCall = buildCompleteEscapeOwnerCall;
12949
13074
  exports.buildCreateCreatorCoinCall = buildCreateCreatorCoinCall;
12950
13075
  exports.buildDeployAccountParams = buildDeployAccountParams;
12951
13076
  exports.buildFeeCall = buildFeeCall;
13077
+ exports.buildFundingTransferCall = buildFundingTransferCall;
12952
13078
  exports.buildLaunchOnEkuboCalls = buildLaunchOnEkuboCalls;
12953
13079
  exports.buildOrderTypedData = buildOrderTypedData;
12954
13080
  exports.buildRemoveOwnerByGuidCall = buildRemoveOwnerByGuidCall;
@@ -12985,6 +13111,8 @@ exports.executeIntent = executeIntent;
12985
13111
  exports.executeIntents = executeIntents;
12986
13112
  exports.executeSponsored = executeSponsored;
12987
13113
  exports.fdvHuman = fdvHuman;
13114
+ exports.fundWithChainTransfer = fundWithChainTransfer;
13115
+ exports.fundingApiFor = fundingApiFor;
12988
13116
  exports.generateStarkKeyPair = generateStarkKeyPair;
12989
13117
  exports.getCounter = getCounter;
12990
13118
  exports.getCounter1155 = getCounter1155;