@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.d.cts CHANGED
@@ -490,14 +490,8 @@ declare abstract class LiquidEvmBaseWallet extends BaseWallet {
490
490
  * Convert bytes to hex string with 0x prefix
491
491
  */
492
492
  protected bytesToHex(bytes: Uint8Array): string;
493
- /**
494
- * Process transaction group to extract transactions that need signing
495
- */
496
- protected processTxns(txnGroup: algosdk.Transaction[], indexesToSign?: number[]): algosdk.Transaction[];
497
- /**
498
- * Process encoded transaction group to extract transactions that need signing
499
- */
500
- protected processEncodedTxns(txnGroup: Uint8Array[], indexesToSign?: number[]): algosdk.Transaction[];
493
+ private processTxns;
494
+ private processEncodedTxns;
501
495
  /**
502
496
  * Sign Algorand transactions using EVM wallet signatures
503
497
  */
package/dist/index.d.ts CHANGED
@@ -490,14 +490,8 @@ declare abstract class LiquidEvmBaseWallet extends BaseWallet {
490
490
  * Convert bytes to hex string with 0x prefix
491
491
  */
492
492
  protected bytesToHex(bytes: Uint8Array): string;
493
- /**
494
- * Process transaction group to extract transactions that need signing
495
- */
496
- protected processTxns(txnGroup: algosdk.Transaction[], indexesToSign?: number[]): algosdk.Transaction[];
497
- /**
498
- * Process encoded transaction group to extract transactions that need signing
499
- */
500
- protected processEncodedTxns(txnGroup: Uint8Array[], indexesToSign?: number[]): algosdk.Transaction[];
493
+ private processTxns;
494
+ private processEncodedTxns;
501
495
  /**
502
496
  * Sign Algorand transactions using EVM wallet signatures
503
497
  */
package/dist/index.js CHANGED
@@ -37,10 +37,10 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
37
37
  mod
38
38
  ));
39
39
 
40
- // ../../node_modules/.pnpm/@magic-sdk+types@24.22.0/node_modules/@magic-sdk/types/dist/es/index.mjs
40
+ // ../../../../node_modules/.pnpm/@magic-sdk+types@24.22.0/node_modules/@magic-sdk/types/dist/es/index.mjs
41
41
  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;
