@medialane/sdk 0.145.0 → 0.147.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.
@@ -352,7 +352,6 @@ var ApiClient = class {
352
352
  getActiveOrdersForToken(contract, tokenId) {
353
353
  return this.get(`/v1/orders/token/${this.addr(contract)}/${tokenId}`);
354
354
  }
355
- /** Offers others made on the address's assets. */
356
355
  getReceivedOffers(address, opts = {}) {
357
356
  const params = new URLSearchParams({ page: String(opts.page ?? 1), limit: String(opts.limit ?? 50) });
358
357
  return this.get(`/v1/orders/received/${this.addr(address)}?${params}`);
@@ -511,7 +510,6 @@ var ApiClient = class {
511
510
  uploadMetadata(metadata) {
512
511
  return this.post("/v1/metadata/upload", metadata);
513
512
  }
514
- /** Pins several JSON files as one IPFS directory, e.g. a drop's token metadata. */
515
513
  async uploadMetadataDirectory(files) {
516
514
  const res = await this.post("/v1/metadata/upload-directory", { files });
517
515
  return res.data;
@@ -565,7 +563,6 @@ var ApiClient = class {
565
563
  headers: this.asSubject(siwsToken)
566
564
  });
567
565
  }
568
- /** @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
566
  checkDeposit(txHash, siwsToken) {
570
567
  return this.request("/v1/portal/credits/check", {
571
568
  method: "POST",
@@ -757,14 +754,9 @@ var ApiClient = class {
757
754
  async verifyEmailCode(email, code) {
758
755
  await this.post("/v1/auth/email/verify-code", { email, code });
759
756
  }
760
- /**
761
- * Makes the passkey the only owner of the session account's wallet. `signature` is the passkey's owner-alive
762
- * proof for the wallet. Answers 409 when the wallet is already set up.
763
- */
764
757
  setupWalletKey(params) {
765
758
  return this.post("/v1/users/me/wallet/key", params);
766
759
  }
767
- /** The session account's wallet, and whether its passkey still has to be set up (`setupWalletKey`). */
768
760
  async getSessionWallet() {
769
761
  const body = await this.post("/v1/users/me/wallet", {});
770
762
  return body.walletAddress ? { walletAddress: body.walletAddress, needsKeySetup: body.needsKeySetup === true } : null;
@@ -12431,12 +12423,11 @@ function computeAccountAddress(ownerPubkey, salt = 0) {
12431
12423
  }
12432
12424
  var STARKNET_SIGNER_TYPE = "0x537461726b6e6574205369676e6572";
12433
12425
  var OPTION_NONE = "0x1";
12434
- var OPTION_SOME = "0x0";
12435
12426
  var SIGNER_STARKNET = "0x0";
12436
12427
  function computeOwnerGuid(ownerPubkey) {
12437
12428
  return starknet.hash.computePoseidonHash(STARKNET_SIGNER_TYPE, starknet.num.toHex(ownerPubkey));
12438
12429
  }
12439
- function changeOwners(accountAddress, guidsToRemove, pubkeysToAdd, ownerAlive) {
12430
+ function changeOwners(accountAddress, guidsToRemove, pubkeysToAdd) {
12440
12431
  return {
12441
12432
  contractAddress: accountAddress,
12442
12433
  entrypoint: "change_owners",
@@ -12445,55 +12436,10 @@ function changeOwners(accountAddress, guidsToRemove, pubkeysToAdd, ownerAlive) {
12445
12436
  ...guidsToRemove,
12446
12437
  starknet.num.toHex(pubkeysToAdd.length),
12447
12438
  ...pubkeysToAdd.flatMap((p) => [SIGNER_STARKNET, starknet.num.toHex(p)]),
12448
- ...ownerAlive ? ownerAliveCalldata(ownerAlive) : [OPTION_NONE]
12439
+ OPTION_NONE
12449
12440
  ]
12450
12441
  };
12451
12442
  }
12452
- function ownerAliveTypedData(newOwnerGuid, expiration, chainId) {
12453
- return {
12454
- types: {
12455
- StarknetDomain: [
12456
- { name: "name", type: "shortstring" },
12457
- { name: "version", type: "shortstring" },
12458
- { name: "chainId", type: "shortstring" },
12459
- { name: "revision", type: "shortstring" }
12460
- ],
12461
- "Owner Alive": [
12462
- { name: "Owner GUID", type: "felt" },
12463
- { name: "Signature expiration", type: "timestamp" }
12464
- ]
12465
- },
12466
- primaryType: "Owner Alive",
12467
- domain: { name: "Owner Alive", version: "1", chainId, revision: "1" },
12468
- message: { "Owner GUID": newOwnerGuid, "Signature expiration": expiration }
12469
- };
12470
- }
12471
- function ownerAliveCalldata(proof) {
12472
- if (proof.signature.length !== 2) {
12473
- throw new Error("owner-alive proof needs an r and s from the incoming owner");
12474
- }
12475
- return [
12476
- OPTION_SOME,
12477
- SIGNER_STARKNET,
12478
- starknet.num.toHex(proof.newOwnerPubkey),
12479
- starknet.num.toHex(proof.signature[0]),
12480
- starknet.num.toHex(proof.signature[1]),
12481
- starknet.num.toHex(proof.expiration)
12482
- ];
12483
- }
12484
- function buildChangeOwnersCall(accountAddress, removeOwnerPubkey, addOwnerPubkey, ownerAlive) {
12485
- if (!ownerAlive) {
12486
- throw new Error(
12487
- "Replacing the signing owner requires an owner-alive proof from the new owner. Sign ownerAliveTypedData with the new owner key and pass it here."
12488
- );
12489
- }
12490
- return changeOwners(
12491
- accountAddress,
12492
- [computeOwnerGuid(removeOwnerPubkey)],
12493
- [addOwnerPubkey],
12494
- ownerAlive
12495
- );
12496
- }
12497
12443
  function buildAddOwnerCall(accountAddress, addOwnerPubkey) {
12498
12444
  return changeOwners(accountAddress, [], [addOwnerPubkey]);
12499
12445
  }
@@ -13131,6 +13077,42 @@ async function completeDeployment(deps, onStep, options = {}) {
13131
13077
  deps.store.notifyChange();
13132
13078
  return { sealed, siwsToken };
13133
13079
  }
13080
+ function createDeploymentCoordinator(execute) {
13081
+ let inFlight = null;
13082
+ let currentStep = null;
13083
+ const listeners = /* @__PURE__ */ new Set();
13084
+ return {
13085
+ run(onStep, options = {}) {
13086
+ if (inFlight) {
13087
+ if (options.forceNew) {
13088
+ return Promise.reject(new Error("A wallet setup is already in progress."));
13089
+ }
13090
+ if (currentStep) onStep(currentStep);
13091
+ listeners.add(onStep);
13092
+ return inFlight.finally(() => listeners.delete(onStep));
13093
+ }
13094
+ listeners.add(onStep);
13095
+ let started;
13096
+ try {
13097
+ started = execute((step) => {
13098
+ currentStep = step;
13099
+ for (const listener of listeners) listener(step);
13100
+ }, options);
13101
+ } catch (err) {
13102
+ listeners.clear();
13103
+ return Promise.reject(err);
13104
+ }
13105
+ const run = started.finally(() => {
13106
+ inFlight = null;
13107
+ currentStep = null;
13108
+ listeners.clear();
13109
+ });
13110
+ inFlight = run;
13111
+ return run;
13112
+ },
13113
+ isDeploying: () => inFlight !== null
13114
+ };
13115
+ }
13134
13116
 
13135
13117
  // src/wallet/client.ts
13136
13118
  function describeDevices(owners, thisDevicePubkey) {
@@ -13147,6 +13129,18 @@ function canRemoveDevice(devices, guid) {
13147
13129
  }
13148
13130
  function createMediaWallet(config) {
13149
13131
  const ttl = config.unlockTtlMs ?? 2e4;
13132
+ const deployments = createDeploymentCoordinator((onStep, options) => {
13133
+ if (!config.backendUrl) throw new Error("This wallet has no backend url configured for sign-in");
13134
+ const deps = {
13135
+ store: config.store,
13136
+ passkey: config.passkey,
13137
+ provider: config.provider,
13138
+ backendUrl: config.backendUrl,
13139
+ deployProxyUrl: config.deployProxyUrl,
13140
+ fetchImpl: config.fetchImpl
13141
+ };
13142
+ return completeDeployment(deps, onStep, options);
13143
+ });
13150
13144
  const unlockCache = /* @__PURE__ */ new Map();
13151
13145
  const lock = (address) => {
13152
13146
  const entry = unlockCache.get(address);
@@ -13232,34 +13226,24 @@ function createMediaWallet(config) {
13232
13226
  const { transactionHash } = await run(sealed, [buildRemoveOwnerByGuidCall(sealed.address, ownerGuid)]);
13233
13227
  return transactionHash;
13234
13228
  },
13235
- completeDeployment(onStep, options = {}) {
13236
- if (!config.backendUrl) throw new Error("This wallet has no backend url configured for sign-in");
13237
- const deps = {
13238
- store: config.store,
13239
- passkey: config.passkey,
13240
- provider: config.provider,
13241
- backendUrl: config.backendUrl,
13242
- deployProxyUrl: config.deployProxyUrl,
13243
- fetchImpl: config.fetchImpl
13244
- };
13245
- return completeDeployment(deps, onStep, options);
13246
- }
13229
+ completeDeployment: (onStep, options) => deployments.run(onStep, options),
13230
+ isDeploying: () => deployments.isDeploying()
13247
13231
  };
13248
13232
  }
13233
+
13234
+ // src/session/session-wallet.ts
13249
13235
  async function adoptSessionWallet(api, saveAddress) {
13250
13236
  const wallet = await api.getSessionWallet();
13251
13237
  if (wallet) saveAddress(wallet.walletAddress);
13252
13238
  return wallet;
13253
13239
  }
13254
- var PROOF_TTL_SECONDS = 600;
13255
- async function setupSessionWalletKey(api, walletAddress, deps) {
13256
- const { sealed, privateKeyHex } = await deps.createOwnerKey();
13257
- const now = deps.now?.() ?? Math.floor(Date.now() / 1e3);
13258
- const expiration = now + PROOF_TTL_SECONDS;
13259
- const message = ownerAliveTypedData(computeOwnerGuid(sealed.ownerPubKey), expiration, "SN_MAIN");
13260
- const signature = signWithPrivateKey(privateKeyHex, starknet.typedData.getMessageHash(message, walletAddress));
13261
- const result = await api.setupWalletKey({ newOwnerPubkey: sealed.ownerPubKey, signature, expiration });
13262
- deps.saveOwner({ ...sealed, address: result.walletAddress });
13240
+ async function claimSessionWallet(api, walletAddress, deps) {
13241
+ const saved = deps.loadOwner();
13242
+ const resuming = saved !== null && normalizeWalletAddress(saved.address) === normalizeWalletAddress(walletAddress);
13243
+ const sealed = resuming ? saved : { ...(await deps.createOwnerKey()).sealed, address: walletAddress };
13244
+ if (!resuming) deps.saveOwner(sealed);
13245
+ const { removeOwnerGuid } = await api.setupWalletKey({ newOwnerPubkey: sealed.ownerPubKey });
13246
+ if (removeOwnerGuid) await deps.removeOwner(sealed, removeOwnerGuid);
13263
13247
  }
13264
13248
 
13265
13249
  exports.ADMIN_HEADERS = ADMIN_HEADERS;
@@ -13315,7 +13299,6 @@ exports.buildAddOwnerCall = buildAddOwnerCall;
13315
13299
  exports.buildAdminSessionTypedData = buildAdminSessionTypedData;
13316
13300
  exports.buildCancelEscapeCall = buildCancelEscapeCall;
13317
13301
  exports.buildCancellationTypedData = buildCancellationTypedData;
13318
- exports.buildChangeOwnersCall = buildChangeOwnersCall;
13319
13302
  exports.buildCompleteEscapeOwnerCall = buildCompleteEscapeOwnerCall;
13320
13303
  exports.buildCreateCreatorCoinCall = buildCreateCreatorCoinCall;
13321
13304
  exports.buildDeployAccountParams = buildDeployAccountParams;
@@ -13329,12 +13312,14 @@ exports.buildSetFirstGuardianCall = buildSetFirstGuardianCall;
13329
13312
  exports.buildTriggerEscapeOwnerCall = buildTriggerEscapeOwnerCall;
13330
13313
  exports.buybackQuoteRaw = buybackQuoteRaw;
13331
13314
  exports.canRemoveDevice = canRemoveDevice;
13315
+ exports.claimSessionWallet = claimSessionWallet;
13332
13316
  exports.coinToRaw = toRaw;
13333
13317
  exports.completeDeployment = completeDeployment;
13334
13318
  exports.computeAccountAddress = computeAccountAddress;
13335
13319
  exports.computeOwnerGuid = computeOwnerGuid;
13336
13320
  exports.confirmIntentBestEffort = confirmIntentBestEffort;
13337
13321
  exports.createAdminSessionGrant = createAdminSessionGrant;
13322
+ exports.createDeploymentCoordinator = createDeploymentCoordinator;
13338
13323
  exports.createMediaWallet = createMediaWallet;
13339
13324
  exports.createOwnerStore = createOwnerStore;
13340
13325
  exports.createPasskeyOwner = createPasskeyOwner;
@@ -13378,7 +13363,6 @@ exports.isValidStarknetAddress = isValidStarknetAddress;
13378
13363
  exports.mintedTokenIdFromReceipt = mintedTokenIdFromReceipt;
13379
13364
  exports.normalizeSiwsSignature = normalizeSiwsSignature;
13380
13365
  exports.normalizeWalletAddress = normalizeWalletAddress;
13381
- exports.ownerAliveTypedData = ownerAliveTypedData;
13382
13366
  exports.ownerConstructorCalldata = ownerConstructorCalldata;
13383
13367
  exports.parseAccountAddress = parseAccountAddress;
13384
13368
  exports.parseAdminHeaders = parseAdminHeaders;
@@ -13391,7 +13375,6 @@ exports.requestSiwsToken = requestSiwsToken;
13391
13375
  exports.sealPrivateKey = sealPrivateKey;
13392
13376
  exports.selfFundedExecutor = selfFundedExecutor;
13393
13377
  exports.sessionKeyHashOf = sessionKeyHashOf;
13394
- exports.setupSessionWalletKey = setupSessionWalletKey;
13395
13378
  exports.signAdminRequest = signAdminRequest;
13396
13379
  exports.signWithPrivateKey = signWithPrivateKey;
13397
13380
  exports.sponsoredExecutor = sponsoredExecutor;