@medialane/sdk 0.121.0 → 0.122.1

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.
@@ -12652,6 +12652,126 @@ function sponsoredExecutor(deps) {
12652
12652
  }
12653
12653
  };
12654
12654
  }
12655
+ async function describeFailure(res, fallback) {
12656
+ const body = await res.json().catch(() => null);
12657
+ throw new Error(body?.error || fallback);
12658
+ }
12659
+ async function deploySponsored(input) {
12660
+ const doFetch = input.fetchImpl ?? fetch;
12661
+ const base = input.proxyUrl.replace(/\/$/, "");
12662
+ const buildRes = await doFetch(`${base}/build`, {
12663
+ method: "POST",
12664
+ headers: { "Content-Type": "application/json" },
12665
+ body: JSON.stringify({
12666
+ ownerPubkey: input.ownerPubKey,
12667
+ ownerAddress: input.ownerAddress,
12668
+ salt: input.salt ?? "0x0"
12669
+ })
12670
+ });
12671
+ if (!buildRes.ok) {
12672
+ await describeFailure(buildRes, "We couldn't prepare your wallet deployment. Please try again.");
12673
+ }
12674
+ const { typedData, deployment, calls } = await buildRes.json();
12675
+ const account = new starknet.Account({
12676
+ provider: input.provider,
12677
+ address: input.ownerAddress,
12678
+ signer: input.privateKeyHex,
12679
+ cairoVersion: "1"
12680
+ });
12681
+ const signature = starknet.stark.signatureToHexArray(await account.signMessage(typedData));
12682
+ const executeRes = await doFetch(`${base}/execute`, {
12683
+ method: "POST",
12684
+ headers: { "Content-Type": "application/json" },
12685
+ body: JSON.stringify({ ownerAddress: input.ownerAddress, typedData, signature, deployment, calls })
12686
+ });
12687
+ if (!executeRes.ok) {
12688
+ await describeFailure(executeRes, "We couldn't complete your wallet deployment. Please try again.");
12689
+ }
12690
+ const { transactionHash } = await executeRes.json();
12691
+ return { transactionHash };
12692
+ }
12693
+ async function deploySelfFunded(input) {
12694
+ const classHash = getCoordinates("STARKNET").mediaWalletClassHash;
12695
+ if (!classHash) throw new Error("Media Wallet class hash is not configured");
12696
+ const account = new starknet.Account({
12697
+ provider: input.provider,
12698
+ address: input.ownerAddress,
12699
+ signer: input.privateKeyHex,
12700
+ cairoVersion: "1"
12701
+ });
12702
+ const { transaction_hash } = await account.deployAccount({
12703
+ classHash,
12704
+ constructorCalldata: ownerConstructorCalldata(input.ownerPubKey),
12705
+ addressSalt: 0,
12706
+ contractAddress: input.ownerAddress
12707
+ });
12708
+ return { transactionHash: transaction_hash };
12709
+ }
12710
+ async function waitUntilDeployed(provider, address, timeoutMs = 9e4, sleep2 = (ms) => new Promise((resolve) => setTimeout(resolve, ms))) {
12711
+ const deadline = Date.now() + timeoutMs;
12712
+ let wait = 1e3;
12713
+ for (; ; ) {
12714
+ if (await isDeployed(provider, address)) return;
12715
+ if (Date.now() >= deadline) {
12716
+ throw new Error(
12717
+ "Your wallet was submitted but has not appeared on Starknet yet. Please try again in a moment."
12718
+ );
12719
+ }
12720
+ await sleep2(wait);
12721
+ wait = Math.min(Math.round(wait * 1.5), 5e3);
12722
+ }
12723
+ }
12724
+ async function completeDeployment(deps, onStep, options = {}) {
12725
+ let sealed = options.forceNew ? null : deps.store.load();
12726
+ let privateKeyHex;
12727
+ if (!sealed) {
12728
+ onStep("creating-passkey");
12729
+ const created = await deps.passkey.createOwnerKey();
12730
+ sealed = created.sealed;
12731
+ privateKeyHex = created.privateKeyHex;
12732
+ deps.store.save(sealed);
12733
+ } else {
12734
+ privateKeyHex = await deps.passkey.unlockOwnerKey(sealed);
12735
+ }
12736
+ onStep("deploying");
12737
+ const wallet = { ownerAddress: sealed.address, ownerPubKey: sealed.ownerPubKey, privateKeyHex };
12738
+ const sponsored = deps.deploySponsoredImpl ?? deploySponsored;
12739
+ const selfFunded = deps.deploySelfFundedImpl ?? deploySelfFunded;
12740
+ if (deps.deployProxyUrl) {
12741
+ try {
12742
+ await sponsored({
12743
+ proxyUrl: deps.deployProxyUrl,
12744
+ provider: deps.provider(),
12745
+ fetchImpl: deps.fetchImpl,
12746
+ ...wallet
12747
+ });
12748
+ } catch (sponsoredErr) {
12749
+ try {
12750
+ await selfFunded({ provider: deps.provider(), ...wallet });
12751
+ } catch (selfFundedErr) {
12752
+ const sponsored2 = sponsoredErr instanceof Error ? sponsoredErr.message : String(sponsoredErr);
12753
+ const selfFunded2 = selfFundedErr instanceof Error ? selfFundedErr.message : String(selfFundedErr);
12754
+ throw new Error(`Sponsored deploy failed: ${sponsored2}. Self-funded fallback failed: ${selfFunded2}`);
12755
+ }
12756
+ }
12757
+ } else {
12758
+ await selfFunded({ provider: deps.provider(), ...wallet });
12759
+ }
12760
+ await (deps.waitUntilDeployedImpl ?? waitUntilDeployed)(deps.provider(), sealed.address);
12761
+ onStep("signing-in");
12762
+ const address = sealed.address;
12763
+ const siwsToken = await (deps.requestSiwsTokenImpl ?? requestSiwsToken)({
12764
+ backendUrl: deps.backendUrl,
12765
+ walletAddress: address,
12766
+ signer: {
12767
+ signMessage: async (td) => signWithPrivateKey(privateKeyHex, starknet.typedData.getMessageHash(td, address))
12768
+ }
12769
+ });
12770
+ deps.store.notifyChange();
12771
+ return { sealed, siwsToken };
12772
+ }
12773
+
12774
+ // src/wallet/client.ts
12655
12775
  function describeDevices(owners, thisDevicePubkey) {
12656
12776
  const mine = computeOwnerGuid(thisDevicePubkey);
12657
12777
  return owners.map((owner) => ({
@@ -12750,6 +12870,18 @@ function createMediaWallet(config) {
12750
12870
  async removeDevice(sealed, ownerGuid) {
12751
12871
  const { transactionHash } = await run(sealed, [buildRemoveOwnerByGuidCall(sealed.address, ownerGuid)]);
12752
12872
  return transactionHash;
12873
+ },
12874
+ completeDeployment(onStep, options = {}) {
12875
+ if (!config.backendUrl) throw new Error("This wallet has no backend url configured for sign-in");
12876
+ const deps = {
12877
+ store: config.store,
12878
+ passkey: config.passkey,
12879
+ provider: config.provider,
12880
+ backendUrl: config.backendUrl,
12881
+ deployProxyUrl: config.deployProxyUrl,
12882
+ fetchImpl: config.fetchImpl
12883
+ };
12884
+ return completeDeployment(deps, onStep, options);
12753
12885
  }
12754
12886
  };
12755
12887
  }
@@ -12816,6 +12948,7 @@ exports.buildTriggerEscapeOwnerCall = buildTriggerEscapeOwnerCall;
12816
12948
  exports.buybackQuoteRaw = buybackQuoteRaw;
12817
12949
  exports.canRemoveDevice = canRemoveDevice;
12818
12950
  exports.coinToRaw = toRaw;
12951
+ exports.completeDeployment = completeDeployment;
12819
12952
  exports.computeAccountAddress = computeAccountAddress;
12820
12953
  exports.computeOwnerGuid = computeOwnerGuid;
12821
12954
  exports.confirmIntentBestEffort = confirmIntentBestEffort;
@@ -12826,6 +12959,8 @@ exports.createPasskeyOwner = createPasskeyOwner;
12826
12959
  exports.createSelfFundConsent = createSelfFundConsent;
12827
12960
  exports.decodeEscapeAndStatus = decodeEscapeAndStatus;
12828
12961
  exports.decodeGuardiansInfo = decodeGuardiansInfo;
12962
+ exports.deploySelfFunded = deploySelfFunded;
12963
+ exports.deploySponsored = deploySponsored;
12829
12964
  exports.deployedCollectionFromReceipt = deployedCollectionFromReceipt;
12830
12965
  exports.deriveAesKey = deriveAesKey;
12831
12966
  exports.deriveOwnerKeyPair = deriveOwnerKeyPair;
@@ -12886,5 +13021,6 @@ exports.validateCoinSupply = validateSupply;
12886
13021
  exports.validateCoinSymbol = validateSymbol;
12887
13022
  exports.validatePrice = validatePrice;
12888
13023
  exports.verifyAdminRequestSig = verifyAdminRequestSig;
13024
+ exports.waitUntilDeployed = waitUntilDeployed;
12889
13025
  //# sourceMappingURL=index.cjs.map
12890
13026
  //# sourceMappingURL=index.cjs.map