@meshsdk/wallet 2.0.0-beta.6 → 2.0.0-beta.8
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 +122 -88
- package/dist/index.d.ts +21 -6
- package/dist/index.js +117 -84
- package/package.json +18 -14
package/dist/index.cjs
CHANGED
|
@@ -21883,7 +21883,7 @@ var require_src = __commonJS({
|
|
|
21883
21883
|
return Buffer.from(res);
|
|
21884
21884
|
}
|
|
21885
21885
|
exports2.mnemonicToSeedSync = mnemonicToSeedSync;
|
|
21886
|
-
function
|
|
21886
|
+
function mnemonicToSeed2(mnemonic, password) {
|
|
21887
21887
|
const mnemonicBuffer = Uint8Array.from(Buffer.from(normalize(mnemonic), "utf8"));
|
|
21888
21888
|
const saltBuffer = Uint8Array.from(Buffer.from(salt(normalize(password)), "utf8"));
|
|
21889
21889
|
return pbkdf2_1.pbkdf2Async(sha512_1.sha512, mnemonicBuffer, saltBuffer, {
|
|
@@ -21891,7 +21891,7 @@ var require_src = __commonJS({
|
|
|
21891
21891
|
dkLen: 64
|
|
21892
21892
|
}).then((res) => Buffer.from(res));
|
|
21893
21893
|
}
|
|
21894
|
-
exports2.mnemonicToSeed =
|
|
21894
|
+
exports2.mnemonicToSeed = mnemonicToSeed2;
|
|
21895
21895
|
function mnemonicToEntropy3(mnemonic, wordlist) {
|
|
21896
21896
|
wordlist = wordlist || DEFAULT_WORDLIST;
|
|
21897
21897
|
if (!wordlist) {
|
|
@@ -21929,7 +21929,7 @@ var require_src = __commonJS({
|
|
|
21929
21929
|
return entropy.toString("hex");
|
|
21930
21930
|
}
|
|
21931
21931
|
exports2.mnemonicToEntropy = mnemonicToEntropy3;
|
|
21932
|
-
function
|
|
21932
|
+
function entropyToMnemonic2(entropy, wordlist) {
|
|
21933
21933
|
if (!Buffer.isBuffer(entropy)) {
|
|
21934
21934
|
entropy = Buffer.from(entropy, "hex");
|
|
21935
21935
|
}
|
|
@@ -21956,14 +21956,14 @@ var require_src = __commonJS({
|
|
|
21956
21956
|
});
|
|
21957
21957
|
return wordlist[0] === "\u3042\u3044\u3053\u304F\u3057\u3093" ? words.join("\u3000") : words.join(" ");
|
|
21958
21958
|
}
|
|
21959
|
-
exports2.entropyToMnemonic =
|
|
21959
|
+
exports2.entropyToMnemonic = entropyToMnemonic2;
|
|
21960
21960
|
function generateMnemonic2(strength, rng, wordlist) {
|
|
21961
21961
|
strength = strength || 128;
|
|
21962
21962
|
if (strength % 32 !== 0) {
|
|
21963
21963
|
throw new TypeError(INVALID_ENTROPY);
|
|
21964
21964
|
}
|
|
21965
21965
|
rng = rng || ((size) => Buffer.from(utils_1.randomBytes(size)));
|
|
21966
|
-
return
|
|
21966
|
+
return entropyToMnemonic2(rng(strength / 8), wordlist);
|
|
21967
21967
|
}
|
|
21968
21968
|
exports2.generateMnemonic = generateMnemonic2;
|
|
21969
21969
|
function validateMnemonic(mnemonic, wordlist) {
|
|
@@ -23853,17 +23853,18 @@ var index_exports = {};
|
|
|
23853
23853
|
__export(index_exports, {
|
|
23854
23854
|
AddressType: () => AddressType,
|
|
23855
23855
|
BaseSigner: () => BaseSigner,
|
|
23856
|
+
BitcoinInMemoryBip32: () => BitcoinInMemoryBip32,
|
|
23856
23857
|
CardanoAddress: () => CardanoAddress,
|
|
23857
23858
|
CardanoBrowserWallet: () => CardanoBrowserWallet,
|
|
23858
23859
|
CardanoHeadlessWallet: () => CardanoHeadlessWallet,
|
|
23860
|
+
CardanoInMemoryBip32: () => CardanoInMemoryBip32,
|
|
23859
23861
|
CredentialType: () => CredentialType,
|
|
23860
|
-
InMemoryBip32: () => InMemoryBip32,
|
|
23861
23862
|
MeshCardanoBrowserWallet: () => MeshCardanoBrowserWallet,
|
|
23862
23863
|
MeshCardanoHeadlessWallet: () => MeshCardanoHeadlessWallet
|
|
23863
23864
|
});
|
|
23864
23865
|
module.exports = __toCommonJS(index_exports);
|
|
23865
23866
|
|
|
23866
|
-
// src/bip32/in-memory-bip32.ts
|
|
23867
|
+
// src/bip32/cardano-in-memory-bip32.ts
|
|
23867
23868
|
var import_crypto2 = require("@cardano-sdk/crypto");
|
|
23868
23869
|
|
|
23869
23870
|
// node_modules/@scure/base/lib/esm/index.js
|
|
@@ -24124,7 +24125,7 @@ function genBech32(encoding) {
|
|
|
24124
24125
|
}
|
|
24125
24126
|
var bech32 = /* @__PURE__ */ genBech32("bech32");
|
|
24126
24127
|
|
|
24127
|
-
// src/bip32/in-memory-bip32.ts
|
|
24128
|
+
// src/bip32/cardano-in-memory-bip32.ts
|
|
24128
24129
|
var import_bip39 = __toESM(require_src(), 1);
|
|
24129
24130
|
|
|
24130
24131
|
// src/cardano/utils/constants.ts
|
|
@@ -24149,9 +24150,6 @@ var DEFAULT_DREP_KEY_DERIVATION_PATH = [
|
|
|
24149
24150
|
|
|
24150
24151
|
// src/interfaces/secret-manager.ts
|
|
24151
24152
|
var derivationPathVectorFromString = (path) => {
|
|
24152
|
-
if (!/^m?\/\d+(\/\d+)*$/.test(path)) {
|
|
24153
|
-
throw new Error(`Invalid derivation path: ${path}`);
|
|
24154
|
-
}
|
|
24155
24153
|
let pathString = path;
|
|
24156
24154
|
if (pathString.startsWith("m/")) {
|
|
24157
24155
|
pathString = pathString.slice(2);
|
|
@@ -24164,6 +24162,15 @@ var derivationPathVectorFromString = (path) => {
|
|
|
24164
24162
|
}
|
|
24165
24163
|
});
|
|
24166
24164
|
};
|
|
24165
|
+
var derivationPathStringFromVector = (path) => {
|
|
24166
|
+
return path.map((part) => {
|
|
24167
|
+
if (part >= HARDENED_OFFSET) {
|
|
24168
|
+
return part - HARDENED_OFFSET + "'";
|
|
24169
|
+
} else {
|
|
24170
|
+
return part.toString();
|
|
24171
|
+
}
|
|
24172
|
+
}).join("/");
|
|
24173
|
+
};
|
|
24167
24174
|
|
|
24168
24175
|
// src/signer/base-signer.ts
|
|
24169
24176
|
var import_core = require("@cardano-sdk/core");
|
|
@@ -24242,8 +24249,8 @@ var BaseSigner = class _BaseSigner {
|
|
|
24242
24249
|
}
|
|
24243
24250
|
};
|
|
24244
24251
|
|
|
24245
|
-
// src/bip32/in-memory-bip32.ts
|
|
24246
|
-
var
|
|
24252
|
+
// src/bip32/cardano-in-memory-bip32.ts
|
|
24253
|
+
var CardanoInMemoryBip32 = class _CardanoInMemoryBip32 {
|
|
24247
24254
|
constructor(privateKey) {
|
|
24248
24255
|
this.bip32PrivateKey = privateKey;
|
|
24249
24256
|
}
|
|
@@ -24254,7 +24261,7 @@ var InMemoryBip32 = class _InMemoryBip32 {
|
|
|
24254
24261
|
Buffer.from(entropy, "hex"),
|
|
24255
24262
|
password || ""
|
|
24256
24263
|
);
|
|
24257
|
-
return new
|
|
24264
|
+
return new _CardanoInMemoryBip32(bip32PrivateKey);
|
|
24258
24265
|
}
|
|
24259
24266
|
static async fromEntropy(entropy, password) {
|
|
24260
24267
|
await (0, import_crypto2.ready)();
|
|
@@ -24262,18 +24269,18 @@ var InMemoryBip32 = class _InMemoryBip32 {
|
|
|
24262
24269
|
Buffer.from(entropy, "hex"),
|
|
24263
24270
|
password || ""
|
|
24264
24271
|
);
|
|
24265
|
-
return new
|
|
24272
|
+
return new _CardanoInMemoryBip32(bip32PrivateKey);
|
|
24266
24273
|
}
|
|
24267
24274
|
static fromKeyHex(keyHex) {
|
|
24268
24275
|
const bip32PrivateKey = import_crypto2.Bip32PrivateKey.fromHex(
|
|
24269
24276
|
keyHex
|
|
24270
24277
|
);
|
|
24271
|
-
return new
|
|
24278
|
+
return new _CardanoInMemoryBip32(bip32PrivateKey);
|
|
24272
24279
|
}
|
|
24273
24280
|
static fromBech32(bech323) {
|
|
24274
24281
|
const bech32DecodedBytes = bech32.decodeToBytes(bech323).bytes;
|
|
24275
24282
|
const bip32PrivateKey = import_crypto2.Bip32PrivateKey.fromBytes(bech32DecodedBytes);
|
|
24276
|
-
return new
|
|
24283
|
+
return new _CardanoInMemoryBip32(bip32PrivateKey);
|
|
24277
24284
|
}
|
|
24278
24285
|
/**
|
|
24279
24286
|
* Get the Bip32 public key in hex format.
|
|
@@ -24294,6 +24301,44 @@ var InMemoryBip32 = class _InMemoryBip32 {
|
|
|
24294
24301
|
}
|
|
24295
24302
|
};
|
|
24296
24303
|
|
|
24304
|
+
// src/bip32/bitcoin-in-memory-bip32.ts
|
|
24305
|
+
var bip32 = __toESM(require("bip32"), 1);
|
|
24306
|
+
var ecc = __toESM(require("tiny-secp256k1"), 1);
|
|
24307
|
+
var import_bip392 = __toESM(require_src(), 1);
|
|
24308
|
+
var BitcoinInMemoryBip32 = class _BitcoinInMemoryBip32 {
|
|
24309
|
+
constructor(root) {
|
|
24310
|
+
this.root = root;
|
|
24311
|
+
}
|
|
24312
|
+
static async fromMnemonic(mnemonic, password) {
|
|
24313
|
+
const seed = await (0, import_bip392.mnemonicToSeed)(mnemonic.join(" "), password || "");
|
|
24314
|
+
const root = bip32.BIP32Factory(ecc).fromSeed(seed);
|
|
24315
|
+
return new _BitcoinInMemoryBip32(root);
|
|
24316
|
+
}
|
|
24317
|
+
static async fromEntropy(entropy, password) {
|
|
24318
|
+
const mnemonic = (0, import_bip392.entropyToMnemonic)(entropy);
|
|
24319
|
+
const seed = await (0, import_bip392.mnemonicToSeed)(mnemonic, password || "");
|
|
24320
|
+
const root = bip32.BIP32Factory(ecc).fromSeed(seed);
|
|
24321
|
+
return new _BitcoinInMemoryBip32(root);
|
|
24322
|
+
}
|
|
24323
|
+
/**
|
|
24324
|
+
* Get the private key (hex) for the provided derivation path.
|
|
24325
|
+
*/
|
|
24326
|
+
getPrivateKey(derivationPath) {
|
|
24327
|
+
const path = Array.isArray(derivationPath) ? `m/${derivationPathStringFromVector(derivationPath)}` : derivationPath;
|
|
24328
|
+
const child = this.root.derivePath(path);
|
|
24329
|
+
if (!child?.privateKey) throw new Error("No private key at path");
|
|
24330
|
+
return Buffer.from(child.privateKey).toString("hex");
|
|
24331
|
+
}
|
|
24332
|
+
/**
|
|
24333
|
+
* Get the public key (hex) for the provided derivation path.
|
|
24334
|
+
*/
|
|
24335
|
+
getPublicKey(derivationPath) {
|
|
24336
|
+
const path = Array.isArray(derivationPath) ? `m/${derivationPathStringFromVector(derivationPath)}` : derivationPath;
|
|
24337
|
+
const child = this.root.derivePath(path);
|
|
24338
|
+
return Buffer.from(child.publicKey).toString("hex");
|
|
24339
|
+
}
|
|
24340
|
+
};
|
|
24341
|
+
|
|
24297
24342
|
// src/cardano/address/cardano-address.ts
|
|
24298
24343
|
var import_core2 = require("@cardano-sdk/core");
|
|
24299
24344
|
var import_crypto3 = require("@cardano-sdk/crypto");
|
|
@@ -24700,29 +24745,11 @@ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBr
|
|
|
24700
24745
|
}
|
|
24701
24746
|
};
|
|
24702
24747
|
|
|
24703
|
-
// src/cardano/wallet/mesh/cardano-
|
|
24748
|
+
// src/cardano/wallet/mesh/cardano-headless-wallet.ts
|
|
24704
24749
|
var import_core9 = require("@cardano-sdk/core");
|
|
24705
24750
|
|
|
24706
|
-
// src/utils/value.ts
|
|
24707
|
-
var import_core5 = require("@cardano-sdk/core");
|
|
24708
|
-
function mergeValue(a, b) {
|
|
24709
|
-
const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
|
|
24710
|
-
b.multiasset()?.forEach((v, k) => {
|
|
24711
|
-
const newVal = (ma.get(k) ?? 0n) + v;
|
|
24712
|
-
if (newVal == 0n) {
|
|
24713
|
-
ma.delete(k);
|
|
24714
|
-
} else {
|
|
24715
|
-
ma.set(k, newVal);
|
|
24716
|
-
}
|
|
24717
|
-
});
|
|
24718
|
-
return new import_core5.Serialization.Value(
|
|
24719
|
-
BigInt(a.coin()) + BigInt(b.coin()),
|
|
24720
|
-
ma.size > 0 ? ma : void 0
|
|
24721
|
-
);
|
|
24722
|
-
}
|
|
24723
|
-
|
|
24724
24751
|
// src/cardano/address/single-address-manager.ts
|
|
24725
|
-
var
|
|
24752
|
+
var import_core5 = require("@cardano-sdk/core");
|
|
24726
24753
|
var AddressManager = class _AddressManager {
|
|
24727
24754
|
static async create(config) {
|
|
24728
24755
|
let paymentSigner;
|
|
@@ -24811,7 +24838,7 @@ var AddressManager = class _AddressManager {
|
|
|
24811
24838
|
);
|
|
24812
24839
|
}
|
|
24813
24840
|
constructor(paymentCredential, stakeCredential, drepCredential, paymentSigner, networkId, stakeSigner, drepSigner) {
|
|
24814
|
-
(0,
|
|
24841
|
+
(0, import_core5.setInConwayEra)(true);
|
|
24815
24842
|
this.paymentCredential = paymentCredential;
|
|
24816
24843
|
this.stakeCredential = stakeCredential;
|
|
24817
24844
|
this.drepCredential = drepCredential;
|
|
@@ -24869,7 +24896,7 @@ var AddressManager = class _AddressManager {
|
|
|
24869
24896
|
};
|
|
24870
24897
|
|
|
24871
24898
|
// src/cardano/signer/cardano-signer.ts
|
|
24872
|
-
var
|
|
24899
|
+
var import_core6 = require("@cardano-sdk/core");
|
|
24873
24900
|
var import_crypto5 = require("@cardano-sdk/crypto");
|
|
24874
24901
|
var import_util5 = require("@cardano-sdk/util");
|
|
24875
24902
|
var import_cbor2 = require("@harmoniclabs/cbor");
|
|
@@ -24878,7 +24905,7 @@ var import_cbor2 = require("@harmoniclabs/cbor");
|
|
|
24878
24905
|
var import_bech32 = __toESM(require_dist(), 1);
|
|
24879
24906
|
var import_blake2b = __toESM(require_blake2b2(), 1);
|
|
24880
24907
|
var import_blakejs = __toESM(require_blakejs(), 1);
|
|
24881
|
-
var
|
|
24908
|
+
var import_bip393 = __toESM(require_src(), 1);
|
|
24882
24909
|
var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
|
|
24883
24910
|
var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
|
|
24884
24911
|
var SLOT_CONFIG_NETWORK = {
|
|
@@ -25063,11 +25090,11 @@ var getCoseKeyFromPublicKey = (cbor) => {
|
|
|
25063
25090
|
// src/cardano/signer/cardano-signer.ts
|
|
25064
25091
|
var CardanoSigner = class {
|
|
25065
25092
|
constructor() {
|
|
25066
|
-
(0,
|
|
25093
|
+
(0, import_core6.setInConwayEra)(true);
|
|
25067
25094
|
}
|
|
25068
25095
|
static async signTx(tx, signers, returnFullTx = false) {
|
|
25069
|
-
const cardanoTx =
|
|
25070
|
-
|
|
25096
|
+
const cardanoTx = import_core6.Serialization.Transaction.fromCbor(
|
|
25097
|
+
import_core6.Serialization.TxCBOR(tx)
|
|
25071
25098
|
);
|
|
25072
25099
|
const txHash = cardanoTx.body().hash();
|
|
25073
25100
|
const vkeyWitnesses = [];
|
|
@@ -25085,22 +25112,22 @@ var CardanoSigner = class {
|
|
|
25085
25112
|
...vkeyWitnesses
|
|
25086
25113
|
] : vkeyWitnesses;
|
|
25087
25114
|
txWitnessSet2.setVkeys(
|
|
25088
|
-
|
|
25115
|
+
import_core6.Serialization.CborSet.fromCore(
|
|
25089
25116
|
witnessSetVkeysValues,
|
|
25090
|
-
|
|
25117
|
+
import_core6.Serialization.VkeyWitness.fromCore
|
|
25091
25118
|
)
|
|
25092
25119
|
);
|
|
25093
|
-
return new
|
|
25120
|
+
return new import_core6.Serialization.Transaction(
|
|
25094
25121
|
cardanoTx.body(),
|
|
25095
25122
|
txWitnessSet2,
|
|
25096
25123
|
cardanoTx.auxiliaryData()
|
|
25097
25124
|
).toCbor();
|
|
25098
25125
|
}
|
|
25099
|
-
const txWitnessSet = new
|
|
25126
|
+
const txWitnessSet = new import_core6.Serialization.TransactionWitnessSet();
|
|
25100
25127
|
txWitnessSet.setVkeys(
|
|
25101
|
-
|
|
25128
|
+
import_core6.Serialization.CborSet.fromCore(
|
|
25102
25129
|
vkeyWitnesses,
|
|
25103
|
-
|
|
25130
|
+
import_core6.Serialization.VkeyWitness.fromCore
|
|
25104
25131
|
)
|
|
25105
25132
|
);
|
|
25106
25133
|
return txWitnessSet.toCbor();
|
|
@@ -25134,7 +25161,7 @@ var CardanoSigner = class {
|
|
|
25134
25161
|
};
|
|
25135
25162
|
|
|
25136
25163
|
// src/cardano/utils/transaction-signers.ts
|
|
25137
|
-
var
|
|
25164
|
+
var import_core7 = require("@cardano-sdk/core");
|
|
25138
25165
|
async function getRequiredSignersFromInputs(txBody, fetcher) {
|
|
25139
25166
|
const requiredSigners = /* @__PURE__ */ new Set();
|
|
25140
25167
|
let inputs = txBody.inputs().values();
|
|
@@ -25162,7 +25189,7 @@ async function getRequiredSignersFromInputs(txBody, fetcher) {
|
|
|
25162
25189
|
});
|
|
25163
25190
|
});
|
|
25164
25191
|
for (const utxo of utxos) {
|
|
25165
|
-
const address =
|
|
25192
|
+
const address = import_core7.Cardano.Address.fromBech32(utxo.output.address);
|
|
25166
25193
|
const addressProps = address.getProps();
|
|
25167
25194
|
if (addressProps.paymentPart) {
|
|
25168
25195
|
if (addressProps.paymentPart.type === 0 /* KeyHash */) {
|
|
@@ -25284,7 +25311,11 @@ function getRequiredSignersFromWithdrawals(txBody) {
|
|
|
25284
25311
|
const withdrawals = txBody.withdrawals();
|
|
25285
25312
|
if (withdrawals) {
|
|
25286
25313
|
for (const rewardAccount of withdrawals.keys()) {
|
|
25287
|
-
|
|
25314
|
+
const address = import_core7.Cardano.Address.fromBech32(rewardAccount);
|
|
25315
|
+
const addressType = address.getType();
|
|
25316
|
+
if (addressType === import_core7.Cardano.AddressType.RewardKey) {
|
|
25317
|
+
requiredSigners.add(import_core7.Cardano.RewardAccount.toHash(rewardAccount));
|
|
25318
|
+
}
|
|
25288
25319
|
}
|
|
25289
25320
|
}
|
|
25290
25321
|
return requiredSigners;
|
|
@@ -25340,7 +25371,25 @@ async function getTransactionRequiredSigners(transaction, fetcher) {
|
|
|
25340
25371
|
return allRequiredSigners;
|
|
25341
25372
|
}
|
|
25342
25373
|
|
|
25343
|
-
// src/cardano/
|
|
25374
|
+
// src/cardano/utils/value.ts
|
|
25375
|
+
var import_core8 = require("@cardano-sdk/core");
|
|
25376
|
+
function mergeValue(a, b) {
|
|
25377
|
+
const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
|
|
25378
|
+
b.multiasset()?.forEach((v, k) => {
|
|
25379
|
+
const newVal = (ma.get(k) ?? 0n) + v;
|
|
25380
|
+
if (newVal == 0n) {
|
|
25381
|
+
ma.delete(k);
|
|
25382
|
+
} else {
|
|
25383
|
+
ma.set(k, newVal);
|
|
25384
|
+
}
|
|
25385
|
+
});
|
|
25386
|
+
return new import_core8.Serialization.Value(
|
|
25387
|
+
BigInt(a.coin()) + BigInt(b.coin()),
|
|
25388
|
+
ma.size > 0 ? ma : void 0
|
|
25389
|
+
);
|
|
25390
|
+
}
|
|
25391
|
+
|
|
25392
|
+
// src/cardano/wallet/mesh/cardano-headless-wallet.ts
|
|
25344
25393
|
var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
25345
25394
|
constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
|
|
25346
25395
|
(0, import_core9.setInConwayEra)(true);
|
|
@@ -25369,9 +25418,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
|
25369
25418
|
* @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
|
|
25370
25419
|
*/
|
|
25371
25420
|
static async fromBip32Root(config) {
|
|
25372
|
-
const
|
|
25421
|
+
const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
|
|
25373
25422
|
return _CardanoHeadlessWallet.create({
|
|
25374
|
-
addressSource: { type: "secretManager", secretManager:
|
|
25423
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
25375
25424
|
networkId: config.networkId,
|
|
25376
25425
|
walletAddressType: config.walletAddressType,
|
|
25377
25426
|
fetcher: config.fetcher,
|
|
@@ -25384,9 +25433,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
|
25384
25433
|
* @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
|
|
25385
25434
|
*/
|
|
25386
25435
|
static async fromBip32RootHex(config) {
|
|
25387
|
-
const
|
|
25436
|
+
const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
|
|
25388
25437
|
return _CardanoHeadlessWallet.create({
|
|
25389
|
-
addressSource: { type: "secretManager", secretManager:
|
|
25438
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
25390
25439
|
networkId: config.networkId,
|
|
25391
25440
|
walletAddressType: config.walletAddressType,
|
|
25392
25441
|
fetcher: config.fetcher,
|
|
@@ -25399,12 +25448,12 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
|
25399
25448
|
* @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
|
|
25400
25449
|
*/
|
|
25401
25450
|
static async fromMnemonic(config) {
|
|
25402
|
-
const
|
|
25451
|
+
const bip322 = await CardanoInMemoryBip32.fromMnemonic(
|
|
25403
25452
|
config.mnemonic,
|
|
25404
25453
|
config.password
|
|
25405
25454
|
);
|
|
25406
25455
|
return _CardanoHeadlessWallet.create({
|
|
25407
|
-
addressSource: { type: "secretManager", secretManager:
|
|
25456
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
25408
25457
|
networkId: config.networkId,
|
|
25409
25458
|
walletAddressType: config.walletAddressType,
|
|
25410
25459
|
fetcher: config.fetcher,
|
|
@@ -25600,9 +25649,7 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
|
25600
25649
|
transaction,
|
|
25601
25650
|
this.fetcher
|
|
25602
25651
|
);
|
|
25603
|
-
const signersMap = await this.addressManager.getCredentialsSigners(
|
|
25604
|
-
requiredSigners
|
|
25605
|
-
);
|
|
25652
|
+
const signersMap = await this.addressManager.getCredentialsSigners(requiredSigners);
|
|
25606
25653
|
if (!partialSign) {
|
|
25607
25654
|
if (requiredSigners.size !== signersMap.size) {
|
|
25608
25655
|
throw new Error("[CardanoWallet] Not all required signers found");
|
|
@@ -25675,12 +25722,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
25675
25722
|
);
|
|
25676
25723
|
}
|
|
25677
25724
|
static async fromMnemonic(config) {
|
|
25678
|
-
const
|
|
25725
|
+
const bip322 = await CardanoInMemoryBip32.fromMnemonic(
|
|
25679
25726
|
config.mnemonic,
|
|
25680
25727
|
config.password
|
|
25681
25728
|
);
|
|
25682
25729
|
return _MeshCardanoHeadlessWallet.create({
|
|
25683
|
-
addressSource: { type: "secretManager", secretManager:
|
|
25730
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
25684
25731
|
networkId: config.networkId,
|
|
25685
25732
|
walletAddressType: config.walletAddressType,
|
|
25686
25733
|
fetcher: config.fetcher,
|
|
@@ -25688,9 +25735,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
25688
25735
|
});
|
|
25689
25736
|
}
|
|
25690
25737
|
static async fromBip32Root(config) {
|
|
25691
|
-
const
|
|
25738
|
+
const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
|
|
25692
25739
|
return _MeshCardanoHeadlessWallet.create({
|
|
25693
|
-
addressSource: { type: "secretManager", secretManager:
|
|
25740
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
25694
25741
|
networkId: config.networkId,
|
|
25695
25742
|
walletAddressType: config.walletAddressType,
|
|
25696
25743
|
fetcher: config.fetcher,
|
|
@@ -25698,9 +25745,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
25698
25745
|
});
|
|
25699
25746
|
}
|
|
25700
25747
|
static async fromBip32RootHex(config) {
|
|
25701
|
-
const
|
|
25748
|
+
const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
|
|
25702
25749
|
return _MeshCardanoHeadlessWallet.create({
|
|
25703
|
-
addressSource: { type: "secretManager", secretManager:
|
|
25750
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
25704
25751
|
networkId: config.networkId,
|
|
25705
25752
|
walletAddressType: config.walletAddressType,
|
|
25706
25753
|
fetcher: config.fetcher,
|
|
@@ -25752,26 +25799,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
25752
25799
|
if (!this.fetcher) {
|
|
25753
25800
|
throw new Error("[CardanoWallet] No fetcher provided");
|
|
25754
25801
|
}
|
|
25755
|
-
const
|
|
25756
|
-
|
|
25757
|
-
|
|
25758
|
-
|
|
25759
|
-
|
|
25760
|
-
if (asset.unit === "lovelace" || asset.unit === "") {
|
|
25761
|
-
lovelace = parseInt(asset.quantity);
|
|
25762
|
-
}
|
|
25763
|
-
}
|
|
25764
|
-
return lovelace;
|
|
25765
|
-
};
|
|
25766
|
-
const sortedUtxos = utxos.sort(
|
|
25767
|
-
(a, b) => getUtxoLovelaceValue(a) - getUtxoLovelaceValue(b)
|
|
25802
|
+
const collaterals = await this.getCollateral();
|
|
25803
|
+
return collaterals.map(
|
|
25804
|
+
(coll) => fromTxUnspentOutput(
|
|
25805
|
+
import_core10.Serialization.TransactionUnspentOutput.fromCbor((0, import_util6.HexBlob)(coll))
|
|
25806
|
+
)
|
|
25768
25807
|
);
|
|
25769
|
-
for (const utxo of sortedUtxos) {
|
|
25770
|
-
if (getUtxoLovelaceValue(utxo) >= 5e6) {
|
|
25771
|
-
return [utxo];
|
|
25772
|
-
}
|
|
25773
|
-
}
|
|
25774
|
-
return [];
|
|
25775
25808
|
}
|
|
25776
25809
|
/**
|
|
25777
25810
|
* Get the balance of the wallet.
|
|
@@ -25894,11 +25927,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
25894
25927
|
0 && (module.exports = {
|
|
25895
25928
|
AddressType,
|
|
25896
25929
|
BaseSigner,
|
|
25930
|
+
BitcoinInMemoryBip32,
|
|
25897
25931
|
CardanoAddress,
|
|
25898
25932
|
CardanoBrowserWallet,
|
|
25899
25933
|
CardanoHeadlessWallet,
|
|
25934
|
+
CardanoInMemoryBip32,
|
|
25900
25935
|
CredentialType,
|
|
25901
|
-
InMemoryBip32,
|
|
25902
25936
|
MeshCardanoBrowserWallet,
|
|
25903
25937
|
MeshCardanoHeadlessWallet
|
|
25904
25938
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -13,13 +13,13 @@ interface ISecretManager {
|
|
|
13
13
|
getSigner(derivationPath: DerivationPath): Promise<ISigner>;
|
|
14
14
|
}
|
|
15
15
|
|
|
16
|
-
declare class
|
|
16
|
+
declare class CardanoInMemoryBip32 implements ISecretManager {
|
|
17
17
|
private bip32PrivateKey;
|
|
18
18
|
private constructor();
|
|
19
|
-
static fromMnemonic(mnemonic: string[], password?: string): Promise<
|
|
20
|
-
static fromEntropy(entropy: string, password?: string): Promise<
|
|
21
|
-
static fromKeyHex(keyHex: string):
|
|
22
|
-
static fromBech32(bech32: string):
|
|
19
|
+
static fromMnemonic(mnemonic: string[], password?: string): Promise<CardanoInMemoryBip32>;
|
|
20
|
+
static fromEntropy(entropy: string, password?: string): Promise<CardanoInMemoryBip32>;
|
|
21
|
+
static fromKeyHex(keyHex: string): CardanoInMemoryBip32;
|
|
22
|
+
static fromBech32(bech32: string): CardanoInMemoryBip32;
|
|
23
23
|
/**
|
|
24
24
|
* Get the Bip32 public key in hex format.
|
|
25
25
|
* @returns {Promise<string>} A promise that resolves to the public key in hex format.
|
|
@@ -32,6 +32,21 @@ declare class InMemoryBip32 implements ISecretManager {
|
|
|
32
32
|
getSigner(derivationPath: DerivationPath): Promise<ISigner>;
|
|
33
33
|
}
|
|
34
34
|
|
|
35
|
+
declare class BitcoinInMemoryBip32 {
|
|
36
|
+
private root;
|
|
37
|
+
private constructor();
|
|
38
|
+
static fromMnemonic(mnemonic: string[], password?: string): Promise<BitcoinInMemoryBip32>;
|
|
39
|
+
static fromEntropy(entropy: string, password?: string): Promise<BitcoinInMemoryBip32>;
|
|
40
|
+
/**
|
|
41
|
+
* Get the private key (hex) for the provided derivation path.
|
|
42
|
+
*/
|
|
43
|
+
getPrivateKey(derivationPath: DerivationPath): string;
|
|
44
|
+
/**
|
|
45
|
+
* Get the public key (hex) for the provided derivation path.
|
|
46
|
+
*/
|
|
47
|
+
getPublicKey(derivationPath: DerivationPath): string;
|
|
48
|
+
}
|
|
49
|
+
|
|
35
50
|
/**
|
|
36
51
|
* BaseSigner provides functionalities to sign and verify data using Ed25519 keys.
|
|
37
52
|
* It supports construction from both extended and normal private key hex formats.
|
|
@@ -515,4 +530,4 @@ declare class MeshCardanoHeadlessWallet extends CardanoHeadlessWallet {
|
|
|
515
530
|
signTxReturnFullTx(tx: string, partialSign?: boolean): Promise<string>;
|
|
516
531
|
}
|
|
517
532
|
|
|
518
|
-
export { AddressType, BaseSigner, type Cardano, CardanoAddress, CardanoBrowserWallet, CardanoHeadlessWallet, type CardanoHeadlessWalletConfig, type Credential, type CredentialSource, CredentialType, type ICardanoWallet,
|
|
533
|
+
export { AddressType, BaseSigner, BitcoinInMemoryBip32, type Cardano, CardanoAddress, CardanoBrowserWallet, CardanoHeadlessWallet, type CardanoHeadlessWalletConfig, CardanoInMemoryBip32, type Credential, type CredentialSource, CredentialType, type ICardanoWallet, MeshCardanoBrowserWallet, MeshCardanoHeadlessWallet, type WalletAddressType };
|
package/dist/index.js
CHANGED
|
@@ -21877,7 +21877,7 @@ var require_src = __commonJS({
|
|
|
21877
21877
|
return Buffer.from(res);
|
|
21878
21878
|
}
|
|
21879
21879
|
exports.mnemonicToSeedSync = mnemonicToSeedSync;
|
|
21880
|
-
function
|
|
21880
|
+
function mnemonicToSeed2(mnemonic, password) {
|
|
21881
21881
|
const mnemonicBuffer = Uint8Array.from(Buffer.from(normalize(mnemonic), "utf8"));
|
|
21882
21882
|
const saltBuffer = Uint8Array.from(Buffer.from(salt(normalize(password)), "utf8"));
|
|
21883
21883
|
return pbkdf2_1.pbkdf2Async(sha512_1.sha512, mnemonicBuffer, saltBuffer, {
|
|
@@ -21885,7 +21885,7 @@ var require_src = __commonJS({
|
|
|
21885
21885
|
dkLen: 64
|
|
21886
21886
|
}).then((res) => Buffer.from(res));
|
|
21887
21887
|
}
|
|
21888
|
-
exports.mnemonicToSeed =
|
|
21888
|
+
exports.mnemonicToSeed = mnemonicToSeed2;
|
|
21889
21889
|
function mnemonicToEntropy3(mnemonic, wordlist) {
|
|
21890
21890
|
wordlist = wordlist || DEFAULT_WORDLIST;
|
|
21891
21891
|
if (!wordlist) {
|
|
@@ -21923,7 +21923,7 @@ var require_src = __commonJS({
|
|
|
21923
21923
|
return entropy.toString("hex");
|
|
21924
21924
|
}
|
|
21925
21925
|
exports.mnemonicToEntropy = mnemonicToEntropy3;
|
|
21926
|
-
function
|
|
21926
|
+
function entropyToMnemonic2(entropy, wordlist) {
|
|
21927
21927
|
if (!Buffer.isBuffer(entropy)) {
|
|
21928
21928
|
entropy = Buffer.from(entropy, "hex");
|
|
21929
21929
|
}
|
|
@@ -21950,14 +21950,14 @@ var require_src = __commonJS({
|
|
|
21950
21950
|
});
|
|
21951
21951
|
return wordlist[0] === "\u3042\u3044\u3053\u304F\u3057\u3093" ? words.join("\u3000") : words.join(" ");
|
|
21952
21952
|
}
|
|
21953
|
-
exports.entropyToMnemonic =
|
|
21953
|
+
exports.entropyToMnemonic = entropyToMnemonic2;
|
|
21954
21954
|
function generateMnemonic2(strength, rng, wordlist) {
|
|
21955
21955
|
strength = strength || 128;
|
|
21956
21956
|
if (strength % 32 !== 0) {
|
|
21957
21957
|
throw new TypeError(INVALID_ENTROPY);
|
|
21958
21958
|
}
|
|
21959
21959
|
rng = rng || ((size) => Buffer.from(utils_1.randomBytes(size)));
|
|
21960
|
-
return
|
|
21960
|
+
return entropyToMnemonic2(rng(strength / 8), wordlist);
|
|
21961
21961
|
}
|
|
21962
21962
|
exports.generateMnemonic = generateMnemonic2;
|
|
21963
21963
|
function validateMnemonic(mnemonic, wordlist) {
|
|
@@ -24435,7 +24435,7 @@ var require_blakejs = __commonJS({
|
|
|
24435
24435
|
}
|
|
24436
24436
|
});
|
|
24437
24437
|
|
|
24438
|
-
// src/bip32/in-memory-bip32.ts
|
|
24438
|
+
// src/bip32/cardano-in-memory-bip32.ts
|
|
24439
24439
|
import {
|
|
24440
24440
|
Bip32PrivateKey,
|
|
24441
24441
|
ready
|
|
@@ -24699,7 +24699,7 @@ function genBech32(encoding) {
|
|
|
24699
24699
|
}
|
|
24700
24700
|
var bech32 = /* @__PURE__ */ genBech32("bech32");
|
|
24701
24701
|
|
|
24702
|
-
// src/bip32/in-memory-bip32.ts
|
|
24702
|
+
// src/bip32/cardano-in-memory-bip32.ts
|
|
24703
24703
|
var import_bip39 = __toESM(require_src(), 1);
|
|
24704
24704
|
|
|
24705
24705
|
// src/cardano/utils/constants.ts
|
|
@@ -24724,9 +24724,6 @@ var DEFAULT_DREP_KEY_DERIVATION_PATH = [
|
|
|
24724
24724
|
|
|
24725
24725
|
// src/interfaces/secret-manager.ts
|
|
24726
24726
|
var derivationPathVectorFromString = (path) => {
|
|
24727
|
-
if (!/^m?\/\d+(\/\d+)*$/.test(path)) {
|
|
24728
|
-
throw new Error(`Invalid derivation path: ${path}`);
|
|
24729
|
-
}
|
|
24730
24727
|
let pathString = path;
|
|
24731
24728
|
if (pathString.startsWith("m/")) {
|
|
24732
24729
|
pathString = pathString.slice(2);
|
|
@@ -24739,6 +24736,15 @@ var derivationPathVectorFromString = (path) => {
|
|
|
24739
24736
|
}
|
|
24740
24737
|
});
|
|
24741
24738
|
};
|
|
24739
|
+
var derivationPathStringFromVector = (path) => {
|
|
24740
|
+
return path.map((part) => {
|
|
24741
|
+
if (part >= HARDENED_OFFSET) {
|
|
24742
|
+
return part - HARDENED_OFFSET + "'";
|
|
24743
|
+
} else {
|
|
24744
|
+
return part.toString();
|
|
24745
|
+
}
|
|
24746
|
+
}).join("/");
|
|
24747
|
+
};
|
|
24742
24748
|
|
|
24743
24749
|
// src/signer/base-signer.ts
|
|
24744
24750
|
import { setInConwayEra } from "@cardano-sdk/core";
|
|
@@ -24823,8 +24829,8 @@ var BaseSigner = class _BaseSigner {
|
|
|
24823
24829
|
}
|
|
24824
24830
|
};
|
|
24825
24831
|
|
|
24826
|
-
// src/bip32/in-memory-bip32.ts
|
|
24827
|
-
var
|
|
24832
|
+
// src/bip32/cardano-in-memory-bip32.ts
|
|
24833
|
+
var CardanoInMemoryBip32 = class _CardanoInMemoryBip32 {
|
|
24828
24834
|
constructor(privateKey) {
|
|
24829
24835
|
this.bip32PrivateKey = privateKey;
|
|
24830
24836
|
}
|
|
@@ -24835,7 +24841,7 @@ var InMemoryBip32 = class _InMemoryBip32 {
|
|
|
24835
24841
|
Buffer.from(entropy, "hex"),
|
|
24836
24842
|
password || ""
|
|
24837
24843
|
);
|
|
24838
|
-
return new
|
|
24844
|
+
return new _CardanoInMemoryBip32(bip32PrivateKey);
|
|
24839
24845
|
}
|
|
24840
24846
|
static async fromEntropy(entropy, password) {
|
|
24841
24847
|
await ready();
|
|
@@ -24843,18 +24849,18 @@ var InMemoryBip32 = class _InMemoryBip32 {
|
|
|
24843
24849
|
Buffer.from(entropy, "hex"),
|
|
24844
24850
|
password || ""
|
|
24845
24851
|
);
|
|
24846
|
-
return new
|
|
24852
|
+
return new _CardanoInMemoryBip32(bip32PrivateKey);
|
|
24847
24853
|
}
|
|
24848
24854
|
static fromKeyHex(keyHex) {
|
|
24849
24855
|
const bip32PrivateKey = Bip32PrivateKey.fromHex(
|
|
24850
24856
|
keyHex
|
|
24851
24857
|
);
|
|
24852
|
-
return new
|
|
24858
|
+
return new _CardanoInMemoryBip32(bip32PrivateKey);
|
|
24853
24859
|
}
|
|
24854
24860
|
static fromBech32(bech323) {
|
|
24855
24861
|
const bech32DecodedBytes = bech32.decodeToBytes(bech323).bytes;
|
|
24856
24862
|
const bip32PrivateKey = Bip32PrivateKey.fromBytes(bech32DecodedBytes);
|
|
24857
|
-
return new
|
|
24863
|
+
return new _CardanoInMemoryBip32(bip32PrivateKey);
|
|
24858
24864
|
}
|
|
24859
24865
|
/**
|
|
24860
24866
|
* Get the Bip32 public key in hex format.
|
|
@@ -24875,6 +24881,44 @@ var InMemoryBip32 = class _InMemoryBip32 {
|
|
|
24875
24881
|
}
|
|
24876
24882
|
};
|
|
24877
24883
|
|
|
24884
|
+
// src/bip32/bitcoin-in-memory-bip32.ts
|
|
24885
|
+
var import_bip392 = __toESM(require_src(), 1);
|
|
24886
|
+
import * as bip32 from "bip32";
|
|
24887
|
+
import * as ecc from "tiny-secp256k1";
|
|
24888
|
+
var BitcoinInMemoryBip32 = class _BitcoinInMemoryBip32 {
|
|
24889
|
+
constructor(root) {
|
|
24890
|
+
this.root = root;
|
|
24891
|
+
}
|
|
24892
|
+
static async fromMnemonic(mnemonic, password) {
|
|
24893
|
+
const seed = await (0, import_bip392.mnemonicToSeed)(mnemonic.join(" "), password || "");
|
|
24894
|
+
const root = bip32.BIP32Factory(ecc).fromSeed(seed);
|
|
24895
|
+
return new _BitcoinInMemoryBip32(root);
|
|
24896
|
+
}
|
|
24897
|
+
static async fromEntropy(entropy, password) {
|
|
24898
|
+
const mnemonic = (0, import_bip392.entropyToMnemonic)(entropy);
|
|
24899
|
+
const seed = await (0, import_bip392.mnemonicToSeed)(mnemonic, password || "");
|
|
24900
|
+
const root = bip32.BIP32Factory(ecc).fromSeed(seed);
|
|
24901
|
+
return new _BitcoinInMemoryBip32(root);
|
|
24902
|
+
}
|
|
24903
|
+
/**
|
|
24904
|
+
* Get the private key (hex) for the provided derivation path.
|
|
24905
|
+
*/
|
|
24906
|
+
getPrivateKey(derivationPath) {
|
|
24907
|
+
const path = Array.isArray(derivationPath) ? `m/${derivationPathStringFromVector(derivationPath)}` : derivationPath;
|
|
24908
|
+
const child = this.root.derivePath(path);
|
|
24909
|
+
if (!child?.privateKey) throw new Error("No private key at path");
|
|
24910
|
+
return Buffer.from(child.privateKey).toString("hex");
|
|
24911
|
+
}
|
|
24912
|
+
/**
|
|
24913
|
+
* Get the public key (hex) for the provided derivation path.
|
|
24914
|
+
*/
|
|
24915
|
+
getPublicKey(derivationPath) {
|
|
24916
|
+
const path = Array.isArray(derivationPath) ? `m/${derivationPathStringFromVector(derivationPath)}` : derivationPath;
|
|
24917
|
+
const child = this.root.derivePath(path);
|
|
24918
|
+
return Buffer.from(child.publicKey).toString("hex");
|
|
24919
|
+
}
|
|
24920
|
+
};
|
|
24921
|
+
|
|
24878
24922
|
// src/cardano/address/cardano-address.ts
|
|
24879
24923
|
import { Cardano, setInConwayEra as setInConwayEra2 } from "@cardano-sdk/core";
|
|
24880
24924
|
import { Hash28ByteBase16 } from "@cardano-sdk/crypto";
|
|
@@ -25281,27 +25325,9 @@ var MeshCardanoBrowserWallet = class _MeshCardanoBrowserWallet extends CardanoBr
|
|
|
25281
25325
|
}
|
|
25282
25326
|
};
|
|
25283
25327
|
|
|
25284
|
-
// src/cardano/wallet/mesh/cardano-
|
|
25328
|
+
// src/cardano/wallet/mesh/cardano-headless-wallet.ts
|
|
25285
25329
|
import { Cardano as Cardano6, Serialization as Serialization6, setInConwayEra as setInConwayEra5 } from "@cardano-sdk/core";
|
|
25286
25330
|
|
|
25287
|
-
// src/utils/value.ts
|
|
25288
|
-
import { Serialization as Serialization3 } from "@cardano-sdk/core";
|
|
25289
|
-
function mergeValue(a, b) {
|
|
25290
|
-
const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
|
|
25291
|
-
b.multiasset()?.forEach((v, k) => {
|
|
25292
|
-
const newVal = (ma.get(k) ?? 0n) + v;
|
|
25293
|
-
if (newVal == 0n) {
|
|
25294
|
-
ma.delete(k);
|
|
25295
|
-
} else {
|
|
25296
|
-
ma.set(k, newVal);
|
|
25297
|
-
}
|
|
25298
|
-
});
|
|
25299
|
-
return new Serialization3.Value(
|
|
25300
|
-
BigInt(a.coin()) + BigInt(b.coin()),
|
|
25301
|
-
ma.size > 0 ? ma : void 0
|
|
25302
|
-
);
|
|
25303
|
-
}
|
|
25304
|
-
|
|
25305
25331
|
// src/cardano/address/single-address-manager.ts
|
|
25306
25332
|
import { setInConwayEra as setInConwayEra3 } from "@cardano-sdk/core";
|
|
25307
25333
|
var AddressManager = class _AddressManager {
|
|
@@ -25450,7 +25476,7 @@ var AddressManager = class _AddressManager {
|
|
|
25450
25476
|
};
|
|
25451
25477
|
|
|
25452
25478
|
// src/cardano/signer/cardano-signer.ts
|
|
25453
|
-
import { Serialization as
|
|
25479
|
+
import { Serialization as Serialization3, setInConwayEra as setInConwayEra4 } from "@cardano-sdk/core";
|
|
25454
25480
|
import { Ed25519PublicKeyHex, Ed25519SignatureHex as Ed25519SignatureHex2 } from "@cardano-sdk/crypto";
|
|
25455
25481
|
import { HexBlob as HexBlob5 } from "@cardano-sdk/util";
|
|
25456
25482
|
import {
|
|
@@ -25465,7 +25491,7 @@ import {
|
|
|
25465
25491
|
var import_bech32 = __toESM(require_dist(), 1);
|
|
25466
25492
|
var import_blake2b = __toESM(require_blake2b2(), 1);
|
|
25467
25493
|
var import_blakejs = __toESM(require_blakejs(), 1);
|
|
25468
|
-
var
|
|
25494
|
+
var import_bip393 = __toESM(require_src(), 1);
|
|
25469
25495
|
var stringToHex = (str) => Buffer.from(str, "utf8").toString("hex");
|
|
25470
25496
|
var isHexString = (hex) => /^[0-9A-F]*$/i.test(hex);
|
|
25471
25497
|
var SLOT_CONFIG_NETWORK = {
|
|
@@ -25664,8 +25690,8 @@ var CardanoSigner = class {
|
|
|
25664
25690
|
setInConwayEra4(true);
|
|
25665
25691
|
}
|
|
25666
25692
|
static async signTx(tx, signers, returnFullTx = false) {
|
|
25667
|
-
const cardanoTx =
|
|
25668
|
-
|
|
25693
|
+
const cardanoTx = Serialization3.Transaction.fromCbor(
|
|
25694
|
+
Serialization3.TxCBOR(tx)
|
|
25669
25695
|
);
|
|
25670
25696
|
const txHash = cardanoTx.body().hash();
|
|
25671
25697
|
const vkeyWitnesses = [];
|
|
@@ -25683,22 +25709,22 @@ var CardanoSigner = class {
|
|
|
25683
25709
|
...vkeyWitnesses
|
|
25684
25710
|
] : vkeyWitnesses;
|
|
25685
25711
|
txWitnessSet2.setVkeys(
|
|
25686
|
-
|
|
25712
|
+
Serialization3.CborSet.fromCore(
|
|
25687
25713
|
witnessSetVkeysValues,
|
|
25688
|
-
|
|
25714
|
+
Serialization3.VkeyWitness.fromCore
|
|
25689
25715
|
)
|
|
25690
25716
|
);
|
|
25691
|
-
return new
|
|
25717
|
+
return new Serialization3.Transaction(
|
|
25692
25718
|
cardanoTx.body(),
|
|
25693
25719
|
txWitnessSet2,
|
|
25694
25720
|
cardanoTx.auxiliaryData()
|
|
25695
25721
|
).toCbor();
|
|
25696
25722
|
}
|
|
25697
|
-
const txWitnessSet = new
|
|
25723
|
+
const txWitnessSet = new Serialization3.TransactionWitnessSet();
|
|
25698
25724
|
txWitnessSet.setVkeys(
|
|
25699
|
-
|
|
25725
|
+
Serialization3.CborSet.fromCore(
|
|
25700
25726
|
vkeyWitnesses,
|
|
25701
|
-
|
|
25727
|
+
Serialization3.VkeyWitness.fromCore
|
|
25702
25728
|
)
|
|
25703
25729
|
);
|
|
25704
25730
|
return txWitnessSet.toCbor();
|
|
@@ -25732,7 +25758,7 @@ var CardanoSigner = class {
|
|
|
25732
25758
|
};
|
|
25733
25759
|
|
|
25734
25760
|
// src/cardano/utils/transaction-signers.ts
|
|
25735
|
-
import { Cardano as
|
|
25761
|
+
import { Cardano as Cardano4 } from "@cardano-sdk/core";
|
|
25736
25762
|
async function getRequiredSignersFromInputs(txBody, fetcher) {
|
|
25737
25763
|
const requiredSigners = /* @__PURE__ */ new Set();
|
|
25738
25764
|
let inputs = txBody.inputs().values();
|
|
@@ -25760,7 +25786,7 @@ async function getRequiredSignersFromInputs(txBody, fetcher) {
|
|
|
25760
25786
|
});
|
|
25761
25787
|
});
|
|
25762
25788
|
for (const utxo of utxos) {
|
|
25763
|
-
const address =
|
|
25789
|
+
const address = Cardano4.Address.fromBech32(utxo.output.address);
|
|
25764
25790
|
const addressProps = address.getProps();
|
|
25765
25791
|
if (addressProps.paymentPart) {
|
|
25766
25792
|
if (addressProps.paymentPart.type === 0 /* KeyHash */) {
|
|
@@ -25882,7 +25908,11 @@ function getRequiredSignersFromWithdrawals(txBody) {
|
|
|
25882
25908
|
const withdrawals = txBody.withdrawals();
|
|
25883
25909
|
if (withdrawals) {
|
|
25884
25910
|
for (const rewardAccount of withdrawals.keys()) {
|
|
25885
|
-
|
|
25911
|
+
const address = Cardano4.Address.fromBech32(rewardAccount);
|
|
25912
|
+
const addressType = address.getType();
|
|
25913
|
+
if (addressType === Cardano4.AddressType.RewardKey) {
|
|
25914
|
+
requiredSigners.add(Cardano4.RewardAccount.toHash(rewardAccount));
|
|
25915
|
+
}
|
|
25886
25916
|
}
|
|
25887
25917
|
}
|
|
25888
25918
|
return requiredSigners;
|
|
@@ -25938,7 +25968,25 @@ async function getTransactionRequiredSigners(transaction, fetcher) {
|
|
|
25938
25968
|
return allRequiredSigners;
|
|
25939
25969
|
}
|
|
25940
25970
|
|
|
25941
|
-
// src/cardano/
|
|
25971
|
+
// src/cardano/utils/value.ts
|
|
25972
|
+
import { Serialization as Serialization5 } from "@cardano-sdk/core";
|
|
25973
|
+
function mergeValue(a, b) {
|
|
25974
|
+
const ma = a.multiasset() ?? /* @__PURE__ */ new Map();
|
|
25975
|
+
b.multiasset()?.forEach((v, k) => {
|
|
25976
|
+
const newVal = (ma.get(k) ?? 0n) + v;
|
|
25977
|
+
if (newVal == 0n) {
|
|
25978
|
+
ma.delete(k);
|
|
25979
|
+
} else {
|
|
25980
|
+
ma.set(k, newVal);
|
|
25981
|
+
}
|
|
25982
|
+
});
|
|
25983
|
+
return new Serialization5.Value(
|
|
25984
|
+
BigInt(a.coin()) + BigInt(b.coin()),
|
|
25985
|
+
ma.size > 0 ? ma : void 0
|
|
25986
|
+
);
|
|
25987
|
+
}
|
|
25988
|
+
|
|
25989
|
+
// src/cardano/wallet/mesh/cardano-headless-wallet.ts
|
|
25942
25990
|
var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
25943
25991
|
constructor(networkId, addressManager, walletAddressType, fetcher, submitter) {
|
|
25944
25992
|
setInConwayEra5(true);
|
|
@@ -25967,9 +26015,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
|
25967
26015
|
* @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
|
|
25968
26016
|
*/
|
|
25969
26017
|
static async fromBip32Root(config) {
|
|
25970
|
-
const
|
|
26018
|
+
const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
|
|
25971
26019
|
return _CardanoHeadlessWallet.create({
|
|
25972
|
-
addressSource: { type: "secretManager", secretManager:
|
|
26020
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
25973
26021
|
networkId: config.networkId,
|
|
25974
26022
|
walletAddressType: config.walletAddressType,
|
|
25975
26023
|
fetcher: config.fetcher,
|
|
@@ -25982,9 +26030,9 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
|
25982
26030
|
* @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
|
|
25983
26031
|
*/
|
|
25984
26032
|
static async fromBip32RootHex(config) {
|
|
25985
|
-
const
|
|
26033
|
+
const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
|
|
25986
26034
|
return _CardanoHeadlessWallet.create({
|
|
25987
|
-
addressSource: { type: "secretManager", secretManager:
|
|
26035
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
25988
26036
|
networkId: config.networkId,
|
|
25989
26037
|
walletAddressType: config.walletAddressType,
|
|
25990
26038
|
fetcher: config.fetcher,
|
|
@@ -25997,12 +26045,12 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
|
25997
26045
|
* @returns {Promise<CardanoHeadlessWallet>} A promise that resolves to a CardanoHeadlessWallet instance
|
|
25998
26046
|
*/
|
|
25999
26047
|
static async fromMnemonic(config) {
|
|
26000
|
-
const
|
|
26048
|
+
const bip322 = await CardanoInMemoryBip32.fromMnemonic(
|
|
26001
26049
|
config.mnemonic,
|
|
26002
26050
|
config.password
|
|
26003
26051
|
);
|
|
26004
26052
|
return _CardanoHeadlessWallet.create({
|
|
26005
|
-
addressSource: { type: "secretManager", secretManager:
|
|
26053
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
26006
26054
|
networkId: config.networkId,
|
|
26007
26055
|
walletAddressType: config.walletAddressType,
|
|
26008
26056
|
fetcher: config.fetcher,
|
|
@@ -26198,9 +26246,7 @@ var CardanoHeadlessWallet = class _CardanoHeadlessWallet {
|
|
|
26198
26246
|
transaction,
|
|
26199
26247
|
this.fetcher
|
|
26200
26248
|
);
|
|
26201
|
-
const signersMap = await this.addressManager.getCredentialsSigners(
|
|
26202
|
-
requiredSigners
|
|
26203
|
-
);
|
|
26249
|
+
const signersMap = await this.addressManager.getCredentialsSigners(requiredSigners);
|
|
26204
26250
|
if (!partialSign) {
|
|
26205
26251
|
if (requiredSigners.size !== signersMap.size) {
|
|
26206
26252
|
throw new Error("[CardanoWallet] Not all required signers found");
|
|
@@ -26273,12 +26319,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
26273
26319
|
);
|
|
26274
26320
|
}
|
|
26275
26321
|
static async fromMnemonic(config) {
|
|
26276
|
-
const
|
|
26322
|
+
const bip322 = await CardanoInMemoryBip32.fromMnemonic(
|
|
26277
26323
|
config.mnemonic,
|
|
26278
26324
|
config.password
|
|
26279
26325
|
);
|
|
26280
26326
|
return _MeshCardanoHeadlessWallet.create({
|
|
26281
|
-
addressSource: { type: "secretManager", secretManager:
|
|
26327
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
26282
26328
|
networkId: config.networkId,
|
|
26283
26329
|
walletAddressType: config.walletAddressType,
|
|
26284
26330
|
fetcher: config.fetcher,
|
|
@@ -26286,9 +26332,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
26286
26332
|
});
|
|
26287
26333
|
}
|
|
26288
26334
|
static async fromBip32Root(config) {
|
|
26289
|
-
const
|
|
26335
|
+
const bip322 = CardanoInMemoryBip32.fromBech32(config.bech32);
|
|
26290
26336
|
return _MeshCardanoHeadlessWallet.create({
|
|
26291
|
-
addressSource: { type: "secretManager", secretManager:
|
|
26337
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
26292
26338
|
networkId: config.networkId,
|
|
26293
26339
|
walletAddressType: config.walletAddressType,
|
|
26294
26340
|
fetcher: config.fetcher,
|
|
@@ -26296,9 +26342,9 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
26296
26342
|
});
|
|
26297
26343
|
}
|
|
26298
26344
|
static async fromBip32RootHex(config) {
|
|
26299
|
-
const
|
|
26345
|
+
const bip322 = CardanoInMemoryBip32.fromKeyHex(config.hex);
|
|
26300
26346
|
return _MeshCardanoHeadlessWallet.create({
|
|
26301
|
-
addressSource: { type: "secretManager", secretManager:
|
|
26347
|
+
addressSource: { type: "secretManager", secretManager: bip322 },
|
|
26302
26348
|
networkId: config.networkId,
|
|
26303
26349
|
walletAddressType: config.walletAddressType,
|
|
26304
26350
|
fetcher: config.fetcher,
|
|
@@ -26350,26 +26396,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
26350
26396
|
if (!this.fetcher) {
|
|
26351
26397
|
throw new Error("[CardanoWallet] No fetcher provided");
|
|
26352
26398
|
}
|
|
26353
|
-
const
|
|
26354
|
-
|
|
26355
|
-
|
|
26356
|
-
|
|
26357
|
-
|
|
26358
|
-
if (asset.unit === "lovelace" || asset.unit === "") {
|
|
26359
|
-
lovelace = parseInt(asset.quantity);
|
|
26360
|
-
}
|
|
26361
|
-
}
|
|
26362
|
-
return lovelace;
|
|
26363
|
-
};
|
|
26364
|
-
const sortedUtxos = utxos.sort(
|
|
26365
|
-
(a, b) => getUtxoLovelaceValue(a) - getUtxoLovelaceValue(b)
|
|
26399
|
+
const collaterals = await this.getCollateral();
|
|
26400
|
+
return collaterals.map(
|
|
26401
|
+
(coll) => fromTxUnspentOutput(
|
|
26402
|
+
Serialization7.TransactionUnspentOutput.fromCbor(HexBlob6(coll))
|
|
26403
|
+
)
|
|
26366
26404
|
);
|
|
26367
|
-
for (const utxo of sortedUtxos) {
|
|
26368
|
-
if (getUtxoLovelaceValue(utxo) >= 5e6) {
|
|
26369
|
-
return [utxo];
|
|
26370
|
-
}
|
|
26371
|
-
}
|
|
26372
|
-
return [];
|
|
26373
26405
|
}
|
|
26374
26406
|
/**
|
|
26375
26407
|
* Get the balance of the wallet.
|
|
@@ -26491,11 +26523,12 @@ var MeshCardanoHeadlessWallet = class _MeshCardanoHeadlessWallet extends Cardano
|
|
|
26491
26523
|
export {
|
|
26492
26524
|
AddressType,
|
|
26493
26525
|
BaseSigner,
|
|
26526
|
+
BitcoinInMemoryBip32,
|
|
26494
26527
|
CardanoAddress,
|
|
26495
26528
|
CardanoBrowserWallet,
|
|
26496
26529
|
CardanoHeadlessWallet,
|
|
26530
|
+
CardanoInMemoryBip32,
|
|
26497
26531
|
CredentialType,
|
|
26498
|
-
InMemoryBip32,
|
|
26499
26532
|
MeshCardanoBrowserWallet,
|
|
26500
26533
|
MeshCardanoHeadlessWallet
|
|
26501
26534
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@meshsdk/wallet",
|
|
3
|
-
"version": "2.0.0-beta.
|
|
3
|
+
"version": "2.0.0-beta.8",
|
|
4
4
|
"description": "Wallets - https://meshjs.dev/apis/wallets",
|
|
5
5
|
"main": "./dist/index.cjs",
|
|
6
6
|
"browser": "./dist/index.js",
|
|
@@ -19,9 +19,9 @@
|
|
|
19
19
|
],
|
|
20
20
|
"scripts": {
|
|
21
21
|
"build": "tsup",
|
|
22
|
-
"build:demo": "
|
|
23
|
-
"dev:demo": "
|
|
24
|
-
"preview:demo": "
|
|
22
|
+
"build:demo": "npm --prefix demo run build",
|
|
23
|
+
"dev:demo": "npm --prefix demo run dev",
|
|
24
|
+
"preview:demo": "npm --prefix demo run start",
|
|
25
25
|
"build:docs": "typedoc src/index.ts --json ../../apps/docs/src/data/mesh-wallets.json",
|
|
26
26
|
"clean": "rm -rf .turbo && rm -rf dist && rm -rf node_modules",
|
|
27
27
|
"dev": "tsup src/index.ts --format esm,cjs --watch --dts",
|
|
@@ -31,29 +31,33 @@
|
|
|
31
31
|
"test": "jest"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
+
"@ianvs/prettier-plugin-sort-imports": "^4.4.1",
|
|
35
|
+
"@meshsdk/common": "1.9.0-beta.100",
|
|
36
|
+
"@meshsdk/provider": "1.9.0-beta.99",
|
|
37
|
+
"@types/jest": "^29.5.12",
|
|
38
|
+
"dotenv": "^16.4.5",
|
|
34
39
|
"eslint": "^8.57.0",
|
|
40
|
+
"jest": "^29.7.0",
|
|
35
41
|
"patch-package": "^8.0.1",
|
|
42
|
+
"prettier": "^3.5.3",
|
|
43
|
+
"ts-jest": "^29.1.4",
|
|
44
|
+
"ts-node": "^10.9.2",
|
|
36
45
|
"tsup": "^8.0.2",
|
|
37
46
|
"typedoc": "^0.26.3",
|
|
38
|
-
"typescript": "^5.3.3"
|
|
39
|
-
"jest": "^29.7.0",
|
|
40
|
-
"@types/jest": "^29.5.12",
|
|
41
|
-
"ts-node": "^10.9.2",
|
|
42
|
-
"ts-jest": "^29.1.4",
|
|
43
|
-
"dotenv": "^16.4.5",
|
|
44
|
-
"@meshsdk/provider": "1.9.0-beta.99",
|
|
45
|
-
"@meshsdk/common": "1.9.0-beta.100"
|
|
47
|
+
"typescript": "^5.3.3"
|
|
46
48
|
},
|
|
47
49
|
"dependencies": {
|
|
48
50
|
"@cardano-sdk/core": "0.46.11",
|
|
49
51
|
"@cardano-sdk/crypto": "0.4.4",
|
|
50
52
|
"@cardano-sdk/util": "0.17.1",
|
|
51
53
|
"@harmoniclabs/cbor": "^1.6.6",
|
|
52
|
-
"json-bigint": "^1.0.0",
|
|
53
54
|
"@simplewebauthn/browser": "^13.0.0",
|
|
54
55
|
"@types/base32-encoding": "^1.0.2",
|
|
55
56
|
"@types/bn.js": "^5.1.5",
|
|
56
|
-
"base32-encoding": "^1.0.0"
|
|
57
|
+
"base32-encoding": "^1.0.0",
|
|
58
|
+
"bip32": "^5.0.0",
|
|
59
|
+
"json-bigint": "^1.0.0",
|
|
60
|
+
"tiny-secp256k1": "^2.2.4"
|
|
57
61
|
},
|
|
58
62
|
"prettier": "./prettier.config.js",
|
|
59
63
|
"publishConfig": {
|