@btc-vision/wallet-sdk 1.0.2 → 1.0.5

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.
Files changed (129) hide show
  1. package/es/bundle.js +1 -1
  2. package/es/bundle.js.LICENSE.txt +2 -2
  3. package/lib/address/index.js +50 -94
  4. package/lib/bitcoin-core.js +7 -47
  5. package/lib/constants.js +1 -4
  6. package/lib/error.js +6 -10
  7. package/lib/index.js +14 -53
  8. package/lib/keyring/hd-keyring.js +40 -89
  9. package/lib/keyring/index.js +4 -20
  10. package/lib/keyring/interfaces/SimpleKeyringOptions.js +16 -31
  11. package/lib/keyring/keystone-keyring.js +142 -211
  12. package/lib/keyring/simple-keyring.js +13 -18
  13. package/lib/message/bip322-simple.js +31 -81
  14. package/lib/message/deterministic-ecdsa.js +7 -43
  15. package/lib/message/ecdsa.js +10 -17
  16. package/lib/message/index.js +3 -19
  17. package/lib/network/index.js +12 -17
  18. package/lib/runes/index.js +1 -17
  19. package/lib/runes/rund_id.js +5 -10
  20. package/lib/runes/varint.js +6 -12
  21. package/lib/transaction/index.js +3 -19
  22. package/lib/transaction/inscription-utxo.js +9 -10
  23. package/lib/transaction/transaction.js +137 -142
  24. package/lib/transaction/utxo.js +13 -18
  25. package/lib/tx-helpers/index.js +8 -18
  26. package/lib/tx-helpers/send-atomicals-ft.js +45 -59
  27. package/lib/tx-helpers/send-atomicals-nft.js +29 -43
  28. package/lib/tx-helpers/send-btc.js +53 -70
  29. package/lib/tx-helpers/send-inscription.js +32 -46
  30. package/lib/tx-helpers/send-inscriptions.js +28 -42
  31. package/lib/tx-helpers/send-runes.js +83 -100
  32. package/lib/tx-helpers/split-inscription-utxo.js +39 -53
  33. package/lib/types.js +2 -5
  34. package/lib/utils.js +16 -29
  35. package/lib/wallet/abstract-wallet.js +1 -2
  36. package/lib/wallet/estimate-wallet.js +130 -147
  37. package/lib/wallet/index.js +3 -19
  38. package/lib/wallet/local-wallet.js +134 -150
  39. package/package.json +21 -12
  40. package/lib/address/index.d.ts +0 -36
  41. package/lib/bitcoin-core.d.ts +0 -5
  42. package/lib/constants.d.ts +0 -1
  43. package/lib/error.d.ts +0 -20
  44. package/lib/index.d.ts +0 -14
  45. package/lib/keyring/hd-keyring.d.ts +0 -50
  46. package/lib/keyring/index.d.ts +0 -4
  47. package/lib/keyring/interfaces/SimpleKeyringOptions.d.ts +0 -52
  48. package/lib/keyring/keystone-keyring.d.ts +0 -82
  49. package/lib/keyring/simple-keyring.d.ts +0 -11
  50. package/lib/message/bip322-simple.d.ts +0 -19
  51. package/lib/message/deterministic-ecdsa.d.ts +0 -2
  52. package/lib/message/ecdsa.d.ts +0 -3
  53. package/lib/message/index.d.ts +0 -3
  54. package/lib/network/index.d.ts +0 -14
  55. package/lib/runes/index.d.ts +0 -1
  56. package/lib/runes/rund_id.d.ts +0 -11
  57. package/lib/runes/varint.d.ts +0 -14
  58. package/lib/src/address/index.d.ts +0 -36
  59. package/lib/src/bitcoin-core.d.ts +0 -5
  60. package/lib/src/constants.d.ts +0 -1
  61. package/lib/src/error.d.ts +0 -20
  62. package/lib/src/index.d.ts +0 -14
  63. package/lib/src/keyring/hd-keyring.d.ts +0 -50
  64. package/lib/src/keyring/index.d.ts +0 -4
  65. package/lib/src/keyring/interfaces/SimpleKeyringOptions.d.ts +0 -52
  66. package/lib/src/keyring/keystone-keyring.d.ts +0 -82
  67. package/lib/src/keyring/simple-keyring.d.ts +0 -11
  68. package/lib/src/message/bip322-simple.d.ts +0 -19
  69. package/lib/src/message/deterministic-ecdsa.d.ts +0 -2
  70. package/lib/src/message/ecdsa.d.ts +0 -3
  71. package/lib/src/message/index.d.ts +0 -3
  72. package/lib/src/network/index.d.ts +0 -14
  73. package/lib/src/runes/index.d.ts +0 -1
  74. package/lib/src/runes/rund_id.d.ts +0 -11
  75. package/lib/src/runes/varint.d.ts +0 -14
  76. package/lib/src/transaction/index.d.ts +0 -3
  77. package/lib/src/transaction/inscription-utxo.d.ts +0 -33
  78. package/lib/src/transaction/transaction.d.ts +0 -51
  79. package/lib/src/transaction/utxo.d.ts +0 -35
  80. package/lib/src/tx-helpers/index.d.ts +0 -8
  81. package/lib/src/tx-helpers/send-atomicals-ft.d.ts +0 -16
  82. package/lib/src/tx-helpers/send-atomicals-nft.d.ts +0 -14
  83. package/lib/src/tx-helpers/send-btc.d.ts +0 -28
  84. package/lib/src/tx-helpers/send-inscription.d.ts +0 -16
  85. package/lib/src/tx-helpers/send-inscriptions.d.ts +0 -14
  86. package/lib/src/tx-helpers/send-runes.d.ts +0 -19
  87. package/lib/src/tx-helpers/split-inscription-utxo.d.ts +0 -15
  88. package/lib/src/types.d.ts +0 -59
  89. package/lib/src/utils.d.ts +0 -23
  90. package/lib/src/wallet/abstract-wallet.d.ts +0 -6
  91. package/lib/src/wallet/estimate-wallet.d.ts +0 -23
  92. package/lib/src/wallet/index.d.ts +0 -3
  93. package/lib/src/wallet/local-wallet.d.ts +0 -23
  94. package/lib/test/address/address.test.d.ts +0 -1
  95. package/lib/test/keyring/hd-keyring.test.d.ts +0 -1
  96. package/lib/test/keyring/keystone-keyring.test.d.ts +0 -1
  97. package/lib/test/keyring/simple-keyring.test.d.ts +0 -1
  98. package/lib/test/message/message.test.d.ts +0 -1
  99. package/lib/test/runes/varint.test.d.ts +0 -1
  100. package/lib/test/transaction/transaction.test.d.ts +0 -1
  101. package/lib/test/transaction/utxo.test.d.ts +0 -1
  102. package/lib/test/tx-helpers/send-atomicals-ft.test.d.ts +0 -1
  103. package/lib/test/tx-helpers/send-atomicals-nft.test.d.ts +0 -1
  104. package/lib/test/tx-helpers/send-btc.test.d.ts +0 -1
  105. package/lib/test/tx-helpers/send-inscription.test.d.ts +0 -1
  106. package/lib/test/tx-helpers/send-inscriptions.test.d.ts +0 -1
  107. package/lib/test/tx-helpers/send-runes.test.d.ts +0 -1
  108. package/lib/test/tx-helpers/split-inscription-utxo.test.d.ts +0 -1
  109. package/lib/test/tx-helpers/utils.d.ts +0 -217
  110. package/lib/test/utils.d.ts +0 -4
  111. package/lib/test/wallet/local-wallet.test.d.ts +0 -1
  112. package/lib/transaction/index.d.ts +0 -3
  113. package/lib/transaction/inscription-utxo.d.ts +0 -33
  114. package/lib/transaction/transaction.d.ts +0 -51
  115. package/lib/transaction/utxo.d.ts +0 -35
  116. package/lib/tx-helpers/index.d.ts +0 -8
  117. package/lib/tx-helpers/send-atomicals-ft.d.ts +0 -16
  118. package/lib/tx-helpers/send-atomicals-nft.d.ts +0 -14
  119. package/lib/tx-helpers/send-btc.d.ts +0 -28
  120. package/lib/tx-helpers/send-inscription.d.ts +0 -16
  121. package/lib/tx-helpers/send-inscriptions.d.ts +0 -14
  122. package/lib/tx-helpers/send-runes.d.ts +0 -19
  123. package/lib/tx-helpers/split-inscription-utxo.d.ts +0 -15
  124. package/lib/types.d.ts +0 -59
  125. package/lib/utils.d.ts +0 -23
  126. package/lib/wallet/abstract-wallet.d.ts +0 -6
  127. package/lib/wallet/estimate-wallet.d.ts +0 -23
  128. package/lib/wallet/index.d.ts +0 -3
  129. package/lib/wallet/local-wallet.d.ts +0 -23
