@meshsdk/wallet 1.6.3 → 1.6.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/index.cjs +155 -71
- package/dist/index.d.cts +56 -13
- package/dist/index.d.ts +56 -13
- package/dist/index.js +161 -75
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -286,23 +286,40 @@ var WalletStaticMethods = class {
|
|
|
286
286
|
import_core_cst.Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
287
287
|
(0, import_core_cst.Ed25519KeyHashHex)(stakingKey.toPublicKey().hash().toString("hex"))
|
|
288
288
|
)
|
|
289
|
-
);
|
|
289
|
+
).toAddress();
|
|
290
290
|
const enterpriseAddress = (0, import_core_cst.buildEnterpriseAddress)(
|
|
291
291
|
networkId,
|
|
292
292
|
import_core_cst.Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
293
293
|
(0, import_core_cst.Ed25519KeyHashHex)(paymentKey.toPublicKey().hash().toString("hex"))
|
|
294
294
|
)
|
|
295
|
-
);
|
|
295
|
+
).toAddress();
|
|
296
296
|
const rewardAddress = (0, import_core_cst.buildRewardAddress)(
|
|
297
297
|
networkId,
|
|
298
298
|
import_core_cst.Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
299
299
|
(0, import_core_cst.Ed25519KeyHashHex)(stakingKey.toPublicKey().hash().toString("hex"))
|
|
300
300
|
)
|
|
301
|
+
).toAddress();
|
|
302
|
+
return {
|
|
303
|
+
baseAddress,
|
|
304
|
+
enterpriseAddress,
|
|
305
|
+
rewardAddress
|
|
306
|
+
};
|
|
307
|
+
}
|
|
308
|
+
static getDRepKey(dRepKey, networkId = 0) {
|
|
309
|
+
const pubKey = dRepKey.toPublicKey().pubKey;
|
|
310
|
+
const pubDRepKey = pubKey.toString("hex");
|
|
311
|
+
const dRepIDBech32 = (0, import_core_cst.buildDRepID)(
|
|
312
|
+
(0, import_core_cst.Ed25519PublicKeyHex)(pubDRepKey),
|
|
313
|
+
networkId
|
|
314
|
+
);
|
|
315
|
+
const dRep = import_core_cst.DRep.newKeyHash(
|
|
316
|
+
(0, import_core_cst.Ed25519KeyHashHex)(dRepKey.toPublicKey().hash().toString("hex"))
|
|
301
317
|
);
|
|
318
|
+
const dRepIDHash = dRep.toKeyHash();
|
|
302
319
|
return {
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
320
|
+
pubDRepKey,
|
|
321
|
+
dRepIDBech32,
|
|
322
|
+
dRepIDHash
|
|
306
323
|
};
|
|
307
324
|
}
|
|
308
325
|
static generateMnemonic(strength = 256) {
|
|
@@ -351,13 +368,13 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
351
368
|
getAccount(accountIndex = 0, keyIndex = 0) {
|
|
352
369
|
if (this._entropy == void 0)
|
|
353
370
|
throw new Error("[EmbeddedWallet] No keys initialized");
|
|
354
|
-
const { paymentKey, stakeKey } = (0, import_core_cst.buildKeys)(
|
|
371
|
+
const { paymentKey, stakeKey, dRepKey } = (0, import_core_cst.buildKeys)(
|
|
355
372
|
this._entropy,
|
|
356
373
|
accountIndex,
|
|
357
374
|
keyIndex
|
|
358
375
|
);
|
|
359
376
|
const { baseAddress, enterpriseAddress, rewardAddress } = WalletStaticMethods.getAddresses(paymentKey, stakeKey, this._networkId);
|
|
360
|
-
|
|
377
|
+
let _account = {
|
|
361
378
|
baseAddress,
|
|
362
379
|
enterpriseAddress,
|
|
363
380
|
rewardAddress,
|
|
@@ -369,25 +386,30 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
369
386
|
paymentKeyHex: paymentKey.toBytes().toString("hex"),
|
|
370
387
|
stakeKeyHex: stakeKey.toBytes().toString("hex")
|
|
371
388
|
};
|
|
389
|
+
if (dRepKey) {
|
|
390
|
+
const { pubDRepKey, dRepIDBech32, dRepIDHash } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
|
|
391
|
+
_account.pubDRepKey = pubDRepKey;
|
|
392
|
+
_account.dRepIDBech32 = dRepIDBech32;
|
|
393
|
+
_account.dRepIDHash = dRepIDHash;
|
|
394
|
+
}
|
|
395
|
+
return _account;
|
|
372
396
|
}
|
|
373
397
|
getNetworkId() {
|
|
374
398
|
return this._networkId;
|
|
375
399
|
}
|
|
376
400
|
signData(address, payload, accountIndex = 0, keyIndex = 0) {
|
|
377
401
|
try {
|
|
378
|
-
const
|
|
379
|
-
const foundAddress = [
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
account.rewardAddress
|
|
383
|
-
].find((a) => a.toBech32() === address);
|
|
402
|
+
const { baseAddress, enterpriseAddress, rewardAddress, paymentKey } = this.getAccount(accountIndex, keyIndex);
|
|
403
|
+
const foundAddress = [baseAddress, enterpriseAddress, rewardAddress].find(
|
|
404
|
+
(a) => a.toBech32() === address
|
|
405
|
+
);
|
|
384
406
|
if (foundAddress === void 0)
|
|
385
407
|
throw new Error(
|
|
386
408
|
`[EmbeddedWallet] Address: ${address} doesn't belong to this account.`
|
|
387
409
|
);
|
|
388
410
|
return (0, import_core_cst.signData)(payload, {
|
|
389
411
|
address: import_core_cst.Address.fromBech32(address),
|
|
390
|
-
key:
|
|
412
|
+
key: paymentKey
|
|
391
413
|
});
|
|
392
414
|
} catch (error) {
|
|
393
415
|
throw new Error(
|
|
@@ -398,13 +420,11 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
398
420
|
signTx(unsignedTx, accountIndex = 0, keyIndex = 0) {
|
|
399
421
|
try {
|
|
400
422
|
const txHash = (0, import_core_cst.deserializeTxHash)((0, import_core_cst.resolveTxHash)(unsignedTx));
|
|
401
|
-
const
|
|
423
|
+
const { paymentKey } = this.getAccount(accountIndex, keyIndex);
|
|
402
424
|
const vKeyWitness = new import_core_cst.VkeyWitness(
|
|
403
|
-
(0, import_core_cst.Ed25519PublicKeyHex)(
|
|
404
|
-
account.paymentKey.toPublicKey().toBytes().toString("hex")
|
|
405
|
-
),
|
|
425
|
+
(0, import_core_cst.Ed25519PublicKeyHex)(paymentKey.toPublicKey().toBytes().toString("hex")),
|
|
406
426
|
(0, import_core_cst.Ed25519SignatureHex)(
|
|
407
|
-
|
|
427
|
+
paymentKey.sign(Buffer.from(txHash, "hex")).toString("hex")
|
|
408
428
|
)
|
|
409
429
|
);
|
|
410
430
|
return vKeyWitness;
|
|
@@ -809,6 +829,9 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
809
829
|
*/
|
|
810
830
|
async signTx(unsignedTx, partialSign = false) {
|
|
811
831
|
const witness = await this._walletInstance.signTx(unsignedTx, partialSign);
|
|
832
|
+
if (witness === "") {
|
|
833
|
+
return unsignedTx;
|
|
834
|
+
}
|
|
812
835
|
return _BrowserWallet.addBrowserWitnesses(unsignedTx, witness);
|
|
813
836
|
}
|
|
814
837
|
/**
|
|
@@ -852,8 +875,15 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
852
875
|
for (let i = 0; i < witnessSets.length; i++) {
|
|
853
876
|
const unsignedTx = unsignedTxs[i];
|
|
854
877
|
const cWitness = witnessSets[i];
|
|
855
|
-
|
|
856
|
-
|
|
878
|
+
if (cWitness === "") {
|
|
879
|
+
signedTxs.push(unsignedTx);
|
|
880
|
+
} else {
|
|
881
|
+
const signedTx = _BrowserWallet.addBrowserWitnesses(
|
|
882
|
+
unsignedTx,
|
|
883
|
+
cWitness
|
|
884
|
+
);
|
|
885
|
+
signedTxs.push(signedTx);
|
|
886
|
+
}
|
|
857
887
|
}
|
|
858
888
|
return signedTxs;
|
|
859
889
|
}
|
|
@@ -953,23 +983,27 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
953
983
|
new Set(balance.map((v) => v.unit.slice(0, import_common2.POLICY_ID_LENGTH)))
|
|
954
984
|
).filter((p) => p !== "lovelace");
|
|
955
985
|
}
|
|
986
|
+
/**
|
|
987
|
+
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
988
|
+
* 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.
|
|
989
|
+
*
|
|
990
|
+
* @returns wallet account's public DRep Key
|
|
991
|
+
*/
|
|
956
992
|
async getPubDRepKey() {
|
|
957
993
|
try {
|
|
958
994
|
if (this._walletInstance.cip95 === void 0) return void 0;
|
|
959
995
|
const dRepKey = await this._walletInstance.cip95.getPubDRepKey();
|
|
960
|
-
const dRepKeyHex =
|
|
961
|
-
const dRepID = import_core_cst3.Ed25519PublicKey.fromHex(dRepKeyHex);
|
|
962
|
-
const dRepIDHex = (await dRepID.hash()).hex();
|
|
996
|
+
const { dRepKeyHex, dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(dRepKey);
|
|
963
997
|
const networkId = await this.getNetworkId();
|
|
964
998
|
const dRepId = (0, import_core_cst3.buildDRepID)(dRepKeyHex, networkId);
|
|
965
999
|
return {
|
|
966
1000
|
pubDRepKey: dRepKey,
|
|
967
|
-
dRepIDHash
|
|
1001
|
+
dRepIDHash,
|
|
968
1002
|
dRepIDBech32: dRepId
|
|
969
1003
|
// todo to check
|
|
970
1004
|
};
|
|
971
1005
|
} catch (e) {
|
|
972
|
-
console.
|
|
1006
|
+
console.error(e);
|
|
973
1007
|
return void 0;
|
|
974
1008
|
}
|
|
975
1009
|
}
|
|
@@ -979,10 +1013,27 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
979
1013
|
const pubStakeKeys = await this._walletInstance.cip95.getRegisteredPubStakeKeys();
|
|
980
1014
|
const pubStakeKeyHashes = await Promise.all(
|
|
981
1015
|
pubStakeKeys.map(async (pubStakeKey) => {
|
|
982
|
-
const
|
|
983
|
-
|
|
984
|
-
|
|
985
|
-
|
|
1016
|
+
const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(pubStakeKey);
|
|
1017
|
+
return dRepIDHash;
|
|
1018
|
+
})
|
|
1019
|
+
);
|
|
1020
|
+
return {
|
|
1021
|
+
pubStakeKeys,
|
|
1022
|
+
pubStakeKeyHashes
|
|
1023
|
+
};
|
|
1024
|
+
} catch (e) {
|
|
1025
|
+
console.error(e);
|
|
1026
|
+
return void 0;
|
|
1027
|
+
}
|
|
1028
|
+
}
|
|
1029
|
+
async getUnregisteredPubStakeKeys() {
|
|
1030
|
+
try {
|
|
1031
|
+
if (this._walletInstance.cip95 === void 0) return void 0;
|
|
1032
|
+
const pubStakeKeys = await this._walletInstance.cip95.getUnregisteredPubStakeKeys();
|
|
1033
|
+
const pubStakeKeyHashes = await Promise.all(
|
|
1034
|
+
pubStakeKeys.map(async (pubStakeKey) => {
|
|
1035
|
+
const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(pubStakeKey);
|
|
1036
|
+
return dRepIDHash;
|
|
986
1037
|
})
|
|
987
1038
|
);
|
|
988
1039
|
return {
|
|
@@ -990,10 +1041,20 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
990
1041
|
pubStakeKeyHashes
|
|
991
1042
|
};
|
|
992
1043
|
} catch (e) {
|
|
993
|
-
console.
|
|
1044
|
+
console.error(e);
|
|
994
1045
|
return void 0;
|
|
995
1046
|
}
|
|
996
1047
|
}
|
|
1048
|
+
static async dRepKeyToDRepID(dRepKey) {
|
|
1049
|
+
const dRepKeyHex = (0, import_core_cst3.Ed25519PublicKeyHex)(dRepKey);
|
|
1050
|
+
const dRepID = import_core_cst3.Ed25519PublicKey.fromHex(dRepKeyHex);
|
|
1051
|
+
const dRepIDHash = (await dRepID.hash()).hex();
|
|
1052
|
+
return {
|
|
1053
|
+
dRepKeyHex,
|
|
1054
|
+
dRepID,
|
|
1055
|
+
dRepIDHash
|
|
1056
|
+
};
|
|
1057
|
+
}
|
|
997
1058
|
static resolveInstance(walletName, extensions = []) {
|
|
998
1059
|
if (window.cardano === void 0) return void 0;
|
|
999
1060
|
if (window.cardano[walletName] === void 0) return void 0;
|
|
@@ -1038,14 +1099,14 @@ var import_core_cst4 = require("@meshsdk/core-cst");
|
|
|
1038
1099
|
var import_transaction = require("@meshsdk/transaction");
|
|
1039
1100
|
var MeshWallet = class {
|
|
1040
1101
|
_wallet;
|
|
1041
|
-
// private readonly _account: Account;
|
|
1042
1102
|
_accountIndex = 0;
|
|
1043
1103
|
_keyIndex = 0;
|
|
1044
1104
|
_fetcher;
|
|
1045
1105
|
_submitter;
|
|
1046
1106
|
_networkId;
|
|
1047
|
-
|
|
1107
|
+
addresses = {};
|
|
1048
1108
|
constructor(options) {
|
|
1109
|
+
this._networkId = options.networkId;
|
|
1049
1110
|
switch (options.key.type) {
|
|
1050
1111
|
case "root":
|
|
1051
1112
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1078,8 +1139,11 @@ var MeshWallet = class {
|
|
|
1078
1139
|
});
|
|
1079
1140
|
this.getAddressesFromWallet(this._wallet);
|
|
1080
1141
|
break;
|
|
1142
|
+
case "address":
|
|
1143
|
+
this._wallet = null;
|
|
1144
|
+
this.buildAddressFromBech32Address(options.key.address);
|
|
1145
|
+
break;
|
|
1081
1146
|
}
|
|
1082
|
-
this._networkId = options.networkId;
|
|
1083
1147
|
if (options.fetcher) this._fetcher = options.fetcher;
|
|
1084
1148
|
if (options.submitter) this._submitter = options.submitter;
|
|
1085
1149
|
if (options.accountIndex) this._accountIndex = options.accountIndex;
|
|
@@ -1120,7 +1184,7 @@ var MeshWallet = class {
|
|
|
1120
1184
|
* @returns an address
|
|
1121
1185
|
*/
|
|
1122
1186
|
getChangeAddress() {
|
|
1123
|
-
return this.
|
|
1187
|
+
return this.addresses.baseAddressBech32 ? this.addresses.baseAddressBech32 : this.addresses.enterpriseAddressBech32;
|
|
1124
1188
|
}
|
|
1125
1189
|
/**
|
|
1126
1190
|
* 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).
|
|
@@ -1173,7 +1237,7 @@ var MeshWallet = class {
|
|
|
1173
1237
|
* @returns a list of reward addresses
|
|
1174
1238
|
*/
|
|
1175
1239
|
getRewardAddresses() {
|
|
1176
|
-
return [this.
|
|
1240
|
+
return [this.addresses.rewardAddressBech32];
|
|
1177
1241
|
}
|
|
1178
1242
|
/**
|
|
1179
1243
|
* Returns a list of unused addresses controlled by the wallet.
|
|
@@ -1213,7 +1277,7 @@ var MeshWallet = class {
|
|
|
1213
1277
|
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1214
1278
|
* @returns a list of UTXOs
|
|
1215
1279
|
*/
|
|
1216
|
-
async getUsedUTxOs(addressType) {
|
|
1280
|
+
async getUsedUTxOs(addressType = "payment") {
|
|
1217
1281
|
return await this.getUnspentOutputs(addressType);
|
|
1218
1282
|
}
|
|
1219
1283
|
/**
|
|
@@ -1222,7 +1286,7 @@ var MeshWallet = class {
|
|
|
1222
1286
|
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1223
1287
|
* @returns a list of UTXOs
|
|
1224
1288
|
*/
|
|
1225
|
-
async getUtxos(addressType) {
|
|
1289
|
+
async getUtxos(addressType = "payment") {
|
|
1226
1290
|
const utxos = await this.getUsedUTxOs(addressType);
|
|
1227
1291
|
return utxos.map((c) => (0, import_core_cst4.fromTxUnspentOutput)(c));
|
|
1228
1292
|
}
|
|
@@ -1278,6 +1342,11 @@ var MeshWallet = class {
|
|
|
1278
1342
|
* @returns array of signed transactions CborHex string
|
|
1279
1343
|
*/
|
|
1280
1344
|
signTxs(unsignedTxs, partialSign = false) {
|
|
1345
|
+
if (!this._wallet) {
|
|
1346
|
+
throw new Error(
|
|
1347
|
+
"[MeshWallet] Read only wallet does not support signing data."
|
|
1348
|
+
);
|
|
1349
|
+
}
|
|
1281
1350
|
const signedTxs = [];
|
|
1282
1351
|
for (const unsignedTx of unsignedTxs) {
|
|
1283
1352
|
const signedTx = this.signTx(unsignedTx, partialSign);
|
|
@@ -1296,7 +1365,7 @@ var MeshWallet = class {
|
|
|
1296
1365
|
async submitTx(tx) {
|
|
1297
1366
|
if (!this._submitter) {
|
|
1298
1367
|
throw new Error(
|
|
1299
|
-
"[
|
|
1368
|
+
"[MeshWallet] Submitter is required to submit transactions. Please provide a submitter."
|
|
1300
1369
|
);
|
|
1301
1370
|
}
|
|
1302
1371
|
return this._submitter.submitTx(tx);
|
|
@@ -1309,11 +1378,11 @@ var MeshWallet = class {
|
|
|
1309
1378
|
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1310
1379
|
* @returns an Address object
|
|
1311
1380
|
*/
|
|
1312
|
-
getUsedAddress(addressType) {
|
|
1313
|
-
if (addressType === "
|
|
1314
|
-
return (0, import_core_cst4.toAddress)(this.
|
|
1381
|
+
getUsedAddress(addressType = "payment") {
|
|
1382
|
+
if (this.addresses.baseAddressBech32 && addressType === "payment") {
|
|
1383
|
+
return (0, import_core_cst4.toAddress)(this.addresses.baseAddressBech32);
|
|
1315
1384
|
} else {
|
|
1316
|
-
return (0, import_core_cst4.toAddress)(this.
|
|
1385
|
+
return (0, import_core_cst4.toAddress)(this.addresses.enterpriseAddressBech32);
|
|
1317
1386
|
}
|
|
1318
1387
|
}
|
|
1319
1388
|
/**
|
|
@@ -1324,14 +1393,14 @@ var MeshWallet = class {
|
|
|
1324
1393
|
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1325
1394
|
* @returns a list of UTXOs
|
|
1326
1395
|
*/
|
|
1327
|
-
async getUnspentOutputs(addressType) {
|
|
1396
|
+
async getUnspentOutputs(addressType = "payment") {
|
|
1328
1397
|
if (!this._fetcher) {
|
|
1329
1398
|
throw new Error(
|
|
1330
|
-
"[
|
|
1399
|
+
"[MeshWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher."
|
|
1331
1400
|
);
|
|
1332
1401
|
}
|
|
1333
1402
|
const utxos = await this._fetcher.fetchAddressUTxOs(
|
|
1334
|
-
addressType == "
|
|
1403
|
+
this.addresses.baseAddressBech32 && addressType == "payment" ? this.addresses.baseAddressBech32 : this.addresses.enterpriseAddressBech32
|
|
1335
1404
|
);
|
|
1336
1405
|
return utxos.map((utxo) => (0, import_core_cst4.toTxUnspentOutput)(utxo));
|
|
1337
1406
|
}
|
|
@@ -1399,6 +1468,13 @@ var MeshWallet = class {
|
|
|
1399
1468
|
const txHash = await this.submitTx(signedTx);
|
|
1400
1469
|
return txHash;
|
|
1401
1470
|
}
|
|
1471
|
+
getPubDRepKey() {
|
|
1472
|
+
return {
|
|
1473
|
+
pubDRepKey: this.addresses.pubDRepKey,
|
|
1474
|
+
dRepIDBech32: this.addresses.dRepIDBech32,
|
|
1475
|
+
dRepIDHash: this.addresses.dRepIDHash
|
|
1476
|
+
};
|
|
1477
|
+
}
|
|
1402
1478
|
/**
|
|
1403
1479
|
* Generate mnemonic or private key
|
|
1404
1480
|
*
|
|
@@ -1414,49 +1490,57 @@ var MeshWallet = class {
|
|
|
1414
1490
|
}
|
|
1415
1491
|
getAddressesFromWallet(wallet) {
|
|
1416
1492
|
const account = wallet.getAccount(this._accountIndex, this._keyIndex);
|
|
1417
|
-
this.
|
|
1493
|
+
this.addresses = {
|
|
1418
1494
|
baseAddress: account.baseAddress,
|
|
1419
1495
|
enterpriseAddress: account.enterpriseAddress,
|
|
1420
1496
|
rewardAddress: account.rewardAddress,
|
|
1421
1497
|
baseAddressBech32: account.baseAddressBech32,
|
|
1422
1498
|
enterpriseAddressBech32: account.enterpriseAddressBech32,
|
|
1423
|
-
rewardAddressBech32: account.rewardAddressBech32
|
|
1499
|
+
rewardAddressBech32: account.rewardAddressBech32,
|
|
1500
|
+
pubDRepKey: account.pubDRepKey,
|
|
1501
|
+
dRepIDBech32: account.dRepIDBech32,
|
|
1502
|
+
dRepIDHash: account.dRepIDHash
|
|
1424
1503
|
};
|
|
1425
1504
|
}
|
|
1426
1505
|
buildAddressFromBech32Address(address) {
|
|
1427
|
-
|
|
1428
|
-
|
|
1429
|
-
|
|
1430
|
-
|
|
1506
|
+
let pubKeyHash = void 0;
|
|
1507
|
+
let stakeKeyHash = void 0;
|
|
1508
|
+
const baseAddress = import_core_cst4.Address.fromBech32(address).asBase();
|
|
1509
|
+
if (baseAddress) {
|
|
1510
|
+
pubKeyHash = baseAddress.getPaymentCredential().hash;
|
|
1511
|
+
stakeKeyHash = baseAddress.getStakeCredential().hash;
|
|
1512
|
+
}
|
|
1513
|
+
const enterpriseAddress = import_core_cst4.Address.fromBech32(address).asEnterprise();
|
|
1514
|
+
if (enterpriseAddress) {
|
|
1515
|
+
pubKeyHash = enterpriseAddress.getPaymentCredential().hash;
|
|
1516
|
+
}
|
|
1517
|
+
const rewardAddress = import_core_cst4.Address.fromBech32(address).asReward();
|
|
1518
|
+
if (rewardAddress) {
|
|
1519
|
+
stakeKeyHash = rewardAddress.getPaymentCredential().hash;
|
|
1520
|
+
}
|
|
1521
|
+
if (pubKeyHash && stakeKeyHash) {
|
|
1522
|
+
this.addresses.baseAddress = (0, import_core_cst4.buildBaseAddress)(
|
|
1431
1523
|
this._networkId,
|
|
1524
|
+
import_core_cst4.Hash28ByteBase16.fromEd25519KeyHashHex((0, import_core_cst4.Ed25519KeyHashHex)(pubKeyHash)),
|
|
1432
1525
|
import_core_cst4.Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
1433
|
-
(0, import_core_cst4.Ed25519KeyHashHex)(
|
|
1434
|
-
),
|
|
1435
|
-
import_core_cst4.Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
1436
|
-
(0, import_core_cst4.Ed25519KeyHashHex)(
|
|
1437
|
-
(0, import_core_cst4.Ed25519KeyHashHex)(deserializedAddress.stakeCredentialHash)
|
|
1438
|
-
)
|
|
1526
|
+
(0, import_core_cst4.Ed25519KeyHashHex)((0, import_core_cst4.Ed25519KeyHashHex)(stakeKeyHash))
|
|
1439
1527
|
)
|
|
1440
1528
|
).toAddress();
|
|
1441
|
-
this.
|
|
1529
|
+
this.addresses.baseAddressBech32 = this.addresses.baseAddress.toBech32();
|
|
1442
1530
|
}
|
|
1443
|
-
if (
|
|
1444
|
-
this.
|
|
1531
|
+
if (pubKeyHash) {
|
|
1532
|
+
this.addresses.enterpriseAddress = (0, import_core_cst4.buildEnterpriseAddress)(
|
|
1445
1533
|
this._networkId,
|
|
1446
|
-
import_core_cst4.Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
1447
|
-
(0, import_core_cst4.Ed25519KeyHashHex)(deserializedAddress.pubKeyHash)
|
|
1448
|
-
)
|
|
1534
|
+
import_core_cst4.Hash28ByteBase16.fromEd25519KeyHashHex((0, import_core_cst4.Ed25519KeyHashHex)(pubKeyHash))
|
|
1449
1535
|
).toAddress();
|
|
1450
|
-
this.
|
|
1536
|
+
this.addresses.enterpriseAddressBech32 = this.addresses.enterpriseAddress.toBech32();
|
|
1451
1537
|
}
|
|
1452
|
-
if (
|
|
1453
|
-
this.
|
|
1538
|
+
if (stakeKeyHash) {
|
|
1539
|
+
this.addresses.rewardAddress = (0, import_core_cst4.buildRewardAddress)(
|
|
1454
1540
|
this._networkId,
|
|
1455
|
-
import_core_cst4.Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
1456
|
-
(0, import_core_cst4.Ed25519KeyHashHex)(deserializedAddress.stakeCredentialHash)
|
|
1457
|
-
)
|
|
1541
|
+
import_core_cst4.Hash28ByteBase16.fromEd25519KeyHashHex((0, import_core_cst4.Ed25519KeyHashHex)(stakeKeyHash))
|
|
1458
1542
|
).toAddress();
|
|
1459
|
-
this.
|
|
1543
|
+
this.addresses.rewardAddressBech32 = this.addresses.rewardAddress.toBech32();
|
|
1460
1544
|
}
|
|
1461
1545
|
}
|
|
1462
1546
|
};
|
package/dist/index.d.cts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataSignature, IFetcher, ISubmitter, ISigner, IInitiator, Wallet, Asset, UTxO, AssetExtended } from '@meshsdk/common';
|
|
2
|
-
import { TransactionUnspentOutput, Address, StricaPrivateKey, VkeyWitness } from '@meshsdk/core-cst';
|
|
2
|
+
import { Ed25519PublicKeyHex, TransactionUnspentOutput, Address, StricaPrivateKey, DRepID, Ed25519KeyHashHex, VkeyWitness } from '@meshsdk/core-cst';
|
|
3
3
|
|
|
4
4
|
type Cardano = {
|
|
5
5
|
[key: string]: {
|
|
@@ -20,7 +20,7 @@ type TransactionSignatureRequest = {
|
|
|
20
20
|
cbor: string;
|
|
21
21
|
partialSign: boolean;
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
interface Cip30WalletApi {
|
|
24
24
|
experimental: ExperimentalFeatures;
|
|
25
25
|
getBalance(): Promise<string>;
|
|
26
26
|
getChangeAddress(): Promise<string>;
|
|
@@ -37,12 +37,14 @@ type WalletInstance = {
|
|
|
37
37
|
signTxs?(txs: TransactionSignatureRequest[]): Promise<string[]>;
|
|
38
38
|
signTxs?(txs: string[], partialSign: boolean): Promise<string[]>;
|
|
39
39
|
submitTx(tx: string): Promise<string>;
|
|
40
|
-
cip95?:
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
cip95?: Cip95WalletApi;
|
|
41
|
+
}
|
|
42
|
+
interface Cip95WalletApi {
|
|
43
|
+
getRegisteredPubStakeKeys: () => Promise<Ed25519PublicKeyHex[]>;
|
|
44
|
+
getUnregisteredPubStakeKeys: () => Promise<Ed25519PublicKeyHex[]>;
|
|
45
|
+
getPubDRepKey: () => Promise<Ed25519PublicKeyHex>;
|
|
46
|
+
}
|
|
47
|
+
type WalletInstance = Cip30WalletApi & Cip95WalletApi;
|
|
46
48
|
type ExperimentalFeatures = {
|
|
47
49
|
getCollateral(): Promise<string[] | undefined>;
|
|
48
50
|
signTxs?(txs: TransactionSignatureRequest[]): Promise<string[]>;
|
|
@@ -285,6 +287,12 @@ declare class BrowserWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
285
287
|
* @returns a list of policy IDs
|
|
286
288
|
*/
|
|
287
289
|
getPolicyIds(): Promise<string[]>;
|
|
290
|
+
/**
|
|
291
|
+
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
292
|
+
* 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.
|
|
293
|
+
*
|
|
294
|
+
* @returns wallet account's public DRep Key
|
|
295
|
+
*/
|
|
288
296
|
getPubDRepKey(): Promise<{
|
|
289
297
|
pubDRepKey: string;
|
|
290
298
|
dRepIDHash: string;
|
|
@@ -294,6 +302,11 @@ declare class BrowserWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
294
302
|
pubStakeKeys: string[];
|
|
295
303
|
pubStakeKeyHashes: string[];
|
|
296
304
|
} | undefined>;
|
|
305
|
+
getUnregisteredPubStakeKeys(): Promise<{
|
|
306
|
+
pubStakeKeys: string[];
|
|
307
|
+
pubStakeKeyHashes: string[];
|
|
308
|
+
} | undefined>;
|
|
309
|
+
private static dRepKeyToDRepID;
|
|
297
310
|
private static resolveInstance;
|
|
298
311
|
static addBrowserWitnesses(unsignedTx: string, witnesses: string): string;
|
|
299
312
|
static getSupportedExtensions(wallet: string): {
|
|
@@ -312,6 +325,9 @@ type Account = {
|
|
|
312
325
|
stakeKey: StricaPrivateKey;
|
|
313
326
|
paymentKeyHex: string;
|
|
314
327
|
stakeKeyHex: string;
|
|
328
|
+
pubDRepKey?: string;
|
|
329
|
+
dRepIDBech32?: DRepID;
|
|
330
|
+
dRepIDHash?: Ed25519KeyHashHex;
|
|
315
331
|
};
|
|
316
332
|
type EmbeddedWalletKeyType = {
|
|
317
333
|
type: "root";
|
|
@@ -337,6 +353,11 @@ declare class WalletStaticMethods {
|
|
|
337
353
|
enterpriseAddress: Address;
|
|
338
354
|
rewardAddress: Address;
|
|
339
355
|
};
|
|
356
|
+
static getDRepKey(dRepKey: StricaPrivateKey, networkId?: number): {
|
|
357
|
+
pubDRepKey: string;
|
|
358
|
+
dRepIDBech32: DRepID;
|
|
359
|
+
dRepIDHash: Ed25519KeyHashHex;
|
|
360
|
+
};
|
|
340
361
|
static generateMnemonic(strength?: number): string[];
|
|
341
362
|
static addWitnessSets(txHex: string, witnesses: VkeyWitness[]): string;
|
|
342
363
|
}
|
|
@@ -364,6 +385,9 @@ type CreateMeshWalletOptions = {
|
|
|
364
385
|
} | {
|
|
365
386
|
type: "mnemonic";
|
|
366
387
|
words: string[];
|
|
388
|
+
} | {
|
|
389
|
+
type: "address";
|
|
390
|
+
address: string;
|
|
367
391
|
};
|
|
368
392
|
accountIndex?: number;
|
|
369
393
|
keyIndex?: number;
|
|
@@ -371,10 +395,14 @@ type CreateMeshWalletOptions = {
|
|
|
371
395
|
/**
|
|
372
396
|
* Mesh Wallet provides a set of APIs to interact with the blockchain. This wallet is compatible with Mesh transaction builders.
|
|
373
397
|
*
|
|
374
|
-
*
|
|
398
|
+
* There are 4 types of keys that can be used to create a wallet:
|
|
399
|
+
* - root: A private key in bech32 format, generally starts with `xprv1`
|
|
400
|
+
* - cli: CLI generated keys starts with `5820`. Payment key is required, and the stake key is optional.
|
|
401
|
+
* - mnemonic: A list of 24 words
|
|
402
|
+
* - address: A bech32 address that can be used to create a read-only wallet, generally starts with `addr` or `addr_test1`
|
|
375
403
|
*
|
|
376
404
|
* ```javascript
|
|
377
|
-
* import { MeshWallet, BlockfrostProvider } from '@
|
|
405
|
+
* import { MeshWallet, BlockfrostProvider } from '@meshsdk/core';
|
|
378
406
|
*
|
|
379
407
|
* const blockchainProvider = new BlockfrostProvider('<BLOCKFROST_API_KEY>');
|
|
380
408
|
*
|
|
@@ -396,7 +424,17 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
396
424
|
private readonly _fetcher?;
|
|
397
425
|
private readonly _submitter?;
|
|
398
426
|
private readonly _networkId;
|
|
399
|
-
|
|
427
|
+
addresses: {
|
|
428
|
+
baseAddress?: Address;
|
|
429
|
+
enterpriseAddress?: Address;
|
|
430
|
+
rewardAddress?: Address;
|
|
431
|
+
baseAddressBech32?: string;
|
|
432
|
+
enterpriseAddressBech32?: string;
|
|
433
|
+
rewardAddressBech32?: string;
|
|
434
|
+
pubDRepKey?: string;
|
|
435
|
+
dRepIDBech32?: DRepID;
|
|
436
|
+
dRepIDHash?: Ed25519KeyHashHex;
|
|
437
|
+
};
|
|
400
438
|
constructor(options: CreateMeshWalletOptions);
|
|
401
439
|
/**
|
|
402
440
|
* Returns a list of assets in the wallet. This API will return every assets in the wallet. Each asset is an object with the following properties:
|
|
@@ -560,6 +598,11 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
560
598
|
* @returns a transaction hash
|
|
561
599
|
*/
|
|
562
600
|
createCollateral(): Promise<string>;
|
|
601
|
+
getPubDRepKey(): {
|
|
602
|
+
pubDRepKey: string | undefined;
|
|
603
|
+
dRepIDBech32: string | undefined;
|
|
604
|
+
dRepIDHash: string | undefined;
|
|
605
|
+
};
|
|
563
606
|
/**
|
|
564
607
|
* Generate mnemonic or private key
|
|
565
608
|
*
|
|
@@ -567,8 +610,8 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
567
610
|
* @returns a transaction hash
|
|
568
611
|
*/
|
|
569
612
|
static brew(privateKey?: boolean, strength?: number): string[] | string;
|
|
570
|
-
getAddressesFromWallet
|
|
571
|
-
buildAddressFromBech32Address
|
|
613
|
+
private getAddressesFromWallet;
|
|
614
|
+
private buildAddressFromBech32Address;
|
|
572
615
|
}
|
|
573
616
|
|
|
574
617
|
export { type Account, AppWallet, type AppWalletKeyType, BrowserWallet, type CreateAppWalletOptions, type CreateEmbeddedWalletOptions, type CreateMeshWalletOptions, EmbeddedWallet, type EmbeddedWalletKeyType, MeshWallet, WalletStaticMethods };
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { DataSignature, IFetcher, ISubmitter, ISigner, IInitiator, Wallet, Asset, UTxO, AssetExtended } from '@meshsdk/common';
|
|
2
|
-
import { TransactionUnspentOutput, Address, StricaPrivateKey, VkeyWitness } from '@meshsdk/core-cst';
|
|
2
|
+
import { Ed25519PublicKeyHex, TransactionUnspentOutput, Address, StricaPrivateKey, DRepID, Ed25519KeyHashHex, VkeyWitness } from '@meshsdk/core-cst';
|
|
3
3
|
|
|
4
4
|
type Cardano = {
|
|
5
5
|
[key: string]: {
|
|
@@ -20,7 +20,7 @@ type TransactionSignatureRequest = {
|
|
|
20
20
|
cbor: string;
|
|
21
21
|
partialSign: boolean;
|
|
22
22
|
};
|
|
23
|
-
|
|
23
|
+
interface Cip30WalletApi {
|
|
24
24
|
experimental: ExperimentalFeatures;
|
|
25
25
|
getBalance(): Promise<string>;
|
|
26
26
|
getChangeAddress(): Promise<string>;
|
|
@@ -37,12 +37,14 @@ type WalletInstance = {
|
|
|
37
37
|
signTxs?(txs: TransactionSignatureRequest[]): Promise<string[]>;
|
|
38
38
|
signTxs?(txs: string[], partialSign: boolean): Promise<string[]>;
|
|
39
39
|
submitTx(tx: string): Promise<string>;
|
|
40
|
-
cip95?:
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
40
|
+
cip95?: Cip95WalletApi;
|
|
41
|
+
}
|
|
42
|
+
interface Cip95WalletApi {
|
|
43
|
+
getRegisteredPubStakeKeys: () => Promise<Ed25519PublicKeyHex[]>;
|
|
44
|
+
getUnregisteredPubStakeKeys: () => Promise<Ed25519PublicKeyHex[]>;
|
|
45
|
+
getPubDRepKey: () => Promise<Ed25519PublicKeyHex>;
|
|
46
|
+
}
|
|
47
|
+
type WalletInstance = Cip30WalletApi & Cip95WalletApi;
|
|
46
48
|
type ExperimentalFeatures = {
|
|
47
49
|
getCollateral(): Promise<string[] | undefined>;
|
|
48
50
|
signTxs?(txs: TransactionSignatureRequest[]): Promise<string[]>;
|
|
@@ -285,6 +287,12 @@ declare class BrowserWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
285
287
|
* @returns a list of policy IDs
|
|
286
288
|
*/
|
|
287
289
|
getPolicyIds(): Promise<string[]>;
|
|
290
|
+
/**
|
|
291
|
+
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
292
|
+
* 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.
|
|
293
|
+
*
|
|
294
|
+
* @returns wallet account's public DRep Key
|
|
295
|
+
*/
|
|
288
296
|
getPubDRepKey(): Promise<{
|
|
289
297
|
pubDRepKey: string;
|
|
290
298
|
dRepIDHash: string;
|
|
@@ -294,6 +302,11 @@ declare class BrowserWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
294
302
|
pubStakeKeys: string[];
|
|
295
303
|
pubStakeKeyHashes: string[];
|
|
296
304
|
} | undefined>;
|
|
305
|
+
getUnregisteredPubStakeKeys(): Promise<{
|
|
306
|
+
pubStakeKeys: string[];
|
|
307
|
+
pubStakeKeyHashes: string[];
|
|
308
|
+
} | undefined>;
|
|
309
|
+
private static dRepKeyToDRepID;
|
|
297
310
|
private static resolveInstance;
|
|
298
311
|
static addBrowserWitnesses(unsignedTx: string, witnesses: string): string;
|
|
299
312
|
static getSupportedExtensions(wallet: string): {
|
|
@@ -312,6 +325,9 @@ type Account = {
|
|
|
312
325
|
stakeKey: StricaPrivateKey;
|
|
313
326
|
paymentKeyHex: string;
|
|
314
327
|
stakeKeyHex: string;
|
|
328
|
+
pubDRepKey?: string;
|
|
329
|
+
dRepIDBech32?: DRepID;
|
|
330
|
+
dRepIDHash?: Ed25519KeyHashHex;
|
|
315
331
|
};
|
|
316
332
|
type EmbeddedWalletKeyType = {
|
|
317
333
|
type: "root";
|
|
@@ -337,6 +353,11 @@ declare class WalletStaticMethods {
|
|
|
337
353
|
enterpriseAddress: Address;
|
|
338
354
|
rewardAddress: Address;
|
|
339
355
|
};
|
|
356
|
+
static getDRepKey(dRepKey: StricaPrivateKey, networkId?: number): {
|
|
357
|
+
pubDRepKey: string;
|
|
358
|
+
dRepIDBech32: DRepID;
|
|
359
|
+
dRepIDHash: Ed25519KeyHashHex;
|
|
360
|
+
};
|
|
340
361
|
static generateMnemonic(strength?: number): string[];
|
|
341
362
|
static addWitnessSets(txHex: string, witnesses: VkeyWitness[]): string;
|
|
342
363
|
}
|
|
@@ -364,6 +385,9 @@ type CreateMeshWalletOptions = {
|
|
|
364
385
|
} | {
|
|
365
386
|
type: "mnemonic";
|
|
366
387
|
words: string[];
|
|
388
|
+
} | {
|
|
389
|
+
type: "address";
|
|
390
|
+
address: string;
|
|
367
391
|
};
|
|
368
392
|
accountIndex?: number;
|
|
369
393
|
keyIndex?: number;
|
|
@@ -371,10 +395,14 @@ type CreateMeshWalletOptions = {
|
|
|
371
395
|
/**
|
|
372
396
|
* Mesh Wallet provides a set of APIs to interact with the blockchain. This wallet is compatible with Mesh transaction builders.
|
|
373
397
|
*
|
|
374
|
-
*
|
|
398
|
+
* There are 4 types of keys that can be used to create a wallet:
|
|
399
|
+
* - root: A private key in bech32 format, generally starts with `xprv1`
|
|
400
|
+
* - cli: CLI generated keys starts with `5820`. Payment key is required, and the stake key is optional.
|
|
401
|
+
* - mnemonic: A list of 24 words
|
|
402
|
+
* - address: A bech32 address that can be used to create a read-only wallet, generally starts with `addr` or `addr_test1`
|
|
375
403
|
*
|
|
376
404
|
* ```javascript
|
|
377
|
-
* import { MeshWallet, BlockfrostProvider } from '@
|
|
405
|
+
* import { MeshWallet, BlockfrostProvider } from '@meshsdk/core';
|
|
378
406
|
*
|
|
379
407
|
* const blockchainProvider = new BlockfrostProvider('<BLOCKFROST_API_KEY>');
|
|
380
408
|
*
|
|
@@ -396,7 +424,17 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
396
424
|
private readonly _fetcher?;
|
|
397
425
|
private readonly _submitter?;
|
|
398
426
|
private readonly _networkId;
|
|
399
|
-
|
|
427
|
+
addresses: {
|
|
428
|
+
baseAddress?: Address;
|
|
429
|
+
enterpriseAddress?: Address;
|
|
430
|
+
rewardAddress?: Address;
|
|
431
|
+
baseAddressBech32?: string;
|
|
432
|
+
enterpriseAddressBech32?: string;
|
|
433
|
+
rewardAddressBech32?: string;
|
|
434
|
+
pubDRepKey?: string;
|
|
435
|
+
dRepIDBech32?: DRepID;
|
|
436
|
+
dRepIDHash?: Ed25519KeyHashHex;
|
|
437
|
+
};
|
|
400
438
|
constructor(options: CreateMeshWalletOptions);
|
|
401
439
|
/**
|
|
402
440
|
* Returns a list of assets in the wallet. This API will return every assets in the wallet. Each asset is an object with the following properties:
|
|
@@ -560,6 +598,11 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
560
598
|
* @returns a transaction hash
|
|
561
599
|
*/
|
|
562
600
|
createCollateral(): Promise<string>;
|
|
601
|
+
getPubDRepKey(): {
|
|
602
|
+
pubDRepKey: string | undefined;
|
|
603
|
+
dRepIDBech32: string | undefined;
|
|
604
|
+
dRepIDHash: string | undefined;
|
|
605
|
+
};
|
|
563
606
|
/**
|
|
564
607
|
* Generate mnemonic or private key
|
|
565
608
|
*
|
|
@@ -567,8 +610,8 @@ declare class MeshWallet implements IInitiator, ISigner, ISubmitter {
|
|
|
567
610
|
* @returns a transaction hash
|
|
568
611
|
*/
|
|
569
612
|
static brew(privateKey?: boolean, strength?: number): string[] | string;
|
|
570
|
-
getAddressesFromWallet
|
|
571
|
-
buildAddressFromBech32Address
|
|
613
|
+
private getAddressesFromWallet;
|
|
614
|
+
private buildAddressFromBech32Address;
|
|
572
615
|
}
|
|
573
616
|
|
|
574
617
|
export { type Account, AppWallet, type AppWalletKeyType, BrowserWallet, type CreateAppWalletOptions, type CreateEmbeddedWalletOptions, type CreateMeshWalletOptions, EmbeddedWallet, type EmbeddedWalletKeyType, MeshWallet, WalletStaticMethods };
|
package/dist/index.js
CHANGED
|
@@ -232,11 +232,13 @@ import {
|
|
|
232
232
|
Bip32PrivateKey,
|
|
233
233
|
buildBaseAddress,
|
|
234
234
|
buildBip32PrivateKey,
|
|
235
|
+
buildDRepID,
|
|
235
236
|
buildEnterpriseAddress,
|
|
236
237
|
buildKeys,
|
|
237
238
|
buildRewardAddress,
|
|
238
239
|
deserializeTx,
|
|
239
240
|
deserializeTxHash,
|
|
241
|
+
DRep,
|
|
240
242
|
Ed25519KeyHashHex,
|
|
241
243
|
Ed25519PublicKeyHex,
|
|
242
244
|
Ed25519SignatureHex,
|
|
@@ -273,23 +275,40 @@ var WalletStaticMethods = class {
|
|
|
273
275
|
Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
274
276
|
Ed25519KeyHashHex(stakingKey.toPublicKey().hash().toString("hex"))
|
|
275
277
|
)
|
|
276
|
-
);
|
|
278
|
+
).toAddress();
|
|
277
279
|
const enterpriseAddress = buildEnterpriseAddress(
|
|
278
280
|
networkId,
|
|
279
281
|
Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
280
282
|
Ed25519KeyHashHex(paymentKey.toPublicKey().hash().toString("hex"))
|
|
281
283
|
)
|
|
282
|
-
);
|
|
284
|
+
).toAddress();
|
|
283
285
|
const rewardAddress = buildRewardAddress(
|
|
284
286
|
networkId,
|
|
285
287
|
Hash28ByteBase16.fromEd25519KeyHashHex(
|
|
286
288
|
Ed25519KeyHashHex(stakingKey.toPublicKey().hash().toString("hex"))
|
|
287
289
|
)
|
|
290
|
+
).toAddress();
|
|
291
|
+
return {
|
|
292
|
+
baseAddress,
|
|
293
|
+
enterpriseAddress,
|
|
294
|
+
rewardAddress
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
static getDRepKey(dRepKey, networkId = 0) {
|
|
298
|
+
const pubKey = dRepKey.toPublicKey().pubKey;
|
|
299
|
+
const pubDRepKey = pubKey.toString("hex");
|
|
300
|
+
const dRepIDBech32 = buildDRepID(
|
|
301
|
+
Ed25519PublicKeyHex(pubDRepKey),
|
|
302
|
+
networkId
|
|
288
303
|
);
|
|
304
|
+
const dRep = DRep.newKeyHash(
|
|
305
|
+
Ed25519KeyHashHex(dRepKey.toPublicKey().hash().toString("hex"))
|
|
306
|
+
);
|
|
307
|
+
const dRepIDHash = dRep.toKeyHash();
|
|
289
308
|
return {
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
309
|
+
pubDRepKey,
|
|
310
|
+
dRepIDBech32,
|
|
311
|
+
dRepIDHash
|
|
293
312
|
};
|
|
294
313
|
}
|
|
295
314
|
static generateMnemonic(strength = 256) {
|
|
@@ -338,13 +357,13 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
338
357
|
getAccount(accountIndex = 0, keyIndex = 0) {
|
|
339
358
|
if (this._entropy == void 0)
|
|
340
359
|
throw new Error("[EmbeddedWallet] No keys initialized");
|
|
341
|
-
const { paymentKey, stakeKey } = buildKeys(
|
|
360
|
+
const { paymentKey, stakeKey, dRepKey } = buildKeys(
|
|
342
361
|
this._entropy,
|
|
343
362
|
accountIndex,
|
|
344
363
|
keyIndex
|
|
345
364
|
);
|
|
346
365
|
const { baseAddress, enterpriseAddress, rewardAddress } = WalletStaticMethods.getAddresses(paymentKey, stakeKey, this._networkId);
|
|
347
|
-
|
|
366
|
+
let _account = {
|
|
348
367
|
baseAddress,
|
|
349
368
|
enterpriseAddress,
|
|
350
369
|
rewardAddress,
|
|
@@ -356,25 +375,30 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
356
375
|
paymentKeyHex: paymentKey.toBytes().toString("hex"),
|
|
357
376
|
stakeKeyHex: stakeKey.toBytes().toString("hex")
|
|
358
377
|
};
|
|
378
|
+
if (dRepKey) {
|
|
379
|
+
const { pubDRepKey, dRepIDBech32, dRepIDHash } = WalletStaticMethods.getDRepKey(dRepKey, this._networkId);
|
|
380
|
+
_account.pubDRepKey = pubDRepKey;
|
|
381
|
+
_account.dRepIDBech32 = dRepIDBech32;
|
|
382
|
+
_account.dRepIDHash = dRepIDHash;
|
|
383
|
+
}
|
|
384
|
+
return _account;
|
|
359
385
|
}
|
|
360
386
|
getNetworkId() {
|
|
361
387
|
return this._networkId;
|
|
362
388
|
}
|
|
363
389
|
signData(address, payload, accountIndex = 0, keyIndex = 0) {
|
|
364
390
|
try {
|
|
365
|
-
const
|
|
366
|
-
const foundAddress = [
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
account.rewardAddress
|
|
370
|
-
].find((a) => a.toBech32() === address);
|
|
391
|
+
const { baseAddress, enterpriseAddress, rewardAddress, paymentKey } = this.getAccount(accountIndex, keyIndex);
|
|
392
|
+
const foundAddress = [baseAddress, enterpriseAddress, rewardAddress].find(
|
|
393
|
+
(a) => a.toBech32() === address
|
|
394
|
+
);
|
|
371
395
|
if (foundAddress === void 0)
|
|
372
396
|
throw new Error(
|
|
373
397
|
`[EmbeddedWallet] Address: ${address} doesn't belong to this account.`
|
|
374
398
|
);
|
|
375
399
|
return signData(payload, {
|
|
376
400
|
address: Address.fromBech32(address),
|
|
377
|
-
key:
|
|
401
|
+
key: paymentKey
|
|
378
402
|
});
|
|
379
403
|
} catch (error) {
|
|
380
404
|
throw new Error(
|
|
@@ -385,13 +409,11 @@ var EmbeddedWallet = class extends WalletStaticMethods {
|
|
|
385
409
|
signTx(unsignedTx, accountIndex = 0, keyIndex = 0) {
|
|
386
410
|
try {
|
|
387
411
|
const txHash = deserializeTxHash(resolveTxHash(unsignedTx));
|
|
388
|
-
const
|
|
412
|
+
const { paymentKey } = this.getAccount(accountIndex, keyIndex);
|
|
389
413
|
const vKeyWitness = new VkeyWitness(
|
|
390
|
-
Ed25519PublicKeyHex(
|
|
391
|
-
account.paymentKey.toPublicKey().toBytes().toString("hex")
|
|
392
|
-
),
|
|
414
|
+
Ed25519PublicKeyHex(paymentKey.toPublicKey().toBytes().toString("hex")),
|
|
393
415
|
Ed25519SignatureHex(
|
|
394
|
-
|
|
416
|
+
paymentKey.sign(Buffer.from(txHash, "hex")).toString("hex")
|
|
395
417
|
)
|
|
396
418
|
);
|
|
397
419
|
return vKeyWitness;
|
|
@@ -556,7 +578,7 @@ import {
|
|
|
556
578
|
} from "@meshsdk/common";
|
|
557
579
|
import {
|
|
558
580
|
addressToBech32,
|
|
559
|
-
buildDRepID,
|
|
581
|
+
buildDRepID as buildDRepID2,
|
|
560
582
|
CardanoSDKUtil,
|
|
561
583
|
deserializeAddress,
|
|
562
584
|
deserializeTx as deserializeTx3,
|
|
@@ -817,6 +839,9 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
817
839
|
*/
|
|
818
840
|
async signTx(unsignedTx, partialSign = false) {
|
|
819
841
|
const witness = await this._walletInstance.signTx(unsignedTx, partialSign);
|
|
842
|
+
if (witness === "") {
|
|
843
|
+
return unsignedTx;
|
|
844
|
+
}
|
|
820
845
|
return _BrowserWallet.addBrowserWitnesses(unsignedTx, witness);
|
|
821
846
|
}
|
|
822
847
|
/**
|
|
@@ -860,8 +885,15 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
860
885
|
for (let i = 0; i < witnessSets.length; i++) {
|
|
861
886
|
const unsignedTx = unsignedTxs[i];
|
|
862
887
|
const cWitness = witnessSets[i];
|
|
863
|
-
|
|
864
|
-
|
|
888
|
+
if (cWitness === "") {
|
|
889
|
+
signedTxs.push(unsignedTx);
|
|
890
|
+
} else {
|
|
891
|
+
const signedTx = _BrowserWallet.addBrowserWitnesses(
|
|
892
|
+
unsignedTx,
|
|
893
|
+
cWitness
|
|
894
|
+
);
|
|
895
|
+
signedTxs.push(signedTx);
|
|
896
|
+
}
|
|
865
897
|
}
|
|
866
898
|
return signedTxs;
|
|
867
899
|
}
|
|
@@ -961,23 +993,27 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
961
993
|
new Set(balance.map((v) => v.unit.slice(0, POLICY_ID_LENGTH)))
|
|
962
994
|
).filter((p) => p !== "lovelace");
|
|
963
995
|
}
|
|
996
|
+
/**
|
|
997
|
+
* The connected wallet account provides the account's public DRep Key, derivation as described in CIP-0105.
|
|
998
|
+
* 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.
|
|
999
|
+
*
|
|
1000
|
+
* @returns wallet account's public DRep Key
|
|
1001
|
+
*/
|
|
964
1002
|
async getPubDRepKey() {
|
|
965
1003
|
try {
|
|
966
1004
|
if (this._walletInstance.cip95 === void 0) return void 0;
|
|
967
1005
|
const dRepKey = await this._walletInstance.cip95.getPubDRepKey();
|
|
968
|
-
const dRepKeyHex =
|
|
969
|
-
const dRepID = Ed25519PublicKey.fromHex(dRepKeyHex);
|
|
970
|
-
const dRepIDHex = (await dRepID.hash()).hex();
|
|
1006
|
+
const { dRepKeyHex, dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(dRepKey);
|
|
971
1007
|
const networkId = await this.getNetworkId();
|
|
972
|
-
const dRepId =
|
|
1008
|
+
const dRepId = buildDRepID2(dRepKeyHex, networkId);
|
|
973
1009
|
return {
|
|
974
1010
|
pubDRepKey: dRepKey,
|
|
975
|
-
dRepIDHash
|
|
1011
|
+
dRepIDHash,
|
|
976
1012
|
dRepIDBech32: dRepId
|
|
977
1013
|
// todo to check
|
|
978
1014
|
};
|
|
979
1015
|
} catch (e) {
|
|
980
|
-
console.
|
|
1016
|
+
console.error(e);
|
|
981
1017
|
return void 0;
|
|
982
1018
|
}
|
|
983
1019
|
}
|
|
@@ -987,10 +1023,27 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
987
1023
|
const pubStakeKeys = await this._walletInstance.cip95.getRegisteredPubStakeKeys();
|
|
988
1024
|
const pubStakeKeyHashes = await Promise.all(
|
|
989
1025
|
pubStakeKeys.map(async (pubStakeKey) => {
|
|
990
|
-
const
|
|
991
|
-
|
|
992
|
-
|
|
993
|
-
|
|
1026
|
+
const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(pubStakeKey);
|
|
1027
|
+
return dRepIDHash;
|
|
1028
|
+
})
|
|
1029
|
+
);
|
|
1030
|
+
return {
|
|
1031
|
+
pubStakeKeys,
|
|
1032
|
+
pubStakeKeyHashes
|
|
1033
|
+
};
|
|
1034
|
+
} catch (e) {
|
|
1035
|
+
console.error(e);
|
|
1036
|
+
return void 0;
|
|
1037
|
+
}
|
|
1038
|
+
}
|
|
1039
|
+
async getUnregisteredPubStakeKeys() {
|
|
1040
|
+
try {
|
|
1041
|
+
if (this._walletInstance.cip95 === void 0) return void 0;
|
|
1042
|
+
const pubStakeKeys = await this._walletInstance.cip95.getUnregisteredPubStakeKeys();
|
|
1043
|
+
const pubStakeKeyHashes = await Promise.all(
|
|
1044
|
+
pubStakeKeys.map(async (pubStakeKey) => {
|
|
1045
|
+
const { dRepIDHash } = await _BrowserWallet.dRepKeyToDRepID(pubStakeKey);
|
|
1046
|
+
return dRepIDHash;
|
|
994
1047
|
})
|
|
995
1048
|
);
|
|
996
1049
|
return {
|
|
@@ -998,10 +1051,20 @@ var BrowserWallet = class _BrowserWallet {
|
|
|
998
1051
|
pubStakeKeyHashes
|
|
999
1052
|
};
|
|
1000
1053
|
} catch (e) {
|
|
1001
|
-
console.
|
|
1054
|
+
console.error(e);
|
|
1002
1055
|
return void 0;
|
|
1003
1056
|
}
|
|
1004
1057
|
}
|
|
1058
|
+
static async dRepKeyToDRepID(dRepKey) {
|
|
1059
|
+
const dRepKeyHex = Ed25519PublicKeyHex2(dRepKey);
|
|
1060
|
+
const dRepID = Ed25519PublicKey.fromHex(dRepKeyHex);
|
|
1061
|
+
const dRepIDHash = (await dRepID.hash()).hex();
|
|
1062
|
+
return {
|
|
1063
|
+
dRepKeyHex,
|
|
1064
|
+
dRepID,
|
|
1065
|
+
dRepIDHash
|
|
1066
|
+
};
|
|
1067
|
+
}
|
|
1005
1068
|
static resolveInstance(walletName, extensions = []) {
|
|
1006
1069
|
if (window.cardano === void 0) return void 0;
|
|
1007
1070
|
if (window.cardano[walletName] === void 0) return void 0;
|
|
@@ -1047,12 +1110,12 @@ import {
|
|
|
1047
1110
|
} from "@meshsdk/common";
|
|
1048
1111
|
import { resolvePrivateKey } from "@meshsdk/core-csl";
|
|
1049
1112
|
import {
|
|
1113
|
+
Address as Address4,
|
|
1050
1114
|
buildBaseAddress as buildBaseAddress2,
|
|
1051
1115
|
buildEnterpriseAddress as buildEnterpriseAddress2,
|
|
1052
1116
|
buildRewardAddress as buildRewardAddress2,
|
|
1053
|
-
CardanoSDKSerializer,
|
|
1054
1117
|
deserializeTx as deserializeTx4,
|
|
1055
|
-
Ed25519KeyHashHex as
|
|
1118
|
+
Ed25519KeyHashHex as Ed25519KeyHashHex3,
|
|
1056
1119
|
fromTxUnspentOutput as fromTxUnspentOutput2,
|
|
1057
1120
|
Hash28ByteBase16 as Hash28ByteBase162,
|
|
1058
1121
|
toAddress as toAddress3,
|
|
@@ -1061,14 +1124,14 @@ import {
|
|
|
1061
1124
|
import { Transaction as Transaction3 } from "@meshsdk/transaction";
|
|
1062
1125
|
var MeshWallet = class {
|
|
1063
1126
|
_wallet;
|
|
1064
|
-
// private readonly _account: Account;
|
|
1065
1127
|
_accountIndex = 0;
|
|
1066
1128
|
_keyIndex = 0;
|
|
1067
1129
|
_fetcher;
|
|
1068
1130
|
_submitter;
|
|
1069
1131
|
_networkId;
|
|
1070
|
-
|
|
1132
|
+
addresses = {};
|
|
1071
1133
|
constructor(options) {
|
|
1134
|
+
this._networkId = options.networkId;
|
|
1072
1135
|
switch (options.key.type) {
|
|
1073
1136
|
case "root":
|
|
1074
1137
|
this._wallet = new EmbeddedWallet({
|
|
@@ -1101,8 +1164,11 @@ var MeshWallet = class {
|
|
|
1101
1164
|
});
|
|
1102
1165
|
this.getAddressesFromWallet(this._wallet);
|
|
1103
1166
|
break;
|
|
1167
|
+
case "address":
|
|
1168
|
+
this._wallet = null;
|
|
1169
|
+
this.buildAddressFromBech32Address(options.key.address);
|
|
1170
|
+
break;
|
|
1104
1171
|
}
|
|
1105
|
-
this._networkId = options.networkId;
|
|
1106
1172
|
if (options.fetcher) this._fetcher = options.fetcher;
|
|
1107
1173
|
if (options.submitter) this._submitter = options.submitter;
|
|
1108
1174
|
if (options.accountIndex) this._accountIndex = options.accountIndex;
|
|
@@ -1143,7 +1209,7 @@ var MeshWallet = class {
|
|
|
1143
1209
|
* @returns an address
|
|
1144
1210
|
*/
|
|
1145
1211
|
getChangeAddress() {
|
|
1146
|
-
return this.
|
|
1212
|
+
return this.addresses.baseAddressBech32 ? this.addresses.baseAddressBech32 : this.addresses.enterpriseAddressBech32;
|
|
1147
1213
|
}
|
|
1148
1214
|
/**
|
|
1149
1215
|
* 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).
|
|
@@ -1196,7 +1262,7 @@ var MeshWallet = class {
|
|
|
1196
1262
|
* @returns a list of reward addresses
|
|
1197
1263
|
*/
|
|
1198
1264
|
getRewardAddresses() {
|
|
1199
|
-
return [this.
|
|
1265
|
+
return [this.addresses.rewardAddressBech32];
|
|
1200
1266
|
}
|
|
1201
1267
|
/**
|
|
1202
1268
|
* Returns a list of unused addresses controlled by the wallet.
|
|
@@ -1236,7 +1302,7 @@ var MeshWallet = class {
|
|
|
1236
1302
|
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1237
1303
|
* @returns a list of UTXOs
|
|
1238
1304
|
*/
|
|
1239
|
-
async getUsedUTxOs(addressType) {
|
|
1305
|
+
async getUsedUTxOs(addressType = "payment") {
|
|
1240
1306
|
return await this.getUnspentOutputs(addressType);
|
|
1241
1307
|
}
|
|
1242
1308
|
/**
|
|
@@ -1245,7 +1311,7 @@ var MeshWallet = class {
|
|
|
1245
1311
|
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1246
1312
|
* @returns a list of UTXOs
|
|
1247
1313
|
*/
|
|
1248
|
-
async getUtxos(addressType) {
|
|
1314
|
+
async getUtxos(addressType = "payment") {
|
|
1249
1315
|
const utxos = await this.getUsedUTxOs(addressType);
|
|
1250
1316
|
return utxos.map((c) => fromTxUnspentOutput2(c));
|
|
1251
1317
|
}
|
|
@@ -1301,6 +1367,11 @@ var MeshWallet = class {
|
|
|
1301
1367
|
* @returns array of signed transactions CborHex string
|
|
1302
1368
|
*/
|
|
1303
1369
|
signTxs(unsignedTxs, partialSign = false) {
|
|
1370
|
+
if (!this._wallet) {
|
|
1371
|
+
throw new Error(
|
|
1372
|
+
"[MeshWallet] Read only wallet does not support signing data."
|
|
1373
|
+
);
|
|
1374
|
+
}
|
|
1304
1375
|
const signedTxs = [];
|
|
1305
1376
|
for (const unsignedTx of unsignedTxs) {
|
|
1306
1377
|
const signedTx = this.signTx(unsignedTx, partialSign);
|
|
@@ -1319,7 +1390,7 @@ var MeshWallet = class {
|
|
|
1319
1390
|
async submitTx(tx) {
|
|
1320
1391
|
if (!this._submitter) {
|
|
1321
1392
|
throw new Error(
|
|
1322
|
-
"[
|
|
1393
|
+
"[MeshWallet] Submitter is required to submit transactions. Please provide a submitter."
|
|
1323
1394
|
);
|
|
1324
1395
|
}
|
|
1325
1396
|
return this._submitter.submitTx(tx);
|
|
@@ -1332,11 +1403,11 @@ var MeshWallet = class {
|
|
|
1332
1403
|
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1333
1404
|
* @returns an Address object
|
|
1334
1405
|
*/
|
|
1335
|
-
getUsedAddress(addressType) {
|
|
1336
|
-
if (addressType === "
|
|
1337
|
-
return toAddress3(this.
|
|
1406
|
+
getUsedAddress(addressType = "payment") {
|
|
1407
|
+
if (this.addresses.baseAddressBech32 && addressType === "payment") {
|
|
1408
|
+
return toAddress3(this.addresses.baseAddressBech32);
|
|
1338
1409
|
} else {
|
|
1339
|
-
return toAddress3(this.
|
|
1410
|
+
return toAddress3(this.addresses.enterpriseAddressBech32);
|
|
1340
1411
|
}
|
|
1341
1412
|
}
|
|
1342
1413
|
/**
|
|
@@ -1347,14 +1418,14 @@ var MeshWallet = class {
|
|
|
1347
1418
|
* @param addressType - the type of address to fetch UTXOs from (default: payment)
|
|
1348
1419
|
* @returns a list of UTXOs
|
|
1349
1420
|
*/
|
|
1350
|
-
async getUnspentOutputs(addressType) {
|
|
1421
|
+
async getUnspentOutputs(addressType = "payment") {
|
|
1351
1422
|
if (!this._fetcher) {
|
|
1352
1423
|
throw new Error(
|
|
1353
|
-
"[
|
|
1424
|
+
"[MeshWallet] Fetcher is required to fetch UTxOs. Please provide a fetcher."
|
|
1354
1425
|
);
|
|
1355
1426
|
}
|
|
1356
1427
|
const utxos = await this._fetcher.fetchAddressUTxOs(
|
|
1357
|
-
addressType == "
|
|
1428
|
+
this.addresses.baseAddressBech32 && addressType == "payment" ? this.addresses.baseAddressBech32 : this.addresses.enterpriseAddressBech32
|
|
1358
1429
|
);
|
|
1359
1430
|
return utxos.map((utxo) => toTxUnspentOutput2(utxo));
|
|
1360
1431
|
}
|
|
@@ -1422,6 +1493,13 @@ var MeshWallet = class {
|
|
|
1422
1493
|
const txHash = await this.submitTx(signedTx);
|
|
1423
1494
|
return txHash;
|
|
1424
1495
|
}
|
|
1496
|
+
getPubDRepKey() {
|
|
1497
|
+
return {
|
|
1498
|
+
pubDRepKey: this.addresses.pubDRepKey,
|
|
1499
|
+
dRepIDBech32: this.addresses.dRepIDBech32,
|
|
1500
|
+
dRepIDHash: this.addresses.dRepIDHash
|
|
1501
|
+
};
|
|
1502
|
+
}
|
|
1425
1503
|
/**
|
|
1426
1504
|
* Generate mnemonic or private key
|
|
1427
1505
|
*
|
|
@@ -1437,49 +1515,57 @@ var MeshWallet = class {
|
|
|
1437
1515
|
}
|
|
1438
1516
|
getAddressesFromWallet(wallet) {
|
|
1439
1517
|
const account = wallet.getAccount(this._accountIndex, this._keyIndex);
|
|
1440
|
-
this.
|
|
1518
|
+
this.addresses = {
|
|
1441
1519
|
baseAddress: account.baseAddress,
|
|
1442
1520
|
enterpriseAddress: account.enterpriseAddress,
|
|
1443
1521
|
rewardAddress: account.rewardAddress,
|
|
1444
1522
|
baseAddressBech32: account.baseAddressBech32,
|
|
1445
1523
|
enterpriseAddressBech32: account.enterpriseAddressBech32,
|
|
1446
|
-
rewardAddressBech32: account.rewardAddressBech32
|
|
1524
|
+
rewardAddressBech32: account.rewardAddressBech32,
|
|
1525
|
+
pubDRepKey: account.pubDRepKey,
|
|
1526
|
+
dRepIDBech32: account.dRepIDBech32,
|
|
1527
|
+
dRepIDHash: account.dRepIDHash
|
|
1447
1528
|
};
|
|
1448
1529
|
}
|
|
1449
1530
|
buildAddressFromBech32Address(address) {
|
|
1450
|
-
|
|
1451
|
-
|
|
1452
|
-
|
|
1453
|
-
|
|
1531
|
+
let pubKeyHash = void 0;
|
|
1532
|
+
let stakeKeyHash = void 0;
|
|
1533
|
+
const baseAddress = Address4.fromBech32(address).asBase();
|
|
1534
|
+
if (baseAddress) {
|
|
1535
|
+
pubKeyHash = baseAddress.getPaymentCredential().hash;
|
|
1536
|
+
stakeKeyHash = baseAddress.getStakeCredential().hash;
|
|
1537
|
+
}
|
|
1538
|
+
const enterpriseAddress = Address4.fromBech32(address).asEnterprise();
|
|
1539
|
+
if (enterpriseAddress) {
|
|
1540
|
+
pubKeyHash = enterpriseAddress.getPaymentCredential().hash;
|
|
1541
|
+
}
|
|
1542
|
+
const rewardAddress = Address4.fromBech32(address).asReward();
|
|
1543
|
+
if (rewardAddress) {
|
|
1544
|
+
stakeKeyHash = rewardAddress.getPaymentCredential().hash;
|
|
1545
|
+
}
|
|
1546
|
+
if (pubKeyHash && stakeKeyHash) {
|
|
1547
|
+
this.addresses.baseAddress = buildBaseAddress2(
|
|
1454
1548
|
this._networkId,
|
|
1549
|
+
Hash28ByteBase162.fromEd25519KeyHashHex(Ed25519KeyHashHex3(pubKeyHash)),
|
|
1455
1550
|
Hash28ByteBase162.fromEd25519KeyHashHex(
|
|
1456
|
-
|
|
1457
|
-
),
|
|
1458
|
-
Hash28ByteBase162.fromEd25519KeyHashHex(
|
|
1459
|
-
Ed25519KeyHashHex2(
|
|
1460
|
-
Ed25519KeyHashHex2(deserializedAddress.stakeCredentialHash)
|
|
1461
|
-
)
|
|
1551
|
+
Ed25519KeyHashHex3(Ed25519KeyHashHex3(stakeKeyHash))
|
|
1462
1552
|
)
|
|
1463
1553
|
).toAddress();
|
|
1464
|
-
this.
|
|
1554
|
+
this.addresses.baseAddressBech32 = this.addresses.baseAddress.toBech32();
|
|
1465
1555
|
}
|
|
1466
|
-
if (
|
|
1467
|
-
this.
|
|
1556
|
+
if (pubKeyHash) {
|
|
1557
|
+
this.addresses.enterpriseAddress = buildEnterpriseAddress2(
|
|
1468
1558
|
this._networkId,
|
|
1469
|
-
Hash28ByteBase162.fromEd25519KeyHashHex(
|
|
1470
|
-
Ed25519KeyHashHex2(deserializedAddress.pubKeyHash)
|
|
1471
|
-
)
|
|
1559
|
+
Hash28ByteBase162.fromEd25519KeyHashHex(Ed25519KeyHashHex3(pubKeyHash))
|
|
1472
1560
|
).toAddress();
|
|
1473
|
-
this.
|
|
1561
|
+
this.addresses.enterpriseAddressBech32 = this.addresses.enterpriseAddress.toBech32();
|
|
1474
1562
|
}
|
|
1475
|
-
if (
|
|
1476
|
-
this.
|
|
1563
|
+
if (stakeKeyHash) {
|
|
1564
|
+
this.addresses.rewardAddress = buildRewardAddress2(
|
|
1477
1565
|
this._networkId,
|
|
1478
|
-
Hash28ByteBase162.fromEd25519KeyHashHex(
|
|
1479
|
-
Ed25519KeyHashHex2(deserializedAddress.stakeCredentialHash)
|
|
1480
|
-
)
|
|
1566
|
+
Hash28ByteBase162.fromEd25519KeyHashHex(Ed25519KeyHashHex3(stakeKeyHash))
|
|
1481
1567
|
).toAddress();
|
|
1482
|
-
this.
|
|
1568
|
+
this.addresses.rewardAddressBech32 = this.addresses.rewardAddress.toBech32();
|
|
1483
1569
|
}
|
|
1484
1570
|
}
|
|
1485
1571
|
};
|