@btc-vision/wallet-sdk 1.0.0 → 1.0.4
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/es/bundle.js +1 -1
- package/es/bundle.js.LICENSE.txt +4 -4
- package/lib/address/index.js +50 -85
- package/lib/bitcoin-core.js +7 -37
- package/lib/constants.js +1 -4
- package/lib/error.js +6 -10
- package/lib/index.js +14 -43
- package/lib/keyring/hd-keyring.js +40 -79
- package/lib/keyring/index.js +4 -20
- package/lib/keyring/interfaces/SimpleKeyringOptions.js +16 -31
- package/lib/keyring/keystone-keyring.js +142 -201
- package/lib/keyring/simple-keyring.js +13 -18
- package/lib/message/bip322-simple.js +31 -71
- package/lib/message/deterministic-ecdsa.js +19 -40
- package/lib/message/ecdsa.js +10 -18
- package/lib/message/index.js +3 -19
- package/lib/network/index.js +12 -17
- package/lib/runes/index.js +1 -17
- package/lib/runes/rund_id.js +8 -13
- package/lib/runes/varint.js +6 -12
- package/lib/transaction/index.js +3 -19
- package/lib/transaction/inscription-utxo.js +45 -38
- package/lib/transaction/transaction.js +134 -139
- package/lib/transaction/utxo.js +13 -18
- package/lib/tx-helpers/index.js +8 -18
- package/lib/tx-helpers/send-atomicals-ft.js +45 -60
- package/lib/tx-helpers/send-atomicals-nft.js +29 -44
- package/lib/tx-helpers/send-btc.js +53 -71
- package/lib/tx-helpers/send-inscription.js +32 -47
- package/lib/tx-helpers/send-inscriptions.js +28 -43
- package/lib/tx-helpers/send-runes.js +83 -97
- package/lib/tx-helpers/split-inscription-utxo.js +39 -54
- package/lib/types.js +2 -5
- package/lib/utils.js +16 -29
- package/lib/wallet/abstract-wallet.js +1 -2
- package/lib/wallet/estimate-wallet.js +130 -147
- package/lib/wallet/index.js +3 -19
- package/lib/wallet/local-wallet.js +134 -150
- package/package.json +103 -95
- package/lib/address/index.d.ts +0 -37
- package/lib/bitcoin-core.d.ts +0 -5
- package/lib/constants.d.ts +0 -1
- package/lib/error.d.ts +0 -20
- package/lib/index.d.ts +0 -14
- package/lib/keyring/hd-keyring.d.ts +0 -50
- package/lib/keyring/index.d.ts +0 -4
- package/lib/keyring/interfaces/SimpleKeyringOptions.d.ts +0 -53
- package/lib/keyring/keystone-keyring.d.ts +0 -82
- package/lib/keyring/simple-keyring.d.ts +0 -11
- package/lib/message/bip322-simple.d.ts +0 -19
- package/lib/message/deterministic-ecdsa.d.ts +0 -2
- package/lib/message/ecdsa.d.ts +0 -3
- package/lib/message/index.d.ts +0 -3
- package/lib/network/index.d.ts +0 -14
- package/lib/runes/index.d.ts +0 -1
- package/lib/runes/rund_id.d.ts +0 -11
- package/lib/runes/varint.d.ts +0 -15
- package/lib/src/address/index.d.ts +0 -37
- package/lib/src/bitcoin-core.d.ts +0 -5
- package/lib/src/constants.d.ts +0 -1
- package/lib/src/error.d.ts +0 -20
- package/lib/src/index.d.ts +0 -14
- package/lib/src/keyring/hd-keyring.d.ts +0 -50
- package/lib/src/keyring/index.d.ts +0 -4
- package/lib/src/keyring/interfaces/SimpleKeyringOptions.d.ts +0 -53
- package/lib/src/keyring/keystone-keyring.d.ts +0 -82
- package/lib/src/keyring/simple-keyring.d.ts +0 -11
- package/lib/src/message/bip322-simple.d.ts +0 -19
- package/lib/src/message/deterministic-ecdsa.d.ts +0 -2
- package/lib/src/message/ecdsa.d.ts +0 -3
- package/lib/src/message/index.d.ts +0 -3
- package/lib/src/network/index.d.ts +0 -14
- package/lib/src/runes/index.d.ts +0 -1
- package/lib/src/runes/rund_id.d.ts +0 -11
- package/lib/src/runes/varint.d.ts +0 -15
- package/lib/src/transaction/index.d.ts +0 -3
- package/lib/src/transaction/inscription-utxo.d.ts +0 -33
- package/lib/src/transaction/transaction.d.ts +0 -52
- package/lib/src/transaction/utxo.d.ts +0 -35
- package/lib/src/tx-helpers/index.d.ts +0 -8
- package/lib/src/tx-helpers/send-atomicals-ft.d.ts +0 -16
- package/lib/src/tx-helpers/send-atomicals-nft.d.ts +0 -14
- package/lib/src/tx-helpers/send-btc.d.ts +0 -28
- package/lib/src/tx-helpers/send-inscription.d.ts +0 -16
- package/lib/src/tx-helpers/send-inscriptions.d.ts +0 -14
- package/lib/src/tx-helpers/send-runes.d.ts +0 -19
- package/lib/src/tx-helpers/split-inscription-utxo.d.ts +0 -15
- package/lib/src/types.d.ts +0 -59
- package/lib/src/utils.d.ts +0 -23
- package/lib/src/wallet/abstract-wallet.d.ts +0 -6
- package/lib/src/wallet/estimate-wallet.d.ts +0 -23
- package/lib/src/wallet/index.d.ts +0 -3
- package/lib/src/wallet/local-wallet.d.ts +0 -23
- package/lib/test/address/address.test.d.ts +0 -1
- package/lib/test/keyring/hd-keyring.test.d.ts +0 -1
- package/lib/test/keyring/keystone-keyring.test.d.ts +0 -1
- package/lib/test/keyring/simple-keyring.test.d.ts +0 -1
- package/lib/test/message/message.test.d.ts +0 -1
- package/lib/test/runes/varint.test.d.ts +0 -1
- package/lib/test/transaction/transaction.test.d.ts +0 -1
- package/lib/test/transaction/utxo.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-atomicals-ft.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-atomicals-nft.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-btc.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-inscription.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-inscriptions.test.d.ts +0 -1
- package/lib/test/tx-helpers/send-runes.test.d.ts +0 -1
- package/lib/test/tx-helpers/split-inscription-utxo.test.d.ts +0 -1
- package/lib/test/tx-helpers/utils.d.ts +0 -217
- package/lib/test/utils.d.ts +0 -4
- package/lib/test/wallet/local-wallet.test.d.ts +0 -1
- package/lib/transaction/index.d.ts +0 -3
- package/lib/transaction/inscription-utxo.d.ts +0 -33
- package/lib/transaction/transaction.d.ts +0 -52
- package/lib/transaction/utxo.d.ts +0 -35
- package/lib/tx-helpers/index.d.ts +0 -8
- package/lib/tx-helpers/send-atomicals-ft.d.ts +0 -16
- package/lib/tx-helpers/send-atomicals-nft.d.ts +0 -14
- package/lib/tx-helpers/send-btc.d.ts +0 -28
- package/lib/tx-helpers/send-inscription.d.ts +0 -16
- package/lib/tx-helpers/send-inscriptions.d.ts +0 -14
- package/lib/tx-helpers/send-runes.d.ts +0 -19
- package/lib/tx-helpers/split-inscription-utxo.d.ts +0 -15
- package/lib/types.d.ts +0 -59
- package/lib/utils.d.ts +0 -23
- package/lib/wallet/abstract-wallet.d.ts +0 -6
- package/lib/wallet/estimate-wallet.d.ts +0 -23
- package/lib/wallet/index.d.ts +0 -3
- package/lib/wallet/local-wallet.d.ts +0 -23
|
@@ -1,26 +1,15 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
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
|
|
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
|
|
38
|
+
return signMessageOfDeterministicECDSA(keyPair, text);
|
|
52
39
|
}
|
|
53
40
|
exportAccount(publicKey) {
|
|
54
41
|
const wallet = this._getWalletForAccount(publicKey);
|
|
55
|
-
return wallet.privateKey
|
|
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 (
|
|
61
|
-
const signer =
|
|
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,76 +1,40 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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.KeystoneKeyring = void 0;
|
|
39
|
-
const keystone_sdk_1 = __importStar(require("@keystonehq/keystone-sdk"));
|
|
40
|
-
const utils_1 = require("@keystonehq/keystone-sdk/dist/utils");
|
|
41
|
-
const bitcoinjs_lib_1 = require("bitcoinjs-lib");
|
|
42
|
-
const bitcore_lib_1 = __importDefault(require("bitcore-lib"));
|
|
43
|
-
const message_1 = require("../message");
|
|
44
|
-
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';
|
|
45
7
|
const type = 'Keystone';
|
|
46
|
-
class KeystoneKeyring extends
|
|
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';
|
|
47
19
|
constructor(opts) {
|
|
48
|
-
super(
|
|
49
|
-
this.type = type;
|
|
50
|
-
this.mfp = '';
|
|
51
|
-
this.keys = [];
|
|
52
|
-
this.activeIndexes = [];
|
|
53
|
-
this.root = null;
|
|
54
|
-
this.page = 0;
|
|
55
|
-
this.perPage = 5;
|
|
56
|
-
this.origin = 'UniSat Wallet';
|
|
20
|
+
super(opts?.network || networks.bitcoin);
|
|
57
21
|
if (opts) {
|
|
58
22
|
this.deserialize(opts);
|
|
59
23
|
}
|
|
60
24
|
}
|
|
61
|
-
initFromUR(type, cbor) {
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
})
|
|
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
|
+
}))
|
|
74
38
|
});
|
|
75
39
|
}
|
|
76
40
|
getHardenedPath(hdPath) {
|
|
@@ -83,27 +47,25 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
|
|
|
83
47
|
if (!key) {
|
|
84
48
|
throw new Error('Invalid path');
|
|
85
49
|
}
|
|
86
|
-
return new
|
|
50
|
+
return new bitcore.HDPublicKey(key.extendedPublicKey);
|
|
87
51
|
}
|
|
88
52
|
getDefaultHdPath() {
|
|
89
53
|
return "m/44'/0'/0'/0";
|
|
90
54
|
}
|
|
91
55
|
initRoot() {
|
|
92
|
-
|
|
93
|
-
this.root = this.getHDPublicKey((_a = this.hdPath) !== null && _a !== void 0 ? _a : this.getDefaultHdPath());
|
|
56
|
+
this.root = this.getHDPublicKey(this.hdPath ?? this.getDefaultHdPath());
|
|
94
57
|
}
|
|
95
58
|
deserialize(opts) {
|
|
96
|
-
var _a;
|
|
97
59
|
this.mfp = opts.mfp;
|
|
98
60
|
this.keys = opts.keys;
|
|
99
|
-
this.hdPath =
|
|
61
|
+
this.hdPath = opts.hdPath ?? this.getDefaultHdPath();
|
|
100
62
|
this.activeIndexes = opts.activeIndexes ? [...opts.activeIndexes] : [];
|
|
101
63
|
this.initRoot();
|
|
102
64
|
if (opts.hdPath !== null &&
|
|
103
65
|
opts.hdPath !== undefined &&
|
|
104
66
|
opts.hdPath.length >= 13 &&
|
|
105
67
|
opts.hdPath[opts.hdPath.length - 1] === '1') {
|
|
106
|
-
this.root = this.root
|
|
68
|
+
this.root = this.root?.derive(`m/1`);
|
|
107
69
|
}
|
|
108
70
|
}
|
|
109
71
|
serialize() {
|
|
@@ -119,36 +81,34 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
|
|
|
119
81
|
let i = 0;
|
|
120
82
|
const pubkeys = [];
|
|
121
83
|
while (count) {
|
|
122
|
-
if (this.activeIndexes
|
|
84
|
+
if (this.activeIndexes?.includes(i)) {
|
|
123
85
|
i++;
|
|
124
86
|
}
|
|
125
87
|
else {
|
|
126
88
|
const w = this.getWalletByIndex(i);
|
|
127
89
|
pubkeys.push(w.publicKey);
|
|
128
|
-
this.activeIndexes
|
|
90
|
+
this.activeIndexes?.push(i);
|
|
129
91
|
count--;
|
|
130
92
|
}
|
|
131
93
|
}
|
|
132
94
|
return pubkeys;
|
|
133
95
|
}
|
|
134
|
-
addChangeAddressAccounts(numberOfAccounts = 1) {
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
i++;
|
|
142
|
-
}
|
|
143
|
-
else {
|
|
144
|
-
const w = this.getChangeAddressWalletByIndex(i);
|
|
145
|
-
pubkeys.push(w.publicKey);
|
|
146
|
-
this.activeIndexes.push(i);
|
|
147
|
-
count--;
|
|
148
|
-
}
|
|
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++;
|
|
149
103
|
}
|
|
150
|
-
|
|
151
|
-
|
|
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);
|
|
152
112
|
}
|
|
153
113
|
getAccounts() {
|
|
154
114
|
if (this.hdPath !== null &&
|
|
@@ -162,27 +122,23 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
|
|
|
162
122
|
}
|
|
163
123
|
return this.activeIndexes.map((i) => this.getWalletByIndex(i).publicKey);
|
|
164
124
|
}
|
|
165
|
-
getAccounts2() {
|
|
166
|
-
return
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
};
|
|
174
|
-
});
|
|
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
|
+
};
|
|
175
133
|
});
|
|
176
134
|
}
|
|
177
|
-
getAccountsWithBrand() {
|
|
178
|
-
return
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
};
|
|
185
|
-
});
|
|
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
|
+
};
|
|
186
142
|
});
|
|
187
143
|
}
|
|
188
144
|
getWalletByIndex(index) {
|
|
@@ -237,24 +193,22 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
|
|
|
237
193
|
}
|
|
238
194
|
return accounts;
|
|
239
195
|
}
|
|
240
|
-
getPage(increment) {
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
return accounts;
|
|
257
|
-
});
|
|
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;
|
|
258
212
|
}
|
|
259
213
|
activeAccounts(indexes) {
|
|
260
214
|
const accounts = [];
|
|
@@ -273,9 +227,8 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
|
|
|
273
227
|
this.activeAccounts(this.activeIndexes);
|
|
274
228
|
}
|
|
275
229
|
changeChangeAddressHdPath(hdPath) {
|
|
276
|
-
var _a;
|
|
277
230
|
this.hdPath = hdPath;
|
|
278
|
-
this.root = this.getHDPublicKey(
|
|
231
|
+
this.root = this.getHDPublicKey(this.hdPath ?? this.getDefaultHdPath());
|
|
279
232
|
this.root = this.root.derive(`m/1`);
|
|
280
233
|
this.activeIndexes = [];
|
|
281
234
|
return [];
|
|
@@ -290,88 +243,76 @@ class KeystoneKeyring extends SimpleKeyringOptions_1.IKeyringBase {
|
|
|
290
243
|
const child = root.derive(`m/1/${index}`);
|
|
291
244
|
return child.publicKey.toString();
|
|
292
245
|
}
|
|
293
|
-
genSignPsbtUr(psbtHex) {
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
origin: this.origin
|
|
298
|
-
});
|
|
299
|
-
const ur = keystoneSDK.btc.generatePSBT(psbt.data.toBuffer());
|
|
300
|
-
return {
|
|
301
|
-
type: ur.type,
|
|
302
|
-
cbor: ur.cbor.toString('hex')
|
|
303
|
-
};
|
|
246
|
+
async genSignPsbtUr(psbtHex) {
|
|
247
|
+
const psbt = Psbt.fromHex(psbtHex);
|
|
248
|
+
const keystoneSDK = new KeystoneSDK({
|
|
249
|
+
origin: this.origin
|
|
304
250
|
});
|
|
251
|
+
const ur = keystoneSDK.btc.generatePSBT(psbt.data.toBuffer());
|
|
252
|
+
return {
|
|
253
|
+
type: ur.type,
|
|
254
|
+
cbor: ur.cbor.toString('hex')
|
|
255
|
+
};
|
|
305
256
|
}
|
|
306
|
-
parseSignPsbtUr(type, cbor) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
origin: this.origin
|
|
310
|
-
});
|
|
311
|
-
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
|
|
312
260
|
});
|
|
261
|
+
return keystoneSDK.btc.parsePSBT(new UR(Buffer.from(cbor, 'hex'), type));
|
|
313
262
|
}
|
|
314
|
-
genSignMsgUr(publicKey, text) {
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
}
|
|
330
|
-
});
|
|
331
|
-
}
|
|
332
|
-
else {
|
|
333
|
-
i = this.activeIndexes.find((i) => this.getWalletByIndex(i).publicKey === publicKey);
|
|
334
|
-
}
|
|
335
|
-
if (i === undefined) {
|
|
336
|
-
throw new Error('publicKey not found');
|
|
337
|
-
}
|
|
338
|
-
const requestId = utils_1.uuid.v4();
|
|
339
|
-
const ur = keystoneSDK.btc.generateSignRequest({
|
|
340
|
-
requestId,
|
|
341
|
-
signData: Buffer.from(text).toString('hex'),
|
|
342
|
-
dataType: keystone_sdk_1.KeystoneBitcoinSDK.DataType.message,
|
|
343
|
-
accounts: [
|
|
344
|
-
{
|
|
345
|
-
path: `${this.hdPath}/${i}`,
|
|
346
|
-
xfp: this.mfp
|
|
347
|
-
}
|
|
348
|
-
],
|
|
349
|
-
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
|
+
}
|
|
350
278
|
});
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
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
|
|
356
298
|
});
|
|
299
|
+
return {
|
|
300
|
+
requestId,
|
|
301
|
+
type: ur.type,
|
|
302
|
+
cbor: ur.cbor.toString('hex')
|
|
303
|
+
};
|
|
357
304
|
}
|
|
358
|
-
parseSignMsgUr(type, cbor) {
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
origin: this.origin
|
|
362
|
-
});
|
|
363
|
-
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
|
|
364
308
|
});
|
|
309
|
+
return keystoneSDK.btc.parseSignature(new UR(Buffer.from(cbor, 'hex'), type));
|
|
365
310
|
}
|
|
366
311
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
367
312
|
signMessage(publicKey, text) {
|
|
368
313
|
return 'Signing Message with Keystone should use genSignMsgUr and parseSignMsgUr';
|
|
369
314
|
}
|
|
370
|
-
verifyMessage(publicKey, text, sig) {
|
|
371
|
-
return
|
|
372
|
-
return (0, message_1.verifyMessageOfECDSA)(publicKey, text, sig);
|
|
373
|
-
});
|
|
315
|
+
async verifyMessage(publicKey, text, sig) {
|
|
316
|
+
return verifyMessageOfECDSA(publicKey, text, sig);
|
|
374
317
|
}
|
|
375
318
|
}
|
|
376
|
-
exports.KeystoneKeyring = KeystoneKeyring;
|
|
377
|
-
KeystoneKeyring.type = type;
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
const bitcoin_core_1 = require("../bitcoin-core");
|
|
6
|
-
const SimpleKeyringOptions_1 = require("./interfaces/SimpleKeyringOptions");
|
|
7
|
-
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';
|
|
8
5
|
const type = 'Simple Key Pair';
|
|
9
|
-
class SimpleKeyring extends
|
|
6
|
+
export class SimpleKeyring extends IKeyringBase {
|
|
7
|
+
static type = type;
|
|
8
|
+
type = type;
|
|
10
9
|
constructor(opts) {
|
|
11
|
-
super(
|
|
12
|
-
this.type = type;
|
|
10
|
+
super(opts?.network || networks.bitcoin);
|
|
13
11
|
if (opts && opts.privateKeys) {
|
|
14
12
|
this.deserialize(opts);
|
|
15
13
|
}
|
|
@@ -32,15 +30,15 @@ class SimpleKeyring extends SimpleKeyringOptions_1.IKeyringBase {
|
|
|
32
30
|
}
|
|
33
31
|
else {
|
|
34
32
|
// base58
|
|
35
|
-
buf = Buffer.from(
|
|
33
|
+
buf = Buffer.from(bs58check.default.decode(key).slice(1, 33));
|
|
36
34
|
}
|
|
37
|
-
return
|
|
35
|
+
return ECPair.fromPrivateKey(buf);
|
|
38
36
|
});
|
|
39
37
|
}
|
|
40
38
|
addAccounts(n = 1) {
|
|
41
39
|
const newWallets = [];
|
|
42
40
|
for (let i = 0; i < n; i++) {
|
|
43
|
-
newWallets.push(
|
|
41
|
+
newWallets.push(ECPair.makeRandom());
|
|
44
42
|
}
|
|
45
43
|
this.wallets = this.wallets.concat(newWallets);
|
|
46
44
|
return newWallets.map(({ publicKey }) => publicKey.toString('hex'));
|
|
@@ -49,10 +47,8 @@ class SimpleKeyring extends SimpleKeyringOptions_1.IKeyringBase {
|
|
|
49
47
|
return this.wallets.map(({ publicKey }) => publicKey.toString('hex'));
|
|
50
48
|
}
|
|
51
49
|
}
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
function verifySignData(publicKey, hash, type, signature) {
|
|
55
|
-
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'));
|
|
56
52
|
if (type === 'ecdsa') {
|
|
57
53
|
return keyPair.verify(Buffer.from(hash, 'hex'), Buffer.from(signature, 'hex'));
|
|
58
54
|
}
|
|
@@ -63,4 +59,3 @@ function verifySignData(publicKey, hash, type, signature) {
|
|
|
63
59
|
throw new Error('Not support type');
|
|
64
60
|
}
|
|
65
61
|
}
|
|
66
|
-
exports.verifySignData = verifySignData;
|