@btc-vision/wallet-sdk 1.0.0
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/LICENSE +15 -0
- package/README.md +24 -0
- package/es/bundle.js +2 -0
- package/es/bundle.js.LICENSE.txt +48 -0
- package/lib/address/index.d.ts +37 -0
- package/lib/address/index.js +235 -0
- package/lib/bitcoin-core.d.ts +5 -0
- package/lib/bitcoin-core.js +37 -0
- package/lib/constants.d.ts +1 -0
- package/lib/constants.js +5 -0
- package/lib/error.d.ts +20 -0
- package/lib/error.js +29 -0
- package/lib/index.d.ts +14 -0
- package/lib/index.js +50 -0
- package/lib/keyring/hd-keyring.d.ts +50 -0
- package/lib/keyring/hd-keyring.js +238 -0
- package/lib/keyring/index.d.ts +4 -0
- package/lib/keyring/index.js +20 -0
- package/lib/keyring/interfaces/SimpleKeyringOptions.d.ts +53 -0
- package/lib/keyring/interfaces/SimpleKeyringOptions.js +85 -0
- package/lib/keyring/keystone-keyring.d.ts +82 -0
- package/lib/keyring/keystone-keyring.js +377 -0
- package/lib/keyring/simple-keyring.d.ts +11 -0
- package/lib/keyring/simple-keyring.js +66 -0
- package/lib/message/bip322-simple.d.ts +19 -0
- package/lib/message/bip322-simple.js +182 -0
- package/lib/message/deterministic-ecdsa.d.ts +2 -0
- package/lib/message/deterministic-ecdsa.js +83 -0
- package/lib/message/ecdsa.d.ts +3 -0
- package/lib/message/ecdsa.js +32 -0
- package/lib/message/index.d.ts +3 -0
- package/lib/message/index.js +19 -0
- package/lib/network/index.d.ts +14 -0
- package/lib/network/index.js +40 -0
- package/lib/runes/index.d.ts +1 -0
- package/lib/runes/index.js +17 -0
- package/lib/runes/rund_id.d.ts +11 -0
- package/lib/runes/rund_id.js +30 -0
- package/lib/runes/varint.d.ts +15 -0
- package/lib/runes/varint.js +45 -0
- package/lib/src/address/index.d.ts +37 -0
- package/lib/src/bitcoin-core.d.ts +5 -0
- package/lib/src/constants.d.ts +1 -0
- package/lib/src/error.d.ts +20 -0
- package/lib/src/index.d.ts +14 -0
- package/lib/src/keyring/hd-keyring.d.ts +50 -0
- package/lib/src/keyring/index.d.ts +4 -0
- package/lib/src/keyring/interfaces/SimpleKeyringOptions.d.ts +53 -0
- package/lib/src/keyring/keystone-keyring.d.ts +82 -0
- package/lib/src/keyring/simple-keyring.d.ts +11 -0
- package/lib/src/message/bip322-simple.d.ts +19 -0
- package/lib/src/message/deterministic-ecdsa.d.ts +2 -0
- package/lib/src/message/ecdsa.d.ts +3 -0
- package/lib/src/message/index.d.ts +3 -0
- package/lib/src/network/index.d.ts +14 -0
- package/lib/src/runes/index.d.ts +1 -0
- package/lib/src/runes/rund_id.d.ts +11 -0
- package/lib/src/runes/varint.d.ts +15 -0
- package/lib/src/transaction/index.d.ts +3 -0
- package/lib/src/transaction/inscription-utxo.d.ts +33 -0
- package/lib/src/transaction/transaction.d.ts +52 -0
- package/lib/src/transaction/utxo.d.ts +35 -0
- package/lib/src/tx-helpers/index.d.ts +8 -0
- package/lib/src/tx-helpers/send-atomicals-ft.d.ts +16 -0
- package/lib/src/tx-helpers/send-atomicals-nft.d.ts +14 -0
- package/lib/src/tx-helpers/send-btc.d.ts +28 -0
- package/lib/src/tx-helpers/send-inscription.d.ts +16 -0
- package/lib/src/tx-helpers/send-inscriptions.d.ts +14 -0
- package/lib/src/tx-helpers/send-runes.d.ts +19 -0
- package/lib/src/tx-helpers/split-inscription-utxo.d.ts +15 -0
- package/lib/src/types.d.ts +59 -0
- package/lib/src/utils.d.ts +23 -0
- package/lib/src/wallet/abstract-wallet.d.ts +6 -0
- package/lib/src/wallet/estimate-wallet.d.ts +23 -0
- package/lib/src/wallet/index.d.ts +3 -0
- package/lib/src/wallet/local-wallet.d.ts +23 -0
- package/lib/test/address/address.test.d.ts +1 -0
- package/lib/test/keyring/hd-keyring.test.d.ts +1 -0
- package/lib/test/keyring/keystone-keyring.test.d.ts +1 -0
- package/lib/test/keyring/simple-keyring.test.d.ts +1 -0
- package/lib/test/message/message.test.d.ts +1 -0
- package/lib/test/runes/varint.test.d.ts +1 -0
- package/lib/test/transaction/transaction.test.d.ts +1 -0
- package/lib/test/transaction/utxo.test.d.ts +1 -0
- package/lib/test/tx-helpers/send-atomicals-ft.test.d.ts +1 -0
- package/lib/test/tx-helpers/send-atomicals-nft.test.d.ts +1 -0
- package/lib/test/tx-helpers/send-btc.test.d.ts +1 -0
- package/lib/test/tx-helpers/send-inscription.test.d.ts +1 -0
- package/lib/test/tx-helpers/send-inscriptions.test.d.ts +1 -0
- package/lib/test/tx-helpers/send-runes.test.d.ts +1 -0
- package/lib/test/tx-helpers/split-inscription-utxo.test.d.ts +1 -0
- package/lib/test/tx-helpers/utils.d.ts +217 -0
- package/lib/test/utils.d.ts +4 -0
- package/lib/test/wallet/local-wallet.test.d.ts +1 -0
- package/lib/transaction/index.d.ts +3 -0
- package/lib/transaction/index.js +19 -0
- package/lib/transaction/inscription-utxo.d.ts +33 -0
- package/lib/transaction/inscription-utxo.js +120 -0
- package/lib/transaction/transaction.d.ts +52 -0
- package/lib/transaction/transaction.js +358 -0
- package/lib/transaction/utxo.d.ts +35 -0
- package/lib/transaction/utxo.js +107 -0
- package/lib/tx-helpers/index.d.ts +8 -0
- package/lib/tx-helpers/index.js +18 -0
- package/lib/tx-helpers/send-atomicals-ft.d.ts +16 -0
- package/lib/tx-helpers/send-atomicals-ft.js +66 -0
- package/lib/tx-helpers/send-atomicals-nft.d.ts +14 -0
- package/lib/tx-helpers/send-atomicals-nft.js +45 -0
- package/lib/tx-helpers/send-btc.d.ts +28 -0
- package/lib/tx-helpers/send-btc.js +78 -0
- package/lib/tx-helpers/send-inscription.d.ts +16 -0
- package/lib/tx-helpers/send-inscription.js +49 -0
- package/lib/tx-helpers/send-inscriptions.d.ts +14 -0
- package/lib/tx-helpers/send-inscriptions.js +45 -0
- package/lib/tx-helpers/send-runes.d.ts +19 -0
- package/lib/tx-helpers/send-runes.js +101 -0
- package/lib/tx-helpers/split-inscription-utxo.d.ts +15 -0
- package/lib/tx-helpers/split-inscription-utxo.js +58 -0
- package/lib/types.d.ts +59 -0
- package/lib/types.js +15 -0
- package/lib/utils.d.ts +23 -0
- package/lib/utils.js +71 -0
- package/lib/wallet/abstract-wallet.d.ts +6 -0
- package/lib/wallet/abstract-wallet.js +2 -0
- package/lib/wallet/estimate-wallet.d.ts +23 -0
- package/lib/wallet/estimate-wallet.js +174 -0
- package/lib/wallet/index.d.ts +3 -0
- package/lib/wallet/index.js +19 -0
- package/lib/wallet/local-wallet.d.ts +23 -0
- package/lib/wallet/local-wallet.js +183 -0
- package/package.json +97 -0
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
+
};
|
|
37
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
+
exports.HdKeyring = void 0;
|
|
39
|
+
const bip39 = __importStar(require("bip39"));
|
|
40
|
+
const hdkey_1 = __importDefault(require("hdkey"));
|
|
41
|
+
const bitcoin_core_1 = require("../bitcoin-core");
|
|
42
|
+
const SimpleKeyringOptions_1 = require("./interfaces/SimpleKeyringOptions");
|
|
43
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
44
|
+
const hdPathString = "m/44'/0'/0'/0";
|
|
45
|
+
const type = 'HD Key Tree';
|
|
46
|
+
class HdKeyring extends SimpleKeyringOptions_1.IKeyringBase {
|
|
47
|
+
/* PUBLIC METHODS */
|
|
48
|
+
constructor(opts) {
|
|
49
|
+
super((opts === null || opts === void 0 ? void 0 : opts.network) || bitcoinjs_lib_1.networks.bitcoin);
|
|
50
|
+
this.type = type;
|
|
51
|
+
this.mnemonic = null;
|
|
52
|
+
this.xpriv = null;
|
|
53
|
+
this.hdPath = hdPathString;
|
|
54
|
+
this.root = null;
|
|
55
|
+
this.wallets = [];
|
|
56
|
+
this.activeIndexes = [];
|
|
57
|
+
this.page = 0;
|
|
58
|
+
this.perPage = 5;
|
|
59
|
+
this._index2wallet = {};
|
|
60
|
+
if (opts) {
|
|
61
|
+
this.deserialize(opts);
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
serialize() {
|
|
65
|
+
return {
|
|
66
|
+
mnemonic: this.mnemonic,
|
|
67
|
+
xpriv: this.xpriv,
|
|
68
|
+
activeIndexes: this.activeIndexes,
|
|
69
|
+
hdPath: this.hdPath,
|
|
70
|
+
passphrase: this.passphrase
|
|
71
|
+
};
|
|
72
|
+
}
|
|
73
|
+
deserialize(_opts = {}) {
|
|
74
|
+
if (this.root) {
|
|
75
|
+
throw new Error('Btc-Hd-Keyring: Secret recovery phrase already provided');
|
|
76
|
+
}
|
|
77
|
+
let opts = _opts;
|
|
78
|
+
this.wallets = [];
|
|
79
|
+
this.mnemonic = null;
|
|
80
|
+
this.xpriv = null;
|
|
81
|
+
this.root = null;
|
|
82
|
+
this.hdPath = opts.hdPath || hdPathString;
|
|
83
|
+
if (opts.passphrase) {
|
|
84
|
+
this.passphrase = opts.passphrase;
|
|
85
|
+
}
|
|
86
|
+
if (opts.mnemonic) {
|
|
87
|
+
this.initFromMnemonic(opts.mnemonic);
|
|
88
|
+
}
|
|
89
|
+
else if (opts.xpriv) {
|
|
90
|
+
this.initFromXpriv(opts.xpriv);
|
|
91
|
+
}
|
|
92
|
+
if (opts.activeIndexes) {
|
|
93
|
+
this.activeAccounts(opts.activeIndexes);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
initFromXpriv(xpriv) {
|
|
97
|
+
if (this.root) {
|
|
98
|
+
throw new Error('Btc-Hd-Keyring: Secret recovery phrase already provided');
|
|
99
|
+
}
|
|
100
|
+
this.xpriv = xpriv;
|
|
101
|
+
this._index2wallet = {};
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
this.hdWallet = hdkey_1.default.fromJSON({ xpriv });
|
|
104
|
+
this.root = this.hdWallet;
|
|
105
|
+
}
|
|
106
|
+
initFromMnemonic(mnemonic) {
|
|
107
|
+
if (this.root) {
|
|
108
|
+
throw new Error('Btc-Hd-Keyring: Secret recovery phrase already provided');
|
|
109
|
+
}
|
|
110
|
+
this.mnemonic = mnemonic;
|
|
111
|
+
this._index2wallet = {};
|
|
112
|
+
const seed = bip39.mnemonicToSeedSync(mnemonic, this.passphrase);
|
|
113
|
+
this.hdWallet = hdkey_1.default.fromMasterSeed(seed);
|
|
114
|
+
this.root = this.hdWallet.derive(this.hdPath);
|
|
115
|
+
}
|
|
116
|
+
changeHdPath(hdPath) {
|
|
117
|
+
if (!this.mnemonic) {
|
|
118
|
+
throw new Error('Btc-Hd-Keyring: Not support');
|
|
119
|
+
}
|
|
120
|
+
this.hdPath = hdPath;
|
|
121
|
+
this.root = this.hdWallet.derive(this.hdPath);
|
|
122
|
+
const indexes = this.activeIndexes;
|
|
123
|
+
this._index2wallet = {};
|
|
124
|
+
this.activeIndexes = [];
|
|
125
|
+
this.wallets = [];
|
|
126
|
+
this.activeAccounts(indexes);
|
|
127
|
+
}
|
|
128
|
+
getAccountByHdPath(hdPath, index) {
|
|
129
|
+
if (!this.mnemonic) {
|
|
130
|
+
throw new Error('Btc-Hd-Keyring: Not support');
|
|
131
|
+
}
|
|
132
|
+
const root = this.hdWallet.derive(hdPath);
|
|
133
|
+
const child = root.deriveChild(index);
|
|
134
|
+
const ecpair = bitcoin_core_1.ECPair.fromPrivateKey(child.privateKey, {
|
|
135
|
+
network: this.network
|
|
136
|
+
});
|
|
137
|
+
return ecpair.publicKey.toString('hex');
|
|
138
|
+
}
|
|
139
|
+
addAccounts(numberOfAccounts = 1) {
|
|
140
|
+
let count = numberOfAccounts;
|
|
141
|
+
let currentIdx = 0;
|
|
142
|
+
const newWallets = [];
|
|
143
|
+
while (count) {
|
|
144
|
+
const [, wallet] = this._addressFromIndex(currentIdx);
|
|
145
|
+
if (this.wallets.includes(wallet)) {
|
|
146
|
+
currentIdx++;
|
|
147
|
+
}
|
|
148
|
+
else {
|
|
149
|
+
this.wallets.push(wallet);
|
|
150
|
+
newWallets.push(wallet);
|
|
151
|
+
this.activeIndexes.push(currentIdx);
|
|
152
|
+
count--;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return newWallets.map((w) => {
|
|
156
|
+
return w.publicKey.toString('hex');
|
|
157
|
+
});
|
|
158
|
+
}
|
|
159
|
+
activeAccounts(indexes) {
|
|
160
|
+
const accounts = [];
|
|
161
|
+
for (const index of indexes) {
|
|
162
|
+
const [address, wallet] = this._addressFromIndex(index);
|
|
163
|
+
this.wallets.push(wallet);
|
|
164
|
+
this.activeIndexes.push(index);
|
|
165
|
+
accounts.push(address);
|
|
166
|
+
}
|
|
167
|
+
return accounts;
|
|
168
|
+
}
|
|
169
|
+
getFirstPage() {
|
|
170
|
+
this.page = 0;
|
|
171
|
+
return this.__getPage(1);
|
|
172
|
+
}
|
|
173
|
+
getNextPage() {
|
|
174
|
+
return this.__getPage(1);
|
|
175
|
+
}
|
|
176
|
+
getPreviousPage() {
|
|
177
|
+
return this.__getPage(-1);
|
|
178
|
+
}
|
|
179
|
+
getAddresses(start, end) {
|
|
180
|
+
const from = start;
|
|
181
|
+
const to = end;
|
|
182
|
+
const accounts = [];
|
|
183
|
+
for (let i = from; i < to; i++) {
|
|
184
|
+
const [address] = this._addressFromIndex(i);
|
|
185
|
+
accounts.push({
|
|
186
|
+
address,
|
|
187
|
+
index: i + 1
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
return accounts;
|
|
191
|
+
}
|
|
192
|
+
__getPage(increment) {
|
|
193
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
194
|
+
this.page += increment;
|
|
195
|
+
if (!this.page || this.page <= 0) {
|
|
196
|
+
this.page = 1;
|
|
197
|
+
}
|
|
198
|
+
const from = (this.page - 1) * this.perPage;
|
|
199
|
+
const to = from + this.perPage;
|
|
200
|
+
const accounts = [];
|
|
201
|
+
for (let i = from; i < to; i++) {
|
|
202
|
+
const [address] = this._addressFromIndex(i);
|
|
203
|
+
accounts.push({
|
|
204
|
+
address,
|
|
205
|
+
index: i + 1
|
|
206
|
+
});
|
|
207
|
+
}
|
|
208
|
+
return accounts;
|
|
209
|
+
});
|
|
210
|
+
}
|
|
211
|
+
getAccounts() {
|
|
212
|
+
return this.wallets.map((w) => {
|
|
213
|
+
return w.publicKey.toString('hex');
|
|
214
|
+
});
|
|
215
|
+
}
|
|
216
|
+
getIndexByAddress(address) {
|
|
217
|
+
for (const key in this._index2wallet) {
|
|
218
|
+
if (this._index2wallet[key][0] === address) {
|
|
219
|
+
return Number(key);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
return null;
|
|
223
|
+
}
|
|
224
|
+
_addressFromIndex(i) {
|
|
225
|
+
if (!this._index2wallet[i]) {
|
|
226
|
+
const child = this.root.deriveChild(i);
|
|
227
|
+
// @ts-ignore
|
|
228
|
+
const ecpair = bitcoin_core_1.ECPair.fromPrivateKey(child.privateKey || Buffer.from(child.toString(), 'hex'), {
|
|
229
|
+
network: this.network
|
|
230
|
+
});
|
|
231
|
+
const address = ecpair.publicKey.toString('hex');
|
|
232
|
+
this._index2wallet[i] = [address, ecpair];
|
|
233
|
+
}
|
|
234
|
+
return this._index2wallet[i];
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
exports.HdKeyring = HdKeyring;
|
|
238
|
+
HdKeyring.type = type;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
__exportStar(require("./hd-keyring"), exports);
|
|
18
|
+
__exportStar(require("./keystone-keyring"), exports);
|
|
19
|
+
__exportStar(require("./simple-keyring"), exports);
|
|
20
|
+
__exportStar(require("./interfaces/SimpleKeyringOptions"), exports);
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { Network, Psbt } from 'bitcoinjs-lib';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
import { ECPairInterface } from 'ecpair';
|
|
5
|
+
interface BaseKeyringOptions {
|
|
6
|
+
readonly network?: Network;
|
|
7
|
+
}
|
|
8
|
+
export interface SimpleKeyringOptions extends BaseKeyringOptions {
|
|
9
|
+
readonly privateKeys?: string[];
|
|
10
|
+
}
|
|
11
|
+
export interface DeserializeOptionBase extends BaseKeyringOptions {
|
|
12
|
+
readonly hdPath?: string;
|
|
13
|
+
readonly activeIndexes?: number[];
|
|
14
|
+
}
|
|
15
|
+
export interface DeserializeOption extends DeserializeOptionBase {
|
|
16
|
+
readonly mnemonic?: string;
|
|
17
|
+
readonly xpriv?: string;
|
|
18
|
+
readonly passphrase?: string;
|
|
19
|
+
}
|
|
20
|
+
export interface KeystoneKey {
|
|
21
|
+
readonly path: string;
|
|
22
|
+
readonly extendedPublicKey: string;
|
|
23
|
+
}
|
|
24
|
+
export interface DeserializeOptionKeystone extends DeserializeOptionBase {
|
|
25
|
+
readonly mfp: string;
|
|
26
|
+
readonly keys: KeystoneKey[];
|
|
27
|
+
}
|
|
28
|
+
export type KeyringOptions = SimpleKeyringOptions | DeserializeOption | DeserializeOptionKeystone;
|
|
29
|
+
export declare abstract class IKeyringBase<T extends BaseKeyringOptions> extends EventEmitter {
|
|
30
|
+
readonly network: Network;
|
|
31
|
+
static type: string;
|
|
32
|
+
type: string;
|
|
33
|
+
protected wallets: ECPairInterface[];
|
|
34
|
+
protected constructor(network?: Network);
|
|
35
|
+
abstract serialize(): T;
|
|
36
|
+
abstract addAccounts(numberOfAccounts: number): string[];
|
|
37
|
+
abstract deserialize(opts?: T): unknown;
|
|
38
|
+
removeAccount(publicKey: string): void;
|
|
39
|
+
verifyMessage(publicKey: string, text: string, sig: string): Promise<boolean>;
|
|
40
|
+
signData(publicKey: string, data: string, type?: 'ecdsa' | 'schnorr'): string;
|
|
41
|
+
abstract getAccounts(): string[];
|
|
42
|
+
signMessage(publicKey: string, text: string): string;
|
|
43
|
+
exportAccount(publicKey: string): string;
|
|
44
|
+
signTransaction(psbt: Psbt, inputs: {
|
|
45
|
+
index: number;
|
|
46
|
+
publicKey: string;
|
|
47
|
+
sighashTypes?: number[];
|
|
48
|
+
disableTweakSigner?: boolean;
|
|
49
|
+
}[], opts?: any): Psbt;
|
|
50
|
+
private _getWalletForAccount;
|
|
51
|
+
private _getPrivateKeyFor;
|
|
52
|
+
}
|
|
53
|
+
export {};
|
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
5
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
6
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
7
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
8
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
9
|
+
});
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.IKeyringBase = void 0;
|
|
13
|
+
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
14
|
+
const events_1 = require("events");
|
|
15
|
+
const bip371_1 = require("bitcoinjs-lib/src/psbt/bip371");
|
|
16
|
+
const utils_1 = require("../../utils");
|
|
17
|
+
const message_1 = require("../../message");
|
|
18
|
+
class IKeyringBase extends events_1.EventEmitter {
|
|
19
|
+
constructor(network = bitcoinjs_lib_1.networks.bitcoin) {
|
|
20
|
+
super();
|
|
21
|
+
this.network = network;
|
|
22
|
+
this.type = '';
|
|
23
|
+
this.wallets = [];
|
|
24
|
+
}
|
|
25
|
+
removeAccount(publicKey) {
|
|
26
|
+
if (!this.wallets.map((wallet) => wallet.publicKey.toString('hex')).includes(publicKey)) {
|
|
27
|
+
throw new Error(`PublicKey ${publicKey} not found in this keyring`);
|
|
28
|
+
}
|
|
29
|
+
this.wallets = this.wallets.filter((wallet) => wallet.publicKey.toString('hex') !== publicKey);
|
|
30
|
+
}
|
|
31
|
+
verifyMessage(publicKey, text, sig) {
|
|
32
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
33
|
+
return (0, message_1.verifyMessageOfECDSA)(publicKey, text, sig);
|
|
34
|
+
});
|
|
35
|
+
}
|
|
36
|
+
// Sign any content, but note that the content signed by this method is unreadable, so use it with caution.
|
|
37
|
+
signData(publicKey, data, type = 'ecdsa') {
|
|
38
|
+
const keyPair = this._getPrivateKeyFor(publicKey);
|
|
39
|
+
if (type === 'ecdsa') {
|
|
40
|
+
return keyPair.sign(Buffer.from(data, 'hex')).toString('hex');
|
|
41
|
+
}
|
|
42
|
+
else if (type === 'schnorr') {
|
|
43
|
+
return keyPair.signSchnorr(Buffer.from(data, 'hex')).toString('hex');
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
throw new Error('Not support type');
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
signMessage(publicKey, text) {
|
|
50
|
+
const keyPair = this._getPrivateKeyFor(publicKey);
|
|
51
|
+
return (0, message_1.signMessageOfDeterministicECDSA)(keyPair, text);
|
|
52
|
+
}
|
|
53
|
+
exportAccount(publicKey) {
|
|
54
|
+
const wallet = this._getWalletForAccount(publicKey);
|
|
55
|
+
return wallet.privateKey.toString('hex');
|
|
56
|
+
}
|
|
57
|
+
signTransaction(psbt, inputs, opts) {
|
|
58
|
+
inputs.forEach((input) => {
|
|
59
|
+
const keyPair = this._getPrivateKeyFor(input.publicKey);
|
|
60
|
+
if ((0, bip371_1.isTaprootInput)(psbt.data.inputs[input.index]) && !input.disableTweakSigner) {
|
|
61
|
+
const signer = (0, utils_1.tweakSigner)(keyPair, opts);
|
|
62
|
+
psbt.signInput(input.index, signer, input.sighashTypes);
|
|
63
|
+
}
|
|
64
|
+
else {
|
|
65
|
+
psbt.signInput(input.index, keyPair, input.sighashTypes);
|
|
66
|
+
}
|
|
67
|
+
});
|
|
68
|
+
return psbt;
|
|
69
|
+
}
|
|
70
|
+
_getWalletForAccount(publicKey) {
|
|
71
|
+
let wallet = this.wallets.find((wallet) => wallet.publicKey.toString('hex') == publicKey);
|
|
72
|
+
if (!wallet) {
|
|
73
|
+
throw new Error('Simple Keyring - Unable to find matching publicKey.');
|
|
74
|
+
}
|
|
75
|
+
return wallet;
|
|
76
|
+
}
|
|
77
|
+
_getPrivateKeyFor(publicKey) {
|
|
78
|
+
if (!publicKey) {
|
|
79
|
+
throw new Error('Must specify publicKey.');
|
|
80
|
+
}
|
|
81
|
+
return this._getWalletForAccount(publicKey);
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
exports.IKeyringBase = IKeyringBase;
|
|
85
|
+
IKeyringBase.type = '';
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import bitcore from 'bitcore-lib';
|
|
2
|
+
import { DeserializeOptionKeystone, IKeyringBase, KeystoneKey } from './interfaces/SimpleKeyringOptions';
|
|
3
|
+
interface Wallet {
|
|
4
|
+
index: number;
|
|
5
|
+
publicKey: string;
|
|
6
|
+
path: string;
|
|
7
|
+
}
|
|
8
|
+
export declare class KeystoneKeyring extends IKeyringBase<DeserializeOptionKeystone> {
|
|
9
|
+
static type: string;
|
|
10
|
+
type: string;
|
|
11
|
+
mfp: string;
|
|
12
|
+
keys: KeystoneKey[];
|
|
13
|
+
hdPath?: string;
|
|
14
|
+
activeIndexes?: number[];
|
|
15
|
+
root: bitcore.HDPublicKey;
|
|
16
|
+
page: number;
|
|
17
|
+
perPage: number;
|
|
18
|
+
origin: string;
|
|
19
|
+
constructor(opts?: DeserializeOptionKeystone);
|
|
20
|
+
initFromUR(type: string, cbor: string): Promise<void>;
|
|
21
|
+
getHardenedPath(hdPath: string): string;
|
|
22
|
+
getHDPublicKey(hdPath: string): bitcore.HDPublicKey;
|
|
23
|
+
getDefaultHdPath(): string;
|
|
24
|
+
initRoot(): void;
|
|
25
|
+
deserialize(opts: DeserializeOptionKeystone): void;
|
|
26
|
+
serialize(): DeserializeOptionKeystone;
|
|
27
|
+
addAccounts(numberOfAccounts?: number): string[];
|
|
28
|
+
addChangeAddressAccounts(numberOfAccounts?: number): Promise<any[]>;
|
|
29
|
+
getAccounts(): string[];
|
|
30
|
+
getAccounts2(): Promise<{
|
|
31
|
+
index: number;
|
|
32
|
+
path: string;
|
|
33
|
+
publicKey: string;
|
|
34
|
+
}[]>;
|
|
35
|
+
getAccountsWithBrand(): Promise<{
|
|
36
|
+
address: string;
|
|
37
|
+
index: number;
|
|
38
|
+
}[]>;
|
|
39
|
+
getWalletByIndex(index: number): Wallet;
|
|
40
|
+
getChangeAddressWalletByIndex(index: number): Wallet;
|
|
41
|
+
removeAccount(publicKey: string): void;
|
|
42
|
+
exportAccount(_publicKey: string): string;
|
|
43
|
+
getFirstPage(): Promise<{
|
|
44
|
+
address: string;
|
|
45
|
+
index: number;
|
|
46
|
+
}[]>;
|
|
47
|
+
getNextPage(): Promise<{
|
|
48
|
+
address: string;
|
|
49
|
+
index: number;
|
|
50
|
+
}[]>;
|
|
51
|
+
getPreviousPage(): Promise<{
|
|
52
|
+
address: string;
|
|
53
|
+
index: number;
|
|
54
|
+
}[]>;
|
|
55
|
+
getAddresses(start: number, end: number): {
|
|
56
|
+
address: string;
|
|
57
|
+
index: number;
|
|
58
|
+
}[];
|
|
59
|
+
getPage(increment: number): Promise<{
|
|
60
|
+
address: string;
|
|
61
|
+
index: number;
|
|
62
|
+
}[]>;
|
|
63
|
+
activeAccounts(indexes: number[]): string[];
|
|
64
|
+
changeHdPath(hdPath: string): void;
|
|
65
|
+
changeChangeAddressHdPath(hdPath: string): any[];
|
|
66
|
+
getAccountByHdPath(hdPath: string, index: number): string;
|
|
67
|
+
getChangeAddressAccountByHdPath(hdPath: string, index: number): string;
|
|
68
|
+
genSignPsbtUr(psbtHex: string): Promise<{
|
|
69
|
+
type: string;
|
|
70
|
+
cbor: string;
|
|
71
|
+
}>;
|
|
72
|
+
parseSignPsbtUr(type: string, cbor: string): Promise<string>;
|
|
73
|
+
genSignMsgUr(publicKey: string, text: string): Promise<{
|
|
74
|
+
requestId: any;
|
|
75
|
+
type: string;
|
|
76
|
+
cbor: string;
|
|
77
|
+
}>;
|
|
78
|
+
parseSignMsgUr(type: string, cbor: string): Promise<import("@keystonehq/keystone-sdk").BtcSignature>;
|
|
79
|
+
signMessage(publicKey: string, text: string): string;
|
|
80
|
+
verifyMessage(publicKey: string, text: string, sig: string): Promise<boolean>;
|
|
81
|
+
}
|
|
82
|
+
export {};
|