@meshsdk/wallet 1.9.0-beta.10 → 1.9.0-beta.101
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 +180 -68
- package/dist/index.d.cts +74 -26
- package/dist/index.d.ts +74 -26
- package/dist/index.js +195 -78
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -572,12 +572,12 @@ var WalletStaticMethods = class {
|
|
|
572
572
|
static privateKeyBech32ToPrivateKeyHex(_bech32) {
|
|
573
573
|
const bech32DecodedBytes = bech32.decodeToBytes(_bech32).bytes;
|
|
574
574
|
const bip32PrivateKey = import_core_cst.Bip32PrivateKey.fromBytes(bech32DecodedBytes);
|
|
575
|
-
return
|
|
575
|
+
return bip32PrivateKey.hex();
|
|
576
576
|
}
|
|
577
577
|
static mnemonicToPrivateKeyHex(words) {
|
|
578
578
|
const entropy = (0, import_common.mnemonicToEntropy)(words.join(" "));
|
|
579
579
|
const bip32PrivateKey = (0, import_core_cst.buildBip32PrivateKey)(entropy);
|
|
580
|
-
return
|
|
580
|
+
return bip32PrivateKey.hex();
|
|
581
581
|
}
|
|
582
582
|
static signingKeyToHexes(paymentKey, stakeKey) {
|
|
583
583
|
return [
|
|
@@ -587,29 +587,21 @@ var WalletStaticMethods = class {
|
|
|
587
587
|
}
|
|
588
588
|
static bip32BytesToPrivateKeyHex(bip32Bytes) {
|
|
589
589
|
const bip32PrivateKey = import_core_cst.Bip32PrivateKey.fromBytes(bip32Bytes);
|
|
590
|
-
return
|
|
590
|
+
return bip32PrivateKey.hex();
|
|
591
591
|
}
|
|
592
592
|
static getAddresses(paymentKey, stakingKey, networkId = 0) {
|
|
593
593
|
const baseAddress = (0, import_core_cst.buildBaseAddress)(
|
|
594
594
|
networkId,
|
|
595
|
-
import_core_cst.Hash28ByteBase16.
|
|
596
|
-
|
|
597
|
-
),
|
|
598
|
-
import_core_cst.Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
599
|
-
stakingKey.toPublic().hash().hex()
|
|
600
|
-
)
|
|
595
|
+
(0, import_core_cst.Hash28ByteBase16)(paymentKey.toPublic().hash().hex()),
|
|
596
|
+
(0, import_core_cst.Hash28ByteBase16)(stakingKey.toPublic().hash().hex())
|
|
601
597
|
).toAddress();
|
|
602
598
|
const enterpriseAddress = (0, import_core_cst.buildEnterpriseAddress)(
|
|
603
599
|
networkId,
|
|
604
|
-
import_core_cst.Hash28ByteBase16.
|
|
605
|
-
paymentKey.toPublic().hash().hex()
|
|
606
|
-
)
|
|
600
|
+
(0, import_core_cst.Hash28ByteBase16)(paymentKey.toPublic().hash().hex())
|
|
607
601
|
).toAddress();
|
|
608
602
|
const rewardAddress = (0, import_core_cst.buildRewardAddress)(
|
|
609
603
|
networkId,
|
|
610
|
-
import_core_cst.Hash28ByteBase16.
|
|
611
|
-
stakingKey.toPublic().hash().hex()
|
|
612
|
-
)
|
|
604
|
+
(0, import_core_cst.Hash28ByteBase16)(stakingKey.toPublic().hash().hex())
|
|
613
605
|
).toAddress();
|
|
614
606
|
return {
|
|
615
607
|
baseAddress,
|
|
@@ -618,17 +610,19 @@ var WalletStaticMethods = class {
|
|
|
618
610
|
};
|
|
619
611
|
}
|
|
620
612
|
static getDRepKey(dRepKey, networkId = 0) {
|
|
621
|
-
const pubDRepKey = dRepKey.toPublic().hex()
|
|
613
|
+
const pubDRepKey = dRepKey.toPublic().hex();
|
|
622
614
|
const dRepIDBech32 = (0, import_core_cst.buildDRepID)(
|
|
623
615
|
(0, import_core_cst.Ed25519PublicKeyHex)(pubDRepKey),
|
|
624
616
|
networkId
|
|
625
617
|
);
|
|
626
618
|
const dRep = import_core_cst.DRep.newKeyHash(dRepKey.toPublic().hash().hex());
|
|
627
619
|
const dRepIDHash = dRep.toKeyHash();
|
|
620
|
+
const dRepIDCip105 = (0, import_core_cst.hexToBech32)("drep", dRepIDHash);
|
|
628
621
|
return {
|
|
629
622
|
pubDRepKey,
|
|
630
623
|
dRepIDBech32,
|
|
631
|
-
dRepIDHash
|
|
624
|
+
dRepIDHash,
|
|
625
|
+
dRepIDCip105
|
|
632
626
|
};
|
|
633
627
|
}
|
|
634
628
|
static generateMnemonic(strength = 256) {
|
|
@@ -652,6 +646,7 @@ var WalletStaticMethods = class {
|
|
|
652
646
|
var EmbeddedWallet = class extends WalletStaticMethods {
|
|
653
647
|
_walletSecret;
|
|
654
648
|
_networkId;
|
|
649
|
+
cryptoIsReady = false;
|
|
655
650
|
constructor(options) {
|
|
656
651
|
super();
|
|
657
652
|
this._networkId = options.networkId;
|
|
@@ -681,6 +676,7 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
681
676
|
}
|
|
682
677
|
async init() {
|
|
683
678
|
await import_core_cst.Crypto.ready();
|
|
679
|
+
this.cryptoIsReady = true;
|
|
684
680
|
}
|
|
685
681
|
getAccount(accountIndex = 0, keyIndex = 0) {
|
|
686
682
|
if (this._walletSecret == void 0)
|
|
@@ -704,10 +700,12 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
704
700
|
stakeKeyHex: stakeKey.hex()
|
|
705
701
|
};
|
|
706
702
|
if (dRepKey) {
|
|
707
|
-
const { pubDRepKey, dRepIDBech32, dRepIDHash } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
|
|
703
|
+
const { pubDRepKey, dRepIDBech32, dRepIDHash, dRepIDCip105 } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
|
|
704
|
+
_account.drepKey = dRepKey;
|
|
708
705
|
_account.pubDRepKey = pubDRepKey;
|
|
709
706
|
_account.dRepIDBech32 = dRepIDBech32;
|
|
710
707
|
_account.dRepIDHash = dRepIDHash;
|
|
708
|
+
_account.dRepIDCip105 = dRepIDCip105;
|
|
711
709
|
}
|
|
712
710
|
return _account;
|
|
713
711
|
}
|
|
@@ -729,7 +727,13 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
729
727
|
*/
|
|
730
728
|
signData(address, payload, accountIndex = 0, keyIndex = 0) {
|
|
731
729
|
try {
|
|
732
|
-
const {
|
|
730
|
+
const {
|
|
731
|
+
baseAddress,
|
|
732
|
+
enterpriseAddress,
|
|
733
|
+
rewardAddress,
|
|
734
|
+
paymentKey,
|
|
735
|
+
stakeKey
|
|
736
|
+
} = this.getAccount(accountIndex, keyIndex);
|
|
733
737
|
const foundAddress = [baseAddress, enterpriseAddress, rewardAddress].find(
|
|
734
738
|
(a) => a.toBech32() === address
|
|
735
739
|
);
|
|
@@ -739,7 +743,7 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
739
743
|
);
|
|
740
744
|
return (0, import_core_cst.signData)(payload, {
|
|
741
745
|
address: import_core_cst.Address.fromBech32(address),
|
|
742
|
-
key: paymentKey
|
|
746
|
+
key: address === rewardAddress.toBech32() ? stakeKey : paymentKey
|
|
743
747
|
});
|
|
744
748
|
} catch (error) {
|
|
745
749
|
throw new Error(
|
|
@@ -753,15 +757,26 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
753
757
|
* @param unsignedTx - a transaction in CBOR
|
|
754
758
|
* @param accountIndex account index (default: 0)
|
|
755
759
|
* @param keyIndex key index (default: 0)
|
|
760
|
+
* @param accountType - type of the account (default: payment)
|
|
756
761
|
* @returns VkeyWitness
|
|
757
762
|
*/
|
|
758
|
-
signTx(unsignedTx, accountIndex = 0, keyIndex = 0) {
|
|
763
|
+
signTx(unsignedTx, accountIndex = 0, keyIndex = 0, accountType = "payment") {
|
|
759
764
|
try {
|
|
760
765
|
const txHash = (0, import_core_cst.deserializeTxHash)((0, import_core_cst.resolveTxHash)(unsignedTx));
|
|
761
|
-
const { paymentKey } = this.getAccount(
|
|
766
|
+
const { paymentKey, stakeKey, drepKey } = this.getAccount(
|
|
767
|
+
accountIndex,
|
|
768
|
+
keyIndex
|
|
769
|
+
);
|
|
770
|
+
let key = paymentKey;
|
|
771
|
+
if (accountType === "stake") {
|
|
772
|
+
key = stakeKey;
|
|
773
|
+
} else if (accountType === "drep") {
|
|
774
|
+
if (!drepKey) throw new Error("DRep key not found");
|
|
775
|
+
key = drepKey;
|
|
776
|
+
}
|
|
762
777
|
const vKeyWitness = new import_core_cst.VkeyWitness(
|
|
763
|
-
|
|
764
|
-
|
|
778
|
+
key.toPublic().hex(),
|
|
779
|
+
key.sign((0, import_core_cst.HexBlob)(txHash)).hex()
|
|
765
780
|
);
|
|
766
781
|
return vKeyWitness;
|
|
767
782
|
} catch (error) {
|
|
@@ -884,7 +899,7 @@ var AppWallet = class {
|
|
|
884
899
|
);
|
|
885
900
|
}
|
|
886
901
|
}
|
|
887
|
-
async signTx(unsignedTx, partialSign = false, accountIndex = 0, keyIndex = 0) {
|
|
902
|
+
async signTx(unsignedTx, partialSign = false, returnFullTx = true, accountIndex = 0, keyIndex = 0) {
|
|
888
903
|
try {
|
|
889
904
|
const tx = (0, import_core_cst2.deserializeTx)(unsignedTx);
|
|
890
905
|
if (!partialSign && tx.witnessSet().vkeys() !== void 0 && tx.witnessSet().vkeys().size() !== 0)
|
|
@@ -896,6 +911,16 @@ var AppWallet = class {
|
|
|
896
911
|
accountIndex,
|
|
897
912
|
keyIndex
|
|
898
913
|
);
|
|
914
|
+
if (!returnFullTx) {
|
|
915
|
+
let witnessSet = new import_core_cst2.TransactionWitnessSet();
|
|
916
|
+
witnessSet.setVkeys(
|
|
917
|
+
import_core_cst2.Serialization.CborSet.fromCore(
|
|
918
|
+
[newSignatures.toCore()],
|
|
919
|
+
import_core_cst2.VkeyWitness.fromCore
|
|
920
|
+
)
|
|
921
|
+
);
|
|
922
|
+
return witnessSet.toCbor();
|
|
923
|
+
}
|
|
899
924
|
let signedTx = EmbeddedWallet.addWitnessSets(unsignedTx, [newSignatures]);
|
|
900
925
|
return signedTx;
|
|
901
926
|
} catch (error) {
|
|
@@ -981,7 +1006,7 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
981
1006
|
return wallets;
|
|
982
1007
|
}
|
|
983
1008
|
/**
|
|
984
|
-
* 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
|
|
1009
|
+
* 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.
|
|
985
1010
|
*
|
|
986
1011
|
* 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.
|
|
987
1012
|
*
|
|
@@ -1104,31 +1129,36 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1104
1129
|
* @param address - optional, if not provided, the first staking address will be used
|
|
1105
1130
|
* @returns a signature
|
|
1106
1131
|
*/
|
|
1107
|
-
async signData(payload, address) {
|
|
1132
|
+
async signData(payload, address, convertFromUTF8 = true) {
|
|
1108
1133
|
if (address === void 0) {
|
|
1109
1134
|
address = (await this.getUsedAddresses())[0];
|
|
1110
1135
|
if (address === void 0) {
|
|
1111
1136
|
address = await this.getChangeAddress();
|
|
1112
1137
|
}
|
|
1113
1138
|
}
|
|
1139
|
+
const _payload = convertFromUTF8 ? (0, import_common2.fromUTF8)(payload) : payload;
|
|
1114
1140
|
if (address.startsWith("drep1")) {
|
|
1115
|
-
return this._walletInstance.cip95.signData(address,
|
|
1141
|
+
return this._walletInstance.cip95.signData(address, _payload);
|
|
1116
1142
|
}
|
|
1117
1143
|
const signerAddress = (0, import_core_cst3.toAddress)(address).toBytes().toString();
|
|
1118
|
-
return this._walletInstance.signData(signerAddress,
|
|
1144
|
+
return this._walletInstance.signData(signerAddress, _payload);
|
|
1119
1145
|
}
|
|
1120
1146
|
/**
|
|
1121
1147
|
* Requests user to sign the provided transaction (tx). The wallet should ask the user for permission, and if given, try to sign the supplied body and return a signed transaction. partialSign should be true if the transaction provided requires multiple signatures.
|
|
1122
1148
|
*
|
|
1123
1149
|
* @param unsignedTx - a transaction in CBOR
|
|
1124
1150
|
* @param partialSign - if the transaction is signed partially
|
|
1151
|
+
* @param returnFullTx - if the full tx should be returned or only the witness set (default: true)
|
|
1125
1152
|
* @returns a signed transaction in CBOR
|
|
1126
1153
|
*/
|
|
1127
|
-
async signTx(unsignedTx, partialSign = false) {
|
|
1154
|
+
async signTx(unsignedTx, partialSign = false, returnFullTx = true) {
|
|
1128
1155
|
const witness = await this._walletInstance.signTx(unsignedTx, partialSign);
|
|
1129
1156
|
if (witness === "") {
|
|
1130
1157
|
return unsignedTx;
|
|
1131
1158
|
}
|
|
1159
|
+
if (!returnFullTx) {
|
|
1160
|
+
return witness;
|
|
1161
|
+
}
|
|
1132
1162
|
return _BrowserWallet.addBrowserWitnesses(unsignedTx, witness);
|
|
1133
1163
|
}
|
|
1134
1164
|
/**
|
|
@@ -1187,7 +1217,7 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1187
1217
|
/**
|
|
1188
1218
|
* Submits the signed transaction to the blockchain network.
|
|
1189
1219
|
*
|
|
1190
|
-
* As wallets should already have this ability to submit transaction, we allow
|
|
1220
|
+
* 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.
|
|
1191
1221
|
*
|
|
1192
1222
|
* @param tx
|
|
1193
1223
|
* @returns a transaction hash
|
|
@@ -1293,19 +1323,18 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1293
1323
|
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
1294
1324
|
* 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.
|
|
1295
1325
|
*
|
|
1296
|
-
* @returns
|
|
1326
|
+
* @returns DRep object
|
|
1297
1327
|
*/
|
|
1298
1328
|
async getDRep() {
|
|
1329
|
+
const pubDRepKey = await this.getPubDRepKey();
|
|
1299
1330
|
try {
|
|
1300
|
-
if (
|
|
1301
|
-
const
|
|
1302
|
-
const
|
|
1303
|
-
const csldRepIdKeyHash = (0, import_core_cst3.blake2b)(28).update(Buffer.from(dRepKey, "hex")).digest("hex");
|
|
1304
|
-
const dRepId = (0, import_core_cst3.hexToBech32)("drep", csldRepIdKeyHash);
|
|
1331
|
+
if (pubDRepKey === void 0) return void 0;
|
|
1332
|
+
const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(pubDRepKey);
|
|
1333
|
+
const dRepIDCip105 = (0, import_core_cst3.hexToBech32)("drep", dRepIDHash);
|
|
1305
1334
|
return {
|
|
1306
|
-
publicKey:
|
|
1335
|
+
publicKey: pubDRepKey,
|
|
1307
1336
|
publicKeyHash: dRepIDHash,
|
|
1308
|
-
dRepIDCip105
|
|
1337
|
+
dRepIDCip105
|
|
1309
1338
|
};
|
|
1310
1339
|
} catch (e) {
|
|
1311
1340
|
console.error(e);
|
|
@@ -1321,15 +1350,8 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1321
1350
|
async getPubDRepKey() {
|
|
1322
1351
|
try {
|
|
1323
1352
|
if (this._walletInstance.cip95 === void 0) return void 0;
|
|
1324
|
-
const
|
|
1325
|
-
|
|
1326
|
-
const csldRepIdKeyHash = (0, import_core_cst3.blake2b)(28).update(Buffer.from(dRepKey, "hex")).digest("hex");
|
|
1327
|
-
const dRepId = (0, import_core_cst3.hexToBech32)("drep", csldRepIdKeyHash);
|
|
1328
|
-
return {
|
|
1329
|
-
pubDRepKey: dRepKey,
|
|
1330
|
-
dRepIDHash,
|
|
1331
|
-
dRepIDBech32: dRepId
|
|
1332
|
-
};
|
|
1353
|
+
const pubDRepKey = await this._walletInstance.cip95.getPubDRepKey();
|
|
1354
|
+
return pubDRepKey;
|
|
1333
1355
|
} catch (e) {
|
|
1334
1356
|
console.error(e);
|
|
1335
1357
|
return void 0;
|
|
@@ -1388,8 +1410,7 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1388
1410
|
if (window.cardano[walletName] === void 0) return void 0;
|
|
1389
1411
|
const wallet = window.cardano[walletName];
|
|
1390
1412
|
if (extensions.length > 0) {
|
|
1391
|
-
|
|
1392
|
-
return wallet.enable({ extensions: _extensions });
|
|
1413
|
+
return wallet.enable({ extensions });
|
|
1393
1414
|
} else {
|
|
1394
1415
|
return wallet?.enable();
|
|
1395
1416
|
}
|
|
@@ -1586,6 +1607,7 @@ var import_core_cst5 = require("@meshsdk/core-cst");
|
|
|
1586
1607
|
var import_transaction = require("@meshsdk/transaction");
|
|
1587
1608
|
var MeshWallet = class {
|
|
1588
1609
|
_keyType;
|
|
1610
|
+
_accountType = "payment";
|
|
1589
1611
|
_wallet;
|
|
1590
1612
|
_accountIndex = 0;
|
|
1591
1613
|
_keyIndex = 0;
|
|
@@ -1600,6 +1622,7 @@ var MeshWallet = class {
|
|
|
1600
1622
|
if (options.submitter) this._submitter = options.submitter;
|
|
1601
1623
|
if (options.accountIndex) this._accountIndex = options.accountIndex;
|
|
1602
1624
|
if (options.keyIndex) this._keyIndex = options.keyIndex;
|
|
1625
|
+
if (options.accountType) this._accountType = options.accountType;
|
|
1603
1626
|
switch (options.key.type) {
|
|
1604
1627
|
case "root":
|
|
1605
1628
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1649,7 +1672,7 @@ var MeshWallet = class {
|
|
|
1649
1672
|
* @returns void
|
|
1650
1673
|
*/
|
|
1651
1674
|
async init() {
|
|
1652
|
-
if (this._wallet) {
|
|
1675
|
+
if (this._wallet && !this._wallet.cryptoIsReady) {
|
|
1653
1676
|
await this._wallet.init();
|
|
1654
1677
|
this.getAddressesFromWallet(this._wallet);
|
|
1655
1678
|
}
|
|
@@ -1669,6 +1692,7 @@ var MeshWallet = class {
|
|
|
1669
1692
|
* @returns a list of assets and their quantities
|
|
1670
1693
|
*/
|
|
1671
1694
|
async getBalance() {
|
|
1695
|
+
await this.init();
|
|
1672
1696
|
const utxos = await this.getUnspentOutputs();
|
|
1673
1697
|
const assets = /* @__PURE__ */ new Map();
|
|
1674
1698
|
utxos.map((utxo) => {
|
|
@@ -1695,8 +1719,24 @@ var MeshWallet = class {
|
|
|
1695
1719
|
*
|
|
1696
1720
|
* @returns an address
|
|
1697
1721
|
*/
|
|
1698
|
-
async getChangeAddress() {
|
|
1699
|
-
|
|
1722
|
+
async getChangeAddress(addressType = "payment") {
|
|
1723
|
+
await this.init();
|
|
1724
|
+
if (this.addresses.baseAddressBech32 && addressType === "payment") {
|
|
1725
|
+
return this.addresses.baseAddressBech32;
|
|
1726
|
+
}
|
|
1727
|
+
return this.addresses.enterpriseAddressBech32;
|
|
1728
|
+
}
|
|
1729
|
+
/**
|
|
1730
|
+
* Returns an address owned by the wallet that should be used as a change address to return leftover assets during transaction creation back to the connected wallet in hex format.
|
|
1731
|
+
*
|
|
1732
|
+
* @returns an address in hex format
|
|
1733
|
+
*/
|
|
1734
|
+
async getChangeAddressHex(addressType = "payment") {
|
|
1735
|
+
await this.init();
|
|
1736
|
+
if (this.addresses.baseAddress && addressType === "payment") {
|
|
1737
|
+
return this.addresses.baseAddress.toBytes().toString();
|
|
1738
|
+
}
|
|
1739
|
+
return this.addresses.enterpriseAddress.toBytes().toString();
|
|
1700
1740
|
}
|
|
1701
1741
|
/**
|
|
1702
1742
|
* 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).
|
|
@@ -1707,11 +1747,27 @@ var MeshWallet = class {
|
|
|
1707
1747
|
* @returns a list of UTXOs
|
|
1708
1748
|
*/
|
|
1709
1749
|
async getCollateral(addressType = "payment") {
|
|
1750
|
+
await this.init();
|
|
1710
1751
|
const utxos = await this.getCollateralUnspentOutput(addressType);
|
|
1711
1752
|
return utxos.map((utxo, i) => {
|
|
1712
1753
|
return (0, import_core_cst5.fromTxUnspentOutput)(utxo);
|
|
1713
1754
|
});
|
|
1714
1755
|
}
|
|
1756
|
+
/**
|
|
1757
|
+
* 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).
|
|
1758
|
+
*
|
|
1759
|
+
* If this cannot be attained, an error message with an explanation of the blocking problem shall be returned. NOTE: wallets are free to return UTXOs that add up to a greater total ADA value than requested in the amount parameter, but wallets must never return any result where UTXOs would sum up to a smaller total ADA value, instead in a case like that an error message must be returned.
|
|
1760
|
+
*
|
|
1761
|
+
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1762
|
+
* @returns a list of UTXOs in hex format
|
|
1763
|
+
*/
|
|
1764
|
+
async getCollateralHex(addressType = "payment") {
|
|
1765
|
+
await this.init();
|
|
1766
|
+
const utxos = await this.getCollateralUnspentOutput(addressType);
|
|
1767
|
+
return utxos.map((utxo) => {
|
|
1768
|
+
return utxo.toCbor().toString();
|
|
1769
|
+
});
|
|
1770
|
+
}
|
|
1715
1771
|
/**
|
|
1716
1772
|
* Return a list of supported CIPs of the wallet.
|
|
1717
1773
|
*
|
|
@@ -1729,6 +1785,7 @@ var MeshWallet = class {
|
|
|
1729
1785
|
* @returns a list of UTXOs
|
|
1730
1786
|
*/
|
|
1731
1787
|
async getCollateralUnspentOutput(addressType = "payment") {
|
|
1788
|
+
await this.init();
|
|
1732
1789
|
const utxos = await this.getUnspentOutputs(addressType);
|
|
1733
1790
|
const pureAdaUtxos = utxos.filter((utxo) => {
|
|
1734
1791
|
return utxo.output().amount().multiasset() === void 0;
|
|
@@ -1747,10 +1804,16 @@ var MeshWallet = class {
|
|
|
1747
1804
|
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
1748
1805
|
* 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.
|
|
1749
1806
|
*
|
|
1750
|
-
* @returns
|
|
1807
|
+
* @returns DRep object
|
|
1751
1808
|
*/
|
|
1752
1809
|
async getDRep() {
|
|
1753
|
-
|
|
1810
|
+
await this.init();
|
|
1811
|
+
if (this.addresses.pubDRepKey && this.addresses.dRepIDHash && this.addresses.dRepIDCip105)
|
|
1812
|
+
return {
|
|
1813
|
+
publicKey: this.addresses.pubDRepKey,
|
|
1814
|
+
publicKeyHash: this.addresses.dRepIDHash,
|
|
1815
|
+
dRepIDCip105: this.addresses.dRepIDCip105
|
|
1816
|
+
};
|
|
1754
1817
|
return void 0;
|
|
1755
1818
|
}
|
|
1756
1819
|
/**
|
|
@@ -1769,6 +1832,13 @@ var MeshWallet = class {
|
|
|
1769
1832
|
async getRewardAddresses() {
|
|
1770
1833
|
return [this.addresses.rewardAddressBech32];
|
|
1771
1834
|
}
|
|
1835
|
+
/**
|
|
1836
|
+
* Returns a list of reward addresses owned by the wallet. A reward address is a stake address that is used to receive rewards from staking.
|
|
1837
|
+
* @returns a list of reward addresses in hex format
|
|
1838
|
+
*/
|
|
1839
|
+
async getRewardAddressesHex() {
|
|
1840
|
+
return [this.addresses.rewardAddress.toBytes().toString()];
|
|
1841
|
+
}
|
|
1772
1842
|
/**
|
|
1773
1843
|
* Returns a list of unused addresses controlled by the wallet.
|
|
1774
1844
|
*
|
|
@@ -1777,6 +1847,14 @@ var MeshWallet = class {
|
|
|
1777
1847
|
async getUnusedAddresses() {
|
|
1778
1848
|
return [await this.getChangeAddress()];
|
|
1779
1849
|
}
|
|
1850
|
+
/**
|
|
1851
|
+
* Returns a list of unused addresses controlled by the wallet.
|
|
1852
|
+
*
|
|
1853
|
+
* @returns a list of unused addresses in hex format
|
|
1854
|
+
*/
|
|
1855
|
+
async getUnusedAddressesHex() {
|
|
1856
|
+
return [await this.getChangeAddressHex()];
|
|
1857
|
+
}
|
|
1780
1858
|
/**
|
|
1781
1859
|
* Returns a list of used addresses controlled by the wallet.
|
|
1782
1860
|
*
|
|
@@ -1785,6 +1863,14 @@ var MeshWallet = class {
|
|
|
1785
1863
|
async getUsedAddresses() {
|
|
1786
1864
|
return [await this.getChangeAddress()];
|
|
1787
1865
|
}
|
|
1866
|
+
/**
|
|
1867
|
+
* Returns a list of used addresses controlled by the wallet.
|
|
1868
|
+
*
|
|
1869
|
+
* @returns a list of used addresses in hex format
|
|
1870
|
+
*/
|
|
1871
|
+
async getUsedAddressesHex() {
|
|
1872
|
+
return [await this.getChangeAddressHex()];
|
|
1873
|
+
}
|
|
1788
1874
|
/**
|
|
1789
1875
|
* Get a list of UTXOs to be used for transaction building.
|
|
1790
1876
|
*
|
|
@@ -1794,6 +1880,7 @@ var MeshWallet = class {
|
|
|
1794
1880
|
* @returns a list of UTXOs
|
|
1795
1881
|
*/
|
|
1796
1882
|
async getUsedUTxOs(addressType = "payment") {
|
|
1883
|
+
await this.init();
|
|
1797
1884
|
return await this.getUnspentOutputs(addressType);
|
|
1798
1885
|
}
|
|
1799
1886
|
/**
|
|
@@ -1806,6 +1893,16 @@ var MeshWallet = class {
|
|
|
1806
1893
|
const utxos = await this.getUsedUTxOs(addressType);
|
|
1807
1894
|
return utxos.map((c) => (0, import_core_cst5.fromTxUnspentOutput)(c));
|
|
1808
1895
|
}
|
|
1896
|
+
/**
|
|
1897
|
+
* Return a list of all UTXOs (unspent transaction outputs) controlled by the wallet.
|
|
1898
|
+
*
|
|
1899
|
+
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1900
|
+
* @returns a list of UTXOs in hex format
|
|
1901
|
+
*/
|
|
1902
|
+
async getUtxosHex(addressType = "payment") {
|
|
1903
|
+
const utxos = await this.getUsedUTxOs(addressType);
|
|
1904
|
+
return utxos.map((c) => c.toCbor().toString());
|
|
1905
|
+
}
|
|
1809
1906
|
/**
|
|
1810
1907
|
* This endpoint utilizes the [CIP-8 - Message Signing](https://cips.cardano.org/cips/cip8/) to sign arbitrary data, to verify the data was signed by the owner of the private key.
|
|
1811
1908
|
*
|
|
@@ -1814,6 +1911,7 @@ var MeshWallet = class {
|
|
|
1814
1911
|
* @returns a signature
|
|
1815
1912
|
*/
|
|
1816
1913
|
async signData(payload, address) {
|
|
1914
|
+
await this.init();
|
|
1817
1915
|
if (!this._wallet) {
|
|
1818
1916
|
throw new Error(
|
|
1819
1917
|
"[MeshWallet] Read only wallet does not support signing data."
|
|
@@ -1834,9 +1932,11 @@ var MeshWallet = class {
|
|
|
1834
1932
|
*
|
|
1835
1933
|
* @param unsignedTx - a transaction in CBOR
|
|
1836
1934
|
* @param partialSign - if the transaction is partially signed (default: false)
|
|
1935
|
+
* @param returnFullTx - if the full tx should be returned or only the witness set (default: true)
|
|
1837
1936
|
* @returns a signed transaction in CBOR
|
|
1838
1937
|
*/
|
|
1839
|
-
async signTx(unsignedTx, partialSign = false) {
|
|
1938
|
+
async signTx(unsignedTx, partialSign = false, returnFullTx = true) {
|
|
1939
|
+
await this.init();
|
|
1840
1940
|
if (!this._wallet) {
|
|
1841
1941
|
throw new Error(
|
|
1842
1942
|
"[MeshWallet] Read only wallet does not support signing data."
|
|
@@ -1850,8 +1950,19 @@ var MeshWallet = class {
|
|
|
1850
1950
|
const newSignatures = this._wallet.signTx(
|
|
1851
1951
|
unsignedTx,
|
|
1852
1952
|
this._accountIndex,
|
|
1853
|
-
this._keyIndex
|
|
1953
|
+
this._keyIndex,
|
|
1954
|
+
this._accountType
|
|
1854
1955
|
);
|
|
1956
|
+
if (!returnFullTx) {
|
|
1957
|
+
let witnessSet = new import_core_cst5.TransactionWitnessSet();
|
|
1958
|
+
witnessSet.setVkeys(
|
|
1959
|
+
import_core_cst5.Serialization.CborSet.fromCore(
|
|
1960
|
+
[newSignatures.toCore()],
|
|
1961
|
+
import_core_cst5.VkeyWitness.fromCore
|
|
1962
|
+
)
|
|
1963
|
+
);
|
|
1964
|
+
return witnessSet.toCbor().toString();
|
|
1965
|
+
}
|
|
1855
1966
|
let signedTx = EmbeddedWallet.addWitnessSets(unsignedTx, [newSignatures]);
|
|
1856
1967
|
return signedTx;
|
|
1857
1968
|
}
|
|
@@ -1862,7 +1973,8 @@ var MeshWallet = class {
|
|
|
1862
1973
|
* @param partialSign - if the transactions are signed partially
|
|
1863
1974
|
* @returns array of signed transactions CborHex string
|
|
1864
1975
|
*/
|
|
1865
|
-
async signTxs(unsignedTxs, partialSign = false) {
|
|
1976
|
+
async signTxs(unsignedTxs, partialSign = false, returnFullTx = true) {
|
|
1977
|
+
await this.init();
|
|
1866
1978
|
if (!this._wallet) {
|
|
1867
1979
|
throw new Error(
|
|
1868
1980
|
"[MeshWallet] Read only wallet does not support signing data."
|
|
@@ -1870,7 +1982,7 @@ var MeshWallet = class {
|
|
|
1870
1982
|
}
|
|
1871
1983
|
const signedTxs = [];
|
|
1872
1984
|
for (const unsignedTx of unsignedTxs) {
|
|
1873
|
-
const signedTx = await this.signTx(unsignedTx, partialSign);
|
|
1985
|
+
const signedTx = await this.signTx(unsignedTx, partialSign, returnFullTx);
|
|
1874
1986
|
signedTxs.push(signedTx);
|
|
1875
1987
|
}
|
|
1876
1988
|
return signedTxs;
|
|
@@ -1878,7 +1990,7 @@ var MeshWallet = class {
|
|
|
1878
1990
|
/**
|
|
1879
1991
|
* Submits the signed transaction to the blockchain network.
|
|
1880
1992
|
*
|
|
1881
|
-
* As wallets should already have this ability to submit transaction, we allow
|
|
1993
|
+
* 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.
|
|
1882
1994
|
*
|
|
1883
1995
|
* @param tx - a signed transaction in CBOR
|
|
1884
1996
|
* @returns a transaction hash
|
|
@@ -2001,7 +2113,8 @@ var MeshWallet = class {
|
|
|
2001
2113
|
return {
|
|
2002
2114
|
pubDRepKey: this.addresses.pubDRepKey,
|
|
2003
2115
|
dRepIDBech32: this.addresses.dRepIDBech32,
|
|
2004
|
-
dRepIDHash: this.addresses.dRepIDHash
|
|
2116
|
+
dRepIDHash: this.addresses.dRepIDHash,
|
|
2117
|
+
dRepIDCip105: this.addresses.dRepIDCip105
|
|
2005
2118
|
};
|
|
2006
2119
|
}
|
|
2007
2120
|
/**
|
|
@@ -2028,7 +2141,8 @@ var MeshWallet = class {
|
|
|
2028
2141
|
rewardAddressBech32: account.rewardAddressBech32,
|
|
2029
2142
|
pubDRepKey: account.pubDRepKey,
|
|
2030
2143
|
dRepIDBech32: account.dRepIDBech32,
|
|
2031
|
-
dRepIDHash: account.dRepIDHash
|
|
2144
|
+
dRepIDHash: account.dRepIDHash,
|
|
2145
|
+
dRepIDCip105: account.dRepIDCip105
|
|
2032
2146
|
};
|
|
2033
2147
|
}
|
|
2034
2148
|
buildAddressFromBech32Address(address) {
|
|
@@ -2050,24 +2164,22 @@ var MeshWallet = class {
|
|
|
2050
2164
|
if (pubKeyHash && stakeKeyHash) {
|
|
2051
2165
|
this.addresses.baseAddress = (0, import_core_cst5.buildBaseAddress)(
|
|
2052
2166
|
this._networkId,
|
|
2053
|
-
|
|
2054
|
-
import_core_cst5.Hash28ByteBase16
|
|
2055
|
-
(0, import_core_cst5.Ed25519KeyHashHex)((0, import_core_cst5.Ed25519KeyHashHex)(stakeKeyHash))
|
|
2056
|
-
)
|
|
2167
|
+
(0, import_core_cst5.Hash28ByteBase16)(pubKeyHash),
|
|
2168
|
+
(0, import_core_cst5.Hash28ByteBase16)(stakeKeyHash)
|
|
2057
2169
|
).toAddress();
|
|
2058
2170
|
this.addresses.baseAddressBech32 = this.addresses.baseAddress.toBech32();
|
|
2059
2171
|
}
|
|
2060
2172
|
if (pubKeyHash) {
|
|
2061
2173
|
this.addresses.enterpriseAddress = (0, import_core_cst5.buildEnterpriseAddress)(
|
|
2062
2174
|
this._networkId,
|
|
2063
|
-
import_core_cst5.Hash28ByteBase16
|
|
2175
|
+
(0, import_core_cst5.Hash28ByteBase16)((0, import_core_cst5.Ed25519KeyHashHex)(pubKeyHash))
|
|
2064
2176
|
).toAddress();
|
|
2065
2177
|
this.addresses.enterpriseAddressBech32 = this.addresses.enterpriseAddress.toBech32();
|
|
2066
2178
|
}
|
|
2067
2179
|
if (stakeKeyHash) {
|
|
2068
2180
|
this.addresses.rewardAddress = (0, import_core_cst5.buildRewardAddress)(
|
|
2069
2181
|
this._networkId,
|
|
2070
|
-
|
|
2182
|
+
(0, import_core_cst5.Hash28ByteBase16)(stakeKeyHash)
|
|
2071
2183
|
).toAddress();
|
|
2072
2184
|
this.addresses.rewardAddressBech32 = this.addresses.rewardAddress.toBech32();
|
|
2073
2185
|
}
|