@meshsdk/wallet 1.9.0-beta.1 → 1.9.0-beta.100
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 +221 -94
- package/dist/index.d.cts +98 -36
- package/dist/index.d.ts +98 -36
- package/dist/index.js +240 -108
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -569,47 +569,39 @@ var bech32 = /* @__PURE__ */ genBech32("bech32");
|
|
|
569
569
|
var import_common = require("@meshsdk/common");
|
|
570
570
|
var import_core_cst = require("@meshsdk/core-cst");
|
|
571
571
|
var WalletStaticMethods = class {
|
|
572
|
-
static
|
|
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
|
-
static
|
|
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
|
-
static
|
|
582
|
+
static signingKeyToHexes(paymentKey, stakeKey) {
|
|
583
583
|
return [
|
|
584
584
|
paymentKey.startsWith("5820") ? paymentKey.slice(4) : paymentKey,
|
|
585
585
|
stakeKey.startsWith("5820") ? stakeKey.slice(4) : stakeKey
|
|
586
586
|
];
|
|
587
587
|
}
|
|
588
|
-
static
|
|
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
|
-
(0, import_core_cst.Ed25519KeyHashHex)(stakingKey.toPublicKey().hash().toString("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
|
-
(0, import_core_cst.Ed25519KeyHashHex)(paymentKey.toPublicKey().hash().toString("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
|
-
(0, import_core_cst.Ed25519KeyHashHex)(stakingKey.toPublicKey().hash().toString("hex"))
|
|
612
|
-
)
|
|
604
|
+
(0, import_core_cst.Hash28ByteBase16)(stakingKey.toPublic().hash().hex())
|
|
613
605
|
).toAddress();
|
|
614
606
|
return {
|
|
615
607
|
baseAddress,
|
|
@@ -618,20 +610,19 @@ var WalletStaticMethods = class {
|
|
|
618
610
|
};
|
|
619
611
|
}
|
|
620
612
|
static getDRepKey(dRepKey, networkId = 0) {
|
|
621
|
-
const
|
|
622
|
-
const pubDRepKey = pubKey.toString("hex");
|
|
613
|
+
const pubDRepKey = dRepKey.toPublic().hex();
|
|
623
614
|
const dRepIDBech32 = (0, import_core_cst.buildDRepID)(
|
|
624
615
|
(0, import_core_cst.Ed25519PublicKeyHex)(pubDRepKey),
|
|
625
616
|
networkId
|
|
626
617
|
);
|
|
627
|
-
const dRep = import_core_cst.DRep.newKeyHash(
|
|
628
|
-
(0, import_core_cst.Ed25519KeyHashHex)(dRepKey.toPublicKey().hash().toString("hex"))
|
|
629
|
-
);
|
|
618
|
+
const dRep = import_core_cst.DRep.newKeyHash(dRepKey.toPublic().hash().hex());
|
|
630
619
|
const dRepIDHash = dRep.toKeyHash();
|
|
620
|
+
const dRepIDCip105 = (0, import_core_cst.hexToBech32)("drep", dRepIDHash);
|
|
631
621
|
return {
|
|
632
622
|
pubDRepKey,
|
|
633
623
|
dRepIDBech32,
|
|
634
|
-
dRepIDHash
|
|
624
|
+
dRepIDHash,
|
|
625
|
+
dRepIDCip105
|
|
635
626
|
};
|
|
636
627
|
}
|
|
637
628
|
static generateMnemonic(strength = 256) {
|
|
@@ -653,40 +644,45 @@ var WalletStaticMethods = class {
|
|
|
653
644
|
}
|
|
654
645
|
};
|
|
655
646
|
var EmbeddedWallet = class extends WalletStaticMethods {
|
|
656
|
-
|
|
647
|
+
_walletSecret;
|
|
657
648
|
_networkId;
|
|
649
|
+
cryptoIsReady = false;
|
|
658
650
|
constructor(options) {
|
|
659
651
|
super();
|
|
660
652
|
this._networkId = options.networkId;
|
|
661
653
|
switch (options.key.type) {
|
|
662
654
|
case "mnemonic":
|
|
663
|
-
this.
|
|
655
|
+
this._walletSecret = WalletStaticMethods.mnemonicToPrivateKeyHex(
|
|
664
656
|
options.key.words
|
|
665
657
|
);
|
|
666
658
|
break;
|
|
667
659
|
case "root":
|
|
668
|
-
this.
|
|
660
|
+
this._walletSecret = WalletStaticMethods.privateKeyBech32ToPrivateKeyHex(
|
|
669
661
|
options.key.bech32
|
|
670
662
|
);
|
|
671
663
|
break;
|
|
672
664
|
case "cli":
|
|
673
|
-
this.
|
|
665
|
+
this._walletSecret = WalletStaticMethods.signingKeyToHexes(
|
|
674
666
|
options.key.payment,
|
|
675
667
|
options.key.stake ?? "f0".repeat(32)
|
|
676
668
|
);
|
|
677
669
|
break;
|
|
678
670
|
case "bip32Bytes":
|
|
679
|
-
this.
|
|
671
|
+
this._walletSecret = WalletStaticMethods.bip32BytesToPrivateKeyHex(
|
|
680
672
|
options.key.bip32Bytes
|
|
681
673
|
);
|
|
682
674
|
break;
|
|
683
675
|
}
|
|
684
676
|
}
|
|
677
|
+
async init() {
|
|
678
|
+
await import_core_cst.Crypto.ready();
|
|
679
|
+
this.cryptoIsReady = true;
|
|
680
|
+
}
|
|
685
681
|
getAccount(accountIndex = 0, keyIndex = 0) {
|
|
686
|
-
if (this.
|
|
682
|
+
if (this._walletSecret == void 0)
|
|
687
683
|
throw new Error("[EmbeddedWallet] No keys initialized");
|
|
688
684
|
const { paymentKey, stakeKey, dRepKey } = (0, import_core_cst.buildKeys)(
|
|
689
|
-
this.
|
|
685
|
+
this._walletSecret,
|
|
690
686
|
accountIndex,
|
|
691
687
|
keyIndex
|
|
692
688
|
);
|
|
@@ -700,14 +696,16 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
700
696
|
rewardAddressBech32: rewardAddress.toBech32(),
|
|
701
697
|
paymentKey,
|
|
702
698
|
stakeKey,
|
|
703
|
-
paymentKeyHex: paymentKey.
|
|
704
|
-
stakeKeyHex: stakeKey.
|
|
699
|
+
paymentKeyHex: paymentKey.hex(),
|
|
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,17 +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
|
-
(0, import_core_cst.
|
|
765
|
-
paymentKey.sign(Buffer.from(txHash, "hex")).toString("hex")
|
|
766
|
-
)
|
|
778
|
+
key.toPublic().hex(),
|
|
779
|
+
key.sign((0, import_core_cst.HexBlob)(txHash)).hex()
|
|
767
780
|
);
|
|
768
781
|
return vKeyWitness;
|
|
769
782
|
} catch (error) {
|
|
@@ -812,6 +825,15 @@ var AppWallet = class {
|
|
|
812
825
|
});
|
|
813
826
|
}
|
|
814
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
|
+
}
|
|
815
837
|
/**
|
|
816
838
|
* Get a list of UTXOs to be used as collateral inputs for transactions with plutus script inputs.
|
|
817
839
|
*
|
|
@@ -877,7 +899,7 @@ var AppWallet = class {
|
|
|
877
899
|
);
|
|
878
900
|
}
|
|
879
901
|
}
|
|
880
|
-
async signTx(unsignedTx, partialSign = false, accountIndex = 0, keyIndex = 0) {
|
|
902
|
+
async signTx(unsignedTx, partialSign = false, returnFullTx = true, accountIndex = 0, keyIndex = 0) {
|
|
881
903
|
try {
|
|
882
904
|
const tx = (0, import_core_cst2.deserializeTx)(unsignedTx);
|
|
883
905
|
if (!partialSign && tx.witnessSet().vkeys() !== void 0 && tx.witnessSet().vkeys().size() !== 0)
|
|
@@ -889,6 +911,16 @@ var AppWallet = class {
|
|
|
889
911
|
accountIndex,
|
|
890
912
|
keyIndex
|
|
891
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
|
+
}
|
|
892
924
|
let signedTx = EmbeddedWallet.addWitnessSets(unsignedTx, [newSignatures]);
|
|
893
925
|
return signedTx;
|
|
894
926
|
} catch (error) {
|
|
@@ -974,7 +1006,7 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
974
1006
|
return wallets;
|
|
975
1007
|
}
|
|
976
1008
|
/**
|
|
977
|
-
* 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.
|
|
978
1010
|
*
|
|
979
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.
|
|
980
1012
|
*
|
|
@@ -1097,31 +1129,36 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1097
1129
|
* @param address - optional, if not provided, the first staking address will be used
|
|
1098
1130
|
* @returns a signature
|
|
1099
1131
|
*/
|
|
1100
|
-
async signData(payload, address) {
|
|
1132
|
+
async signData(payload, address, convertFromUTF8 = true) {
|
|
1101
1133
|
if (address === void 0) {
|
|
1102
1134
|
address = (await this.getUsedAddresses())[0];
|
|
1103
1135
|
if (address === void 0) {
|
|
1104
1136
|
address = await this.getChangeAddress();
|
|
1105
1137
|
}
|
|
1106
1138
|
}
|
|
1139
|
+
const _payload = convertFromUTF8 ? (0, import_common2.fromUTF8)(payload) : payload;
|
|
1107
1140
|
if (address.startsWith("drep1")) {
|
|
1108
|
-
return this._walletInstance.cip95.signData(address,
|
|
1141
|
+
return this._walletInstance.cip95.signData(address, _payload);
|
|
1109
1142
|
}
|
|
1110
1143
|
const signerAddress = (0, import_core_cst3.toAddress)(address).toBytes().toString();
|
|
1111
|
-
return this._walletInstance.signData(signerAddress,
|
|
1144
|
+
return this._walletInstance.signData(signerAddress, _payload);
|
|
1112
1145
|
}
|
|
1113
1146
|
/**
|
|
1114
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.
|
|
1115
1148
|
*
|
|
1116
1149
|
* @param unsignedTx - a transaction in CBOR
|
|
1117
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)
|
|
1118
1152
|
* @returns a signed transaction in CBOR
|
|
1119
1153
|
*/
|
|
1120
|
-
async signTx(unsignedTx, partialSign = false) {
|
|
1154
|
+
async signTx(unsignedTx, partialSign = false, returnFullTx = true) {
|
|
1121
1155
|
const witness = await this._walletInstance.signTx(unsignedTx, partialSign);
|
|
1122
1156
|
if (witness === "") {
|
|
1123
1157
|
return unsignedTx;
|
|
1124
1158
|
}
|
|
1159
|
+
if (!returnFullTx) {
|
|
1160
|
+
return witness;
|
|
1161
|
+
}
|
|
1125
1162
|
return _BrowserWallet.addBrowserWitnesses(unsignedTx, witness);
|
|
1126
1163
|
}
|
|
1127
1164
|
/**
|
|
@@ -1180,7 +1217,7 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1180
1217
|
/**
|
|
1181
1218
|
* Submits the signed transaction to the blockchain network.
|
|
1182
1219
|
*
|
|
1183
|
-
* 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.
|
|
1184
1221
|
*
|
|
1185
1222
|
* @param tx
|
|
1186
1223
|
* @returns a transaction hash
|
|
@@ -1286,19 +1323,18 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1286
1323
|
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
1287
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.
|
|
1288
1325
|
*
|
|
1289
|
-
* @returns
|
|
1326
|
+
* @returns DRep object
|
|
1290
1327
|
*/
|
|
1291
1328
|
async getDRep() {
|
|
1329
|
+
const pubDRepKey = await this.getPubDRepKey();
|
|
1292
1330
|
try {
|
|
1293
|
-
if (
|
|
1294
|
-
const
|
|
1295
|
-
const
|
|
1296
|
-
const csldRepIdKeyHash = (0, import_core_cst3.blake2b)(28).update(Buffer.from(dRepKey, "hex")).digest("hex");
|
|
1297
|
-
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);
|
|
1298
1334
|
return {
|
|
1299
|
-
publicKey:
|
|
1335
|
+
publicKey: pubDRepKey,
|
|
1300
1336
|
publicKeyHash: dRepIDHash,
|
|
1301
|
-
dRepIDCip105
|
|
1337
|
+
dRepIDCip105
|
|
1302
1338
|
};
|
|
1303
1339
|
} catch (e) {
|
|
1304
1340
|
console.error(e);
|
|
@@ -1314,15 +1350,8 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1314
1350
|
async getPubDRepKey() {
|
|
1315
1351
|
try {
|
|
1316
1352
|
if (this._walletInstance.cip95 === void 0) return void 0;
|
|
1317
|
-
const
|
|
1318
|
-
|
|
1319
|
-
const csldRepIdKeyHash = (0, import_core_cst3.blake2b)(28).update(Buffer.from(dRepKey, "hex")).digest("hex");
|
|
1320
|
-
const dRepId = (0, import_core_cst3.hexToBech32)("drep", csldRepIdKeyHash);
|
|
1321
|
-
return {
|
|
1322
|
-
pubDRepKey: dRepKey,
|
|
1323
|
-
dRepIDHash,
|
|
1324
|
-
dRepIDBech32: dRepId
|
|
1325
|
-
};
|
|
1353
|
+
const pubDRepKey = await this._walletInstance.cip95.getPubDRepKey();
|
|
1354
|
+
return pubDRepKey;
|
|
1326
1355
|
} catch (e) {
|
|
1327
1356
|
console.error(e);
|
|
1328
1357
|
return void 0;
|
|
@@ -1381,8 +1410,7 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
1381
1410
|
if (window.cardano[walletName] === void 0) return void 0;
|
|
1382
1411
|
const wallet = window.cardano[walletName];
|
|
1383
1412
|
if (extensions.length > 0) {
|
|
1384
|
-
|
|
1385
|
-
return wallet.enable({ extensions: _extensions });
|
|
1413
|
+
return wallet.enable({ extensions });
|
|
1386
1414
|
} else {
|
|
1387
1415
|
return wallet?.enable();
|
|
1388
1416
|
}
|
|
@@ -1578,6 +1606,8 @@ var import_common4 = require("@meshsdk/common");
|
|
|
1578
1606
|
var import_core_cst5 = require("@meshsdk/core-cst");
|
|
1579
1607
|
var import_transaction = require("@meshsdk/transaction");
|
|
1580
1608
|
var MeshWallet = class {
|
|
1609
|
+
_keyType;
|
|
1610
|
+
_accountType = "payment";
|
|
1581
1611
|
_wallet;
|
|
1582
1612
|
_accountIndex = 0;
|
|
1583
1613
|
_keyIndex = 0;
|
|
@@ -1587,10 +1617,12 @@ var MeshWallet = class {
|
|
|
1587
1617
|
addresses = {};
|
|
1588
1618
|
constructor(options) {
|
|
1589
1619
|
this._networkId = options.networkId;
|
|
1620
|
+
this._keyType = options.key.type;
|
|
1590
1621
|
if (options.fetcher) this._fetcher = options.fetcher;
|
|
1591
1622
|
if (options.submitter) this._submitter = options.submitter;
|
|
1592
1623
|
if (options.accountIndex) this._accountIndex = options.accountIndex;
|
|
1593
1624
|
if (options.keyIndex) this._keyIndex = options.keyIndex;
|
|
1625
|
+
if (options.accountType) this._accountType = options.accountType;
|
|
1594
1626
|
switch (options.key.type) {
|
|
1595
1627
|
case "root":
|
|
1596
1628
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1600,7 +1632,6 @@ var MeshWallet = class {
|
|
|
1600
1632
|
bech32: options.key.bech32
|
|
1601
1633
|
}
|
|
1602
1634
|
});
|
|
1603
|
-
this.getAddressesFromWallet(this._wallet);
|
|
1604
1635
|
break;
|
|
1605
1636
|
case "cli":
|
|
1606
1637
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1611,7 +1642,6 @@ var MeshWallet = class {
|
|
|
1611
1642
|
stake: options.key.stake
|
|
1612
1643
|
}
|
|
1613
1644
|
});
|
|
1614
|
-
this.getAddressesFromWallet(this._wallet);
|
|
1615
1645
|
break;
|
|
1616
1646
|
case "mnemonic":
|
|
1617
1647
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1621,7 +1651,6 @@ var MeshWallet = class {
|
|
|
1621
1651
|
words: options.key.words
|
|
1622
1652
|
}
|
|
1623
1653
|
});
|
|
1624
|
-
this.getAddressesFromWallet(this._wallet);
|
|
1625
1654
|
break;
|
|
1626
1655
|
case "bip32Bytes":
|
|
1627
1656
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1631,7 +1660,6 @@ var MeshWallet = class {
|
|
|
1631
1660
|
bip32Bytes: options.key.bip32Bytes
|
|
1632
1661
|
}
|
|
1633
1662
|
});
|
|
1634
|
-
this.getAddressesFromWallet(this._wallet);
|
|
1635
1663
|
break;
|
|
1636
1664
|
case "address":
|
|
1637
1665
|
this._wallet = null;
|
|
@@ -1639,6 +1667,16 @@ var MeshWallet = class {
|
|
|
1639
1667
|
break;
|
|
1640
1668
|
}
|
|
1641
1669
|
}
|
|
1670
|
+
/**
|
|
1671
|
+
* Initializes the wallet. This is a required call as fetching addresses from the wallet is an async operation.
|
|
1672
|
+
* @returns void
|
|
1673
|
+
*/
|
|
1674
|
+
async init() {
|
|
1675
|
+
if (this._wallet && !this._wallet.cryptoIsReady) {
|
|
1676
|
+
await this._wallet.init();
|
|
1677
|
+
this.getAddressesFromWallet(this._wallet);
|
|
1678
|
+
}
|
|
1679
|
+
}
|
|
1642
1680
|
/**
|
|
1643
1681
|
* Returns all derived addresses from the wallet.
|
|
1644
1682
|
* @returns a list of addresses
|
|
@@ -1654,6 +1692,7 @@ var MeshWallet = class {
|
|
|
1654
1692
|
* @returns a list of assets and their quantities
|
|
1655
1693
|
*/
|
|
1656
1694
|
async getBalance() {
|
|
1695
|
+
await this.init();
|
|
1657
1696
|
const utxos = await this.getUnspentOutputs();
|
|
1658
1697
|
const assets = /* @__PURE__ */ new Map();
|
|
1659
1698
|
utxos.map((utxo) => {
|
|
@@ -1680,8 +1719,24 @@ var MeshWallet = class {
|
|
|
1680
1719
|
*
|
|
1681
1720
|
* @returns an address
|
|
1682
1721
|
*/
|
|
1683
|
-
getChangeAddress() {
|
|
1684
|
-
|
|
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();
|
|
1685
1740
|
}
|
|
1686
1741
|
/**
|
|
1687
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).
|
|
@@ -1692,11 +1747,27 @@ var MeshWallet = class {
|
|
|
1692
1747
|
* @returns a list of UTXOs
|
|
1693
1748
|
*/
|
|
1694
1749
|
async getCollateral(addressType = "payment") {
|
|
1750
|
+
await this.init();
|
|
1695
1751
|
const utxos = await this.getCollateralUnspentOutput(addressType);
|
|
1696
1752
|
return utxos.map((utxo, i) => {
|
|
1697
1753
|
return (0, import_core_cst5.fromTxUnspentOutput)(utxo);
|
|
1698
1754
|
});
|
|
1699
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
|
+
}
|
|
1700
1771
|
/**
|
|
1701
1772
|
* Return a list of supported CIPs of the wallet.
|
|
1702
1773
|
*
|
|
@@ -1714,6 +1785,7 @@ var MeshWallet = class {
|
|
|
1714
1785
|
* @returns a list of UTXOs
|
|
1715
1786
|
*/
|
|
1716
1787
|
async getCollateralUnspentOutput(addressType = "payment") {
|
|
1788
|
+
await this.init();
|
|
1717
1789
|
const utxos = await this.getUnspentOutputs(addressType);
|
|
1718
1790
|
const pureAdaUtxos = utxos.filter((utxo) => {
|
|
1719
1791
|
return utxo.output().amount().multiasset() === void 0;
|
|
@@ -1732,10 +1804,16 @@ var MeshWallet = class {
|
|
|
1732
1804
|
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
1733
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.
|
|
1734
1806
|
*
|
|
1735
|
-
* @returns
|
|
1807
|
+
* @returns DRep object
|
|
1736
1808
|
*/
|
|
1737
1809
|
async getDRep() {
|
|
1738
|
-
|
|
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
|
+
};
|
|
1739
1817
|
return void 0;
|
|
1740
1818
|
}
|
|
1741
1819
|
/**
|
|
@@ -1754,13 +1832,28 @@ var MeshWallet = class {
|
|
|
1754
1832
|
async getRewardAddresses() {
|
|
1755
1833
|
return [this.addresses.rewardAddressBech32];
|
|
1756
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
|
+
}
|
|
1757
1842
|
/**
|
|
1758
1843
|
* Returns a list of unused addresses controlled by the wallet.
|
|
1759
1844
|
*
|
|
1760
1845
|
* @returns a list of unused addresses
|
|
1761
1846
|
*/
|
|
1762
1847
|
async getUnusedAddresses() {
|
|
1763
|
-
return [this.getChangeAddress()];
|
|
1848
|
+
return [await this.getChangeAddress()];
|
|
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()];
|
|
1764
1857
|
}
|
|
1765
1858
|
/**
|
|
1766
1859
|
* Returns a list of used addresses controlled by the wallet.
|
|
@@ -1768,7 +1861,15 @@ var MeshWallet = class {
|
|
|
1768
1861
|
* @returns a list of used addresses
|
|
1769
1862
|
*/
|
|
1770
1863
|
async getUsedAddresses() {
|
|
1771
|
-
return [this.getChangeAddress()];
|
|
1864
|
+
return [await this.getChangeAddress()];
|
|
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()];
|
|
1772
1873
|
}
|
|
1773
1874
|
/**
|
|
1774
1875
|
* Get a list of UTXOs to be used for transaction building.
|
|
@@ -1779,6 +1880,7 @@ var MeshWallet = class {
|
|
|
1779
1880
|
* @returns a list of UTXOs
|
|
1780
1881
|
*/
|
|
1781
1882
|
async getUsedUTxOs(addressType = "payment") {
|
|
1883
|
+
await this.init();
|
|
1782
1884
|
return await this.getUnspentOutputs(addressType);
|
|
1783
1885
|
}
|
|
1784
1886
|
/**
|
|
@@ -1791,6 +1893,16 @@ var MeshWallet = class {
|
|
|
1791
1893
|
const utxos = await this.getUsedUTxOs(addressType);
|
|
1792
1894
|
return utxos.map((c) => (0, import_core_cst5.fromTxUnspentOutput)(c));
|
|
1793
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
|
+
}
|
|
1794
1906
|
/**
|
|
1795
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.
|
|
1796
1908
|
*
|
|
@@ -1799,13 +1911,14 @@ var MeshWallet = class {
|
|
|
1799
1911
|
* @returns a signature
|
|
1800
1912
|
*/
|
|
1801
1913
|
async signData(payload, address) {
|
|
1914
|
+
await this.init();
|
|
1802
1915
|
if (!this._wallet) {
|
|
1803
1916
|
throw new Error(
|
|
1804
1917
|
"[MeshWallet] Read only wallet does not support signing data."
|
|
1805
1918
|
);
|
|
1806
1919
|
}
|
|
1807
1920
|
if (address === void 0) {
|
|
1808
|
-
address = this.getChangeAddress();
|
|
1921
|
+
address = await this.getChangeAddress();
|
|
1809
1922
|
}
|
|
1810
1923
|
return this._wallet.signData(
|
|
1811
1924
|
address,
|
|
@@ -1819,9 +1932,11 @@ var MeshWallet = class {
|
|
|
1819
1932
|
*
|
|
1820
1933
|
* @param unsignedTx - a transaction in CBOR
|
|
1821
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)
|
|
1822
1936
|
* @returns a signed transaction in CBOR
|
|
1823
1937
|
*/
|
|
1824
|
-
async signTx(unsignedTx, partialSign = false) {
|
|
1938
|
+
async signTx(unsignedTx, partialSign = false, returnFullTx = true) {
|
|
1939
|
+
await this.init();
|
|
1825
1940
|
if (!this._wallet) {
|
|
1826
1941
|
throw new Error(
|
|
1827
1942
|
"[MeshWallet] Read only wallet does not support signing data."
|
|
@@ -1835,8 +1950,19 @@ var MeshWallet = class {
|
|
|
1835
1950
|
const newSignatures = this._wallet.signTx(
|
|
1836
1951
|
unsignedTx,
|
|
1837
1952
|
this._accountIndex,
|
|
1838
|
-
this._keyIndex
|
|
1953
|
+
this._keyIndex,
|
|
1954
|
+
this._accountType
|
|
1839
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
|
+
}
|
|
1840
1966
|
let signedTx = EmbeddedWallet.addWitnessSets(unsignedTx, [newSignatures]);
|
|
1841
1967
|
return signedTx;
|
|
1842
1968
|
}
|
|
@@ -1847,7 +1973,8 @@ var MeshWallet = class {
|
|
|
1847
1973
|
* @param partialSign - if the transactions are signed partially
|
|
1848
1974
|
* @returns array of signed transactions CborHex string
|
|
1849
1975
|
*/
|
|
1850
|
-
async signTxs(unsignedTxs, partialSign = false) {
|
|
1976
|
+
async signTxs(unsignedTxs, partialSign = false, returnFullTx = true) {
|
|
1977
|
+
await this.init();
|
|
1851
1978
|
if (!this._wallet) {
|
|
1852
1979
|
throw new Error(
|
|
1853
1980
|
"[MeshWallet] Read only wallet does not support signing data."
|
|
@@ -1855,7 +1982,7 @@ var MeshWallet = class {
|
|
|
1855
1982
|
}
|
|
1856
1983
|
const signedTxs = [];
|
|
1857
1984
|
for (const unsignedTx of unsignedTxs) {
|
|
1858
|
-
const signedTx = await this.signTx(unsignedTx, partialSign);
|
|
1985
|
+
const signedTx = await this.signTx(unsignedTx, partialSign, returnFullTx);
|
|
1859
1986
|
signedTxs.push(signedTx);
|
|
1860
1987
|
}
|
|
1861
1988
|
return signedTxs;
|
|
@@ -1863,7 +1990,7 @@ var MeshWallet = class {
|
|
|
1863
1990
|
/**
|
|
1864
1991
|
* Submits the signed transaction to the blockchain network.
|
|
1865
1992
|
*
|
|
1866
|
-
* 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.
|
|
1867
1994
|
*
|
|
1868
1995
|
* @param tx - a signed transaction in CBOR
|
|
1869
1996
|
* @returns a transaction hash
|
|
@@ -1976,7 +2103,7 @@ var MeshWallet = class {
|
|
|
1976
2103
|
*/
|
|
1977
2104
|
async createCollateral() {
|
|
1978
2105
|
const tx = new import_transaction.Transaction({ initiator: this });
|
|
1979
|
-
tx.sendLovelace(this.getChangeAddress(), "5000000");
|
|
2106
|
+
tx.sendLovelace(await this.getChangeAddress(), "5000000");
|
|
1980
2107
|
const unsignedTx = await tx.build();
|
|
1981
2108
|
const signedTx = await this.signTx(unsignedTx);
|
|
1982
2109
|
const txHash = await this.submitTx(signedTx);
|
|
@@ -1986,7 +2113,8 @@ var MeshWallet = class {
|
|
|
1986
2113
|
return {
|
|
1987
2114
|
pubDRepKey: this.addresses.pubDRepKey,
|
|
1988
2115
|
dRepIDBech32: this.addresses.dRepIDBech32,
|
|
1989
|
-
dRepIDHash: this.addresses.dRepIDHash
|
|
2116
|
+
dRepIDHash: this.addresses.dRepIDHash,
|
|
2117
|
+
dRepIDCip105: this.addresses.dRepIDCip105
|
|
1990
2118
|
};
|
|
1991
2119
|
}
|
|
1992
2120
|
/**
|
|
@@ -2013,7 +2141,8 @@ var MeshWallet = class {
|
|
|
2013
2141
|
rewardAddressBech32: account.rewardAddressBech32,
|
|
2014
2142
|
pubDRepKey: account.pubDRepKey,
|
|
2015
2143
|
dRepIDBech32: account.dRepIDBech32,
|
|
2016
|
-
dRepIDHash: account.dRepIDHash
|
|
2144
|
+
dRepIDHash: account.dRepIDHash,
|
|
2145
|
+
dRepIDCip105: account.dRepIDCip105
|
|
2017
2146
|
};
|
|
2018
2147
|
}
|
|
2019
2148
|
buildAddressFromBech32Address(address) {
|
|
@@ -2035,24 +2164,22 @@ var MeshWallet = class {
|
|
|
2035
2164
|
if (pubKeyHash && stakeKeyHash) {
|
|
2036
2165
|
this.addresses.baseAddress = (0, import_core_cst5.buildBaseAddress)(
|
|
2037
2166
|
this._networkId,
|
|
2038
|
-
|
|
2039
|
-
import_core_cst5.Hash28ByteBase16
|
|
2040
|
-
(0, import_core_cst5.Ed25519KeyHashHex)((0, import_core_cst5.Ed25519KeyHashHex)(stakeKeyHash))
|
|
2041
|
-
)
|
|
2167
|
+
(0, import_core_cst5.Hash28ByteBase16)(pubKeyHash),
|
|
2168
|
+
(0, import_core_cst5.Hash28ByteBase16)(stakeKeyHash)
|
|
2042
2169
|
).toAddress();
|
|
2043
2170
|
this.addresses.baseAddressBech32 = this.addresses.baseAddress.toBech32();
|
|
2044
2171
|
}
|
|
2045
2172
|
if (pubKeyHash) {
|
|
2046
2173
|
this.addresses.enterpriseAddress = (0, import_core_cst5.buildEnterpriseAddress)(
|
|
2047
2174
|
this._networkId,
|
|
2048
|
-
import_core_cst5.Hash28ByteBase16
|
|
2175
|
+
(0, import_core_cst5.Hash28ByteBase16)((0, import_core_cst5.Ed25519KeyHashHex)(pubKeyHash))
|
|
2049
2176
|
).toAddress();
|
|
2050
2177
|
this.addresses.enterpriseAddressBech32 = this.addresses.enterpriseAddress.toBech32();
|
|
2051
2178
|
}
|
|
2052
2179
|
if (stakeKeyHash) {
|
|
2053
2180
|
this.addresses.rewardAddress = (0, import_core_cst5.buildRewardAddress)(
|
|
2054
2181
|
this._networkId,
|
|
2055
|
-
|
|
2182
|
+
(0, import_core_cst5.Hash28ByteBase16)(stakeKeyHash)
|
|
2056
2183
|
).toAddress();
|
|
2057
2184
|
this.addresses.rewardAddressBech32 = this.addresses.rewardAddress.toBech32();
|
|
2058
2185
|
}
|