@teleportdao/bitcoin 1.4.3 → 1.4.6
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/bitcoin-base.d.ts +66 -53
- package/dist/bitcoin-base.d.ts.map +1 -1
- package/dist/bitcoin-base.js +47 -38
- package/dist/bitcoin-base.js.map +1 -1
- package/dist/bitcoin-interface-utils.d.ts +12 -10
- package/dist/bitcoin-interface-utils.d.ts.map +1 -1
- package/dist/bitcoin-interface-utils.js +16 -10
- package/dist/bitcoin-interface-utils.js.map +1 -1
- package/dist/bitcoin-interface.d.ts +206 -50
- package/dist/bitcoin-interface.d.ts.map +1 -1
- package/dist/bitcoin-interface.js +42 -27
- package/dist/bitcoin-interface.js.map +1 -1
- package/dist/bitcoin-utils.d.ts +111 -41
- package/dist/bitcoin-utils.d.ts.map +1 -1
- package/dist/bitcoin-utils.js +215 -156
- package/dist/bitcoin-utils.js.map +1 -1
- package/dist/bundle.js +13 -0
- package/dist/index.d.ts +5 -6
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +32 -12
- package/dist/index.js.map +1 -1
- package/dist/sign/sign-transaction.d.ts +9 -5
- package/dist/sign/sign-transaction.d.ts.map +1 -1
- package/dist/sign/sign-transaction.js +14 -11
- package/dist/sign/sign-transaction.js.map +1 -1
- package/dist/teleport-dao-payments.d.ts +68 -89
- package/dist/teleport-dao-payments.d.ts.map +1 -1
- package/dist/teleport-dao-payments.js +16 -4
- package/dist/teleport-dao-payments.js.map +1 -1
- package/dist/transaction-builder/bitcoin-transaction-builder.d.ts +30 -11
- package/dist/transaction-builder/bitcoin-transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder/bitcoin-transaction-builder.js +37 -9
- package/dist/transaction-builder/bitcoin-transaction-builder.js.map +1 -1
- package/dist/transaction-builder/transaction-builder.d.ts +198 -9
- package/dist/transaction-builder/transaction-builder.d.ts.map +1 -1
- package/dist/transaction-builder/transaction-builder.js +291 -38
- package/dist/transaction-builder/transaction-builder.js.map +1 -1
- package/dist/utils/networks.d.ts +5 -35
- package/dist/utils/networks.d.ts.map +1 -1
- package/dist/utils/networks.js +26 -2
- package/dist/utils/networks.js.map +1 -1
- package/dist/utils/tools.d.ts +15 -9
- package/dist/utils/tools.d.ts.map +1 -1
- package/dist/utils/tools.js +14 -11
- package/dist/utils/tools.js.map +1 -1
- package/package.json +8 -6
- package/src/{bitcoin-base.js → bitcoin-base.ts} +248 -219
- package/src/{bitcoin-interface-utils.js → bitcoin-interface-utils.ts} +59 -53
- package/src/{bitcoin-interface.js → bitcoin-interface.ts} +420 -350
- package/src/{bitcoin-utils.js → bitcoin-utils.ts} +608 -483
- package/src/helper/teleport-request-helper.js +179 -179
- package/src/index.ts +5 -0
- package/src/sign/sign-transaction.ts +96 -0
- package/src/{teleport-dao-payments.js → teleport-dao-payments.ts} +341 -280
- package/src/transaction-builder/bitcoin-transaction-builder.ts +61 -0
- package/src/transaction-builder/transaction-builder.ts +567 -0
- package/src/utils/{networks.js → networks.ts} +33 -31
- package/src/utils/{tools.js → tools.ts} +80 -72
- package/tsconfig.json +10 -9
- package/webpack.config.js +16 -0
- package/dist/transaction-builder/transaction-builder-common.d.ts +0 -57
- package/dist/transaction-builder/transaction-builder-common.d.ts.map +0 -1
- package/dist/transaction-builder/transaction-builder-common.js +0 -183
- package/dist/transaction-builder/transaction-builder-common.js.map +0 -1
- package/src/index.js +0 -15
- package/src/sign/sign-transaction.js +0 -36
- package/src/transaction-builder/bitcoin-transaction-builder.js +0 -37
- package/src/transaction-builder/transaction-builder-common.js +0 -236
- package/src/transaction-builder/transaction-builder.js +0 -159
package/dist/bitcoin-base.d.ts
CHANGED
|
@@ -1,62 +1,75 @@
|
|
|
1
|
-
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import TransactionBuilder, { BitcoinConnectionInfo } from "./transaction-builder/bitcoin-transaction-builder";
|
|
3
|
+
import type { ExtendedUtxo, SignerInfo, Target } from "./transaction-builder/transaction-builder";
|
|
4
|
+
import BitcoinSign from "./sign/sign-transaction";
|
|
5
|
+
import { Network, Payment } from "bitcoinjs-lib";
|
|
6
|
+
import { BitcoinInterface } from "./bitcoin-interface";
|
|
2
7
|
declare class BitcoinBase {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
network: Network;
|
|
9
|
+
hdWalletPath: {
|
|
10
|
+
p2pkh: string;
|
|
11
|
+
p2wpkh: string;
|
|
12
|
+
"p2sh-p2wpkh": string;
|
|
13
|
+
p2sh: string;
|
|
14
|
+
p2wsh: string;
|
|
15
|
+
"p2sh-p2wsh": string;
|
|
16
|
+
};
|
|
17
|
+
transactionBuilder: TransactionBuilder;
|
|
18
|
+
btcInterface: BitcoinInterface;
|
|
19
|
+
signer: BitcoinSign;
|
|
20
|
+
currentAccount?: string;
|
|
21
|
+
currentAccountType?: string;
|
|
22
|
+
privateKey?: Buffer;
|
|
23
|
+
publicKey?: Buffer;
|
|
24
|
+
publicKeys?: Buffer[];
|
|
25
|
+
addressObj?: Payment;
|
|
26
|
+
bitcoinAddress: string | undefined;
|
|
27
|
+
constructor(networkName: string, connectionInfo?: BitcoinConnectionInfo);
|
|
28
|
+
static createTransactionInputsAndOutputs({ targets, extendedUtxo, changeAddress, feeRate, }: {
|
|
29
|
+
targets: Target[];
|
|
30
|
+
extendedUtxo: ExtendedUtxo[];
|
|
31
|
+
changeAddress: string;
|
|
32
|
+
feeRate: number;
|
|
33
|
+
fullAmount?: boolean;
|
|
9
34
|
}): {
|
|
10
|
-
inputs:
|
|
11
|
-
fee:
|
|
12
|
-
outputs:
|
|
13
|
-
change:
|
|
14
|
-
address: any;
|
|
15
|
-
value: any;
|
|
16
|
-
} | undefined;
|
|
35
|
+
inputs: ExtendedUtxo[];
|
|
36
|
+
fee: number;
|
|
37
|
+
outputs: Target[];
|
|
38
|
+
change: import("./transaction-builder/transaction-builder").ChangeTarget | undefined;
|
|
17
39
|
};
|
|
18
40
|
static checkBalanceIsSufficient({ targets, extendedUtxo, changeAddress, feeRate, fullAmount, }: {
|
|
19
|
-
targets:
|
|
20
|
-
extendedUtxo:
|
|
21
|
-
changeAddress:
|
|
22
|
-
feeRate:
|
|
23
|
-
fullAmount?: boolean
|
|
41
|
+
targets: Target[];
|
|
42
|
+
extendedUtxo: ExtendedUtxo[];
|
|
43
|
+
changeAddress: string;
|
|
44
|
+
feeRate: number;
|
|
45
|
+
fullAmount?: boolean;
|
|
24
46
|
}): boolean;
|
|
25
|
-
constructor(networkName: any, connectionInfo?: {
|
|
26
|
-
api: {
|
|
27
|
-
enabled: boolean;
|
|
28
|
-
provider: string;
|
|
29
|
-
};
|
|
30
|
-
});
|
|
31
|
-
network: any;
|
|
32
|
-
hdWalletPath: any;
|
|
33
|
-
transactionBuilder: TransactionBuilder;
|
|
34
|
-
btcInterface: import("./bitcoin-interface");
|
|
35
|
-
signer: BitcoinSign;
|
|
36
|
-
currentAccount: string | null | undefined;
|
|
37
|
-
currentAccountType: string | null;
|
|
38
|
-
privateKey: Buffer | null;
|
|
39
|
-
publicKey: Buffer | null;
|
|
40
|
-
publicKeys: any[];
|
|
41
47
|
setMultiSigAccount(accountType?: string): void;
|
|
42
|
-
setAccountPrivateKey(privateKeyHex:
|
|
43
|
-
setAccountPublicKey(publicKeyHex:
|
|
44
|
-
setAccountPrivateKeyByMnemonic({ mnemonic, mnemonicPassword, index, walletNumber, addressType, }:
|
|
48
|
+
setAccountPrivateKey(privateKeyHex: string): void;
|
|
49
|
+
setAccountPublicKey(publicKeyHex: string): void;
|
|
50
|
+
setAccountPrivateKeyByMnemonic({ mnemonic, mnemonicPassword, index, walletNumber, addressType, }: {
|
|
51
|
+
mnemonic: string;
|
|
52
|
+
mnemonicPassword?: string;
|
|
53
|
+
index?: number;
|
|
54
|
+
walletNumber?: number;
|
|
55
|
+
addressType?: string;
|
|
56
|
+
}): string | undefined;
|
|
45
57
|
setAccount(accountType?: string): string | undefined;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
58
|
+
getExtendedUtxo(input: SignerInfo): Promise<{
|
|
59
|
+
signerInfo: SignerInfo;
|
|
60
|
+
hash: string;
|
|
61
|
+
value: number;
|
|
62
|
+
index: number;
|
|
63
|
+
}[]>;
|
|
64
|
+
send({ receiverAddress, amount, fullAmount, speed, }: {
|
|
65
|
+
receiverAddress: string;
|
|
66
|
+
amount: number;
|
|
67
|
+
fullAmount?: boolean;
|
|
68
|
+
speed?: "normal" | "fast" | "slow";
|
|
69
|
+
}): Promise<string>;
|
|
70
|
+
sendSignedPsbt(signedPsbt: string): Promise<string>;
|
|
71
|
+
sendSignedTx(signedTx: string): Promise<string>;
|
|
72
|
+
sendMultiSignedPsbt(signedPsbts?: string[]): Promise<string>;
|
|
59
73
|
}
|
|
60
|
-
|
|
61
|
-
import BitcoinSign = require("./sign/sign-transaction");
|
|
74
|
+
export { BitcoinBase };
|
|
62
75
|
//# sourceMappingURL=bitcoin-base.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin-base.d.ts","sourceRoot":"","sources":["../src/bitcoin-base.
|
|
1
|
+
{"version":3,"file":"bitcoin-base.d.ts","sourceRoot":"","sources":["../src/bitcoin-base.ts"],"names":[],"mappings":";AAAA,OAAO,kBAAkB,EAAE,EACzB,qBAAqB,EACtB,MAAM,mDAAmD,CAAA;AAE1D,OAAO,KAAK,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,EAAE,MAAM,2CAA2C,CAAA;AACjG,OAAO,WAAW,MAAM,yBAAyB,CAAA;AAOjD,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAChD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAA;AAEtD,cAAM,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,SAAS;IAmBvC,oBAAoB,CAAC,aAAa,EAAE,MAAM;IAM1C,mBAAmB,CAAC,YAAY,EAAE,MAAM;IAIxC,8BAA8B,CAAC,EAC7B,QAAQ,EACR,gBAAqB,EACrB,KAAS,EACT,YAAgB,EAChB,WAA2B,GAC5B,EAAE;QACD,QAAQ,EAAE,MAAM,CAAA;QAChB,gBAAgB,CAAC,EAAE,MAAM,CAAA;QACzB,KAAK,CAAC,EAAE,MAAM,CAAA;QACd,YAAY,CAAC,EAAE,MAAM,CAAA;QACrB,WAAW,CAAC,EAAE,MAAM,CAAA;KACrB;IAgBD,UAAU,CAAC,WAAW,SAAU;IAe1B,eAAe,CAAC,KAAK,EAAE,UAAU;;;;;;IAIjC,IAAI,CAAC,EACT,eAAe,EACf,MAAM,EACN,UAAkB,EAClB,KAAgB,GACjB,EAAE;QACD,eAAe,EAAE,MAAM,CAAA;QACvB,MAAM,EAAE,MAAM,CAAA;QACd,UAAU,CAAC,EAAE,OAAO,CAAA;QACpB,KAAK,CAAC,EAAE,QAAQ,GAAG,MAAM,GAAG,MAAM,CAAA;KACnC;IA+BK,cAAc,CAAC,UAAU,EAAE,MAAM;IAMjC,YAAY,CAAC,QAAQ,EAAE,MAAM;IAK7B,mBAAmB,CAAC,WAAW,GAAE,MAAM,EAAO;CAKrD;AAED,OAAO,EAAE,WAAW,EAAE,CAAA"}
|
package/dist/bitcoin-base.js
CHANGED
|
@@ -8,13 +8,18 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
9
|
});
|
|
10
10
|
};
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
const
|
|
17
|
-
const
|
|
11
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
12
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
13
|
+
};
|
|
14
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
15
|
+
exports.BitcoinBase = void 0;
|
|
16
|
+
const bitcoin_transaction_builder_1 = __importDefault(require("./transaction-builder/bitcoin-transaction-builder"));
|
|
17
|
+
const sign_transaction_1 = __importDefault(require("./sign/sign-transaction"));
|
|
18
|
+
const bip39_1 = __importDefault(require("bip39"));
|
|
19
|
+
const bip32_1 = __importDefault(require("bip32"));
|
|
20
|
+
const configs_1 = require("@teleportdao/configs");
|
|
21
|
+
const bitcoin_utils_1 = require("./bitcoin-utils");
|
|
22
|
+
const networks_1 = __importDefault(require("./utils/networks"));
|
|
18
23
|
class BitcoinBase {
|
|
19
24
|
constructor(networkName, connectionInfo = {
|
|
20
25
|
api: {
|
|
@@ -22,34 +27,36 @@ class BitcoinBase {
|
|
|
22
27
|
provider: "BlockStream",
|
|
23
28
|
},
|
|
24
29
|
}) {
|
|
25
|
-
this.network =
|
|
26
|
-
this.hdWalletPath =
|
|
27
|
-
this.transactionBuilder = new
|
|
30
|
+
this.network = networks_1.default[networkName];
|
|
31
|
+
this.hdWalletPath = configs_1.hdWalletPath.bitcoin;
|
|
32
|
+
this.transactionBuilder = new bitcoin_transaction_builder_1.default(connectionInfo, networkName, this.network);
|
|
28
33
|
this.btcInterface = this.transactionBuilder.btcInterface;
|
|
29
|
-
this.signer = new
|
|
30
|
-
this.currentAccount =
|
|
31
|
-
this.currentAccountType =
|
|
32
|
-
this.privateKey =
|
|
33
|
-
this.publicKey =
|
|
34
|
+
this.signer = new sign_transaction_1.default(this.network);
|
|
35
|
+
this.currentAccount = undefined;
|
|
36
|
+
this.currentAccountType = undefined;
|
|
37
|
+
this.privateKey = undefined;
|
|
38
|
+
this.publicKey = undefined;
|
|
34
39
|
this.publicKeys = [];
|
|
35
40
|
}
|
|
36
|
-
static createTransactionInputsAndOutputs({ targets, extendedUtxo, changeAddress, feeRate,
|
|
37
|
-
return
|
|
41
|
+
static createTransactionInputsAndOutputs({ targets, extendedUtxo, changeAddress, feeRate, }) {
|
|
42
|
+
return bitcoin_transaction_builder_1.default.helperHandleInputsAndOutputs({
|
|
38
43
|
targets,
|
|
39
44
|
extendedUtxo,
|
|
40
|
-
|
|
45
|
+
changeObject: {
|
|
46
|
+
address: changeAddress,
|
|
47
|
+
},
|
|
41
48
|
feeRate,
|
|
42
|
-
fullAmount,
|
|
43
49
|
});
|
|
44
50
|
}
|
|
45
51
|
static checkBalanceIsSufficient({ targets, extendedUtxo, changeAddress, feeRate, fullAmount = false, }) {
|
|
46
52
|
try {
|
|
47
|
-
|
|
53
|
+
bitcoin_transaction_builder_1.default.helperHandleInputsAndOutputs({
|
|
48
54
|
targets,
|
|
49
55
|
extendedUtxo,
|
|
50
|
-
|
|
56
|
+
changeObject: {
|
|
57
|
+
address: changeAddress,
|
|
58
|
+
},
|
|
51
59
|
feeRate,
|
|
52
|
-
fullAmount,
|
|
53
60
|
});
|
|
54
61
|
return true;
|
|
55
62
|
}
|
|
@@ -66,26 +73,31 @@ class BitcoinBase {
|
|
|
66
73
|
}
|
|
67
74
|
setAccountPrivateKey(privateKeyHex) {
|
|
68
75
|
this.privateKey = Buffer.from(privateKeyHex, "hex");
|
|
69
|
-
let publicKey = getPubKeyFromPrivateKeyHex(privateKeyHex, this.network);
|
|
76
|
+
let publicKey = (0, bitcoin_utils_1.getPubKeyFromPrivateKeyHex)(privateKeyHex, this.network);
|
|
70
77
|
this.publicKey = publicKey;
|
|
71
78
|
}
|
|
72
79
|
setAccountPublicKey(publicKeyHex) {
|
|
73
80
|
this.publicKey = Buffer.from(publicKeyHex, "hex");
|
|
74
81
|
}
|
|
75
82
|
setAccountPrivateKeyByMnemonic({ mnemonic, mnemonicPassword = "", index = 0, walletNumber = 0, addressType = "p2sh-p2wpkh", }) {
|
|
76
|
-
if (!
|
|
83
|
+
if (!bip39_1.default.validateMnemonic(mnemonic))
|
|
77
84
|
throw new Error("invalid mnemonic");
|
|
78
|
-
const seed =
|
|
79
|
-
const node =
|
|
80
|
-
|
|
85
|
+
const seed = bip39_1.default.mnemonicToSeedSync(mnemonic, mnemonicPassword);
|
|
86
|
+
const node = bip32_1.default.fromSeed(seed);
|
|
87
|
+
let basePath = this.hdWalletPath[addressType];
|
|
88
|
+
if (!basePath) {
|
|
81
89
|
throw new Error("incorrect path or addressType");
|
|
82
|
-
|
|
90
|
+
}
|
|
91
|
+
const path = `${basePath}/${walletNumber}`;
|
|
83
92
|
const account = node.derivePath(path);
|
|
84
93
|
const userKeyPair = account.derive(index);
|
|
85
94
|
this.setAccountPrivateKey(userKeyPair.privateKey.toString("hex"));
|
|
86
95
|
return this.setAccount(addressType);
|
|
87
96
|
}
|
|
88
97
|
setAccount(accountType = "p2pkh") {
|
|
98
|
+
if (!this.publicKey) {
|
|
99
|
+
throw new Error("account not initialized");
|
|
100
|
+
}
|
|
89
101
|
let addressObj = this.transactionBuilder.createAddressObject({
|
|
90
102
|
addressType: accountType,
|
|
91
103
|
publicKey: this.publicKey,
|
|
@@ -96,19 +108,16 @@ class BitcoinBase {
|
|
|
96
108
|
this.bitcoinAddress = addressObj.address;
|
|
97
109
|
return addressObj.address;
|
|
98
110
|
}
|
|
99
|
-
getExtendedUtxo(
|
|
111
|
+
getExtendedUtxo(input) {
|
|
100
112
|
return __awaiter(this, void 0, void 0, function* () {
|
|
101
|
-
return this.transactionBuilder.getExtendedUtxo(
|
|
102
|
-
address,
|
|
103
|
-
addressType,
|
|
104
|
-
publicKey,
|
|
105
|
-
derivationPath,
|
|
106
|
-
masterFingerprint,
|
|
107
|
-
});
|
|
113
|
+
return this.transactionBuilder.getExtendedUtxo(input);
|
|
108
114
|
});
|
|
109
115
|
}
|
|
110
|
-
send({ receiverAddress, amount, fullAmount = false, speed = "normal" }) {
|
|
116
|
+
send({ receiverAddress, amount, fullAmount = false, speed = "normal", }) {
|
|
111
117
|
return __awaiter(this, void 0, void 0, function* () {
|
|
118
|
+
if (!this.currentAccount || !this.currentAccountType || !this.publicKey || !this.privateKey) {
|
|
119
|
+
throw new Error("account not initialized");
|
|
120
|
+
}
|
|
112
121
|
let extendedUtxo = yield this.getExtendedUtxo({
|
|
113
122
|
address: this.currentAccount,
|
|
114
123
|
addressType: this.currentAccountType,
|
|
@@ -156,5 +165,5 @@ class BitcoinBase {
|
|
|
156
165
|
});
|
|
157
166
|
}
|
|
158
167
|
}
|
|
159
|
-
|
|
168
|
+
exports.BitcoinBase = BitcoinBase;
|
|
160
169
|
//# sourceMappingURL=bitcoin-base.js.map
|
package/dist/bitcoin-base.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin-base.js","sourceRoot":"","sources":["../src/bitcoin-base.
|
|
1
|
+
{"version":3,"file":"bitcoin-base.js","sourceRoot":"","sources":["../src/bitcoin-base.ts"],"names":[],"mappings":";;;;;;;;;;;;;;;AAAA,oHAE0D;AAG1D,+EAAiD;AAEjD,kDAAyB;AACzB,kDAAyB;AACzB,kDAAmD;AACnD,mDAA4D;AAC5D,gEAAuC;AAIvC,MAAM,WAAW;IAoBf,YACE,WAAmB,EACnB,iBAAwC;QACtC,GAAG,EAAE;YACH,OAAO,EAAE,IAAI;YACb,QAAQ,EAAE,aAAa;SACxB;KACF;QAED,IAAI,CAAC,OAAO,GAAG,kBAAQ,CAAC,WAAW,CAAC,CAAA;QACpC,IAAI,CAAC,YAAY,GAAG,sBAAY,CAAC,OAAO,CAAA;QAExC,IAAI,CAAC,kBAAkB,GAAG,IAAI,qCAAkB,CAAC,cAAc,EAAE,WAAW,EAAE,IAAI,CAAC,OAAO,CAAC,CAAA;QAC3F,IAAI,CAAC,YAAY,GAAG,IAAI,CAAC,kBAAkB,CAAC,YAAY,CAAA;QAExD,IAAI,CAAC,MAAM,GAAG,IAAI,0BAAW,CAAC,IAAI,CAAC,OAAO,CAAC,CAAA;QAE3C,IAAI,CAAC,cAAc,GAAG,SAAS,CAAA;QAC/B,IAAI,CAAC,kBAAkB,GAAG,SAAS,CAAA;QAEnC,IAAI,CAAC,UAAU,GAAG,SAAS,CAAA;QAC3B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oinjs-lib";
|
|
3
|
+
export declare class BitcoinInterfaceUtils {
|
|
4
|
+
testnet: boolean;
|
|
5
|
+
network: Network;
|
|
6
|
+
constructor(networkName: string);
|
|
7
|
+
convertHashToAddress(hashHex: string, addressType: string): string;
|
|
8
|
+
convertScriptToAddress(scriptHex: string, addressType: string): string;
|
|
9
|
+
convertAddressToScript(address: string): {
|
|
9
10
|
script: Buffer | undefined;
|
|
10
11
|
hash: Buffer | undefined;
|
|
11
12
|
addressType: "p2wpkh" | "p2sh" | "p2pkh";
|
|
12
13
|
};
|
|
13
|
-
convertAddressToObject(address:
|
|
14
|
+
convertAddressToObject(address: string): {
|
|
14
15
|
addressObject: import("bitcoinjs-lib").Payment;
|
|
15
16
|
addressType: "p2wpkh" | "p2sh" | "p2pkh";
|
|
16
17
|
};
|
|
17
|
-
createAddressObjectByPublicKey(
|
|
18
|
+
createAddressObjectByPublicKey(publicKey: string, addressType: string): import("bitcoinjs-lib").Payment;
|
|
18
19
|
}
|
|
20
|
+
export default BitcoinInterfaceUtils;
|
|
19
21
|
//# sourceMappingURL=bitcoin-interface-utils.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin-interface-utils.d.ts","sourceRoot":"","sources":["../src/bitcoin-interface-utils.
|
|
1
|
+
{"version":3,"file":"bitcoin-interface-utils.d.ts","sourceRoot":"","sources":["../src/bitcoin-interface-utils.ts"],"names":[],"mappings":";AAOA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,eAAe,CAAA;AAE5C,qBAAa,qBAAqB;IAChC,OAAO,EAAE,OAAO,CAAA;IAChB,OAAO,EAAE,OAAO,CAAA;gBACJ,WAAW,EAAE,MAAM;IAK/B,oBAAoB,CAAC,OAAO,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IASzD,sBAAsB,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;IAS7D,sBAAsB,CAAC,OAAO,EAAE,MAAM;;;;;IAStC,sBAAsB,CAAC,OAAO,EAAE,MAAM;;;;IAKtC,8BAA8B,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM;CAOtE;AAED,eAAe,qBAAqB,CAAA"}
|
|
@@ -1,25 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
+
};
|
|
5
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
+
exports.BitcoinInterfaceUtils = void 0;
|
|
7
|
+
const networks_1 = __importDefault(require("./utils/networks"));
|
|
8
|
+
const bitcoin_utils_1 = require("./bitcoin-utils");
|
|
4
9
|
class BitcoinInterfaceUtils {
|
|
5
10
|
constructor(networkName) {
|
|
6
11
|
this.testnet = networkName.includes("_testnet");
|
|
7
|
-
this.network =
|
|
12
|
+
this.network = networks_1.default[networkName];
|
|
8
13
|
}
|
|
9
14
|
convertHashToAddress(hashHex, addressType) {
|
|
10
|
-
let addressObj = createAddressObjectByHash({ addressType, hash: Buffer.from(hashHex, "hex") }, this.network);
|
|
15
|
+
let addressObj = (0, bitcoin_utils_1.createAddressObjectByHash)({ addressType, hash: Buffer.from(hashHex, "hex") }, this.network);
|
|
11
16
|
if (!addressObj.address)
|
|
12
17
|
throw new Error("incorrect input");
|
|
13
18
|
return addressObj.address;
|
|
14
19
|
}
|
|
15
20
|
convertScriptToAddress(scriptHex, addressType) {
|
|
16
|
-
let addressObj = createAddressObjectByScript({ addressType, script: Buffer.from(scriptHex, "hex") }, this.network);
|
|
21
|
+
let addressObj = (0, bitcoin_utils_1.createAddressObjectByScript)({ addressType, script: Buffer.from(scriptHex, "hex") }, this.network);
|
|
17
22
|
if (!addressObj.address)
|
|
18
23
|
throw new Error("incorrect input");
|
|
19
24
|
return addressObj.address;
|
|
20
25
|
}
|
|
21
26
|
convertAddressToScript(address) {
|
|
22
|
-
let { addressObject, addressType } = createAddressObjectByAddress(address, this.network);
|
|
27
|
+
let { addressObject, addressType } = (0, bitcoin_utils_1.createAddressObjectByAddress)(address, this.network);
|
|
23
28
|
return {
|
|
24
29
|
script: addressObject.output,
|
|
25
30
|
hash: addressObject.hash,
|
|
@@ -27,13 +32,14 @@ class BitcoinInterfaceUtils {
|
|
|
27
32
|
};
|
|
28
33
|
}
|
|
29
34
|
convertAddressToObject(address) {
|
|
30
|
-
let addObj = createAddressObjectByAddress(address, this.network);
|
|
35
|
+
let addObj = (0, bitcoin_utils_1.createAddressObjectByAddress)(address, this.network);
|
|
31
36
|
return addObj;
|
|
32
37
|
}
|
|
33
|
-
createAddressObjectByPublicKey(
|
|
34
|
-
let addObj = createAddressObjectByPublicKey({
|
|
38
|
+
createAddressObjectByPublicKey(publicKey, addressType) {
|
|
39
|
+
let addObj = (0, bitcoin_utils_1.createAddressObjectByPublicKey)({ publicKey: Buffer.from(publicKey, "hex"), addressType }, this.network);
|
|
35
40
|
return addObj;
|
|
36
41
|
}
|
|
37
42
|
}
|
|
38
|
-
|
|
43
|
+
exports.BitcoinInterfaceUtils = BitcoinInterfaceUtils;
|
|
44
|
+
exports.default = BitcoinInterfaceUtils;
|
|
39
45
|
//# sourceMappingURL=bitcoin-interface-utils.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitcoin-interface-utils.js","sourceRoot":"","sources":["../src/bitcoin-interface-utils.
|
|
1
|
+
{"version":3,"file":"bitcoin-interface-utils.js","sourceRoot":"","sources":["../src/bitcoin-interface-utils.ts"],"names":[],"mappings":";;;;;;AAAA,gEAAuC;AACvC,mDAKwB;AAGxB,MAAa,qBAAqB;IAGhC,YAAY,WAAmB;QAC7B,IAAI,CAAC,OAAO,GAAG,WAAW,CAAC,QAAQ,CAAC,UAAU,CAAC,CAAA;QAC/C,IAAI,CAAC,OAAO,GAAG,kBAAQ,CAAC,WAAW,CAAC,CAAA;IACtC,CAAC;IAED,oBAAoB,CAAC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