@meshsdk/bitcoin 1.9.0-beta.62 → 1.9.0-beta.64
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 +35 -4
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +10 -2
- package/dist/index.d.ts +10 -2
- package/dist/index.js +35 -4
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.cjs
CHANGED
|
@@ -4320,8 +4320,14 @@ var EmbeddedWallet = /*#__PURE__*/ function() {
|
|
|
4320
4320
|
function EmbeddedWallet(options) {
|
|
4321
4321
|
_class_call_check(this, EmbeddedWallet);
|
|
4322
4322
|
this._network = options.testnet ? bitcoin.networks.testnet : bitcoin.networks.bitcoin;
|
|
4323
|
-
|
|
4324
|
-
|
|
4323
|
+
if (options.key.type === "mnemonic") {
|
|
4324
|
+
var _options_path;
|
|
4325
|
+
this._wallet = _derive(options.key.words, (_options_path = options.path) !== null && _options_path !== void 0 ? _options_path : "m/84'/0'/0'/0/0", this._network);
|
|
4326
|
+
this._isReadOnly = false;
|
|
4327
|
+
} else {
|
|
4328
|
+
this._address = options.key.address;
|
|
4329
|
+
this._isReadOnly = true;
|
|
4330
|
+
}
|
|
4325
4331
|
this._provider = options.provider;
|
|
4326
4332
|
}
|
|
4327
4333
|
_create_class(EmbeddedWallet, [
|
|
@@ -4333,6 +4339,16 @@ var EmbeddedWallet = /*#__PURE__*/ function() {
|
|
|
4333
4339
|
* @throws {Error} If internal address or public key is not properly initialized.
|
|
4334
4340
|
*/ key: "getAddress",
|
|
4335
4341
|
value: function getAddress() {
|
|
4342
|
+
if (this._isReadOnly && this._address) {
|
|
4343
|
+
return {
|
|
4344
|
+
address: this._address,
|
|
4345
|
+
purpose: "payment",
|
|
4346
|
+
addressType: "p2wpkh"
|
|
4347
|
+
};
|
|
4348
|
+
}
|
|
4349
|
+
if (!this._wallet) {
|
|
4350
|
+
throw new Error("Wallet not initialized properly.");
|
|
4351
|
+
}
|
|
4336
4352
|
return resolveAddress(this._wallet.publicKey, this._network);
|
|
4337
4353
|
}
|
|
4338
4354
|
},
|
|
@@ -4341,8 +4357,15 @@ var EmbeddedWallet = /*#__PURE__*/ function() {
|
|
|
4341
4357
|
* Returns the hex-encoded public key of the wallet.
|
|
4342
4358
|
*
|
|
4343
4359
|
* @returns {string} The public key in hexadecimal format.
|
|
4360
|
+
* @throws {Error} If the wallet is read-only and public key is not available.
|
|
4344
4361
|
*/ key: "getPublicKey",
|
|
4345
4362
|
value: function getPublicKey() {
|
|
4363
|
+
if (this._isReadOnly) {
|
|
4364
|
+
throw new Error("Public key is not available for read-only wallets.");
|
|
4365
|
+
}
|
|
4366
|
+
if (!this._wallet) {
|
|
4367
|
+
throw new Error("Wallet not initialized properly.");
|
|
4368
|
+
}
|
|
4346
4369
|
return this._wallet.publicKey.toString("hex");
|
|
4347
4370
|
}
|
|
4348
4371
|
},
|
|
@@ -4393,9 +4416,13 @@ var EmbeddedWallet = /*#__PURE__*/ function() {
|
|
|
4393
4416
|
*
|
|
4394
4417
|
* @param message - The message to be signed.
|
|
4395
4418
|
* @returns The signature of the message as a string.
|
|
4419
|
+
* @throws {Error} If the wallet is read-only or private key is not available.
|
|
4396
4420
|
*/ key: "signData",
|
|
4397
4421
|
value: function signData(message) {
|
|
4398
|
-
if (
|
|
4422
|
+
if (this._isReadOnly) {
|
|
4423
|
+
throw new Error("Cannot sign data with a read-only wallet.");
|
|
4424
|
+
}
|
|
4425
|
+
if (!this._wallet || !this._wallet.privateKey) {
|
|
4399
4426
|
throw new Error("Private key is not available for signing.");
|
|
4400
4427
|
}
|
|
4401
4428
|
var keyPair = ECPair.fromPrivateKey(this._wallet.privateKey, {
|
|
@@ -4416,9 +4443,13 @@ var EmbeddedWallet = /*#__PURE__*/ function() {
|
|
|
4416
4443
|
* Sign a transaction payload.
|
|
4417
4444
|
* @param payload - The transaction payload to sign.
|
|
4418
4445
|
* @returns The signed transaction in hex format.
|
|
4446
|
+
* @throws {Error} If the wallet is read-only or private key is not available.
|
|
4419
4447
|
*/ key: "signTx",
|
|
4420
4448
|
value: function signTx(payload) {
|
|
4421
|
-
if (
|
|
4449
|
+
if (this._isReadOnly) {
|
|
4450
|
+
throw new Error("Cannot sign transactions with a read-only wallet.");
|
|
4451
|
+
}
|
|
4452
|
+
if (!this._wallet || !this._wallet.privateKey) {
|
|
4422
4453
|
throw new Error("Private key is not available for signing.");
|
|
4423
4454
|
}
|
|
4424
4455
|
var psbt = new bitcoin.Psbt({
|