@meshsdk/wallet 1.8.14 → 1.9.0-beta-39
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 +95 -67
- package/dist/index.d.cts +43 -27
- package/dist/index.d.ts +43 -27
- package/dist/index.js +101 -70
- package/package.json +4 -5
package/dist/index.js
CHANGED
|
@@ -564,13 +564,14 @@ import {
|
|
|
564
564
|
buildEnterpriseAddress,
|
|
565
565
|
buildKeys,
|
|
566
566
|
buildRewardAddress,
|
|
567
|
+
Crypto,
|
|
567
568
|
deserializeTx,
|
|
568
569
|
deserializeTxHash,
|
|
569
570
|
DRep,
|
|
570
|
-
Ed25519KeyHashHex,
|
|
571
571
|
Ed25519PublicKeyHex,
|
|
572
|
-
Ed25519SignatureHex,
|
|
573
572
|
Hash28ByteBase16,
|
|
573
|
+
HexBlob,
|
|
574
|
+
hexToBech32,
|
|
574
575
|
resolveTxHash,
|
|
575
576
|
Serialization,
|
|
576
577
|
signData,
|
|
@@ -578,23 +579,23 @@ import {
|
|
|
578
579
|
VkeyWitness
|
|
579
580
|
} from "@meshsdk/core-cst";
|
|
580
581
|
var WalletStaticMethods = class {
|
|
581
|
-
static
|
|
582
|
+
static privateKeyBech32ToPrivateKeyHex(_bech32) {
|
|
582
583
|
const bech32DecodedBytes = bech32.decodeToBytes(_bech32).bytes;
|
|
583
584
|
const bip32PrivateKey = Bip32PrivateKey.fromBytes(bech32DecodedBytes);
|
|
584
585
|
return bytesToHex(bip32PrivateKey.bytes());
|
|
585
586
|
}
|
|
586
|
-
static
|
|
587
|
+
static mnemonicToPrivateKeyHex(words) {
|
|
587
588
|
const entropy = mnemonicToEntropy(words.join(" "));
|
|
588
589
|
const bip32PrivateKey = buildBip32PrivateKey(entropy);
|
|
589
590
|
return bytesToHex(bip32PrivateKey.bytes());
|
|
590
591
|
}
|
|
591
|
-
static
|
|
592
|
+
static signingKeyToHexes(paymentKey, stakeKey) {
|
|
592
593
|
return [
|
|
593
594
|
paymentKey.startsWith("5820") ? paymentKey.slice(4) : paymentKey,
|
|
594
595
|
stakeKey.startsWith("5820") ? stakeKey.slice(4) : stakeKey
|
|
595
596
|
];
|
|
596
597
|
}
|
|
597
|
-
static
|
|
598
|
+
static bip32BytesToPrivateKeyHex(bip32Bytes) {
|
|
598
599
|
const bip32PrivateKey = Bip32PrivateKey.fromBytes(bip32Bytes);
|
|
599
600
|
return bytesToHex(bip32PrivateKey.bytes());
|
|
600
601
|
}
|
|
@@ -602,22 +603,22 @@ var WalletStaticMethods = class {
|
|
|
602
603
|
const baseAddress = buildBaseAddress(
|
|
603
604
|
networkId,
|
|
604
605
|
Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
605
|
-
|
|
606
|
+
paymentKey.toPublic().hash().hex()
|
|
606
607
|
),
|
|
607
608
|
Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
608
|
-
|
|
609
|
+
stakingKey.toPublic().hash().hex()
|
|
609
610
|
)
|
|
610
611
|
).toAddress();
|
|
611
612
|
const enterpriseAddress = buildEnterpriseAddress(
|
|
612
613
|
networkId,
|
|
613
614
|
Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
614
|
-
|
|
615
|
+
paymentKey.toPublic().hash().hex()
|
|
615
616
|
)
|
|
616
617
|
).toAddress();
|
|
617
618
|
const rewardAddress = buildRewardAddress(
|
|
618
619
|
networkId,
|
|
619
620
|
Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
620
|
-
|
|
621
|
+
stakingKey.toPublic().hash().hex()
|
|
621
622
|
)
|
|
622
623
|
).toAddress();
|
|
623
624
|
return {
|
|
@@ -627,20 +628,19 @@ var WalletStaticMethods = class {
|
|
|
627
628
|
};
|
|
628
629
|
}
|
|
629
630
|
static getDRepKey(dRepKey, networkId = 0) {
|
|
630
|
-
const
|
|
631
|
-
const pubDRepKey = pubKey.toString("hex");
|
|
631
|
+
const pubDRepKey = dRepKey.toPublic().hex().toString();
|
|
632
632
|
const dRepIDBech32 = buildDRepID(
|
|
633
633
|
Ed25519PublicKeyHex(pubDRepKey),
|
|
634
634
|
networkId
|
|
635
635
|
);
|
|
636
|
-
const dRep = DRep.newKeyHash(
|
|
637
|
-
Ed25519KeyHashHex(dRepKey.toPublicKey().hash().toString("hex"))
|
|
638
|
-
);
|
|
636
|
+
const dRep = DRep.newKeyHash(dRepKey.toPublic().hash().hex());
|
|
639
637
|
const dRepIDHash = dRep.toKeyHash();
|
|
638
|
+
const dRepIDCip105 = hexToBech32("drep", dRepIDHash);
|
|
640
639
|
return {
|
|
641
640
|
pubDRepKey,
|
|
642
641
|
dRepIDBech32,
|
|
643
|
-
dRepIDHash
|
|
642
|
+
dRepIDHash,
|
|
643
|
+
dRepIDCip105
|
|
644
644
|
};
|
|
645
645
|
}
|
|
646
646
|
static generateMnemonic(strength = 256) {
|
|
@@ -662,40 +662,45 @@ var WalletStaticMethods = class {
|
|
|
662
662
|
}
|
|
663
663
|
};
|
|
664
664
|
var EmbeddedWallet = class extends WalletStaticMethods {
|
|
665
|
-
|
|
665
|
+
_walletSecret;
|
|
666
666
|
_networkId;
|
|
667
|
+
cryptoIsReady = false;
|
|
667
668
|
constructor(options) {
|
|
668
669
|
super();
|
|
669
670
|
this._networkId = options.networkId;
|
|
670
671
|
switch (options.key.type) {
|
|
671
672
|
case "mnemonic":
|
|
672
|
-
this.
|
|
673
|
+
this._walletSecret = WalletStaticMethods.mnemonicToPrivateKeyHex(
|
|
673
674
|
options.key.words
|
|
674
675
|
);
|
|
675
676
|
break;
|
|
676
677
|
case "root":
|
|
677
|
-
this.
|
|
678
|
+
this._walletSecret = WalletStaticMethods.privateKeyBech32ToPrivateKeyHex(
|
|
678
679
|
options.key.bech32
|
|
679
680
|
);
|
|
680
681
|
break;
|
|
681
682
|
case "cli":
|
|
682
|
-
this.
|
|
683
|
+
this._walletSecret = WalletStaticMethods.signingKeyToHexes(
|
|
683
684
|
options.key.payment,
|
|
684
685
|
options.key.stake ?? "f0".repeat(32)
|
|
685
686
|
);
|
|
686
687
|
break;
|
|
687
688
|
case "bip32Bytes":
|
|
688
|
-
this.
|
|
689
|
+
this._walletSecret = WalletStaticMethods.bip32BytesToPrivateKeyHex(
|
|
689
690
|
options.key.bip32Bytes
|
|
690
691
|
);
|
|
691
692
|
break;
|
|
692
693
|
}
|
|
693
694
|
}
|
|
695
|
+
async init() {
|
|
696
|
+
await Crypto.ready();
|
|
697
|
+
this.cryptoIsReady = true;
|
|
698
|
+
}
|
|
694
699
|
getAccount(accountIndex = 0, keyIndex = 0) {
|
|
695
|
-
if (this.
|
|
700
|
+
if (this._walletSecret == void 0)
|
|
696
701
|
throw new Error("[EmbeddedWallet] No keys initialized");
|
|
697
702
|
const { paymentKey, stakeKey, dRepKey } = buildKeys(
|
|
698
|
-
this.
|
|
703
|
+
this._walletSecret,
|
|
699
704
|
accountIndex,
|
|
700
705
|
keyIndex
|
|
701
706
|
);
|
|
@@ -709,14 +714,15 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
709
714
|
rewardAddressBech32: rewardAddress.toBech32(),
|
|
710
715
|
paymentKey,
|
|
711
716
|
stakeKey,
|
|
712
|
-
paymentKeyHex: paymentKey.
|
|
713
|
-
stakeKeyHex: stakeKey.
|
|
717
|
+
paymentKeyHex: paymentKey.hex(),
|
|
718
|
+
stakeKeyHex: stakeKey.hex()
|
|
714
719
|
};
|
|
715
720
|
if (dRepKey) {
|
|
716
|
-
const { pubDRepKey, dRepIDBech32, dRepIDHash } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
|
|
721
|
+
const { pubDRepKey, dRepIDBech32, dRepIDHash, dRepIDCip105 } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
|
|
717
722
|
_account.pubDRepKey = pubDRepKey;
|
|
718
723
|
_account.dRepIDBech32 = dRepIDBech32;
|
|
719
724
|
_account.dRepIDHash = dRepIDHash;
|
|
725
|
+
_account.dRepIDCip105 = dRepIDCip105;
|
|
720
726
|
}
|
|
721
727
|
return _account;
|
|
722
728
|
}
|
|
@@ -769,10 +775,8 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
769
775
|
const txHash = deserializeTxHash(resolveTxHash(unsignedTx));
|
|
770
776
|
const { paymentKey } = this.getAccount(accountIndex, keyIndex);
|
|
771
777
|
const vKeyWitness = new VkeyWitness(
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
paymentKey.sign(Buffer.from(txHash, "hex")).toString("hex")
|
|
775
|
-
)
|
|
778
|
+
paymentKey.toPublic().hex(),
|
|
779
|
+
paymentKey.sign(HexBlob(txHash)).hex()
|
|
776
780
|
);
|
|
777
781
|
return vKeyWitness;
|
|
778
782
|
} catch (error) {
|
|
@@ -821,6 +825,15 @@ var AppWallet = class {
|
|
|
821
825
|
});
|
|
822
826
|
}
|
|
823
827
|
}
|
|
828
|
+
/**
|
|
829
|
+
* Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
|
|
830
|
+
* @returns void
|
|
831
|
+
*/
|
|
832
|
+
async init() {
|
|
833
|
+
if (this._wallet) {
|
|
834
|
+
await this._wallet.init();
|
|
835
|
+
}
|
|
836
|
+
}
|
|
824
837
|
/**
|
|
825
838
|
* Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
|
|
826
839
|
*
|
|
@@ -934,7 +947,6 @@ import {
|
|
|
934
947
|
POLICY_ID_LENGTH,
|
|
935
948
|
resolveFingerprint
|
|
936
949
|
} from "@meshsdk/common";
|
|
937
|
-
import { csl } from "@meshsdk/core-csl";
|
|
938
950
|
import {
|
|
939
951
|
addressToBech32,
|
|
940
952
|
CardanoSDKUtil,
|
|
@@ -946,6 +958,7 @@ import {
|
|
|
946
958
|
Ed25519PublicKeyHex as Ed25519PublicKeyHex2,
|
|
947
959
|
fromTxUnspentOutput,
|
|
948
960
|
fromValue,
|
|
961
|
+
hexToBech32 as hexToBech322,
|
|
949
962
|
Serialization as Serialization2,
|
|
950
963
|
toAddress as toAddress2,
|
|
951
964
|
Transaction as Transaction2,
|
|
@@ -1004,7 +1017,7 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1004
1017
|
return wallets;
|
|
1005
1018
|
}
|
|
1006
1019
|
/**
|
|
1007
|
-
* This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the
|
|
1020
|
+
* This is the entrypoint to start communication with the user's wallet. The wallet should request the user's permission to connect the web page to the user's wallet, and if permission has been granted, the wallet will be returned and exposing the full API for the app to use.
|
|
1008
1021
|
*
|
|
1009
1022
|
* Query BrowserWallet.getInstalledWallets() to get a list of available wallets, then provide the wallet name for which wallet the user would like to connect with.
|
|
1010
1023
|
*
|
|
@@ -1210,7 +1223,7 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1210
1223
|
/**
|
|
1211
1224
|
* Submits the signed transaction to the blockchain network.
|
|
1212
1225
|
*
|
|
1213
|
-
* As wallets should already have this ability to submit transaction, we allow
|
|
1226
|
+
* As wallets should already have this ability to submit transaction, we allow apps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the app to track. The wallet can return error messages or failure if there was an error in sending it.
|
|
1214
1227
|
*
|
|
1215
1228
|
* @param tx
|
|
1216
1229
|
* @returns a transaction hash
|
|
@@ -1316,19 +1329,18 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1316
1329
|
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
1317
1330
|
* These are used by the client to identify the user's on-chain CIP-1694 interactions, i.e. if a user has registered to be a DRep.
|
|
1318
1331
|
*
|
|
1319
|
-
* @returns
|
|
1332
|
+
* @returns DRep object
|
|
1320
1333
|
*/
|
|
1321
1334
|
async getDRep() {
|
|
1335
|
+
const pubDRepKey = await this.getPubDRepKey();
|
|
1322
1336
|
try {
|
|
1323
|
-
if (
|
|
1324
|
-
const
|
|
1325
|
-
const
|
|
1326
|
-
const csldRepIdKeyHash = csl.PublicKey.from_hex(dRepKey).hash();
|
|
1327
|
-
const dRepId = csldRepIdKeyHash.to_bech32("drep");
|
|
1337
|
+
if (pubDRepKey === void 0) return void 0;
|
|
1338
|
+
const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(pubDRepKey);
|
|
1339
|
+
const dRepIDCip105 = hexToBech322("drep", dRepIDHash);
|
|
1328
1340
|
return {
|
|
1329
|
-
publicKey:
|
|
1341
|
+
publicKey: pubDRepKey,
|
|
1330
1342
|
publicKeyHash: dRepIDHash,
|
|
1331
|
-
dRepIDCip105
|
|
1343
|
+
dRepIDCip105
|
|
1332
1344
|
};
|
|
1333
1345
|
} catch (e) {
|
|
1334
1346
|
console.error(e);
|
|
@@ -1344,15 +1356,8 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1344
1356
|
async getPubDRepKey() {
|
|
1345
1357
|
try {
|
|
1346
1358
|
if (this._walletInstance.cip95 === void 0) return void 0;
|
|
1347
|
-
const
|
|
1348
|
-
|
|
1349
|
-
const csldRepIdKeyHash = csl.PublicKey.from_hex(dRepKey).hash();
|
|
1350
|
-
const dRepId = csldRepIdKeyHash.to_bech32("drep");
|
|
1351
|
-
return {
|
|
1352
|
-
pubDRepKey: dRepKey,
|
|
1353
|
-
dRepIDHash,
|
|
1354
|
-
dRepIDBech32: dRepId
|
|
1355
|
-
};
|
|
1359
|
+
const pubDRepKey = await this._walletInstance.cip95.getPubDRepKey();
|
|
1360
|
+
return pubDRepKey;
|
|
1356
1361
|
} catch (e) {
|
|
1357
1362
|
console.error(e);
|
|
1358
1363
|
return void 0;
|
|
@@ -1411,8 +1416,7 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1411
1416
|
if (window.cardano[walletName] === void 0) return void 0;
|
|
1412
1417
|
const wallet = window.cardano[walletName];
|
|
1413
1418
|
if (extensions.length > 0) {
|
|
1414
|
-
|
|
1415
|
-
return wallet.enable({ extensions: _extensions });
|
|
1419
|
+
return wallet.enable({ extensions });
|
|
1416
1420
|
} else {
|
|
1417
1421
|
return wallet?.enable();
|
|
1418
1422
|
}
|
|
@@ -1446,13 +1450,13 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1446
1450
|
// src/browser/webauthn/cardano/build-wallet-from-passkey.ts
|
|
1447
1451
|
var import_base32_encoding = __toESM(require_base32_encoding(), 1);
|
|
1448
1452
|
var import_bech32 = __toESM(require_dist(), 1);
|
|
1449
|
-
import { Crypto } from "@meshsdk/core-cst";
|
|
1453
|
+
import { Crypto as Crypto2 } from "@meshsdk/core-cst";
|
|
1450
1454
|
async function buildWalletFromPasskey(rawId, password, appSalt = "appSalt") {
|
|
1451
1455
|
const entropy = await createEntropy(rawId, appSalt);
|
|
1452
1456
|
return buildKey(Buffer.from(entropy), password);
|
|
1453
1457
|
}
|
|
1454
1458
|
function buildKey(entropy, password) {
|
|
1455
|
-
const bip32Key =
|
|
1459
|
+
const bip32Key = Crypto2.Bip32PrivateKey.fromBip39Entropy(entropy, password);
|
|
1456
1460
|
const bytes = import_base32_encoding.default.encode(bip32Key.bytes());
|
|
1457
1461
|
const bech32PrivateKey = import_bech32.bech32.encode("xprv", bytes, 1023);
|
|
1458
1462
|
return {
|
|
@@ -1609,7 +1613,6 @@ import {
|
|
|
1609
1613
|
resolveFingerprint as resolveFingerprint2,
|
|
1610
1614
|
toUTF8
|
|
1611
1615
|
} from "@meshsdk/common";
|
|
1612
|
-
import { resolvePrivateKey } from "@meshsdk/core-csl";
|
|
1613
1616
|
import {
|
|
1614
1617
|
Address as Address4,
|
|
1615
1618
|
buildBaseAddress as buildBaseAddress2,
|
|
@@ -1619,11 +1622,13 @@ import {
|
|
|
1619
1622
|
Ed25519KeyHashHex as Ed25519KeyHashHex3,
|
|
1620
1623
|
fromTxUnspentOutput as fromTxUnspentOutput2,
|
|
1621
1624
|
Hash28ByteBase16 as Hash28ByteBase162,
|
|
1625
|
+
resolvePrivateKey,
|
|
1622
1626
|
toAddress as toAddress3,
|
|
1623
1627
|
toTxUnspentOutput as toTxUnspentOutput2
|
|
1624
1628
|
} from "@meshsdk/core-cst";
|
|
1625
1629
|
import { Transaction as Transaction3 } from "@meshsdk/transaction";
|
|
1626
1630
|
var MeshWallet = class {
|
|
1631
|
+
_keyType;
|
|
1627
1632
|
_wallet;
|
|
1628
1633
|
_accountIndex = 0;
|
|
1629
1634
|
_keyIndex = 0;
|
|
@@ -1633,6 +1638,7 @@ var MeshWallet = class {
|
|
|
1633
1638
|
addresses = {};
|
|
1634
1639
|
constructor(options) {
|
|
1635
1640
|
this._networkId = options.networkId;
|
|
1641
|
+
this._keyType = options.key.type;
|
|
1636
1642
|
if (options.fetcher) this._fetcher = options.fetcher;
|
|
1637
1643
|
if (options.submitter) this._submitter = options.submitter;
|
|
1638
1644
|
if (options.accountIndex) this._accountIndex = options.accountIndex;
|
|
@@ -1646,7 +1652,6 @@ var MeshWallet = class {
|
|
|
1646
1652
|
bech32: options.key.bech32
|
|
1647
1653
|
}
|
|
1648
1654
|
});
|
|
1649
|
-
this.getAddressesFromWallet(this._wallet);
|
|
1650
1655
|
break;
|
|
1651
1656
|
case "cli":
|
|
1652
1657
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1657,7 +1662,6 @@ var MeshWallet = class {
|
|
|
1657
1662
|
stake: options.key.stake
|
|
1658
1663
|
}
|
|
1659
1664
|
});
|
|
1660
|
-
this.getAddressesFromWallet(this._wallet);
|
|
1661
1665
|
break;
|
|
1662
1666
|
case "mnemonic":
|
|
1663
1667
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1667,7 +1671,6 @@ var MeshWallet = class {
|
|
|
1667
1671
|
words: options.key.words
|
|
1668
1672
|
}
|
|
1669
1673
|
});
|
|
1670
|
-
this.getAddressesFromWallet(this._wallet);
|
|
1671
1674
|
break;
|
|
1672
1675
|
case "bip32Bytes":
|
|
1673
1676
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1677,7 +1680,6 @@ var MeshWallet = class {
|
|
|
1677
1680
|
bip32Bytes: options.key.bip32Bytes
|
|
1678
1681
|
}
|
|
1679
1682
|
});
|
|
1680
|
-
this.getAddressesFromWallet(this._wallet);
|
|
1681
1683
|
break;
|
|
1682
1684
|
case "address":
|
|
1683
1685
|
this._wallet = null;
|
|
@@ -1685,6 +1687,16 @@ var MeshWallet = class {
|
|
|
1685
1687
|
break;
|
|
1686
1688
|
}
|
|
1687
1689
|
}
|
|
1690
|
+
/**
|
|
1691
|
+
* Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
|
|
1692
|
+
* @returns void
|
|
1693
|
+
*/
|
|
1694
|
+
async init() {
|
|
1695
|
+
if (this._wallet && !this._wallet.cryptoIsReady) {
|
|
1696
|
+
await this._wallet.init();
|
|
1697
|
+
this.getAddressesFromWallet(this._wallet);
|
|
1698
|
+
}
|
|
1699
|
+
}
|
|
1688
1700
|
/**
|
|
1689
1701
|
* Returns all derived addresses from the wallet.
|
|
1690
1702
|
* @returns a list of addresses
|
|
@@ -1700,6 +1712,7 @@ var MeshWallet = class {
|
|
|
1700
1712
|
* @returns a list of assets and their quantities
|
|
1701
1713
|
*/
|
|
1702
1714
|
async getBalance() {
|
|
1715
|
+
await this.init();
|
|
1703
1716
|
const utxos = await this.getUnspentOutputs();
|
|
1704
1717
|
const assets = /* @__PURE__ */ new Map();
|
|
1705
1718
|
utxos.map((utxo) => {
|
|
@@ -1726,8 +1739,12 @@ var MeshWallet = class {
|
|
|
1726
1739
|
*
|
|
1727
1740
|
* @returns an address
|
|
1728
1741
|
*/
|
|
1729
|
-
getChangeAddress() {
|
|
1730
|
-
|
|
1742
|
+
async getChangeAddress(addressType = "payment") {
|
|
1743
|
+
await this.init();
|
|
1744
|
+
if (this.addresses.baseAddressBech32 && addressType === "payment") {
|
|
1745
|
+
return this.addresses.baseAddressBech32;
|
|
1746
|
+
}
|
|
1747
|
+
return this.addresses.enterpriseAddressBech32;
|
|
1731
1748
|
}
|
|
1732
1749
|
/**
|
|
1733
1750
|
* This function shall return a list of one or more UTXOs (unspent transaction outputs) controlled by the wallet that are required to reach AT LEAST the combined ADA value target specified in amount AND the best suitable to be used as collateral inputs for transactions with plutus script inputs (pure ADA-only UTXOs).
|
|
@@ -1738,6 +1755,7 @@ var MeshWallet = class {
|
|
|
1738
1755
|
* @returns a list of UTXOs
|
|
1739
1756
|
*/
|
|
1740
1757
|
async getCollateral(addressType = "payment") {
|
|
1758
|
+
await this.init();
|
|
1741
1759
|
const utxos = await this.getCollateralUnspentOutput(addressType);
|
|
1742
1760
|
return utxos.map((utxo, i) => {
|
|
1743
1761
|
return fromTxUnspentOutput2(utxo);
|
|
@@ -1760,6 +1778,7 @@ var MeshWallet = class {
|
|
|
1760
1778
|
* @returns a list of UTXOs
|
|
1761
1779
|
*/
|
|
1762
1780
|
async getCollateralUnspentOutput(addressType = "payment") {
|
|
1781
|
+
await this.init();
|
|
1763
1782
|
const utxos = await this.getUnspentOutputs(addressType);
|
|
1764
1783
|
const pureAdaUtxos = utxos.filter((utxo) => {
|
|
1765
1784
|
return utxo.output().amount().multiasset() === void 0;
|
|
@@ -1778,10 +1797,16 @@ var MeshWallet = class {
|
|
|
1778
1797
|
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
1779
1798
|
* These are used by the client to identify the user's on-chain CIP-1694 interactions, i.e. if a user has registered to be a DRep.
|
|
1780
1799
|
*
|
|
1781
|
-
* @returns
|
|
1800
|
+
* @returns DRep object
|
|
1782
1801
|
*/
|
|
1783
1802
|
async getDRep() {
|
|
1784
|
-
|
|
1803
|
+
await this.init();
|
|
1804
|
+
if (this.addresses.pubDRepKey && this.addresses.dRepIDHash && this.addresses.dRepIDCip105)
|
|
1805
|
+
return {
|
|
1806
|
+
publicKey: this.addresses.pubDRepKey,
|
|
1807
|
+
publicKeyHash: this.addresses.dRepIDHash,
|
|
1808
|
+
dRepIDCip105: this.addresses.dRepIDCip105
|
|
1809
|
+
};
|
|
1785
1810
|
return void 0;
|
|
1786
1811
|
}
|
|
1787
1812
|
/**
|
|
@@ -1806,7 +1831,7 @@ var MeshWallet = class {
|
|
|
1806
1831
|
* @returns a list of unused addresses
|
|
1807
1832
|
*/
|
|
1808
1833
|
async getUnusedAddresses() {
|
|
1809
|
-
return [this.getChangeAddress()];
|
|
1834
|
+
return [await this.getChangeAddress()];
|
|
1810
1835
|
}
|
|
1811
1836
|
/**
|
|
1812
1837
|
* Returns a list of used addresses controlled by the wallet.
|
|
@@ -1814,7 +1839,7 @@ var MeshWallet = class {
|
|
|
1814
1839
|
* @returns a list of used addresses
|
|
1815
1840
|
*/
|
|
1816
1841
|
async getUsedAddresses() {
|
|
1817
|
-
return [this.getChangeAddress()];
|
|
1842
|
+
return [await this.getChangeAddress()];
|
|
1818
1843
|
}
|
|
1819
1844
|
/**
|
|
1820
1845
|
* Get a list of UTXOs to be used for transaction building.
|
|
@@ -1825,6 +1850,7 @@ var MeshWallet = class {
|
|
|
1825
1850
|
* @returns a list of UTXOs
|
|
1826
1851
|
*/
|
|
1827
1852
|
async getUsedUTxOs(addressType = "payment") {
|
|
1853
|
+
await this.init();
|
|
1828
1854
|
return await this.getUnspentOutputs(addressType);
|
|
1829
1855
|
}
|
|
1830
1856
|
/**
|
|
@@ -1845,13 +1871,14 @@ var MeshWallet = class {
|
|
|
1845
1871
|
* @returns a signature
|
|
1846
1872
|
*/
|
|
1847
1873
|
async signData(payload, address) {
|
|
1874
|
+
await this.init();
|
|
1848
1875
|
if (!this._wallet) {
|
|
1849
1876
|
throw new Error(
|
|
1850
1877
|
"[MeshWallet] Read only wallet does not support signing data."
|
|
1851
1878
|
);
|
|
1852
1879
|
}
|
|
1853
1880
|
if (address === void 0) {
|
|
1854
|
-
address = this.getChangeAddress();
|
|
1881
|
+
address = await this.getChangeAddress();
|
|
1855
1882
|
}
|
|
1856
1883
|
return this._wallet.signData(
|
|
1857
1884
|
address,
|
|
@@ -1868,6 +1895,7 @@ var MeshWallet = class {
|
|
|
1868
1895
|
* @returns a signed transaction in CBOR
|
|
1869
1896
|
*/
|
|
1870
1897
|
async signTx(unsignedTx, partialSign = false) {
|
|
1898
|
+
await this.init();
|
|
1871
1899
|
if (!this._wallet) {
|
|
1872
1900
|
throw new Error(
|
|
1873
1901
|
"[MeshWallet] Read only wallet does not support signing data."
|
|
@@ -1894,6 +1922,7 @@ var MeshWallet = class {
|
|
|
1894
1922
|
* @returns array of signed transactions CborHex string
|
|
1895
1923
|
*/
|
|
1896
1924
|
async signTxs(unsignedTxs, partialSign = false) {
|
|
1925
|
+
await this.init();
|
|
1897
1926
|
if (!this._wallet) {
|
|
1898
1927
|
throw new Error(
|
|
1899
1928
|
"[MeshWallet] Read only wallet does not support signing data."
|
|
@@ -1909,7 +1938,7 @@ var MeshWallet = class {
|
|
|
1909
1938
|
/**
|
|
1910
1939
|
* Submits the signed transaction to the blockchain network.
|
|
1911
1940
|
*
|
|
1912
|
-
* As wallets should already have this ability to submit transaction, we allow
|
|
1941
|
+
* As wallets should already have this ability to submit transaction, we allow apps to request that a transaction be sent through it. If the wallet accepts the transaction and tries to send it, it shall return the transaction ID for the app to track. The wallet can return error messages or failure if there was an error in sending it.
|
|
1913
1942
|
*
|
|
1914
1943
|
* @param tx - a signed transaction in CBOR
|
|
1915
1944
|
* @returns a transaction hash
|
|
@@ -2022,7 +2051,7 @@ var MeshWallet = class {
|
|
|
2022
2051
|
*/
|
|
2023
2052
|
async createCollateral() {
|
|
2024
2053
|
const tx = new Transaction3({ initiator: this });
|
|
2025
|
-
tx.sendLovelace(this.getChangeAddress(), "5000000");
|
|
2054
|
+
tx.sendLovelace(await this.getChangeAddress(), "5000000");
|
|
2026
2055
|
const unsignedTx = await tx.build();
|
|
2027
2056
|
const signedTx = await this.signTx(unsignedTx);
|
|
2028
2057
|
const txHash = await this.submitTx(signedTx);
|
|
@@ -2032,7 +2061,8 @@ var MeshWallet = class {
|
|
|
2032
2061
|
return {
|
|
2033
2062
|
pubDRepKey: this.addresses.pubDRepKey,
|
|
2034
2063
|
dRepIDBech32: this.addresses.dRepIDBech32,
|
|
2035
|
-
dRepIDHash: this.addresses.dRepIDHash
|
|
2064
|
+
dRepIDHash: this.addresses.dRepIDHash,
|
|
2065
|
+
dRepIDCip105: this.addresses.dRepIDCip105
|
|
2036
2066
|
};
|
|
2037
2067
|
}
|
|
2038
2068
|
/**
|
|
@@ -2059,7 +2089,8 @@ var MeshWallet = class {
|
|
|
2059
2089
|
rewardAddressBech32: account.rewardAddressBech32,
|
|
2060
2090
|
pubDRepKey: account.pubDRepKey,
|
|
2061
2091
|
dRepIDBech32: account.dRepIDBech32,
|
|
2062
|
-
dRepIDHash: account.dRepIDHash
|
|
2092
|
+
dRepIDHash: account.dRepIDHash,
|
|
2093
|
+
dRepIDCip105: account.dRepIDCip105
|
|
2063
2094
|
};
|
|
2064
2095
|
}
|
|
2065
2096
|
buildAddressFromBech32Address(address) {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/wallet",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.9.0-beta-39",
|
|
4
4
|
"description": "Wallets - https://meshjs.dev/apis/wallets",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|
|
@@ -35,10 +35,9 @@
|
|
|
35
35
|
"typescript": "^5.3.3"
|
|
36
36
|
},
|
|
37
37
|
"dependencies": {
|
|
38
|
-
"@meshsdk/common": "1.
|
|
39
|
-
"@meshsdk/core-
|
|
40
|
-
"@meshsdk/
|
|
41
|
-
"@meshsdk/transaction": "1.8.14",
|
|
38
|
+
"@meshsdk/common": "1.9.0-beta-39",
|
|
39
|
+
"@meshsdk/core-cst": "1.9.0-beta-39",
|
|
40
|
+
"@meshsdk/transaction": "1.9.0-beta-39",
|
|
42
41
|
"@simplewebauthn/browser": "^13.0.0"
|
|
43
42
|
},
|
|
44
43
|
"prettier": "@meshsdk/configs/prettier",
|