@medialane/sdk 0.121.0 → 0.122.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.
- package/dist/starknet/index.cjs +120 -0
- package/dist/starknet/index.cjs.map +1 -1
- package/dist/starknet/index.d.cts +52 -1
- package/dist/starknet/index.d.ts +52 -1
- package/dist/starknet/index.js +119 -2
- package/dist/starknet/index.js.map +1 -1
- package/package.json +2 -2
package/dist/starknet/index.cjs
CHANGED
|
@@ -12652,6 +12652,111 @@ 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 completeDeployment(deps, onStep, options = {}) {
|
|
12711
|
+
let sealed = options.forceNew ? null : deps.store.load();
|
|
12712
|
+
let privateKeyHex;
|
|
12713
|
+
if (!sealed) {
|
|
12714
|
+
onStep("creating-passkey");
|
|
12715
|
+
const created = await deps.passkey.createOwnerKey();
|
|
12716
|
+
sealed = created.sealed;
|
|
12717
|
+
privateKeyHex = created.privateKeyHex;
|
|
12718
|
+
deps.store.save(sealed);
|
|
12719
|
+
} else {
|
|
12720
|
+
privateKeyHex = await deps.passkey.unlockOwnerKey(sealed);
|
|
12721
|
+
}
|
|
12722
|
+
onStep("deploying");
|
|
12723
|
+
const wallet = { ownerAddress: sealed.address, ownerPubKey: sealed.ownerPubKey, privateKeyHex };
|
|
12724
|
+
const sponsored = deps.deploySponsoredImpl ?? deploySponsored;
|
|
12725
|
+
const selfFunded = deps.deploySelfFundedImpl ?? deploySelfFunded;
|
|
12726
|
+
if (deps.deployProxyUrl) {
|
|
12727
|
+
try {
|
|
12728
|
+
await sponsored({
|
|
12729
|
+
proxyUrl: deps.deployProxyUrl,
|
|
12730
|
+
provider: deps.provider(),
|
|
12731
|
+
fetchImpl: deps.fetchImpl,
|
|
12732
|
+
...wallet
|
|
12733
|
+
});
|
|
12734
|
+
} catch (sponsoredErr) {
|
|
12735
|
+
try {
|
|
12736
|
+
await selfFunded({ provider: deps.provider(), ...wallet });
|
|
12737
|
+
} catch (selfFundedErr) {
|
|
12738
|
+
const sponsored2 = sponsoredErr instanceof Error ? sponsoredErr.message : String(sponsoredErr);
|
|
12739
|
+
const selfFunded2 = selfFundedErr instanceof Error ? selfFundedErr.message : String(selfFundedErr);
|
|
12740
|
+
throw new Error(`Sponsored deploy failed: ${sponsored2}. Self-funded fallback failed: ${selfFunded2}`);
|
|
12741
|
+
}
|
|
12742
|
+
}
|
|
12743
|
+
} else {
|
|
12744
|
+
await selfFunded({ provider: deps.provider(), ...wallet });
|
|
12745
|
+
}
|
|
12746
|
+
onStep("signing-in");
|
|
12747
|
+
const address = sealed.address;
|
|
12748
|
+
const siwsToken = await (deps.requestSiwsTokenImpl ?? requestSiwsToken)({
|
|
12749
|
+
backendUrl: deps.backendUrl,
|
|
12750
|
+
walletAddress: address,
|
|
12751
|
+
signer: {
|
|
12752
|
+
signMessage: async (td) => signWithPrivateKey(privateKeyHex, starknet.typedData.getMessageHash(td, address))
|
|
12753
|
+
}
|
|
12754
|
+
});
|
|
12755
|
+
deps.store.notifyChange();
|
|
12756
|
+
return { sealed, siwsToken };
|
|
12757
|
+
}
|
|
12758
|
+
|
|
12759
|
+
// src/wallet/client.ts
|
|
12655
12760
|
function describeDevices(owners, thisDevicePubkey) {
|
|
12656
12761
|
const mine = computeOwnerGuid(thisDevicePubkey);
|
|
12657
12762
|
return owners.map((owner) => ({
|
|
@@ -12750,6 +12855,18 @@ function createMediaWallet(config) {
|
|
|
12750
12855
|
async removeDevice(sealed, ownerGuid) {
|
|
12751
12856
|
const { transactionHash } = await run(sealed, [buildRemoveOwnerByGuidCall(sealed.address, ownerGuid)]);
|
|
12752
12857
|
return transactionHash;
|
|
12858
|
+
},
|
|
12859
|
+
completeDeployment(onStep, options = {}) {
|
|
12860
|
+
if (!config.backendUrl) throw new Error("This wallet has no backend url configured for sign-in");
|
|
12861
|
+
const deps = {
|
|
12862
|
+
store: config.store,
|
|
12863
|
+
passkey: config.passkey,
|
|
12864
|
+
provider: config.provider,
|
|
12865
|
+
backendUrl: config.backendUrl,
|
|
12866
|
+
deployProxyUrl: config.deployProxyUrl,
|
|
12867
|
+
fetchImpl: config.fetchImpl
|
|
12868
|
+
};
|
|
12869
|
+
return completeDeployment(deps, onStep, options);
|
|
12753
12870
|
}
|
|
12754
12871
|
};
|
|
12755
12872
|
}
|
|
@@ -12816,6 +12933,7 @@ exports.buildTriggerEscapeOwnerCall = buildTriggerEscapeOwnerCall;
|
|
|
12816
12933
|
exports.buybackQuoteRaw = buybackQuoteRaw;
|
|
12817
12934
|
exports.canRemoveDevice = canRemoveDevice;
|
|
12818
12935
|
exports.coinToRaw = toRaw;
|
|
12936
|
+
exports.completeDeployment = completeDeployment;
|
|
12819
12937
|
exports.computeAccountAddress = computeAccountAddress;
|
|
12820
12938
|
exports.computeOwnerGuid = computeOwnerGuid;
|
|
12821
12939
|
exports.confirmIntentBestEffort = confirmIntentBestEffort;
|
|
@@ -12826,6 +12944,8 @@ exports.createPasskeyOwner = createPasskeyOwner;
|
|
|
12826
12944
|
exports.createSelfFundConsent = createSelfFundConsent;
|
|
12827
12945
|
exports.decodeEscapeAndStatus = decodeEscapeAndStatus;
|
|
12828
12946
|
exports.decodeGuardiansInfo = decodeGuardiansInfo;
|
|
12947
|
+
exports.deploySelfFunded = deploySelfFunded;
|
|
12948
|
+
exports.deploySponsored = deploySponsored;
|
|
12829
12949
|
exports.deployedCollectionFromReceipt = deployedCollectionFromReceipt;
|
|
12830
12950
|
exports.deriveAesKey = deriveAesKey;
|
|
12831
12951
|
exports.deriveOwnerKeyPair = deriveOwnerKeyPair;
|