xpi-ts 0.2.16 → 0.2.18

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 (89) hide show
  1. package/dist/cjs/lib/rank/index.js +9 -14
  2. package/dist/esm/index.js +46 -7
  3. package/dist/esm/jest.config.js +3 -1
  4. package/dist/esm/lib/bitcore/address.js +76 -72
  5. package/dist/esm/lib/bitcore/block/block.js +48 -44
  6. package/dist/esm/lib/bitcore/block/blockheader.js +59 -55
  7. package/dist/esm/lib/bitcore/block/index.js +9 -3
  8. package/dist/esm/lib/bitcore/block/merkleblock.js +55 -49
  9. package/dist/esm/lib/bitcore/crypto/bn.js +26 -20
  10. package/dist/esm/lib/bitcore/crypto/ecdsa.js +49 -45
  11. package/dist/esm/lib/bitcore/crypto/hash.js +27 -23
  12. package/dist/esm/lib/bitcore/crypto/index.js +22 -8
  13. package/dist/esm/lib/bitcore/crypto/musig2.js +76 -66
  14. package/dist/esm/lib/bitcore/crypto/point.js +38 -31
  15. package/dist/esm/lib/bitcore/crypto/random.js +9 -5
  16. package/dist/esm/lib/bitcore/crypto/schnorr.js +41 -37
  17. package/dist/esm/lib/bitcore/crypto/signature.js +35 -31
  18. package/dist/esm/lib/bitcore/crypto/sigtype.js +10 -4
  19. package/dist/esm/lib/bitcore/encoding/base58.js +15 -8
  20. package/dist/esm/lib/bitcore/encoding/base58check.js +17 -10
  21. package/dist/esm/lib/bitcore/encoding/bufferreader.js +22 -18
  22. package/dist/esm/lib/bitcore/encoding/bufferwriter.js +27 -23
  23. package/dist/esm/lib/bitcore/encoding/varint.js +17 -13
  24. package/dist/esm/lib/bitcore/errors.js +5 -1
  25. package/dist/esm/lib/bitcore/hdprivatekey.js +67 -63
  26. package/dist/esm/lib/bitcore/hdpublickey.js +72 -68
  27. package/dist/esm/lib/bitcore/index.js +167 -42
  28. package/dist/esm/lib/bitcore/message.js +40 -36
  29. package/dist/esm/lib/bitcore/mnemonic/errors.js +5 -2
  30. package/dist/esm/lib/bitcore/mnemonic/index.js +15 -4
  31. package/dist/esm/lib/bitcore/mnemonic/mnemonic.js +28 -24
  32. package/dist/esm/lib/bitcore/mnemonic/pbkdf2.js +11 -8
  33. package/dist/esm/lib/bitcore/mnemonic/words/english.js +4 -1
  34. package/dist/esm/lib/bitcore/mnemonic/words/french.js +4 -1
  35. package/dist/esm/lib/bitcore/mnemonic/words/index.js +8 -5
  36. package/dist/esm/lib/bitcore/musig2/index.js +9 -2
  37. package/dist/esm/lib/bitcore/musig2/session.js +32 -28
  38. package/dist/esm/lib/bitcore/musig2/signer.js +43 -38
  39. package/dist/esm/lib/bitcore/networks.js +51 -44
  40. package/dist/esm/lib/bitcore/opcode.js +12 -8
  41. package/dist/esm/lib/bitcore/privatekey.js +43 -39
  42. package/dist/esm/lib/bitcore/publickey.js +50 -46
  43. package/dist/esm/lib/bitcore/script/chunk.js +5 -1
  44. package/dist/esm/lib/bitcore/script/interpreter/condition-stack.js +5 -1
  45. package/dist/esm/lib/bitcore/script/interpreter/index.js +25 -4
  46. package/dist/esm/lib/bitcore/script/interpreter/interpreter.js +385 -379
  47. package/dist/esm/lib/bitcore/script/interpreter/script-num.js +15 -10
  48. package/dist/esm/lib/bitcore/script/interpreter/types.js +17 -14
  49. package/dist/esm/lib/bitcore/script/taproot.js +130 -107
  50. package/dist/esm/lib/bitcore/script.js +205 -201
  51. package/dist/esm/lib/bitcore/taproot/musig2.js +48 -40
  52. package/dist/esm/lib/bitcore/transaction/index.js +23 -6
  53. package/dist/esm/lib/bitcore/transaction/input/multisig.js +6 -2
  54. package/dist/esm/lib/bitcore/transaction/input/multisigscripthash.js +6 -2
  55. package/dist/esm/lib/bitcore/transaction/input/publickey.js +6 -2
  56. package/dist/esm/lib/bitcore/transaction/input/publickeyhash.js +6 -2
  57. package/dist/esm/lib/bitcore/transaction/input/taproot.js +6 -2
  58. package/dist/esm/lib/bitcore/transaction/input.js +139 -129
  59. package/dist/esm/lib/bitcore/transaction/outpoint.js +17 -13
  60. package/dist/esm/lib/bitcore/transaction/output.js +35 -31
  61. package/dist/esm/lib/bitcore/transaction/sighash.js +104 -99
  62. package/dist/esm/lib/bitcore/transaction/signature.js +42 -38
  63. package/dist/esm/lib/bitcore/transaction/transaction.js +115 -111
  64. package/dist/esm/lib/bitcore/transaction/unspentoutput.js +27 -23
  65. package/dist/esm/lib/bitcore/unit.js +7 -3
  66. package/dist/esm/lib/bitcore/uri.js +8 -4
  67. package/dist/esm/lib/bitcore/util/base32.js +10 -6
  68. package/dist/esm/lib/bitcore/util/bits.js +10 -4
  69. package/dist/esm/lib/bitcore/util/buffer.js +22 -18
  70. package/dist/esm/lib/bitcore/util/convertBits.js +7 -4
  71. package/dist/esm/lib/bitcore/util/js.js +5 -1
  72. package/dist/esm/lib/bitcore/util/merkle.js +15 -9
  73. package/dist/esm/lib/bitcore/util/preconditions.js +13 -9
  74. package/dist/esm/lib/bitcore/util.js +19 -12
  75. package/dist/esm/lib/bitcore/xaddress.js +50 -46
  76. package/dist/esm/lib/nft.js +60 -55
  77. package/dist/esm/lib/rank/api.js +4 -1
  78. package/dist/esm/lib/rank/index.js +141 -129
  79. package/dist/esm/lib/rank/opcode.js +3 -1
  80. package/dist/esm/lib/rank/script.js +11 -5
  81. package/dist/esm/lib/rank/transaction.js +9 -6
  82. package/dist/esm/lib/rpc.js +7 -3
  83. package/dist/esm/utils/constants.js +13 -10
  84. package/dist/esm/utils/env.js +6 -2
  85. package/dist/esm/utils/string.js +28 -16
  86. package/dist/esm/utils/wallet.js +11 -8
  87. package/dist/types/lib/rank/index.d.ts +1 -1
  88. package/dist/types/lib/rank/index.d.ts.map +1 -1
  89. package/package.json +1 -1
