emblem-vault-sdk 1.9.2 → 1.9.4
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/bundle.js +8 -8
- package/dist/derive.js +2 -1
- package/dist/index.js +6 -7
- package/docs/bundle.js +8 -8
- package/package.json +1 -1
- package/src/derive.ts +5 -3
- package/src/index.ts +5 -7
- package/types/index.d.ts +1 -1
package/dist/bundle.js
CHANGED
|
@@ -709352,9 +709352,9 @@ const bip39 = __importStar(require("bip39"));
|
|
|
709352
709352
|
// import bitcoin from "bitcoinjs-lib";
|
|
709353
709353
|
const ecc = __importStar(require("@bitcoin-js/tiny-secp256k1-asmjs"));
|
|
709354
709354
|
const bip32 = (0, bip32_1.BIP32Factory)(ecc);
|
|
709355
|
-
let mainnet = { "messagePrefix": "\u0018Bitcoin Signed Message:\n", "bech32": "bc", "bip32": { "public": 76067358, "private": 76066276 }, "pubKeyHash": 0, "scriptHash": 5, "wif": 128 };
|
|
709356
709355
|
const generateTaprootAddressFromMnemonic = (phrase) => __awaiter(void 0, void 0, void 0, function* () {
|
|
709357
709356
|
let bitcoin = window.bitcoin;
|
|
709357
|
+
let mainnet = bitcoin.networks.mainnet;
|
|
709358
709358
|
bitcoin.initEccLib(ecc);
|
|
709359
709359
|
const seed = bip39.mnemonicToSeedSync(phrase);
|
|
709360
709360
|
const rootKey = bip32.fromSeed(seed, mainnet);
|
|
@@ -709376,6 +709376,7 @@ exports.generateTaprootAddressFromMnemonic = generateTaprootAddressFromMnemonic;
|
|
|
709376
709376
|
const getPsbtTxnSize = (phrase, psbtBase64) => {
|
|
709377
709377
|
var _a, _b;
|
|
709378
709378
|
let bitcoin = window.bitcoin;
|
|
709379
|
+
let mainnet = bitcoin.networks.mainnet;
|
|
709379
709380
|
const parsedPsbt = bitcoin.Psbt.fromBase64(psbtBase64);
|
|
709380
709381
|
const psbt = new bitcoin.Psbt();
|
|
709381
709382
|
const seed = bip39.mnemonicToSeedSync(phrase);
|
|
@@ -709476,7 +709477,7 @@ const bignumber_1 = require("@ethersproject/bignumber");
|
|
|
709476
709477
|
const utils_1 = require("./utils");
|
|
709477
709478
|
const sats_connect_1 = require("sats-connect");
|
|
709478
709479
|
const derive_1 = require("./derive");
|
|
709479
|
-
const SDK_VERSION = '1.9.
|
|
709480
|
+
const SDK_VERSION = '1.9.3';
|
|
709480
709481
|
class EmblemVaultSDK {
|
|
709481
709482
|
constructor(apiKey, baseUrl) {
|
|
709482
709483
|
this.apiKey = apiKey;
|
|
@@ -709934,9 +709935,8 @@ class EmblemVaultSDK {
|
|
|
709934
709935
|
});
|
|
709935
709936
|
});
|
|
709936
709937
|
}
|
|
709937
|
-
generatePSBT(phrase) {
|
|
709938
|
+
generatePSBT(phrase, satsPerByte = 20) {
|
|
709938
709939
|
return __awaiter(this, void 0, void 0, function* () {
|
|
709939
|
-
const desiredFeeRate = 2; // sats per byte -> mainnet will be much higher
|
|
709940
709940
|
const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield this.getSatsConnectAddress();
|
|
709941
709941
|
// change this to mainnet
|
|
709942
709942
|
if (window.bitcoin) {
|
|
@@ -709993,18 +709993,18 @@ class EmblemVaultSDK {
|
|
|
709993
709993
|
});
|
|
709994
709994
|
totalFeeInput += utxo.value;
|
|
709995
709995
|
size = (0, derive_1.getPsbtTxnSize)(phrase, psbt.toBase64());
|
|
709996
|
-
if (totalFeeInput >=
|
|
709996
|
+
if (totalFeeInput >= satsPerByte * size) {
|
|
709997
709997
|
break;
|
|
709998
709998
|
}
|
|
709999
709999
|
}
|
|
710000
|
-
if (totalFeeInput <
|
|
710000
|
+
if (totalFeeInput < satsPerByte * size) {
|
|
710001
710001
|
throw new Error("Insufficient funds at desired fee rate");
|
|
710002
710002
|
}
|
|
710003
710003
|
// maybe add output for change if change is greater than 1000 sats (dust)
|
|
710004
|
-
if (
|
|
710004
|
+
if (satsPerByte * size > 1000) {
|
|
710005
710005
|
psbt.addOutput({
|
|
710006
710006
|
address: paymentAddress,
|
|
710007
|
-
value: totalFeeInput - Math.ceil(
|
|
710007
|
+
value: totalFeeInput - Math.ceil(satsPerByte * size),
|
|
710008
710008
|
});
|
|
710009
710009
|
}
|
|
710010
710010
|
// sign
|
package/dist/derive.js
CHANGED
|
@@ -38,9 +38,9 @@ const bip39 = __importStar(require("bip39"));
|
|
|
38
38
|
// import bitcoin from "bitcoinjs-lib";
|
|
39
39
|
const ecc = __importStar(require("@bitcoin-js/tiny-secp256k1-asmjs"));
|
|
40
40
|
const bip32 = (0, bip32_1.BIP32Factory)(ecc);
|
|
41
|
-
let mainnet = { "messagePrefix": "\u0018Bitcoin Signed Message:\n", "bech32": "bc", "bip32": { "public": 76067358, "private": 76066276 }, "pubKeyHash": 0, "scriptHash": 5, "wif": 128 };
|
|
42
41
|
const generateTaprootAddressFromMnemonic = (phrase) => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
42
|
let bitcoin = window.bitcoin;
|
|
43
|
+
let mainnet = bitcoin.networks.mainnet;
|
|
44
44
|
bitcoin.initEccLib(ecc);
|
|
45
45
|
const seed = bip39.mnemonicToSeedSync(phrase);
|
|
46
46
|
const rootKey = bip32.fromSeed(seed, mainnet);
|
|
@@ -62,6 +62,7 @@ exports.generateTaprootAddressFromMnemonic = generateTaprootAddressFromMnemonic;
|
|
|
62
62
|
const getPsbtTxnSize = (phrase, psbtBase64) => {
|
|
63
63
|
var _a, _b;
|
|
64
64
|
let bitcoin = window.bitcoin;
|
|
65
|
+
let mainnet = bitcoin.networks.mainnet;
|
|
65
66
|
const parsedPsbt = bitcoin.Psbt.fromBase64(psbtBase64);
|
|
66
67
|
const psbt = new bitcoin.Psbt();
|
|
67
68
|
const seed = bip39.mnemonicToSeedSync(phrase);
|
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ const bignumber_1 = require("@ethersproject/bignumber");
|
|
|
36
36
|
const utils_1 = require("./utils");
|
|
37
37
|
const sats_connect_1 = require("sats-connect");
|
|
38
38
|
const derive_1 = require("./derive");
|
|
39
|
-
const SDK_VERSION = '1.9.
|
|
39
|
+
const SDK_VERSION = '1.9.3';
|
|
40
40
|
class EmblemVaultSDK {
|
|
41
41
|
constructor(apiKey, baseUrl) {
|
|
42
42
|
this.apiKey = apiKey;
|
|
@@ -494,9 +494,8 @@ class EmblemVaultSDK {
|
|
|
494
494
|
});
|
|
495
495
|
});
|
|
496
496
|
}
|
|
497
|
-
generatePSBT(phrase) {
|
|
497
|
+
generatePSBT(phrase, satsPerByte = 20) {
|
|
498
498
|
return __awaiter(this, void 0, void 0, function* () {
|
|
499
|
-
const desiredFeeRate = 2; // sats per byte -> mainnet will be much higher
|
|
500
499
|
const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield this.getSatsConnectAddress();
|
|
501
500
|
// change this to mainnet
|
|
502
501
|
if (window.bitcoin) {
|
|
@@ -553,18 +552,18 @@ class EmblemVaultSDK {
|
|
|
553
552
|
});
|
|
554
553
|
totalFeeInput += utxo.value;
|
|
555
554
|
size = (0, derive_1.getPsbtTxnSize)(phrase, psbt.toBase64());
|
|
556
|
-
if (totalFeeInput >=
|
|
555
|
+
if (totalFeeInput >= satsPerByte * size) {
|
|
557
556
|
break;
|
|
558
557
|
}
|
|
559
558
|
}
|
|
560
|
-
if (totalFeeInput <
|
|
559
|
+
if (totalFeeInput < satsPerByte * size) {
|
|
561
560
|
throw new Error("Insufficient funds at desired fee rate");
|
|
562
561
|
}
|
|
563
562
|
// maybe add output for change if change is greater than 1000 sats (dust)
|
|
564
|
-
if (
|
|
563
|
+
if (satsPerByte * size > 1000) {
|
|
565
564
|
psbt.addOutput({
|
|
566
565
|
address: paymentAddress,
|
|
567
|
-
value: totalFeeInput - Math.ceil(
|
|
566
|
+
value: totalFeeInput - Math.ceil(satsPerByte * size),
|
|
568
567
|
});
|
|
569
568
|
}
|
|
570
569
|
// sign
|
package/docs/bundle.js
CHANGED
|
@@ -709352,9 +709352,9 @@ const bip39 = __importStar(require("bip39"));
|
|
|
709352
709352
|
// import bitcoin from "bitcoinjs-lib";
|
|
709353
709353
|
const ecc = __importStar(require("@bitcoin-js/tiny-secp256k1-asmjs"));
|
|
709354
709354
|
const bip32 = (0, bip32_1.BIP32Factory)(ecc);
|
|
709355
|
-
let mainnet = { "messagePrefix": "\u0018Bitcoin Signed Message:\n", "bech32": "bc", "bip32": { "public": 76067358, "private": 76066276 }, "pubKeyHash": 0, "scriptHash": 5, "wif": 128 };
|
|
709356
709355
|
const generateTaprootAddressFromMnemonic = (phrase) => __awaiter(void 0, void 0, void 0, function* () {
|
|
709357
709356
|
let bitcoin = window.bitcoin;
|
|
709357
|
+
let mainnet = bitcoin.networks.mainnet;
|
|
709358
709358
|
bitcoin.initEccLib(ecc);
|
|
709359
709359
|
const seed = bip39.mnemonicToSeedSync(phrase);
|
|
709360
709360
|
const rootKey = bip32.fromSeed(seed, mainnet);
|
|
@@ -709376,6 +709376,7 @@ exports.generateTaprootAddressFromMnemonic = generateTaprootAddressFromMnemonic;
|
|
|
709376
709376
|
const getPsbtTxnSize = (phrase, psbtBase64) => {
|
|
709377
709377
|
var _a, _b;
|
|
709378
709378
|
let bitcoin = window.bitcoin;
|
|
709379
|
+
let mainnet = bitcoin.networks.mainnet;
|
|
709379
709380
|
const parsedPsbt = bitcoin.Psbt.fromBase64(psbtBase64);
|
|
709380
709381
|
const psbt = new bitcoin.Psbt();
|
|
709381
709382
|
const seed = bip39.mnemonicToSeedSync(phrase);
|
|
@@ -709476,7 +709477,7 @@ const bignumber_1 = require("@ethersproject/bignumber");
|
|
|
709476
709477
|
const utils_1 = require("./utils");
|
|
709477
709478
|
const sats_connect_1 = require("sats-connect");
|
|
709478
709479
|
const derive_1 = require("./derive");
|
|
709479
|
-
const SDK_VERSION = '1.9.
|
|
709480
|
+
const SDK_VERSION = '1.9.3';
|
|
709480
709481
|
class EmblemVaultSDK {
|
|
709481
709482
|
constructor(apiKey, baseUrl) {
|
|
709482
709483
|
this.apiKey = apiKey;
|
|
@@ -709934,9 +709935,8 @@ class EmblemVaultSDK {
|
|
|
709934
709935
|
});
|
|
709935
709936
|
});
|
|
709936
709937
|
}
|
|
709937
|
-
generatePSBT(phrase) {
|
|
709938
|
+
generatePSBT(phrase, satsPerByte = 20) {
|
|
709938
709939
|
return __awaiter(this, void 0, void 0, function* () {
|
|
709939
|
-
const desiredFeeRate = 2; // sats per byte -> mainnet will be much higher
|
|
709940
709940
|
const { paymentAddress, paymentPublicKey, ordinalsAddress } = yield this.getSatsConnectAddress();
|
|
709941
709941
|
// change this to mainnet
|
|
709942
709942
|
if (window.bitcoin) {
|
|
@@ -709993,18 +709993,18 @@ class EmblemVaultSDK {
|
|
|
709993
709993
|
});
|
|
709994
709994
|
totalFeeInput += utxo.value;
|
|
709995
709995
|
size = (0, derive_1.getPsbtTxnSize)(phrase, psbt.toBase64());
|
|
709996
|
-
if (totalFeeInput >=
|
|
709996
|
+
if (totalFeeInput >= satsPerByte * size) {
|
|
709997
709997
|
break;
|
|
709998
709998
|
}
|
|
709999
709999
|
}
|
|
710000
|
-
if (totalFeeInput <
|
|
710000
|
+
if (totalFeeInput < satsPerByte * size) {
|
|
710001
710001
|
throw new Error("Insufficient funds at desired fee rate");
|
|
710002
710002
|
}
|
|
710003
710003
|
// maybe add output for change if change is greater than 1000 sats (dust)
|
|
710004
|
-
if (
|
|
710004
|
+
if (satsPerByte * size > 1000) {
|
|
710005
710005
|
psbt.addOutput({
|
|
710006
710006
|
address: paymentAddress,
|
|
710007
|
-
value: totalFeeInput - Math.ceil(
|
|
710007
|
+
value: totalFeeInput - Math.ceil(satsPerByte * size),
|
|
710008
710008
|
});
|
|
710009
710009
|
}
|
|
710010
710010
|
// sign
|
package/package.json
CHANGED
package/src/derive.ts
CHANGED
|
@@ -6,14 +6,15 @@ import * as ecc from '@bitcoin-js/tiny-secp256k1-asmjs'
|
|
|
6
6
|
|
|
7
7
|
const bip32 = BIP32Factory(ecc);
|
|
8
8
|
|
|
9
|
-
let mainnet: any = {"messagePrefix":"\u0018Bitcoin Signed Message:\n","bech32":"bc","bip32":{"public":76067358,"private":76066276},"pubKeyHash":0,"scriptHash":5,"wif":128}
|
|
9
|
+
// let mainnet: any = {"messagePrefix":"\u0018Bitcoin Signed Message:\n","bech32":"bc","bip32":{"public":76067358,"private":76066276},"pubKeyHash":0,"scriptHash":5,"wif":128}
|
|
10
10
|
declare global {
|
|
11
11
|
interface Window {
|
|
12
12
|
bitcoin: any;
|
|
13
13
|
}
|
|
14
14
|
}
|
|
15
15
|
export const generateTaprootAddressFromMnemonic = async (phrase: string) => {
|
|
16
|
-
let bitcoin = window.bitcoin;
|
|
16
|
+
let bitcoin = window.bitcoin;
|
|
17
|
+
let mainnet = bitcoin.networks.mainnet;
|
|
17
18
|
bitcoin.initEccLib(ecc);
|
|
18
19
|
const seed = bip39.mnemonicToSeedSync(phrase);
|
|
19
20
|
|
|
@@ -39,7 +40,8 @@ export const generateTaprootAddressFromMnemonic = async (phrase: string) => {
|
|
|
39
40
|
// we sign it with a dummy key and then extract the transaction
|
|
40
41
|
// it should be very close to 100% accurate
|
|
41
42
|
export const getPsbtTxnSize = (phrase: string, psbtBase64: string) => {
|
|
42
|
-
let bitcoin = window.bitcoin;
|
|
43
|
+
let bitcoin = window.bitcoin;
|
|
44
|
+
let mainnet = bitcoin.networks.mainnet;
|
|
43
45
|
const parsedPsbt = bitcoin.Psbt.fromBase64(psbtBase64);
|
|
44
46
|
|
|
45
47
|
const psbt = new bitcoin.Psbt();
|
package/src/index.ts
CHANGED
|
@@ -404,9 +404,7 @@ class EmblemVaultSDK {
|
|
|
404
404
|
});
|
|
405
405
|
}
|
|
406
406
|
|
|
407
|
-
async generatePSBT(phrase: string) {
|
|
408
|
-
|
|
409
|
-
const desiredFeeRate = 2; // sats per byte -> mainnet will be much higher
|
|
407
|
+
async generatePSBT(phrase: string, satsPerByte: number = 20) {
|
|
410
408
|
|
|
411
409
|
const { paymentAddress, paymentPublicKey, ordinalsAddress } = await this.getSatsConnectAddress();
|
|
412
410
|
|
|
@@ -481,20 +479,20 @@ class EmblemVaultSDK {
|
|
|
481
479
|
|
|
482
480
|
size = getPsbtTxnSize(phrase, psbt.toBase64());
|
|
483
481
|
|
|
484
|
-
if (totalFeeInput >=
|
|
482
|
+
if (totalFeeInput >= satsPerByte * size) {
|
|
485
483
|
break;
|
|
486
484
|
}
|
|
487
485
|
}
|
|
488
486
|
|
|
489
|
-
if (totalFeeInput <
|
|
487
|
+
if (totalFeeInput < satsPerByte * size) {
|
|
490
488
|
throw new Error("Insufficient funds at desired fee rate");
|
|
491
489
|
}
|
|
492
490
|
|
|
493
491
|
// maybe add output for change if change is greater than 1000 sats (dust)
|
|
494
|
-
if (
|
|
492
|
+
if (satsPerByte * size > 1000) {
|
|
495
493
|
psbt.addOutput({
|
|
496
494
|
address: paymentAddress,
|
|
497
|
-
value: totalFeeInput - Math.ceil(
|
|
495
|
+
value: totalFeeInput - Math.ceil(satsPerByte * size),
|
|
498
496
|
});
|
|
499
497
|
}
|
|
500
498
|
|
package/types/index.d.ts
CHANGED
|
@@ -46,7 +46,7 @@ declare class EmblemVaultSDK {
|
|
|
46
46
|
legacyBalanceFromContractByAddress(web3: any, address: string): Promise<number[]>;
|
|
47
47
|
refreshLegacyOwnership(web3: any, address: string): Promise<void>;
|
|
48
48
|
getSatsConnectAddress(): Promise<SatsConnectAddress>;
|
|
49
|
-
generatePSBT(phrase: string): Promise<void>;
|
|
49
|
+
generatePSBT(phrase: string, satsPerByte?: number): Promise<void>;
|
|
50
50
|
getTaprootAddressFromMnemonic(phrase: string): Promise<{
|
|
51
51
|
p2tr: any;
|
|
52
52
|
tweakedSigner: import("bip32/types/bip32").Signer;
|