@btc-vision/wallet-sdk 1.0.5 → 1.0.7
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/lib/address/index.d.ts +36 -0
- package/lib/bitcoin-core.d.ts +5 -0
- package/lib/constants.d.ts +1 -0
- package/lib/error.d.ts +20 -0
- package/lib/index.d.ts +14 -0
- package/lib/keyring/hd-keyring.d.ts +50 -0
- package/lib/keyring/index.d.ts +4 -0
- package/lib/keyring/interfaces/SimpleKeyringOptions.d.ts +52 -0
- package/lib/keyring/interfaces/SimpleKeyringOptions.js +2 -2
- package/lib/keyring/keystone-keyring.d.ts +82 -0
- package/lib/keyring/keystone-keyring.js +1 -1
- package/lib/keyring/simple-keyring.d.ts +11 -0
- package/lib/message/bip322-simple.d.ts +19 -0
- package/lib/message/bip322-simple.js +6 -3
- package/lib/message/deterministic-ecdsa.d.ts +2 -0
- package/lib/message/deterministic-ecdsa.js +1 -1
- package/lib/message/ecdsa.d.ts +3 -0
- package/lib/message/index.d.ts +3 -0
- package/lib/network/index.d.ts +14 -0
- package/lib/runes/index.d.ts +1 -0
- package/lib/runes/rund_id.d.ts +11 -0
- package/lib/runes/varint.d.ts +14 -0
- package/lib/transaction/index.d.ts +3 -0
- package/lib/transaction/inscription-utxo.d.ts +33 -0
- package/lib/transaction/transaction.d.ts +51 -0
- package/lib/transaction/utxo.d.ts +35 -0
- package/lib/tx-helpers/index.d.ts +8 -0
- package/lib/tx-helpers/send-atomicals-ft.d.ts +16 -0
- package/lib/tx-helpers/send-atomicals-nft.d.ts +14 -0
- package/lib/tx-helpers/send-btc.d.ts +28 -0
- package/lib/tx-helpers/send-inscription.d.ts +16 -0
- package/lib/tx-helpers/send-inscriptions.d.ts +14 -0
- package/lib/tx-helpers/send-runes.d.ts +19 -0
- package/lib/tx-helpers/split-inscription-utxo.d.ts +15 -0
- package/lib/types.d.ts +59 -0
- package/lib/utils.d.ts +23 -0
- package/lib/wallet/abstract-wallet.d.ts +6 -0
- package/lib/wallet/estimate-wallet.d.ts +23 -0
- package/lib/wallet/estimate-wallet.js +3 -3
- package/lib/wallet/index.d.ts +3 -0
- package/lib/wallet/local-wallet.d.ts +23 -0
- package/lib/wallet/local-wallet.js +3 -3
- package/package.json +1 -1
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as bitcoin from '@btc-vision/bitcoin';
|
|
2
|
+
import { NetworkType } from '../network';
|
|
3
|
+
import { AddressType } from '../types';
|
|
4
|
+
/**
|
|
5
|
+
* Convert public key to bitcoin payment object.
|
|
6
|
+
*/
|
|
7
|
+
export declare function publicKeyToPayment(publicKey: string, type: AddressType, networkType: NetworkType): bitcoin.P2PKHPayment | bitcoin.P2WPKHPayment | bitcoin.P2TRPayment | bitcoin.P2SHPayment | null | undefined;
|
|
8
|
+
/**
|
|
9
|
+
* Convert public key to bitcoin address.
|
|
10
|
+
*/
|
|
11
|
+
export declare function publicKeyToAddress(publicKey: string, type: AddressType, networkType: NetworkType): string;
|
|
12
|
+
/**
|
|
13
|
+
* Convert public key to bitcoin scriptPk.
|
|
14
|
+
*/
|
|
15
|
+
export declare function publicKeyToScriptPk(publicKey: string, type: AddressType, networkType: NetworkType): string | undefined;
|
|
16
|
+
/**
|
|
17
|
+
* Convert bitcoin address to scriptPk.
|
|
18
|
+
*/
|
|
19
|
+
export declare function addressToScriptPk(address: string, networkType: NetworkType): Buffer<ArrayBufferLike>;
|
|
20
|
+
/**
|
|
21
|
+
* Check if the address is valid.
|
|
22
|
+
*/
|
|
23
|
+
export declare function isValidAddress(address: string, networkType?: NetworkType): boolean;
|
|
24
|
+
export declare function decodeAddress(address: string): {
|
|
25
|
+
networkType: NetworkType;
|
|
26
|
+
addressType: AddressType;
|
|
27
|
+
dust: number;
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* Get address type.
|
|
31
|
+
*/
|
|
32
|
+
export declare function getAddressType(address: string, networkType?: NetworkType): AddressType;
|
|
33
|
+
/**
|
|
34
|
+
* Convert scriptPk to address.
|
|
35
|
+
*/
|
|
36
|
+
export declare function scriptPkToAddress(scriptPk: string | Buffer, networkType?: NetworkType): string;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export declare const UTXO_DUST = 546;
|
package/lib/error.d.ts
ADDED
|
@@ -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
|
+
}
|
package/lib/index.d.ts
ADDED
|
@@ -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 | null;
|
|
8
|
+
xpriv: string | null;
|
|
9
|
+
passphrase: string | null;
|
|
10
|
+
hdPath: string;
|
|
11
|
+
root: bitcore.HDPrivateKey | null;
|
|
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 | null;
|
|
49
|
+
private _addressFromIndex;
|
|
50
|
+
}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { Network, Psbt } from '@btc-vision/bitcoin';
|
|
2
|
+
import { ECPairInterface } from 'ecpair';
|
|
3
|
+
import { EventEmitter } from 'events';
|
|
4
|
+
interface BaseKeyringOptions {
|
|
5
|
+
readonly network?: Network;
|
|
6
|
+
}
|
|
7
|
+
export interface SimpleKeyringOptions extends BaseKeyringOptions {
|
|
8
|
+
readonly privateKeys?: string[];
|
|
9
|
+
}
|
|
10
|
+
export interface DeserializeOptionBase extends BaseKeyringOptions {
|
|
11
|
+
readonly hdPath?: string;
|
|
12
|
+
readonly activeIndexes?: number[];
|
|
13
|
+
}
|
|
14
|
+
export interface DeserializeOption extends DeserializeOptionBase {
|
|
15
|
+
readonly mnemonic?: string | null;
|
|
16
|
+
readonly xpriv?: string | null;
|
|
17
|
+
readonly passphrase?: string | null;
|
|
18
|
+
}
|
|
19
|
+
export interface KeystoneKey {
|
|
20
|
+
readonly path: string;
|
|
21
|
+
readonly extendedPublicKey: string;
|
|
22
|
+
}
|
|
23
|
+
export interface DeserializeOptionKeystone extends DeserializeOptionBase {
|
|
24
|
+
readonly mfp: string;
|
|
25
|
+
readonly keys: KeystoneKey[];
|
|
26
|
+
}
|
|
27
|
+
export type KeyringOptions = SimpleKeyringOptions | DeserializeOption | DeserializeOptionKeystone;
|
|
28
|
+
export declare abstract class IKeyringBase<T extends BaseKeyringOptions> extends EventEmitter {
|
|
29
|
+
readonly network: Network;
|
|
30
|
+
static type: string;
|
|
31
|
+
type: string;
|
|
32
|
+
protected wallets: ECPairInterface[];
|
|
33
|
+
protected constructor(network?: Network);
|
|
34
|
+
abstract serialize(): T;
|
|
35
|
+
abstract addAccounts(numberOfAccounts: number): string[];
|
|
36
|
+
abstract deserialize(opts?: T): unknown;
|
|
37
|
+
removeAccount(publicKey: string): void;
|
|
38
|
+
verifyMessage(publicKey: string, text: string, sig: string): Promise<boolean>;
|
|
39
|
+
signData(publicKey: string, data: string, type?: 'ecdsa' | 'schnorr'): string;
|
|
40
|
+
abstract getAccounts(): string[];
|
|
41
|
+
signMessage(publicKey: string, message: string | Buffer): string;
|
|
42
|
+
exportAccount(publicKey: string): string | undefined;
|
|
43
|
+
signTransaction(psbt: Psbt, inputs: {
|
|
44
|
+
index: number;
|
|
45
|
+
publicKey: string;
|
|
46
|
+
sighashTypes?: number[];
|
|
47
|
+
disableTweakSigner?: boolean;
|
|
48
|
+
}[], opts?: any): Psbt;
|
|
49
|
+
private _getWalletForAccount;
|
|
50
|
+
private _getPrivateKeyFor;
|
|
51
|
+
}
|
|
52
|
+
export {};
|
|
@@ -33,9 +33,9 @@ export class IKeyringBase extends EventEmitter {
|
|
|
33
33
|
throw new Error('Not support type');
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
|
-
signMessage(publicKey,
|
|
36
|
+
signMessage(publicKey, message) {
|
|
37
37
|
const keyPair = this._getPrivateKeyFor(publicKey);
|
|
38
|
-
return signMessageOfDeterministicECDSA(keyPair,
|
|
38
|
+
return signMessageOfDeterministicECDSA(keyPair, message);
|
|
39
39
|
}
|
|
40
40
|
exportAccount(publicKey) {
|
|
41
41
|
const wallet = this._getWalletForAccount(publicKey);
|
|
@@ -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 | undefined;
|
|
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<string[]>;
|
|
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): never[];
|
|
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, message: string | Buffer): string;
|
|
80
|
+
verifyMessage(publicKey: string, text: string, sig: string): Promise<boolean>;
|
|
81
|
+
}
|
|
82
|
+
export {};
|
|
@@ -309,7 +309,7 @@ export class KeystoneKeyring extends IKeyringBase {
|
|
|
309
309
|
return keystoneSDK.btc.parseSignature(new UR(Buffer.from(cbor, 'hex'), type));
|
|
310
310
|
}
|
|
311
311
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
312
|
-
signMessage(publicKey,
|
|
312
|
+
signMessage(publicKey, message) {
|
|
313
313
|
return 'Signing Message with Keystone should use genSignMsgUr and parseSignMsgUr';
|
|
314
314
|
}
|
|
315
315
|
async verifyMessage(publicKey, text, sig) {
|
|
@@ -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 * as bitcoin from '@btc-vision/bitcoin';
|
|
2
|
+
import { NetworkType } from '../network';
|
|
3
|
+
import { AbstractWallet } from '../wallet';
|
|
4
|
+
export declare function genPsbtOfBIP322Simple({ message, address, networkType }: {
|
|
5
|
+
message: string | Buffer;
|
|
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 | Buffer;
|
|
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;
|
|
@@ -8,7 +8,8 @@ function bip0322_hash(message) {
|
|
|
8
8
|
const { sha256 } = bitcoin.crypto;
|
|
9
9
|
const tag = 'BIP0322-signed-message';
|
|
10
10
|
const tagHash = sha256(Buffer.from(tag));
|
|
11
|
-
const
|
|
11
|
+
const messageBuffer = typeof message === 'string' ? Buffer.from(message, 'utf8') : message;
|
|
12
|
+
const result = sha256(Buffer.concat([tagHash, tagHash, messageBuffer]));
|
|
12
13
|
return result.toString('hex');
|
|
13
14
|
}
|
|
14
15
|
export function genPsbtOfBIP322Simple({ message, address, networkType }) {
|
|
@@ -43,9 +44,11 @@ export function genPsbtOfBIP322Simple({ message, address, networkType }) {
|
|
|
43
44
|
export function getSignatureFromPsbtOfBIP322Simple(psbt) {
|
|
44
45
|
const txToSign = psbt.extractTransaction();
|
|
45
46
|
function encodeVarString(b) {
|
|
46
|
-
|
|
47
|
+
const { buffer: vb } = encode(b.length);
|
|
48
|
+
return Buffer.concat([Buffer.from(vb), b]);
|
|
47
49
|
}
|
|
48
|
-
const
|
|
50
|
+
const { buffer: varintBuf } = encode(txToSign.ins[0].witness.length);
|
|
51
|
+
const len = Buffer.from(varintBuf);
|
|
49
52
|
const result = Buffer.concat([len, ...txToSign.ins[0].witness.map((w) => encodeVarString(w))]);
|
|
50
53
|
const signature = result.toString('base64');
|
|
51
54
|
return signature;
|
|
@@ -30,7 +30,7 @@ function varintBufNum(n) {
|
|
|
30
30
|
}
|
|
31
31
|
function magicHash(message) {
|
|
32
32
|
const prefix1 = varintBufNum(MAGIC_BYTES.length);
|
|
33
|
-
const messageBuffer = Buffer.from(message);
|
|
33
|
+
const messageBuffer = typeof message === 'string' ? Buffer.from(message) : message;
|
|
34
34
|
const prefix2 = varintBufNum(messageBuffer.length);
|
|
35
35
|
const buf = Buffer.concat([prefix1, MAGIC_BYTES, prefix2, messageBuffer]);
|
|
36
36
|
return bitcoin.crypto.hash256(buf);
|
|
@@ -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 @btc-vision/bitcoin network.
|
|
9
|
+
*/
|
|
10
|
+
export declare function toPsbtNetwork(networkType: NetworkType): bitcoin.networks.Network;
|
|
11
|
+
/**
|
|
12
|
+
* Convert @btc-vision/bitcoin network to network type.
|
|
13
|
+
*/
|
|
14
|
+
export declare function toNetworkType(network: bitcoin.Network): NetworkType;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './varint';
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
declare function try_decode(buf: any): (string | number)[];
|
|
2
|
+
declare function encodeToVec(n: any, v: any): void;
|
|
3
|
+
declare function decode(buffer: any): {
|
|
4
|
+
num: string | number;
|
|
5
|
+
index: string | number;
|
|
6
|
+
};
|
|
7
|
+
declare function encode(n: any): Buffer<ArrayBuffer>;
|
|
8
|
+
export declare const varint: {
|
|
9
|
+
encode: typeof encode;
|
|
10
|
+
decode: typeof decode;
|
|
11
|
+
try_decode: typeof try_decode;
|
|
12
|
+
encodeToVec: typeof encodeToVec;
|
|
13
|
+
};
|
|
14
|
+
export {};
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { UnspentOutput } from '../types';
|
|
2
|
+
export declare class InscriptionUnit {
|
|
3
|
+
satoshis: number;
|
|
4
|
+
inscriptions: {
|
|
5
|
+
id: string;
|
|
6
|
+
outputOffset: number;
|
|
7
|
+
unitOffset: number;
|
|
8
|
+
}[];
|
|
9
|
+
constructor(satoshis: number, inscriptions: {
|
|
10
|
+
id: string;
|
|
11
|
+
outputOffset: number;
|
|
12
|
+
unitOffset: number;
|
|
13
|
+
}[]);
|
|
14
|
+
hasInscriptions(): boolean;
|
|
15
|
+
}
|
|
16
|
+
export declare class InscriptionUnspendOutput {
|
|
17
|
+
inscriptionUnits: InscriptionUnit[];
|
|
18
|
+
utxo: UnspentOutput;
|
|
19
|
+
constructor(utxo: UnspentOutput, outputValue?: number);
|
|
20
|
+
/**
|
|
21
|
+
* Get non-Ord satoshis for spending
|
|
22
|
+
*/
|
|
23
|
+
getNonInscriptionSatoshis(): number;
|
|
24
|
+
/**
|
|
25
|
+
* Get last non-ord satoshis for spending.
|
|
26
|
+
* Only the last one is available
|
|
27
|
+
* @returns
|
|
28
|
+
*/
|
|
29
|
+
getLastUnitSatoshis(): number;
|
|
30
|
+
hasInscriptions(): boolean;
|
|
31
|
+
dump(): void;
|
|
32
|
+
private split;
|
|
33
|
+
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { bitcoin } from '../bitcoin-core';
|
|
2
|
+
import { NetworkType } from '../network';
|
|
3
|
+
import { ToSignInput, UnspentOutput } from '../types';
|
|
4
|
+
interface TxOutput {
|
|
5
|
+
address?: string;
|
|
6
|
+
script?: Buffer;
|
|
7
|
+
value: number;
|
|
8
|
+
}
|
|
9
|
+
/**
|
|
10
|
+
* Transaction
|
|
11
|
+
*/
|
|
12
|
+
export declare class Transaction {
|
|
13
|
+
outputs: TxOutput[];
|
|
14
|
+
changedAddress: string;
|
|
15
|
+
private utxos;
|
|
16
|
+
private inputs;
|
|
17
|
+
private changeOutputIndex;
|
|
18
|
+
private networkType;
|
|
19
|
+
private feeRate;
|
|
20
|
+
private enableRBF;
|
|
21
|
+
private _cacheNetworkFee;
|
|
22
|
+
private _cacheBtcUtxos;
|
|
23
|
+
private _cacheToSignInputs;
|
|
24
|
+
constructor();
|
|
25
|
+
setNetworkType(network: NetworkType): void;
|
|
26
|
+
setEnableRBF(enable: boolean): void;
|
|
27
|
+
setFeeRate(feeRate: number): void;
|
|
28
|
+
setChangeAddress(address: string): void;
|
|
29
|
+
addInput(utxo: UnspentOutput): void;
|
|
30
|
+
removeLastInput(): void;
|
|
31
|
+
getTotalInput(): number;
|
|
32
|
+
getTotalOutput(): number;
|
|
33
|
+
getUnspent(): number;
|
|
34
|
+
calNetworkFee(): Promise<number>;
|
|
35
|
+
addOutput(address: string, value: number): void;
|
|
36
|
+
addOpreturn(data: Buffer[]): void;
|
|
37
|
+
addScriptOutput(script: Buffer, value: number): void;
|
|
38
|
+
getOutput(index: number): TxOutput;
|
|
39
|
+
addChangeOutput(value: number): void;
|
|
40
|
+
getChangeOutput(): TxOutput;
|
|
41
|
+
getChangeAmount(): number;
|
|
42
|
+
removeChangeOutput(): void;
|
|
43
|
+
removeRecentOutputs(count: number): void;
|
|
44
|
+
toPsbt(): bitcoin.Psbt;
|
|
45
|
+
clone(): Transaction;
|
|
46
|
+
createEstimatePsbt(): Promise<bitcoin.Psbt>;
|
|
47
|
+
addSufficientUtxosForFee(btcUtxos: UnspentOutput[], forceAsFee?: boolean): Promise<ToSignInput[]>;
|
|
48
|
+
dumpTx(psbt: any): Promise<void>;
|
|
49
|
+
private selectBtcUtxos;
|
|
50
|
+
}
|
|
51
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import { NetworkType } from '../network';
|
|
2
|
+
import { AddressType, UnspentOutput } from '../types';
|
|
3
|
+
declare function hasInscription(utxos: UnspentOutput[]): boolean;
|
|
4
|
+
declare function hasAtomicalsFT(utxos: UnspentOutput[]): boolean;
|
|
5
|
+
declare function hasAtomicalsNFT(utxos: UnspentOutput[]): boolean;
|
|
6
|
+
declare function hasAtomicals(utxos: UnspentOutput[]): boolean;
|
|
7
|
+
declare function hasAnyAssets(utxos: UnspentOutput[]): boolean;
|
|
8
|
+
/**
|
|
9
|
+
* select utxos so that the total amount of utxos is greater than or equal to targetAmount
|
|
10
|
+
* return the selected utxos and the unselected utxos
|
|
11
|
+
* @param utxos
|
|
12
|
+
* @param targetAmount
|
|
13
|
+
*/
|
|
14
|
+
declare function selectBtcUtxos(utxos: UnspentOutput[], targetAmount: number): {
|
|
15
|
+
selectedUtxos: UnspentOutput[];
|
|
16
|
+
remainingUtxos: UnspentOutput[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* return the added virtual size of the utxo
|
|
20
|
+
*/
|
|
21
|
+
declare function getAddedVirtualSize(addressType: AddressType): number;
|
|
22
|
+
export declare function getUtxoDust(addressType: AddressType): 546 | 294 | 330;
|
|
23
|
+
export declare function getAddressUtxoDust(address: string, networkType?: NetworkType): number;
|
|
24
|
+
export declare const utxoHelper: {
|
|
25
|
+
hasAtomicalsFT: typeof hasAtomicalsFT;
|
|
26
|
+
hasAtomicalsNFT: typeof hasAtomicalsNFT;
|
|
27
|
+
hasAtomicals: typeof hasAtomicals;
|
|
28
|
+
hasInscription: typeof hasInscription;
|
|
29
|
+
hasAnyAssets: typeof hasAnyAssets;
|
|
30
|
+
selectBtcUtxos: typeof selectBtcUtxos;
|
|
31
|
+
getAddedVirtualSize: typeof getAddedVirtualSize;
|
|
32
|
+
getUtxoDust: typeof getUtxoDust;
|
|
33
|
+
getAddressUtxoDust: typeof getAddressUtxoDust;
|
|
34
|
+
};
|
|
35
|
+
export {};
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { sendAtomicalsFT } from './send-atomicals-ft';
|
|
2
|
+
import { sendAtomicalsNFT } from './send-atomicals-nft';
|
|
3
|
+
import { sendAllBTC, sendBTC } from './send-btc';
|
|
4
|
+
import { sendInscription } from './send-inscription';
|
|
5
|
+
import { sendInscriptions } from './send-inscriptions';
|
|
6
|
+
import { sendRunes } from './send-runes';
|
|
7
|
+
import { splitInscriptionUtxo } from './split-inscription-utxo';
|
|
8
|
+
export { sendAllBTC, sendAtomicalsFT, sendAtomicalsNFT, sendBTC, sendInscription, sendInscriptions, sendRunes, splitInscriptionUtxo };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NetworkType } from '../network';
|
|
2
|
+
import { ToSignInput, UnspentOutput } from '../types';
|
|
3
|
+
export declare function sendAtomicalsFT(params: {
|
|
4
|
+
assetUtxos: UnspentOutput[];
|
|
5
|
+
btcUtxos: UnspentOutput[];
|
|
6
|
+
toAddress: string;
|
|
7
|
+
networkType: NetworkType;
|
|
8
|
+
changeAssetAddress: string;
|
|
9
|
+
sendAmount: number;
|
|
10
|
+
changeAddress: string;
|
|
11
|
+
feeRate: number;
|
|
12
|
+
enableRBF?: boolean;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
psbt: import("@btc-vision/bitcoin").Psbt;
|
|
15
|
+
toSignInputs: ToSignInput[];
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NetworkType } from '../network';
|
|
2
|
+
import { ToSignInput, UnspentOutput } from '../types';
|
|
3
|
+
export declare function sendAtomicalsNFT(params: {
|
|
4
|
+
assetUtxo: UnspentOutput;
|
|
5
|
+
btcUtxos: UnspentOutput[];
|
|
6
|
+
toAddress: string;
|
|
7
|
+
networkType: NetworkType;
|
|
8
|
+
changeAddress: string;
|
|
9
|
+
feeRate: number;
|
|
10
|
+
enableRBF?: boolean;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
psbt: import("@btc-vision/bitcoin").Psbt;
|
|
13
|
+
toSignInputs: ToSignInput[];
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { NetworkType } from '../network';
|
|
2
|
+
import { ToSignInput, UnspentOutput } from '../types';
|
|
3
|
+
export declare function sendBTC(params: {
|
|
4
|
+
btcUtxos: UnspentOutput[];
|
|
5
|
+
tos: {
|
|
6
|
+
address: string;
|
|
7
|
+
satoshis: number;
|
|
8
|
+
}[];
|
|
9
|
+
networkType: NetworkType;
|
|
10
|
+
changeAddress: string;
|
|
11
|
+
feeRate: number;
|
|
12
|
+
enableRBF?: boolean;
|
|
13
|
+
memo?: string;
|
|
14
|
+
memos?: string[];
|
|
15
|
+
}): Promise<{
|
|
16
|
+
psbt: import("@btc-vision/bitcoin").Psbt;
|
|
17
|
+
toSignInputs: ToSignInput[];
|
|
18
|
+
}>;
|
|
19
|
+
export declare function sendAllBTC(params: {
|
|
20
|
+
btcUtxos: UnspentOutput[];
|
|
21
|
+
toAddress: string;
|
|
22
|
+
networkType: NetworkType;
|
|
23
|
+
feeRate: number;
|
|
24
|
+
enableRBF?: boolean;
|
|
25
|
+
}): Promise<{
|
|
26
|
+
psbt: import("@btc-vision/bitcoin").Psbt;
|
|
27
|
+
toSignInputs: ToSignInput[];
|
|
28
|
+
}>;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { NetworkType } from '../network';
|
|
2
|
+
import { UnspentOutput } from '../types';
|
|
3
|
+
export declare function sendInscription({ assetUtxo, btcUtxos, toAddress, networkType, changeAddress, feeRate, outputValue, enableRBF, enableMixed }: {
|
|
4
|
+
assetUtxo: UnspentOutput;
|
|
5
|
+
btcUtxos: UnspentOutput[];
|
|
6
|
+
toAddress: string;
|
|
7
|
+
networkType: NetworkType;
|
|
8
|
+
changeAddress: string;
|
|
9
|
+
feeRate: number;
|
|
10
|
+
outputValue: number;
|
|
11
|
+
enableRBF?: boolean;
|
|
12
|
+
enableMixed?: boolean;
|
|
13
|
+
}): Promise<{
|
|
14
|
+
psbt: import("@btc-vision/bitcoin").Psbt;
|
|
15
|
+
toSignInputs: import("../types").ToSignInput[];
|
|
16
|
+
}>;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import { NetworkType } from '../network';
|
|
2
|
+
import { ToSignInput, UnspentOutput } from '../types';
|
|
3
|
+
export declare function sendInscriptions({ assetUtxos, btcUtxos, toAddress, networkType, changeAddress, feeRate, enableRBF }: {
|
|
4
|
+
assetUtxos: UnspentOutput[];
|
|
5
|
+
btcUtxos: UnspentOutput[];
|
|
6
|
+
toAddress: string;
|
|
7
|
+
networkType: NetworkType;
|
|
8
|
+
changeAddress: string;
|
|
9
|
+
feeRate: number;
|
|
10
|
+
enableRBF?: boolean;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
psbt: import("@btc-vision/bitcoin").Psbt;
|
|
13
|
+
toSignInputs: ToSignInput[];
|
|
14
|
+
}>;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { bitcoin } from '../bitcoin-core';
|
|
2
|
+
import { NetworkType } from '../network';
|
|
3
|
+
import { ToSignInput, UnspentOutput } from '../types';
|
|
4
|
+
export declare function sendRunes({ assetUtxos, btcUtxos, assetAddress, btcAddress, toAddress, networkType, runeid, runeAmount, outputValue, feeRate, enableRBF }: {
|
|
5
|
+
assetUtxos: UnspentOutput[];
|
|
6
|
+
btcUtxos: UnspentOutput[];
|
|
7
|
+
assetAddress: string;
|
|
8
|
+
btcAddress: string;
|
|
9
|
+
toAddress: string;
|
|
10
|
+
networkType: NetworkType;
|
|
11
|
+
runeid: string;
|
|
12
|
+
runeAmount: string;
|
|
13
|
+
outputValue: number;
|
|
14
|
+
feeRate: number;
|
|
15
|
+
enableRBF?: boolean;
|
|
16
|
+
}): Promise<{
|
|
17
|
+
psbt: bitcoin.Psbt;
|
|
18
|
+
toSignInputs: ToSignInput[];
|
|
19
|
+
}>;
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { NetworkType } from '../network';
|
|
2
|
+
import { ToSignInput, UnspentOutput } from '../types';
|
|
3
|
+
export declare function splitInscriptionUtxo({ btcUtxos, assetUtxo, networkType, changeAddress, feeRate, enableRBF, outputValue }: {
|
|
4
|
+
btcUtxos: UnspentOutput[];
|
|
5
|
+
assetUtxo: UnspentOutput;
|
|
6
|
+
networkType: NetworkType;
|
|
7
|
+
changeAddress: string;
|
|
8
|
+
feeRate?: number;
|
|
9
|
+
enableRBF?: boolean;
|
|
10
|
+
outputValue?: number;
|
|
11
|
+
}): Promise<{
|
|
12
|
+
psbt: import("@btc-vision/bitcoin").Psbt;
|
|
13
|
+
toSignInputs: ToSignInput[];
|
|
14
|
+
splitedCount: number;
|
|
15
|
+
}>;
|
package/lib/types.d.ts
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
interface BaseUserToSignInput {
|
|
2
|
+
index: number;
|
|
3
|
+
sighashTypes?: number[] | undefined;
|
|
4
|
+
disableTweakSigner?: boolean;
|
|
5
|
+
}
|
|
6
|
+
export interface AddressUserToSignInput extends BaseUserToSignInput {
|
|
7
|
+
address: string;
|
|
8
|
+
}
|
|
9
|
+
export interface PublicKeyUserToSignInput extends BaseUserToSignInput {
|
|
10
|
+
publicKey: string;
|
|
11
|
+
}
|
|
12
|
+
export type UserToSignInput = AddressUserToSignInput | PublicKeyUserToSignInput;
|
|
13
|
+
export interface SignPsbtOptions {
|
|
14
|
+
autoFinalized?: boolean;
|
|
15
|
+
toSignInputs?: UserToSignInput[];
|
|
16
|
+
}
|
|
17
|
+
export interface ToSignInput {
|
|
18
|
+
index: number;
|
|
19
|
+
publicKey: string;
|
|
20
|
+
sighashTypes?: number[];
|
|
21
|
+
disableTweakSigner?: boolean;
|
|
22
|
+
}
|
|
23
|
+
export interface UnspentOutput {
|
|
24
|
+
txid: string;
|
|
25
|
+
vout: number;
|
|
26
|
+
satoshis: number;
|
|
27
|
+
scriptPk: string;
|
|
28
|
+
pubkey: string;
|
|
29
|
+
addressType: AddressType;
|
|
30
|
+
inscriptions: {
|
|
31
|
+
inscriptionId: string;
|
|
32
|
+
inscriptionNumber?: number;
|
|
33
|
+
offset: number;
|
|
34
|
+
}[];
|
|
35
|
+
atomicals: {
|
|
36
|
+
atomicalId: string;
|
|
37
|
+
atomicalNumber: number;
|
|
38
|
+
type: 'FT' | 'NFT';
|
|
39
|
+
ticker?: string;
|
|
40
|
+
atomicalValue?: number;
|
|
41
|
+
}[];
|
|
42
|
+
runes?: {
|
|
43
|
+
runeid: string;
|
|
44
|
+
amount: string;
|
|
45
|
+
}[];
|
|
46
|
+
rawtx?: string;
|
|
47
|
+
}
|
|
48
|
+
export declare enum AddressType {
|
|
49
|
+
P2PKH = 0,
|
|
50
|
+
P2WPKH = 1,
|
|
51
|
+
P2TR = 2,
|
|
52
|
+
P2SH_P2WPKH = 3,
|
|
53
|
+
M44_P2WPKH = 4,// deprecated
|
|
54
|
+
M44_P2TR = 5,// deprecated
|
|
55
|
+
P2WSH = 6,
|
|
56
|
+
P2SH = 7,
|
|
57
|
+
UNKNOWN = 8
|
|
58
|
+
}
|
|
59
|
+
export {};
|
package/lib/utils.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { bitcoin } from './bitcoin-core';
|
|
2
|
+
export declare const toXOnly: (pubKey: Buffer) => Buffer<ArrayBufferLike>;
|
|
3
|
+
/**
|
|
4
|
+
* Transform raw private key to taproot address private key
|
|
5
|
+
*/
|
|
6
|
+
export declare function tweakSigner(signer: bitcoin.Signer, opts?: any): bitcoin.Signer;
|
|
7
|
+
/**
|
|
8
|
+
* ECDSA signature validator
|
|
9
|
+
*/
|
|
10
|
+
export declare const validator: (pubkey: Buffer, msghash: Buffer, signature: Buffer) => boolean;
|
|
11
|
+
/**
|
|
12
|
+
* Schnorr signature validator
|
|
13
|
+
*/
|
|
14
|
+
export declare const schnorrValidator: (pubkey: Buffer, msghash: Buffer, signature: Buffer) => boolean;
|
|
15
|
+
/**
|
|
16
|
+
* Transform satoshis to btc format
|
|
17
|
+
*/
|
|
18
|
+
export declare function satoshisToAmount(val: number): string;
|
|
19
|
+
/**
|
|
20
|
+
* Transform btc format to satoshis
|
|
21
|
+
*/
|
|
22
|
+
export declare function amountToSaothis(val: any): number;
|
|
23
|
+
export declare function shortAddress(address?: string, len?: number): string;
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import { bitcoin } from '../bitcoin-core';
|
|
2
|
+
import { SignPsbtOptions } from '../types';
|
|
3
|
+
export interface AbstractWallet {
|
|
4
|
+
signPsbt(psbt: bitcoin.Psbt, opts?: SignPsbtOptions): Promise<bitcoin.Psbt>;
|
|
5
|
+
signMessage(message: string | Buffer, type: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
6
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { bitcoin } from '../bitcoin-core';
|
|
2
|
+
import { SimpleKeyring } from '../keyring';
|
|
3
|
+
import { NetworkType } from '../network';
|
|
4
|
+
import { AddressType, SignPsbtOptions } from '../types';
|
|
5
|
+
import { AbstractWallet } from './abstract-wallet';
|
|
6
|
+
/**
|
|
7
|
+
* EstimateWallet is a wallet that can be used to estimate the size of a transaction.
|
|
8
|
+
*/
|
|
9
|
+
export declare class EstimateWallet implements AbstractWallet {
|
|
10
|
+
keyring: SimpleKeyring;
|
|
11
|
+
address: string;
|
|
12
|
+
pubkey: string;
|
|
13
|
+
network: bitcoin.Network;
|
|
14
|
+
networkType: NetworkType;
|
|
15
|
+
addressType: AddressType;
|
|
16
|
+
constructor(wif: string, networkType?: NetworkType, addressType?: AddressType);
|
|
17
|
+
static fromRandom(addressType?: AddressType, networkType?: NetworkType): EstimateWallet;
|
|
18
|
+
getNetworkType(): NetworkType;
|
|
19
|
+
signPsbt(psbt: bitcoin.Psbt, opts?: SignPsbtOptions): Promise<bitcoin.Psbt>;
|
|
20
|
+
getPublicKey(): Promise<string>;
|
|
21
|
+
signMessage(message: string | Buffer, type: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
22
|
+
private formatOptionsToSignInputs;
|
|
23
|
+
}
|
|
@@ -76,10 +76,10 @@ export class EstimateWallet {
|
|
|
76
76
|
const pubkeys = await this.keyring.getAccounts();
|
|
77
77
|
return pubkeys[0];
|
|
78
78
|
}
|
|
79
|
-
async signMessage(
|
|
79
|
+
async signMessage(message, type) {
|
|
80
80
|
if (type === 'bip322-simple') {
|
|
81
81
|
return await signMessageOfBIP322Simple({
|
|
82
|
-
message
|
|
82
|
+
message,
|
|
83
83
|
address: this.address,
|
|
84
84
|
networkType: this.networkType,
|
|
85
85
|
wallet: this
|
|
@@ -87,7 +87,7 @@ export class EstimateWallet {
|
|
|
87
87
|
}
|
|
88
88
|
else {
|
|
89
89
|
const pubkey = await this.getPublicKey();
|
|
90
|
-
return
|
|
90
|
+
return this.keyring.signMessage(pubkey, message);
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
async formatOptionsToSignInputs(_psbt, options) {
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { bitcoin } from '../bitcoin-core';
|
|
2
|
+
import { SimpleKeyring } from '../keyring';
|
|
3
|
+
import { NetworkType } from '../network';
|
|
4
|
+
import { AddressType, SignPsbtOptions } from '../types';
|
|
5
|
+
import { AbstractWallet } from './abstract-wallet';
|
|
6
|
+
export declare class LocalWallet implements AbstractWallet {
|
|
7
|
+
keyring: SimpleKeyring;
|
|
8
|
+
address: string;
|
|
9
|
+
pubkey: string;
|
|
10
|
+
network: bitcoin.Network;
|
|
11
|
+
addressType: AddressType;
|
|
12
|
+
networkType: NetworkType;
|
|
13
|
+
scriptPk: string | undefined;
|
|
14
|
+
constructor(wif: string, addressType?: AddressType, networkType?: NetworkType);
|
|
15
|
+
static fromMnemonic(addressType: AddressType, networkType: NetworkType, mnemonic: string, passPhrase?: string, hdPath?: string): LocalWallet;
|
|
16
|
+
static fromRandom(addressType?: AddressType, networkType?: NetworkType): LocalWallet;
|
|
17
|
+
getNetworkType(): NetworkType;
|
|
18
|
+
signPsbt(psbt: bitcoin.Psbt, opts?: SignPsbtOptions): Promise<bitcoin.Psbt>;
|
|
19
|
+
getPublicKey(): string;
|
|
20
|
+
signMessage(message: string | Buffer, type: 'bip322-simple' | 'ecdsa'): Promise<string>;
|
|
21
|
+
signData(data: string, type?: 'ecdsa' | 'schnorr'): Promise<string>;
|
|
22
|
+
private formatOptionsToSignInputs;
|
|
23
|
+
}
|
|
@@ -82,10 +82,10 @@ export class LocalWallet {
|
|
|
82
82
|
const pubkeys = this.keyring.getAccounts();
|
|
83
83
|
return pubkeys[0];
|
|
84
84
|
}
|
|
85
|
-
async signMessage(
|
|
85
|
+
async signMessage(message, type) {
|
|
86
86
|
if (type === 'bip322-simple') {
|
|
87
87
|
return await signMessageOfBIP322Simple({
|
|
88
|
-
message
|
|
88
|
+
message,
|
|
89
89
|
address: this.address,
|
|
90
90
|
networkType: this.networkType,
|
|
91
91
|
wallet: this
|
|
@@ -93,7 +93,7 @@ export class LocalWallet {
|
|
|
93
93
|
}
|
|
94
94
|
else {
|
|
95
95
|
const pubkey = this.getPublicKey();
|
|
96
|
-
return this.keyring.signMessage(pubkey,
|
|
96
|
+
return this.keyring.signMessage(pubkey, message);
|
|
97
97
|
}
|
|
98
98
|
}
|
|
99
99
|
async signData(data, type = 'ecdsa') {
|