@@ -1,26 +1,15 @@
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) {
1
+ import { isTaprootInput, networks } from '@btc-vision/bitcoin';
2
+ import { EventEmitter } from 'events';
3
+ import { signMessageOfDeterministicECDSA, verifyMessageOfECDSA } from '../../message';
4
+ import { tweakSigner } from '../../utils';
5
+ export class IKeyringBase extends EventEmitter {
6
+ network;
7
+ static type = '';
8
+ type = '';
9
+ wallets = [];
10
+ constructor(network = networks.bitcoin) {
20
11
  super();
21
12
  this.network = network;
22
- this.type = '';
23
- this.wallets = [];
24
13
  }
25
14
  removeAccount(publicKey) {
26
15
  if (!this.wallets.map((wallet) => wallet.publicKey.toString('hex')).includes(publicKey)) {
@@ -28,10 +17,8 @@ class IKeyringBase extends events_1.EventEmitter {
28
17
  }
29
18
  this.wallets = this.wallets.filter((wallet) => wallet.publicKey.toString('hex') !== publicKey);
30
19
  }
31
- verifyMessage(publicKey, text, sig) {
32
- return __awaiter(this, void 0, void 0, function* () {
33
- return (0, message_1.verifyMessageOfECDSA)(publicKey, text, sig);
34
- });
20
+ async verifyMessage(publicKey, text, sig) {
21
+ return verifyMessageOfECDSA(publicKey, text, sig);
35
22
  }
36
23
  // Sign any content, but note that the content signed by this method is unreadable, so use it with caution.
37
24
  signData(publicKey, data, type = 'ecdsa') {
@@ -48,17 +35,17 @@ class IKeyringBase extends events_1.EventEmitter {
48
35
  }
49
36
  signMessage(publicKey, text) {
50
37
  const keyPair = this._getPrivateKeyFor(publicKey);
51
- return (0, message_1.signMessageOfDeterministicECDSA)(keyPair, text);
38
+ return signMessageOfDeterministicECDSA(keyPair, text);
52
39
  }
53
40
  exportAccount(publicKey) {
54
41
  const wallet = this._getWalletForAccount(publicKey);
55
- return wallet.privateKey.toString('hex');
42
+ return wallet.privateKey?.toString('hex');
56
43
  }
57
44
  signTransaction(psbt, inputs, opts) {
58
45
  inputs.forEach((input) => {
59
46
  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);
47
+ if (isTaprootInput(psbt.data.inputs[input.index]) && !input.disableTweakSigner) {
48
+ const signer = tweakSigner(keyPair, opts);
62
49
  psbt.signInput(input.index, signer, input.sighashTypes);
63
50
  }
64
51
  else {
@@ -81,5 +68,3 @@ class IKeyringBase extends events_1.EventEmitter {
81
68
  return this._getWalletForAccount(publicKey);
82
69
  }
83
70
  }
84
- exports.IKeyringBase = IKeyringBase;
85
- IKeyringBase.type = '';
@@ -1,86 +1,40 @@
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 () {
19
- var ownKeys = function(o) {
20
- ownKeys = Object.getOwnPropertyNames || function (o) {
21
- var ar = [];
22
- for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
23
- return ar;
24
- };
25
- return ownKeys(o);
26
- };
27
- return function (mod) {
28
- if (mod && mod.__esModule) return mod;
29
- var result = {};
30
- if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
31
- __setModuleDefault(result, mod);
32
- return result;
33
- };
34
- })();
35
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
36
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
37
- return new (P || (P = Promise))(function (resolve, reject) {
38
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
39
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
40
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
41
- step((generator = generator.apply(thisArg, _arguments || [])).next());
42
- });
43
- };
44
- var __importDefault = (this && this.__importDefault) || function (mod) {
45
- return (mod && mod.__esModule) ? mod : { "default": mod };
46
- };
47
- Object.defineProperty(exports, "__esModule", { value: true });
48
- exports.KeystoneKeyring = void 0;
49
- const keystone_sdk_1 = __importStar(require("@keystonehq/keystone-sdk"));
50
- const utils_1 = require("@keystonehq/keystone-sdk/dist/utils");
51
- const bitcoinjs_lib_1 = require("bitcoinjs-lib");
52
- const bitcore_lib_1 = __importDefault(require("bitcore-lib"));
53
- const message_1 = require("../message");
54
- const SimpleKeyringOptions_1 = require("./interfaces/SimpleKeyringOptions");
1
+ import { networks, Psbt } from '@btc-vision/bitcoin';
2
+ import KeystoneSDK, { KeystoneBitcoinSDK, UR } from '@keystonehq/keystone-sdk';
3
+ import { uuid } from '@keystonehq/keystone-sdk/dist/utils';
4
+ import bitcore from 'bitcore-lib';
5
+ import { verifyMessageOfECDSA } from '../message';
6
+ import { IKeyringBase } from './interfaces/SimpleKeyringOptions';
55
7
  const type = 'Keystone';
56
- class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
8
+ export class KeystoneKeyring extends IKeyringBase {
9
+ static type = type;
10
+ type = type;
11
+ mfp = '';
12
+ keys = [];
13
+ hdPath;
14
+ activeIndexes = [];
15
+ root = undefined;
16
+ page = 0;
17
+ perPage = 5;
18
+ origin = 'UniSat Wallet';
57
19
  constructor(opts) {
58
- super((opts === null || opts === void 0 ? void 0 : opts.network) || bitcoinjs_lib_1.networks.bitcoin);
59
- this.type = type;
60
- this.mfp = '';
61
- this.keys = [];
62
- this.activeIndexes = [];
63
- this.root = null;
64
- this.page = 0;
65
- this.perPage = 5;
66
- this.origin = 'UniSat Wallet';
20
+ super(opts?.network || networks.bitcoin);
67
21
  if (opts) {
68
22
  this.deserialize(opts);
69
23
  }
70
24
  }
71
- initFromUR(type, cbor) {
72
- return __awaiter(this, void 0, void 0, function* () {
73
- const keystoneSDK = new keystone_sdk_1.default({
74
- origin: this.origin
75
- });
76
- const account = keystoneSDK.parseAccount(new keystone_sdk_1.UR(Buffer.from(cbor, 'hex'), type));
77
- this.deserialize({
78
- mfp: account.masterFingerprint,
79
- keys: account.keys.map((k) => ({
80
- path: k.path,
81
- extendedPublicKey: k.extendedPublicKey
82
- }))
83
- });
25
+ async initFromUR(type, cbor) {
26
+ const keystoneSDK = new KeystoneSDK({
27
+ origin: this.origin
28
+ });
29
+ const account = keystoneSDK.parseAccount(new UR(Buffer.from(cbor, 'hex'), type));
30
+ this.deserialize({
31
+ mfp: account.masterFingerprint,
32
+ keys: account.keys
33
+ .filter((k) => k.extendedPublicKey !== undefined)
34
+ .map((k) => ({
35
+ path: k.path,
36
+ extendedPublicKey: k.extendedPublicKey
37
+ }))
84
38
  });
85
39
  }
86
40
  getHardenedPath(hdPath) {
@@ -93,27 +47,25 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
93
47
  if (!key) {
94
48
  throw new Error('Invalid path');
95
49
  }
96
- return new bitcore_lib_1.default.HDPublicKey(key.extendedPublicKey);
50
+ return new bitcore.HDPublicKey(key.extendedPublicKey);
97
51
  }
98
52
  getDefaultHdPath() {
99
53
  return "m/44'/0'/0'/0";
100
54
  }
101
55
  initRoot() {
102
- var _a;
103
- this.root = this.getHDPublicKey((_a = this.hdPath) !== null && _a !== void 0 ? _a : this.getDefaultHdPath());
56
+ this.root = this.getHDPublicKey(this.hdPath ?? this.getDefaultHdPath());
104
57
  }
105
58
  deserialize(opts) {
106
- var _a;
107
59
  this.mfp = opts.mfp;
108
60
  this.keys = opts.keys;
109
- this.hdPath = (_a = opts.hdPath) !== null && _a !== void 0 ? _a : this.getDefaultHdPath();
61
+ this.hdPath = opts.hdPath ?? this.getDefaultHdPath();
110
62
  this.activeIndexes = opts.activeIndexes ? [...opts.activeIndexes] : [];
111
63
  this.initRoot();
112
64
  if (opts.hdPath !== null &&
113
65
  opts.hdPath !== undefined &&
114
66
  opts.hdPath.length >= 13 &&
115
67
  opts.hdPath[opts.hdPath.length - 1] === '1') {
116
- this.root = this.root.derive(`m/1`);
68
+ this.root = this.root?.derive(`m/1`);
117
69
  }
118
70
  }
119
71
  serialize() {
@@ -129,36 +81,34 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
129
81
  let i = 0;
130
82
  const pubkeys = [];
131
83
  while (count) {
132
- if (this.activeIndexes.includes(i)) {
84
+ if (this.activeIndexes?.includes(i)) {
133
85
  i++;
134
86
  }
135
87
  else {
136
88
  const w = this.getWalletByIndex(i);
137
89
  pubkeys.push(w.publicKey);
138
- this.activeIndexes.push(i);
90
+ this.activeIndexes?.push(i);
139
91
  count--;
140
92
  }
141
93
  }
142
94
  return pubkeys;
143
95
  }
144
- addChangeAddressAccounts() {
145
- return __awaiter(this, arguments, void 0, function* (numberOfAccounts = 1) {
146
- let count = numberOfAccounts;
147
- let i = 0;
148
- const pubkeys = [];
149
- while (count) {
150
- if (this.activeIndexes.includes(i)) {
151
- i++;
152
- }
153
- else {
154
- const w = this.getChangeAddressWalletByIndex(i);
155
- pubkeys.push(w.publicKey);
156
- this.activeIndexes.push(i);
157
- count--;
158
- }
96
+ async addChangeAddressAccounts(numberOfAccounts = 1) {
97
+ let count = numberOfAccounts;
98
+ let i = 0;
99
+ const pubkeys = [];
100
+ while (count) {
101
+ if (this.activeIndexes?.includes(i)) {
102
+ i++;
159
103
  }
160
- return Promise.resolve(pubkeys);
161
- });
104
+ else {
105
+ const w = this.getChangeAddressWalletByIndex(i);
106
+ pubkeys.push(w.publicKey);
107
+ this.activeIndexes?.push(i);
108
+ count--;
109
+ }
110
+ }
111
+ return Promise.resolve(pubkeys);
162
112
  }
163
113
  getAccounts() {
164
114
  if (this.hdPath !== null &&
@@ -172,27 +122,23 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
172
122
  }
173
123
  return this.activeIndexes.map((i) => this.getWalletByIndex(i).publicKey);
174
124
  }
175
- getAccounts2() {
176
- return __awaiter(this, void 0, void 0, function* () {
177
- return this.activeIndexes.map((index) => {
178
- const child = this.root.derive(`m/${index}`);
179
- return {
180
- index,
181
- path: `${this.hdPath}/${index}`,
182
- publicKey: child.publicKey.toString()
183
- };
184
- });
125
+ async getAccounts2() {
126
+ return this.activeIndexes.map((index) => {
127
+ const child = this.root.derive(`m/${index}`);
128
+ return {
129
+ index,
130
+ path: `${this.hdPath}/${index}`,
131
+ publicKey: child.publicKey.toString()
132
+ };
185
133
  });
186
134
  }
187
- getAccountsWithBrand() {
188
- return __awaiter(this, void 0, void 0, function* () {
189
- return this.activeIndexes.map((i) => {
190
- const w = this.getWalletByIndex(i);
191
- return {
192
- address: w.publicKey,
193
- index: i
194
- };
195
- });
135
+ async getAccountsWithBrand() {
136
+ return this.activeIndexes.map((i) => {
137
+ const w = this.getWalletByIndex(i);
138
+ return {
139
+ address: w.publicKey,
140
+ index: i
141
+ };
196
142
  });
197
143
  }
198
144
  getWalletByIndex(index) {
@@ -247,24 +193,22 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
247
193
  }
248
194
  return accounts;
249
195
  }
250
- getPage(increment) {
251
- return __awaiter(this, void 0, void 0, function* () {
252
- this.page += increment;
253
- if (!this.page || this.page <= 0) {
254
- this.page = 1;
255
- }
256
- const from = (this.page - 1) * this.perPage;
257
- const to = from + this.perPage;
258
- const accounts = [];
259
- for (let i = from; i < to; i++) {
260
- const w = this.getWalletByIndex(i);
261
- accounts.push({
262
- address: w.publicKey,
263
- index: i + 1
264
- });
265
- }
266
- return accounts;
267
- });
196
+ async getPage(increment) {
197
+ this.page += increment;
198
+ if (!this.page || this.page <= 0) {
199
+ this.page = 1;
200
+ }
201
+ const from = (this.page - 1) * this.perPage;
202
+ const to = from + this.perPage;
203
+ const accounts = [];
204
+ for (let i = from; i < to; i++) {
205
+ const w = this.getWalletByIndex(i);
206
+ accounts.push({
207
+ address: w.publicKey,
208
+ index: i + 1
209
+ });
210
+ }
211
+ return accounts;
268
212
  }
269
213
  activeAccounts(indexes) {
270
214
  const accounts = [];
@@ -283,9 +227,8 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
283
227
  this.activeAccounts(this.activeIndexes);
284
228
  }
285
229
  changeChangeAddressHdPath(hdPath) {
286
- var _a;
287
230
  this.hdPath = hdPath;
288
- this.root = this.getHDPublicKey((_a = this.hdPath) !== null && _a !== void 0 ? _a : this.getDefaultHdPath());
231
+ this.root = this.getHDPublicKey(this.hdPath ?? this.getDefaultHdPath());
289
232
  this.root = this.root.derive(`m/1`);
290
233
  this.activeIndexes = [];
291
234
  return [];
@@ -300,88 +243,76 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
300
243
  const child = root.derive(`m/1/${index}`);
301
244
  return child.publicKey.toString();
302
245
  }
303
- genSignPsbtUr(psbtHex) {
304
- return __awaiter(this, void 0, void 0, function* () {
305
- const psbt = bitcoinjs_lib_1.Psbt.fromHex(psbtHex);
306
- const keystoneSDK = new keystone_sdk_1.default({
307
- origin: this.origin
308
- });
309
- const ur = keystoneSDK.btc.generatePSBT(psbt.data.toBuffer());
310
- return {
311
- type: ur.type,
312
- cbor: ur.cbor.toString('hex')
313
- };
246
+ async genSignPsbtUr(psbtHex) {
247
+ const psbt = Psbt.fromHex(psbtHex);
248
+ const keystoneSDK = new KeystoneSDK({
249
+ origin: this.origin
314
250
  });
251
+ const ur = keystoneSDK.btc.generatePSBT(psbt.data.toBuffer());
252
+ return {
253
+ type: ur.type,
254
+ cbor: ur.cbor.toString('hex')
255
+ };
315
256
  }
316
- parseSignPsbtUr(type, cbor) {
317
- return __awaiter(this, void 0, void 0, function* () {
318
- const keystoneSDK = new keystone_sdk_1.default({
319
- origin: this.origin
320
- });
321
- return keystoneSDK.btc.parsePSBT(new keystone_sdk_1.UR(Buffer.from(cbor, 'hex'), type));
257
+ async parseSignPsbtUr(type, cbor) {
258
+ const keystoneSDK = new KeystoneSDK({
259
+ origin: this.origin
322
260
  });
261
+ return keystoneSDK.btc.parsePSBT(new UR(Buffer.from(cbor, 'hex'), type));
323
262
  }
324
- genSignMsgUr(publicKey, text) {
325
- return __awaiter(this, void 0, void 0, function* () {
326
- const keystoneSDK = new keystone_sdk_1.default({
327
- origin: this.origin
328
- });
329
- let i = undefined;
330
- if (this.hdPath !== null &&
331
- this.hdPath !== undefined &&
332
- this.hdPath.length >= 13 &&
333
- this.hdPath[this.hdPath.length - 1] === '1') {
334
- const root = this.getHDPublicKey(this.hdPath);
335
- i = this.activeIndexes.find((i) => {
336
- const child = root.derive(`m/1/${i}`);
337
- if (child.publicKey.toString() === publicKey) {
338
- return true;
339
- }
340
- });
341
- }
342
- else {
343
- i = this.activeIndexes.find((i) => this.getWalletByIndex(i).publicKey === publicKey);
344
- }
345
- if (i === undefined) {
346
- throw new Error('publicKey not found');
347
- }
348
- const requestId = utils_1.uuid.v4();
349
- const ur = keystoneSDK.btc.generateSignRequest({
350
- requestId,
351
- signData: Buffer.from(text).toString('hex'),
352
- dataType: keystone_sdk_1.KeystoneBitcoinSDK.DataType.message,
353
- accounts: [
354
- {
355
- path: `${this.hdPath}/${i}`,
356
- xfp: this.mfp
357
- }
358
- ],
359
- origin: this.origin
263
+ async genSignMsgUr(publicKey, text) {
264
+ const keystoneSDK = new KeystoneSDK({
265
+ origin: this.origin
266
+ });
267
+ let i = undefined;
268
+ if (this.hdPath !== null &&
269
+ this.hdPath !== undefined &&
270
+ this.hdPath.length >= 13 &&
271
+ this.hdPath[this.hdPath.length - 1] === '1') {
272
+ const root = this.getHDPublicKey(this.hdPath);
273
+ i = this.activeIndexes.find((i) => {
274
+ const child = root.derive(`m/1/${i}`);
275
+ if (child.publicKey.toString() === publicKey) {
276
+ return true;
277
+ }
360
278
  });
361
- return {
362
- requestId,
363
- type: ur.type,
364
- cbor: ur.cbor.toString('hex')
365
- };
279
+ }
280
+ else {
281
+ i = this.activeIndexes.find((i) => this.getWalletByIndex(i).publicKey === publicKey);
282
+ }
283
+ if (i === undefined) {
284
+ throw new Error('publicKey not found');
285
+ }
286
+ const requestId = uuid.v4();
287
+ const ur = keystoneSDK.btc.generateSignRequest({
288
+ requestId,
289
+ signData: Buffer.from(text).toString('hex'),
290
+ dataType: KeystoneBitcoinSDK.DataType.message,
291
+ accounts: [
292
+ {
293
+ path: `${this.hdPath}/${i}`,
294
+ xfp: this.mfp
295
+ }
296
+ ],
297
+ origin: this.origin
366
298
  });
299
+ return {
300
+ requestId,
301
+ type: ur.type,
302
+ cbor: ur.cbor.toString('hex')
303
+ };
367
304
  }
368
- parseSignMsgUr(type, cbor) {
369
- return __awaiter(this, void 0, void 0, function* () {
370
- const keystoneSDK = new keystone_sdk_1.default({
371
- origin: this.origin
372
- });
373
- return keystoneSDK.btc.parseSignature(new keystone_sdk_1.UR(Buffer.from(cbor, 'hex'), type));
305
+ async parseSignMsgUr(type, cbor) {
306
+ const keystoneSDK = new KeystoneSDK({
307
+ origin: this.origin
374
308
  });
309
+ return keystoneSDK.btc.parseSignature(new UR(Buffer.from(cbor, 'hex'), type));
375
310
  }
376
311
  // eslint-disable-next-line @typescript-eslint/no-unused-vars
377
312
  signMessage(publicKey, text) {
378
313
  return 'Signing Message with Keystone should use genSignMsgUr and parseSignMsgUr';
379
314
  }
380
- verifyMessage(publicKey, text, sig) {
381
- return __awaiter(this, void 0, void 0, function* () {
382
- return (0, message_1.verifyMessageOfECDSA)(publicKey, text, sig);
383
- });
315
+ async verifyMessage(publicKey, text, sig) {
316
+ return verifyMessageOfECDSA(publicKey, text, sig);
384
317
  }
385
318
  }
386
- exports.KeystoneKeyring = KeystoneKeyring;
387
- KeystoneKeyring.type = type;
@@ -1,16 +1,13 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SimpleKeyring = void 0;
4
- exports.verifySignData = verifySignData;
5
- const bs58check_1 = require("bs58check");
6
- const bitcoin_core_1 = require("../bitcoin-core");
7
- const SimpleKeyringOptions_1 = require("./interfaces/SimpleKeyringOptions");
8
- const bitcoinjs_lib_1 = require("bitcoinjs-lib");
1
+ import { networks } from '@btc-vision/bitcoin';
2
+ import * as bs58check from 'bs58check';
3
+ import { ECPair } from '../bitcoin-core';
4
+ import { IKeyringBase } from './interfaces/SimpleKeyringOptions';
9
5
  const type = 'Simple Key Pair';
10
- class SimpleKeyring extends SimpleKeyringOptions_1.IKeyringBase {
6
+ export class SimpleKeyring extends IKeyringBase {
7
+ static type = type;
8
+ type = type;
11
9
  constructor(opts) {
12
- super((opts === null || opts === void 0 ? void 0 : opts.network) || bitcoinjs_lib_1.networks.bitcoin);
13
- this.type = type;
10
+ super(opts?.network || networks.bitcoin);
14
11
  if (opts && opts.privateKeys) {
15
12
  this.deserialize(opts);
16
13
  }
@@ -33,15 +30,15 @@ class SimpleKeyring extends SimpleKeyringOptions_1.IKeyringBase {
33
30
  }
34
31
  else {
35
32
  // base58
36
- buf = Buffer.from((0, bs58check_1.decode)(key).slice(1, 33));
33
+ buf = Buffer.from(bs58check.default.decode(key).slice(1, 33));
37
34
  }
38
- return bitcoin_core_1.ECPair.fromPrivateKey(buf);
35
+ return ECPair.fromPrivateKey(buf);
39
36
  });
40
37
  }
41
38
  addAccounts(n = 1) {
42
39
  const newWallets = [];
43
40
  for (let i = 0; i < n; i++) {
44
- newWallets.push(bitcoin_core_1.ECPair.makeRandom());
41
+ newWallets.push(ECPair.makeRandom());
45
42
  }
46
43
  this.wallets = this.wallets.concat(newWallets);
47
44
  return newWallets.map(({ publicKey }) => publicKey.toString('hex'));
@@ -50,10 +47,8 @@ class SimpleKeyring extends SimpleKeyringOptions_1.IKeyringBase {
50
47
  return this.wallets.map(({ publicKey }) => publicKey.toString('hex'));
51
48
  }
52
49
  }
53
- exports.SimpleKeyring = SimpleKeyring;
54
- SimpleKeyring.type = type;
55
- function verifySignData(publicKey, hash, type, signature) {
56
- const keyPair = bitcoin_core_1.ECPair.fromPublicKey(Buffer.from(publicKey, 'hex'));
50
+ export function verifySignData(publicKey, hash, type, signature) {
51
+ const keyPair = ECPair.fromPublicKey(Buffer.from(publicKey, 'hex'));
57
52
  if (type === 'ecdsa') {
58
53
  return keyPair.verify(Buffer.from(hash, 'hex'), Buffer.from(signature, 'hex'));
59
54
  }