@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.
- package/es/bundle.js +1 -1
- package/es/bundle.js.LICENSE.txt +2 -2
- package/lib/address/index.js +50 -94
- package/lib/bitcoin-core.js +7 -47
- package/lib/constants.js +1 -4
- package/lib/error.js +6 -10
- package/lib/index.js +14 -53
- package/lib/keyring/hd-keyring.js +40 -89
- package/lib/keyring/index.js +4 -20
- package/lib/keyring/interfaces/SimpleKeyringOptions.js +16 -31
- package/lib/keyring/keystone-keyring.js +142 -211
- package/lib/keyring/simple-keyring.js +13 -18
- package/lib/message/bip322-simple.js +31 -81
- package/lib/message/deterministic-ecdsa.js +7 -43
- package/lib/message/ecdsa.js +10 -17
- 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 +5 -10
- package/lib/runes/varint.js +6 -12
- package/lib/transaction/index.js +3 -19
- package/lib/transaction/inscription-utxo.js +9 -10
- package/lib/transaction/transaction.js +137 -142
- package/lib/transaction/utxo.js +13 -18
- package/lib/tx-helpers/index.js +8 -18
- package/lib/tx-helpers/send-atomicals-ft.js +45 -59
- package/lib/tx-helpers/send-atomicals-nft.js +29 -43
- package/lib/tx-helpers/send-btc.js +53 -70
- package/lib/tx-helpers/send-inscription.js +32 -46
- package/lib/tx-helpers/send-inscriptions.js +28 -42
- package/lib/tx-helpers/send-runes.js +83 -100
- package/lib/tx-helpers/split-inscription-utxo.js +39 -53
- 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 +21 -12
- package/lib/address/index.d.ts +0 -36
- 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 -52
- 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 -14
- package/lib/src/address/index.d.ts +0 -36
- 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 -52
- 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 -14
- 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 -51
- 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 -51
- 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,86 +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 () {
|
|
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
|
|
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(
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
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
|
|
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
|
-
|
|
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 =
|
|
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
|
|
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
|
|
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
|
|
90
|
+
this.activeIndexes?.push(i);
|
|
139
91
|
count--;
|
|
140
92
|
}
|
|
141
93
|
}
|
|
142
94
|
return pubkeys;
|
|
143
95
|
}
|
|
144
|
-
addChangeAddressAccounts() {
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
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
|
-
|
|
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
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
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
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
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(
|
|
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
|
-
|
|
305
|
-
|
|
306
|
-
|
|
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
|
-
|
|
318
|
-
|
|
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
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
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
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
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
|
-
|
|
370
|
-
|
|
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
|
|
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
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
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
|
|
6
|
+
export class SimpleKeyring extends IKeyringBase {
|
|
7
|
+
static type = type;
|
|
8
|
+
type = type;
|
|
11
9
|
constructor(opts) {
|
|
12
|
-
super(
|
|
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(
|
|
33
|
+
buf = Buffer.from(bs58check.default.decode(key).slice(1, 33));
|
|
37
34
|
}
|
|
38
|
-
return
|
|
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(
|
|
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
|
-
|
|
54
|
-
|
|
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
|
}
|