@d13co/use-wallet 4.5.2 → 4.5.4

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/index.cjs CHANGED
@@ -33,10 +33,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
33
33
  ));
34
34
  var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
35
35
 
36
- // ../../node_modules/.pnpm/@magic-sdk+types@24.22.0/node_modules/@magic-sdk/types/dist/es/index.mjs
36
+ // ../../../../node_modules/.pnpm/@magic-sdk+types@24.22.0/node_modules/@magic-sdk/types/dist/es/index.mjs
37
37
  var m, v, u, _, f, g, Z, E, y, x, A, R, I, N, h, T, O, S, b, C, F, U, k, L, w, D, G, V, H, q, W, J, Y, B, P, j, Q, X, z;
38
38
  var init_es = __esm({
39
- "../../node_modules/.pnpm/@magic-sdk+types@24.22.0/node_modules/@magic-sdk/types/dist/es/index.mjs"() {
39
+ "../../../../node_modules/.pnpm/@magic-sdk+types@24.22.0/node_modules/@magic-sdk/types/dist/es/index.mjs"() {
40
40
  "use strict";
41
41
  m = ((o) => (o.MissingApiKey = "MISSING_API_KEY", o.ModalNotReady = "MODAL_NOT_READY", o.ConnectionLost = "CONNECTION_WAS_LOST", o.MalformedResponse = "MALFORMED_RESPONSE", o.InvalidArgument = "INVALID_ARGUMENT", o.ExtensionNotInitialized = "EXTENSION_NOT_INITIALIZED", o.IncompatibleExtensions = "INCOMPATIBLE_EXTENSIONS", o))(m || {});
42
42
  v = ((s) => (s.SyncWeb3Method = "SYNC_WEB3_METHOD", s.DuplicateIframe = "DUPLICATE_IFRAME", s.ReactNativeEndpointConfiguration = "REACT_NATIVE_ENDPOINT_CONFIGURATION", s.DeprecationNotice = "DEPRECATION_NOTICE", s.ProductAnnouncement = "ANNOUNCEMENT", s))(v || {});
@@ -80,7 +80,7 @@ var init_es = __esm({
80
80
  }
81
81
  });
82
82
 
83
- // ../../node_modules/.pnpm/@magic-sdk+provider@29.5.0_localforage@1.10.0/node_modules/@magic-sdk/provider/dist/es/index.mjs
83
+ // ../../../../node_modules/.pnpm/@magic-sdk+provider@29.5.0_localforage@1.10.0/node_modules/@magic-sdk/provider/dist/es/index.mjs
84
84
  function ir(r10) {
85
85
  let e = { exports: {} };
86
86
  return r10(e, e.exports), e.exports;
@@ -383,7 +383,7 @@ function On(r10) {
383
383
  }
384
384
  var Yt, Ne, Qt, Zt, er, tr, rr, nr, sr, or, Nt, ar, $e, cr, h2, Z2, ze, ot, lr, dr, Ye, oe, Qe, Ze, X2, M, ur, J2, pr, mr, hr, Er, fr, gr, yr, Rr, vr, Tr, Ir, br, Pr, Ae, z2, Y2, et, tt, Q2, y2, E2, wr, xr, Sr, rt, Mr, T2, Cr, Nr, Ar, $r, Lr, Or, _r, kr, Dr, qr, it, Ur, nt, st, Fr, Wr, ie, ae, at, m2, ut, $, U2, L2, de, te, Qr, me, pe, R2, x2, A2, Zr, en, tn, rn, Oe, _e, he, bt, nn, sn, St, K, At, De, $t, f2, Tn, ye, Ue, Fe, We, Je, In, Te, Ie, Pe, we, H2, xe, Me, je, An, Ht, Bt, $n, Ve, Xt, Be, Ce, He;
385
385
  var init_es2 = __esm({
386
- "../../node_modules/.pnpm/@magic-sdk+provider@29.5.0_localforage@1.10.0/node_modules/@magic-sdk/provider/dist/es/index.mjs"() {
386
+ "../../../../node_modules/.pnpm/@magic-sdk+provider@29.5.0_localforage@1.10.0/node_modules/@magic-sdk/provider/dist/es/index.mjs"() {
387
387
  "use strict";
388
388
  init_es();
389
389
  init_es();
@@ -1503,16 +1503,16 @@ var init_es2 = __esm({
1503
1503
  }
1504
1504
  });
1505
1505
 
1506
- // ../../node_modules/.pnpm/@magic-sdk+commons@25.4.2_@magic-sdk+provider@29.5.0_localforage@1.10.0__@magic-sdk+types@24.22.0/node_modules/@magic-sdk/commons/dist/es/index.mjs
1506
+ // ../../../../node_modules/.pnpm/@magic-sdk+commons@25.4.2_@magic-sdk+provider@29.5.0_localforage@1.10.0__@magic-sdk+types@24.22.0/node_modules/@magic-sdk/commons/dist/es/index.mjs
1507
1507
  var init_es3 = __esm({
1508
- "../../node_modules/.pnpm/@magic-sdk+commons@25.4.2_@magic-sdk+provider@29.5.0_localforage@1.10.0__@magic-sdk+types@24.22.0/node_modules/@magic-sdk/commons/dist/es/index.mjs"() {
1508
+ "../../../../node_modules/.pnpm/@magic-sdk+commons@25.4.2_@magic-sdk+provider@29.5.0_localforage@1.10.0__@magic-sdk+types@24.22.0/node_modules/@magic-sdk/commons/dist/es/index.mjs"() {
1509
1509
  "use strict";
1510
1510
  init_es2();
1511
1511
  init_es();
1512
1512
  }
1513
1513
  });
1514
1514
 
1515
- // ../../node_modules/.pnpm/magic-sdk@29.4.2/node_modules/magic-sdk/dist/es/index.mjs
1515
+ // ../../../../node_modules/.pnpm/magic-sdk@29.4.2/node_modules/magic-sdk/dist/es/index.mjs
1516
1516
  var es_exports = {};
1517
1517
  __export(es_exports, {
1518
1518
  AuthEventOnReceived: () => k,
@@ -1571,7 +1571,7 @@ function st2(_2) {
1571
1571
  }
1572
1572
  var $r2, Qe2, Zr2, qr2, kr2, et2, de2, Je2, rt2, $e2, qe2, er2, pe2, Te2, at2, ye2, wt2;
1573
1573
  var init_es4 = __esm({
1574
- "../../node_modules/.pnpm/magic-sdk@29.4.2/node_modules/magic-sdk/dist/es/index.mjs"() {
1574
+ "../../../../node_modules/.pnpm/magic-sdk@29.4.2/node_modules/magic-sdk/dist/es/index.mjs"() {
1575
1575
  "use strict";
1576
1576
  init_es2();
1577
1577
  init_es2();
@@ -3195,14 +3195,14 @@ var init_es4 = __esm({
3195
3195
  }
3196
3196
  });
3197
3197
 
3198
- // ../../node_modules/.pnpm/@magic-ext+algorand@24.4.2/node_modules/@magic-ext/algorand/dist/es/index.mjs
3198
+ // ../../../../node_modules/.pnpm/@magic-ext+algorand@24.4.2/node_modules/@magic-ext/algorand/dist/es/index.mjs
3199
3199
  var es_exports2 = {};
3200
3200
  __export(es_exports2, {
3201
3201
  AlgorandExtension: () => r9
3202
3202
  });
3203
3203
  var r9;
3204
3204
  var init_es5 = __esm({
3205
- "../../node_modules/.pnpm/@magic-ext+algorand@24.4.2/node_modules/@magic-ext/algorand/dist/es/index.mjs"() {
3205
+ "../../../../node_modules/.pnpm/@magic-ext+algorand@24.4.2/node_modules/@magic-ext/algorand/dist/es/index.mjs"() {
3206
3206
  "use strict";
3207
3207
  init_es3();
3208
3208
  r9 = class extends He.Internal {
@@ -3232,9 +3232,9 @@ var init_es5 = __esm({
3232
3232
  }
3233
3233
  });
3234
3234
 
3235
- // ../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js
3235
+ // ../../../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js
3236
3236
  var require_nacl_fast = __commonJS({
3237
- "../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js"(exports2, module2) {
3237
+ "../../../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js"(exports2, module2) {
3238
3238
  "use strict";
3239
3239
  (function(nacl) {
3240
3240
  "use strict";
@@ -8270,7 +8270,9 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8270
8270
  if (currentChainId === ALGORAND_CHAIN_ID_HEX) {
8271
8271
  return;
8272
8272
  }
8273
- this.logger.info(`Wrong chain (${currentChainId}), switching to Algorand (${ALGORAND_CHAIN_ID_HEX})...`);
8273
+ this.logger.info(
8274
+ `Wrong chain (${currentChainId}), switching to Algorand (${ALGORAND_CHAIN_ID_HEX})...`
8275
+ );
8274
8276
  try {
8275
8277
  await provider.request({
8276
8278
  method: "wallet_switchEthereumChain",
@@ -8331,9 +8333,6 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8331
8333
  bytesToHex(bytes) {
8332
8334
  return "0x" + Array.from(bytes).map((b3) => b3.toString(16).padStart(2, "0")).join("");
8333
8335
  }
8334
- /**
8335
- * Process transaction group to extract transactions that need signing
8336
- */
8337
8336
  processTxns(txnGroup, indexesToSign) {
8338
8337
  const txnsToSign = [];
8339
8338
  txnGroup.forEach((txn, index) => {
@@ -8341,14 +8340,13 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8341
8340
  const signer = txn.sender.toString();
8342
8341
  const canSignTxn = this.addresses.includes(signer);
8343
8342
  if (isIndexMatch && canSignTxn) {
8344
- txnsToSign.push(txn);
8343
+ txnsToSign.push({ txn });
8344
+ } else {
8345
+ txnsToSign.push({ txn, signers: [] });
8345
8346
  }
8346
8347
  });
8347
8348
  return txnsToSign;
8348
8349
  }
8349
- /**
8350
- * Process encoded transaction group to extract transactions that need signing
8351
- */
8352
8350
  processEncodedTxns(txnGroup, indexesToSign) {
8353
8351
  const txnsToSign = [];
8354
8352
  txnGroup.forEach((txnBuffer, index) => {
@@ -8359,7 +8357,9 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8359
8357
  const signer = txn.sender.toString();
8360
8358
  const canSignTxn = !isSigned && this.addresses.includes(signer);
8361
8359
  if (isIndexMatch && canSignTxn) {
8362
- txnsToSign.push(txn);
8360
+ txnsToSign.push({ txn });
8361
+ } else {
8362
+ txnsToSign.push({ txn, signers: [] });
8363
8363
  }
8364
8364
  });
8365
8365
  return txnsToSign;
@@ -8370,25 +8370,17 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8370
8370
  signTransactions = async (txnGroup, indexesToSign) => {
8371
8371
  try {
8372
8372
  this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
8373
- const evmSdk = await this.initializeEvmSdk();
8374
- let flatTxns = [];
8373
+ const liquidEvmSdk = await this.initializeEvmSdk();
8374
+ let txnsToSign = [];
8375
8375
  if (isTransactionArray(txnGroup)) {
8376
- flatTxns = flattenTxnGroup(txnGroup);
8376
+ const flatTxns = flattenTxnGroup(txnGroup);
8377
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
8377
8378
  } else {
8378
- const flatEncoded = flattenTxnGroup(txnGroup);
8379
- flatTxns = flatEncoded.map((txnBuffer) => {
8380
- const decodedObj = import_algosdk9.default.msgpackRawDecode(txnBuffer);
8381
- const isSigned = isSignedTxn(decodedObj);
8382
- return isSigned ? import_algosdk9.default.decodeSignedTransaction(txnBuffer).txn : import_algosdk9.default.decodeUnsignedTransaction(txnBuffer);
8383
- });
8384
- }
8385
- const txnsToSign = isTransactionArray(txnGroup) ? this.processTxns(flatTxns, indexesToSign) : this.processEncodedTxns(flattenTxnGroup(txnGroup), indexesToSign);
8386
- if (txnsToSign.length === 0) {
8387
- this.logger.debug("No transactions to sign");
8388
- return flatTxns.map(() => null);
8379
+ const flatTxns = flattenTxnGroup(txnGroup);
8380
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
8389
8381
  }
8390
8382
  const firstTxn = txnsToSign[0];
8391
- const algorandAddress = firstTxn.sender.toString();
8383
+ const algorandAddress = firstTxn.txn.sender.toString();
8392
8384
  const evmAddress = this.evmAddressMap.get(algorandAddress);
8393
8385
  if (!evmAddress) {
8394
8386
  throw new Error(`No EVM address found for Algorand address: ${algorandAddress}`);
@@ -8396,14 +8388,20 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8396
8388
  const onBeforeSign = this.options.uiHooks?.onBeforeSign ?? this.managerUIHooks?.onBeforeSign;
8397
8389
  if (onBeforeSign) {
8398
8390
  this.logger.debug("Running onBeforeSign hook", { txnGroup, indexesToSign });
8399
- await onBeforeSign(txnGroup, indexesToSign);
8391
+ const txnsAsUint8 = txnsToSign.map(({ txn }) => import_algosdk9.default.encodeUnsignedTransaction(txn));
8392
+ await onBeforeSign(txnsAsUint8, indexesToSign);
8400
8393
  }
8401
8394
  await this.ensureAlgorandChain();
8402
- const signedBlobs = await evmSdk.signTxn({
8395
+ const { signer: evmSigner } = await liquidEvmSdk.getSigner({
8403
8396
  evmAddress,
8404
- txns: flatTxns,
8405
8397
  signMessage: (typedData) => this.signWithProvider(typedData, evmAddress)
8406
8398
  });
8399
+ const allTxns = txnsToSign.map((t) => t.txn);
8400
+ const signIndexes = txnsToSign.reduce((acc, t, i) => {
8401
+ if (!("signers" in t)) acc.push(i);
8402
+ return acc;
8403
+ }, []);
8404
+ const signedBlobs = await evmSigner(allTxns, signIndexes);
8407
8405
  const onAfterSign = this.options.uiHooks?.onAfterSign ?? this.managerUIHooks?.onAfterSign;
8408
8406
  if (onAfterSign) {
8409
8407
  this.logger.debug("Running onAfterSign hook");
@@ -8412,12 +8410,10 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8412
8410
  } catch (e) {
8413
8411
  }
8414
8412
  }
8415
- const result = flatTxns.map((txn, index) => {
8416
- const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
8417
- const signer = txn.sender.toString();
8418
- const canSignTxn = this.addresses.includes(signer);
8419
- if (isIndexMatch && canSignTxn) {
8420
- return signedBlobs[index];
8413
+ let signedIdx = 0;
8414
+ const result = txnsToSign.map((_2, index) => {
8415
+ if (signIndexes.includes(index)) {
8416
+ return signedBlobs[signedIdx++];
8421
8417
  }
8422
8418
  return null;
8423
8419
  });