@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.
Files changed (131) hide show
  1. package/LICENSE +15 -0
  2. package/README.md +24 -0
  3. package/es/bundle.js +2 -0
  4. package/es/bundle.js.LICENSE.txt +48 -0
  5. package/lib/address/index.d.ts +37 -0
  6. package/lib/address/index.js +235 -0
  7. package/lib/bitcoin-core.d.ts +5 -0
  8. package/lib/bitcoin-core.js +37 -0
  9. package/lib/constants.d.ts +1 -0
  10. package/lib/constants.js +5 -0
  11. package/lib/error.d.ts +20 -0
  12. package/lib/error.js +29 -0
  13. package/lib/index.d.ts +14 -0
  14. package/lib/index.js +50 -0
  15. package/lib/keyring/hd-keyring.d.ts +50 -0
  16. package/lib/keyring/hd-keyring.js +238 -0
  17. package/lib/keyring/index.d.ts +4 -0
  18. package/lib/keyring/index.js +20 -0
  19. package/lib/keyring/interfaces/SimpleKeyringOptions.d.ts +53 -0
  20. package/lib/keyring/interfaces/SimpleKeyringOptions.js +85 -0
  21. package/lib/keyring/keystone-keyring.d.ts +82 -0
  22. package/lib/keyring/keystone-keyring.js +377 -0
  23. package/lib/keyring/simple-keyring.d.ts +11 -0
  24. package/lib/keyring/simple-keyring.js +66 -0
  25. package/lib/message/bip322-simple.d.ts +19 -0
  26. package/lib/message/bip322-simple.js +182 -0
  27. package/lib/message/deterministic-ecdsa.d.ts +2 -0
  28. package/lib/message/deterministic-ecdsa.js +83 -0
  29. package/lib/message/ecdsa.d.ts +3 -0
  30. package/lib/message/ecdsa.js +32 -0
  31. package/lib/message/index.d.ts +3 -0
  32. package/lib/message/index.js +19 -0
  33. package/lib/network/index.d.ts +14 -0
  34. package/lib/network/index.js +40 -0
  35. package/lib/runes/index.d.ts +1 -0
  36. package/lib/runes/index.js +17 -0
  37. package/lib/runes/rund_id.d.ts +11 -0
  38. package/lib/runes/rund_id.js +30 -0
  39. package/lib/runes/varint.d.ts +15 -0
  40. package/lib/runes/varint.js +45 -0
  41. package/lib/src/address/index.d.ts +37 -0
  42. package/lib/src/bitcoin-core.d.ts +5 -0
  43. package/lib/src/constants.d.ts +1 -0
  44. package/lib/src/error.d.ts +20 -0
  45. package/lib/src/index.d.ts +14 -0
  46. package/lib/src/keyring/hd-keyring.d.ts +50 -0
  47. package/lib/src/keyring/index.d.ts +4 -0
  48. package/lib/src/keyring/interfaces/SimpleKeyringOptions.d.ts +53 -0
  49. package/lib/src/keyring/keystone-keyring.d.ts +82 -0
  50. package/lib/src/keyring/simple-keyring.d.ts +11 -0
  51. package/lib/src/message/bip322-simple.d.ts +19 -0
  52. package/lib/src/message/deterministic-ecdsa.d.ts +2 -0
  53. package/lib/src/message/ecdsa.d.ts +3 -0
  54. package/lib/src/message/index.d.ts +3 -0
  55. package/lib/src/network/index.d.ts +14 -0
  56. package/lib/src/runes/index.d.ts +1 -0
  57. package/lib/src/runes/rund_id.d.ts +11 -0
  58. package/lib/src/runes/varint.d.ts +15 -0
  59. package/lib/src/transaction/index.d.ts +3 -0
  60. package/lib/src/transaction/inscription-utxo.d.ts +33 -0
  61. package/lib/src/transaction/transaction.d.ts +52 -0
  62. package/lib/src/transaction/utxo.d.ts +35 -0
  63. package/lib/src/tx-helpers/index.d.ts +8 -0
  64. package/lib/src/tx-helpers/send-atomicals-ft.d.ts +16 -0
  65. package/lib/src/tx-helpers/send-atomicals-nft.d.ts +14 -0
  66. package/lib/src/tx-helpers/send-btc.d.ts +28 -0
  67. package/lib/src/tx-helpers/send-inscription.d.ts +16 -0
  68. package/lib/src/tx-helpers/send-inscriptions.d.ts +14 -0
  69. package/lib/src/tx-helpers/send-runes.d.ts +19 -0
  70. package/lib/src/tx-helpers/split-inscription-utxo.d.ts +15 -0
  71. package/lib/src/types.d.ts +59 -0
  72. package/lib/src/utils.d.ts +23 -0
  73. package/lib/src/wallet/abstract-wallet.d.ts +6 -0
  74. package/lib/src/wallet/estimate-wallet.d.ts +23 -0
  75. package/lib/src/wallet/index.d.ts +3 -0
  76. package/lib/src/wallet/local-wallet.d.ts +23 -0
  77. package/lib/test/address/address.test.d.ts +1 -0
  78. package/lib/test/keyring/hd-keyring.test.d.ts +1 -0
  79. package/lib/test/keyring/keystone-keyring.test.d.ts +1 -0
  80. package/lib/test/keyring/simple-keyring.test.d.ts +1 -0
  81. package/lib/test/message/message.test.d.ts +1 -0
  82. package/lib/test/runes/varint.test.d.ts +1 -0
  83. package/lib/test/transaction/transaction.test.d.ts +1 -0
  84. package/lib/test/transaction/utxo.test.d.ts +1 -0
  85. package/lib/test/tx-helpers/send-atomicals-ft.test.d.ts +1 -0
  86. package/lib/test/tx-helpers/send-atomicals-nft.test.d.ts +1 -0
  87. package/lib/test/tx-helpers/send-btc.test.d.ts +1 -0
  88. package/lib/test/tx-helpers/send-inscription.test.d.ts +1 -0
  89. package/lib/test/tx-helpers/send-inscriptions.test.d.ts +1 -0
  90. package/lib/test/tx-helpers/send-runes.test.d.ts +1 -0
  91. package/lib/test/tx-helpers/split-inscription-utxo.test.d.ts +1 -0
  92. package/lib/test/tx-helpers/utils.d.ts +217 -0
  93. package/lib/test/utils.d.ts +4 -0
  94. package/lib/test/wallet/local-wallet.test.d.ts +1 -0
  95. package/lib/transaction/index.d.ts +3 -0
  96. package/lib/transaction/index.js +19 -0
  97. package/lib/transaction/inscription-utxo.d.ts +33 -0
  98. package/lib/transaction/inscription-utxo.js +120 -0
  99. package/lib/transaction/transaction.d.ts +52 -0
  100. package/lib/transaction/transaction.js +358 -0
  101. package/lib/transaction/utxo.d.ts +35 -0
  102. package/lib/transaction/utxo.js +107 -0
  103. package/lib/tx-helpers/index.d.ts +8 -0
  104. package/lib/tx-helpers/index.js +18 -0
  105. package/lib/tx-helpers/send-atomicals-ft.d.ts +16 -0
  106. package/lib/tx-helpers/send-atomicals-ft.js +66 -0
  107. package/lib/tx-helpers/send-atomicals-nft.d.ts +14 -0
  108. package/lib/tx-helpers/send-atomicals-nft.js +45 -0
  109. package/lib/tx-helpers/send-btc.d.ts +28 -0
  110. package/lib/tx-helpers/send-btc.js +78 -0
  111. package/lib/tx-helpers/send-inscription.d.ts +16 -0
  112. package/lib/tx-helpers/send-inscription.js +49 -0
  113. package/lib/tx-helpers/send-inscriptions.d.ts +14 -0
  114. package/lib/tx-helpers/send-inscriptions.js +45 -0
  115. package/lib/tx-helpers/send-runes.d.ts +19 -0
  116. package/lib/tx-helpers/send-runes.js +101 -0
  117. package/lib/tx-helpers/split-inscription-utxo.d.ts +15 -0
  118. package/lib/tx-helpers/split-inscription-utxo.js +58 -0
  119. package/lib/types.d.ts +59 -0
  120. package/lib/types.js +15 -0
  121. package/lib/utils.d.ts +23 -0
  122. package/lib/utils.js +71 -0
  123. package/lib/wallet/abstract-wallet.d.ts +6 -0
  124. package/lib/wallet/abstract-wallet.js +2 -0
  125. package/lib/wallet/estimate-wallet.d.ts +23 -0
  126. package/lib/wallet/estimate-wallet.js +174 -0
  127. package/lib/wallet/index.d.ts +3 -0
  128. package/lib/wallet/index.js +19 -0
  129. package/lib/wallet/local-wallet.d.ts +23 -0
  130. package/lib/wallet/local-wallet.js +183 -0
  131. package/package.json +97 -0
