@txnlab/use-wallet 1.0.4 → 1.0.5
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/cjs/clients/algosigner/client.d.ts +1 -1
- package/dist/cjs/clients/base/base.d.ts +1 -1
- package/dist/cjs/clients/defly/client.d.ts +1 -1
- package/dist/cjs/clients/exodus/client.d.ts +1 -1
- package/dist/cjs/clients/kmd/client.d.ts +1 -1
- package/dist/cjs/clients/myalgo/client.d.ts +1 -1
- package/dist/cjs/clients/pera/client.d.ts +1 -1
- package/dist/cjs/clients/walletconnect/client.d.ts +1 -1
- package/dist/cjs/hooks/useWallet.d.ts +1 -1
- package/dist/cjs/index.js +145 -54
- package/dist/cjs/index.js.map +1 -1
- package/dist/esm/clients/algosigner/client.d.ts +1 -1
- package/dist/esm/clients/base/base.d.ts +1 -1
- package/dist/esm/clients/defly/client.d.ts +1 -1
- package/dist/esm/clients/exodus/client.d.ts +1 -1
- package/dist/esm/clients/kmd/client.d.ts +1 -1
- package/dist/esm/clients/myalgo/client.d.ts +1 -1
- package/dist/esm/clients/pera/client.d.ts +1 -1
- package/dist/esm/clients/walletconnect/client.d.ts +1 -1
- package/dist/esm/hooks/useWallet.d.ts +1 -1
- package/dist/esm/index.js +145 -54
- package/dist/index.d.ts +9 -9
- package/package.json +1 -1
|
@@ -26,7 +26,7 @@ declare class AlgoSignerClient extends BaseWallet {
|
|
|
26
26
|
}>;
|
|
27
27
|
reconnect(onDisconnect: () => void): Promise<null>;
|
|
28
28
|
disconnect(): Promise<void>;
|
|
29
|
-
signTransactions(connectedAccounts: string[], transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
29
|
+
signTransactions(connectedAccounts: string[], transactions: Uint8Array[], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
30
30
|
/** @deprecated */
|
|
31
31
|
formatTransactionsArray(transactions: TransactionsArray): AlgoSignerTransaction[];
|
|
32
32
|
/** @deprecated */
|
|
@@ -9,7 +9,7 @@ declare abstract class BaseClient {
|
|
|
9
9
|
abstract connect(onDisconnect: () => void): Promise<Wallet>;
|
|
10
10
|
abstract disconnect(): Promise<void>;
|
|
11
11
|
abstract reconnect(onDisconnect: () => void): Promise<Wallet | null>;
|
|
12
|
-
abstract signTransactions(connectedAccounts: string[], transactions: Array<Uint8Array
|
|
12
|
+
abstract signTransactions(connectedAccounts: string[], transactions: Array<Uint8Array>, indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
13
13
|
abstract signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
14
14
|
protected constructor(metadata: Metadata, algosdk: typeof _algosdk, algodClient: _algosdk.Algodv2);
|
|
15
15
|
healthCheck(): Promise<{}>;
|
|
@@ -28,7 +28,7 @@ declare class DeflyWalletClient extends BaseWallet {
|
|
|
28
28
|
isWalletConnect: boolean;
|
|
29
29
|
} | null>;
|
|
30
30
|
disconnect(): Promise<void>;
|
|
31
|
-
signTransactions(connectedAccounts: string[], transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
31
|
+
signTransactions(connectedAccounts: string[], transactions: Uint8Array[], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
32
32
|
/** @deprecated */
|
|
33
33
|
signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
34
34
|
/** @deprecated */
|
|
@@ -26,7 +26,7 @@ declare class ExodusClient extends BaseWallet {
|
|
|
26
26
|
}>;
|
|
27
27
|
reconnect(onDisconnect: () => void): Promise<null>;
|
|
28
28
|
disconnect(): Promise<void>;
|
|
29
|
-
signTransactions(connectedAccounts: string[], transactions: Array<Uint8Array
|
|
29
|
+
signTransactions(connectedAccounts: string[], transactions: Array<Uint8Array>, indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
30
30
|
/** @deprecated */
|
|
31
31
|
signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
32
32
|
}
|
|
@@ -23,7 +23,7 @@ declare class KMDWalletClient extends BaseWallet {
|
|
|
23
23
|
releaseToken(token: string): Promise<void>;
|
|
24
24
|
listWallets(): Promise<Record<string, string>>;
|
|
25
25
|
listAccounts(wallet: string, password: string): Promise<Array<Account>>;
|
|
26
|
-
signTransactions(connectedAccounts: string[], transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
26
|
+
signTransactions(connectedAccounts: string[], transactions: Uint8Array[], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
27
27
|
signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
28
28
|
}
|
|
29
29
|
export default KMDWalletClient;
|
|
@@ -30,7 +30,7 @@ declare class MyAlgoWalletClient extends BaseWallet {
|
|
|
30
30
|
}>;
|
|
31
31
|
reconnect(): Promise<null>;
|
|
32
32
|
disconnect(): Promise<void>;
|
|
33
|
-
signTransactions(connectedAccounts: string[], transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
33
|
+
signTransactions(connectedAccounts: string[], transactions: Uint8Array[], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
34
34
|
/** @deprecated */
|
|
35
35
|
signEncodedTransactions(transactions: TransactionsArray): Promise<Uint8Array[]>;
|
|
36
36
|
}
|
|
@@ -26,7 +26,7 @@ declare class PeraWalletClient extends BaseWallet {
|
|
|
26
26
|
isWalletConnect: boolean;
|
|
27
27
|
} | null>;
|
|
28
28
|
disconnect(): Promise<void>;
|
|
29
|
-
signTransactions(connectedAccounts: string[], transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
29
|
+
signTransactions(connectedAccounts: string[], transactions: Uint8Array[], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
30
30
|
/** @deprecated */
|
|
31
31
|
formatTransactionsArray(transactions: TransactionsArray): PeraTransaction[];
|
|
32
32
|
/** @deprecated */
|
|
@@ -27,7 +27,7 @@ declare class WalletConnectClient extends BaseWallet {
|
|
|
27
27
|
} | null>;
|
|
28
28
|
check(): boolean;
|
|
29
29
|
disconnect(): Promise<void>;
|
|
30
|
-
signTransactions(connectedAccounts: string[], transactions: Uint8Array[]): Promise<Uint8Array[]>;
|
|
30
|
+
signTransactions(connectedAccounts: string[], transactions: Uint8Array[], indexesToSign?: number[], returnGroup?: boolean): Promise<Uint8Array[]>;
|
|
31
31
|
/** @deprecarted */
|
|
32
32
|
formatTransactionsArray(transactions: TransactionsArray): WalletConnectTransaction[];
|
|
33
33
|
/** @deprecated */
|
|
@@ -17,7 +17,7 @@ export default function useWallet(): {
|
|
|
17
17
|
activeAccount: import("../types").Account | null;
|
|
18
18
|
activeAddress: string | undefined;
|
|
19
19
|
signer: algosdk.TransactionSigner;
|
|
20
|
-
signTransactions: (transactions: Array<Uint8Array
|
|
20
|
+
signTransactions: (transactions: Array<Uint8Array>, indexesToSign?: number[], returnGroup?: boolean) => Promise<Uint8Array[]>;
|
|
21
21
|
sendTransactions: (transactions: Uint8Array[], waitRoundsToConfirm?: number) => Promise<{
|
|
22
22
|
"confirmed-round": number;
|
|
23
23
|
"global-state-delta": Record<string, unknown>[];
|
package/dist/cjs/index.js
CHANGED
|
@@ -1133,7 +1133,6 @@ class PeraWalletClient extends BaseClient {
|
|
|
1133
1133
|
}
|
|
1134
1134
|
async reconnect(onDisconnect) {
|
|
1135
1135
|
const accounts = await this.#client.reconnectSession().catch(console.info);
|
|
1136
|
-
console.log("accounts?", accounts);
|
|
1137
1136
|
this.#client.connector?.on("disconnect", onDisconnect);
|
|
1138
1137
|
if (!accounts) {
|
|
1139
1138
|
onDisconnect();
|
|
@@ -1151,37 +1150,56 @@ class PeraWalletClient extends BaseClient {
|
|
|
1151
1150
|
async disconnect() {
|
|
1152
1151
|
await this.#client.disconnect();
|
|
1153
1152
|
}
|
|
1154
|
-
async signTransactions(connectedAccounts, transactions) {
|
|
1153
|
+
async signTransactions(connectedAccounts, transactions, indexesToSign, returnGroup = true) {
|
|
1155
1154
|
// Decode the transactions to access their properties.
|
|
1156
1155
|
const decodedTxns = transactions.map((txn) => {
|
|
1157
1156
|
return this.algosdk.decodeObj(txn);
|
|
1158
1157
|
});
|
|
1158
|
+
const signedIndexes = [];
|
|
1159
1159
|
// Marshal the transactions,
|
|
1160
1160
|
// and add the signers property if they shouldn't be signed.
|
|
1161
1161
|
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
1162
|
-
|
|
1162
|
+
const isSigned = "txn" in txn;
|
|
1163
|
+
// If the indexes to be signed is specified, designate that it should be signed
|
|
1164
|
+
if (indexesToSign && indexesToSign.length && indexesToSign.includes(i)) {
|
|
1165
|
+
signedIndexes.push(i);
|
|
1166
|
+
acc.push({
|
|
1167
|
+
txn: this.algosdk.decodeUnsignedTransaction(transactions[i]),
|
|
1168
|
+
});
|
|
1169
|
+
// If the transaction is unsigned and is to be sent from a connected account,
|
|
1170
|
+
// designate that it should be signed
|
|
1171
|
+
}
|
|
1172
|
+
else if (!isSigned &&
|
|
1163
1173
|
connectedAccounts.includes(this.algosdk.encodeAddress(txn["snd"]))) {
|
|
1174
|
+
signedIndexes.push(i);
|
|
1164
1175
|
acc.push({
|
|
1165
1176
|
txn: this.algosdk.decodeUnsignedTransaction(transactions[i]),
|
|
1166
1177
|
});
|
|
1178
|
+
// Otherwise, designate that it should not be signed
|
|
1167
1179
|
}
|
|
1168
|
-
else {
|
|
1180
|
+
else if (isSigned) {
|
|
1169
1181
|
acc.push({
|
|
1170
1182
|
txn: this.algosdk.decodeSignedTransaction(transactions[i]).txn,
|
|
1171
1183
|
signers: [],
|
|
1172
1184
|
});
|
|
1173
1185
|
}
|
|
1186
|
+
else if (!isSigned) {
|
|
1187
|
+
acc.push({
|
|
1188
|
+
txn: this.algosdk.decodeUnsignedTransaction(transactions[i]),
|
|
1189
|
+
signers: [],
|
|
1190
|
+
});
|
|
1191
|
+
}
|
|
1174
1192
|
return acc;
|
|
1175
1193
|
}, []);
|
|
1176
1194
|
// Sign them with the client.
|
|
1177
1195
|
const result = await this.#client.signTransaction([txnsToSign]);
|
|
1178
1196
|
// Join the newly signed transactions with the original group of transactions.
|
|
1179
|
-
const signedTxns =
|
|
1180
|
-
if (
|
|
1197
|
+
const signedTxns = transactions.reduce((acc, txn, i) => {
|
|
1198
|
+
if (signedIndexes.includes(i)) {
|
|
1181
1199
|
const signedByUser = result.shift();
|
|
1182
1200
|
signedByUser && acc.push(signedByUser);
|
|
1183
1201
|
}
|
|
1184
|
-
else {
|
|
1202
|
+
else if (returnGroup) {
|
|
1185
1203
|
acc.push(transactions[i]);
|
|
1186
1204
|
}
|
|
1187
1205
|
return acc;
|
|
@@ -1290,31 +1308,38 @@ class MyAlgoWalletClient extends BaseClient {
|
|
|
1290
1308
|
async disconnect() {
|
|
1291
1309
|
return;
|
|
1292
1310
|
}
|
|
1293
|
-
async signTransactions(connectedAccounts, transactions) {
|
|
1311
|
+
async signTransactions(connectedAccounts, transactions, indexesToSign, returnGroup = true) {
|
|
1294
1312
|
// Decode the transactions to access their properties.
|
|
1295
1313
|
const decodedTxns = transactions.map((txn) => {
|
|
1296
1314
|
return this.algosdk.decodeObj(txn);
|
|
1297
1315
|
});
|
|
1298
|
-
|
|
1316
|
+
const signedIndexes = [];
|
|
1317
|
+
// Get the transactions to be signed
|
|
1299
1318
|
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
1300
|
-
|
|
1301
|
-
// add it to the
|
|
1302
|
-
if (
|
|
1319
|
+
const isSigned = "txn" in txn;
|
|
1320
|
+
// If the indexes to be signed is specified, add it to the transactions to be signed,
|
|
1321
|
+
if (indexesToSign && indexesToSign.length && indexesToSign?.includes(i)) {
|
|
1322
|
+
signedIndexes.push(i);
|
|
1323
|
+
acc.push(transactions[i]);
|
|
1324
|
+
// Otherwise, if the transaction is unsigned and is to be sent from a connected account,
|
|
1325
|
+
// add it to the transactions to be signed
|
|
1326
|
+
}
|
|
1327
|
+
else if (!isSigned &&
|
|
1303
1328
|
connectedAccounts.includes(this.algosdk.encodeAddress(txn["snd"]))) {
|
|
1329
|
+
signedIndexes.push(i);
|
|
1304
1330
|
acc.push(transactions[i]);
|
|
1305
1331
|
}
|
|
1306
1332
|
return acc;
|
|
1307
1333
|
}, []);
|
|
1308
1334
|
// Sign them with the client.
|
|
1309
1335
|
const result = await this.#client.signTransaction(txnsToSign);
|
|
1310
|
-
|
|
1311
|
-
|
|
1312
|
-
if (!("txn" in txn)) {
|
|
1336
|
+
const signedTxns = transactions.reduce((acc, txn, i) => {
|
|
1337
|
+
if (signedIndexes.includes(i)) {
|
|
1313
1338
|
const signedByUser = result.shift()?.blob;
|
|
1314
1339
|
signedByUser && acc.push(signedByUser);
|
|
1315
1340
|
}
|
|
1316
|
-
else {
|
|
1317
|
-
acc.push(
|
|
1341
|
+
else if (returnGroup) {
|
|
1342
|
+
acc.push(txn);
|
|
1318
1343
|
}
|
|
1319
1344
|
return acc;
|
|
1320
1345
|
}, []);
|
|
@@ -1421,37 +1446,57 @@ class DeflyWalletClient extends BaseClient {
|
|
|
1421
1446
|
async disconnect() {
|
|
1422
1447
|
await this.#client.disconnect();
|
|
1423
1448
|
}
|
|
1424
|
-
async signTransactions(connectedAccounts, transactions) {
|
|
1449
|
+
async signTransactions(connectedAccounts, transactions, indexesToSign, returnGroup = true) {
|
|
1425
1450
|
// Decode the transactions to access their properties.
|
|
1426
1451
|
const decodedTxns = transactions.map((txn) => {
|
|
1427
1452
|
return this.algosdk.decodeObj(txn);
|
|
1428
1453
|
});
|
|
1454
|
+
const signedIndexes = [];
|
|
1429
1455
|
// Marshal the transactions,
|
|
1430
1456
|
// and add the signers property if they shouldn't be signed.
|
|
1431
1457
|
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
1432
|
-
|
|
1458
|
+
const isSigned = "txn" in txn;
|
|
1459
|
+
// If the indexes to be signed is specified, designate that it should be signed
|
|
1460
|
+
if (indexesToSign && indexesToSign.length && indexesToSign.includes(i)) {
|
|
1461
|
+
signedIndexes.push(i);
|
|
1462
|
+
acc.push({
|
|
1463
|
+
txn: this.algosdk.decodeUnsignedTransaction(transactions[i]),
|
|
1464
|
+
});
|
|
1465
|
+
// If the transaction is unsigned and is to be sent from a connected account,
|
|
1466
|
+
// designate that it should be signed
|
|
1467
|
+
}
|
|
1468
|
+
else if (!isSigned &&
|
|
1433
1469
|
connectedAccounts.includes(this.algosdk.encodeAddress(txn["snd"]))) {
|
|
1470
|
+
signedIndexes.push(i);
|
|
1434
1471
|
acc.push({
|
|
1435
1472
|
txn: this.algosdk.decodeUnsignedTransaction(transactions[i]),
|
|
1436
1473
|
});
|
|
1474
|
+
// Otherwise, designate that it should not be signed
|
|
1437
1475
|
}
|
|
1438
|
-
else {
|
|
1476
|
+
else if (isSigned) {
|
|
1439
1477
|
acc.push({
|
|
1440
1478
|
txn: this.algosdk.decodeSignedTransaction(transactions[i]).txn,
|
|
1441
1479
|
signers: [],
|
|
1442
1480
|
});
|
|
1443
1481
|
}
|
|
1482
|
+
else if (!isSigned) {
|
|
1483
|
+
acc.push({
|
|
1484
|
+
txn: this.algosdk.decodeUnsignedTransaction(transactions[i]),
|
|
1485
|
+
signers: [],
|
|
1486
|
+
});
|
|
1487
|
+
}
|
|
1444
1488
|
return acc;
|
|
1445
1489
|
}, []);
|
|
1446
1490
|
// Sign them with the client.
|
|
1447
1491
|
const result = await this.#client.signTransaction([txnsToSign]);
|
|
1448
|
-
// Join the newly signed transactions with the original group of transactions
|
|
1449
|
-
|
|
1450
|
-
|
|
1492
|
+
// Join the newly signed transactions with the original group of transactions
|
|
1493
|
+
// if 'returnGroup' param is specified
|
|
1494
|
+
const signedTxns = transactions.reduce((acc, txn, i) => {
|
|
1495
|
+
if (signedIndexes.includes(i)) {
|
|
1451
1496
|
const signedByUser = result.shift();
|
|
1452
1497
|
signedByUser && acc.push(signedByUser);
|
|
1453
1498
|
}
|
|
1454
|
-
else {
|
|
1499
|
+
else if (returnGroup) {
|
|
1455
1500
|
acc.push(transactions[i]);
|
|
1456
1501
|
}
|
|
1457
1502
|
return acc;
|
|
@@ -1571,17 +1616,26 @@ class ExodusClient extends BaseClient {
|
|
|
1571
1616
|
async disconnect() {
|
|
1572
1617
|
return;
|
|
1573
1618
|
}
|
|
1574
|
-
async signTransactions(connectedAccounts, transactions) {
|
|
1619
|
+
async signTransactions(connectedAccounts, transactions, indexesToSign, returnGroup = true) {
|
|
1575
1620
|
// Decode the transactions to access their properties.
|
|
1576
1621
|
const decodedTxns = transactions.map((txn) => {
|
|
1577
1622
|
return this.algosdk.decodeObj(txn);
|
|
1578
1623
|
});
|
|
1624
|
+
const signedIndexes = [];
|
|
1579
1625
|
// Get the unsigned transactions.
|
|
1580
1626
|
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
1581
|
-
|
|
1627
|
+
const isSigned = "txn" in txn;
|
|
1628
|
+
// If the indexes to be signed is specified
|
|
1582
1629
|
// add it to the arrays of transactions to be signed.
|
|
1583
|
-
if (
|
|
1630
|
+
if (indexesToSign && indexesToSign.length && indexesToSign.includes(i)) {
|
|
1631
|
+
signedIndexes.push(i);
|
|
1632
|
+
acc.push(transactions[i]);
|
|
1633
|
+
// If the transaction isn't already signed and is to be sent from a connected account,
|
|
1634
|
+
// add it to the arrays of transactions to be signed
|
|
1635
|
+
}
|
|
1636
|
+
else if (!isSigned &&
|
|
1584
1637
|
connectedAccounts.includes(this.algosdk.encodeAddress(txn["snd"]))) {
|
|
1638
|
+
signedIndexes.push(i);
|
|
1585
1639
|
acc.push(transactions[i]);
|
|
1586
1640
|
}
|
|
1587
1641
|
return acc;
|
|
@@ -1589,12 +1643,12 @@ class ExodusClient extends BaseClient {
|
|
|
1589
1643
|
// Sign them with the client.
|
|
1590
1644
|
const result = await this.#client.signTransaction(txnsToSign);
|
|
1591
1645
|
// Join the newly signed transactions with the original group of transactions.
|
|
1592
|
-
const signedTxns =
|
|
1593
|
-
if (
|
|
1646
|
+
const signedTxns = transactions.reduce((acc, txn, i) => {
|
|
1647
|
+
if (signedIndexes.includes(i)) {
|
|
1594
1648
|
const signedByUser = result.shift();
|
|
1595
1649
|
signedByUser && acc.push(signedByUser);
|
|
1596
1650
|
}
|
|
1597
|
-
else {
|
|
1651
|
+
else if (returnGroup) {
|
|
1598
1652
|
acc.push(transactions[i]);
|
|
1599
1653
|
}
|
|
1600
1654
|
return acc;
|
|
@@ -1709,7 +1763,7 @@ class AlgoSignerClient extends BaseClient {
|
|
|
1709
1763
|
async disconnect() {
|
|
1710
1764
|
return;
|
|
1711
1765
|
}
|
|
1712
|
-
async signTransactions(connectedAccounts, transactions) {
|
|
1766
|
+
async signTransactions(connectedAccounts, transactions, indexesToSign, returnGroup = true) {
|
|
1713
1767
|
// Decode the transactions to access their properties.
|
|
1714
1768
|
const decodedTxns = transactions.map((txn) => {
|
|
1715
1769
|
return this.algosdk.decodeObj(txn);
|
|
@@ -1717,12 +1771,26 @@ class AlgoSignerClient extends BaseClient {
|
|
|
1717
1771
|
// Marshal the transactions,
|
|
1718
1772
|
// and add the signers property if they shouldn't be signed.
|
|
1719
1773
|
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
1774
|
+
const isSigned = "txn" in txn;
|
|
1720
1775
|
const txnObj = {
|
|
1721
1776
|
txn: this.#client.encoding.msgpackToBase64(transactions[i]),
|
|
1722
1777
|
};
|
|
1723
|
-
if (
|
|
1724
|
-
|
|
1725
|
-
|
|
1778
|
+
if (indexesToSign &&
|
|
1779
|
+
indexesToSign.length &&
|
|
1780
|
+
!indexesToSign.includes(i)) {
|
|
1781
|
+
txnObj.txn = this.#client.encoding.msgpackToBase64(isSigned
|
|
1782
|
+
? this.algosdk
|
|
1783
|
+
.decodeSignedTransaction(transactions[i])
|
|
1784
|
+
.txn.toByte()
|
|
1785
|
+
: this.algosdk.decodeUnsignedTransaction(transactions[i]).toByte());
|
|
1786
|
+
txnObj.signers = [];
|
|
1787
|
+
}
|
|
1788
|
+
else if (!connectedAccounts.includes(this.algosdk.encodeAddress(isSigned ? txn.txn["snd"] : txn["snd"]))) {
|
|
1789
|
+
txnObj.txn = this.#client.encoding.msgpackToBase64(isSigned
|
|
1790
|
+
? this.algosdk
|
|
1791
|
+
.decodeSignedTransaction(transactions[i])
|
|
1792
|
+
.txn.toByte()
|
|
1793
|
+
: this.algosdk.decodeUnsignedTransaction(transactions[i]).toByte());
|
|
1726
1794
|
txnObj.signers = [];
|
|
1727
1795
|
}
|
|
1728
1796
|
acc.push(txnObj);
|
|
@@ -1730,12 +1798,13 @@ class AlgoSignerClient extends BaseClient {
|
|
|
1730
1798
|
}, []);
|
|
1731
1799
|
// Sign them with the client.
|
|
1732
1800
|
const result = await this.#client.signTxn(txnsToSign);
|
|
1733
|
-
// Join the newly signed transactions with the original group of transactions
|
|
1801
|
+
// Join the newly signed transactions with the original group of transactions
|
|
1802
|
+
// if 'returnGroup' param is specified
|
|
1734
1803
|
const signedTxns = result.reduce((acc, txn, i) => {
|
|
1735
1804
|
if (txn) {
|
|
1736
1805
|
acc.push(new Uint8Array(Buffer.from(txn.blob, "base64")));
|
|
1737
1806
|
}
|
|
1738
|
-
else {
|
|
1807
|
+
else if (returnGroup) {
|
|
1739
1808
|
acc.push(transactions[i]);
|
|
1740
1809
|
}
|
|
1741
1810
|
return acc;
|
|
@@ -1808,8 +1877,8 @@ class WalletConnectClient extends BaseClient {
|
|
|
1808
1877
|
const walletConnect = new WalletConnect({
|
|
1809
1878
|
bridge: "https://bridge.walletconnect.org",
|
|
1810
1879
|
qrcodeModal: QRCodeModal,
|
|
1811
|
-
storageId:
|
|
1812
|
-
...(clientOptions || {})
|
|
1880
|
+
storageId: "walletconnect-generic",
|
|
1881
|
+
...(clientOptions || {}),
|
|
1813
1882
|
});
|
|
1814
1883
|
const algosdk = algosdkStatic || (await Algod.init(algodOptions)).algosdk;
|
|
1815
1884
|
const algodClient = await getAlgodClient(algosdk, algodOptions);
|
|
@@ -1894,7 +1963,7 @@ class WalletConnectClient extends BaseClient {
|
|
|
1894
1963
|
console.error("Error disconnecting", e);
|
|
1895
1964
|
}
|
|
1896
1965
|
}
|
|
1897
|
-
async signTransactions(connectedAccounts, transactions) {
|
|
1966
|
+
async signTransactions(connectedAccounts, transactions, indexesToSign, returnGroup = true) {
|
|
1898
1967
|
// Decode the transactions to access their properties.
|
|
1899
1968
|
const decodedTxns = transactions.map((txn) => {
|
|
1900
1969
|
return this.algosdk.decodeObj(txn);
|
|
@@ -1902,7 +1971,15 @@ class WalletConnectClient extends BaseClient {
|
|
|
1902
1971
|
// Marshal the transactions,
|
|
1903
1972
|
// and add the signers property if they shouldn't be signed.
|
|
1904
1973
|
const txnsToSign = decodedTxns.reduce((acc, txn, i) => {
|
|
1905
|
-
|
|
1974
|
+
const isSigned = "txn" in txn;
|
|
1975
|
+
if (indexesToSign &&
|
|
1976
|
+
indexesToSign.length &&
|
|
1977
|
+
indexesToSign.includes(i)) {
|
|
1978
|
+
acc.push({
|
|
1979
|
+
txn: Buffer.from(transactions[i]).toString("base64"),
|
|
1980
|
+
});
|
|
1981
|
+
}
|
|
1982
|
+
else if (!isSigned &&
|
|
1906
1983
|
connectedAccounts.includes(this.algosdk.encodeAddress(txn["snd"]))) {
|
|
1907
1984
|
acc.push({
|
|
1908
1985
|
txn: Buffer.from(transactions[i]).toString("base64"),
|
|
@@ -1910,7 +1987,9 @@ class WalletConnectClient extends BaseClient {
|
|
|
1910
1987
|
}
|
|
1911
1988
|
else {
|
|
1912
1989
|
acc.push({
|
|
1913
|
-
txn:
|
|
1990
|
+
txn: isSigned
|
|
1991
|
+
? Buffer.from(this.algosdk.encodeUnsignedTransaction(this.algosdk.decodeSignedTransaction(transactions[i]).txn)).toString("base64")
|
|
1992
|
+
: Buffer.from(transactions[i]).toString("base64"),
|
|
1914
1993
|
signers: [],
|
|
1915
1994
|
});
|
|
1916
1995
|
}
|
|
@@ -1929,7 +2008,7 @@ class WalletConnectClient extends BaseClient {
|
|
|
1929
2008
|
if (txn) {
|
|
1930
2009
|
signedTxns.push(new Uint8Array(Buffer.from(txn, "base64")));
|
|
1931
2010
|
}
|
|
1932
|
-
if (
|
|
2011
|
+
if (returnGroup) {
|
|
1933
2012
|
signedTxns.push(transactions[i]);
|
|
1934
2013
|
}
|
|
1935
2014
|
return signedTxns;
|
|
@@ -2075,7 +2154,7 @@ class KMDWalletClient extends BaseClient {
|
|
|
2075
2154
|
this.releaseToken(token);
|
|
2076
2155
|
return mappedAccounts;
|
|
2077
2156
|
}
|
|
2078
|
-
async signTransactions(connectedAccounts, transactions) {
|
|
2157
|
+
async signTransactions(connectedAccounts, transactions, indexesToSign, returnGroup = true) {
|
|
2079
2158
|
// Decode the transactions to access their properties.
|
|
2080
2159
|
const decodedTxns = transactions.map((txn) => {
|
|
2081
2160
|
return this.algosdk.decodeObj(txn);
|
|
@@ -2088,14 +2167,23 @@ class KMDWalletClient extends BaseClient {
|
|
|
2088
2167
|
const signingPromises = [];
|
|
2089
2168
|
for (const idx in decodedTxns) {
|
|
2090
2169
|
const dtxn = decodedTxns[idx];
|
|
2170
|
+
const isSigned = "txn" in dtxn;
|
|
2091
2171
|
// push the incoming txn into signed, we'll overwrite it later
|
|
2092
2172
|
signedTxns.push(transactions[idx]);
|
|
2093
2173
|
// Its already signed, skip it
|
|
2094
|
-
if (
|
|
2174
|
+
if (isSigned) {
|
|
2095
2175
|
continue;
|
|
2176
|
+
// Not specified in indexes to sign, skip it
|
|
2177
|
+
}
|
|
2178
|
+
else if (indexesToSign &&
|
|
2179
|
+
indexesToSign.length &&
|
|
2180
|
+
!indexesToSign.includes(Number(idx))) {
|
|
2181
|
+
continue;
|
|
2182
|
+
}
|
|
2096
2183
|
// Not to be signed by our signer, skip it
|
|
2097
|
-
if (!connectedAccounts.includes(this.algosdk.encodeAddress(dtxn.snd)))
|
|
2184
|
+
else if (!connectedAccounts.includes(this.algosdk.encodeAddress(dtxn.snd))) {
|
|
2098
2185
|
continue;
|
|
2186
|
+
}
|
|
2099
2187
|
// overwrite with an empty blob
|
|
2100
2188
|
signedTxns[idx] = new Uint8Array();
|
|
2101
2189
|
const txn = this.algosdk.Transaction.from_obj_for_encoding(dtxn);
|
|
@@ -2104,15 +2192,19 @@ class KMDWalletClient extends BaseClient {
|
|
|
2104
2192
|
const signingResults = await Promise.all(signingPromises);
|
|
2105
2193
|
// Restore the newly signed txns in the correct order
|
|
2106
2194
|
let signedIdx = 0;
|
|
2107
|
-
|
|
2195
|
+
const formattedTxns = signedTxns.reduce((acc, txn, i) => {
|
|
2108
2196
|
// If its an empty array, infer that it is one of the
|
|
2109
2197
|
// ones we wanted to have signed and overwrite the empty buff
|
|
2110
|
-
if (
|
|
2111
|
-
|
|
2198
|
+
if (txn.length === 0) {
|
|
2199
|
+
acc.push(signingResults[signedIdx]);
|
|
2112
2200
|
signedIdx += 1;
|
|
2113
2201
|
}
|
|
2114
|
-
|
|
2115
|
-
|
|
2202
|
+
else if (returnGroup) {
|
|
2203
|
+
acc.push(txn);
|
|
2204
|
+
}
|
|
2205
|
+
return acc;
|
|
2206
|
+
}, []);
|
|
2207
|
+
return formattedTxns;
|
|
2116
2208
|
}
|
|
2117
2209
|
signEncodedTransactions(transactions) {
|
|
2118
2210
|
throw new Error("Method not implemented.");
|
|
@@ -2251,12 +2343,12 @@ function useWallet() {
|
|
|
2251
2343
|
console.error(e);
|
|
2252
2344
|
}
|
|
2253
2345
|
};
|
|
2254
|
-
const signTransactions = async (transactions) => {
|
|
2346
|
+
const signTransactions = async (transactions, indexesToSign, returnGroup = true) => {
|
|
2255
2347
|
const walletClient = await getClient(activeAccount?.providerId);
|
|
2256
2348
|
if (!walletClient || !activeAccount?.address) {
|
|
2257
2349
|
throw new Error("No wallet found.");
|
|
2258
2350
|
}
|
|
2259
|
-
const signedTransactions = await walletClient.signTransactions(connectedActiveAccounts.map((acct) => acct.address), transactions);
|
|
2351
|
+
const signedTransactions = await walletClient.signTransactions(connectedActiveAccounts.map((acct) => acct.address), transactions, indexesToSign, returnGroup);
|
|
2260
2352
|
return signedTransactions;
|
|
2261
2353
|
};
|
|
2262
2354
|
const sendTransactions = async (transactions, waitRoundsToConfirm) => {
|
|
@@ -2267,8 +2359,7 @@ function useWallet() {
|
|
|
2267
2359
|
const signer = async (txnGroup, indexesToSign) => {
|
|
2268
2360
|
const algosdk = await getAlgosdk();
|
|
2269
2361
|
const txnBlobs = txnGroup.map(algosdk.encodeUnsignedTransaction);
|
|
2270
|
-
|
|
2271
|
-
return txns.filter((_, index) => indexesToSign.includes(index));
|
|
2362
|
+
return await Promise.resolve(signTransactions(txnBlobs, indexesToSign, false));
|
|
2272
2363
|
};
|
|
2273
2364
|
const getAccountInfo = async () => {
|
|
2274
2365
|
if (!activeAccount)
|