@@ -202,14 +202,14 @@ function toScriptRANK(sentiment, platform, profileId, postId) {
202
202
  return buffer_1.Buffer.from(script, 'hex');
203
203
  }
204
204
  function toScriptRNKC({ platform, profileId, postId, comment, }) {
205
- if (!platform) {
206
- throw new Error('Must specify platform');
205
+ if (!platform || !profileId) {
206
+ throw new Error('Must specify platform and profileId');
207
207
  }
208
208
  const platformSpec = exports.PlatformConfiguration.get(platform);
209
209
  if (!platformSpec || !platformSpec.profileId) {
210
210
  throw new Error('No platform profileId specification defined');
211
211
  }
212
- if (profileId && !platformSpec.profileId.regex.test(profileId)) {
212
+ if (!platformSpec.profileId.regex.test(profileId)) {
213
213
  throw new Error(`Invalid profileId: ${profileId}`);
214
214
  }
215
215
  if (postId && !platformSpec.postId.regex.test(postId)) {
@@ -225,13 +225,11 @@ function toScriptRNKC({ platform, profileId, postId, comment, }) {
225
225
  const LOKAD_PREFIX = (0, string_js_1.toHex)(exports.LOKAD_PREFIX_RNKC);
226
226
  let scriptRNKC = OP_RETURN + (0, string_js_1.toHex)(4) + LOKAD_PREFIX;
227
227
  scriptRNKC += (0, string_js_1.toHex)(1) + (0, string_js_1.toHex)(toPlatformBuf(platform));
228
- if (profileId) {
229
- scriptRNKC += (0, string_js_1.toHex)(platformSpec.profileId.len);
230
- scriptRNKC += (0, string_js_1.toHex)(toProfileIdBuf(platform, profileId));
231
- if (postId) {
232
- scriptRNKC += (0, string_js_1.toHex)(platformSpec.postId.len);
233
- scriptRNKC += (0, string_js_1.toHex)(toPostIdBuf(platform, postId));
234
- }
228
+ scriptRNKC += (0, string_js_1.toHex)(platformSpec.profileId.len);
229
+ scriptRNKC += (0, string_js_1.toHex)(toProfileIdBuf(platform, profileId));
230
+ if (postId) {
231
+ scriptRNKC += (0, string_js_1.toHex)(platformSpec.postId.len);
232
+ scriptRNKC += (0, string_js_1.toHex)(toPostIdBuf(platform, postId));
235
233
  }
236
234
  scriptBufs.push(buffer_1.Buffer.from(scriptRNKC, 'hex'));
237
235
  const commentBuf1 = commentBuf.slice(0, constants_js_1.MAX_OP_RETURN_DATA);
@@ -314,11 +312,8 @@ class ScriptProcessor {
314
312
  return undefined;
315
313
  }
316
314
  const profileIdSpec = platformSpec.profileId;
317
- if (this.script.length < chunk.offset + profileIdSpec.len) {
318
- return undefined;
319
- }
320
315
  const profileIdBuf = this.script.slice(chunk.offset, chunk.offset + profileIdSpec.len);
321
- if (profileIdBuf.length !== profileIdSpec.len) {
316
+ if (profileIdBuf.length < profileIdSpec.len) {
322
317
  return undefined;
323
318
  }
324
319
  switch (platform) {
package/dist/esm/index.js CHANGED
@@ -1,7 +1,46 @@
1
- export * from './lib/rpc.js';
2
- export * as Bitcore from './lib/bitcore/index.js';
3
- export * as RANK from './lib/rank/index.js';
4
- export * from './utils/constants.js';
5
- export * from './utils/env.js';
6
- export * from './utils/string.js';
7
- export * from './utils/wallet.js';
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 __exportStar = (this && this.__exportStar) || function(m, exports) {
19
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
20
+ };
21
+ var __importStar = (this && this.__importStar) || (function () {
22
+ var ownKeys = function(o) {
23
+ ownKeys = Object.getOwnPropertyNames || function (o) {
24
+ var ar = [];
25
+ for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
26
+ return ar;
27
+ };
28
+ return ownKeys(o);
29
+ };
30
+ return function (mod) {
31
+ if (mod && mod.__esModule) return mod;
32
+ var result = {};
33
+ if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
34
+ __setModuleDefault(result, mod);
35
+ return result;
36
+ };
37
+ })();
38
+ Object.defineProperty(exports, "__esModule", { value: true });
39
+ exports.RANK = exports.Bitcore = void 0;
40
+ __exportStar(require("./lib/rpc.js"), exports);
41
+ exports.Bitcore = __importStar(require("./lib/bitcore/index.js"));
42
+ exports.RANK = __importStar(require("./lib/rank/index.js"));
43
+ __exportStar(require("./utils/constants.js"), exports);
44
+ __exportStar(require("./utils/env.js"), exports);
45
+ __exportStar(require("./utils/string.js"), exports);
46
+ __exportStar(require("./utils/wallet.js"), exports);
@@ -1,4 +1,6 @@
1
- export default {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.default = {
2
4
  preset: 'ts-jest',
3
5
  testEnvironment: 'node',
4
6
  roots: ['<rootDir>'],
@@ -1,14 +1,17 @@
1
- import { Preconditions as $ } from './util/preconditions';
2
- import { BitcoreError } from './errors';
3
- import { Base58Check } from './encoding/base58check';
4
- import { get as getNetwork, defaultNetwork, } from './networks';
5
- import { Hash } from './crypto/hash';
6
- import { JSUtil, BufferUtil } from './util';
7
- import { PublicKey } from './publickey';
8
- import { XAddress } from './xaddress';
9
- import { Script } from './script';
10
- import { Opcode } from './opcode';
11
- export class Address {
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.Address = void 0;
4
+ const preconditions_1 = require("./util/preconditions");
5
+ const errors_1 = require("./errors");
6
+ const base58check_1 = require("./encoding/base58check");
7
+ const networks_1 = require("./networks");
8
+ const hash_1 = require("./crypto/hash");
9
+ const util_1 = require("./util");
10
+ const publickey_1 = require("./publickey");
11
+ const xaddress_1 = require("./xaddress");
12
+ const script_1 = require("./script");
13
+ const opcode_1 = require("./opcode");
14
+ class Address {
12
15
  static PayToPublicKeyHash = 'pubkeyhash';
13
16
  static PayToScriptHash = 'scripthash';
14
17
  static PayToTaproot = 'taproot';
@@ -19,12 +22,12 @@ export class Address {
19
22
  if (data instanceof Address) {
20
23
  return data;
21
24
  }
22
- $.checkArgument(data !== undefined, 'data', 'First argument is required, please include address data.', 'guide/address.html');
23
- if (network && !getNetwork(network)) {
25
+ preconditions_1.Preconditions.checkArgument(data !== undefined, 'data', 'First argument is required, please include address data.', 'guide/address.html');
26
+ if (network && !(0, networks_1.get)(network)) {
24
27
  throw new TypeError('Second argument must be "livenet", "testnet", or "regtest".');
25
28
  }
26
29
  const networkExplicitlyProvided = network !== undefined;
27
- network ||= defaultNetwork;
30
+ network ||= networks_1.defaultNetwork;
28
31
  if (type &&
29
32
  type !== Address.PayToPublicKeyHash &&
30
33
  type !== Address.PayToScriptHash &&
@@ -32,9 +35,9 @@ export class Address {
32
35
  throw new TypeError('Third argument must be "pubkeyhash", "scripthash", or "taproot".');
33
36
  }
34
37
  const info = this._classifyArguments(data, network, type, networkExplicitlyProvided);
35
- info.network = info.network || getNetwork(network) || defaultNetwork;
38
+ info.network = info.network || (0, networks_1.get)(network) || networks_1.defaultNetwork;
36
39
  info.type = info.type || type || Address.PayToPublicKeyHash;
37
- JSUtil.defineImmutable(this, {
40
+ util_1.JSUtil.defineImmutable(this, {
38
41
  hashBuffer: info.hashBuffer,
39
42
  network: info.network,
40
43
  type: info.type,
@@ -42,32 +45,32 @@ export class Address {
42
45
  }
43
46
  _classifyArguments(data, network, type, networkExplicitlyProvided = true) {
44
47
  if (typeof network === 'string') {
45
- const networkObj = getNetwork(network);
48
+ const networkObj = (0, networks_1.get)(network);
46
49
  if (!networkObj) {
47
50
  throw new TypeError('Unknown network');
48
51
  }
49
52
  network = networkObj;
50
53
  }
51
- if ((BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
54
+ if ((util_1.BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
52
55
  data.length === 20) {
53
56
  return Address._transformHash(data);
54
57
  }
55
- else if ((BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
58
+ else if ((util_1.BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
56
59
  data.length === 21) {
57
60
  return Address._transformBuffer(data, network, type);
58
61
  }
59
- else if ((BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
62
+ else if ((util_1.BufferUtil.isBuffer(data) || data instanceof Uint8Array) &&
60
63
  data.length === 33) {
61
64
  return {
62
- hashBuffer: BufferUtil.from(data),
63
- network: typeof network === 'string' ? getNetwork(network) : network,
65
+ hashBuffer: util_1.BufferUtil.from(data),
66
+ network: typeof network === 'string' ? (0, networks_1.get)(network) : network,
64
67
  type: type || Address.PayToTaproot,
65
68
  };
66
69
  }
67
- else if (data instanceof PublicKey) {
70
+ else if (data instanceof publickey_1.PublicKey) {
68
71
  return Address._transformPublicKey(data, network);
69
72
  }
70
- else if (data instanceof Script) {
73
+ else if (data instanceof script_1.Script) {
71
74
  return Address._transformScript(data, network);
72
75
  }
73
76
  else if (typeof data === 'string') {
@@ -85,8 +88,8 @@ export class Address {
85
88
  }
86
89
  static _classifyFromVersion(buffer) {
87
90
  const version = {};
88
- const pubkeyhashNetwork = getNetwork(buffer[0], 'pubkeyhash');
89
- const scripthashNetwork = getNetwork(buffer[0], 'scripthash');
91
+ const pubkeyhashNetwork = (0, networks_1.get)(buffer[0], 'pubkeyhash');
92
+ const scripthashNetwork = (0, networks_1.get)(buffer[0], 'scripthash');
90
93
  if (pubkeyhashNetwork) {
91
94
  version.network = pubkeyhashNetwork;
92
95
  version.type = Address.PayToPublicKeyHash;
@@ -102,7 +105,7 @@ export class Address {
102
105
  throw new TypeError('data parameter supplied is not a string.');
103
106
  }
104
107
  data = data.trim();
105
- const networkObj = getNetwork(network);
108
+ const networkObj = (0, networks_1.get)(network);
106
109
  if (network && !networkObj) {
107
110
  throw new TypeError('Unknown network');
108
111
  }
@@ -113,7 +116,7 @@ export class Address {
113
116
  throw new TypeError('Address has mismatched network type.');
114
117
  }
115
118
  return {
116
- hashBuffer: BufferUtil.from(info.hashBuffer),
119
+ hashBuffer: util_1.BufferUtil.from(info.hashBuffer),
117
120
  network: info.network,
118
121
  type: info.type,
119
122
  };
@@ -135,7 +138,7 @@ export class Address {
135
138
  }
136
139
  static _transformLegacyString(data, network, type) {
137
140
  const info = {};
138
- const decoded = Base58Check.decode(data);
141
+ const decoded = base58check_1.Base58Check.decode(data);
139
142
  const version = Address._classifyFromVersion(decoded);
140
143
  if (!version.network || !version.type) {
141
144
  throw new TypeError('Address has invalid version.');
@@ -151,10 +154,10 @@ export class Address {
151
154
  }
152
155
  static _transformXAddressString(data, network, type) {
153
156
  if (typeof network === 'string') {
154
- network = getNetwork(network);
157
+ network = (0, networks_1.get)(network);
155
158
  }
156
- network ||= defaultNetwork;
157
- const decodedXAddress = XAddress._decode(data);
159
+ network ||= networks_1.defaultNetwork;
160
+ const decodedXAddress = xaddress_1.XAddress._decode(data);
158
161
  if (!decodedXAddress.hashBuffer) {
159
162
  throw new TypeError('Invalid XAddress.');
160
163
  }
@@ -163,8 +166,8 @@ export class Address {
163
166
  const decodedType = decodedXAddress.type;
164
167
  if (decodedType === 'taproot' || decodedType === Address.PayToTaproot) {
165
168
  if (hashBuffer.length === 36 &&
166
- hashBuffer[0] === Opcode.OP_SCRIPTTYPE &&
167
- hashBuffer[1] === Opcode.OP_1 &&
169
+ hashBuffer[0] === opcode_1.Opcode.OP_SCRIPTTYPE &&
170
+ hashBuffer[1] === opcode_1.Opcode.OP_1 &&
168
171
  hashBuffer[2] === 0x21) {
169
172
  hashBuffer = hashBuffer.slice(3, 36);
170
173
  }
@@ -180,15 +183,15 @@ export class Address {
180
183
  };
181
184
  }
182
185
  if (hashBuffer.length === 25 &&
183
- hashBuffer[0] === Opcode.OP_DUP &&
184
- hashBuffer[1] === Opcode.OP_HASH160 &&
186
+ hashBuffer[0] === opcode_1.Opcode.OP_DUP &&
187
+ hashBuffer[1] === opcode_1.Opcode.OP_HASH160 &&
185
188
  hashBuffer[2] === 0x14) {
186
189
  hashBuffer = hashBuffer.slice(3, 23);
187
190
  }
188
191
  else if (hashBuffer.length === 23 &&
189
- hashBuffer[0] === Opcode.OP_HASH160 &&
192
+ hashBuffer[0] === opcode_1.Opcode.OP_HASH160 &&
190
193
  hashBuffer[1] === 0x14 &&
191
- hashBuffer[22] === Opcode.OP_EQUAL) {
194
+ hashBuffer[22] === opcode_1.Opcode.OP_EQUAL) {
192
195
  hashBuffer = hashBuffer.slice(2, 22);
193
196
  return {
194
197
  hashBuffer: hashBuffer,
@@ -204,25 +207,25 @@ export class Address {
204
207
  }
205
208
  static _transformHash(hash) {
206
209
  const info = {};
207
- if (!BufferUtil.isBuffer(hash)) {
210
+ if (!util_1.BufferUtil.isBuffer(hash)) {
208
211
  throw new TypeError('Address supplied is not a buffer.');
209
212
  }
210
213
  if (hash.length !== 20) {
211
214
  throw new TypeError('Address hashbuffers must be exactly 20 bytes.');
212
215
  }
213
- info.hashBuffer = BufferUtil.from(hash);
216
+ info.hashBuffer = util_1.BufferUtil.from(hash);
214
217
  return info;
215
218
  }
216
219
  static _transformBuffer(buffer, network, type) {
217
220
  const info = {};
218
- if (!BufferUtil.isBuffer(buffer)) {
221
+ if (!util_1.BufferUtil.isBuffer(buffer)) {
219
222
  throw new TypeError('Address supplied is not a buffer.');
220
223
  }
221
224
  if (buffer.length !== 21) {
222
225
  throw new TypeError('Address buffers must be exactly 21 bytes.');
223
226
  }
224
- const networkObj = getNetwork(network);
225
- const bufferVersion = Address._classifyFromVersion(BufferUtil.from(buffer));
227
+ const networkObj = (0, networks_1.get)(network);
228
+ const bufferVersion = Address._classifyFromVersion(util_1.BufferUtil.from(buffer));
226
229
  if (network && !networkObj) {
227
230
  throw new TypeError('Unknown network');
228
231
  }
@@ -233,29 +236,29 @@ export class Address {
233
236
  if (!bufferVersion.type || (type && type !== bufferVersion.type)) {
234
237
  throw new TypeError('Address has mismatched type.');
235
238
  }
236
- info.hashBuffer = BufferUtil.from(buffer).slice(1);
239
+ info.hashBuffer = util_1.BufferUtil.from(buffer).slice(1);
237
240
  info.network = bufferVersion.network;
238
241
  info.type = bufferVersion.type;
239
242
  return info;
240
243
  }
241
244
  static _transformPublicKey(pubkey, network) {
242
245
  const info = {};
243
- if (!(pubkey instanceof PublicKey)) {
246
+ if (!(pubkey instanceof publickey_1.PublicKey)) {
244
247
  throw new TypeError('Address must be an instance of PublicKey.');
245
248
  }
246
- info.hashBuffer = Hash.sha256ripemd160(pubkey.toBuffer());
249
+ info.hashBuffer = hash_1.Hash.sha256ripemd160(pubkey.toBuffer());
247
250
  info.type = Address.PayToPublicKeyHash;
248
- info.network = network ?? defaultNetwork;
251
+ info.network = network ?? networks_1.defaultNetwork;
249
252
  return info;
250
253
  }
251
254
  static _transformScript(script, network) {
252
- $.checkArgument(script instanceof Script, 'script', 'script must be a Script instance');
255
+ preconditions_1.Preconditions.checkArgument(script instanceof script_1.Script, 'script', 'script must be a Script instance');
253
256
  const address = script.getAddressInfo();
254
257
  if (!address) {
255
- throw new BitcoreError.Script.CantDeriveAddress('Cannot derive address from script');
258
+ throw new errors_1.BitcoreError.Script.CantDeriveAddress('Cannot derive address from script');
256
259
  }
257
260
  if (typeof network === 'string') {
258
- network = getNetwork(network);
261
+ network = (0, networks_1.get)(network);
259
262
  }
260
263
  return {
261
264
  hashBuffer: address.hashBuffer,
@@ -264,34 +267,34 @@ export class Address {
264
267
  };
265
268
  }
266
269
  static _transformObject(data) {
267
- $.checkArgument(data.hashBuffer !== undefined, 'data', 'Must provide a `hash` or `hashBuffer` property');
268
- $.checkArgument(data.type !== undefined, 'data', 'Must provide a `type` property');
270
+ preconditions_1.Preconditions.checkArgument(data.hashBuffer !== undefined, 'data', 'Must provide a `hash` or `hashBuffer` property');
271
+ preconditions_1.Preconditions.checkArgument(data.type !== undefined, 'data', 'Must provide a `type` property');
269
272
  return {
270
- hashBuffer: data.hashBuffer || BufferUtil.from(data.hashBuffer.toString(), 'hex'),
271
- network: getNetwork(data.network) || defaultNetwork,
273
+ hashBuffer: data.hashBuffer || util_1.BufferUtil.from(data.hashBuffer.toString(), 'hex'),
274
+ network: (0, networks_1.get)(data.network) || networks_1.defaultNetwork,
272
275
  type: data.type,
273
276
  };
274
277
  }
275
278
  static createMultisig(publicKeys, threshold, network) {
276
- const networkObj = network || publicKeys[0].network || defaultNetwork;
277
- return Address.payingTo(Script.buildMultisigOut(publicKeys, threshold, {}), networkObj);
279
+ const networkObj = network || publicKeys[0].network || networks_1.defaultNetwork;
280
+ return Address.payingTo(script_1.Script.buildMultisigOut(publicKeys, threshold, {}), networkObj);
278
281
  }
279
282
  static fromPublicKey(data, network) {
280
- const networkObj = getNetwork(network) || defaultNetwork;
283
+ const networkObj = (0, networks_1.get)(network) || networks_1.defaultNetwork;
281
284
  const info = Address._transformPublicKey(data, networkObj);
282
285
  return new Address(info.hashBuffer, info.network, info.type);
283
286
  }
284
287
  static fromPublicKeyHash(hash, network) {
285
- const networkObj = getNetwork(network) || defaultNetwork;
288
+ const networkObj = (0, networks_1.get)(network) || networks_1.defaultNetwork;
286
289
  return new Address(hash, networkObj, Address.PayToPublicKeyHash);
287
290
  }
288
291
  static fromScriptHash(hash, network) {
289
- const networkObj = getNetwork(network) || defaultNetwork;
292
+ const networkObj = (0, networks_1.get)(network) || networks_1.defaultNetwork;
290
293
  return new Address(hash, networkObj, Address.PayToScriptHash);
291
294
  }
292
295
  static fromTaprootCommitment(commitment, network) {
293
- const networkObj = getNetwork(network) || defaultNetwork;
294
- const commitmentBuf = commitment instanceof PublicKey ? commitment.toBuffer() : commitment;
296
+ const networkObj = (0, networks_1.get)(network) || networks_1.defaultNetwork;
297
+ const commitmentBuf = commitment instanceof publickey_1.PublicKey ? commitment.toBuffer() : commitment;
295
298
  if (commitmentBuf.length !== 33) {
296
299
  throw new Error('Taproot commitment must be 33-byte compressed public key');
297
300
  }
@@ -306,19 +309,19 @@ export class Address {
306
309
  return new Address(info.hashBuffer, info.network, info.type);
307
310
  }
308
311
  static fromObject(obj) {
309
- $.checkState(JSUtil.isHexa(obj.hash), 'Unexpected hash property, "' + obj.hash + '", expected to be hex.');
310
- const hashBuffer = BufferUtil.from(obj.hash, 'hex');
312
+ preconditions_1.Preconditions.checkState(util_1.JSUtil.isHexa(obj.hash), 'Unexpected hash property, "' + obj.hash + '", expected to be hex.');
313
+ const hashBuffer = util_1.BufferUtil.from(obj.hash, 'hex');
311
314
  return new Address(hashBuffer, obj.network, obj.type);
312
315
  }
313
316
  static fromScript(script, network) {
314
- $.checkArgument(script instanceof Script, 'script', 'script must be a Script instance');
317
+ preconditions_1.Preconditions.checkArgument(script instanceof script_1.Script, 'script', 'script must be a Script instance');
315
318
  const info = Address._transformScript(script, network);
316
319
  return new Address(info.hashBuffer, network, info.type);
317
320
  }
318
321
  static payingTo(script, network) {
319
- $.checkArgument(script !== null, 'script', 'script is required');
320
- $.checkArgument(script instanceof Script, 'script', 'script must be instance of Script');
321
- return Address.fromScriptHash(Hash.sha256ripemd160(script.toBuffer()), network);
322
+ preconditions_1.Preconditions.checkArgument(script !== null, 'script', 'script is required');
323
+ preconditions_1.Preconditions.checkArgument(script instanceof script_1.Script, 'script', 'script must be instance of Script');
324
+ return Address.fromScriptHash(hash_1.Hash.sha256ripemd160(script.toBuffer()), network);
322
325
  }
323
326
  static getValidationError(data, network, type) {
324
327
  try {
@@ -345,10 +348,10 @@ export class Address {
345
348
  return this.hashBuffer;
346
349
  }
347
350
  toFullBuffer() {
348
- const version = BufferUtil.from([
351
+ const version = util_1.BufferUtil.from([
349
352
  this.network[this.type],
350
353
  ]);
351
- const buf = BufferUtil.concat([version, this.hashBuffer]);
354
+ const buf = util_1.BufferUtil.concat([version, this.hashBuffer]);
352
355
  return buf;
353
356
  }
354
357
  toCashBuffer() {
@@ -375,11 +378,11 @@ export class Address {
375
378
  }
376
379
  toXAddress(network) {
377
380
  if (this.isPayToTaproot()) {
378
- const xaddr = new XAddress(this.hashBuffer, network ?? this.network, this.type);
381
+ const xaddr = new xaddress_1.XAddress(this.hashBuffer, network ?? this.network, this.type);
379
382
  return xaddr.toString();
380
383
  }
381
- const script = Script.fromAddress(this);
382
- const xaddr = new XAddress(script.toBuffer(), network ?? this.network, this.type);
384
+ const script = script_1.Script.fromAddress(this);
385
+ const xaddr = new xaddress_1.XAddress(script.toBuffer(), network ?? this.network, this.type);
383
386
  return xaddr.toString();
384
387
  }
385
388
  static decodeCashAddress(address) {
@@ -400,3 +403,4 @@ export class Address {
400
403
  '>');
401
404
  }
402
405
  }
406
+ exports.Address = Address;