42
42
  var init_es = __esm({
43
- "../../node_modules/.pnpm/@magic-sdk+types@24.22.0/node_modules/@magic-sdk/types/dist/es/index.mjs"() {
43
+ "../../../../node_modules/.pnpm/@magic-sdk+types@24.22.0/node_modules/@magic-sdk/types/dist/es/index.mjs"() {
44
44
  "use strict";
45
45
  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 || {});
46
46
  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 || {});
@@ -84,7 +84,7 @@ var init_es = __esm({
84
84
  }
85
85
  });
86
86
 
87
- // ../../node_modules/.pnpm/@magic-sdk+provider@29.5.0_localforage@1.10.0/node_modules/@magic-sdk/provider/dist/es/index.mjs
87
+ // ../../../../node_modules/.pnpm/@magic-sdk+provider@29.5.0_localforage@1.10.0/node_modules/@magic-sdk/provider/dist/es/index.mjs
88
88
  function ir(r10) {
89
89
  let e = { exports: {} };
90
90
  return r10(e, e.exports), e.exports;
@@ -387,7 +387,7 @@ function On(r10) {
387
387
  }
388
388
  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;
389
389
  var init_es2 = __esm({
390
- "../../node_modules/.pnpm/@magic-sdk+provider@29.5.0_localforage@1.10.0/node_modules/@magic-sdk/provider/dist/es/index.mjs"() {
390
+ "../../../../node_modules/.pnpm/@magic-sdk+provider@29.5.0_localforage@1.10.0/node_modules/@magic-sdk/provider/dist/es/index.mjs"() {
391
391
  "use strict";
392
392
  init_es();
393
393
  init_es();
@@ -1507,16 +1507,16 @@ var init_es2 = __esm({
1507
1507
  }
1508
1508
  });
1509
1509
 
1510
- // ../../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
1510
+ // ../../../../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
1511
1511
  var init_es3 = __esm({
1512
- "../../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"() {
1512
+ "../../../../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"() {
1513
1513
  "use strict";
1514
1514
  init_es2();
1515
1515
  init_es();
1516
1516
  }
1517
1517
  });
1518
1518
 
1519
- // ../../node_modules/.pnpm/magic-sdk@29.4.2/node_modules/magic-sdk/dist/es/index.mjs
1519
+ // ../../../../node_modules/.pnpm/magic-sdk@29.4.2/node_modules/magic-sdk/dist/es/index.mjs
1520
1520
  var es_exports = {};
1521
1521
  __export(es_exports, {
1522
1522
  AuthEventOnReceived: () => k,
@@ -1575,7 +1575,7 @@ function st2(_2) {
1575
1575
  }
1576
1576
  var $r2, Qe2, Zr2, qr2, kr2, et2, de2, Je2, rt2, $e2, qe2, er2, pe2, Te2, at2, ye2, wt2;
1577
1577
  var init_es4 = __esm({
1578
- "../../node_modules/.pnpm/magic-sdk@29.4.2/node_modules/magic-sdk/dist/es/index.mjs"() {
1578
+ "../../../../node_modules/.pnpm/magic-sdk@29.4.2/node_modules/magic-sdk/dist/es/index.mjs"() {
1579
1579
  "use strict";
1580
1580
  init_es2();
1581
1581
  init_es2();
@@ -3199,14 +3199,14 @@ var init_es4 = __esm({
3199
3199
  }
3200
3200
  });
3201
3201
 
3202
- // ../../node_modules/.pnpm/@magic-ext+algorand@24.4.2/node_modules/@magic-ext/algorand/dist/es/index.mjs
3202
+ // ../../../../node_modules/.pnpm/@magic-ext+algorand@24.4.2/node_modules/@magic-ext/algorand/dist/es/index.mjs
3203
3203
  var es_exports2 = {};
3204
3204
  __export(es_exports2, {
3205
3205
  AlgorandExtension: () => r9
3206
3206
  });
3207
3207
  var r9;
3208
3208
  var init_es5 = __esm({
3209
- "../../node_modules/.pnpm/@magic-ext+algorand@24.4.2/node_modules/@magic-ext/algorand/dist/es/index.mjs"() {
3209
+ "../../../../node_modules/.pnpm/@magic-ext+algorand@24.4.2/node_modules/@magic-ext/algorand/dist/es/index.mjs"() {
3210
3210
  "use strict";
3211
3211
  init_es3();
3212
3212
  r9 = class extends He.Internal {
@@ -3236,9 +3236,9 @@ var init_es5 = __esm({
3236
3236
  }
3237
3237
  });
3238
3238
 
3239
- // ../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js
3239
+ // ../../../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js
3240
3240
  var require_nacl_fast = __commonJS({
3241
- "../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js"(exports, module) {
3241
+ "../../../../node_modules/.pnpm/tweetnacl@1.0.3/node_modules/tweetnacl/nacl-fast.js"(exports, module) {
3242
3242
  "use strict";
3243
3243
  (function(nacl) {
3244
3244
  "use strict";
@@ -8224,7 +8224,9 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8224
8224
  if (currentChainId === ALGORAND_CHAIN_ID_HEX) {
8225
8225
  return;
8226
8226
  }
8227
- this.logger.info(`Wrong chain (${currentChainId}), switching to Algorand (${ALGORAND_CHAIN_ID_HEX})...`);
8227
+ this.logger.info(
8228
+ `Wrong chain (${currentChainId}), switching to Algorand (${ALGORAND_CHAIN_ID_HEX})...`
8229
+ );
8228
8230
  try {
8229
8231
  await provider.request({
8230
8232
  method: "wallet_switchEthereumChain",
@@ -8285,9 +8287,6 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8285
8287
  bytesToHex(bytes) {
8286
8288
  return "0x" + Array.from(bytes).map((b3) => b3.toString(16).padStart(2, "0")).join("");
8287
8289
  }
8288
- /**
8289
- * Process transaction group to extract transactions that need signing
8290
- */
8291
8290
  processTxns(txnGroup, indexesToSign) {
8292
8291
  const txnsToSign = [];
8293
8292
  txnGroup.forEach((txn, index) => {
@@ -8295,14 +8294,13 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8295
8294
  const signer = txn.sender.toString();
8296
8295
  const canSignTxn = this.addresses.includes(signer);
8297
8296
  if (isIndexMatch && canSignTxn) {
8298
- txnsToSign.push(txn);
8297
+ txnsToSign.push({ txn });
8298
+ } else {
8299
+ txnsToSign.push({ txn, signers: [] });
8299
8300
  }
8300
8301
  });
8301
8302
  return txnsToSign;
8302
8303
  }
8303
- /**
8304
- * Process encoded transaction group to extract transactions that need signing
8305
- */
8306
8304
  processEncodedTxns(txnGroup, indexesToSign) {
8307
8305
  const txnsToSign = [];
8308
8306
  txnGroup.forEach((txnBuffer, index) => {
@@ -8313,7 +8311,9 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8313
8311
  const signer = txn.sender.toString();
8314
8312
  const canSignTxn = !isSigned && this.addresses.includes(signer);
8315
8313
  if (isIndexMatch && canSignTxn) {
8316
- txnsToSign.push(txn);
8314
+ txnsToSign.push({ txn });
8315
+ } else {
8316
+ txnsToSign.push({ txn, signers: [] });
8317
8317
  }
8318
8318
  });
8319
8319
  return txnsToSign;
@@ -8324,25 +8324,17 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8324
8324
  signTransactions = async (txnGroup, indexesToSign) => {
8325
8325
  try {
8326
8326
  this.logger.debug("Signing transactions...", { txnGroup, indexesToSign });
8327
- const evmSdk = await this.initializeEvmSdk();
8328
- let flatTxns = [];
8327
+ const liquidEvmSdk = await this.initializeEvmSdk();
8328
+ let txnsToSign = [];
8329
8329
  if (isTransactionArray(txnGroup)) {
8330
- flatTxns = flattenTxnGroup(txnGroup);
8330
+ const flatTxns = flattenTxnGroup(txnGroup);
8331
+ txnsToSign = this.processTxns(flatTxns, indexesToSign);
8331
8332
  } else {
8332
- const flatEncoded = flattenTxnGroup(txnGroup);
8333
- flatTxns = flatEncoded.map((txnBuffer) => {
8334
- const decodedObj = algosdk9.msgpackRawDecode(txnBuffer);
8335
- const isSigned = isSignedTxn(decodedObj);
8336
- return isSigned ? algosdk9.decodeSignedTransaction(txnBuffer).txn : algosdk9.decodeUnsignedTransaction(txnBuffer);
8337
- });
8338
- }
8339
- const txnsToSign = isTransactionArray(txnGroup) ? this.processTxns(flatTxns, indexesToSign) : this.processEncodedTxns(flattenTxnGroup(txnGroup), indexesToSign);
8340
- if (txnsToSign.length === 0) {
8341
- this.logger.debug("No transactions to sign");
8342
- return flatTxns.map(() => null);
8333
+ const flatTxns = flattenTxnGroup(txnGroup);
8334
+ txnsToSign = this.processEncodedTxns(flatTxns, indexesToSign);
8343
8335
  }
8344
8336
  const firstTxn = txnsToSign[0];
8345
- const algorandAddress = firstTxn.sender.toString();
8337
+ const algorandAddress = firstTxn.txn.sender.toString();
8346
8338
  const evmAddress = this.evmAddressMap.get(algorandAddress);
8347
8339
  if (!evmAddress) {
8348
8340
  throw new Error(`No EVM address found for Algorand address: ${algorandAddress}`);
@@ -8350,14 +8342,20 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8350
8342
  const onBeforeSign = this.options.uiHooks?.onBeforeSign ?? this.managerUIHooks?.onBeforeSign;
8351
8343
  if (onBeforeSign) {
8352
8344
  this.logger.debug("Running onBeforeSign hook", { txnGroup, indexesToSign });
8353
- await onBeforeSign(txnGroup, indexesToSign);
8345
+ const txnsAsUint8 = txnsToSign.map(({ txn }) => algosdk9.encodeUnsignedTransaction(txn));
8346
+ await onBeforeSign(txnsAsUint8, indexesToSign);
8354
8347
  }
8355
8348
  await this.ensureAlgorandChain();
8356
- const signedBlobs = await evmSdk.signTxn({
8349
+ const { signer: evmSigner } = await liquidEvmSdk.getSigner({
8357
8350
  evmAddress,
8358
- txns: flatTxns,
8359
8351
  signMessage: (typedData) => this.signWithProvider(typedData, evmAddress)
8360
8352
  });
8353
+ const allTxns = txnsToSign.map((t) => t.txn);
8354
+ const signIndexes = txnsToSign.reduce((acc, t, i) => {
8355
+ if (!("signers" in t)) acc.push(i);
8356
+ return acc;
8357
+ }, []);
8358
+ const signedBlobs = await evmSigner(allTxns, signIndexes);
8361
8359
  const onAfterSign = this.options.uiHooks?.onAfterSign ?? this.managerUIHooks?.onAfterSign;
8362
8360
  if (onAfterSign) {
8363
8361
  this.logger.debug("Running onAfterSign hook");
@@ -8366,12 +8364,10 @@ var LiquidEvmBaseWallet = class extends BaseWallet {
8366
8364
  } catch (e) {
8367
8365
  }
8368
8366
  }
8369
- const result = flatTxns.map((txn, index) => {
8370
- const isIndexMatch = !indexesToSign || indexesToSign.includes(index);
8371
- const signer = txn.sender.toString();
8372
- const canSignTxn = this.addresses.includes(signer);
8373
- if (isIndexMatch && canSignTxn) {
8374
- return signedBlobs[index];
8367
+ let signedIdx = 0;
8368
+ const result = txnsToSign.map((_2, index) => {
8369
+ if (signIndexes.includes(index)) {
8370
+ return signedBlobs[signedIdx++];
8375
8371
  }
8376
8372
  return null;
8377
8373
  });