@@ -0,0 +1,83 @@
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
+ Object.defineProperty(exports, "__esModule", { value: true });
26
+ exports.signMessageOfDeterministicECDSA = void 0;
27
+ const hmac = __importStar(require("@noble/hashes/hmac"));
28
+ const sha256 = __importStar(require("@noble/hashes/sha256"));
29
+ const noble_secp256k1 = __importStar(require("@noble/secp256k1"));
30
+ const bitcoin_core_1 = require("../bitcoin-core");
31
+ noble_secp256k1.utils.hmacSha256Sync = (key, ...msgs) => hmac.hmac(sha256.sha256, key, noble_secp256k1.utils.concatBytes(...msgs));
32
+ const MAGIC_BYTES = Buffer.from('Bitcoin Signed Message:\n');
33
+ function varintBufNum(n) {
34
+ let buf;
35
+ if (n < 253) {
36
+ buf = Buffer.alloc(1);
37
+ buf.writeUInt8(n, 0);
38
+ }
39
+ else if (n < 0x10000) {
40
+ buf = Buffer.alloc(1 + 2);
41
+ buf.writeUInt8(253, 0);
42
+ buf.writeUInt16LE(n, 1);
43
+ }
44
+ else if (n < 0x100000000) {
45
+ buf = Buffer.alloc(1 + 4);
46
+ buf.writeUInt8(254, 0);
47
+ buf.writeUInt32LE(n, 1);
48
+ }
49
+ else {
50
+ buf = Buffer.alloc(1 + 8);
51
+ buf.writeUInt8(255, 0);
52
+ buf.writeInt32LE(n & -1, 1);
53
+ buf.writeUInt32LE(Math.floor(n / 0x100000000), 5);
54
+ }
55
+ return buf;
56
+ }
57
+ function magicHash(message) {
58
+ const prefix1 = varintBufNum(MAGIC_BYTES.length);
59
+ const messageBuffer = Buffer.from(message);
60
+ const prefix2 = varintBufNum(messageBuffer.length);
61
+ const buf = Buffer.concat([prefix1, MAGIC_BYTES, prefix2, messageBuffer]);
62
+ return bitcoin_core_1.bitcoin.crypto.hash256(buf);
63
+ }
64
+ function toCompact(i, signature, compressed) {
65
+ if (!(i === 0 || i === 1 || i === 2 || i === 3)) {
66
+ throw new Error('i must be equal to 0, 1, 2, or 3');
67
+ }
68
+ let val = i + 27 + 4;
69
+ if (!compressed) {
70
+ val = val - 4;
71
+ }
72
+ return Buffer.concat([Uint8Array.of(val), Uint8Array.from(signature)]);
73
+ }
74
+ function signMessageOfDeterministicECDSA(ecpair, message) {
75
+ const hash = magicHash(message);
76
+ const [signature, i] = noble_secp256k1.signSync(Buffer.from(hash), ecpair.privateKey.toString('hex'), {
77
+ canonical: true,
78
+ recovered: true,
79
+ der: false
80
+ });
81
+ return toCompact(i, signature, true).toString('base64');
82
+ }
83
+ exports.signMessageOfDeterministicECDSA = signMessageOfDeterministicECDSA;
@@ -0,0 +1,3 @@
1
+ import { ECPairInterface } from 'ecpair';
2
+ export declare function signMessageOfECDSA(privateKey: ECPairInterface, text: string): string;
3
+ export declare function verifyMessageOfECDSA(publicKey: string, text: string, sig: string): boolean;
@@ -0,0 +1,32 @@
1
+ "use strict";
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.verifyMessageOfECDSA = exports.signMessageOfECDSA = void 0;
7
+ const bitcore_lib_1 = __importDefault(require("bitcore-lib"));
8
+ function signMessageOfECDSA(privateKey, text) {
9
+ const keyPair = privateKey;
10
+ const message = new bitcore_lib_1.default.Message(text);
11
+ // @ts-ignore
12
+ return message.sign(new bitcore_lib_1.default.PrivateKey(keyPair.privateKey));
13
+ }
14
+ exports.signMessageOfECDSA = signMessageOfECDSA;
15
+ function verifyMessageOfECDSA(publicKey, text, sig) {
16
+ const message = new bitcore_lib_1.default.Message(text);
17
+ // @ts-ignore
18
+ const signature = bitcore_lib_1.default.crypto.Signature.fromCompact(Buffer.from(sig, 'base64'));
19
+ const hash = message.magicHash();
20
+ // recover the public key
21
+ // @ts-ignore
22
+ const ecdsa = new bitcore_lib_1.default.crypto.ECDSA();
23
+ ecdsa.hashbuf = hash;
24
+ ecdsa.sig = signature;
25
+ const pubkeyInSig = ecdsa.toPublicKey();
26
+ const pubkeyInSigString = new bitcore_lib_1.default.PublicKey(Object.assign({}, pubkeyInSig.toObject(), { compressed: true })).toString();
27
+ if (pubkeyInSigString != publicKey) {
28
+ return false;
29
+ }
30
+ return bitcore_lib_1.default.crypto.ECDSA.verify(hash, signature, pubkeyInSig);
31
+ }
32
+ exports.verifyMessageOfECDSA = verifyMessageOfECDSA;
@@ -0,0 +1,3 @@
1
+ export * from './bip322-simple';
2
+ export * from './deterministic-ecdsa';
3
+ export * from './ecdsa';
@@ -0,0 +1,19 @@
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("./bip322-simple"), exports);
18
+ __exportStar(require("./deterministic-ecdsa"), exports);
19
+ __exportStar(require("./ecdsa"), exports);
@@ -0,0 +1,14 @@
1
+ import { bitcoin } from '../bitcoin-core';
2
+ export declare enum NetworkType {
3
+ MAINNET = 0,
4
+ TESTNET = 1,
5
+ REGTEST = 2
6
+ }
7
+ /**
8
+ * Convert network type to bitcoinjs-lib network.
9
+ */
10
+ export declare function toPsbtNetwork(networkType: NetworkType): bitcoin.networks.Network;
11
+ /**
12
+ * Convert bitcoinjs-lib network to network type.
13
+ */
14
+ export declare function toNetworkType(network: bitcoin.Network): NetworkType;
@@ -0,0 +1,40 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.toNetworkType = exports.toPsbtNetwork = exports.NetworkType = void 0;
4
+ const bitcoin_core_1 = require("../bitcoin-core");
5
+ var NetworkType;
6
+ (function (NetworkType) {
7
+ NetworkType[NetworkType["MAINNET"] = 0] = "MAINNET";
8
+ NetworkType[NetworkType["TESTNET"] = 1] = "TESTNET";
9
+ NetworkType[NetworkType["REGTEST"] = 2] = "REGTEST";
10
+ })(NetworkType = exports.NetworkType || (exports.NetworkType = {}));
11
+ /**
12
+ * Convert network type to bitcoinjs-lib network.
13
+ */
14
+ function toPsbtNetwork(networkType) {
15
+ if (networkType === NetworkType.MAINNET) {
16
+ return bitcoin_core_1.bitcoin.networks.bitcoin;
17
+ }
18
+ else if (networkType === NetworkType.TESTNET) {
19
+ return bitcoin_core_1.bitcoin.networks.testnet;
20
+ }
21
+ else {
22
+ return bitcoin_core_1.bitcoin.networks.regtest;
23
+ }
24
+ }
25
+ exports.toPsbtNetwork = toPsbtNetwork;
26
+ /**
27
+ * Convert bitcoinjs-lib network to network type.
28
+ */
29
+ function toNetworkType(network) {
30
+ if (network.bech32 == bitcoin_core_1.bitcoin.networks.bitcoin.bech32) {
31
+ return NetworkType.MAINNET;
32
+ }
33
+ else if (network.bech32 == bitcoin_core_1.bitcoin.networks.testnet.bech32) {
34
+ return NetworkType.TESTNET;
35
+ }
36
+ else {
37
+ return NetworkType.REGTEST;
38
+ }
39
+ }
40
+ exports.toNetworkType = toNetworkType;
@@ -0,0 +1 @@
1
+ export * from './varint';
@@ -0,0 +1,17 @@
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("./varint"), exports);
@@ -0,0 +1,11 @@
1
+ export declare class RuneId {
2
+ block: number;
3
+ tx: number;
4
+ constructor({ block, tx }: {
5
+ block: number;
6
+ tx: number;
7
+ });
8
+ static fromBigInt(n: any): RuneId;
9
+ toString(): string;
10
+ static fromString(s: string): RuneId;
11
+ }
@@ -0,0 +1,30 @@
1
+ "use strict";
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.RuneId = void 0;
7
+ const big_integer_1 = __importDefault(require("big-integer"));
8
+ class RuneId {
9
+ constructor({ block, tx }) {
10
+ this.block = block;
11
+ this.tx = tx;
12
+ }
13
+ static fromBigInt(n) {
14
+ const bigN = (0, big_integer_1.default)(n);
15
+ const block = bigN.shiftRight(16);
16
+ const tx = bigN.and(0xffff);
17
+ if (block.greater(Number.MAX_SAFE_INTEGER) || tx.greater(Number.MAX_SAFE_INTEGER)) {
18
+ throw new Error('Integer overflow');
19
+ }
20
+ return new RuneId({ block: block.toJSNumber(), tx: tx.toJSNumber() });
21
+ }
22
+ toString() {
23
+ return `${this.block}:${this.tx}`;
24
+ }
25
+ static fromString(s) {
26
+ const [block, tx] = s.split(':').map(Number);
27
+ return new RuneId({ block, tx });
28
+ }
29
+ }
30
+ exports.RuneId = RuneId;
@@ -0,0 +1,15 @@
1
+ /// <reference types="node" />
2
+ declare function try_decode(buf: any): (string | number)[];
3
+ declare function encodeToVec(n: any, v: any): void;
4
+ declare function decode(buffer: any): {
5
+ num: string | number;
6
+ index: string | number;
7
+ };
8
+ declare function encode(n: any): Buffer;
9
+ export declare const varint: {
10
+ encode: typeof encode;
11
+ decode: typeof decode;
12
+ try_decode: typeof try_decode;
13
+ encodeToVec: typeof encodeToVec;
14
+ };
15
+ export {};
@@ -0,0 +1,45 @@
1
+ "use strict";
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.varint = void 0;
7
+ const big_integer_1 = __importDefault(require("big-integer"));
8
+ function try_decode(buf) {
9
+ let n = (0, big_integer_1.default)(0);
10
+ let m = (0, big_integer_1.default)(1);
11
+ for (let i = 0;; i++) {
12
+ if (i >= buf.length) {
13
+ throw new Error('Buffer too short');
14
+ }
15
+ let byte = (0, big_integer_1.default)(buf.readUInt8(i));
16
+ n = n.plus(byte.and(0x7f).multiply(m));
17
+ if (byte.and(0x80).equals(0)) {
18
+ return [n.toString(), i + 1];
19
+ }
20
+ m = m.shiftLeft(7);
21
+ }
22
+ }
23
+ function encodeToVec(n, v) {
24
+ n = (0, big_integer_1.default)(n);
25
+ while (n.shiftRight(7).greater(0)) {
26
+ v.push(n.and(0b01111111).or(0b10000000).toJSNumber());
27
+ n = n.shiftRight(7);
28
+ }
29
+ v.push(n.toJSNumber());
30
+ }
31
+ function decode(buffer) {
32
+ const ret = try_decode(buffer);
33
+ return { num: ret[0], index: ret[1] };
34
+ }
35
+ function encode(n) {
36
+ let v = [];
37
+ encodeToVec(n, v);
38
+ return Buffer.from(new Uint8Array(v));
39
+ }
40
+ exports.varint = {
41
+ encode,
42
+ decode,
43
+ try_decode,
44
+ encodeToVec
45
+ };
@@ -0,0 +1,37 @@
1
+ /// <reference types="node" />
2
+ import { NetworkType } from '../network';
3
+ import { AddressType } from '../types';
4
+ import * as bitcoin from 'bitcoinjs-lib';
5
+ /**
6
+ * Convert public key to bitcoin payment object.
7
+ */
8
+ export declare function publicKeyToPayment(publicKey: string, type: AddressType, networkType: NetworkType): bitcoin.payments.Payment;
9
+ /**
10
+ * Convert public key to bitcoin address.
11
+ */
12
+ export declare function publicKeyToAddress(publicKey: string, type: AddressType, networkType: NetworkType): string;
13
+ /**
14
+ * Convert public key to bitcoin scriptPk.
15
+ */
16
+ export declare function publicKeyToScriptPk(publicKey: string, type: AddressType, networkType: NetworkType): string;
17
+ /**
18
+ * Convert bitcoin address to scriptPk.
19
+ */
20
+ export declare function addressToScriptPk(address: string, networkType: NetworkType): Buffer;
21
+ /**
22
+ * Check if the address is valid.
23
+ */
24
+ export declare function isValidAddress(address: string, networkType?: NetworkType): boolean;
25
+ export declare function decodeAddress(address: string): {
26
+ networkType: NetworkType;
27
+ addressType: AddressType;
28
+ dust: number;
29
+ };
30
+ /**
31
+ * Get address type.
32
+ */
33
+ export declare function getAddressType(address: string, networkType?: NetworkType): AddressType;
34
+ /**
35
+ * Convert scriptPk to address.
36
+ */
37
+ export declare function scriptPkToAddress(scriptPk: string | Buffer, networkType?: NetworkType): string;
@@ -0,0 +1,5 @@
1
+ import * as ecc from '@bitcoinerlab/secp256k1';
2
+ import * as bitcoin from 'bitcoinjs-lib';
3
+ export declare const ECPair: import("ecpair").ECPairAPI;
4
+ export { ECPairInterface } from 'ecpair';
5
+ export { ecc, bitcoin };
@@ -0,0 +1 @@
1
+ export declare const UTXO_DUST = 546;
@@ -0,0 +1,20 @@
1
+ export declare enum ErrorCodes {
2
+ UNKNOWN = -1,
3
+ INSUFFICIENT_BTC_UTXO = -2,
4
+ INSUFFICIENT_ASSET_UTXO = -3,
5
+ NOT_SAFE_UTXOS = -4,
6
+ ASSET_MAYBE_LOST = -5,
7
+ ONLY_ONE_ARC20_CAN_BE_SENT = -6
8
+ }
9
+ export declare const ErrorMessages: {
10
+ [-1]: string;
11
+ [-2]: string;
12
+ [-3]: string;
13
+ [-4]: string;
14
+ [-5]: string;
15
+ [-6]: string;
16
+ };
17
+ export declare class WalletUtilsError extends Error {
18
+ code: ErrorCodes;
19
+ constructor(code: ErrorCodes, message?: string);
20
+ }
@@ -0,0 +1,14 @@
1
+ export * as address from './address';
2
+ export * as core from './bitcoin-core';
3
+ export * from './constants';
4
+ export * as keyring from './keyring';
5
+ export * as message from './message';
6
+ export * as transaction from './transaction';
7
+ export * as txHelpers from './tx-helpers';
8
+ export * from './types';
9
+ export * as utils from './utils';
10
+ export * as wallet from './wallet';
11
+ export * from './keyring/interfaces/SimpleKeyringOptions';
12
+ export * from './keyring/hd-keyring';
13
+ export * from './keyring/keystone-keyring';
14
+ export * from './keyring/simple-keyring';
@@ -0,0 +1,50 @@
1
+ import bitcore from 'bitcore-lib';
2
+ import { ECPairInterface } from '../bitcoin-core';
3
+ import { DeserializeOption, IKeyringBase } from './interfaces/SimpleKeyringOptions';
4
+ export declare class HdKeyring extends IKeyringBase<DeserializeOption> {
5
+ static type: string;
6
+ type: string;
7
+ mnemonic: string;
8
+ xpriv: string;
9
+ passphrase: string;
10
+ hdPath: string;
11
+ root: bitcore.HDPrivateKey;
12
+ hdWallet?: any;
13
+ wallets: ECPairInterface[];
14
+ activeIndexes: number[];
15
+ page: number;
16
+ perPage: number;
17
+ private _index2wallet;
18
+ constructor(opts?: DeserializeOption);
19
+ serialize(): DeserializeOption;
20
+ deserialize(_opts?: DeserializeOption): void;
21
+ initFromXpriv(xpriv: string): void;
22
+ initFromMnemonic(mnemonic: string): void;
23
+ changeHdPath(hdPath: string): void;
24
+ getAccountByHdPath(hdPath: string, index: number): string;
25
+ addAccounts(numberOfAccounts?: number): string[];
26
+ activeAccounts(indexes: number[]): string[];
27
+ getFirstPage(): Promise<{
28
+ address: string;
29
+ index: number;
30
+ }[]>;
31
+ getNextPage(): Promise<{
32
+ address: string;
33
+ index: number;
34
+ }[]>;
35
+ getPreviousPage(): Promise<{
36
+ address: string;
37
+ index: number;
38
+ }[]>;
39
+ getAddresses(start: number, end: number): {
40
+ address: string;
41
+ index: number;
42
+ }[];
43
+ __getPage(increment: number): Promise<{
44
+ address: string;
45
+ index: number;
46
+ }[]>;
47
+ getAccounts(): string[];
48
+ getIndexByAddress(address: string): number;
49
+ private _addressFromIndex;
50
+ }
@@ -0,0 +1,4 @@
1
+ export * from './hd-keyring';
2
+ export * from './keystone-keyring';
3
+ export * from './simple-keyring';
4
+ export * from './interfaces/SimpleKeyringOptions';
@@ -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,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 {};
@@ -0,0 +1,11 @@
1
+ import { IKeyringBase, SimpleKeyringOptions } from './interfaces/SimpleKeyringOptions';
2
+ export declare class SimpleKeyring extends IKeyringBase<SimpleKeyringOptions> {
3
+ static type: string;
4
+ type: string;
5
+ constructor(opts?: SimpleKeyringOptions);
6
+ serialize(): SimpleKeyringOptions;
7
+ deserialize(opts: SimpleKeyringOptions): void;
8
+ addAccounts(n?: number): string[];
9
+ getAccounts(): string[];
10
+ }
11
+ export declare function verifySignData(publicKey: string, hash: string, type: 'ecdsa' | 'schnorr', signature: string): boolean;
@@ -0,0 +1,19 @@
1
+ import { NetworkType } from '../network';
2
+ import { AbstractWallet } from '../wallet';
3
+ import * as bitcoin from 'bitcoinjs-lib';
4
+ export declare function genPsbtOfBIP322Simple({ message, address, networkType }: {
5
+ message: string;
6
+ address: string;
7
+ networkType: NetworkType;
8
+ }): bitcoin.Psbt;
9
+ export declare function getSignatureFromPsbtOfBIP322Simple(psbt: bitcoin.Psbt): string;
10
+ /**
11
+ * reference: https://github.com/bitcoin/bips/blob/master/bip-0322.mediawiki
12
+ */
13
+ export declare function signMessageOfBIP322Simple({ message, address, networkType, wallet }: {
14
+ message: string;
15
+ address: string;
16
+ networkType: NetworkType;
17
+ wallet: AbstractWallet;
18
+ }): Promise<string>;
19
+ export declare function verifyMessageOfBIP322Simple(address: string, msg: string, signature: string, networkType?: NetworkType): boolean;
@@ -0,0 +1,2 @@
1
+ import { ECPairInterface } from '../bitcoin-core';
2
+ export declare function signMessageOfDeterministicECDSA(ecpair: ECPairInterface, message: string): string;
@@ -0,0 +1,3 @@
1
+ import { ECPairInterface } from 'ecpair';
2
+ export declare function signMessageOfECDSA(privateKey: ECPairInterface, text: string): string;
3
+ export declare function verifyMessageOfECDSA(publicKey: string, text: string, sig: string): boolean;
@@ -0,0 +1,3 @@
1
+ export * from './bip322-simple';
2
+ export * from './deterministic-ecdsa';
3
+ export * from './ecdsa';